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
{
35 EXPR_INITIALIZER
, // initializer list
36 EXPR_IDENTIFIER
, // identifier in initializer
37 EXPR_INDEX
, // index in initializer
38 EXPR_POS
, // position in initializer
42 enum expression_type type
;
48 unsigned long long value
;
51 struct string
*string
;
53 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
54 struct expression
*unop
;
57 struct /* symbol_arg */ {
58 struct symbol
*symbol
;
59 struct ident
*symbol_name
;
63 struct statement
*statement
;
65 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
66 struct /* binop_arg */ {
67 struct expression
*left
, *right
;
70 struct /* deref_arg */ {
71 struct expression
*deref
;
74 // EXPR_CAST and EXPR_SIZEOF
75 struct /* cast_arg */ {
76 struct symbol
*cast_type
;
77 struct expression
*cast_expression
;
80 struct /* conditional_expr */ {
81 struct expression
*conditional
, *cond_true
, *cond_false
;
84 struct /* call_expr */ {
85 struct expression
*fn
;
86 struct expression_list
*args
;
89 struct /* bitfield_expr */ {
90 unsigned char bitpos
, nrbits
;
91 struct expression
*address
;
94 struct /* label_expr */ {
95 struct symbol
*label_symbol
;
98 struct expression_list
*expr_list
;
100 struct ident
*expr_ident
;
102 struct /* index_expr */ {
103 unsigned int idx_from
, idx_to
;
106 struct /* initpos_expr */ {
107 unsigned int init_offset
;
108 struct symbol
*init_sym
;
109 struct expression
*init_expr
;
114 /* Constant expression values */
115 long long get_expression_value(struct expression
*);
117 /* Expression parsing */
118 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
119 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
120 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
121 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
122 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
124 extern void check_duplicates(struct symbol
*sym
);
125 extern struct symbol
*evaluate_symbol(struct symbol
*sym
);
126 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
127 extern struct symbol
*evaluate_expression(struct expression
*);
129 extern void expand_symbol(struct symbol
*);
131 static inline struct expression
*alloc_expression(struct position pos
, int type
)
133 struct expression
*expr
= __alloc_expression(0);
139 static inline struct expression
*alloc_const_expression(struct position pos
, int value
)
141 struct expression
*expr
= __alloc_expression(0);
142 expr
->type
= EXPR_VALUE
;
145 expr
->ctype
= &int_ctype
;
149 /* Type name parsing */
150 struct token
*typename(struct token
*, struct symbol
**);
152 static inline int lookup_type(struct token
*token
)
154 if (token
->pos
.type
== TOKEN_IDENT
)
155 return lookup_symbol(token
->ident
, NS_TYPEDEF
) != NULL
;
159 /* Statement parsing */
160 struct statement
*alloc_statement(struct position pos
, int type
);
161 struct token
*initializer(struct expression
**tree
, struct token
*token
);
162 struct token
*compound_statement(struct token
*, struct statement
*);
164 /* The preprocessor calls this 'constant_expression()' */
165 #define constant_expression(token,tree) conditional_expression(token, tree)
167 /* Cast folding of constant values.. */
168 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
169 struct expression
*old
, struct symbol
*oldtype
);