Style improvements.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Mon, 24 May 2010 19:55:13 +0000 (15:55 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Mon, 24 May 2010 20:08:48 +0000 (16:08 -0400)
src/aop-pc-entry.c
src/aop-pc-fun-call.c
src/aop-pointcut.h

index 4d22e68ac19d7b631ef326cc7044c03e128b7c5e..b24bd02848f6e6a49d39e5812d9cd2b0100e7eed 100644 (file)
@@ -37,7 +37,6 @@
 #include "aop-pointcut.h"
 #include "aop-type.h"
 
-
 static void
 op_join_on_function_entry (struct aop_pointcut *pc, join_callback cb,
                           void *callback_param)
@@ -46,21 +45,18 @@ op_join_on_function_entry (struct aop_pointcut *pc, join_callback cb,
   aop_assert (pc->kind == ATP_ENTRY);
 
   if(pc->pc_entry.function_name != NULL)
-    {   
-      if (strcmp( IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
-                 ,pc->pc_entry.function_name)!=0)
-       {
-         fprintf(stderr,"%s function does not match the pointcut specifier",
-                 pc->pc_entry.function_name);
-         return;
-       }
+    {
+      const char *func_name =
+       IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
+      if (strcmp (func_name, pc->pc_entry.function_name) != 0)
+       return;
     }
 
   FOR_EACH_BB(bb)
     {
       gimple_stmt_iterator gsi;
 
-      for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+      for (gsi = gsi_start_bb (bb) ; !gsi_end_p (gsi) ; gsi_next (&gsi))
        {
          struct aop_joinpoint jp;
          jp.pc = pc;
@@ -89,4 +85,3 @@ void aop_filter_function_entry_pointcut(struct aop_pointcut *pc_function_entry,
 {
   pc_function_entry->pc_entry.function_name = advice_function_entry;
 }
-
index 5f7d70777078b2601c3ac4623e1f03662e1455d5..ff5c8467fb747803d0b798679c5c582966a30d05 100644 (file)
 #include <diagnostic.h>
 #include <string.h>
 
-
 #include "aop.h"
 #include "aop-pointcut.h"
 #include "aop-type.h"
 #include "aop-dynval.h"
 
-//123456789012345678901234567890123456789012345678901234567890123456789012345678
+/* Returns true if func_decl matches the arguments described in
+   param_list by type. */
+static bool
+param_desc_matches (struct aop_param_desc *param_list, gimple func_stmt)
+{
+  int num_args = gimple_call_num_args (func_stmt);
+
+  while (param_list != NULL)
+    {
+      /* The param_list wants to match an argument that isn't
+        there. */
+      if (param_list->param_id >= num_args)
+       return false;
+
+      param_list = param_list->next;
+    }
+
+  return true;
+}
+
 static void
 op_join_on_function_call (struct aop_pointcut *pc, join_callback cb,
-                          void *callback_param)
+                         void *callback_param)
 {
-  aop_assert (pc->kind == ATP_CALL);
-
   basic_block my_basic_block;
   gimple_stmt_iterator gsi;
   tree func_decl;
   tree func;
 
-  const char * func_name;
+  aop_assert (pc->kind == ATP_CALL);
 
   FOR_EACH_BB(my_basic_block)
-  {
-    for (gsi = gsi_start_bb (my_basic_block) ; !gsi_end_p (gsi) ;
-        gsi_next (&gsi)) 
-      {
-       gimple my_statement = gsi_stmt (gsi);
-
-       /* At this stage, there should be no GIMPLE 
-          statements with sub-statements. */
-       gcc_assert(!gimple_has_substatements (my_statement));
-
-       if (gimple_code (my_statement) == GIMPLE_CALL)
-         {
-           func = gimple_call_fn (my_statement);
+    {
+      for (gsi = gsi_start_bb (my_basic_block) ; !gsi_end_p (gsi) ;
+          gsi_next (&gsi)) 
+       {
+         gimple stmt = gsi_stmt (gsi);
+
+         /* At this stage, there should be no GIMPLE statements with
+            sub-statements. */
+         gcc_assert(!gimple_has_substatements (stmt));
+
+         if (gimple_code (stmt) == GIMPLE_CALL)
+           {
+             const char *func_name;
+
+             func = gimple_call_fn (stmt);
            
-           if (TREE_CODE (func) != ADDR_EXPR)
-             {
-               /* This is a call to a function pointer. 
-                  Don't worry about it. */
-               continue;
-             }
+             if (TREE_CODE (func) != ADDR_EXPR)
+               {
+                 /* This is a call to a function pointer.  Don't
+                    worry about it. */
+                 continue;
+               }
            
-           func_decl = TREE_OPERAND (func, 0);
-           func_name = IDENTIFIER_POINTER (DECL_NAME (func_decl));
+             func_decl = TREE_OPERAND (func, 0);
+             func_name = IDENTIFIER_POINTER (DECL_NAME (func_decl));
    
-           if (strcmp (pc->pc_call.function_name, func_name) == 0) 
-             {
-               int num_args = gimple_call_num_args (my_statement);
-               
-               struct aop_param_desc *iter = NULL;     
-               if(pc->pc_call.param_list_head != NULL ) {
-                 iter =  pc->pc_call.param_list_head;
-                       while( iter->next != NULL ) {
-                         iter = iter->next;    
-                          
-                          if(iter->param_id > num_args - 1 ||
-                             iter->param_id < 0) {
-                            return; 
-                          }                       
-                       }                       
-               }   
+             if (strcmp (pc->pc_call.function_name, func_name) == 0) 
+               {
+                 if (!param_desc_matches (pc->pc_call.param_list_head, stmt))
+                   continue;
                                        
-               struct aop_joinpoint jp;
-               jp.pc = pc;
-               jp.gsi = &gsi;
-               jp.is_prepared = false;
-               cb (&jp, callback_param);               
-             }
-         }
-
-      }
-  } 
+                 struct aop_joinpoint jp;
+                 jp.pc = pc;
+                 jp.gsi = &gsi;
+                 jp.is_prepared = false;
+                 cb (&jp, callback_param);             
+               }
+           }
+       }
+    } 
 }
 
 struct aop_pointcut *
@@ -118,9 +123,8 @@ aop_match_function_call ()
   pc->insert_after = op_default_insert_after;
   pc->insert_before = op_default_insert_before;
   pc->prepare_for_weave = op_default_prepare_for_weave;
-  /*
-       Initialize the list to NULL
-  */
+
+  /* Initialize the list to NULL */
   pc->pc_call.param_list_head = NULL;
   return pc;
 }
@@ -156,18 +160,15 @@ void aop_filter_function_call_pointcut_by_param_index(struct aop_pointcut *pc,
   aop_add_param_descriptor (pc, param_id);
 }
 
-
 static tree
 op_get_return_value (struct aop_dynval *dv)
 {
   gimple stmt;
   tree return_value;
 
-  /* 
-     If this function isn't on the right side of an assignment, we
-     need to _put it_ on the right hand side of an assignment so
-     we can grab its return value. 
-  */
+  /* If this function isn't on the right side of an assignment, we
+     need to _put it_ on the right hand side of an assignment so we
+     can grab its return value.  */
   struct aop_joinpoint *jp = dv->jp;
   stmt = gsi_stmt (*(jp->gsi));
   
@@ -188,7 +189,6 @@ op_get_return_value (struct aop_dynval *dv)
   return_value = stabilize_reference (gimple_call_lhs (stmt));
   debug_gimple_stmt (stmt);
   return return_value;
 }
 
 struct aop_dynval *
@@ -200,8 +200,7 @@ aop_capture_return_value (struct aop_joinpoint *jp)
   dv->type = aop_t_all_unsigned ();
   dv->jp = jp;
   dv->get_dynval = op_get_return_value;
-  return dv;
-  
+  return dv;  
 }
 
 static tree
@@ -218,7 +217,6 @@ op_get_param (struct aop_dynval *dv)
   return param;
 }
 
-
 struct aop_dynval *
 aop_capture_param (struct aop_joinpoint *jp, int param_index)
 {
index 3c960361a1bef40abf058b2ec2ae34c5b623552b..f5014efbf04550d12e6978ef5f47af80bb26d6ee 100644 (file)
@@ -30,6 +30,13 @@ enum aop_pckind {
   ATP_CALL
 };
 
+/* An aop_param_desc describes a single function parameter, including
+   its type. */
+struct aop_param_desc {
+  int param_id;
+  struct aop_param_desc *next;
+};
+
 /* Information specific to assignment pointcuts. */
 struct aop_pc_assign {
   const struct aop_type *type;
@@ -43,17 +50,8 @@ struct aop_pc_entry {
   const char *function_name;
 };
 
-struct aop_param_desc;
-
-struct aop_param_desc {
-  int param_id;
-  struct aop_param_desc * next;  
-};
-
-
 struct aop_pc_fun_call {
   const char *function_name;
-  int param_id;  
   struct aop_param_desc *param_list_head; 
 };