db: make member_info callbacks take 1 or 0 instead of "static" or "global"
[smatch.git] / smatch_db.c
blobdbd1f8662b18b066440b53a8b9a95db57344a739
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_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, int static_flag, 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, int static_flag, struct expression *expr, int param, struct state_list *slist,
222 void (*callback)(char *fn, int static_flag, 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, static_flag, 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;
265 name = get_fnptr_name(expr->fn);
266 if (!name)
267 return;
269 FOR_EACH_PTR(member_callbacks, cb) {
270 slist = get_all_states(cb->owner);
271 i = 0;
272 FOR_EACH_PTR(expr->args, arg) {
273 print_struct_members(name, is_static(expr->fn), arg, i, slist, cb->callback);
274 i++;
275 } END_FOR_EACH_PTR(arg);
276 free_slist(&slist);
277 } END_FOR_EACH_PTR(cb);
279 free_string(name);
282 static int get_param(int param, char **name, struct symbol **sym)
284 struct symbol *arg;
285 int i;
287 i = 0;
288 FOR_EACH_PTR(cur_func_sym->ctype.base_type->arguments, arg) {
290 * this is a temporary hack to work around a bug (I think in sparse?)
291 * 2.6.37-rc1:fs/reiserfs/journal.o
292 * If there is a function definition without parameter name found
293 * after a function implementation then it causes a crash.
294 * int foo() {}
295 * int bar(char *);
297 if (arg->ident->name < (char *)100)
298 continue;
299 if (i == param && arg->ident->name) {
300 *name = arg->ident->name;
301 *sym = arg;
302 return TRUE;
304 i++;
305 } END_FOR_EACH_PTR(arg);
307 return FALSE;
310 static struct state_list *final_states;
311 static int prev_func_id = -1;
312 static int db_callback(void *unused, int argc, char **argv, char **azColName)
314 int func_id;
315 long type;
316 long param;
317 char *name = NULL;
318 struct symbol *sym = NULL;
319 struct def_callback *def_callback;
321 if (argc != 5)
322 return 0;
324 func_id = atoi(argv[0]);
325 errno = 0;
326 type = strtol(argv[1], NULL, 10);
327 param = strtol(argv[2], NULL, 10);
328 if (errno)
329 return 0;
331 if (prev_func_id == -1)
332 prev_func_id = func_id;
333 if (func_id != prev_func_id) {
334 merge_slist(&final_states, __pop_fake_cur_slist());
335 __push_fake_cur_slist();
336 __unnullify_path();
337 prev_func_id = func_id;
340 if (type == INTERNAL)
341 return 0;
342 if (param >= 0 && !get_param(param, &name, &sym))
343 return 0;
345 FOR_EACH_PTR(callbacks, def_callback) {
346 if (def_callback->hook_type == type)
347 def_callback->callback(name, sym, argv[3], argv[4]);
348 } END_FOR_EACH_PTR(def_callback);
350 return 0;
353 static void get_direct_callers(struct symbol *sym)
355 char sql_filter[1024];
357 if (sym->ctype.modifiers & MOD_STATIC) {
358 snprintf(sql_filter, 1024,
359 "file = '%s' and function = '%s' order by function_id;",
360 get_filename(), sym->ident->name);
361 } else {
362 snprintf(sql_filter, 1024,
363 "function = '%s' and static = 0 order by function_id;",
364 sym->ident->name);
367 run_sql(db_callback, "select function_id, type, parameter, key, value from caller_info"
368 " where %s", sql_filter);
371 static char *ptr_name;
372 static int get_ptr_name(void *unused, int argc, char **argv, char **azColName)
374 if (!ptr_name)
375 ptr_name = alloc_string(argv[0]);
376 return 0;
379 static void get_function_pointer_callers(struct symbol *sym)
381 char sql_filter[1024];
383 if (sym->ctype.modifiers & MOD_STATIC) {
384 snprintf(sql_filter, 1024, "file = '%s' and function = '%s';",
385 get_filename(), sym->ident->name);
386 } else {
387 snprintf(sql_filter, 1024, "function = '%s';",
388 sym->ident->name);
391 ptr_name = NULL;
392 run_sql(get_ptr_name, "select ptr from function_ptr where %s", sql_filter);
393 if (!ptr_name)
394 return;
396 run_sql(db_callback, "select function_id, type, parameter, key, value from caller_info"
397 " where function = '%s' order by function_id", ptr_name);
399 free_string(ptr_name);
402 static void match_data_from_db(struct symbol *sym)
404 struct sm_state *sm;
406 if (!sym || !sym->ident || !sym->ident->name)
407 return;
409 __push_fake_cur_slist();
410 __unnullify_path();
411 prev_func_id = -1;
413 get_direct_callers(sym);
414 get_function_pointer_callers(sym);
416 merge_slist(&final_states, __pop_fake_cur_slist());
418 FOR_EACH_PTR(final_states, sm) {
419 __set_sm(sm);
420 } END_FOR_EACH_PTR(sm);
422 free_slist(&final_states);
425 static void match_function_assign(struct expression *expr)
427 struct expression *right = expr->right;
428 struct symbol *sym;
429 char *fn_name;
430 char *ptr_name;
432 if (right->type == EXPR_PREOP && right->op == '&')
433 right = strip_expr(right->unop);
434 if (right->type != EXPR_SYMBOL)
435 return;
436 sym = get_type(right);
437 if (!sym || sym->type != SYM_FN)
438 return;
440 fn_name = expr_to_var(right);
441 ptr_name = get_fnptr_name(expr->left);
442 if (!fn_name || !ptr_name)
443 goto free;
445 sql_insert_function_ptr(fn_name, ptr_name);
447 free:
448 free_string(fn_name);
449 free_string(ptr_name);
452 static struct expression *call_implies_call_expr;
453 static int call_implies_callbacks(void *unused, int argc, char **argv, char **azColName)
455 struct call_implies_callback *cb;
456 struct expression *arg = NULL;
457 int type;
458 int param;
460 if (argc != 4)
461 return 0;
463 type = atoi(argv[1]);
464 param = atoi(argv[2]);
466 FOR_EACH_PTR(call_implies_cb_list, cb) {
467 if (cb->type != type)
468 continue;
469 if (param != -1) {
470 arg = get_argument_from_call_expr(call_implies_call_expr->args, param);
471 if (!arg)
472 continue;
474 cb->callback(arg, argv[3]);
475 } END_FOR_EACH_PTR(cb);
477 return 0;
480 static void match_call_implies(struct expression *expr)
482 struct symbol *sym;
483 static char sql_filter[1024];
485 if (expr->fn->type != EXPR_SYMBOL)
486 return;
487 sym = expr->fn->symbol;
488 if (!sym)
489 return;
491 if (sym->ctype.modifiers & MOD_STATIC) {
492 snprintf(sql_filter, 1024, "file = '%s' and function = '%s';",
493 get_filename(), sym->ident->name);
494 } else {
495 snprintf(sql_filter, 1024, "function = '%s' and static = 0;",
496 sym->ident->name);
499 call_implies_call_expr = expr;
500 run_sql(call_implies_callbacks,
501 "select function, type, parameter, value from call_implies where %s",
502 sql_filter);
503 return;
506 static void print_initializer_list(struct expression_list *expr_list,
507 struct symbol *struct_type)
509 struct expression *expr;
510 struct symbol *base_type;
511 char struct_name[256];
513 FOR_EACH_PTR(expr_list, expr) {
514 if (expr->type == EXPR_INDEX && expr->idx_expression && expr->idx_expression->type == EXPR_INITIALIZER) {
515 print_initializer_list(expr->idx_expression->expr_list, struct_type);
516 continue;
518 if (expr->type != EXPR_IDENTIFIER)
519 continue;
520 if (!expr->expr_ident)
521 continue;
522 if (!expr->ident_expression || !expr->ident_expression->symbol_name)
523 continue;
524 base_type = get_type(expr->ident_expression);
525 if (!base_type || base_type->type != SYM_FN)
526 continue;
527 snprintf(struct_name, sizeof(struct_name), "(struct %s)->%s",
528 struct_type->ident->name, expr->expr_ident->name);
529 sql_insert_function_ptr(expr->ident_expression->symbol_name->name,
530 struct_name);
531 } END_FOR_EACH_PTR(expr);
534 static void global_variable(struct symbol *sym)
536 struct symbol *struct_type;
538 if (!sym->ident)
539 return;
540 if (!sym->initializer || sym->initializer->type != EXPR_INITIALIZER)
541 return;
542 struct_type = get_base_type(sym);
543 if (!struct_type)
544 return;
545 if (struct_type->type == SYM_ARRAY) {
546 struct_type = get_base_type(struct_type);
547 if (!struct_type)
548 return;
550 if (struct_type->type != SYM_STRUCT || !struct_type->ident)
551 return;
552 print_initializer_list(sym->initializer->expr_list, struct_type);
555 static void match_return_info(int return_id, char *return_ranges, struct expression *expr, struct state_list *slist)
557 sql_insert_return_states(return_id, return_ranges, INTERNAL, -1, "", "");
560 static int return_id;
561 static void match_function_def(struct symbol *sym)
563 return_id = 0;
566 static void call_return_state_hooks_compare(struct expression *expr)
568 struct returned_state_callback *cb;
569 struct state_list *slist;
570 char *return_ranges;
571 int final_pass_orig = final_pass;
573 __push_fake_cur_slist();
575 final_pass = 0;
576 __split_whole_condition(expr);
577 final_pass = final_pass_orig;
579 return_ranges = alloc_sname("1");
581 return_id++;
582 slist = __get_cur_slist();
583 FOR_EACH_PTR(returned_state_callbacks, cb) {
584 cb->callback(return_id, return_ranges, expr, slist);
585 } END_FOR_EACH_PTR(cb);
587 __push_true_states();
588 __use_false_states();
590 return_ranges = alloc_sname("0");;
591 return_id++;
592 slist = __get_cur_slist();
593 FOR_EACH_PTR(returned_state_callbacks, cb) {
594 cb->callback(return_id, return_ranges, expr, slist);
595 } END_FOR_EACH_PTR(cb);
597 __merge_true_states();
598 __pop_fake_cur_slist();
601 static int call_return_state_hooks_split_possible(struct expression *expr)
603 struct returned_state_callback *cb;
604 struct state_list *slist;
605 struct range_list *rl;
606 char *return_ranges;
607 struct sm_state *sm;
608 struct sm_state *tmp;
609 int ret = 0;
610 int nr_possible, nr_states;
612 sm = get_sm_state_expr(SMATCH_EXTRA, expr);
613 if (!sm || !sm->merged)
614 return 0;
616 /* bail if it gets too complicated */
617 nr_possible = ptr_list_size((struct ptr_list *)sm->possible);
618 nr_states = ptr_list_size((struct ptr_list *)__get_cur_slist());
619 if (nr_possible >= 100)
620 return 0;
621 if (nr_states * nr_possible >= 1000)
622 return 0;
624 FOR_EACH_PTR(sm->possible, tmp) {
625 if (tmp->merged)
626 continue;
628 ret = 1;
629 __push_fake_cur_slist();
631 overwrite_states_using_pool(tmp);
633 rl = cast_rl(cur_func_return_type(), estate_rl(tmp->state));
634 return_ranges = show_rl(rl);
636 return_id++;
637 slist = __get_cur_slist();
638 FOR_EACH_PTR(returned_state_callbacks, cb) {
639 cb->callback(return_id, return_ranges, expr, slist);
640 } END_FOR_EACH_PTR(cb);
642 __pop_fake_cur_slist();
643 } END_FOR_EACH_PTR(tmp);
645 return ret;
648 static void call_return_state_hooks(struct expression *expr)
650 struct returned_state_callback *cb;
651 struct state_list *slist;
652 struct range_list *rl;
653 char *return_ranges;
654 int nr_states;
656 expr = strip_expr(expr);
658 if (!expr) {
659 return_ranges = alloc_sname("");
660 } else if (is_condition(expr)) {
661 call_return_state_hooks_compare(expr);
662 return;
663 } else if (call_return_state_hooks_split_possible(expr)) {
664 return;
665 } else if (get_implied_rl(expr, &rl)) {
666 rl = cast_rl(cur_func_return_type(), rl);
667 return_ranges = show_rl(rl);
668 } else {
669 rl = alloc_whole_rl(cur_func_return_type());
670 return_ranges = show_rl(rl);
673 return_id++;
674 slist = __get_cur_slist();
675 nr_states = ptr_list_size((struct ptr_list *)__get_cur_slist());
676 FOR_EACH_PTR(returned_state_callbacks, cb) {
677 if (nr_states < 10000)
678 cb->callback(return_id, return_ranges, expr, slist);
679 else
680 cb->callback(return_id, return_ranges, expr, NULL);
681 } END_FOR_EACH_PTR(cb);
684 static void print_returned_struct_members(int return_id, char *return_ranges, struct expression *expr, struct state_list *slist)
686 struct returned_member_callback *cb;
687 struct state_list *my_slist;
688 struct sm_state *sm;
689 struct symbol *type;
690 char *name;
691 char member_name[256];
692 int len;
694 type = get_type(expr);
695 if (!type || type->type != SYM_PTR)
696 return;
697 type = get_real_base_type(type);
698 if (!type || type->type != SYM_STRUCT)
699 return;
700 name = expr_to_var(expr);
701 if (!name)
702 return;
704 member_name[sizeof(member_name) - 1] = '\0';
705 strcpy(member_name, "$$");
707 len = strlen(name);
708 FOR_EACH_PTR(returned_member_callbacks, cb) {
709 my_slist = get_all_states_slist(cb->owner, slist);
710 FOR_EACH_PTR(my_slist, sm) {
711 if (strncmp(sm->name, name, len) != 0)
712 continue;
713 if (strncmp(sm->name + len, "->", 2) != 0)
714 continue;
715 strncpy(member_name + 2, sm->name + len, sizeof(member_name) - 2);
716 cb->callback(return_id, return_ranges, member_name, sm->state);
717 } END_FOR_EACH_PTR(sm);
718 free_slist(&my_slist);
719 } END_FOR_EACH_PTR(cb);
721 free_string(name);
724 static void match_end_func_info(struct symbol *sym)
726 if (__path_is_null())
727 return;
728 call_return_state_hooks(NULL);
731 void open_smatch_db(void)
733 #ifdef SQLITE_OPEN_READONLY
734 int rc;
736 if (option_no_db)
737 return;
739 rc = sqlite3_open_v2("smatch_db.sqlite", &db, SQLITE_OPEN_READONLY, NULL);
740 if (rc != SQLITE_OK) {
741 option_no_db = 1;
742 return;
744 return;
745 #else
746 option_no_db = 1;
747 return;
748 #endif
751 void register_definition_db_callbacks(int id)
753 add_hook(&match_function_def, FUNC_DEF_HOOK);
755 if (option_info) {
756 add_hook(&match_call_info, FUNCTION_CALL_HOOK);
757 add_hook(&match_call_hack, FUNCTION_CALL_HOOK);
758 add_hook(&match_function_assign, ASSIGNMENT_HOOK);
759 add_hook(&match_function_assign, GLOBAL_ASSIGNMENT_HOOK);
760 add_hook(&global_variable, BASE_HOOK);
761 add_hook(&global_variable, DECLARATION_HOOK);
762 add_returned_state_callback(match_return_info);
763 add_returned_state_callback(print_returned_struct_members);
764 add_hook(&call_return_state_hooks, RETURN_HOOK);
765 add_hook(&match_end_func_info, END_FUNC_HOOK);
768 if (option_no_db)
769 return;
771 add_hook(&match_data_from_db, FUNC_DEF_HOOK);
772 add_hook(&match_call_implies, FUNCTION_CALL_HOOK);
775 char *get_variable_from_key(struct expression *arg, char *key, struct symbol **sym)
777 char buf[256];
778 char *tmp;
780 if (strcmp(key, "$$") == 0)
781 return expr_to_var_sym(arg, sym);
783 if (strcmp(key, "*$$") == 0) {
784 if (arg->type == EXPR_PREOP && arg->op == '&') {
785 arg = strip_expr(arg->unop);
786 return expr_to_var_sym(arg, sym);
787 } else {
788 tmp = expr_to_var_sym(arg, sym);
789 if (!tmp)
790 return NULL;
791 snprintf(buf, sizeof(buf), "*%s", tmp);
792 free_string(tmp);
793 return alloc_string(buf);
797 if (arg->type == EXPR_PREOP && arg->op == '&') {
798 arg = strip_expr(arg->unop);
799 tmp = expr_to_var_sym(arg, sym);
800 if (!tmp)
801 return NULL;
802 snprintf(buf, sizeof(buf), "%s.%s", tmp, key + 4);
803 return alloc_string(buf);
806 tmp = expr_to_var_sym(arg, sym);
807 if (!tmp)
808 return NULL;
809 snprintf(buf, sizeof(buf), "%s%s", tmp, key + 2);
810 free_string(tmp);
811 return alloc_string(buf);