Clean up silliness.
[smatch.git] / expression.h
blob8c6c6079c7ccec3988a2a822c366488fad8c4e8c
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_LOGICAL,
20 EXPR_DEREF,
21 EXPR_PREOP,
22 EXPR_POSTOP,
23 EXPR_CAST,
24 EXPR_SIZEOF,
25 EXPR_CONDITIONAL,
26 EXPR_STATEMENT,
27 EXPR_CALL,
28 EXPR_COMMA,
29 EXPR_COMPARE,
30 EXPR_BITFIELD,
31 EXPR_INITIALIZER, // initializer list
32 EXPR_IDENTIFIER, // identifier in initializer
33 EXPR_INDEX, // index in initializer
36 struct expression {
37 enum expression_type type;
38 int op;
39 struct position pos;
40 struct symbol *ctype;
41 union {
42 // EXPR_VALUE
43 unsigned long long value;
45 // EXPR_STRING
46 struct string *string;
48 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
49 struct expression *unop;
51 // EXPR_SYMBOL
52 struct symbol_arg {
53 struct symbol *symbol;
54 struct ident *symbol_name;
57 // EXPR_STATEMENT
58 struct statement *statement;
60 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
61 struct binop_arg {
62 struct expression *left, *right;
64 // EXPR_DEREF
65 struct deref_arg {
66 struct expression *deref;
67 struct ident *member;
69 // EXPR_CAST and EXPR_SIZEOF
70 struct cast_arg {
71 struct symbol *cast_type;
72 struct expression *cast_expression;
74 // EXPR_CONDITIONAL
75 struct conditional_expr {
76 struct expression *conditional, *cond_true, *cond_false;
78 // EXPR_CALL
79 struct call_expr {
80 struct expression *fn;
81 struct expression_list *args;
83 // EXPR_BITFIELD
84 struct bitfield_expr {
85 unsigned char bitpos, nrbits;
86 struct expression *address;
88 // EXPR_INITIALIZER
89 struct expression_list *expr_list;
90 // EXPR_IDENTIFIER
91 struct ident *expr_ident;
92 // EXPR_INDEX
93 struct index_expr {
94 unsigned int idx_from, idx_to;
99 /* Constant expression values */
100 long long get_expression_value(struct expression *);
102 /* Expression parsing */
103 struct token *parse_expression(struct token *token, struct expression **tree);
104 struct token *conditional_expression(struct token *token, struct expression **tree);
105 struct token *primary_expression(struct token *token, struct expression **tree);
106 struct token *parens_expression(struct token *token, struct expression **expr, const char *where);
107 struct token *assignment_expression(struct token *token, struct expression **tree);
109 extern struct symbol *evaluate_symbol(struct symbol *sym);
110 extern struct symbol *evaluate_statement(struct statement *stmt);
111 extern struct symbol *evaluate_expression(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 /* The preprocessor calls this 'constant_expression()' */
137 #define constant_expression(token,tree) conditional_expression(token, tree)
139 #endif