2 * sparse/check_assigned_expr.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 * This is not a check. It just saves an struct expression pointer
12 * whenever something is assigned. This can be used later on by other scripts.
16 #include "smatch_slist.h"
18 int check_assigned_expr_id
;
21 struct expression
*get_assigned_expr(struct expression
*expr
)
23 struct smatch_state
*state
;
25 state
= get_state_expr(my_id
, expr
);
28 return (struct expression
*)state
->data
;
31 static struct smatch_state
*alloc_my_state(struct expression
*expr
)
33 struct smatch_state
*state
;
36 state
= __alloc_smatch_state(0);
37 expr
= strip_expr(expr
);
38 name
= get_variable_from_expr_complex(expr
, NULL
);
39 state
->name
= alloc_sname(name
);
45 static void match_assignment(struct expression
*expr
)
49 set_state_expr(my_id
, expr
->left
, alloc_my_state(expr
->right
));
52 void check_assigned_expr(int id
)
54 my_id
= check_assigned_expr_id
= id
;
55 add_hook(&match_assignment
, ASSIGNMENT_HOOK
);