Start doing type evaluation for binops - integer promotion rules
[smatch.git] / expression.h
blob83dbc6a86d2c8bb619d86f14e1b95fb75a6c64b2
1 #ifndef EXPRESSION_H
2 #define EXPRESSION_H
3 /*
4 * sparse/expression.h
6 * Copyright (C) 2003 Linus Torvalds, all rights reserved
8 * Declarations and helper functions for expression parsing.
9 */
11 enum expression_type {
12 EXPR_CONSTANT,
13 EXPR_VALUE,
14 EXPR_SYMBOL,
15 EXPR_BINOP,
16 EXPR_DEREF,
17 EXPR_PREOP,
18 EXPR_POSTOP,
19 EXPR_CAST,
20 EXPR_SIZEOF,
21 EXPR_CONDITIONAL,
22 EXPR_STATEMENT,
23 EXPR_CALL,
26 struct expression {
27 int type, op;
28 struct token *token;
29 struct symbol *ctype;
30 union {
31 long long value;
32 struct expression *unop;
33 struct statement *statement;
34 struct symbol *symbol;
35 struct binop_arg {
36 struct expression *left, *right;
38 struct deref_arg {
39 struct expression *deref;
40 struct token *member;
42 struct cast_arg {
43 struct symbol *cast_type;
44 struct expression *cast_expression;
46 struct conditional_expr {
47 struct expression *conditional, *cond_true, *cond_false;
49 struct statement_struct {
50 struct symbol_list *syms;
51 struct statement_list *stmts;
56 /* Constant expression values */
57 long long get_expression_value(struct expression *);
59 /* Expression parsing */
60 struct token *parse_expression(struct token *token, struct expression **tree);
61 struct token *conditional_expression(struct token *token, struct expression **tree);
62 struct token *primary_expression(struct token *token, struct expression **tree);
63 struct token *parens_expression(struct token *token, struct expression **expr, const char *where);
64 struct token *assignment_expression(struct token *token, struct expression **tree);
66 extern int evaluate_expression(struct expression *);
68 static inline struct expression *alloc_expression(struct token *token, int type)
70 struct expression *expr = __alloc_expression(0);
71 expr->type = type;
72 expr->token = token;
73 return expr;
76 /* Type name parsing */
77 struct token *typename(struct token *, struct symbol **);
79 static inline int lookup_type(struct token *token)
81 if (token->type == TOKEN_IDENT)
82 return lookup_symbol(token->ident, NS_TYPEDEF) != NULL;
83 return 0;
86 /* Statement parsing */
87 struct statement *alloc_statement(struct token * token, int type);
88 struct token *initializer(struct token *token, struct ctype *type);
89 struct token *compound_statement(struct token *, struct statement *);
91 /* The preprocessor calls this 'constant_expression()' */
92 #define constant_expression(token,tree) conditional_expression(token, tree)
94 #endif