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"
12 #include "smatch_extra.h"
16 static char *get_source_parameter(struct expression
*expr
)
21 struct sm_state
*orig
, *cur
;
25 name
= expr_to_var_sym(expr
, &sym
);
28 param
= get_param_num_from_sym(sym
);
31 cur
= get_sm_state(SMATCH_EXTRA
, name
, sym
);
34 orig
= get_sm_state_slist(get_start_states(), SMATCH_EXTRA
, name
, sym
);
40 snprintf(buf
, sizeof(buf
), "p %d", param
);
41 ret
= alloc_string(buf
);
48 static char *get_source_assignment(struct expression
*expr
)
50 struct expression
*right
;
55 right
= get_assigned_expr(expr
);
56 right
= strip_expr(right
);
59 if (right
->type
!= EXPR_CALL
|| right
->fn
->type
!= EXPR_SYMBOL
)
61 if (is_fake_call(right
))
63 name
= expr_to_str(right
->fn
);
66 snprintf(buf
, sizeof(buf
), "r %s", name
);
67 ret
= alloc_string(buf
);
72 static char *get_source_str(struct expression
*expr
)
76 source
= get_source_parameter(expr
);
79 return get_source_assignment(expr
);
82 static void match_caller_info(struct expression
*expr
)
84 struct expression
*tmp
;
89 FOR_EACH_PTR(expr
->args
, tmp
) {
91 source
= get_source_str(tmp
);
94 sql_insert_caller_info(expr
, DATA_SOURCE
, i
, "$$", source
);
96 } END_FOR_EACH_PTR(tmp
);
99 void register_data_source(int id
)
104 add_hook(&match_caller_info
, FUNCTION_CALL_HOOK
);