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 check_duplicates(struct symbol
*sym
);
138 extern struct symbol
*evaluate_symbol(struct symbol
*sym
);
139 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
140 extern struct symbol
*evaluate_expression(struct expression
*);
142 extern void expand_symbol(struct symbol
*);
144 static inline struct expression
*alloc_expression(struct position pos
, int type
)
146 struct expression
*expr
= __alloc_expression(0);
152 static inline struct expression
*alloc_const_expression(struct position pos
, int value
)
154 struct expression
*expr
= __alloc_expression(0);
155 expr
->type
= EXPR_VALUE
;
158 expr
->ctype
= &int_ctype
;
162 /* Type name parsing */
163 struct token
*typename(struct token
*, struct symbol
**);
165 static inline int lookup_type(struct token
*token
)
167 if (token
->pos
.type
== TOKEN_IDENT
) {
168 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_SYMBOL
| NS_TYPEDEF
);
169 return sym
&& sym
->namespace == NS_TYPEDEF
;
174 /* Statement parsing */
175 struct statement
*alloc_statement(struct position pos
, int type
);
176 struct token
*initializer(struct expression
**tree
, struct token
*token
);
177 struct token
*compound_statement(struct token
*, struct statement
*);
179 /* The preprocessor calls this 'constant_expression()' */
180 #define constant_expression(token,tree) conditional_expression(token, tree)
182 /* Cast folding of constant values.. */
183 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
184 struct expression
*old
, struct symbol
*oldtype
);