6 * Copyright (C) 2003 Transmeta Corp.
8 * Licensed under the Open Software License version 1.1
10 * Declarations and helper functions for expression parsing.
13 struct expression_list
;
15 enum expression_type
{
34 EXPR_INITIALIZER
, // initializer list
35 EXPR_IDENTIFIER
, // identifier in initializer
36 EXPR_INDEX
, // index in initializer
37 EXPR_POS
, // position in initializer
41 enum expression_type type
;
47 unsigned long long value
;
50 struct string
*string
;
52 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
53 struct expression
*unop
;
56 struct /* symbol_arg */ {
57 struct symbol
*symbol
;
58 struct ident
*symbol_name
;
62 struct statement
*statement
;
64 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
65 struct /* binop_arg */ {
66 struct expression
*left
, *right
;
69 struct /* deref_arg */ {
70 struct expression
*deref
;
73 // EXPR_CAST and EXPR_SIZEOF
74 struct /* cast_arg */ {
75 struct symbol
*cast_type
;
76 struct expression
*cast_expression
;
79 struct /* conditional_expr */ {
80 struct expression
*conditional
, *cond_true
, *cond_false
;
83 struct /* call_expr */ {
84 struct expression
*fn
;
85 struct expression_list
*args
;
88 struct /* bitfield_expr */ {
89 unsigned char bitpos
, nrbits
;
90 struct expression
*address
;
93 struct /* label_expr */ {
94 struct symbol
*label_symbol
;
97 struct expression_list
*expr_list
;
99 struct ident
*expr_ident
;
101 struct /* index_expr */ {
102 unsigned int idx_from
, idx_to
;
105 struct /* initpos_expr */ {
106 unsigned int init_offset
;
107 struct symbol
*init_sym
;
108 struct expression
*init_expr
;
113 /* Constant expression values */
114 long long get_expression_value(struct expression
*);
116 /* Expression parsing */
117 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
118 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
119 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
120 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
121 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
123 extern void check_duplicates(struct symbol
*sym
);
124 extern struct symbol
*evaluate_symbol(struct symbol
*sym
);
125 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
126 extern struct symbol
*evaluate_expression(struct expression
*);
128 static inline struct expression
*alloc_expression(struct position pos
, int type
)
130 struct expression
*expr
= __alloc_expression(0);
136 /* Type name parsing */
137 struct token
*typename(struct token
*, struct symbol
**);
139 static inline int lookup_type(struct token
*token
)
141 if (token
->pos
.type
== TOKEN_IDENT
)
142 return lookup_symbol(token
->ident
, NS_TYPEDEF
) != NULL
;
146 /* Statement parsing */
147 struct statement
*alloc_statement(struct position pos
, int type
);
148 struct token
*initializer(struct expression
**tree
, struct token
*token
);
149 struct token
*compound_statement(struct token
*, struct statement
*);
151 /* The preprocessor calls this 'constant_expression()' */
152 #define constant_expression(token,tree) conditional_expression(token, tree)