1*1f5207b7SJohn Levon /*
2*1f5207b7SJohn Levon  * Copyright (C) 2014 Oracle.
3*1f5207b7SJohn Levon  *
4*1f5207b7SJohn Levon  * This program is free software; you can redistribute it and/or
5*1f5207b7SJohn Levon  * modify it under the terms of the GNU General Public License
6*1f5207b7SJohn Levon  * as published by the Free Software Foundation; either version 2
7*1f5207b7SJohn Levon  * of the License, or (at your option) any later version.
8*1f5207b7SJohn Levon  *
9*1f5207b7SJohn Levon  * This program is distributed in the hope that it will be useful,
10*1f5207b7SJohn Levon  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*1f5207b7SJohn Levon  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*1f5207b7SJohn Levon  * GNU General Public License for more details.
13*1f5207b7SJohn Levon  *
14*1f5207b7SJohn Levon  * You should have received a copy of the GNU General Public License
15*1f5207b7SJohn Levon  * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16*1f5207b7SJohn Levon  */
17*1f5207b7SJohn Levon 
18*1f5207b7SJohn Levon /*
19*1f5207b7SJohn Levon  * The plan here is to save all the possible values store to a given struct
20*1f5207b7SJohn Levon  * member.
21*1f5207b7SJohn Levon  *
22*1f5207b7SJohn Levon  * We will load all the values in to the function_type_val table first then
23*1f5207b7SJohn Levon  * run a script on that and load all the resulting values into the type_val
24*1f5207b7SJohn Levon  * table.
25*1f5207b7SJohn Levon  *
26*1f5207b7SJohn Levon  * So in this file we want to take the union of everything assigned to the
27*1f5207b7SJohn Levon  * struct member and insert it into the function_type_val at the end.
28*1f5207b7SJohn Levon  *
29*1f5207b7SJohn Levon  * You would think that we could use smatch_modification_hooks.c or
30*1f5207b7SJohn Levon  * extra_modification_hook() here to get the information here but in the end we
31*1f5207b7SJohn Levon  * need to code everything again a third time.
32*1f5207b7SJohn Levon  *
33*1f5207b7SJohn Levon  */
34*1f5207b7SJohn Levon 
35*1f5207b7SJohn Levon /*
36*1f5207b7SJohn Levon  * Remember links like:
37*1f5207b7SJohn Levon  *
38*1f5207b7SJohn Levon  * foo->void_ptr = some_struct.
39*1f5207b7SJohn Levon  *
40*1f5207b7SJohn Levon  * If we get a some_struct pointer from foo->void_ptr then assume it's the same
41*1f5207b7SJohn Levon  * stuff.
42*1f5207b7SJohn Levon  */
43*1f5207b7SJohn Levon 
44*1f5207b7SJohn Levon #include "smatch.h"
45*1f5207b7SJohn Levon #include "smatch_slist.h"
46*1f5207b7SJohn Levon #include "smatch_extra.h"
47*1f5207b7SJohn Levon 
48*1f5207b7SJohn Levon static int my_id;
49*1f5207b7SJohn Levon 
match_assign(struct expression * expr)50*1f5207b7SJohn Levon static void match_assign(struct expression *expr)
51*1f5207b7SJohn Levon {
52*1f5207b7SJohn Levon 	struct symbol *type;
53*1f5207b7SJohn Levon 
54*1f5207b7SJohn Levon 	if (!is_void_pointer(expr->left))
55*1f5207b7SJohn Levon 		return;
56*1f5207b7SJohn Levon 
57*1f5207b7SJohn Levon 	type = get_type(expr->right);
58*1f5207b7SJohn Levon 	if (!type || type->type != SYM_PTR)
59*1f5207b7SJohn Levon 		return;
60*1f5207b7SJohn Levon 	type = get_real_base_type(type);
61*1f5207b7SJohn Levon 	if (!type || type->type != SYM_STRUCT)
62*1f5207b7SJohn Levon 		return;
63*1f5207b7SJohn Levon 
64*1f5207b7SJohn Levon 	sql_insert_data_info(expr->left, TYPE_LINK, type_to_str(type));
65*1f5207b7SJohn Levon }
66*1f5207b7SJohn Levon 
register_type_links(int id)67*1f5207b7SJohn Levon void register_type_links(int id)
68*1f5207b7SJohn Levon {
69*1f5207b7SJohn Levon 	if (!option_info)
70*1f5207b7SJohn Levon 		return;
71*1f5207b7SJohn Levon 	my_id = id;
72*1f5207b7SJohn Levon 
73*1f5207b7SJohn Levon 	add_hook(&match_assign, ASSIGNMENT_HOOK);
74*1f5207b7SJohn Levon }
75