#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. */
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. */
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
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
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