From 71cd2df608d4f1550695b94271e531e201f8e35f Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 14 Jul 2015 14:31:19 +0300 Subject: [PATCH] helper: export get_complication_score() I am going to use this in expr_to_chunk_sym_vsl() so I'm just moving it. No functional changes. Signed-off-by: Dan Carpenter --- smatch.h | 1 + smatch_helper.c | 38 ++++++++++++++++++++++++++++++++++++++ smatch_stored_conditions.c | 38 -------------------------------------- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/smatch.h b/smatch.h index d181fb68..b0c08d0e 100644 --- a/smatch.h +++ b/smatch.h @@ -279,6 +279,7 @@ char *expr_to_var_sym(struct expression *expr, struct symbol **sym_ptr); char *expr_to_known_chunk_sym(struct expression *expr, struct symbol **sym); char *expr_to_chunk_sym_vsl(struct expression *expr, struct symbol **sym, struct var_sym_list **vsl); +int get_complication_score(struct expression *expr); int sym_name_is(const char *name, struct expression *expr); int get_const_value(struct expression *expr, sval_t *sval); diff --git a/smatch_helper.c b/smatch_helper.c index f55d667b..aef3dcad 100644 --- a/smatch_helper.c +++ b/smatch_helper.c @@ -362,6 +362,44 @@ struct symbol *expr_to_sym(struct expression *expr) return sym; } +int get_complication_score(struct expression *expr) +{ + int score = 0; + + expr = strip_expr(expr); + + /* + * Don't forget to keep get_complication_score() and store_all_links() + * in sync. + * + */ + + switch (expr->type) { + case EXPR_CALL: + return 999; + case EXPR_COMPARE: + case EXPR_BINOP: + score += get_complication_score(expr->left); + score += get_complication_score(expr->right); + return score; + case EXPR_SYMBOL: + if (is_local_variable(expr)) + return 1; + return 999; + case EXPR_VALUE: + return 0; +#if 0 + case EXPR_PREOP: + if (expr->op == SPECIAL_INCREMENT || + expr->op == SPECIAL_DECREMENT) + return 999; + return get_complication_score(expr->unop); +#endif + default: + return 999; + } +} + char *expr_to_chunk_helper(struct expression *expr, struct symbol **sym, struct var_sym_list **vsl) { char *name, *left_name, *right_name; diff --git a/smatch_stored_conditions.c b/smatch_stored_conditions.c index eaa43324..4f7c9692 100644 --- a/smatch_stored_conditions.c +++ b/smatch_stored_conditions.c @@ -146,44 +146,6 @@ free: free_string(var); } -static int get_complication_score(struct expression *expr) -{ - int score = 0; - - expr = strip_expr(expr); - - /* - * Don't forget to keep get_complication_score() and store_all_links() - * in sync. - * - */ - - switch (expr->type) { - case EXPR_CALL: - return 999; - case EXPR_COMPARE: - case EXPR_BINOP: - score += get_complication_score(expr->left); - score += get_complication_score(expr->right); - return score; - case EXPR_SYMBOL: - if (is_local_variable(expr)) - return 1; - return 999; - case EXPR_VALUE: - return 0; -#if 0 - case EXPR_PREOP: - if (expr->op == SPECIAL_INCREMENT || - expr->op == SPECIAL_DECREMENT) - return 999; - return get_complication_score(expr->unop); -#endif - default: - return 999; - } -} - static int condition_too_complicated(struct expression *expr) { if (get_complication_score(expr) > 2) -- 2.11.4.GIT