コード例 #1
0
ファイル: Parser.cs プロジェクト: Plankankul/SpecSharp
        public override Block VisitBlock(Block block)
        {
            if (block == null)
            {
                return(null);
            }
            StatementList savedStatementList = this.CurrentStatementList;

            try{
                StatementList oldStatements = block.Statements;
                int           n             = oldStatements == null ? 0 : oldStatements.Length;
                StatementList newStatements = this.CurrentStatementList = block.Statements = new StatementList(n);
                for (int i = 0; i < n; i++)
                {
                    newStatements.Add((Statement)this.Visit(oldStatements[i]));
                }
                return(block);
            }finally{
                this.CurrentStatementList = savedStatementList;
            }
        }
コード例 #2
0
            internal void Transfer(LocalsStack /*!*/ targetStack, StatementList /*!*/ statements)
            {
                Debug.Assert(targetStack != null);
                if (targetStack == this)
                {
                    return;
                }
                int n = this.top;

                Debug.Assert(n == targetStack.top);
                for (int i = 0; i <= n; i++)
                {
                    Local sloc = this.elements[i];
                    Local tloc = targetStack.elements[i];
                    if (sloc == tloc)
                    {
                        continue;
                    }
                    Debug.Assert(sloc != null && tloc != null);
                    statements.Add(new AssignmentStatement(tloc, sloc));
                }
            }
コード例 #3
0
        public override Statement VisitBranch(Branch branch)
        {
            if (branch == null)
            {
                return(null);
            }

            if (branch.Target == null)
            {
                return(null);
            }

            branch.Condition = this.VisitExpression(branch.Condition);

            int         n           = this.localsStack.top + 1;
            LocalsStack targetStack = (LocalsStack)this.StackLocalsAtEntry[branch.Target.UniqueKey];

            if (targetStack == null)
            {
                this.StackLocalsAtEntry[branch.Target.UniqueKey] = this.localsStack.Clone();
                return(branch);
            }

            // Target block has an entry stack that is different from the current stack.  Need to copy stack
            // before branching.
            if (n <= 0)
            {
                return(branch); //Empty stack, no need to copy
            }
            StatementList statements = new StatementList();

            this.localsStack.Transfer(targetStack, statements);
            statements.Add(branch);

            return(new Block(statements));
        }