3 static struct position
get_cur_pos(void)
5 static struct position pos
;
6 static struct position none
;
7 struct expression
*expr
;
8 struct statement
*stmt
;
10 expr
= last_ptr_list((struct ptr_list
*)big_expression_stack
);
11 stmt
= last_ptr_list((struct ptr_list
*)big_statement_stack
);
21 struct expression
*zero_expr()
23 static struct expression
*zero
;
28 zero
= alloc_expression(get_cur_pos(), EXPR_VALUE
);
30 zero
->ctype
= &char_ctype
;
34 struct expression
*value_expr(long long val
)
36 struct expression
*expr
;
41 expr
= alloc_expression(get_cur_pos(), EXPR_VALUE
);
43 expr
->ctype
= &llong_ctype
;
47 struct expression
*member_expression(struct expression
*deref
, int op
, struct ident
*member
)
49 struct expression
*expr
;
51 expr
= alloc_expression(deref
->pos
, EXPR_DEREF
);
54 expr
->member
= member
;
58 struct expression
*deref_expression(struct expression
*expr
)
60 struct expression
*preop
;
62 preop
= alloc_expression(expr
->pos
, EXPR_PREOP
);
68 struct expression
*assign_expression(struct expression
*left
, struct expression
*right
)
70 struct expression
*expr
;
72 expr
= alloc_expression(right
->pos
, EXPR_ASSIGNMENT
);
79 struct expression
*binop_expression(struct expression
*left
, int op
, struct expression
*right
)
81 struct expression
*expr
;
83 expr
= alloc_expression(right
->pos
, EXPR_BINOP
);
90 struct expression
*array_element_expression(struct expression
*array
, struct expression
*offset
)
92 struct expression
*expr
;
94 expr
= binop_expression(array
, '+', offset
);
95 return deref_expression(expr
);
98 struct expression
*symbol_expression(struct symbol
*sym
)
100 struct expression
*expr
;
102 expr
= alloc_expression(sym
->pos
, EXPR_SYMBOL
);
104 expr
->symbol_name
= sym
->ident
;
108 #define FAKE_NAME "smatch_fake"
109 struct ident unknown_value
= {
110 .len
= sizeof(FAKE_NAME
),
114 static int fake_counter
;
115 static struct ident
*fake_ident()
121 snprintf(buf
, sizeof(buf
), "smatch_fake_%d", fake_counter
++);
122 len
= strlen(buf
) + 1;
123 ret
= malloc(sizeof(*ret
) + len
);
124 memset(ret
, 0, sizeof(*ret
));
125 memcpy(ret
->name
, buf
, len
);
131 struct expression
*unknown_value_expression(struct expression
*expr
)
133 struct expression
*ret
;
136 type
= get_type(expr
);
137 if (!type
|| type
->type
!= SYM_BASETYPE
)
140 ret
= alloc_expression(expr
->pos
, EXPR_SYMBOL
);
141 ret
->symbol
= alloc_symbol(expr
->pos
, SYM_BASETYPE
);
142 ret
->symbol
->ctype
.base_type
= type
;
143 ret
->symbol_name
= fake_ident();