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
{
37 EXPR_INITIALIZER
, // initializer list
38 EXPR_IDENTIFIER
, // identifier in initializer
39 EXPR_INDEX
, // index in initializer
40 EXPR_POS
, // position in initializer
45 enum expression_type type
;
51 unsigned long long value
;
57 struct string
*string
;
59 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
60 struct expression
*unop
;
62 // EXPR_SYMBOL, EXPR_TYPE
63 struct /* symbol_arg */ {
64 struct symbol
*symbol
;
65 struct ident
*symbol_name
;
69 struct statement
*statement
;
71 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
72 struct /* binop_arg */ {
73 struct expression
*left
, *right
;
76 struct /* deref_arg */ {
77 struct expression
*deref
;
80 // EXPR_CAST and EXPR_SIZEOF
81 struct /* cast_arg */ {
82 struct symbol
*cast_type
;
83 struct expression
*cast_expression
;
86 struct /* conditional_expr */ {
87 struct expression
*conditional
, *cond_true
, *cond_false
;
90 struct /* call_expr */ {
91 struct expression
*fn
;
92 struct expression_list
*args
;
95 struct /* bitfield_expr */ {
96 unsigned char bitpos
, nrbits
;
97 struct expression
*address
;
100 struct /* label_expr */ {
101 struct symbol
*label_symbol
;
104 struct expression_list
*expr_list
;
106 struct ident
*expr_ident
;
108 struct /* index_expr */ {
109 unsigned int idx_from
, idx_to
;
112 struct /* initpos_expr */ {
113 unsigned int init_offset
;
114 struct symbol
*init_sym
;
115 struct expression
*init_expr
;
120 /* Constant expression values */
121 long long get_expression_value(struct expression
*);
123 /* Expression parsing */
124 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
125 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
126 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
127 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
128 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
130 extern void check_duplicates(struct symbol
*sym
);
131 extern struct symbol
*evaluate_symbol(struct symbol
*sym
);
132 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
133 extern struct symbol
*evaluate_expression(struct expression
*);
135 extern void expand_symbol(struct symbol
*);
137 static inline struct expression
*alloc_expression(struct position pos
, int type
)
139 struct expression
*expr
= __alloc_expression(0);
145 static inline struct expression
*alloc_const_expression(struct position pos
, int value
)
147 struct expression
*expr
= __alloc_expression(0);
148 expr
->type
= EXPR_VALUE
;
151 expr
->ctype
= &int_ctype
;
155 /* Type name parsing */
156 struct token
*typename(struct token
*, struct symbol
**);
158 static inline int lookup_type(struct token
*token
)
160 if (token
->pos
.type
== TOKEN_IDENT
) {
161 struct symbol
*sym
= lookup_symbol(token
->ident
, NS_SYMBOL
| NS_TYPEDEF
);
162 return sym
&& sym
->namespace == NS_TYPEDEF
;
167 /* Statement parsing */
168 struct statement
*alloc_statement(struct position pos
, int type
);
169 struct token
*initializer(struct expression
**tree
, struct token
*token
);
170 struct token
*compound_statement(struct token
*, struct statement
*);
172 /* The preprocessor calls this 'constant_expression()' */
173 #define constant_expression(token,tree) conditional_expression(token, tree)
175 /* Cast folding of constant values.. */
176 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
177 struct expression
*old
, struct symbol
*oldtype
);