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