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
)
32 expr
= strip_expr(expr
);
33 if (expr
->type
!= EXPR_SYMBOL
)
36 name
= expr_to_var_sym(expr
, &sym
);
39 param
= get_param_num_from_sym(sym
);
42 if (param_was_set(expr
))
45 snprintf(buf
, sizeof(buf
), "p %d", param
);
46 ret
= alloc_string(buf
);
53 static char *get_source_assignment(struct expression
*expr
)
55 struct expression
*right
;
60 right
= get_assigned_expr(expr
);
61 right
= strip_expr(right
);
64 if (right
->type
!= EXPR_CALL
|| right
->fn
->type
!= EXPR_SYMBOL
)
66 if (is_fake_call(right
))
68 name
= expr_to_str(right
->fn
);
71 snprintf(buf
, sizeof(buf
), "r %s", name
);
72 ret
= alloc_string(buf
);
77 static char *get_source_str(struct expression
*expr
)
81 source
= get_source_parameter(expr
);
84 return get_source_assignment(expr
);
87 static void match_caller_info(struct expression
*expr
)
89 struct expression
*tmp
;
94 FOR_EACH_PTR(expr
->args
, tmp
) {
96 source
= get_source_str(tmp
);
99 sql_insert_caller_info(expr
, DATA_SOURCE
, i
, "$", source
);
101 } END_FOR_EACH_PTR(tmp
);
104 void register_data_source(int id
)
109 add_hook(&match_caller_info
, FUNCTION_CALL_HOOK
);