Mark an inline symbol accessed when taking its address.
[smatch.git] / expression.h
blobd03cdc355ae02dd6559df3aff75e628bd41e2098
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_ALIGNOF,
30 EXPR_CONDITIONAL,
31 EXPR_SELECT, // a "safe" conditional expression
32 EXPR_STATEMENT,
33 EXPR_CALL,
34 EXPR_COMMA,
35 EXPR_COMPARE,
36 EXPR_BITFIELD,
37 EXPR_LABEL,
38 EXPR_INITIALIZER, // initializer list
39 EXPR_IDENTIFIER, // identifier in initializer
40 EXPR_INDEX, // index in initializer
41 EXPR_POS, // position in initializer
42 EXPR_FVALUE,
45 struct expression {
46 enum expression_type type;
47 int op;
48 struct position pos;
49 struct symbol *ctype;
50 union {
51 // EXPR_VALUE
52 unsigned long long value;
54 // EXPR_FVALUE
55 long double fvalue;
57 // EXPR_STRING
58 struct string *string;
60 // EXPR_UNOP, EXPR_PREOP and EXPR_POSTOP
61 struct expression *unop;
63 // EXPR_SYMBOL, EXPR_TYPE
64 struct /* symbol_arg */ {
65 struct symbol *symbol;
66 struct ident *symbol_name;
69 // EXPR_STATEMENT
70 struct statement *statement;
72 // EXPR_BINOP, EXPR_COMMA, EXPR_COMPARE, EXPR_LOGICAL and EXPR_ASSIGNMENT
73 struct /* binop_arg */ {
74 struct expression *left, *right;
76 // EXPR_DEREF
77 struct /* deref_arg */ {
78 struct expression *deref;
79 struct ident *member;
81 // EXPR_CAST and EXPR_SIZEOF
82 struct /* cast_arg */ {
83 struct symbol *cast_type;
84 struct expression *cast_expression;
86 // EXPR_CONDITIONAL
87 // EXPR_SELECT
88 struct /* conditional_expr */ {
89 struct expression *conditional, *cond_true, *cond_false;
91 // EXPR_CALL
92 struct /* call_expr */ {
93 struct expression *fn;
94 struct expression_list *args;
96 // EXPR_BITFIELD
97 struct /* bitfield_expr */ {
98 unsigned char bitpos, nrbits;
99 struct expression *address;
101 // EXPR_LABEL
102 struct /* label_expr */ {
103 struct symbol *label_symbol;
105 // EXPR_INITIALIZER
106 struct expression_list *expr_list;
107 // EXPR_IDENTIFIER
108 struct ident *expr_ident;
109 // EXPR_INDEX
110 struct /* index_expr */ {
111 unsigned int idx_from, idx_to;
113 // EXPR_POS
114 struct /* initpos_expr */ {
115 unsigned int init_offset;
116 struct symbol *init_sym;
117 struct expression *init_expr;
122 /* Constant expression values */
123 long long get_expression_value(struct expression *);
125 /* Expression parsing */
126 struct token *parse_expression(struct token *token, struct expression **tree);
127 struct token *conditional_expression(struct token *token, struct expression **tree);
128 struct token *primary_expression(struct token *token, struct expression **tree);
129 struct token *parens_expression(struct token *token, struct expression **expr, const char *where);
130 struct token *assignment_expression(struct token *token, struct expression **tree);
132 extern void check_duplicates(struct symbol *sym);
133 extern struct symbol *evaluate_symbol(struct symbol *sym);
134 extern struct symbol *evaluate_statement(struct statement *stmt);
135 extern struct symbol *evaluate_expression(struct expression *);
137 extern void expand_symbol(struct symbol *);
139 static inline struct expression *alloc_expression(struct position pos, int type)
141 struct expression *expr = __alloc_expression(0);
142 expr->type = type;
143 expr->pos = pos;
144 return expr;
147 static inline struct expression *alloc_const_expression(struct position pos, int value)
149 struct expression *expr = __alloc_expression(0);
150 expr->type = EXPR_VALUE;
151 expr->pos = pos;
152 expr->value = value;
153 expr->ctype = &int_ctype;
154 return expr;
157 /* Type name parsing */
158 struct token *typename(struct token *, struct symbol **);
160 static inline int lookup_type(struct token *token)
162 if (token->pos.type == TOKEN_IDENT) {
163 struct symbol *sym = lookup_symbol(token->ident, NS_SYMBOL | NS_TYPEDEF);
164 return sym && sym->namespace == NS_TYPEDEF;
166 return 0;
169 /* Statement parsing */
170 struct statement *alloc_statement(struct position pos, int type);
171 struct token *initializer(struct expression **tree, struct token *token);
172 struct token *compound_statement(struct token *, struct statement *);
174 /* The preprocessor calls this 'constant_expression()' */
175 #define constant_expression(token,tree) conditional_expression(token, tree)
177 /* Cast folding of constant values.. */
178 void cast_value(struct expression *expr, struct symbol *newtype,
179 struct expression *old, struct symbol *oldtype);
181 #endif