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
;
43 case ASSIGNMENT_AFTER_HOOK
:
44 container
->data_type
= EXPR_HOOK
;
47 container
->data_type
= EXPR_HOOK
;
49 case WHOLE_CONDITION_HOOK
:
50 container
->data_type
= EXPR_HOOK
;
52 case FUNCTION_CALL_HOOK
:
53 container
->data_type
= EXPR_HOOK
;
55 case FUNCTION_CALL_AFTER_HOOK
:
56 container
->data_type
= EXPR_HOOK
;
59 container
->data_type
= EXPR_HOOK
;
62 container
->data_type
= SYM_HOOK
;
65 container
->data_type
= SYM_HOOK
;
68 container
->data_type
= SYM_HOOK
;
71 container
->data_type
= STMT_HOOK
;
74 add_ptr_list(&hook_funcs
, container
);
77 void add_merge_hook(int client_id
, merge_func_t
*func
)
79 struct hook_container
*container
= __alloc_hook_container(0);
80 container
->data_type
= client_id
;
82 add_ptr_list(&merge_funcs
, container
);
86 static void pass_expr_to_client(void * fn
, void * data
)
88 typedef void (expr_func
)(struct expression
*expr
);
89 ((expr_func
*) fn
)((struct expression
*) data
);
92 static void pass_stmt_to_client(void * fn
, void * data
)
94 typedef void (stmt_func
)(struct statement
*stmt
);
95 ((stmt_func
*) fn
)((struct statement
*) data
);
98 static void pass_sym_to_client(void * fn
, void * data
)
100 typedef void (sym_func
)(struct symbol
*sym
);
101 ((sym_func
*) fn
)((struct symbol
*) data
);
104 void __pass_to_client(void *data
, enum hook_type type
)
106 struct hook_container
*container
;
111 FOR_EACH_PTR(hook_funcs
, container
) {
112 if (container
->hook_type
== type
) {
113 switch(container
->data_type
) {
115 pass_expr_to_client(container
->fn
, data
);
118 pass_stmt_to_client(container
->fn
, data
);
121 pass_sym_to_client(container
->fn
, data
);
125 } END_FOR_EACH_PTR(container
);
128 void __pass_declarations_to_client(struct symbol_list
*sym_list
)
131 FOR_EACH_PTR(sym_list
, sym
) {
132 __pass_to_client(sym
, DECLARATION_HOOK
);
133 } END_FOR_EACH_PTR(sym
);
136 int __has_merge_function(int client_id
)
138 struct hook_container
*tmp
;
140 FOR_EACH_PTR(merge_funcs
, tmp
) {
141 if (tmp
->data_type
== client_id
)
143 } END_FOR_EACH_PTR(tmp
);
147 int __client_merge_function(int owner
, const char *name
, struct symbol
*sym
,
150 struct hook_container
*tmp
;
152 FOR_EACH_PTR(merge_funcs
, tmp
) {
153 if (tmp
->data_type
== owner
)
154 return ((merge_func_t
*) tmp
->fn
)(name
, sym
, s1
, s2
);
155 } END_FOR_EACH_PTR(tmp
);