function_ptrs: separate into its own file
[smatch.git] / smatch_function_ptrs.c
blobe1502383b39b25e589777f65b317fd90a7534d50
1 /*
2 * smatch/smatch_function_ptrs.c
4 * Copyright (C) 2013 Oracle.
6 * Licensed under the Open Software License version 1.1
8 */
11 * Track how functions are saved as various struct members or passed as
12 * parameters.
16 #include "smatch.h"
17 #include "smatch_slist.h"
19 static int my_id;
21 static void match_function_assign(struct expression *expr)
23 struct expression *right = expr->right;
24 struct symbol *sym;
25 char *fn_name;
26 char *ptr_name;
28 if (right->type == EXPR_PREOP && right->op == '&')
29 right = strip_expr(right->unop);
30 if (right->type != EXPR_SYMBOL)
31 return;
32 sym = get_type(right);
33 if (!sym || sym->type != SYM_FN)
34 return;
36 fn_name = expr_to_var(right);
37 ptr_name = get_fnptr_name(expr->left);
38 if (!fn_name || !ptr_name)
39 goto free;
41 sql_insert_function_ptr(fn_name, ptr_name);
43 free:
44 free_string(fn_name);
45 free_string(ptr_name);
48 void register_function_ptrs(int id)
50 my_id = id;
52 if (!option_info)
53 return;
55 add_hook(&match_function_assign, ASSIGNMENT_HOOK);