sval: update smatch_helper.c
[smatch.git] / smatch_expressions.c
bloba5de4b887c000c45e1d0218faa9888ea31ce8672
1 #include "smatch.h"
3 static struct position pos;
5 struct expression *zero_expr()
7 static struct expression *zero;
9 if (zero)
10 return zero;
12 zero = alloc_expression(pos, EXPR_VALUE);
13 zero->value = 0;
14 return zero;
17 struct expression *value_expr(long long val)
19 struct expression *expr;
21 if (!val)
22 return zero_expr();
24 expr = alloc_expression(pos, EXPR_VALUE);
25 expr->value = val;
26 return expr;
29 struct expression *deref_expression(struct expression *deref, int op, struct ident *member)
31 struct expression *expr;
33 expr = alloc_expression(pos, EXPR_DEREF);
34 expr->op = op;
35 expr->deref = deref;
36 expr->member = member;
37 return expr;
40 struct expression *assign_expression(struct expression *left, struct expression *right)
42 struct expression *expr;
44 expr = alloc_expression(right->pos, EXPR_ASSIGNMENT);
45 expr->op = '=';
46 expr->left = left;
47 expr->right = right;
48 return expr;
51 struct expression *symbol_expression(struct symbol *sym)
53 struct expression *expr;
55 expr = alloc_expression(sym->pos, EXPR_SYMBOL);
56 expr->symbol = sym;
57 expr->symbol_name = sym->ident;
58 return expr;