validation/non-pointer-null.c: Make global static to avoid extraneous warning.
[smatch.git] / expression.h
blob1bf02c4aad382c7715d81c6522cc3b8ab073efa1
1 #ifndef EXPRESSION_H
2 #define EXPRESSION_H
3 /*
4 * sparse/expression.h
6 * Copyright (C) 2003 Transmeta Corp.
7 * 2003 Linus Torvalds
9 * Licensed under the Open Software License version 1.1
11 * Declarations and helper functions for expression parsing.
14 #include "allocate.h"
16 struct expression_list;
18 enum expression_type {
19 EXPR_VALUE = 1,
20 EXPR_STRING,
21 EXPR_SYMBOL,
22 EXPR_TYPE,
23 EXPR_BINOP,
24 EXPR_ASSIGNMENT,
25 EXPR_LOGICAL,
26 EXPR_DEREF,
27 EXPR_PREOP,
28 EXPR_POSTOP,
29 EXPR_CAST,
30 EXPR_IMPLIED_CAST,
31 EXPR_SIZEOF,
32 EXPR_ALIGNOF,
33 EXPR_PTRSIZEOF,
34 EXPR_CONDITIONAL,
35 EXPR_SELECT, // a "safe" conditional expression
36 EXPR_STATEMENT,
37 EXPR_CALL,
38 EXPR_COMMA,
39 EXPR_COMPARE,
40 EXPR_LABEL,
41 EXPR_INITIALIZER, // initializer list
42 EXPR_IDENTIFIER, // identifier in initializer
43 EXPR_INDEX, // index in initializer
44 EXPR_POS, // position in initializer
45 EXPR_FVALUE,
46 EXPR_SLICE,
49 struct expression {
50 enum expression_type type;
51 int op;
52 struct position pos;
53 struct symbol *ctype;
54 union {
55 // EXPR_VALUE
56 unsigned long long value;
58 // EXPR_FVALUE
59 long double fvalue;
61 // EXPR_STRING
62 struct string *string;
64 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
65 struct /* unop */ {
66 struct expression *unop;
67 unsigned long op_value;
70 // EXPR_SYMBOL, EXPR_TYPE
71 struct /* symbol_arg */ {
72 struct symbol *symbol;
73 struct ident *symbol_name;
76 // EXPR_STATEMENT
77 struct statement *statement;
79 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
80 struct /* binop_arg */ {
81 struct expression *left, *right;
83 // EXPR_DEREF
84 struct /* deref_arg */ {
85 struct expression *deref;
86 struct ident *member;
88 // EXPR_SLICE
89 struct /* slice */ {
90 struct expression *base;
91 unsigned r_bitpos, r_nrbits;
93 // EXPR_CAST and EXPR_SIZEOF
94 struct /* cast_arg */ {
95 struct symbol *cast_type;
96 struct expression *cast_expression;
98 // EXPR_CONDITIONAL
99 // EXPR_SELECT
100 struct /* conditional_expr */ {
101 struct expression *conditional, *cond_true, *cond_false;
103 // EXPR_CALL
104 struct /* call_expr */ {
105 struct expression *fn;
106 struct expression_list *args;
108 // EXPR_LABEL
109 struct /* label_expr */ {
110 struct symbol *label_symbol;
112 // EXPR_INITIALIZER
113 struct expression_list *expr_list;
114 // EXPR_IDENTIFIER
115 struct /* ident_expr */ {
116 struct ident *expr_ident;
117 struct symbol *field;
118 struct expression *ident_expression;
120 // EXPR_INDEX
121 struct /* index_expr */ {
122 unsigned int idx_from, idx_to;
123 struct expression *idx_expression;
125 // EXPR_POS
126 struct /* initpos_expr */ {
127 unsigned int init_offset, init_nr;
128 struct expression *init_expr;
133 /* Constant expression values */
134 long long get_expression_value(struct expression *);
136 /* Expression parsing */
137 struct token *parse_expression(struct token *token, struct expression **tree);
138 struct token *conditional_expression(struct token *token, struct expression **tree);
139 struct token *primary_expression(struct token *token, struct expression **tree);
140 struct token *parens_expression(struct token *token, struct expression **expr, const char *where);
141 struct token *assignment_expression(struct token *token, struct expression **tree);
143 extern void evaluate_symbol_list(struct symbol_list *list);
144 extern struct symbol *evaluate_statement(struct statement *stmt);
145 extern struct symbol *evaluate_expression(struct expression *);
147 extern int expand_symbol(struct symbol *);
149 static inline struct expression *alloc_expression(struct position pos, int type)
151 struct expression *expr = __alloc_expression(0);
152 expr->type = type;
153 expr->pos = pos;
154 return expr;
157 static inline struct expression *alloc_const_expression(struct position pos, int value)
159 struct expression *expr = __alloc_expression(0);
160 expr->type = EXPR_VALUE;
161 expr->pos = pos;
162 expr->value = value;
163 expr->ctype = &int_ctype;
164 return expr;
167 /* Type name parsing */
168 struct token *typename(struct token *, struct symbol **);
170 static inline int lookup_type(struct token *token)
172 if (token->pos.type == TOKEN_IDENT) {
173 struct symbol *sym = lookup_symbol(token->ident, NS_SYMBOL | NS_TYPEDEF);
174 return sym && sym->namespace == NS_TYPEDEF;
176 return 0;
179 /* Statement parsing */
180 struct statement *alloc_statement(struct position pos, int type);
181 struct token *initializer(struct expression **tree, struct token *token);
182 struct token *compound_statement(struct token *, struct statement *);
184 /* The preprocessor calls this 'constant_expression()' */
185 #define constant_expression(token,tree) conditional_expression(token, tree)
187 /* Cast folding of constant values.. */
188 void cast_value(struct expression *expr, struct symbol *newtype,
189 struct expression *old, struct symbol *oldtype);
191 #endif