コード例 #1
0
 private int GetScopeHashCode(string key)
 {
     if (localVariables.Contains(key))
     {
         VariableDeclaration value = (VariableDeclaration)localVariables[key];
         BlockStatement      block = (BlockStatement)AstUtil.GetParentOfType(value, typeof(BlockStatement));
         return(block.GetHashCode());
     }
     return(-1);
 }
コード例 #2
0
 public override object TrackedVisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
 {
     if (localVariables.Contains(identifierExpression.Identifier))
     {
         BlockStatement blockStatement = (BlockStatement)AstUtil.GetParentOfType(identifierExpression, typeof(BlockStatement));
         int            hashCode       = blockStatement.GetHashCode();
         if (hashCode != GetScopeHashCode(identifierExpression.Identifier))
         {
             string renamedVariableName = GetModifiedName(blockStatement, identifierExpression.Identifier);
             if (renamedVariableName != null)
             {
                 identifierExpression.Identifier = renamedVariableName;
             }
         }
     }
     return(base.TrackedVisitIdentifierExpression(identifierExpression, data));
 }
コード例 #3
0
        private string GetModifiedName(BlockStatement blockStatement, string identifier)
        {
            int hashCode;

            while (blockStatement != null)
            {
                hashCode = blockStatement.GetHashCode();
                string identifierHash = identifier + "_" + hashCode;
                if (renamedVariables.Contains(identifierHash))
                {
                    return((string)renamedVariables[identifierHash]);
                }
                else
                {
                    blockStatement = (BlockStatement)AstUtil.GetParentOfType(blockStatement, typeof(BlockStatement));
                }
            }
            return(null);
        }
コード例 #4
0
        public override object TrackedVisitVariableDeclaration(VariableDeclaration variableDeclaration, object data)
        {
            BlockStatement blockStatement = (BlockStatement)AstUtil.GetParentOfType(variableDeclaration, typeof(BlockStatement));

            if (blockStatement != null)
            {
                int hashCode = blockStatement.GetHashCode();
                if (!(blockStatement.Parent is MethodDeclaration) && !localVariables.Contains(variableDeclaration.Name))
                {
                    localVariables.Add(variableDeclaration.Name, variableDeclaration);
                }
                else if (HasConflict(variableDeclaration))
                {
                    string newName = renamer.GetNewName(variableDeclaration.Name);
                    renamedVariables.Add(variableDeclaration.Name + "_" + hashCode, newName);
                    variableDeclaration.Name = newName;
                }
            }
            return(base.TrackedVisitVariableDeclaration(variableDeclaration, data));
        }
コード例 #5
0
        public override object TrackedVisitBlockStatement(BlockStatement blockStatement, object data)
        {
            BlockStatement     replaced           = blockStatement;
            InsertionBlockData insertionBlockData = new InsertionBlockData();

            base.TrackedVisitBlockStatement(blockStatement, insertionBlockData);
            if (insertionBlockData.Block != null && insertionBlockData.Statements.Count > 0)
            {
                if (blockStatement.GetHashCode() == insertionBlockData.Block.GetHashCode())
                {
                    IList <INode> nodes = new List <INode>();
                    foreach (Statement node in insertionBlockData.Statements)
                    {
                        nodes.Add(node);
                    }
                    replaced.Children.InsertRange(insertionBlockData.BlockChildIndex, nodes);
                    ReplaceCurrentNode(replaced);
                }
            }
            return(null);
        }