7 * of the License, or (at your option) any later version.
8 *
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.
13 *
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
16 */
17
18 #include "smatch.h"
19 #include "smatch_slist.h"
20 #include "smatch_extra.h"
21
22 static int my_id;
23
24 static char *get_source_parameter(struct expression *expr)
25 {
26 struct expression *tmp;
27 struct symbol *sym;
28 char *name;
29 int param;
30 char *ret = NULL;
31 char buf[32];
32 int cnt = 0;
33
34 tmp = expr;
35 while ((tmp = get_assigned_expr(tmp))) {
36 expr = tmp;
37 if (cnt++ > 3)
38 break;
39 }
40
41 expr = strip_expr(expr);
42 if (expr->type != EXPR_SYMBOL)
43 return NULL;
44
45 name = expr_to_var_sym(expr, &sym);
46 if (!name || !sym)
47 goto free;
48 param = get_param_num_from_sym(sym);
49 if (param < 0)
50 goto free;
51 if (param_was_set(expr))
52 goto free;
53
54 snprintf(buf, sizeof(buf), "p %d", param);
55 ret = alloc_string(buf);
56
57 free:
58 free_string(name);
59 return ret;
60 }
61
62 static char *get_source_assignment(struct expression *expr)
63 {
64 struct expression *right;
65 char *name;
66 char buf[64];
67 char *ret;
68
69 right = get_assigned_expr(expr);
70 right = strip_expr(right);
71 if (!right)
72 return NULL;
73 if (right->type != EXPR_CALL || right->fn->type != EXPR_SYMBOL)
74 return NULL;
|
7 * of the License, or (at your option) any later version.
8 *
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.
13 *
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
16 */
17
18 #include "smatch.h"
19 #include "smatch_slist.h"
20 #include "smatch_extra.h"
21
22 static int my_id;
23
24 static char *get_source_parameter(struct expression *expr)
25 {
26 struct expression *tmp;
27 const char *param_name;
28 struct symbol *sym;
29 char *name;
30 int param;
31 char *ret = NULL;
32 char buf[32];
33 int cnt = 0;
34 bool modified = false;
35
36 tmp = expr;
37 while ((tmp = get_assigned_expr(tmp))) {
38 expr = tmp;
39 if (cnt++ > 3)
40 break;
41 }
42
43 expr = strip_expr(expr);
44 if (expr->type != EXPR_SYMBOL)
45 return NULL;
46
47 name = expr_to_var_sym(expr, &sym);
48 if (!name || !sym)
49 goto free;
50 param = get_param_num_from_sym(sym);
51 if (param < 0)
52 goto free;
53 param_name = get_param_name_var_sym(name, sym);
54 if (!param_name)
55 goto free;
56 if (param_was_set_var_sym(name, sym))
57 modified = true;
58
59 snprintf(buf, sizeof(buf), "$%d%s%s", param, param_name + 1,
60 modified ? " [m]" : "");
61 ret = alloc_string(buf);
62
63 free:
64 free_string(name);
65 return ret;
66 }
67
68 static char *get_source_assignment(struct expression *expr)
69 {
70 struct expression *right;
71 char *name;
72 char buf[64];
73 char *ret;
74
75 right = get_assigned_expr(expr);
76 right = strip_expr(right);
77 if (!right)
78 return NULL;
79 if (right->type != EXPR_CALL || right->fn->type != EXPR_SYMBOL)
80 return NULL;
|