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
;
35 while ((tmp
= get_assigned_expr(tmp
))) {
41 expr
= strip_expr(expr
);
42 if (expr
->type
!= EXPR_SYMBOL
)
45 name
= expr_to_var_sym(expr
, &sym
);
48 param
= get_param_num_from_sym(sym
);
51 if (param_was_set(expr
))
54 snprintf(buf
, sizeof(buf
), "p %d", param
);
55 ret
= alloc_string(buf
);
62 static char *get_source_assignment(struct expression
*expr
)
64 struct expression
*right
;
69 right
= get_assigned_expr(expr
);
70 right
= strip_expr(right
);
73 if (right
->type
!= EXPR_CALL
|| right
->fn
->type
!= EXPR_SYMBOL
)
75 if (is_fake_call(right
))
77 name
= expr_to_str(right
->fn
);
80 snprintf(buf
, sizeof(buf
), "r %s", name
);
81 ret
= alloc_string(buf
);
86 static char *get_source_str(struct expression
*arg
)
90 source
= get_source_parameter(arg
);
93 return get_source_assignment(arg
);
96 static void match_caller_info(struct expression
*expr
)
98 struct expression
*arg
;
103 FOR_EACH_PTR(expr
->args
, arg
) {
105 source
= get_source_str(arg
);
108 sql_insert_caller_info(expr
, DATA_SOURCE
, i
, "$", source
);
110 } END_FOR_EACH_PTR(arg
);
113 void register_data_source(int id
)
118 add_hook(&match_caller_info
, FUNCTION_CALL_HOOK
);