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(void)
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
;
55 expr
->member_offset
= -1;
59 struct expression
*deref_expression(struct expression
*expr
)
61 struct expression
*preop
;
63 preop
= alloc_expression(expr
->pos
, EXPR_PREOP
);
69 struct expression
*assign_expression(struct expression
*left
, struct expression
*right
)
71 struct expression
*expr
;
73 expr
= alloc_expression(right
->pos
, EXPR_ASSIGNMENT
);
80 struct expression
*binop_expression(struct expression
*left
, int op
, struct expression
*right
)
82 struct expression
*expr
;
84 expr
= alloc_expression(right
->pos
, EXPR_BINOP
);
91 struct expression
*array_element_expression(struct expression
*array
, struct expression
*offset
)
93 struct expression
*expr
;
95 expr
= binop_expression(array
, '+', offset
);
96 return deref_expression(expr
);
99 struct expression
*symbol_expression(struct symbol
*sym
)
101 struct expression
*expr
;
103 expr
= alloc_expression(sym
->pos
, EXPR_SYMBOL
);
105 expr
->symbol_name
= sym
->ident
;
109 struct expression
*compare_expression(struct expression
*left
, int op
, struct expression
*right
)
111 struct expression
*expr
;
113 expr
= alloc_expression(get_cur_pos(), EXPR_COMPARE
);
120 struct expression
*gen_expression_from_key(struct expression
*arg
, const char *key
)
122 struct expression
*ret
= NULL
;
123 struct token
*token
, *end
;
129 /* The idea is that we can parse either $0->foo or $->foo */
133 while (*p
>= '0' && *p
<= '9')
135 len
= snprintf(buf
, sizeof(buf
), "%s\n", p
);
136 alloc
= alloc_string(buf
);
138 token
= tokenize_buffer(alloc
, len
, &end
);
141 if (token_type(token
) != TOKEN_STREAMBEGIN
)
146 while (token_type(token
) == TOKEN_SPECIAL
&&
147 token
->special
== SPECIAL_DEREFERENCE
) {
149 if (token_type(token
) != TOKEN_IDENT
) {
153 ret
= deref_expression(ret
);
154 ret
= member_expression(ret
, '*', token
->ident
);
158 if (token_type(token
) != TOKEN_STREAMEND
)