Generate-unique-no-for-lexical-block-in-fun-scope
authorKetan Dixit <ketan.dixit@gmail.com>
Mon, 2 Aug 2010 21:47:33 +0000 (17:47 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Mon, 2 Aug 2010 22:03:39 +0000 (18:03 -0400)
src/aop-pc-assign.c
src/aop.h

index 710e25db6d24a10c2062d6161ec2037086be2b25..66bcf71aeb11d2eef54e1693c5b96bd2775b0e7d 100644 (file)
@@ -380,6 +380,31 @@ aop_match_assignment_by_type (const struct aop_type *type)
   return pc;
 }
 
+static bool
+find_lexical_block (tree lhs, tree block, int *indexp)
+{
+  tree t;
+
+  /* Search locally */
+  if (BLOCK_VARS (block))
+    for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
+      if (lhs == t)
+       return true;
+
+  if(BLOCK_CHAIN (block))
+    {
+      for (t = BLOCK_CHAIN (block); t; t = BLOCK_CHAIN(block))
+       {
+         (*indexp)++;
+         bool found = false;
+         found = find_lexical_block (lhs, t, indexp);
+         if (found)
+           return true;
+       }
+    }
+  return false;
+}
+
 /**
  * Return the scope of the variable that an assignment statement
  * assigns to (i.e., the left-hand side), which will be on of the
@@ -390,11 +415,14 @@ aop_match_assignment_by_type (const struct aop_type *type)
  * \return For a direct assignment to a variable, the scope of that
  * variable, otherwise AOP_MEMORY_SCOPE.
  */
-enum aop_scope
+int
 aop_capture_lhs_var_scope (struct aop_joinpoint *jp)
 {
   tree lhs;
+  tree function_block;
+  int var_index = 0;
   lhs = get_lhs_var (jp);
+
   if (lhs != NULL_TREE)
     {
       if (DECL_FILE_SCOPE_P (lhs))
@@ -410,7 +438,12 @@ aop_capture_lhs_var_scope (struct aop_joinpoint *jp)
        }
       else if (TREE_CODE (DECL_CONTEXT (lhs)) == FUNCTION_DECL)
        {
-         return AOP_FUNCTION_SCOPE;
+         function_block = DECL_INITIAL (current_function_decl);
+         bool retval = false;
+         retval = find_lexical_block (lhs, function_block, &var_index);
+
+         aop_assert (retval == true);
+         return var_index;
        }
       else
        {
index ecca714580096d40d32c7d047947ee81ceeb56cb..c90f7371a35275fdeafedfa8808c72e68ed893de 100644 (file)
--- a/src/aop.h
+++ b/src/aop.h
@@ -270,29 +270,22 @@ extern struct aop_dynval *aop_capture_assigned_value (struct aop_joinpoint *jp);
  * values to indicate the scope of the variable assigned in a
  * specified assignment statement.
  */
-enum aop_scope {
-  /**
-   * The variable is accessible by name from anywhere in the program.
-   */
-  AOP_GLOBAL_SCOPE,
-
-  /**
-   * The variable is only accessible by name from the current file.
-   */
-  AOP_FILE_SCOPE,
+/**
+ * The variable is accessible by name from anywhere in the program.
+ */
+#define AOP_GLOBAL_SCOPE -1
+  
+/**
+ * The variable is only accessible by name from the current file.
+ */
+#define AOP_FILE_SCOPE  -2
 
-  /**
-   * The variable is only accessible by name from the current function
-   * or method.
-   */
-  AOP_FUNCTION_SCOPE,
+/**
+ * Used for an assignment that does not assign to a variable.  For
+ * example, the assignment may be to a field in a struct or a
+ * dereferenced pointer.
+ */
+#define AOP_MEMORY_SCOPE  -3
 
-  /**
-   * Used for an assignment that does not assign to a variable.  For
-   * example, the assignment may be to a field in a struct or a
-   * dereferenced pointer.
-   */
-  AOP_MEMORY_SCOPE,
-};
-extern enum aop_scope aop_capture_lhs_var_scope (struct aop_joinpoint *jp);
+extern int aop_capture_lhs_var_scope (struct aop_joinpoint *jp);
 #endif