db: move type_size to use raw SQL
[smatch.git] / smatch_db.c
blob5deaecbbc06712ccc46df0fa550cc75f5b51a3e4
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, char *global_static, 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_function_ptr(const char *fn, const char *struct_name)
92 sql_insert(function_ptr, "'%s', '%s', '%s'", get_filename(), fn,
93 struct_name);
96 void sql_insert_return_values(const char *return_values)
98 sql_insert(return_values, "'%s', '%s', %d, '%s'", get_filename(),
99 get_function(), fn_static(), return_values);
102 void sql_insert_call_implies(int type, int param, int value)
104 sql_insert(call_implies, "'%s', '%s', %d, %d, %d, %d", get_filename(),
105 get_function(), fn_static(), type, param, value);
108 void sql_insert_type_size(const char *member, int size)
110 sql_insert(type_size, "'%s', '%s', %d", get_filename(), member, size);
113 void add_definition_db_callback(void (*callback)(const char *name, struct symbol *sym, char *key, char *value), int type)
115 struct def_callback *def_callback = __alloc_def_callback(0);
117 def_callback->hook_type = type;
118 def_callback->callback = callback;
119 add_ptr_list(&callbacks, def_callback);
123 * These call backs are used when the --info option is turned on to print struct
124 * member information. For example foo->bar could have a state in
125 * smatch_extra.c and also check_user.c.
127 void add_member_info_callback(int owner, void (*callback)(char *fn, char *global_static, int param, char *printed_name, struct smatch_state *state))
129 struct member_info_callback *member_callback = __alloc_member_info_callback(0);
131 member_callback->owner = owner;
132 member_callback->callback = callback;
133 add_ptr_list(&member_callbacks, member_callback);
136 void add_returned_state_callback(void (*fn)(int return_id, char *return_ranges, struct expression *returned_expr, struct state_list *slist))
138 struct returned_state_callback *callback = __alloc_returned_state_callback(0);
140 callback->callback = fn;
141 add_ptr_list(&returned_state_callbacks, callback);
144 void add_returned_member_callback(int owner, void (*callback)(int return_id, char *return_ranges, char *printed_name, struct smatch_state *state))
146 struct returned_member_callback *member_callback = __alloc_returned_member_callback(0);
148 member_callback->owner = owner;
149 member_callback->callback = callback;
150 add_ptr_list(&returned_member_callbacks, member_callback);
153 void add_db_fn_call_callback(int type, void (*callback)(struct expression *arg, char *value))
155 struct call_implies_callback *cb = __alloc_call_implies_callback(0);
157 cb->type = type;
158 cb->callback = callback;
159 add_ptr_list(&call_implies_cb_list, cb);
162 static struct symbol *return_type;
163 static struct range_list *return_range_list;
164 static int db_return_callback(void *unused, int argc, char **argv, char **azColName)
166 if (argc != 1)
167 return 0;
168 if (option_debug)
169 sm_msg("return type %d", type_positive_bits(return_type));
170 str_to_rl(return_type, argv[0], &return_range_list);
171 return 0;
174 struct range_list *db_return_vals(struct expression *expr)
176 struct symbol *sym;
177 static char sql_filter[1024];
179 if (expr->type != EXPR_CALL)
180 return NULL;
181 if (expr->fn->type != EXPR_SYMBOL)
182 return NULL;
183 return_type = get_type(expr);
184 if (!return_type)
185 return NULL;
186 sym = expr->fn->symbol;
187 if (!sym)
188 return NULL;
190 if (sym->ctype.modifiers & MOD_STATIC) {
191 snprintf(sql_filter, 1024, "file = '%s' and function = '%s';",
192 get_filename(), sym->ident->name);
193 } else {
194 snprintf(sql_filter, 1024, "function = '%s' and static = 0;",
195 sym->ident->name);
198 return_range_list = NULL;
199 run_sql(db_return_callback, "select return from return_values where %s",
200 sql_filter);
201 return return_range_list;
204 static void match_call_hack(struct expression *expr)
206 char *name;
209 * we just want to record something in the database so that if we have
210 * two calls like: frob(4); frob(some_unkown); then on the receiving
211 * side we know that sometimes frob is called with unknown parameters.
214 name = get_fnptr_name(expr->fn);
215 if (!name)
216 return;
217 sm_msg("info: call_marker '%s' %s", name, is_static(expr->fn) ? "static" : "global");
218 free_string(name);
221 static void print_struct_members(char *fn, char *global_static, struct expression *expr, int param, struct state_list *slist,
222 void (*callback)(char *fn, char *global_static, int param, char *printed_name, struct smatch_state *state))
224 struct sm_state *sm;
225 char *name;
226 struct symbol *sym;
227 int len;
228 char printed_name[256];
229 int is_address = 0;
231 expr = strip_expr(expr);
232 if (expr->type == EXPR_PREOP && expr->op == '&') {
233 expr = strip_expr(expr->unop);
234 is_address = 1;
237 name = expr_to_var_sym(expr, &sym);
238 if (!name || !sym)
239 goto free;
241 len = strlen(name);
242 FOR_EACH_PTR(slist, sm) {
243 if (sm->sym != sym)
244 continue;
245 if (strncmp(name, sm->name, len) || sm->name[len] == '\0')
246 continue;
247 if (is_address)
248 snprintf(printed_name, sizeof(printed_name), "$$->%s", sm->name + len + 1);
249 else
250 snprintf(printed_name, sizeof(printed_name), "$$%s", sm->name + len);
251 callback(fn, global_static, param, printed_name, sm->state);
252 } END_FOR_EACH_PTR(sm);
253 free:
254 free_string(name);
257 static void match_call_info(struct expression *expr)
259 struct member_info_callback *cb;
260 struct expression *arg;
261 struct state_list *slist;
262 char *name;
263 int i;
264 char *gs;
266 name = get_fnptr_name(expr->fn);
267 if (!name)
268 return;
270 if (is_static(expr->fn))
271 gs = (char *)"static";
272 else
273 gs = (char *)"global";
275 FOR_EACH_PTR(member_callbacks, cb) {
276 slist = get_all_states(cb->owner);
277 i = 0;
278 FOR_EACH_PTR(expr->args, arg) {
279 print_struct_members(name, gs, arg, i, slist, cb->callback);
280 i++;
281 } END_FOR_EACH_PTR(arg);
282 free_slist(&slist);
283 } END_FOR_EACH_PTR(cb);
285 free_string(name);
288 static int get_param(int param, char **name, struct symbol **sym)
290 struct symbol *arg;
291 int i;
293 i = 0;
294 FOR_EACH_PTR(cur_func_sym->ctype.base_type->arguments, arg) {
296 * this is a temporary hack to work around a bug (I think in sparse?)
297 * 2.6.37-rc1:fs/reiserfs/journal.o
298 * If there is a function definition without parameter name found
299 * after a function implementation then it causes a crash.
300 * int foo() {}
301 * int bar(char *);
303 if (arg->ident->name < (char *)100)
304 continue;
305 if (i == param && arg->ident->name) {
306 *name = arg->ident->name;
307 *sym = arg;
308 return TRUE;
310 i++;
311 } END_FOR_EACH_PTR(arg);
313 return FALSE;
316 static struct state_list *final_states;
317 static int prev_func_id = -1;
318 static int db_callback(void *unused, int argc, char **argv, char **azColName)
320 int func_id;
321 long type;
322 long param;
323 char *name = NULL;
324 struct symbol *sym = NULL;
325 struct def_callback *def_callback;
327 if (argc != 5)
328 return 0;
330 func_id = atoi(argv[0]);
331 errno = 0;
332 type = strtol(argv[1], NULL, 10);
333 param = strtol(argv[2], NULL, 10);
334 if (errno)
335 return 0;
337 if (prev_func_id == -1)
338 prev_func_id = func_id;
339 if (func_id != prev_func_id) {
340 merge_slist(&final_states, __pop_fake_cur_slist());
341 __push_fake_cur_slist();
342 __unnullify_path();
343 prev_func_id = func_id;
346 if (type == INTERNAL)
347 return 0;
348 if (param >= 0 && !get_param(param, &name, &sym))
349 return 0;
351 FOR_EACH_PTR(callbacks, def_callback) {
352 if (def_callback->hook_type == type)
353 def_callback->callback(name, sym, argv[3], argv[4]);
354 } END_FOR_EACH_PTR(def_callback);
356 return 0;
359 static void get_direct_callers(struct symbol *sym)
361 char sql_filter[1024];
363 if (sym->ctype.modifiers & MOD_STATIC) {
364 snprintf(sql_filter, 1024,
365 "file = '%s' and function = '%s' order by function_id;",
366 get_filename(), sym->ident->name);
367 } else {
368 snprintf(sql_filter, 1024,
369 "function = '%s' and static = 0 order by function_id;",
370 sym->ident->name);
373 run_sql(db_callback, "select function_id, type, parameter, key, value from caller_info"
374 " where %s", sql_filter);
377 static char *ptr_name;
378 static int get_ptr_name(void *unused, int argc, char **argv, char **azColName)
380 if (!ptr_name)
381 ptr_name = alloc_string(argv[0]);
382 return 0;
385 static void get_function_pointer_callers(struct symbol *sym)
387 char sql_filter[1024];
389 if (sym->ctype.modifiers & MOD_STATIC) {
390 snprintf(sql_filter, 1024, "file = '%s' and function = '%s';",
391 get_filename(), sym->ident->name);
392 } else {
393 snprintf(sql_filter, 1024, "function = '%s';",
394 sym->ident->name);
397 ptr_name = NULL;
398 run_sql(get_ptr_name, "select ptr from function_ptr where %s", sql_filter);
399 if (!ptr_name)
400 return;
402 run_sql(db_callback, "select function_id, type, parameter, key, value from caller_info"
403 " where function = '%s' order by function_id", ptr_name);
405 free_string(ptr_name);
408 static void match_data_from_db(struct symbol *sym)
410 struct sm_state *sm;
412 if (!sym || !sym->ident || !sym->ident->name)
413 return;
415 __push_fake_cur_slist();
416 __unnullify_path();
417 prev_func_id = -1;
419 get_direct_callers(sym);
420 get_function_pointer_callers(sym);
422 merge_slist(&final_states, __pop_fake_cur_slist());
424 FOR_EACH_PTR(final_states, sm) {
425 __set_sm(sm);
426 } END_FOR_EACH_PTR(sm);
428 free_slist(&final_states);
431 static void match_function_assign(struct expression *expr)
433 struct expression *right = expr->right;
434 struct symbol *sym;
435 char *fn_name;
436 char *ptr_name;
438 if (right->type == EXPR_PREOP && right->op == '&')
439 right = strip_expr(right->unop);
440 if (right->type != EXPR_SYMBOL)
441 return;
442 sym = get_type(right);
443 if (!sym || sym->type != SYM_FN)
444 return;
446 fn_name = expr_to_var(right);
447 ptr_name = get_fnptr_name(expr->left);
448 if (!fn_name || !ptr_name)
449 goto free;
451 sql_insert_function_ptr(fn_name, ptr_name);
453 free:
454 free_string(fn_name);
455 free_string(ptr_name);
458 static struct expression *call_implies_call_expr;
459 static int call_implies_callbacks(void *unused, int argc, char **argv, char **azColName)
461 struct call_implies_callback *cb;
462 struct expression *arg = NULL;
463 int type;
464 int param;
466 if (argc != 4)
467 return 0;
469 type = atoi(argv[1]);
470 param = atoi(argv[2]);
472 FOR_EACH_PTR(call_implies_cb_list, cb) {
473 if (cb->type != type)
474 continue;
475 if (param != -1) {
476 arg = get_argument_from_call_expr(call_implies_call_expr->args, param);
477 if (!arg)
478 continue;
480 cb->callback(arg, argv[3]);
481 } END_FOR_EACH_PTR(cb);
483 return 0;
486 static void match_call_implies(struct expression *expr)
488 struct symbol *sym;
489 static char sql_filter[1024];
491 if (expr->fn->type != EXPR_SYMBOL)
492 return;
493 sym = expr->fn->symbol;
494 if (!sym)
495 return;
497 if (sym->ctype.modifiers & MOD_STATIC) {
498 snprintf(sql_filter, 1024, "file = '%s' and function = '%s';",
499 get_filename(), sym->ident->name);
500 } else {
501 snprintf(sql_filter, 1024, "function = '%s' and static = 0;",
502 sym->ident->name);
505 call_implies_call_expr = expr;
506 run_sql(call_implies_callbacks,
507 "select function, type, parameter, value from call_implies where %s",
508 sql_filter);
509 return;
512 static void print_initializer_list(struct expression_list *expr_list,
513 struct symbol *struct_type)
515 struct expression *expr;
516 struct symbol *base_type;
517 char struct_name[256];
519 FOR_EACH_PTR(expr_list, expr) {
520 if (expr->type == EXPR_INDEX && expr->idx_expression && expr->idx_expression->type == EXPR_INITIALIZER) {
521 print_initializer_list(expr->idx_expression->expr_list, struct_type);
522 continue;
524 if (expr->type != EXPR_IDENTIFIER)
525 continue;
526 if (!expr->expr_ident)
527 continue;
528 if (!expr->ident_expression || !expr->ident_expression->symbol_name)
529 continue;
530 base_type = get_type(expr->ident_expression);
531 if (!base_type || base_type->type != SYM_FN)
532 continue;
533 snprintf(struct_name, sizeof(struct_name), "(struct %s)->%s",
534 struct_type->ident->name, expr->expr_ident->name);
535 sql_insert_function_ptr(expr->ident_expression->symbol_name->name,
536 struct_name);
537 } END_FOR_EACH_PTR(expr);
540 static void global_variable(struct symbol *sym)
542 struct symbol *struct_type;
544 if (!sym->ident)
545 return;
546 if (!sym->initializer || sym->initializer->type != EXPR_INITIALIZER)
547 return;
548 struct_type = get_base_type(sym);
549 if (!struct_type)
550 return;
551 if (struct_type->type == SYM_ARRAY) {
552 struct_type = get_base_type(struct_type);
553 if (!struct_type)
554 return;
556 if (struct_type->type != SYM_STRUCT || !struct_type->ident)
557 return;
558 print_initializer_list(sym->initializer->expr_list, struct_type);
561 static void match_return_info(int return_id, char *return_ranges, struct expression *expr, struct state_list *slist)
563 sql_insert_return_states(return_id, return_ranges, INTERNAL, -1, "", "");
566 static int return_id;
567 static void match_function_def(struct symbol *sym)
569 return_id = 0;
572 static void call_return_state_hooks_compare(struct expression *expr)
574 struct returned_state_callback *cb;
575 struct state_list *slist;
576 char *return_ranges;
577 int final_pass_orig = final_pass;
579 __push_fake_cur_slist();
581 final_pass = 0;
582 __split_whole_condition(expr);
583 final_pass = final_pass_orig;
585 return_ranges = alloc_sname("1");
587 return_id++;
588 slist = __get_cur_slist();
589 FOR_EACH_PTR(returned_state_callbacks, cb) {
590 cb->callback(return_id, return_ranges, expr, slist);
591 } END_FOR_EACH_PTR(cb);
593 __push_true_states();
594 __use_false_states();
596 return_ranges = alloc_sname("0");;
597 return_id++;
598 slist = __get_cur_slist();
599 FOR_EACH_PTR(returned_state_callbacks, cb) {
600 cb->callback(return_id, return_ranges, expr, slist);
601 } END_FOR_EACH_PTR(cb);
603 __merge_true_states();
604 __pop_fake_cur_slist();
607 static int call_return_state_hooks_split_possible(struct expression *expr)
609 struct returned_state_callback *cb;
610 struct state_list *slist;
611 struct range_list *rl;
612 char *return_ranges;
613 struct sm_state *sm;
614 struct sm_state *tmp;
615 int ret = 0;
616 int nr_possible, nr_states;
618 sm = get_sm_state_expr(SMATCH_EXTRA, expr);
619 if (!sm || !sm->merged)
620 return 0;
622 /* bail if it gets too complicated */
623 nr_possible = ptr_list_size((struct ptr_list *)sm->possible);
624 nr_states = ptr_list_size((struct ptr_list *)__get_cur_slist());
625 if (nr_possible >= 100)
626 return 0;
627 if (nr_states * nr_possible >= 1000)
628 return 0;
630 FOR_EACH_PTR(sm->possible, tmp) {
631 if (tmp->merged)
632 continue;
634 ret = 1;
635 __push_fake_cur_slist();
637 overwrite_states_using_pool(tmp);
639 rl = cast_rl(cur_func_return_type(), estate_rl(tmp->state));
640 return_ranges = show_rl(rl);
642 return_id++;
643 slist = __get_cur_slist();
644 FOR_EACH_PTR(returned_state_callbacks, cb) {
645 cb->callback(return_id, return_ranges, expr, slist);
646 } END_FOR_EACH_PTR(cb);
648 __pop_fake_cur_slist();
649 } END_FOR_EACH_PTR(tmp);
651 return ret;
654 static void call_return_state_hooks(struct expression *expr)
656 struct returned_state_callback *cb;
657 struct state_list *slist;
658 struct range_list *rl;
659 char *return_ranges;
660 int nr_states;
662 expr = strip_expr(expr);
664 if (!expr) {
665 return_ranges = alloc_sname("");
666 } else if (is_condition(expr)) {
667 call_return_state_hooks_compare(expr);
668 return;
669 } else if (call_return_state_hooks_split_possible(expr)) {
670 return;
671 } else if (get_implied_rl(expr, &rl)) {
672 rl = cast_rl(cur_func_return_type(), rl);
673 return_ranges = show_rl(rl);
674 } else {
675 rl = alloc_whole_rl(cur_func_return_type());
676 return_ranges = show_rl(rl);
679 return_id++;
680 slist = __get_cur_slist();
681 nr_states = ptr_list_size((struct ptr_list *)__get_cur_slist());
682 FOR_EACH_PTR(returned_state_callbacks, cb) {
683 if (nr_states < 10000)
684 cb->callback(return_id, return_ranges, expr, slist);
685 else
686 cb->callback(return_id, return_ranges, expr, NULL);
687 } END_FOR_EACH_PTR(cb);
690 static void print_returned_struct_members(int return_id, char *return_ranges, struct expression *expr, struct state_list *slist)
692 struct returned_member_callback *cb;
693 struct state_list *my_slist;
694 struct sm_state *sm;
695 struct symbol *type;
696 char *name;
697 char member_name[256];
698 int len;
700 type = get_type(expr);
701 if (!type || type->type != SYM_PTR)
702 return;
703 type = get_real_base_type(type);
704 if (!type || type->type != SYM_STRUCT)
705 return;
706 name = expr_to_var(expr);
707 if (!name)
708 return;
710 member_name[sizeof(member_name) - 1] = '\0';
711 strcpy(member_name, "$$");
713 len = strlen(name);
714 FOR_EACH_PTR(returned_member_callbacks, cb) {
715 my_slist = get_all_states_slist(cb->owner, slist);
716 FOR_EACH_PTR(my_slist, sm) {
717 if (strncmp(sm->name, name, len) != 0)
718 continue;
719 if (strncmp(sm->name + len, "->", 2) != 0)
720 continue;
721 strncpy(member_name + 2, sm->name + len, sizeof(member_name) - 2);
722 cb->callback(return_id, return_ranges, member_name, sm->state);
723 } END_FOR_EACH_PTR(sm);
724 free_slist(&my_slist);
725 } END_FOR_EACH_PTR(cb);
727 free_string(name);
730 static void match_end_func_info(struct symbol *sym)
732 if (__path_is_null())
733 return;
734 call_return_state_hooks(NULL);
737 void open_smatch_db(void)
739 #ifdef SQLITE_OPEN_READONLY
740 int rc;
742 if (option_no_db)
743 return;
745 rc = sqlite3_open_v2("smatch_db.sqlite", &db, SQLITE_OPEN_READONLY, NULL);
746 if (rc != SQLITE_OK) {
747 option_no_db = 1;
748 return;
750 return;
751 #else
752 option_no_db = 1;
753 return;
754 #endif
757 void register_definition_db_callbacks(int id)
759 add_hook(&match_function_def, FUNC_DEF_HOOK);
761 if (option_info) {
762 add_hook(&match_call_info, FUNCTION_CALL_HOOK);
763 add_hook(&match_call_hack, FUNCTION_CALL_HOOK);
764 add_hook(&match_function_assign, ASSIGNMENT_HOOK);
765 add_hook(&match_function_assign, GLOBAL_ASSIGNMENT_HOOK);
766 add_hook(&global_variable, BASE_HOOK);
767 add_hook(&global_variable, DECLARATION_HOOK);
768 add_returned_state_callback(match_return_info);
769 add_returned_state_callback(print_returned_struct_members);
770 add_hook(&call_return_state_hooks, RETURN_HOOK);
771 add_hook(&match_end_func_info, END_FUNC_HOOK);
774 if (option_no_db)
775 return;
777 add_hook(&match_data_from_db, FUNC_DEF_HOOK);
778 add_hook(&match_call_implies, FUNCTION_CALL_HOOK);
781 char *get_variable_from_key(struct expression *arg, char *key, struct symbol **sym)
783 char buf[256];
784 char *tmp;
786 if (strcmp(key, "$$") == 0)
787 return expr_to_var_sym(arg, sym);
789 if (strcmp(key, "*$$") == 0) {
790 if (arg->type == EXPR_PREOP && arg->op == '&') {
791 arg = strip_expr(arg->unop);
792 return expr_to_var_sym(arg, sym);
793 } else {
794 tmp = expr_to_var_sym(arg, sym);
795 if (!tmp)
796 return NULL;
797 snprintf(buf, sizeof(buf), "*%s", tmp);
798 free_string(tmp);
799 return alloc_string(buf);
803 if (arg->type == EXPR_PREOP && arg->op == '&') {
804 arg = strip_expr(arg->unop);
805 tmp = expr_to_var_sym(arg, sym);
806 if (!tmp)
807 return NULL;
808 snprintf(buf, sizeof(buf), "%s.%s", tmp, key + 4);
809 return alloc_string(buf);
812 tmp = expr_to_var_sym(arg, sym);
813 if (!tmp)
814 return NULL;
815 snprintf(buf, sizeof(buf), "%s%s", tmp, key + 2);
816 free_string(tmp);
817 return alloc_string(buf);