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
{
31 EXPR_SELECT
, // a "safe" conditional expression
38 EXPR_INITIALIZER
, // initializer list
39 EXPR_IDENTIFIER
, // identifier in initializer
40 EXPR_INDEX
, // index in initializer
41 EXPR_POS
, // position in initializer
47 enum expression_type type
;
53 unsigned long long value
;
59 struct string
*string
;
61 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
62 struct expression
*unop
;
64 // EXPR_SYMBOL, EXPR_TYPE
65 struct /* symbol_arg */ {
66 struct symbol
*symbol
;
67 struct ident
*symbol_name
;
71 struct statement
*statement
;
73 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
74 struct /* binop_arg */ {
75 struct expression
*left
, *right
;
78 struct /* deref_arg */ {
79 struct expression
*deref
;
84 struct expression
*base
;
85 unsigned r_bitpos
, r_nrbits
;
87 // EXPR_CAST and EXPR_SIZEOF
88 struct /* cast_arg */ {
89 struct symbol
*cast_type
;
90 struct expression
*cast_expression
;
94 struct /* conditional_expr */ {
95 struct expression
*conditional
, *cond_true
, *cond_false
;
98 struct /* call_expr */ {
99 struct expression
*fn
;
100 struct expression_list
*args
;
103 struct /* bitfield_expr */ {
104 unsigned char bitpos
, nrbits
;
105 struct expression
*address
;
108 struct /* label_expr */ {
109 struct symbol
*label_symbol
;
112 struct expression_list
*expr_list
;
114 struct ident
*expr_ident
;
116 struct /* index_expr */ {
117 unsigned int idx_from
, idx_to
;
120 struct /* initpos_expr */ {
121 unsigned int init_offset
;
122 struct symbol
*init_sym
;
123 struct expression
*init_expr
;
128 /* Constant expression values */
129 long long get_expression_value(struct expression
*);
131 /* Expression parsing */
132 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
133 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
134 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
135 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
136 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
138 extern void check_duplicates(struct symbol
*sym
);
139 extern struct symbol
*evaluate_symbol(struct symbol
*sym
);
140 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
141 extern struct symbol
*evaluate_expression(struct expression
*);
143 extern void expand_symbol(struct symbol
*);
145 static inline struct expression
*alloc_expression(struct position pos
, int type
)
147 struct expression
*expr
= __alloc_expression(0);
153 static inline struct expression
*alloc_const_expression(struct position pos
, int value
)
155 struct expression
*expr
= __alloc_expression(0);
156 expr
->type
= EXPR_VALUE
;
159 expr
->ctype
= &int_ctype
;
163 /* Type name parsing */
164 struct token
*typename(struct token
*, struct symbol
**);
166 static inline int lookup_type(struct token
*token
)
168 if (token
->pos
.type
== TOKEN_IDENT
) {
169 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_SYMBOL
| NS_TYPEDEF
);
170 return sym
&& sym
->namespace == NS_TYPEDEF
;
175 /* Statement parsing */
176 struct statement
*alloc_statement(struct position pos
, int type
);
177 struct token
*initializer(struct expression
**tree
, struct token
*token
);
178 struct token
*compound_statement(struct token
*, struct statement
*);
180 /* The preprocessor calls this 'constant_expression()' */
181 #define constant_expression(token,tree) conditional_expression(token, tree)
183 /* Cast folding of constant values.. */
184 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
185 struct expression
*old
, struct symbol
*oldtype
);