[PATCH] line-splicing fixes in sparse
[smatch.git] / expression.h
blobe05fb59ea7a76d54bb752fba7c88e232ee15edf7
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 struct expression_list;
16 enum expression_type {
17 EXPR_VALUE,
18 EXPR_STRING,
19 EXPR_SYMBOL,
20 EXPR_TYPE,
21 EXPR_BINOP,
22 EXPR_ASSIGNMENT,
23 EXPR_LOGICAL,
24 EXPR_DEREF,
25 EXPR_PREOP,
26 EXPR_POSTOP,
27 EXPR_CAST,
28 EXPR_SIZEOF,
29 EXPR_CONDITIONAL,
30 EXPR_STATEMENT,
31 EXPR_CALL,
32 EXPR_COMMA,
33 EXPR_COMPARE,
34 EXPR_BITFIELD,
35 EXPR_LABEL,
36 EXPR_INITIALIZER, // initializer list
37 EXPR_IDENTIFIER, // identifier in initializer
38 EXPR_INDEX, // index in initializer
39 EXPR_POS, // position in initializer
42 struct expression {
43 enum expression_type type;
44 int op;
45 struct position pos;
46 struct symbol *ctype;
47 union {
48 // EXPR_VALUE
49 unsigned long long value;
51 // EXPR_STRING
52 struct string *string;
54 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
55 struct expression *unop;
57 // EXPR_SYMBOL, EXPR_TYPE
58 struct /* symbol_arg */ {
59 struct symbol *symbol;
60 struct ident *symbol_name;
63 // EXPR_STATEMENT
64 struct statement *statement;
66 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
67 struct /* binop_arg */ {
68 struct expression *left, *right;
70 // EXPR_DEREF
71 struct /* deref_arg */ {
72 struct expression *deref;
73 struct ident *member;
75 // EXPR_CAST and EXPR_SIZEOF
76 struct /* cast_arg */ {
77 struct symbol *cast_type;
78 struct expression *cast_expression;
80 // EXPR_CONDITIONAL
81 struct /* conditional_expr */ {
82 struct expression *conditional, *cond_true, *cond_false;
84 // EXPR_CALL
85 struct /* call_expr */ {
86 struct expression *fn;
87 struct expression_list *args;
89 // EXPR_BITFIELD
90 struct /* bitfield_expr */ {
91 unsigned char bitpos, nrbits;
92 struct expression *address;
94 // EXPR_LABEL
95 struct /* label_expr */ {
96 struct symbol *label_symbol;
98 // EXPR_INITIALIZER
99 struct expression_list *expr_list;
100 // EXPR_IDENTIFIER
101 struct ident *expr_ident;
102 // EXPR_INDEX
103 struct /* index_expr */ {
104 unsigned int idx_from, idx_to;
106 // EXPR_POS
107 struct /* initpos_expr */ {
108 unsigned int init_offset;
109 struct symbol *init_sym;
110 struct expression *init_expr;
115 /* Constant expression values */
116 long long get_expression_value(struct expression *);
118 /* Expression parsing */
119 struct token *parse_expression(struct token *token, struct expression **tree);
120 struct token *conditional_expression(struct token *token, struct expression **tree);
121 struct token *primary_expression(struct token *token, struct expression **tree);
122 struct token *parens_expression(struct token *token, struct expression **expr, const char *where);
123 struct token *assignment_expression(struct token *token, struct expression **tree);
125 extern void check_duplicates(struct symbol *sym);
126 extern struct symbol *evaluate_symbol(struct symbol *sym);
127 extern struct symbol *evaluate_statement(struct statement *stmt);
128 extern struct symbol *evaluate_expression(struct expression *);
130 extern void expand_symbol(struct symbol *);
132 static inline struct expression *alloc_expression(struct position pos, int type)
134 struct expression *expr = __alloc_expression(0);
135 expr->type = type;
136 expr->pos = pos;
137 return expr;
140 static inline struct expression *alloc_const_expression(struct position pos, int value)
142 struct expression *expr = __alloc_expression(0);
143 expr->type = EXPR_VALUE;
144 expr->pos = pos;
145 expr->value = value;
146 expr->ctype = &int_ctype;
147 return expr;
150 /* Type name parsing */
151 struct token *typename(struct token *, struct symbol **);
153 static inline int lookup_type(struct token *token)
155 if (token->pos.type == TOKEN_IDENT) {
156 struct symbol *sym = lookup_symbol(token->ident, NS_SYMBOL | NS_TYPEDEF);
157 return sym && sym->namespace == NS_TYPEDEF;
159 return 0;
162 /* Statement parsing */
163 struct statement *alloc_statement(struct position pos, int type);
164 struct token *initializer(struct expression **tree, struct token *token);
165 struct token *compound_statement(struct token *, struct statement *);
167 /* The preprocessor calls this 'constant_expression()' */
168 #define constant_expression(token,tree) conditional_expression(token, tree)
170 /* Cast folding of constant values.. */
171 void cast_value(struct expression *expr, struct symbol *newtype,
172 struct expression *old, struct symbol *oldtype);
174 #endif