6 * Copyright (C) 2003 Transmeta Corp.
9 * Licensed under the Open Software License version 1.1
11 * Declarations and helper functions for expression parsing.
14 struct expression_list
;
16 enum expression_type
{
33 EXPR_SELECT
, // a "safe" conditional expression
39 EXPR_INITIALIZER
, // initializer list
40 EXPR_IDENTIFIER
, // identifier in initializer
41 EXPR_INDEX
, // index in initializer
42 EXPR_POS
, // position in initializer
48 enum expression_type type
;
54 unsigned long long value
;
60 struct string
*string
;
62 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
63 struct expression
*unop
;
65 // EXPR_SYMBOL, EXPR_TYPE
66 struct /* symbol_arg */ {
67 struct symbol
*symbol
;
68 struct ident
*symbol_name
;
72 struct statement
*statement
;
74 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
75 struct /* binop_arg */ {
76 struct expression
*left
, *right
;
79 struct /* deref_arg */ {
80 struct expression
*deref
;
85 struct expression
*base
;
86 unsigned r_bitpos
, r_nrbits
;
88 // EXPR_CAST and EXPR_SIZEOF
89 struct /* cast_arg */ {
90 struct symbol
*cast_type
;
91 struct expression
*cast_expression
;
95 struct /* conditional_expr */ {
96 struct expression
*conditional
, *cond_true
, *cond_false
;
99 struct /* call_expr */ {
100 struct expression
*fn
;
101 struct expression_list
*args
;
104 struct /* label_expr */ {
105 struct symbol
*label_symbol
;
108 struct expression_list
*expr_list
;
110 struct /* ident_expr */ {
111 struct ident
*expr_ident
;
112 struct expression
*ident_expression
;
115 struct /* index_expr */ {
116 unsigned int idx_from
, idx_to
;
117 struct expression
*idx_expression
;
120 struct /* initpos_expr */ {
121 unsigned int init_offset
, init_nr
;
122 struct expression
*init_expr
;
127 /* Constant expression values */
128 long long get_expression_value(struct expression
*);
130 /* Expression parsing */
131 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
132 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
133 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
134 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
135 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
137 extern void evaluate_symbol_list(struct symbol_list
*list
);
138 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
139 extern struct symbol
*evaluate_expression(struct expression
*);
141 extern void expand_symbol(struct symbol
*);
143 static inline struct expression
*alloc_expression(struct position pos
, int type
)
145 struct expression
*expr
= __alloc_expression(0);
151 static inline struct expression
*alloc_const_expression(struct position pos
, int value
)
153 struct expression
*expr
= __alloc_expression(0);
154 expr
->type
= EXPR_VALUE
;
157 expr
->ctype
= &int_ctype
;
161 /* Type name parsing */
162 struct token
*typename(struct token
*, struct symbol
**);
164 static inline int lookup_type(struct token
*token
)
166 if (token
->pos
.type
== TOKEN_IDENT
) {
167 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_SYMBOL
| NS_TYPEDEF
);
168 return sym
&& sym
->namespace == NS_TYPEDEF
;
173 /* Statement parsing */
174 struct statement
*alloc_statement(struct position pos
, int type
);
175 struct token
*initializer(struct expression
**tree
, struct token
*token
);
176 struct token
*compound_statement(struct token
*, struct statement
*);
178 /* The preprocessor calls this 'constant_expression()' */
179 #define constant_expression(token,tree) conditional_expression(token, tree)
181 /* Cast folding of constant values.. */
182 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
183 struct expression
*old
, struct symbol
*oldtype
);