2 * Copyright (C) 2013 Oracle.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 #include "smatch_slist.h"
20 #include "smatch_extra.h"
24 static char *get_source_parameter(struct expression
*expr
)
26 struct expression
*tmp
;
27 const char *param_name
;
34 bool modified
= false;
37 while ((tmp
= get_assigned_expr(tmp
))) {
43 expr
= strip_expr(expr
);
44 if (expr
->type
!= EXPR_SYMBOL
)
47 name
= expr_to_var_sym(expr
, &sym
);
50 param
= get_param_num_from_sym(sym
);
53 param_name
= get_param_name_var_sym(name
, sym
);
56 if (param_was_set_var_sym(name
, sym
))
59 snprintf(buf
, sizeof(buf
), "$%d%s%s", param
, param_name
+ 1,
60 modified
? " [m]" : "");
61 ret
= alloc_string(buf
);
68 static char *get_source_assignment(struct expression
*expr
)
70 struct expression
*right
;
75 right
= get_assigned_expr(expr
);
76 right
= strip_expr(right
);
79 if (right
->type
!= EXPR_CALL
|| right
->fn
->type
!= EXPR_SYMBOL
)
81 if (is_fake_call(right
))
83 name
= expr_to_str(right
->fn
);
86 snprintf(buf
, sizeof(buf
), "r %s", name
);
87 ret
= alloc_string(buf
);
92 static char *get_source_str(struct expression
*arg
)
96 source
= get_source_parameter(arg
);
99 return get_source_assignment(arg
);
102 static void match_caller_info(struct expression
*expr
)
104 struct expression
*arg
;
109 FOR_EACH_PTR(expr
->args
, arg
) {
111 source
= get_source_str(arg
);
114 sql_insert_caller_info(expr
, DATA_SOURCE
, i
, "$", source
);
116 } END_FOR_EACH_PTR(arg
);
119 void register_data_source(int id
)
124 add_hook(&match_caller_info
, FUNCTION_CALL_HOOK
);