From acf7fa57ce7e113517aff72f3610c6d143b61732 Mon Sep 17 00:00:00 2001 From: Justin Seyster Date: Fri, 2 Jul 2010 19:55:24 -0400 Subject: [PATCH] Added aop_capture_called_function_name. Fixed some error messages. --- src/aop-pc-fun-call.c | 86 +++++++++++++++++++++++++++++++------------ src/aop.h | 1 + 2 files changed, 64 insertions(+), 23 deletions(-) diff --git a/src/aop-pc-fun-call.c b/src/aop-pc-fun-call.c index f0e4a98..a3a1c3d 100644 --- a/src/aop-pc-fun-call.c +++ b/src/aop-pc-fun-call.c @@ -39,6 +39,34 @@ #include "aop-type.h" #include "aop-dynval.h" +/* Given a GIMPLE_CALL statement, return the name of the called + function, or NULL if the function is not named. */ +static const char * +get_function_name (gimple call_stmt) +{ + tree func; + + aop_assert (gimple_code (call_stmt) == GIMPLE_CALL); + + func = gimple_call_fn (call_stmt); + + if (TREE_CODE (func) == ADDR_EXPR) + { + tree func_decl; + const char *func_name; + + func_decl = TREE_OPERAND (func, 0); + func_name = IDENTIFIER_POINTER (DECL_NAME (func_decl)); + + return func_name; + } + else + { + /* This is a call to a function pointer, so it has no name. */ + return NULL; + } +} + /* Given a GIMPLE_CALL statement, return the type of the nth parameter passed if there is an nth parameter or NULL if there is no nth parameter. */ @@ -58,37 +86,23 @@ get_param_type (gimple call_stmt, int n) static bool call_matches (struct aop_pointcut *pc, gimple call_stmt) { - tree func; tree return_type; struct aop_param_desc *param; aop_assert (pc->kind == ATP_CALL); aop_assert (gimple_code (call_stmt) == GIMPLE_CALL); - func = gimple_call_fn (call_stmt); - /* Check function name only if the user filtered by name. */ if (pc->pc_call.function_name != NULL) { - if (TREE_CODE (func) == ADDR_EXPR) - { - /* Get the function's name and compare it to the filter-by - name. */ - tree func_decl; - const char *func_name; + const char *func_name; - func_decl = TREE_OPERAND (func, 0); - func_name = IDENTIFIER_POINTER (DECL_NAME (func_decl)); - - if (strcmp (pc->pc_call.function_name, func_name) != 0) - return false; - } - else - { - /* This is a call to a function pointer, so it can't match a - name. */ - return false; - } + /* Note that get_function_name returns NULL if the call is to a + function pointer. We consider function pointer calls to + never match a name. */ + if ((func_name = get_function_name (call_stmt)) == NULL + || strcmp (pc->pc_call.function_name, func_name) != 0) + return false; } /* Check parameter types. */ @@ -271,9 +285,35 @@ void aop_filter_call_pc_by_return_type (struct aop_pointcut *pc, const struct aop_type *type) { + if (pc->kind != ATP_CALL) + fatal_error ("(InterAspect) Attempt to filter by return type on" + " unsupported join point."); + pc->pc_call.return_type = type; } +/** + * Get the name of the function called in a function call join point. + * Calls to function pointers do not have a name, so + * aop_capture_called_function_name() will return NULL instead. + * \param jp A function call join point. Function call join points + * are obtained by joining on an aop_match_function_call() pointcut. + * \return Name of the called function or NULL if the call is to a + * function pointer. + */ +const char * +aop_capture_called_function_name(struct aop_joinpoint *jp) +{ + struct aop_pointcut *pc; + + pc = jp->pc; + if (pc->kind != ATP_CALL) + fatal_error ("(InterAspect) Attempt to capture called function name from" + " unsupported join point."); + + return get_function_name (jp->stmt); +} + /** * Get a dynval representing a function call's return value. Note * that you must filter with aop_filter_call_pc_by_return_type() in @@ -384,7 +424,7 @@ aop_capture_param (struct aop_joinpoint *jp, int n) pc = jp->pc; if (pc->kind != ATP_CALL) - fatal_error ("(InterAspect) Attempt to capture return value from an" + fatal_error ("(InterAspect) Attempt to capture parameter from an" " unsupported join point."); /* Search for an aop_param_desc for this parameter, so that we know @@ -433,7 +473,7 @@ aop_capture_param_by_type (struct aop_joinpoint *jp, int n, pc = jp->pc; if (pc->kind != ATP_CALL) - fatal_error ("(InterAspect) Attempt to capture return value from an" + fatal_error ("(InterAspect) Attempt to capture parameter from an" " unsupported join point."); /* Check that there is a nth parameter and that it matches the diff --git a/src/aop.h b/src/aop.h index fb1b31d..364523e 100644 --- a/src/aop.h +++ b/src/aop.h @@ -110,6 +110,7 @@ extern void aop_filter_call_pc_by_return_type (struct aop_pointcut *pc, extern void aop_filter_function_call_pointcut_by_param_index ( struct aop_pointcut *pc, int param_index); +extern const char *aop_capture_called_function_name(struct aop_joinpoint *jp); extern struct aop_dynval *aop_capture_return_value (struct aop_joinpoint *jp); extern struct aop_dynval *aop_capture_return_value_by_type ( struct aop_joinpoint *jp, const struct aop_type *type); -- 2.43.0