2 * smatch/smatch_data_source.c
4 * Copyright (C) 2013 Oracle.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_slist.h"
15 static char *get_source_parameter(struct expression
*expr
)
20 struct sm_state
*orig
, *cur
;
24 name
= expr_to_var_sym(expr
, &sym
);
27 param
= get_param_num_from_sym(sym
);
30 cur
= get_sm_state(SMATCH_EXTRA
, name
, sym
);
33 orig
= get_sm_state_slist(get_start_states(), SMATCH_EXTRA
, name
, sym
);
39 snprintf(buf
, sizeof(buf
), "p %d", param
);
40 ret
= alloc_string(buf
);
47 static char *get_source_assignment(struct expression
*expr
)
49 struct expression
*right
;
54 right
= get_assigned_expr(expr
);
55 right
= strip_expr(right
);
58 if (right
->type
!= EXPR_CALL
|| right
->fn
->type
!= EXPR_SYMBOL
)
60 name
= expr_to_str(right
->fn
);
63 snprintf(buf
, sizeof(buf
), "r %s", name
);
64 ret
= alloc_string(buf
);
69 static char *get_source_str(struct expression
*expr
)
73 source
= get_source_parameter(expr
);
76 return get_source_assignment(expr
);
79 static void match_caller_info(struct expression
*expr
)
81 struct expression
*tmp
;
86 FOR_EACH_PTR(expr
->args
, tmp
) {
88 source
= get_source_str(tmp
);
91 sql_insert_caller_info(expr
, DATA_SOURCE
, i
, "$$", source
);
93 } END_FOR_EACH_PTR(tmp
);
96 void register_data_source(int id
)
101 add_hook(&match_caller_info
, FUNCTION_CALL_HOOK
);