From 5defc7f1a2259e4111cbcc95911616e252ce1a7e Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 16 Apr 2018 13:03:29 +0300 Subject: [PATCH] expression/smatch_expressions: move expr_set/get_parent functions These are stored in the expression struct but they're pretty closely tied with Smatch. Moving them makes debugging them easier. Signed-off-by: Dan Carpenter --- check_free_strict.c | 1 + check_logical_instead_of_bitwise.c | 1 + check_precedence.c | 1 + expression.h | 32 -------------------------------- smatch_expressions.c | 34 ++++++++++++++++++++++++++++++++++ smatch_extra.h | 4 ++++ 6 files changed, 41 insertions(+), 32 deletions(-) diff --git a/check_free_strict.c b/check_free_strict.c index 7c033076..3dcac4d7 100644 --- a/check_free_strict.c +++ b/check_free_strict.c @@ -23,6 +23,7 @@ #include #include "smatch.h" #include "smatch_slist.h" +#include "smatch_extra.h" static int my_id; diff --git a/check_logical_instead_of_bitwise.c b/check_logical_instead_of_bitwise.c index 3c35f6b0..6bb531db 100644 --- a/check_logical_instead_of_bitwise.c +++ b/check_logical_instead_of_bitwise.c @@ -16,6 +16,7 @@ */ #include "smatch.h" +#include "smatch_extra.h" static int my_id; diff --git a/check_precedence.c b/check_precedence.c index e0b8e37d..bacbfff3 100644 --- a/check_precedence.c +++ b/check_precedence.c @@ -16,6 +16,7 @@ */ #include "smatch.h" +#include "smatch_extra.h" static int my_id; diff --git a/expression.h b/expression.h index e52a251d..4255c178 100644 --- a/expression.h +++ b/expression.h @@ -307,36 +307,4 @@ struct token *compound_statement(struct token *, struct statement *); void cast_value(struct expression *expr, struct symbol *newtype, struct expression *old, struct symbol *oldtype); -static inline void expr_set_parent_expr(struct expression *expr, struct expression *parent) -{ - if (!expr) - return; - expr->parent = (unsigned long)parent | 0x1UL; -} - -static inline void expr_set_parent_stmt(struct expression *expr, struct statement *parent) -{ - if (!expr) - return; - expr->parent = (unsigned long)parent; -} - -static inline struct expression *expr_get_parent_expr(struct expression *expr) -{ - if (!expr) - return NULL; - if (!(expr->parent & 0x1UL)) - return NULL; - return (struct expression *)(expr->parent & ~0x1UL); -} - -static inline struct statement *expr_get_parent_stmt(struct expression *expr) -{ - if (!expr) - return NULL; - if (expr->parent & 0x1UL) - return NULL; - return (struct statement *)expr->parent; -} - #endif diff --git a/smatch_expressions.c b/smatch_expressions.c index c5050724..b5ce6bc9 100644 --- a/smatch_expressions.c +++ b/smatch_expressions.c @@ -1,4 +1,5 @@ #include "smatch.h" +#include "smatch_extra.h" __ALLOCATOR(struct expression, "temporary expr", tmp_expression); @@ -174,3 +175,36 @@ struct expression *gen_expression_from_key(struct expression *arg, const char *k return ret; } +void expr_set_parent_expr(struct expression *expr, struct expression *parent) +{ + if (!expr) + return; + + expr->parent = (unsigned long)parent | 0x1UL; +} + +void expr_set_parent_stmt(struct expression *expr, struct statement *parent) +{ + if (!expr) + return; + expr->parent = (unsigned long)parent; +} + +struct expression *expr_get_parent_expr(struct expression *expr) +{ + if (!expr) + return NULL; + if (!(expr->parent & 0x1UL)) + return NULL; + return (struct expression *)(expr->parent & ~0x1UL); +} + +struct statement *expr_get_parent_stmt(struct expression *expr) +{ + if (!expr) + return NULL; + if (expr->parent & 0x1UL) + return NULL; + return (struct statement *)expr->parent; +} + diff --git a/smatch_extra.h b/smatch_extra.h index fc2be60a..d255973c 100644 --- a/smatch_extra.h +++ b/smatch_extra.h @@ -203,6 +203,10 @@ struct expression *unknown_value_expression(struct expression *expr); int is_fake_call(struct expression *expr); struct expression *gen_expression_from_key(struct expression *arg, const char *key); void free_tmp_expressions(void); +void expr_set_parent_expr(struct expression *expr, struct expression *parent); +void expr_set_parent_stmt(struct expression *expr, struct statement *parent); +struct expression *expr_get_parent_expr(struct expression *expr); +struct statement *expr_get_parent_stmt(struct expression *expr); /* smatch_param_limit.c */ struct smatch_state *get_orig_estate(const char *name, struct symbol *sym); -- 2.11.4.GIT