6 * Copyright (C) 2003 Transmeta Corp.
9 * Licensed under the Open Software License version 1.1
11 * Declarations and helper functions for expression parsing.
18 struct expression_list
;
20 enum expression_type
{
38 EXPR_SELECT
, // a "safe" conditional expression
44 EXPR_INITIALIZER
, // initializer list
45 EXPR_IDENTIFIER
, // identifier in initializer
46 EXPR_INDEX
, // index in initializer
47 EXPR_POS
, // position in initializer
56 }; /* for expr->flags */
60 }; /* for expr->taint */
63 enum expression_type type
:8;
71 unsigned long long value
;
81 struct string
*string
;
84 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
86 struct expression
*unop
;
87 unsigned long op_value
;
90 // EXPR_SYMBOL, EXPR_TYPE
91 struct /* symbol_arg */ {
92 struct symbol
*symbol
;
93 struct ident
*symbol_name
;
97 struct statement
*statement
;
99 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
100 struct /* binop_arg */ {
101 struct expression
*left
, *right
;
104 struct /* deref_arg */ {
105 struct expression
*deref
;
106 struct ident
*member
;
110 struct expression
*base
;
111 unsigned r_bitpos
, r_nrbits
;
113 // EXPR_CAST and EXPR_SIZEOF
114 struct /* cast_arg */ {
115 struct symbol
*cast_type
;
116 struct expression
*cast_expression
;
120 struct /* conditional_expr */ {
121 struct expression
*conditional
, *cond_true
, *cond_false
;
124 struct /* call_expr */ {
125 struct expression
*fn
;
126 struct expression_list
*args
;
129 struct /* label_expr */ {
130 struct symbol
*label_symbol
;
133 struct expression_list
*expr_list
;
135 struct /* ident_expr */ {
136 struct ident
*expr_ident
;
137 struct symbol
*field
;
138 struct expression
*ident_expression
;
141 struct /* index_expr */ {
142 unsigned int idx_from
, idx_to
;
143 struct expression
*idx_expression
;
146 struct /* initpos_expr */ {
147 unsigned int init_offset
, init_nr
;
148 struct expression
*init_expr
;
153 struct expression
*down
;
156 struct expression
*index
;
162 /* Constant expression values */
163 int is_zero_constant(struct expression
*);
164 long long get_expression_value(struct expression
*);
165 long long const_expression_value(struct expression
*);
167 /* Expression parsing */
168 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
169 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
170 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
171 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
172 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
174 extern void evaluate_symbol_list(struct symbol_list
*list
);
175 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
176 extern struct symbol
*evaluate_expression(struct expression
*);
178 extern int expand_symbol(struct symbol
*);
180 static inline struct expression
*alloc_expression(struct position pos
, int type
)
182 struct expression
*expr
= __alloc_expression(0);
188 static inline struct expression
*alloc_const_expression(struct position pos
, int value
)
190 struct expression
*expr
= __alloc_expression(0);
191 expr
->type
= EXPR_VALUE
;
194 expr
->ctype
= &int_ctype
;
198 /* Type name parsing */
199 struct token
*typename(struct token
*, struct symbol
**, int *);
201 static inline int lookup_type(struct token
*token
)
203 if (token
->pos
.type
== TOKEN_IDENT
) {
204 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_SYMBOL
| NS_TYPEDEF
);
205 return sym
&& (sym
->namespace & NS_TYPEDEF
);
210 /* Statement parsing */
211 struct statement
*alloc_statement(struct position pos
, int type
);
212 struct token
*initializer(struct expression
**tree
, struct token
*token
);
213 struct token
*compound_statement(struct token
*, struct statement
*);
215 /* The preprocessor calls this 'constant_expression()' */
216 #define constant_expression(token,tree) conditional_expression(token, tree)
218 /* Cast folding of constant values.. */
219 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
220 struct expression
*old
, struct symbol
*oldtype
);