stored_conditions: store comparisons and not logicals
[smatch.git] / check_assigned_expr.c
blobe9aa7ad3a00d1bee63cc324d4d6f820265c234b4
1 /*
2 * Copyright (C) 2009 Dan Carpenter.
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 * This is not a check. It just saves an struct expression pointer
20 * whenever something is assigned. This can be used later on by other scripts.
23 #include "smatch.h"
24 #include "smatch_slist.h"
26 int check_assigned_expr_id;
27 static int my_id;
29 struct expression *get_assigned_expr(struct expression *expr)
31 struct smatch_state *state;
33 state = get_state_expr(my_id, expr);
34 if (!state)
35 return NULL;
36 return (struct expression *)state->data;
39 static struct smatch_state *alloc_my_state(struct expression *expr)
41 struct smatch_state *state;
42 char *name;
44 state = __alloc_smatch_state(0);
45 expr = strip_expr(expr);
46 name = expr_to_str(expr);
47 state->name = alloc_sname(name);
48 free_string(name);
49 state->data = expr;
50 return state;
53 static void match_assignment(struct expression *expr)
55 if (expr->op != '=')
56 return;
57 set_state_expr(my_id, expr->left, alloc_my_state(expr->right));
60 void check_assigned_expr(int id)
62 my_id = check_assigned_expr_id = id;
63 add_hook(&match_assignment, ASSIGNMENT_HOOK);