Add test-suite comment to bad-array-designated-initializer.c
[smatch.git] / expression.h
bloba91315321676b9d76fb7441f7612cdb3e62f3599
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,
47 EXPR_OFFSETOF,
50 enum {
51 Int_const_expr = 1,
52 Float_literal = 2,
53 }; /* for expr->flags */
55 struct expression {
56 enum expression_type type:8;
57 unsigned flags:8;
58 int op;
59 struct position pos;
60 struct symbol *ctype;
61 union {
62 // EXPR_VALUE
63 unsigned long long value;
65 // EXPR_FVALUE
66 long double fvalue;
68 // EXPR_STRING
69 struct string *string;
71 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
72 struct /* unop */ {
73 struct expression *unop;
74 unsigned long op_value;
77 // EXPR_SYMBOL, EXPR_TYPE
78 struct /* symbol_arg */ {
79 struct symbol *symbol;
80 struct ident *symbol_name;
83 // EXPR_STATEMENT
84 struct statement *statement;
86 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
87 struct /* binop_arg */ {
88 struct expression *left, *right;
90 // EXPR_DEREF
91 struct /* deref_arg */ {
92 struct expression *deref;
93 struct ident *member;
95 // EXPR_SLICE
96 struct /* slice */ {
97 struct expression *base;
98 unsigned r_bitpos, r_nrbits;
100 // EXPR_CAST and EXPR_SIZEOF
101 struct /* cast_arg */ {
102 struct symbol *cast_type;
103 struct expression *cast_expression;
105 // EXPR_CONDITIONAL
106 // EXPR_SELECT
107 struct /* conditional_expr */ {
108 struct expression *conditional, *cond_true, *cond_false;
110 // EXPR_CALL
111 struct /* call_expr */ {
112 struct expression *fn;
113 struct expression_list *args;
115 // EXPR_LABEL
116 struct /* label_expr */ {
117 struct symbol *label_symbol;
119 // EXPR_INITIALIZER
120 struct expression_list *expr_list;
121 // EXPR_IDENTIFIER
122 struct /* ident_expr */ {
123 struct ident *expr_ident;
124 struct symbol *field;
125 struct expression *ident_expression;
127 // EXPR_INDEX
128 struct /* index_expr */ {
129 unsigned int idx_from, idx_to;
130 struct expression *idx_expression;
132 // EXPR_POS
133 struct /* initpos_expr */ {
134 unsigned int init_offset, init_nr;
135 struct expression *init_expr;
137 // EXPR_OFFSETOF
138 struct {
139 struct symbol *in;
140 struct expression *down;
141 union {
142 struct ident *ident;
143 struct expression *index;
149 /* Constant expression values */
150 long long get_expression_value(struct expression *);
151 long long const_expression_value(struct expression *);
153 /* Expression parsing */
154 struct token *parse_expression(struct token *token, struct expression **tree);
155 struct token *conditional_expression(struct token *token, struct expression **tree);
156 struct token *primary_expression(struct token *token, struct expression **tree);
157 struct token *parens_expression(struct token *token, struct expression **expr, const char *where);
158 struct token *assignment_expression(struct token *token, struct expression **tree);
160 extern void evaluate_symbol_list(struct symbol_list *list);
161 extern struct symbol *evaluate_statement(struct statement *stmt);
162 extern struct symbol *evaluate_expression(struct expression *);
164 extern int expand_symbol(struct symbol *);
166 static inline struct expression *alloc_expression(struct position pos, int type)
168 struct expression *expr = __alloc_expression(0);
169 expr->type = type;
170 expr->pos = pos;
171 return expr;
174 static inline struct expression *alloc_const_expression(struct position pos, int value)
176 struct expression *expr = __alloc_expression(0);
177 expr->type = EXPR_VALUE;
178 expr->pos = pos;
179 expr->value = value;
180 expr->ctype = &int_ctype;
181 return expr;
184 /* Type name parsing */
185 struct token *typename(struct token *, struct symbol **);
187 static inline int lookup_type(struct token *token)
189 if (token->pos.type == TOKEN_IDENT) {
190 struct symbol *sym = lookup_symbol(token->ident, NS_SYMBOL | NS_TYPEDEF);
191 return sym && sym->namespace == NS_TYPEDEF;
193 return 0;
196 /* Statement parsing */
197 struct statement *alloc_statement(struct position pos, int type);
198 struct token *initializer(struct expression **tree, struct token *token);
199 struct token *compound_statement(struct token *, struct statement *);
201 /* The preprocessor calls this 'constant_expression()' */
202 #define constant_expression(token,tree) conditional_expression(token, tree)
204 /* Cast folding of constant values.. */
205 void cast_value(struct expression *expr, struct symbol *newtype,
206 struct expression *old, struct symbol *oldtype);
208 #endif