From e0110822ef316a67f96a61c3587386d91f4f5d12 Mon Sep 17 00:00:00 2001 From: Ketan Dixit Date: Mon, 25 Oct 2010 21:04:10 -0400 Subject: [PATCH] Capture param without filtering --- src/aop-pc-entry.c | 2 +- src/aop-pointcut.c | 86 +++++++++++++++++++++++++++++++++------------- src/aop.h | 4 +++ 3 files changed, 68 insertions(+), 24 deletions(-) diff --git a/src/aop-pc-entry.c b/src/aop-pc-entry.c index 2fa9bad..6960592 100644 --- a/src/aop-pc-entry.c +++ b/src/aop-pc-entry.c @@ -22,7 +22,6 @@ #undef PACKAGE_VERSION #include - #include #include #include @@ -211,6 +210,7 @@ void aop_filter_entry_by_name(struct aop_pointcut *pc_function_entry, pc_function_entry->pc_entry.function_name = advice_function_entry; } + /* Close Doxygen defgroup block. */ /** * \} diff --git a/src/aop-pointcut.c b/src/aop-pointcut.c index f53c80f..4acd224 100644 --- a/src/aop-pointcut.c +++ b/src/aop-pointcut.c @@ -187,29 +187,29 @@ aop_capture_in_param (struct aop_joinpoint *jp, int n) } bool -check_in_param (struct aop_param_desc *param_desc) +check_in_param (int param_index, const struct aop_type *type) { - tree param_type; - tree param_decl; - int index = 0; - bool index_found = false; - for (param_decl = DECL_ARGUMENTS (current_function_decl); - param_decl; param_decl = TREE_CHAIN (param_decl)) - { - if (index == param_desc->param_index) - { - /* Index found check the type */ - if ((param_type = TREE_TYPE (param_decl)) == NULL - || !does_type_match (param_type, param_desc->type)) - index_found = false; - else - index_found = true; - - break; - } - index++; - } - return index_found; + tree param_decl; + tree param_type; + int index = 0; + bool index_found = false; + for (param_decl = DECL_ARGUMENTS (current_function_decl); + param_decl; param_decl = TREE_CHAIN (param_decl)) + { + if (index == param_index) + { + /* Index found check the type */ + if ((param_type = TREE_TYPE (param_decl)) == NULL + || !does_type_match (param_type, type)) + index_found = false; + else + index_found = true; + + break; + } + index++; + } + return index_found; } bool @@ -221,7 +221,7 @@ check_in_params (struct aop_pointcut *pc) for (param_desc = pc->in_param_list_head ; param_desc != NULL ; param_desc = param_desc->next) { - if(!check_in_param (param_desc)) + if(!check_in_param (param_desc->param_index, param_desc->type)) return false; } @@ -280,3 +280,43 @@ aop_filter_by_in_param (struct aop_pointcut *pc, int n, param->type = type; } +/** + * Get a dynval representing the nth parameter passed to the current + * function if there is a parameter n and it matches the specified + * type. This function makes it possible to capture a parameter even + * if you have not filtered on its type with + * aop_filter_call_pc_by_param(). However, it returns NULL if there + * is no parameter n or if parameter n does not match the specified + * type. + * \param jp A function call join point. Function call join points + * are obtained by joining on an aop_match_function_call() pointcut. + * \param n The index of the parameter to capture. Parameters are + * indexed from zero. + * \param type This function verifies that the captured parameter + * matches the specified type. + * \return dynval with its type determined by the specified type or + * NULL if there is no matching parameter n. + */ +struct aop_dynval * +aop_capture_in_param_by_type (struct aop_joinpoint *jp, int n, + const struct aop_type *type) +{ + struct aop_pointcut *pc; + struct aop_dynval *dv; + + pc = jp->pc; + + /* Check that there is a nth parameter and that it matches the + type. */ + + if (!check_in_param (n, type)) + return NULL; + + dv = ggc_alloc (sizeof (struct aop_dynval)); + dv->kind = ADV_FUN_PARAM; + dv->type = type; + dv->jp = jp; + dv->get_dynval = op_get_in_param; + dv->dynval_call.param_index = n; + return dv; +} diff --git a/src/aop.h b/src/aop.h index b59b76b..44135fd 100644 --- a/src/aop.h +++ b/src/aop.h @@ -337,4 +337,8 @@ extern int aop_capture_lineno (struct aop_joinpoint *jp); extern const char *aop_capture_file_name (struct aop_joinpoint *jp); +extern struct aop_dynval * +aop_capture_in_param_by_type (struct aop_joinpoint *jp, int n, + const struct aop_type *type); + #endif -- 2.34.1