6 * Copyright (C) 2003 Transmeta Corp.
9 * Licensed under the Open Software License version 1.1
11 * Declarations and helper functions for expression parsing.
16 struct expression_list
;
18 enum expression_type
{
35 EXPR_SELECT
, // a "safe" conditional expression
41 EXPR_INITIALIZER
, // initializer list
42 EXPR_IDENTIFIER
, // identifier in initializer
43 EXPR_INDEX
, // index in initializer
44 EXPR_POS
, // position in initializer
50 enum expression_type type
;
56 unsigned long long value
;
62 struct string
*string
;
64 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
66 struct expression
*unop
;
67 unsigned long op_value
;
70 // EXPR_SYMBOL, EXPR_TYPE
71 struct /* symbol_arg */ {
72 struct symbol
*symbol
;
73 struct ident
*symbol_name
;
77 struct statement
*statement
;
79 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
80 struct /* binop_arg */ {
81 struct expression
*left
, *right
;
84 struct /* deref_arg */ {
85 struct expression
*deref
;
90 struct expression
*base
;
91 unsigned r_bitpos
, r_nrbits
;
93 // EXPR_CAST and EXPR_SIZEOF
94 struct /* cast_arg */ {
95 struct symbol
*cast_type
;
96 struct expression
*cast_expression
;
100 struct /* conditional_expr */ {
101 struct expression
*conditional
, *cond_true
, *cond_false
;
104 struct /* call_expr */ {
105 struct expression
*fn
;
106 struct expression_list
*args
;
109 struct /* label_expr */ {
110 struct symbol
*label_symbol
;
113 struct expression_list
*expr_list
;
115 struct /* ident_expr */ {
116 struct ident
*expr_ident
;
117 struct expression
*ident_expression
;
120 struct /* index_expr */ {
121 unsigned int idx_from
, idx_to
;
122 struct expression
*idx_expression
;
125 struct /* initpos_expr */ {
126 unsigned int init_offset
, init_nr
;
127 struct expression
*init_expr
;
132 /* Constant expression values */
133 long long get_expression_value(struct expression
*);
135 /* Expression parsing */
136 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
137 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
138 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
139 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
140 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
142 extern void evaluate_symbol_list(struct symbol_list
*list
);
143 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
144 extern struct symbol
*evaluate_expression(struct expression
*);
146 extern int expand_symbol(struct symbol
*);
148 static inline struct expression
*alloc_expression(struct position pos
, int type
)
150 struct expression
*expr
= __alloc_expression(0);
156 static inline struct expression
*alloc_const_expression(struct position pos
, int value
)
158 struct expression
*expr
= __alloc_expression(0);
159 expr
->type
= EXPR_VALUE
;
162 expr
->ctype
= &int_ctype
;
166 /* Type name parsing */
167 struct token
*typename(struct token
*, struct symbol
**);
169 static inline int lookup_type(struct token
*token
)
171 if (token
->pos
.type
== TOKEN_IDENT
) {
172 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_SYMBOL
| NS_TYPEDEF
);
173 return sym
&& sym
->namespace == NS_TYPEDEF
;
178 /* Statement parsing */
179 struct statement
*alloc_statement(struct position pos
, int type
);
180 struct token
*initializer(struct expression
**tree
, struct token
*token
);
181 struct token
*compound_statement(struct token
*, struct statement
*);
183 /* The preprocessor calls this 'constant_expression()' */
184 #define constant_expression(token,tree) conditional_expression(token, tree)
186 /* Cast folding of constant values.. */
187 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
188 struct expression
*old
, struct symbol
*oldtype
);