6 * Copyright (C) 2003 Transmeta Corp, all rights reserved.
8 * Declarations and helper functions for expression parsing.
11 struct expression_list
;
13 enum expression_type
{
30 EXPR_INITIALIZER
, // initializer list
31 EXPR_IDENTIFIER
, // identifier in initializer
32 EXPR_INDEX
, // index in initializer
36 enum expression_type type
;
42 unsigned long long value
;
45 struct string
*string
;
47 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
48 struct expression
*unop
;
52 struct symbol
*symbol
;
53 struct ident
*symbol_name
;
57 struct statement
*statement
;
59 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE and EXPR_ASSIGNMENT
61 struct expression
*left
, *right
;
65 struct expression
*deref
;
68 // EXPR_CAST and EXPR_SIZEOF
70 struct symbol
*cast_type
;
71 struct expression
*cast_expression
;
74 struct conditional_expr
{
75 struct expression
*conditional
, *cond_true
, *cond_false
;
79 struct expression
*fn
;
80 struct expression_list
*args
;
83 struct bitfield_expr
{
84 unsigned char bitpos
, nrbits
;
85 struct expression
*address
;
88 struct expression_list
*expr_list
;
90 struct ident
*expr_ident
;
93 unsigned int idx_from
, idx_to
;
98 /* Constant expression values */
99 long long get_expression_value(struct expression
*);
101 /* Expression parsing */
102 struct token
*parse_expression(struct token
*token
, struct expression
**tree
);
103 struct token
*conditional_expression(struct token
*token
, struct expression
**tree
);
104 struct token
*primary_expression(struct token
*token
, struct expression
**tree
);
105 struct token
*parens_expression(struct token
*token
, struct expression
**expr
, const char *where
);
106 struct token
*assignment_expression(struct token
*token
, struct expression
**tree
);
108 extern struct symbol
*evaluate_symbol(struct symbol
*sym
);
109 extern struct symbol
*evaluate_statement(struct statement
*stmt
);
110 extern struct symbol
*evaluate_expression(struct expression
*);
111 extern struct symbol
*evaluate_initializer(struct symbol
*, struct expression
*);
113 static inline struct expression
*alloc_expression(struct position pos
, int type
)
115 struct expression
*expr
= __alloc_expression(0);
121 /* Type name parsing */
122 struct token
*typename(struct token
*, struct symbol
**);
124 static inline int lookup_type(struct token
*token
)
126 if (token
->pos
.type
== TOKEN_IDENT
)
127 return lookup_symbol(token
->ident
, NS_TYPEDEF
) != NULL
;
131 /* Statement parsing */
132 struct statement
*alloc_statement(struct position pos
, int type
);
133 struct token
*initializer(struct expression
**tree
, struct token
*token
);
134 struct token
*compound_statement(struct token
*, struct statement
*);
136 extern void clean_up_statement(struct statement
*stmt
, void *_parent
, int flags
);
137 extern void clean_up_symbol(struct symbol
*sym
, void *_parent
, int flags
);
139 /* The preprocessor calls this 'constant_expression()' */
140 #define constant_expression(token,tree) conditional_expression(token, tree)