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
*);
172 /* Expression parsing */
173 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
174 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
175 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
176 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
177 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
179 extern void evaluate_symbol_list(struct symbol_list
*list
);
180 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
181 extern struct symbol
*evaluate_expression(struct expression
*);
183 extern int expand_symbol(struct symbol
*);
185 static inline struct expression
*alloc_expression(struct position pos
, int type
)
187 struct expression
*expr
= __alloc_expression(0);
193 static inline struct expression
*alloc_const_expression(struct position pos
, int value
)
195 struct expression
*expr
= __alloc_expression(0);
196 expr
->type
= EXPR_VALUE
;
199 expr
->ctype
= &int_ctype
;
203 /* Type name parsing */
204 struct token
*typename(struct token
*, struct symbol
**, int *);
206 static inline int lookup_type(struct token
*token
)
208 if (token
->pos
.type
== TOKEN_IDENT
) {
209 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_SYMBOL
| NS_TYPEDEF
);
210 return sym
&& (sym
->namespace & NS_TYPEDEF
);
215 /* Statement parsing */
216 struct statement
*alloc_statement(struct position pos
, int type
);
217 struct token
*initializer(struct expression
**tree
, struct token
*token
);
218 struct token
*compound_statement(struct token
*, struct statement
*);
220 /* The preprocessor calls this 'constant_expression()' */
221 #define constant_expression(token,tree) conditional_expression(token, tree)
223 /* Cast folding of constant values.. */
224 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
225 struct expression
*old
, struct symbol
*oldtype
);