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
;
79 struct string
*string
;
81 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
83 struct expression
*unop
;
84 unsigned long op_value
;
87 // EXPR_SYMBOL, EXPR_TYPE
88 struct /* symbol_arg */ {
89 struct symbol
*symbol
;
90 struct ident
*symbol_name
;
94 struct statement
*statement
;
96 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
97 struct /* binop_arg */ {
98 struct expression
*left
, *right
;
101 struct /* deref_arg */ {
102 struct expression
*deref
;
103 struct ident
*member
;
107 struct expression
*base
;
108 unsigned r_bitpos
, r_nrbits
;
110 // EXPR_CAST and EXPR_SIZEOF
111 struct /* cast_arg */ {
112 struct symbol
*cast_type
;
113 struct expression
*cast_expression
;
117 struct /* conditional_expr */ {
118 struct expression
*conditional
, *cond_true
, *cond_false
;
121 struct /* call_expr */ {
122 struct expression
*fn
;
123 struct expression_list
*args
;
126 struct /* label_expr */ {
127 struct symbol
*label_symbol
;
130 struct expression_list
*expr_list
;
132 struct /* ident_expr */ {
133 struct ident
*expr_ident
;
134 struct symbol
*field
;
135 struct expression
*ident_expression
;
138 struct /* index_expr */ {
139 unsigned int idx_from
, idx_to
;
140 struct expression
*idx_expression
;
143 struct /* initpos_expr */ {
144 unsigned int init_offset
, init_nr
;
145 struct expression
*init_expr
;
150 struct expression
*down
;
153 struct expression
*index
;
159 /* Constant expression values */
160 int is_zero_constant(struct expression
*);
161 long long get_expression_value(struct expression
*);
162 long long const_expression_value(struct expression
*);
164 /* Expression parsing */
165 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
166 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
167 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
168 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
169 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
171 extern void evaluate_symbol_list(struct symbol_list
*list
);
172 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
173 extern struct symbol
*evaluate_expression(struct expression
*);
175 extern int expand_symbol(struct symbol
*);
177 static inline struct expression
*alloc_expression(struct position pos
, int type
)
179 struct expression
*expr
= __alloc_expression(0);
185 static inline struct expression
*alloc_const_expression(struct position pos
, int value
)
187 struct expression
*expr
= __alloc_expression(0);
188 expr
->type
= EXPR_VALUE
;
191 expr
->ctype
= &int_ctype
;
195 /* Type name parsing */
196 struct token
*typename(struct token
*, struct symbol
**, int);
198 static inline int lookup_type(struct token
*token
)
200 if (token
->pos
.type
== TOKEN_IDENT
) {
201 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_SYMBOL
| NS_TYPEDEF
);
202 return sym
&& sym
->namespace == NS_TYPEDEF
;
207 /* Statement parsing */
208 struct statement
*alloc_statement(struct position pos
, int type
);
209 struct token
*initializer(struct expression
**tree
, struct token
*token
);
210 struct token
*compound_statement(struct token
*, struct statement
*);
212 /* The preprocessor calls this 'constant_expression()' */
213 #define constant_expression(token,tree) conditional_expression(token, tree)
215 /* Cast folding of constant values.. */
216 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
217 struct expression
*old
, struct symbol
*oldtype
);