s390x: add the proper defines for data types
[smatch.git] / expression.h
blob80b3be5f526f7b788ff746f96ae233ceed8f50a9
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 Taint_comma = 1,
76 }; /* for expr->taint */
78 struct expression {
79 enum expression_type type:8;
80 unsigned flags:8;
81 int op;
82 struct position pos;
83 struct symbol *ctype;
84 union {
85 // EXPR_VALUE
86 struct {
87 unsigned long long value;
88 unsigned taint;
91 // EXPR_FVALUE
92 long double fvalue;
94 // EXPR_STRING
95 struct {
96 int wide;
97 struct string *string;
100 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
101 struct /* unop */ {
102 struct expression *unop;
103 unsigned long op_value;
106 // EXPR_SYMBOL, EXPR_TYPE
107 struct /* symbol_arg */ {
108 struct symbol *symbol;
109 struct ident *symbol_name;
112 // EXPR_STATEMENT
113 struct statement *statement;
115 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
116 struct /* binop_arg */ {
117 struct expression *left, *right;
119 // EXPR_DEREF
120 struct /* deref_arg */ {
121 struct expression *deref;
122 struct ident *member;
124 // EXPR_SLICE
125 struct /* slice */ {
126 struct expression *base;
127 unsigned r_bitpos, r_nrbits;
129 // EXPR_CAST and EXPR_SIZEOF
130 struct /* cast_arg */ {
131 struct symbol *cast_type;
132 struct expression *cast_expression;
134 // EXPR_CONDITIONAL
135 // EXPR_SELECT
136 struct /* conditional_expr */ {
137 struct expression *conditional, *cond_true, *cond_false;
139 // EXPR_CALL
140 struct /* call_expr */ {
141 struct expression *fn;
142 struct expression_list *args;
144 // EXPR_LABEL
145 struct /* label_expr */ {
146 struct symbol *label_symbol;
148 // EXPR_INITIALIZER
149 struct expression_list *expr_list;
150 // EXPR_IDENTIFIER
151 struct /* ident_expr */ {
152 int offset;
153 struct ident *expr_ident;
154 struct symbol *field;
155 struct expression *ident_expression;
157 // EXPR_INDEX
158 struct /* index_expr */ {
159 unsigned int idx_from, idx_to;
160 struct expression *idx_expression;
162 // EXPR_POS
163 struct /* initpos_expr */ {
164 unsigned int init_offset, init_nr;
165 struct expression *init_expr;
167 // EXPR_OFFSETOF
168 struct {
169 struct symbol *in;
170 struct expression *down;
171 union {
172 struct ident *ident;
173 struct expression *index;
179 /* Constant expression values */
180 int is_zero_constant(struct expression *);
181 long long get_expression_value(struct expression *);
182 long long const_expression_value(struct expression *);
183 long long get_expression_value_silent(struct expression *expr);
185 /* Expression parsing */
186 struct token *parse_expression(struct token *token, struct expression **tree);
187 struct token *conditional_expression(struct token *token, struct expression **tree);
188 struct token *primary_expression(struct token *token, struct expression **tree);
189 struct token *parens_expression(struct token *token, struct expression **expr, const char *where);
190 struct token *assignment_expression(struct token *token, struct expression **tree);
192 extern void evaluate_symbol_list(struct symbol_list *list);
193 extern struct symbol *evaluate_statement(struct statement *stmt);
194 extern struct symbol *evaluate_expression(struct expression *);
196 extern int expand_symbol(struct symbol *);
198 static inline struct expression *alloc_expression(struct position pos, int type)
200 struct expression *expr = __alloc_expression(0);
201 expr->type = type;
202 expr->pos = pos;
203 return expr;
206 static inline struct expression *alloc_const_expression(struct position pos, int value)
208 struct expression *expr = __alloc_expression(0);
209 expr->type = EXPR_VALUE;
210 expr->pos = pos;
211 expr->value = value;
212 expr->ctype = &int_ctype;
213 return expr;
216 /* Type name parsing */
217 struct token *typename(struct token *, struct symbol **, int *);
219 static inline int lookup_type(struct token *token)
221 if (token->pos.type == TOKEN_IDENT) {
222 struct symbol *sym = lookup_symbol(token->ident, NS_SYMBOL | NS_TYPEDEF);
223 return sym && (sym->namespace & NS_TYPEDEF);
225 return 0;
228 /* Statement parsing */
229 struct statement *alloc_statement(struct position pos, int type);
230 struct token *initializer(struct expression **tree, struct token *token);
231 struct token *compound_statement(struct token *, struct statement *);
233 /* The preprocessor calls this 'constant_expression()' */
234 #define constant_expression(token,tree) conditional_expression(token, tree)
236 /* Cast folding of constant values.. */
237 void cast_value(struct expression *expr, struct symbol *newtype,
238 struct expression *old, struct symbol *oldtype);
240 #endif