Пример #1
0
 private Statement ParseDo(TokenSet followers)
   //^ requires this.currentToken == Token.Do;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   SourceLocationBuilder slb = new SourceLocationBuilder(this.scanner.CurrentSourceLocation);
   this.GetNextToken();
   this.Skip(Token.While);
   Expression condition = this.ParseExpression(followers|Token.EndOfLine);
   this.Skip(Token.EndOfLine);
   BlockStatement body = this.ParseStatementBlock(followers|Token.Loop);
   slb.UpdateToSpan(this.scanner.CurrentSourceLocation);
   WhileDoStatement result = new WhileDoStatement(condition, body, slb);
   this.SkipClosingKeyword(Token.Loop, followers);
   return result;
 }
Пример #2
0
        public override void TraverseChildren(IBlockStatement block)
        {
            Contract.Assume(block is BlockStatement);
            var decompiledBlock = (BlockStatement)block;
            var statements      = decompiledBlock.Statements;

            for (int i = 0; i < statements.Count - 3; i++)
            {
                var gotoCondition = statements[i] as GotoStatement;
                if (gotoCondition == null)
                {
                    continue;
                }
                var gotosThatTarget = this.gotosThatTarget[(uint)gotoCondition.TargetStatement.Label.UniqueKey];
                Contract.Assume(gotosThatTarget != null && gotosThatTarget.Count >= 1);
                if (gotosThatTarget.Count != 1)
                {
                    continue;
                }
                var conditionalGotoBody = LookForCondition(statements, i + 1, gotoCondition.TargetStatement);
                if (conditionalGotoBody == null || !(conditionalGotoBody.FalseBranch is EmptyStatement))
                {
                    continue;
                }
                var gotoBody = conditionalGotoBody.TrueBranch as GotoStatement;
                if (gotoBody == null)
                {
                    continue;
                }
                Contract.Assume(i < statements.Count - 3);
                if (!IsOrContainsAsFirstStatement(statements[i + 1], gotoBody.TargetStatement))
                {
                    continue;
                }
                gotosThatTarget.Remove(gotoCondition);
                gotosThatTarget = this.gotosThatTarget[(uint)gotoBody.TargetStatement.Label.UniqueKey];
                Contract.Assume(gotosThatTarget != null && gotosThatTarget.Count >= 1);
                gotosThatTarget.Remove(gotoBody);
                var loopBody  = ExtractBlock(statements, i + 1, gotoCondition.TargetStatement);
                var whileLoop = new WhileDoStatement()
                {
                    Body = loopBody, Condition = conditionalGotoBody.Condition
                };
                Contract.Assume(i < statements.Count);
                statements[i] = whileLoop;
            }
            base.TraverseChildren(block);
        }
Пример #3
0
 private Statement ParseWhile(TokenSet followers) 
   //^ requires this.currentToken == Token.While;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   SourceLocationBuilder slb = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken);
   this.GetNextToken();
   Expression condition = this.ParseParenthesizedExpression(false, followers);
   Statement body = this.ParseStatement(followers);
   slb.UpdateToSpan(body.SourceLocation);
   WhileDoStatement result = new WhileDoStatement(condition, body, slb);
   this.SkipTo(followers);
   return result;
 }