From: Ketan Dixit Date: Mon, 2 Aug 2010 21:47:33 +0000 (-0400) Subject: Generate-unique-no-for-lexical-block-in-fun-scope X-Git-Tag: release-v1.0~77 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=f59209e2091a78b80d290f1ebe114f95c10bdf49;p=interaspect.git Generate-unique-no-for-lexical-block-in-fun-scope --- diff --git a/src/aop-pc-assign.c b/src/aop-pc-assign.c index 710e25d..66bcf71 100644 --- a/src/aop-pc-assign.c +++ b/src/aop-pc-assign.c @@ -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 { diff --git a/src/aop.h b/src/aop.h index ecca714..c90f737 100644 --- 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