6 * Copyright (C) 2003 Transmeta Corp.
8 * Licensed under the Open Software License version 1.1
10 * Declarations and helper functions for expression parsing.
13 struct expression_list
;
15 enum expression_type
{
33 EXPR_INITIALIZER
, // initializer list
34 EXPR_IDENTIFIER
, // identifier in initializer
35 EXPR_INDEX
, // index in initializer
36 EXPR_POS
, // position in initializer
40 enum expression_type type
;
46 unsigned long long value
;
49 struct string
*string
;
51 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
52 struct expression
*unop
;
56 struct symbol
*symbol
;
57 struct ident
*symbol_name
;
61 struct statement
*statement
;
63 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
65 struct expression
*left
, *right
;
69 struct expression
*deref
;
72 // EXPR_CAST and EXPR_SIZEOF
74 struct symbol
*cast_type
;
75 struct expression
*cast_expression
;
78 struct conditional_expr
{
79 struct expression
*conditional
, *cond_true
, *cond_false
;
83 struct expression
*fn
;
84 struct expression_list
*args
;
87 struct bitfield_expr
{
88 unsigned char bitpos
, nrbits
;
89 struct expression
*address
;
92 struct expression_list
*expr_list
;
94 struct ident
*expr_ident
;
97 unsigned int idx_from
, idx_to
;
100 struct initpos_expr
{
101 unsigned int init_offset
;
102 struct symbol
*init_sym
;
103 struct expression
*init_expr
;
108 /* Constant expression values */
109 long long get_expression_value(struct expression
*);
111 /* Expression parsing */
112 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
113 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
114 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
115 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
116 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
118 extern struct symbol
*evaluate_symbol(struct symbol
*sym
);
119 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
120 extern struct symbol
*evaluate_expression(struct expression
*);
122 static inline struct expression
*alloc_expression(struct position pos
, int type
)
124 struct expression
*expr
= __alloc_expression(0);
130 /* Type name parsing */
131 struct token
*typename(struct token
*, struct symbol
**);
133 static inline int lookup_type(struct token
*token
)
135 if (token
->pos
.type
== TOKEN_IDENT
)
136 return lookup_symbol(token
->ident
, NS_TYPEDEF
) != NULL
;
140 /* Statement parsing */
141 struct statement
*alloc_statement(struct position pos
, int type
);
142 struct token
*initializer(struct expression
**tree
, struct token
*token
);
143 struct token
*compound_statement(struct token
*, struct statement
*);
145 /* The preprocessor calls this 'constant_expression()' */
146 #define constant_expression(token,tree) conditional_expression(token, tree)