Oops. The argument symbol initializers got lost on inlining,
[smatch.git] / expression.h
blob8a5ea3b59477d51728ad32c85ebbacffa4408d27
1 #ifndef EXPRESSION_H
2 #define EXPRESSION_H
3 /*
4 * sparse/expression.h
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 {
16 EXPR_VALUE,
17 EXPR_STRING,
18 EXPR_SYMBOL,
19 EXPR_BINOP,
20 EXPR_ASSIGNMENT,
21 EXPR_LOGICAL,
22 EXPR_DEREF,
23 EXPR_PREOP,
24 EXPR_POSTOP,
25 EXPR_CAST,
26 EXPR_SIZEOF,
27 EXPR_CONDITIONAL,
28 EXPR_STATEMENT,
29 EXPR_CALL,
30 EXPR_COMMA,
31 EXPR_COMPARE,
32 EXPR_BITFIELD,
33 EXPR_LABEL,
34 EXPR_INITIALIZER, // initializer list
35 EXPR_IDENTIFIER, // identifier in initializer
36 EXPR_INDEX, // index in initializer
37 EXPR_POS, // position in initializer
40 struct expression {
41 enum expression_type type;
42 int op;
43 struct position pos;
44 struct symbol *ctype;
45 union {
46 // EXPR_VALUE
47 unsigned long long value;
49 // EXPR_STRING
50 struct string *string;
52 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
53 struct expression *unop;
55 // EXPR_SYMBOL
56 struct /* symbol_arg */ {
57 struct symbol *symbol;
58 struct ident *symbol_name;
61 // EXPR_STATEMENT
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;
68 // EXPR_DEREF
69 struct /* deref_arg */ {
70 struct expression *deref;
71 struct ident *member;
73 // EXPR_CAST and EXPR_SIZEOF
74 struct /* cast_arg */ {
75 struct symbol *cast_type;
76 struct expression *cast_expression;
78 // EXPR_CONDITIONAL
79 struct /* conditional_expr */ {
80 struct expression *conditional, *cond_true, *cond_false;
82 // EXPR_CALL
83 struct /* call_expr */ {
84 struct expression *fn;
85 struct expression_list *args;
87 // EXPR_BITFIELD
88 struct /* bitfield_expr */ {
89 unsigned char bitpos, nrbits;
90 struct expression *address;
92 // EXPR_LABEL
93 struct /* label_expr */ {
94 struct symbol *label_symbol;
96 // EXPR_INITIALIZER
97 struct expression_list *expr_list;
98 // EXPR_IDENTIFIER
99 struct ident *expr_ident;
100 // EXPR_INDEX
101 struct /* index_expr */ {
102 unsigned int idx_from, idx_to;
104 // EXPR_POS
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);
131 expr->type = type;
132 expr->pos = pos;
133 return expr;
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;
143 return 0;
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)
154 #endif