Added aop_capture_called_function_name.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Fri, 2 Jul 2010 23:55:24 +0000 (19:55 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Fri, 2 Jul 2010 23:55:24 +0000 (19:55 -0400)
Fixed some error messages.

src/aop-pc-fun-call.c
src/aop.h

index f0e4a983fff105384efbf92edb3c2696829ad273..a3a1c3de1eb83b3bcab19530a9c518f5a575e192 100644 (file)
 #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
index fb1b31dedec4ee30dd4727ce1b4bef89a187fc99..364523efb280eb4baf1e40f186708206d592f492 100644 (file)
--- 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);