db: remove bogus parameter information from hook type functions
[smatch.git] / expression.h
blob58a013c40152dee605fc7ceba835af56ca40dc4c
1 #ifndef EXPRESSION_H
2 #define EXPRESSION_H
3 /*
4 * sparse/expression.h
6 * Copyright (C) 2003 Transmeta Corp.
7 * 2003 Linus Torvalds
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
27 * Declarations and helper functions for expression parsing.
30 #include "allocate.h"
31 #include "lib.h"
32 #include "symbol.h"
34 struct expression_list;
36 enum expression_type {
37 EXPR_VALUE = 1,
38 EXPR_STRING,
39 EXPR_SYMBOL,
40 EXPR_TYPE,
41 EXPR_BINOP,
42 EXPR_ASSIGNMENT,
43 EXPR_LOGICAL,
44 EXPR_DEREF,
45 EXPR_PREOP,
46 EXPR_POSTOP,
47 EXPR_CAST,
48 EXPR_FORCE_CAST,
49 EXPR_IMPLIED_CAST,
50 EXPR_SIZEOF,
51 EXPR_ALIGNOF,
52 EXPR_PTRSIZEOF,
53 EXPR_CONDITIONAL,
54 EXPR_SELECT, // a "safe" conditional expression
55 EXPR_STATEMENT,
56 EXPR_CALL,
57 EXPR_COMMA,
58 EXPR_COMPARE,
59 EXPR_LABEL,
60 EXPR_INITIALIZER, // initializer list
61 EXPR_IDENTIFIER, // identifier in initializer
62 EXPR_INDEX, // index in initializer
63 EXPR_POS, // position in initializer
64 EXPR_FVALUE,
65 EXPR_SLICE,
66 EXPR_OFFSETOF,
69 enum {
70 Int_const_expr = 1,
71 Float_literal = 2,
72 }; /* for expr->flags */
74 enum {
75 Handled = 1,
76 }; /* for expr->flags */
78 enum {
79 Taint_comma = 1,
80 }; /* for expr->taint */
82 struct expression {
83 enum expression_type type:8;
84 unsigned flags:8;
85 unsigned smatch_flags:16;
86 int op;
87 struct position pos;
88 struct symbol *ctype;
89 union {
90 // EXPR_VALUE
91 struct {
92 unsigned long long value;
93 unsigned taint;
96 // EXPR_FVALUE
97 long double fvalue;
99 // EXPR_STRING
100 struct {
101 int wide;
102 struct string *string;
105 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
106 struct /* unop */ {
107 struct expression *unop;
108 unsigned long op_value;
111 // EXPR_SYMBOL, EXPR_TYPE
112 struct /* symbol_arg */ {
113 struct symbol *symbol;
114 struct ident *symbol_name;
117 // EXPR_STATEMENT
118 struct statement *statement;
120 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
121 struct /* binop_arg */ {
122 struct expression *left, *right;
124 // EXPR_DEREF
125 struct /* deref_arg */ {
126 struct expression *deref;
127 struct ident *member;
129 // EXPR_SLICE
130 struct /* slice */ {
131 struct expression *base;
132 unsigned r_bitpos, r_nrbits;
134 // EXPR_CAST and EXPR_SIZEOF
135 struct /* cast_arg */ {
136 struct symbol *cast_type;
137 struct expression *cast_expression;
139 // EXPR_CONDITIONAL
140 // EXPR_SELECT
141 struct /* conditional_expr */ {
142 struct expression *conditional, *cond_true, *cond_false;
144 // EXPR_CALL
145 struct /* call_expr */ {
146 struct expression *fn;
147 struct expression_list *args;
149 // EXPR_LABEL
150 struct /* label_expr */ {
151 struct symbol *label_symbol;
153 // EXPR_INITIALIZER
154 struct expression_list *expr_list;
155 // EXPR_IDENTIFIER
156 struct /* ident_expr */ {
157 struct ident *expr_ident;
158 struct symbol *field;
159 struct expression *ident_expression;
161 // EXPR_INDEX
162 struct /* index_expr */ {
163 unsigned int idx_from, idx_to;
164 struct expression *idx_expression;
166 // EXPR_POS
167 struct /* initpos_expr */ {
168 unsigned int init_offset, init_nr;
169 struct expression *init_expr;
171 // EXPR_OFFSETOF
172 struct {
173 struct symbol *in;
174 struct expression *down;
175 union {
176 struct ident *ident;
177 struct expression *index;
183 /* Constant expression values */
184 int is_zero_constant(struct expression *);
185 long long get_expression_value(struct expression *);
186 long long const_expression_value(struct expression *);
187 long long get_expression_value_silent(struct expression *expr);
189 /* Expression parsing */
190 struct token *parse_expression(struct token *token, struct expression **tree);
191 struct token *conditional_expression(struct token *token, struct expression **tree);
192 struct token *primary_expression(struct token *token, struct expression **tree);
193 struct token *parens_expression(struct token *token, struct expression **expr, const char *where);
194 struct token *assignment_expression(struct token *token, struct expression **tree);
196 extern void evaluate_symbol_list(struct symbol_list *list);
197 extern struct symbol *evaluate_statement(struct statement *stmt);
198 extern struct symbol *evaluate_expression(struct expression *);
200 extern int expand_symbol(struct symbol *);
202 static inline struct expression *alloc_expression(struct position pos, int type)
204 struct expression *expr = __alloc_expression(0);
205 expr->type = type;
206 expr->pos = pos;
207 return expr;
210 static inline struct expression *alloc_const_expression(struct position pos, int value)
212 struct expression *expr = __alloc_expression(0);
213 expr->type = EXPR_VALUE;
214 expr->pos = pos;
215 expr->value = value;
216 expr->ctype = &int_ctype;
217 return expr;
220 /* Type name parsing */
221 struct token *typename(struct token *, struct symbol **, int *);
223 static inline int lookup_type(struct token *token)
225 if (token->pos.type == TOKEN_IDENT) {
226 struct symbol *sym = lookup_symbol(token->ident, NS_SYMBOL | NS_TYPEDEF);
227 return sym && (sym->namespace & NS_TYPEDEF);
229 return 0;
232 /* Statement parsing */
233 struct statement *alloc_statement(struct position pos, int type);
234 struct token *initializer(struct expression **tree, struct token *token);
235 struct token *compound_statement(struct token *, struct statement *);
237 /* The preprocessor calls this 'constant_expression()' */
238 #define constant_expression(token,tree) conditional_expression(token, tree)
240 /* Cast folding of constant values.. */
241 void cast_value(struct expression *expr, struct symbol *newtype,
242 struct expression *old, struct symbol *oldtype);
244 #endif