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
)
29 struct sm_state
*orig
, *cur
;
33 name
= expr_to_var_sym(expr
, &sym
);
36 param
= get_param_num_from_sym(sym
);
39 cur
= get_sm_state(SMATCH_EXTRA
, name
, sym
);
42 orig
= get_sm_state_slist(get_start_states(), SMATCH_EXTRA
, name
, sym
);
48 snprintf(buf
, sizeof(buf
), "p %d", param
);
49 ret
= alloc_string(buf
);
56 static char *get_source_assignment(struct expression
*expr
)
58 struct expression
*right
;
63 right
= get_assigned_expr(expr
);
64 right
= strip_expr(right
);
67 if (right
->type
!= EXPR_CALL
|| right
->fn
->type
!= EXPR_SYMBOL
)
69 if (is_fake_call(right
))
71 name
= expr_to_str(right
->fn
);
74 snprintf(buf
, sizeof(buf
), "r %s", name
);
75 ret
= alloc_string(buf
);
80 static char *get_source_str(struct expression
*expr
)
84 source
= get_source_parameter(expr
);
87 return get_source_assignment(expr
);
90 static void match_caller_info(struct expression
*expr
)
92 struct expression
*tmp
;
97 FOR_EACH_PTR(expr
->args
, tmp
) {
99 source
= get_source_str(tmp
);
102 sql_insert_caller_info(expr
, DATA_SOURCE
, i
, "$$", source
);
104 } END_FOR_EACH_PTR(tmp
);
107 void register_data_source(int id
)
112 add_hook(&match_caller_info
, FUNCTION_CALL_HOOK
);