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
46 enum expression_type type
;
52 unsigned long long value
;
58 struct string
*string
;
60 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
61 struct expression
*unop
;
63 // EXPR_SYMBOL, EXPR_TYPE
64 struct /* symbol_arg */ {
65 struct symbol
*symbol
;
66 struct ident
*symbol_name
;
70 struct statement
*statement
;
72 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
73 struct /* binop_arg */ {
74 struct expression
*left
, *right
;
77 struct /* deref_arg */ {
78 struct expression
*deref
;
81 // EXPR_CAST and EXPR_SIZEOF
82 struct /* cast_arg */ {
83 struct symbol
*cast_type
;
84 struct expression
*cast_expression
;
88 struct /* conditional_expr */ {
89 struct expression
*conditional
, *cond_true
, *cond_false
;
92 struct /* call_expr */ {
93 struct expression
*fn
;
94 struct expression_list
*args
;
97 struct /* bitfield_expr */ {
98 unsigned char bitpos
, nrbits
;
99 struct expression
*address
;
102 struct /* label_expr */ {
103 struct symbol
*label_symbol
;
106 struct expression_list
*expr_list
;
108 struct ident
*expr_ident
;
110 struct /* index_expr */ {
111 unsigned int idx_from
, idx_to
;
114 struct /* initpos_expr */ {
115 unsigned int init_offset
;
116 struct symbol
*init_sym
;
117 struct expression
*init_expr
;
122 /* Constant expression values */
123 long long get_expression_value(struct expression
*);
125 /* Expression parsing */
126 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
127 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
128 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
129 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
130 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
132 extern void check_duplicates(struct symbol
*sym
);
133 extern struct symbol
*evaluate_symbol(struct symbol
*sym
);
134 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
135 extern struct symbol
*evaluate_expression(struct expression
*);
137 extern void expand_symbol(struct symbol
*);
139 static inline struct expression
*alloc_expression(struct position pos
, int type
)
141 struct expression
*expr
= __alloc_expression(0);
147 static inline struct expression
*alloc_const_expression(struct position pos
, int value
)
149 struct expression
*expr
= __alloc_expression(0);
150 expr
->type
= EXPR_VALUE
;
153 expr
->ctype
= &int_ctype
;
157 /* Type name parsing */
158 struct token
*typename(struct token
*, struct symbol
**);
160 static inline int lookup_type(struct token
*token
)
162 if (token
->pos
.type
== TOKEN_IDENT
) {
163 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_SYMBOL
| NS_TYPEDEF
);
164 return sym
&& sym
->namespace == NS_TYPEDEF
;
169 /* Statement parsing */
170 struct statement
*alloc_statement(struct position pos
, int type
);
171 struct token
*initializer(struct expression
**tree
, struct token
*token
);
172 struct token
*compound_statement(struct token
*, struct statement
*);
174 /* The preprocessor calls this 'constant_expression()' */
175 #define constant_expression(token,tree) conditional_expression(token, tree)
177 /* Cast folding of constant values.. */
178 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
179 struct expression
*old
, struct symbol
*oldtype
);