2 * sparse/smatch_hooks.c
4 * Copyright (C) 2006 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
12 struct hook_container
{
17 ALLOCATOR(hook_container
, "hook functions");
18 DECLARE_PTR_LIST(hook_func_list
, struct hook_container
);
19 static struct hook_func_list
*hook_funcs
;
20 static struct hook_func_list
*merge_funcs
;
22 void add_hook(void *func
, enum hook_type type
)
24 struct hook_container
*container
= __alloc_hook_container(0);
25 container
->hook_type
= type
;
29 container
->data_type
= EXPR_HOOK
;
32 container
->data_type
= STMT_HOOK
;
35 container
->data_type
= SYM_HOOK
;
37 case DECLARATION_HOOK
:
38 container
->data_type
= SYM_HOOK
;
41 container
->data_type
= EXPR_HOOK
;
44 container
->data_type
= EXPR_HOOK
;
46 case ASSIGNMENT_AFTER_HOOK
:
47 container
->data_type
= EXPR_HOOK
;
50 container
->data_type
= EXPR_HOOK
;
52 case WHOLE_CONDITION_HOOK
:
53 container
->data_type
= EXPR_HOOK
;
55 case FUNCTION_CALL_HOOK
:
56 container
->data_type
= EXPR_HOOK
;
58 case FUNCTION_CALL_AFTER_HOOK
:
59 container
->data_type
= EXPR_HOOK
;
62 container
->data_type
= EXPR_HOOK
;
65 container
->data_type
= SYM_HOOK
;
68 container
->data_type
= SYM_HOOK
;
71 container
->data_type
= SYM_HOOK
;
74 container
->data_type
= STMT_HOOK
;
77 add_ptr_list(&hook_funcs
, container
);
80 void add_merge_hook(int client_id
, merge_func_t
*func
)
82 struct hook_container
*container
= __alloc_hook_container(0);
83 container
->data_type
= client_id
;
85 add_ptr_list(&merge_funcs
, container
);
89 static void pass_expr_to_client(void * fn
, void * data
)
91 typedef void (expr_func
)(struct expression
*expr
);
92 ((expr_func
*) fn
)((struct expression
*) data
);
95 static void pass_stmt_to_client(void * fn
, void * data
)
97 typedef void (stmt_func
)(struct statement
*stmt
);
98 ((stmt_func
*) fn
)((struct statement
*) data
);
101 static void pass_sym_to_client(void * fn
, void * data
)
103 typedef void (sym_func
)(struct symbol
*sym
);
104 ((sym_func
*) fn
)((struct symbol
*) data
);
107 void __pass_to_client(void *data
, enum hook_type type
)
109 struct hook_container
*container
;
114 FOR_EACH_PTR(hook_funcs
, container
) {
115 if (container
->hook_type
== type
) {
116 switch(container
->data_type
) {
118 pass_expr_to_client(container
->fn
, data
);
121 pass_stmt_to_client(container
->fn
, data
);
124 pass_sym_to_client(container
->fn
, data
);
128 } END_FOR_EACH_PTR(container
);
131 void __pass_declarations_to_client(struct symbol_list
*sym_list
)
134 FOR_EACH_PTR(sym_list
, sym
) {
135 __pass_to_client(sym
, DECLARATION_HOOK
);
136 } END_FOR_EACH_PTR(sym
);
139 int __has_merge_function(int client_id
)
141 struct hook_container
*tmp
;
143 FOR_EACH_PTR(merge_funcs
, tmp
) {
144 if (tmp
->data_type
== client_id
)
146 } END_FOR_EACH_PTR(tmp
);
150 int __client_merge_function(int owner
, const char *name
, struct symbol
*sym
,
153 struct hook_container
*tmp
;
155 FOR_EACH_PTR(merge_funcs
, tmp
) {
156 if (tmp
->data_type
== owner
)
157 return ((merge_func_t
*) tmp
->fn
)(name
, sym
, s1
, s2
);
158 } END_FOR_EACH_PTR(tmp
);