Oops. Move type definition to top of function, instead of
[smatch.git] / expression.h
blob16621d29af46d15d9c9c8395c37689372048a70a
1 #ifndef EXPRESSION_H
2 #define EXPRESSION_H
3 /*
4 * sparse/expression.h
6 * Copyright (C) 2003 Transmeta Corp, all rights reserved.
8 * Declarations and helper functions for expression parsing.
9 */
11 struct expression_list;
13 enum expression_type {
14 EXPR_VALUE,
15 EXPR_STRING,
16 EXPR_SYMBOL,
17 EXPR_BINOP,
18 EXPR_ASSIGNMENT,
19 EXPR_DEREF,
20 EXPR_PREOP,
21 EXPR_POSTOP,
22 EXPR_CAST,
23 EXPR_SIZEOF,
24 EXPR_CONDITIONAL,
25 EXPR_STATEMENT,
26 EXPR_CALL,
27 EXPR_COMMA,
28 EXPR_COMPARE,
29 EXPR_BITFIELD,
30 EXPR_INITIALIZER, // initializer list
31 EXPR_IDENTIFIER, // identifier in initializer
32 EXPR_INDEX, // index in initializer
35 struct expression {
36 enum expression_type type;
37 int op;
38 struct position pos;
39 struct symbol *ctype;
40 union {
41 // EXPR_VALUE
42 unsigned long long value;
44 // EXPR_STRING
45 struct string *string;
47 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
48 struct expression *unop;
50 // EXPR_SYMBOL
51 struct symbol_arg {
52 struct symbol *symbol;
53 struct ident *symbol_name;
56 // EXPR_STATEMENT
57 struct statement *statement;
59 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE and EXPR_ASSIGNMENT
60 struct binop_arg {
61 struct expression *left, *right;
63 // EXPR_DEREF
64 struct deref_arg {
65 struct expression *deref;
66 struct ident *member;
68 // EXPR_CAST and EXPR_SIZEOF
69 struct cast_arg {
70 struct symbol *cast_type;
71 struct expression *cast_expression;
73 // EXPR_CONDITIONAL
74 struct conditional_expr {
75 struct expression *conditional, *cond_true, *cond_false;
77 // EXPR_CALL
78 struct call_expr {
79 struct expression *fn;
80 struct expression_list *args;
82 // EXPR_BITFIELD
83 struct bitfield_expr {
84 unsigned char bitpos, nrbits;
85 struct expression *address;
87 // EXPR_INITIALIZER
88 struct expression_list *expr_list;
89 // EXPR_IDENTIFIER
90 struct ident *expr_ident;
91 // EXPR_INDEX
92 struct index_expr {
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);
116 expr->type = type;
117 expr->pos = pos;
118 return expr;
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;
128 return 0;
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)
142 #endif