helper: handle assignments in expr_to_str()
[smatch.git] / smatch_db.c
blob2c21259456afa1a66431c5aa5653dd433574673f
1 /*
2 * smatch/smatch_db.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include <string.h>
11 #include <errno.h>
12 #include <sqlite3.h>
13 #include "smatch.h"
14 #include "smatch_slist.h"
15 #include "smatch_extra.h"
17 #define sql_insert(table, values...) \
18 do { \
19 if (option_info) { \
20 sm_prefix(); \
21 sm_printf("SQL: insert into " #table " values (" values); \
22 sm_printf(");\n"); \
23 } \
24 } while (0)
26 static sqlite3 *db;
28 struct def_callback {
29 int hook_type;
30 void (*callback)(const char *name, struct symbol *sym, char *key, char *value);
32 ALLOCATOR(def_callback, "definition db hook callbacks");
33 DECLARE_PTR_LIST(callback_list, struct def_callback);
34 static struct callback_list *callbacks;
36 struct member_info_callback {
37 int owner;
38 void (*callback)(char *fn, int static_flag, int param, char *printed_name, struct smatch_state *state);
40 ALLOCATOR(member_info_callback, "caller_info callbacks");
41 DECLARE_PTR_LIST(member_info_cb_list, struct member_info_callback);
42 static struct member_info_cb_list *member_callbacks;
44 struct returned_state_callback {
45 void (*callback)(int return_id, char *return_ranges, struct expression *return_expr, struct state_list *slist);
47 ALLOCATOR(returned_state_callback, "returned state callbacks");
48 DECLARE_PTR_LIST(returned_state_cb_list, struct returned_state_callback);
49 static struct returned_state_cb_list *returned_state_callbacks;
51 struct returned_member_callback {
52 int owner;
53 void (*callback)(int return_id, char *return_ranges, char *printed_name, struct smatch_state *state);
55 ALLOCATOR(returned_member_callback, "returned member callbacks");
56 DECLARE_PTR_LIST(returned_member_cb_list, struct returned_member_callback);
57 static struct returned_member_cb_list *returned_member_callbacks;
59 struct call_implies_callback {
60 int type;
61 void (*callback)(struct expression *arg, char *value);
63 ALLOCATOR(call_implies_callback, "call_implies callbacks");
64 DECLARE_PTR_LIST(call_implies_cb_list, struct call_implies_callback);
65 static struct call_implies_cb_list *call_implies_cb_list;
67 void sql_exec(int (*callback)(void*, int, char**, char**), const char *sql)
69 char *err = NULL;
70 int rc;
72 if (option_no_db || !db)
73 return;
75 rc = sqlite3_exec(db, sql, callback, 0, &err);
76 if (rc != SQLITE_OK) {
77 fprintf(stderr, "SQL error #2: %s\n", err);
78 fprintf(stderr, "SQL: '%s'\n", sql);
82 void sql_insert_return_states(int return_id, const char *return_ranges,
83 int type, int param, const char *key, const char *value)
85 sql_insert(return_states, "'%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s'",
86 get_filename(), get_function(), return_id, return_ranges,
87 fn_static(), type, param, key, value);
90 void sql_insert_caller_info(const char *fn, int static_flag, int type,
91 int param, const char *key, const char *value)
93 if (!option_info)
94 return;
96 sm_msg("SQL_caller_info: insert into caller_info values ("
97 "'%s', '%s', '%s', %%FUNC_ID%%, %d, %d, %d, '%s', '%s');",
98 get_filename(), get_function(), fn, static_flag, type, param,
99 key, value);
102 void sql_insert_function_ptr(const char *fn, const char *struct_name)
104 sql_insert(function_ptr, "'%s', '%s', '%s'", get_filename(), fn,
105 struct_name);
108 void sql_insert_return_values(const char *return_values)
110 sql_insert(return_values, "'%s', '%s', %d, '%s'", get_filename(),
111 get_function(), fn_static(), return_values);
114 void sql_insert_call_implies(int type, int param, int value)
116 sql_insert(call_implies, "'%s', '%s', %d, %d, %d, %d", get_filename(),
117 get_function(), fn_static(), type, param, value);
120 void sql_insert_type_size(const char *member, int size)
122 sql_insert(type_size, "'%s', '%s', %d", get_filename(), member, size);
125 void add_definition_db_callback(void (*callback)(const char *name, struct symbol *sym, char *key, char *value), int type)
127 struct def_callback *def_callback = __alloc_def_callback(0);
129 def_callback->hook_type = type;
130 def_callback->callback = callback;
131 add_ptr_list(&callbacks, def_callback);
135 * These call backs are used when the --info option is turned on to print struct
136 * member information. For example foo->bar could have a state in
137 * smatch_extra.c and also check_user.c.
139 void add_member_info_callback(int owner, void (*callback)(char *fn, int static_flag, int param, char *printed_name, struct smatch_state *state))
141 struct member_info_callback *member_callback = __alloc_member_info_callback(0);
143 member_callback->owner = owner;
144 member_callback->callback = callback;
145 add_ptr_list(&member_callbacks, member_callback);
148 void add_returned_state_callback(void (*fn)(int return_id, char *return_ranges, struct expression *returned_expr, struct state_list *slist))
150 struct returned_state_callback *callback = __alloc_returned_state_callback(0);
152 callback->callback = fn;
153 add_ptr_list(&returned_state_callbacks, callback);
156 void add_returned_member_callback(int owner, void (*callback)(int return_id, char *return_ranges, char *printed_name, struct smatch_state *state))
158 struct returned_member_callback *member_callback = __alloc_returned_member_callback(0);
160 member_callback->owner = owner;
161 member_callback->callback = callback;
162 add_ptr_list(&returned_member_callbacks, member_callback);
165 void add_db_fn_call_callback(int type, void (*callback)(struct expression *arg, char *value))
167 struct call_implies_callback *cb = __alloc_call_implies_callback(0);
169 cb->type = type;
170 cb->callback = callback;
171 add_ptr_list(&call_implies_cb_list, cb);
174 static struct symbol *return_type;
175 static struct range_list *return_range_list;
176 static int db_return_callback(void *unused, int argc, char **argv, char **azColName)
178 if (argc != 1)
179 return 0;
180 if (option_debug)
181 sm_msg("return type %d", type_positive_bits(return_type));
182 str_to_rl(return_type, argv[0], &return_range_list);
183 return 0;
186 struct range_list *db_return_vals(struct expression *expr)
188 struct symbol *sym;
189 static char sql_filter[1024];
191 if (expr->type != EXPR_CALL)
192 return NULL;
193 if (expr->fn->type != EXPR_SYMBOL)
194 return NULL;
195 return_type = get_type(expr);
196 if (!return_type)
197 return NULL;
198 sym = expr->fn->symbol;
199 if (!sym)
200 return NULL;
202 if (sym->ctype.modifiers & MOD_STATIC) {
203 snprintf(sql_filter, 1024, "file = '%s' and function = '%s';",
204 get_filename(), sym->ident->name);
205 } else {
206 snprintf(sql_filter, 1024, "function = '%s' and static = 0;",
207 sym->ident->name);
210 return_range_list = NULL;
211 run_sql(db_return_callback, "select return from return_values where %s",
212 sql_filter);
213 return return_range_list;
216 static void match_call_marker(struct expression *expr)
218 char *name;
221 * we just want to record something in the database so that if we have
222 * two calls like: frob(4); frob(some_unkown); then on the receiving
223 * side we know that sometimes frob is called with unknown parameters.
226 name = get_fnptr_name(expr->fn);
227 if (!name)
228 return;
229 sql_insert_caller_info(name, is_static(expr->fn), INTERNAL, -1, "%call_marker%", "");
230 free_string(name);
233 static void print_struct_members(char *fn, int static_flag, struct expression *expr, int param, struct state_list *slist,
234 void (*callback)(char *fn, int static_flag, int param, char *printed_name, struct smatch_state *state))
236 struct sm_state *sm;
237 char *name;
238 struct symbol *sym;
239 int len;
240 char printed_name[256];
241 int is_address = 0;
243 expr = strip_expr(expr);
244 if (expr->type == EXPR_PREOP && expr->op == '&') {
245 expr = strip_expr(expr->unop);
246 is_address = 1;
249 name = expr_to_var_sym(expr, &sym);
250 if (!name || !sym)
251 goto free;
253 len = strlen(name);
254 FOR_EACH_PTR(slist, sm) {
255 if (sm->sym != sym)
256 continue;
257 if (strncmp(name, sm->name, len) || sm->name[len] == '\0')
258 continue;
259 if (is_address)
260 snprintf(printed_name, sizeof(printed_name), "$$->%s", sm->name + len + 1);
261 else
262 snprintf(printed_name, sizeof(printed_name), "$$%s", sm->name + len);
263 callback(fn, static_flag, param, printed_name, sm->state);
264 } END_FOR_EACH_PTR(sm);
265 free:
266 free_string(name);
269 static void match_call_info(struct expression *expr)
271 struct member_info_callback *cb;
272 struct expression *arg;
273 struct state_list *slist;
274 char *name;
275 int i;
277 name = get_fnptr_name(expr->fn);
278 if (!name)
279 return;
281 FOR_EACH_PTR(member_callbacks, cb) {
282 slist = get_all_states(cb->owner);
283 i = 0;
284 FOR_EACH_PTR(expr->args, arg) {
285 print_struct_members(name, is_static(expr->fn), arg, i, slist, cb->callback);
286 i++;
287 } END_FOR_EACH_PTR(arg);
288 free_slist(&slist);
289 } END_FOR_EACH_PTR(cb);
291 free_string(name);
294 static int get_param(int param, char **name, struct symbol **sym)
296 struct symbol *arg;
297 int i;
299 i = 0;
300 FOR_EACH_PTR(cur_func_sym->ctype.base_type->arguments, arg) {
302 * this is a temporary hack to work around a bug (I think in sparse?)
303 * 2.6.37-rc1:fs/reiserfs/journal.o
304 * If there is a function definition without parameter name found
305 * after a function implementation then it causes a crash.
306 * int foo() {}
307 * int bar(char *);
309 if (arg->ident->name < (char *)100)
310 continue;
311 if (i == param && arg->ident->name) {
312 *name = arg->ident->name;
313 *sym = arg;
314 return TRUE;
316 i++;
317 } END_FOR_EACH_PTR(arg);
319 return FALSE;
322 static struct state_list *final_states;
323 static int prev_func_id = -1;
324 static int db_callback(void *unused, int argc, char **argv, char **azColName)
326 int func_id;
327 long type;
328 long param;
329 char *name = NULL;
330 struct symbol *sym = NULL;
331 struct def_callback *def_callback;
333 if (argc != 5)
334 return 0;
336 func_id = atoi(argv[0]);
337 errno = 0;
338 type = strtol(argv[1], NULL, 10);
339 param = strtol(argv[2], NULL, 10);
340 if (errno)
341 return 0;
343 if (prev_func_id == -1)
344 prev_func_id = func_id;
345 if (func_id != prev_func_id) {
346 merge_slist(&final_states, __pop_fake_cur_slist());
347 __push_fake_cur_slist();
348 __unnullify_path();
349 prev_func_id = func_id;
352 if (type == INTERNAL)
353 return 0;
354 if (param >= 0 && !get_param(param, &name, &sym))
355 return 0;
357 FOR_EACH_PTR(callbacks, def_callback) {
358 if (def_callback->hook_type == type)
359 def_callback->callback(name, sym, argv[3], argv[4]);
360 } END_FOR_EACH_PTR(def_callback);
362 return 0;
365 static void get_direct_callers(struct symbol *sym)
367 char sql_filter[1024];
369 if (sym->ctype.modifiers & MOD_STATIC) {
370 snprintf(sql_filter, 1024,
371 "file = '%s' and function = '%s' order by function_id;",
372 get_filename(), sym->ident->name);
373 } else {
374 snprintf(sql_filter, 1024,
375 "function = '%s' and static = 0 order by function_id;",
376 sym->ident->name);
379 run_sql(db_callback, "select function_id, type, parameter, key, value from caller_info"
380 " where %s", sql_filter);
383 static char *ptr_name;
384 static int get_ptr_name(void *unused, int argc, char **argv, char **azColName)
386 if (!ptr_name)
387 ptr_name = alloc_string(argv[0]);
388 return 0;
391 static void get_function_pointer_callers(struct symbol *sym)
393 char sql_filter[1024];
395 if (sym->ctype.modifiers & MOD_STATIC) {
396 snprintf(sql_filter, 1024, "file = '%s' and function = '%s';",
397 get_filename(), sym->ident->name);
398 } else {
399 snprintf(sql_filter, 1024, "function = '%s';",
400 sym->ident->name);
403 ptr_name = NULL;
404 run_sql(get_ptr_name, "select ptr from function_ptr where %s", sql_filter);
405 if (!ptr_name)
406 return;
408 run_sql(db_callback, "select function_id, type, parameter, key, value from caller_info"
409 " where function = '%s' order by function_id", ptr_name);
411 free_string(ptr_name);
414 static void match_data_from_db(struct symbol *sym)
416 struct sm_state *sm;
418 if (!sym || !sym->ident || !sym->ident->name)
419 return;
421 __push_fake_cur_slist();
422 __unnullify_path();
423 prev_func_id = -1;
425 get_direct_callers(sym);
426 get_function_pointer_callers(sym);
428 merge_slist(&final_states, __pop_fake_cur_slist());
430 FOR_EACH_PTR(final_states, sm) {
431 __set_sm(sm);
432 } END_FOR_EACH_PTR(sm);
434 free_slist(&final_states);
437 static void match_function_assign(struct expression *expr)
439 struct expression *right = expr->right;
440 struct symbol *sym;
441 char *fn_name;
442 char *ptr_name;
444 if (right->type == EXPR_PREOP && right->op == '&')
445 right = strip_expr(right->unop);
446 if (right->type != EXPR_SYMBOL)
447 return;
448 sym = get_type(right);
449 if (!sym || sym->type != SYM_FN)
450 return;
452 fn_name = expr_to_var(right);
453 ptr_name = get_fnptr_name(expr->left);
454 if (!fn_name || !ptr_name)
455 goto free;
457 sql_insert_function_ptr(fn_name, ptr_name);
459 free:
460 free_string(fn_name);
461 free_string(ptr_name);
464 static struct expression *call_implies_call_expr;
465 static int call_implies_callbacks(void *unused, int argc, char **argv, char **azColName)
467 struct call_implies_callback *cb;
468 struct expression *arg = NULL;
469 int type;
470 int param;
472 if (argc != 4)
473 return 0;
475 type = atoi(argv[1]);
476 param = atoi(argv[2]);
478 FOR_EACH_PTR(call_implies_cb_list, cb) {
479 if (cb->type != type)
480 continue;
481 if (param != -1) {
482 arg = get_argument_from_call_expr(call_implies_call_expr->args, param);
483 if (!arg)
484 continue;
486 cb->callback(arg, argv[3]);
487 } END_FOR_EACH_PTR(cb);
489 return 0;
492 static void match_call_implies(struct expression *expr)
494 struct symbol *sym;
495 static char sql_filter[1024];
497 if (expr->fn->type != EXPR_SYMBOL)
498 return;
499 sym = expr->fn->symbol;
500 if (!sym)
501 return;
503 if (sym->ctype.modifiers & MOD_STATIC) {
504 snprintf(sql_filter, 1024, "file = '%s' and function = '%s';",
505 get_filename(), sym->ident->name);
506 } else {
507 snprintf(sql_filter, 1024, "function = '%s' and static = 0;",
508 sym->ident->name);
511 call_implies_call_expr = expr;
512 run_sql(call_implies_callbacks,
513 "select function, type, parameter, value from call_implies where %s",
514 sql_filter);
515 return;
518 static void print_initializer_list(struct expression_list *expr_list,
519 struct symbol *struct_type)
521 struct expression *expr;
522 struct symbol *base_type;
523 char struct_name[256];
525 FOR_EACH_PTR(expr_list, expr) {
526 if (expr->type == EXPR_INDEX && expr->idx_expression && expr->idx_expression->type == EXPR_INITIALIZER) {
527 print_initializer_list(expr->idx_expression->expr_list, struct_type);
528 continue;
530 if (expr->type != EXPR_IDENTIFIER)
531 continue;
532 if (!expr->expr_ident)
533 continue;
534 if (!expr->ident_expression || !expr->ident_expression->symbol_name)
535 continue;
536 base_type = get_type(expr->ident_expression);
537 if (!base_type || base_type->type != SYM_FN)
538 continue;
539 snprintf(struct_name, sizeof(struct_name), "(struct %s)->%s",
540 struct_type->ident->name, expr->expr_ident->name);
541 sql_insert_function_ptr(expr->ident_expression->symbol_name->name,
542 struct_name);
543 } END_FOR_EACH_PTR(expr);
546 static void global_variable(struct symbol *sym)
548 struct symbol *struct_type;
550 if (!sym->ident)
551 return;
552 if (!sym->initializer || sym->initializer->type != EXPR_INITIALIZER)
553 return;
554 struct_type = get_base_type(sym);
555 if (!struct_type)
556 return;
557 if (struct_type->type == SYM_ARRAY) {
558 struct_type = get_base_type(struct_type);
559 if (!struct_type)
560 return;
562 if (struct_type->type != SYM_STRUCT || !struct_type->ident)
563 return;
564 print_initializer_list(sym->initializer->expr_list, struct_type);
567 static void match_return_info(int return_id, char *return_ranges, struct expression *expr, struct state_list *slist)
569 sql_insert_return_states(return_id, return_ranges, INTERNAL, -1, "", "");
572 static int return_id;
573 static void match_function_def(struct symbol *sym)
575 return_id = 0;
578 static void call_return_state_hooks_compare(struct expression *expr)
580 struct returned_state_callback *cb;
581 struct state_list *slist;
582 char *return_ranges;
583 int final_pass_orig = final_pass;
585 __push_fake_cur_slist();
587 final_pass = 0;
588 __split_whole_condition(expr);
589 final_pass = final_pass_orig;
591 return_ranges = alloc_sname("1");
593 return_id++;
594 slist = __get_cur_slist();
595 FOR_EACH_PTR(returned_state_callbacks, cb) {
596 cb->callback(return_id, return_ranges, expr, slist);
597 } END_FOR_EACH_PTR(cb);
599 __push_true_states();
600 __use_false_states();
602 return_ranges = alloc_sname("0");;
603 return_id++;
604 slist = __get_cur_slist();
605 FOR_EACH_PTR(returned_state_callbacks, cb) {
606 cb->callback(return_id, return_ranges, expr, slist);
607 } END_FOR_EACH_PTR(cb);
609 __merge_true_states();
610 __pop_fake_cur_slist();
613 static int call_return_state_hooks_split_possible(struct expression *expr)
615 struct returned_state_callback *cb;
616 struct state_list *slist;
617 struct range_list *rl;
618 char *return_ranges;
619 struct sm_state *sm;
620 struct sm_state *tmp;
621 int ret = 0;
622 int nr_possible, nr_states;
624 sm = get_sm_state_expr(SMATCH_EXTRA, expr);
625 if (!sm || !sm->merged)
626 return 0;
628 /* bail if it gets too complicated */
629 nr_possible = ptr_list_size((struct ptr_list *)sm->possible);
630 nr_states = ptr_list_size((struct ptr_list *)__get_cur_slist());
631 if (nr_possible >= 100)
632 return 0;
633 if (nr_states * nr_possible >= 1000)
634 return 0;
636 FOR_EACH_PTR(sm->possible, tmp) {
637 if (tmp->merged)
638 continue;
640 ret = 1;
641 __push_fake_cur_slist();
643 overwrite_states_using_pool(tmp);
645 rl = cast_rl(cur_func_return_type(), estate_rl(tmp->state));
646 return_ranges = show_rl(rl);
648 return_id++;
649 slist = __get_cur_slist();
650 FOR_EACH_PTR(returned_state_callbacks, cb) {
651 cb->callback(return_id, return_ranges, expr, slist);
652 } END_FOR_EACH_PTR(cb);
654 __pop_fake_cur_slist();
655 } END_FOR_EACH_PTR(tmp);
657 return ret;
660 static void call_return_state_hooks(struct expression *expr)
662 struct returned_state_callback *cb;
663 struct state_list *slist;
664 struct range_list *rl;
665 char *return_ranges;
666 int nr_states;
668 expr = strip_expr(expr);
670 if (!expr) {
671 return_ranges = alloc_sname("");
672 } else if (is_condition(expr)) {
673 call_return_state_hooks_compare(expr);
674 return;
675 } else if (call_return_state_hooks_split_possible(expr)) {
676 return;
677 } else if (get_implied_rl(expr, &rl)) {
678 rl = cast_rl(cur_func_return_type(), rl);
679 return_ranges = show_rl(rl);
680 } else {
681 rl = alloc_whole_rl(cur_func_return_type());
682 return_ranges = show_rl(rl);
685 return_id++;
686 slist = __get_cur_slist();
687 nr_states = ptr_list_size((struct ptr_list *)__get_cur_slist());
688 FOR_EACH_PTR(returned_state_callbacks, cb) {
689 if (nr_states < 10000)
690 cb->callback(return_id, return_ranges, expr, slist);
691 else
692 cb->callback(return_id, return_ranges, expr, NULL);
693 } END_FOR_EACH_PTR(cb);
696 static void print_returned_struct_members(int return_id, char *return_ranges, struct expression *expr, struct state_list *slist)
698 struct returned_member_callback *cb;
699 struct state_list *my_slist;
700 struct sm_state *sm;
701 struct symbol *type;
702 char *name;
703 char member_name[256];
704 int len;
706 type = get_type(expr);
707 if (!type || type->type != SYM_PTR)
708 return;
709 type = get_real_base_type(type);
710 if (!type || type->type != SYM_STRUCT)
711 return;
712 name = expr_to_var(expr);
713 if (!name)
714 return;
716 member_name[sizeof(member_name) - 1] = '\0';
717 strcpy(member_name, "$$");
719 len = strlen(name);
720 FOR_EACH_PTR(returned_member_callbacks, cb) {
721 my_slist = get_all_states_slist(cb->owner, slist);
722 FOR_EACH_PTR(my_slist, sm) {
723 if (strncmp(sm->name, name, len) != 0)
724 continue;
725 if (strncmp(sm->name + len, "->", 2) != 0)
726 continue;
727 strncpy(member_name + 2, sm->name + len, sizeof(member_name) - 2);
728 cb->callback(return_id, return_ranges, member_name, sm->state);
729 } END_FOR_EACH_PTR(sm);
730 free_slist(&my_slist);
731 } END_FOR_EACH_PTR(cb);
733 free_string(name);
736 static void match_end_func_info(struct symbol *sym)
738 if (__path_is_null())
739 return;
740 call_return_state_hooks(NULL);
743 void open_smatch_db(void)
745 #ifdef SQLITE_OPEN_READONLY
746 int rc;
748 if (option_no_db)
749 return;
751 rc = sqlite3_open_v2("smatch_db.sqlite", &db, SQLITE_OPEN_READONLY, NULL);
752 if (rc != SQLITE_OK) {
753 option_no_db = 1;
754 return;
756 return;
757 #else
758 option_no_db = 1;
759 return;
760 #endif
763 void register_definition_db_callbacks(int id)
765 add_hook(&match_function_def, FUNC_DEF_HOOK);
767 if (option_info) {
768 add_hook(&match_call_info, FUNCTION_CALL_HOOK);
769 add_hook(&match_function_assign, ASSIGNMENT_HOOK);
770 add_hook(&match_function_assign, GLOBAL_ASSIGNMENT_HOOK);
771 add_hook(&global_variable, BASE_HOOK);
772 add_hook(&global_variable, DECLARATION_HOOK);
773 add_returned_state_callback(match_return_info);
774 add_returned_state_callback(print_returned_struct_members);
775 add_hook(&call_return_state_hooks, RETURN_HOOK);
776 add_hook(&match_end_func_info, END_FUNC_HOOK);
779 if (option_no_db)
780 return;
782 add_hook(&match_data_from_db, FUNC_DEF_HOOK);
783 add_hook(&match_call_implies, FUNCTION_CALL_HOOK);
786 void register_db_call_marker(int id)
788 if (!option_info)
789 return;
790 add_hook(&match_call_marker, FUNCTION_CALL_HOOK);
793 char *get_variable_from_key(struct expression *arg, char *key, struct symbol **sym)
795 char buf[256];
796 char *tmp;
798 if (strcmp(key, "$$") == 0)
799 return expr_to_var_sym(arg, sym);
801 if (strcmp(key, "*$$") == 0) {
802 if (arg->type == EXPR_PREOP && arg->op == '&') {
803 arg = strip_expr(arg->unop);
804 return expr_to_var_sym(arg, sym);
805 } else {
806 tmp = expr_to_var_sym(arg, sym);
807 if (!tmp)
808 return NULL;
809 snprintf(buf, sizeof(buf), "*%s", tmp);
810 free_string(tmp);
811 return alloc_string(buf);
815 if (arg->type == EXPR_PREOP && arg->op == '&') {
816 arg = strip_expr(arg->unop);
817 tmp = expr_to_var_sym(arg, sym);
818 if (!tmp)
819 return NULL;
820 snprintf(buf, sizeof(buf), "%s.%s", tmp, key + 4);
821 return alloc_string(buf);
824 tmp = expr_to_var_sym(arg, sym);
825 if (!tmp)
826 return NULL;
827 snprintf(buf, sizeof(buf), "%s%s", tmp, key + 2);
828 free_string(tmp);
829 return alloc_string(buf);