From f4f4ccacbea644e73a5f545cb07b76a0172308ae Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sun, 5 Apr 2009 21:59:45 +0300 Subject: [PATCH] Add CASE_HOOK. This is going to be used by smatch_extra and smatch_implied. Signed-off-by: Dan Carpenter --- Makefile | 6 +++++- smatch.h | 3 +++ smatch_flow.c | 8 +++++++- smatch_hooks.c | 17 +++++++++++++++++ smatch_slist.c | 2 +- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a7be884b..6d77c51f 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,10 @@ PKGCONFIGDIR=$(LIBDIR)/pkgconfig PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse test-linearize example \ test-unssa test-dissect ctags smatch -SMATCH_FILES=smatch_flow.o smatch_conditions.o smatch_slist.o smatch_states.o smatch_helper.o smatch_hooks.o smatch_function_hooks.o smatch_extra.o smatch_extra_helper.o smatch_implied.o smatch_ignore.o smatch_tracker.o smatch_files.o +SMATCH_FILES=smatch_flow.o smatch_conditions.o smatch_slist.o smatch_states.o \ + smatch_helper.o smatch_hooks.o smatch_function_hooks.o smatch_extra.o \ + smatch_extra_helper.o smatch_implied.o smatch_ignore.o \ + smatch_tracker.o smatch_files.o smatch_expression_stacks.o SMATCH_CHECKS=$(shell ls check_*.c | sed -e 's/\.c/.o/') @@ -181,6 +184,7 @@ smatch_function_hooks.o: $(LIB_H) smatch.h smatch_helper.o: $(LIB_H) smatch.h smatch_slist.o: $(LIB_H) smatch.h smatch_slist.h smatch_extra.h smatch_states.o: $(LIB_H) smatch.h smatch_slist.h +smatch_expression_stacks.o: $(LIB_H) smatch.h smatch.o: $(LIB_H) smatch.h $(SMATCH_CHECKS): smatch.h smatch_slist.h test-unssa.o: $(LIB_H) diff --git a/smatch.h b/smatch.h index a7b58324..7890a004 100644 --- a/smatch.h +++ b/smatch.h @@ -54,6 +54,7 @@ enum hook_type { CALL_ASSIGNMENT_HOOK, OP_HOOK, DEREF_HOOK, + CASE_HOOK, BASE_HOOK, FUNC_DEF_HOOK, END_FUNC_HOOK, @@ -243,6 +244,8 @@ void __print_cur_slist(); /* smatch_hooks.c */ void __pass_to_client(void *data, enum hook_type type); void __pass_to_client_no_data(enum hook_type type); +void __pass_case_to_client(struct expression *switch_expr, + struct expression *case_expr); int __has_merge_function(int client_id); struct smatch_state *__client_merge_function(int owner, const char *name, struct symbol *sym, diff --git a/smatch_flow.c b/smatch_flow.c index 9de013e1..1def8005 100644 --- a/smatch_flow.c +++ b/smatch_flow.c @@ -10,12 +10,14 @@ #include #include "token.h" #include "smatch.h" +#include "smatch_expression_stacks.h" static int __smatch_lineno = 0; static char *filename; static char *cur_func; static int line_func_start; +static struct expression_stack *switch_expr_stack = NULL; char *get_filename(void) { return filename; } char *get_function(void) { return cur_func; } @@ -299,6 +301,7 @@ void __split_statements(struct statement *stmt) return; case STMT_SWITCH: __split_expr(stmt->switch_expression); + push_expression(&switch_expr_stack, stmt->switch_expression); __save_switch_states(); __push_default(); __push_breaks(); @@ -307,9 +310,12 @@ void __split_statements(struct statement *stmt) __merge_switches(); __pop_switches(); __merge_breaks(); + pop_expression(&switch_expr_stack); return; case STMT_CASE: __merge_switches(); + __pass_case_to_client(top_expression(switch_expr_stack), + stmt->case_expression); if (!stmt->case_expression) __set_default(); __split_expr(stmt->case_expression); @@ -428,7 +434,7 @@ static void split_functions(struct symbol_list *sym_list) cur_func = NULL; line_func_start = 0; clear_all_states(); - + free_expression_stack(&switch_expr_stack); } else { __pass_to_client(sym, BASE_HOOK); } diff --git a/smatch_hooks.c b/smatch_hooks.c index fd0af76f..91588d5f 100644 --- a/smatch_hooks.c +++ b/smatch_hooks.c @@ -59,6 +59,9 @@ void add_hook(void *func, enum hook_type type) case DEREF_HOOK: container->data_type = EXPR_HOOK; break; + case CASE_HOOK: + /* nothing needed */ + break; case BASE_HOOK: container->data_type = SYM_HOOK; break; @@ -152,6 +155,20 @@ void __pass_to_client_no_data(enum hook_type type) } END_FOR_EACH_PTR(container); } +void __pass_case_to_client(struct expression *switch_expr, + struct expression *case_expr) +{ + typedef void (case_func)(struct expression *switch_expr, + struct expression *case_expr); + struct hook_container *container; + + FOR_EACH_PTR(hook_funcs, container) { + if (container->hook_type == CASE_HOOK) { + ((case_func *) container->fn)(switch_expr, case_expr); + } + } END_FOR_EACH_PTR(container); +} + int __has_merge_function(int client_id) { struct hook_container *tmp; diff --git a/smatch_slist.c b/smatch_slist.c index 2ad44491..1053b484 100644 --- a/smatch_slist.c +++ b/smatch_slist.c @@ -3,7 +3,7 @@ * * Copyright (C) 2008,2009 Dan Carpenter. * - * Licensed under the Open Software License version 1.1 + * Licensed under the Open Software License version 1.1 * */ -- 2.11.4.GIT