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->flags */
64 }; /* for expr->taint */
67 enum expression_type type
:8;
69 unsigned smatch_flags
:16;
76 unsigned long long value
;
86 struct string
*string
;
89 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
91 struct expression
*unop
;
92 unsigned long op_value
;
95 // EXPR_SYMBOL, EXPR_TYPE
96 struct /* symbol_arg */ {
97 struct symbol
*symbol
;
98 struct ident
*symbol_name
;
102 struct statement
*statement
;
104 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
105 struct /* binop_arg */ {
106 struct expression
*left
, *right
;
109 struct /* deref_arg */ {
110 struct expression
*deref
;
111 struct ident
*member
;
115 struct expression
*base
;
116 unsigned r_bitpos
, r_nrbits
;
118 // EXPR_CAST and EXPR_SIZEOF
119 struct /* cast_arg */ {
120 struct symbol
*cast_type
;
121 struct expression
*cast_expression
;
125 struct /* conditional_expr */ {
126 struct expression
*conditional
, *cond_true
, *cond_false
;
129 struct /* call_expr */ {
130 struct expression
*fn
;
131 struct expression_list
*args
;
134 struct /* label_expr */ {
135 struct symbol
*label_symbol
;
138 struct expression_list
*expr_list
;
140 struct /* ident_expr */ {
141 struct ident
*expr_ident
;
142 struct symbol
*field
;
143 struct expression
*ident_expression
;
146 struct /* index_expr */ {
147 unsigned int idx_from
, idx_to
;
148 struct expression
*idx_expression
;
151 struct /* initpos_expr */ {
152 unsigned int init_offset
, init_nr
;
153 struct expression
*init_expr
;
158 struct expression
*down
;
161 struct expression
*index
;
167 /* Constant expression values */
168 int is_zero_constant(struct expression
*);
169 long long get_expression_value(struct expression
*);
170 long long const_expression_value(struct expression
*);
171 long long get_expression_value_nomod(struct expression
*);
173 /* Expression parsing */
174 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
175 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
176 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
177 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
178 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
180 extern void evaluate_symbol_list(struct symbol_list
*list
);
181 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
182 extern struct symbol
*evaluate_expression(struct expression
*);
184 extern int expand_symbol(struct symbol
*);
186 static inline struct expression
*alloc_expression(struct position pos
, int type
)
188 struct expression
*expr
= __alloc_expression(0);
194 static inline struct expression
*alloc_const_expression(struct position pos
, int value
)
196 struct expression
*expr
= __alloc_expression(0);
197 expr
->type
= EXPR_VALUE
;
200 expr
->ctype
= &int_ctype
;
204 /* Type name parsing */
205 struct token
*typename(struct token
*, struct symbol
**, int *);
207 static inline int lookup_type(struct token
*token
)
209 if (token
->pos
.type
== TOKEN_IDENT
) {
210 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_SYMBOL
| NS_TYPEDEF
);
211 return sym
&& (sym
->namespace & NS_TYPEDEF
);
216 /* Statement parsing */
217 struct statement
*alloc_statement(struct position pos
, int type
);
218 struct token
*initializer(struct expression
**tree
, struct token
*token
);
219 struct token
*compound_statement(struct token
*, struct statement
*);
221 /* The preprocessor calls this 'constant_expression()' */
222 #define constant_expression(token,tree) conditional_expression(token, tree)
224 /* Cast folding of constant values.. */
225 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
226 struct expression
*old
, struct symbol
*oldtype
);