11f5207b7SJohn Levon /* 21f5207b7SJohn Levon * Copyright (C) 2009 Dan Carpenter. 31f5207b7SJohn Levon * 41f5207b7SJohn Levon * This program is free software; you can redistribute it and/or 51f5207b7SJohn Levon * modify it under the terms of the GNU General Public License 61f5207b7SJohn Levon * as published by the Free Software Foundation; either version 2 71f5207b7SJohn Levon * of the License, or (at your option) any later version. 81f5207b7SJohn Levon * 91f5207b7SJohn Levon * This program is distributed in the hope that it will be useful, 101f5207b7SJohn Levon * but WITHOUT ANY WARRANTY; without even the implied warranty of 111f5207b7SJohn Levon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 121f5207b7SJohn Levon * GNU General Public License for more details. 131f5207b7SJohn Levon * 141f5207b7SJohn Levon * You should have received a copy of the GNU General Public License 151f5207b7SJohn Levon * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt 161f5207b7SJohn Levon */ 171f5207b7SJohn Levon 181f5207b7SJohn Levon /* 191f5207b7SJohn Levon * The idea behind this test is that if we have: 201f5207b7SJohn Levon * void foo(int bar) 211f5207b7SJohn Levon * { 221f5207b7SJohn Levon * baz(1, bar); 231f5207b7SJohn Levon * } 241f5207b7SJohn Levon * 251f5207b7SJohn Levon * Passing "bar" to foo() really means passing "bar" to baz(); 26*5a0e240fSJohn Levon * 271f5207b7SJohn Levon * In this case it would print: 281f5207b7SJohn Levon * info: param_mapper 0 => bar 1 291f5207b7SJohn Levon * 301f5207b7SJohn Levon */ 311f5207b7SJohn Levon 321f5207b7SJohn Levon #include "smatch.h" 331f5207b7SJohn Levon 341f5207b7SJohn Levon static int my_id; 351f5207b7SJohn Levon match_call(struct expression * expr)361f5207b7SJohn Levonstatic void match_call(struct expression *expr) 371f5207b7SJohn Levon { 381f5207b7SJohn Levon struct expression *tmp; 391f5207b7SJohn Levon char *func; 401f5207b7SJohn Levon int arg_num; 411f5207b7SJohn Levon int i; 421f5207b7SJohn Levon 431f5207b7SJohn Levon if (expr->fn->type != EXPR_SYMBOL) 441f5207b7SJohn Levon return; 451f5207b7SJohn Levon 461f5207b7SJohn Levon func = expr->fn->symbol_name->name; 471f5207b7SJohn Levon 48*5a0e240fSJohn Levon i = -1; 491f5207b7SJohn Levon FOR_EACH_PTR(expr->args, tmp) { 501f5207b7SJohn Levon i++; 51*5a0e240fSJohn Levon tmp = strip_expr(tmp); 52*5a0e240fSJohn Levon if (tmp->type != EXPR_SYMBOL) 53*5a0e240fSJohn Levon continue; 54*5a0e240fSJohn Levon if (param_was_set(tmp)) 55*5a0e240fSJohn Levon continue; 56*5a0e240fSJohn Levon arg_num = get_param_num_from_sym(tmp->symbol); 57*5a0e240fSJohn Levon if (arg_num < 0) 58*5a0e240fSJohn Levon continue; 59*5a0e240fSJohn Levon sm_msg("info: param_mapper %d => %s %d", arg_num, func, i); 601f5207b7SJohn Levon } END_FOR_EACH_PTR(tmp); 611f5207b7SJohn Levon } 621f5207b7SJohn Levon check_param_mapper(int id)631f5207b7SJohn Levonvoid check_param_mapper(int id) 641f5207b7SJohn Levon { 65*5a0e240fSJohn Levon if (!option_info) 661f5207b7SJohn Levon return; 671f5207b7SJohn Levon my_id = id; 681f5207b7SJohn Levon add_hook(&match_call, FUNCTION_CALL_HOOK); 691f5207b7SJohn Levon } 70