Capture param without filtering
authorKetan Dixit <ketan.dixit@gmail.com>
Tue, 26 Oct 2010 01:04:10 +0000 (21:04 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Tue, 26 Oct 2010 01:11:28 +0000 (21:11 -0400)
src/aop-pc-entry.c
src/aop-pointcut.c
src/aop.h

index 2fa9bad3398cc1f67d6c6ae1e129de3c4b3cb1ed..6960592d2e05d399d94ad17149eebacfd75dc49e 100644 (file)
@@ -22,7 +22,6 @@
 #undef PACKAGE_VERSION
 
 #include <locale.h>
-
 #include <config.h>
 #include <system.h>
 #include <coretypes.h>
@@ -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. */
 /**
  * \}
index f53c80f63a8077ea2bec86fc239a6326602c0d2d..4acd224208cb6231eccf5d9a637bd99af3d398c5 100644 (file)
@@ -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;
+}
index b59b76b6f07a51d29d29c84d57deca4283900dae..44135fdce38eba34cc6e1fac7692fa3aff435214 100644 (file)
--- 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