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
64 struct expression
*unop
;
65 unsigned long op_value
;
68 // EXPR_SYMBOL, EXPR_TYPE
69 struct /* symbol_arg */ {
70 struct symbol
*symbol
;
71 struct ident
*symbol_name
;
75 struct statement
*statement
;
77 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
78 struct /* binop_arg */ {
79 struct expression
*left
, *right
;
82 struct /* deref_arg */ {
83 struct expression
*deref
;
88 struct expression
*base
;
89 unsigned r_bitpos
, r_nrbits
;
91 // EXPR_CAST and EXPR_SIZEOF
92 struct /* cast_arg */ {
93 struct symbol
*cast_type
;
94 struct expression
*cast_expression
;
98 struct /* conditional_expr */ {
99 struct expression
*conditional
, *cond_true
, *cond_false
;
102 struct /* call_expr */ {
103 struct expression
*fn
;
104 struct expression_list
*args
;
107 struct /* label_expr */ {
108 struct symbol
*label_symbol
;
111 struct expression_list
*expr_list
;
113 struct /* ident_expr */ {
114 struct ident
*expr_ident
;
115 struct expression
*ident_expression
;
118 struct /* index_expr */ {
119 unsigned int idx_from
, idx_to
;
120 struct expression
*idx_expression
;
123 struct /* initpos_expr */ {
124 unsigned int init_offset
, init_nr
;
125 struct expression
*init_expr
;
130 /* Constant expression values */
131 long long get_expression_value(struct expression
*);
133 /* Expression parsing */
134 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
135 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
136 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
137 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
138 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
140 extern void evaluate_symbol_list(struct symbol_list
*list
);
141 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
142 extern struct symbol
*evaluate_expression(struct expression
*);
144 extern void expand_symbol(struct symbol
*);
146 static inline struct expression
*alloc_expression(struct position pos
, int type
)
148 struct expression
*expr
= __alloc_expression(0);
154 static inline struct expression
*alloc_const_expression(struct position pos
, int value
)
156 struct expression
*expr
= __alloc_expression(0);
157 expr
->type
= EXPR_VALUE
;
160 expr
->ctype
= &int_ctype
;
164 /* Type name parsing */
165 struct token
*typename(struct token
*, struct symbol
**);
167 static inline int lookup_type(struct token
*token
)
169 if (token
->pos
.type
== TOKEN_IDENT
) {
170 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_SYMBOL
| NS_TYPEDEF
);
171 return sym
&& sym
->namespace == NS_TYPEDEF
;
176 /* Statement parsing */
177 struct statement
*alloc_statement(struct position pos
, int type
);
178 struct token
*initializer(struct expression
**tree
, struct token
*token
);
179 struct token
*compound_statement(struct token
*, struct statement
*);
181 /* The preprocessor calls this 'constant_expression()' */
182 #define constant_expression(token,tree) conditional_expression(token, tree)
184 /* Cast folding of constant values.. */
185 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
186 struct expression
*old
, struct symbol
*oldtype
);