Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the FinallyStatement class.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens that form the statement.
        /// </param>
        /// <param name="tryStatement">
        /// The try-statement that this finally-statement is embedded to.
        /// </param>
        /// <param name="embeddedStatement">
        /// The statement embedded within the finally-statement.
        /// </param>
        internal FinallyStatement(CsTokenList tokens, TryStatement tryStatement, BlockStatement embeddedStatement)
            : base(StatementType.Finally, tokens)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tryStatement, "tryStatement");
            Param.AssertNotNull(embeddedStatement, "embeddedStatement");

            this.tryStatement      = tryStatement;
            this.embeddedStatement = embeddedStatement;

            this.AddStatement(embeddedStatement);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the FinallyStatement class.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens that form the statement.
        /// </param>
        /// <param name="tryStatement">
        /// The try-statement that this finally-statement is embedded to.
        /// </param>
        /// <param name="embeddedStatement">
        /// The statement embedded within the finally-statement.
        /// </param>
        internal FinallyStatement(CsTokenList tokens, TryStatement tryStatement, BlockStatement embeddedStatement)
            : base(StatementType.Finally, tokens)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tryStatement, "tryStatement");
            Param.AssertNotNull(embeddedStatement, "embeddedStatement");

            this.tryStatement = tryStatement;
            this.embeddedStatement = embeddedStatement;

            this.AddStatement(embeddedStatement);
        }
Exemplo n.º 3
0
 private void PrepareMatcher(StatementCollection statements, int statementIndex)
 {
     this.statements     = statements;
     this.statementIndex = statementIndex;
     @try       = null;
     this.body  = null;
     this.@lock = null;
     this.lockObjectExpression = null;
     this.theLocalVariable     = null;
     this.thePhiVariable       = null;
     this.lockingInstructions.Clear();
 }
Exemplo n.º 4
0
        IMethod CreateDisposeMethod()
        {
            BooMethodBuilder mn = _enumerator.AddVirtualMethod("Dispose", TypeSystemServices.VoidType);

            mn.Method.LexicalInfo = this.LexicalInfo;

            LabelStatement noEnsure = CodeBuilder.CreateLabel(_generator.Method, "noEnsure").LabelStatement;

            mn.Body.Add(noEnsure);
            mn.Body.Add(SetStateTo(_finishedStateNumber));
            mn.Body.Add(new ReturnStatement());

            // Create a section calling all ensure methods for each converted try block
            LabelStatement[] disposeLabels = new LabelStatement[_labels.Count];
            for (int i = 0; i < _convertedTryStatements.Count; i++)
            {
                TryStatementInfo info = _convertedTryStatements[i];
                disposeLabels[info._stateNumber] = CodeBuilder.CreateLabel(_generator.Method, "$ensure_" + info._stateNumber).LabelStatement;
                mn.Body.Add(disposeLabels[info._stateNumber]);
                mn.Body.Add(SetStateTo(_finishedStateNumber));
                Block block = mn.Body;
                while (info._parent != null)
                {
                    TryStatement ts = new TryStatement();
                    block.Add(ts);
                    ts.ProtectedBlock.Add(CallMethodOnSelf(info._ensureMethod));
                    block = ts.EnsureBlock = new Block();
                    info  = info._parent;
                }
                block.Add(CallMethodOnSelf(info._ensureMethod));
                mn.Body.Add(new ReturnStatement());
            }

            // now map the labels of the suspended states to the labels we just created
            for (int i = 0; i < _labels.Count; i++)
            {
                if (_tryStatementInfoForLabels[i] == null)
                {
                    disposeLabels[i] = noEnsure;
                }
                else
                {
                    disposeLabels[i] = disposeLabels[_tryStatementInfoForLabels[i]._stateNumber];
                }
            }

            mn.Body.Insert(0, CodeBuilder.CreateSwitch(
                               this.LexicalInfo,
                               CodeBuilder.CreateMemberReference(_state),
                               disposeLabels));
            return(mn.Entity);
        }
        bool IsLockStatement(TryStatement @try)
        {
            if (@try == null)
            {
                return(false);
            }

            //If the lock is with a flag and it's V1 then the statements in the try should be at least 3: 2 assignments and the method invocation
            // If the lock is with a flag and it's V2 the statement in the try should be at least 1: the method invocation.
            bool result = (this.lockType == LockType.WithFlagV1 && @try.Try.Statements.Count > 2) || this.lockType == LockType.Simple ||
                          (this.lockType == LockType.WithFlagV2 && @try.Try.Statements.Count > 0);

            result &= @try.CatchClauses.Count == 0 && @try.Finally != null;

            if (result)
            {
                if (lockType == LockType.WithFlagV1 || lockType == LockType.WithFlagV2)
                {
                    int enterMethodInvocationIndex;
                    if (lockType == LockType.WithFlagV1)
                    {
                        result &= CheckTheAssignExpressions(@try.Try.Statements[0], @try.Try.Statements[1]);
                        enterMethodInvocationIndex = 2;
                    }
                    else // lockType == LockType.WithFlagV2
                    {
                        enterMethodInvocationIndex = 0;
                    }

                    //The index 3 is because of the generated PhiVariable, if this variable is cleand before this step the matching will fail
                    result &= @try.Try.Statements[enterMethodInvocationIndex].CodeNodeType == CodeNodeType.ExpressionStatement;

                    if (result)
                    {
                        ExpressionStatement expressionStmt = @try.Try.Statements[enterMethodInvocationIndex] as ExpressionStatement;
                        result &= expressionStmt.Expression.CodeNodeType == CodeNodeType.MethodInvocationExpression;

                        MethodInvocationExpression methodInvocation = expressionStmt.Expression as MethodInvocationExpression;
                        result &= CheckTheMethodInvocation(methodInvocation, "Enter") && methodInvocation.MethodExpression.Method.Parameters.Count == 2;
                        if (result)
                        {
                            lockingInstructions.AddRange(methodInvocation.UnderlyingSameMethodInstructions);
                            this.theFlagVariable = GetTheFlagVariable(methodInvocation);
                        }
                    }
                }

                result &= CheckTheFinallyClause(@try.Finally.Body);
            }

            return(result);
        }
Exemplo n.º 6
0
        public virtual void VisitTryStatement(TryStatement tryStatement)
        {
            VisitStatement(tryStatement.Block);
            if (tryStatement.Handler != null)
            {
                VisitCatchClause(tryStatement.Handler);
            }

            if (tryStatement.Finalizer != null)
            {
                VisitStatement(tryStatement.Finalizer);
            }
        }
Exemplo n.º 7
0
        void ProcessFinallyHandler(ExceptionHandlerData data, TryStatement @try)
        {
            if (data.FinallyRange == null)
            {
                return;
            }

            var range = data.FinallyRange;

            @try.Finally = new BlockStatement();

            MoveStatementsToBlock(range.Start, range.End, @try.Finally);
        }
Exemplo n.º 8
0
 public void VisitTry(TryStatement t)
 {
     var tryStmt = gen.Try(
         () => t.body.Accept(this),
         t.exHandlers.Select(eh => GenerateClause(eh)),
         () =>
     {
         if (t.finallyHandler != null)
         {
             t.finallyHandler.Accept(this);
         }
     });
 }
Exemplo n.º 9
0
        // TryStmt
        public override bool Walk(TryStatement node)
        {
            BitArray save = _bits;

            _bits = new BitArray(_bits);

            // Flow the body
            node.Body.Walk(this);

            if (node.Else != null)
            {
                // Else is flown only after completion of Try with same bits
                node.Else.Walk(this);
            }


            if (node.Handlers != null)
            {
                foreach (TryStatementHandler tsh in node.Handlers)
                {
                    // Restore to saved state
                    _bits.SetAll(false);
                    _bits.Or(save);

                    // Flow the test
                    if (tsh.Test != null)
                    {
                        tsh.Test.Walk(this);
                    }

                    // Define the target
                    if (tsh.Target != null)
                    {
                        tsh.Target.Walk(_fdef);
                    }

                    // Flow the body
                    tsh.Body.Walk(this);
                }
            }

            _bits = save;

            if (node.Finally != null)
            {
                // Flow finally - this executes no matter what
                node.Finally.Walk(this);
            }

            return(false);
        }
Exemplo n.º 10
0
        public override void VisitTryStatement(TryStatement node)
        {
            WriteKeyword("try");
            WriteLine();
            Visit(node.Try);
            Visit(node.CatchClauses);

            if (node.Finally != null)
            {
                WriteKeyword("finally");
                WriteLine();
                Visit(node.Finally);
            }
        }
            protected override void VisitTryStatement(TryStatement tryStatement)
            {
                Visit(tryStatement.Block);

                if (tryStatement.Handler != null)
                {
                    Visit(tryStatement.Handler);
                }

                if (tryStatement.Finalizer != null)
                {
                    Visit(tryStatement.Finalizer);
                }
            }
Exemplo n.º 12
0
        void ProcessExceptionData(ExceptionHandlerData data)
        {
            var list = GetOrCreateStatementListAt(data.TryRange.Start.Index);

            var @try = new TryStatement(new BlockStatement(), null, null);

            MoveStatementsToBlock(data.TryRange.Start, data.TryRange.End, @try.Try);

            ProcessCatchHandlers(data, @try);

            ProcessFinallyHandler(data, @try);

            list.Add(@try);
        }
        public Statement GetStatement()
        {
            var tryStatement = new TryStatement();

            tryStatement.TryBlock = statementInterpreterHandler.GetStatement(tryStatementSyntax.Block);

            tryStatement.Catches.AddRange(tryStatementSyntax.Catches.Select(x =>
                                                                            statementInterpreterHandler.GetStatement(x)).Cast <CatchStatement>());

            tryStatement.Finally = tryStatementSyntax.Finally == null ?
                                   null : statementInterpreterHandler.GetStatement(tryStatementSyntax.Finally);

            return(tryStatement);
        }
Exemplo n.º 14
0
        public void FindOutermostExceptionScopeWithin_InsideFinally_Throw()
        {
            //-- Arrange

            var rootScope = new StatementScope(m_Class, m_Method, new StatementBlock());
            var homeScope = new StatementScope(new StatementBlock());

            var tryStatement = new TryStatement(() => { });
            var finallyScope = new StatementScope(new StatementBlock(), tryStatement, ExceptionBlockType.Finally);

            //-- Act

            var result = StatementScope.Current.FindOutermostTryStatementWithin(homeScope);
        }
Exemplo n.º 15
0
        public override bool Walk(TryStatement node)
        {
            node.Body.Walk(this);
            if (node.Handlers != null)
            {
                foreach (var handler in node.Handlers)
                {
                    ISet <Namespace> test    = EmptySet <Namespace> .Instance;
                    bool             madeSet = false;
                    if (handler.Test != null)
                    {
                        var testTypes = _eval.Evaluate(handler.Test);

                        if (handler.Target != null)
                        {
                            foreach (var type in testTypes)
                            {
                                ClassInfo klass = type as ClassInfo;
                                if (klass != null)
                                {
                                    test = test.Union(klass.Instance.SelfSet, ref madeSet);
                                }

                                BuiltinClassInfo builtinClass = type as BuiltinClassInfo;
                                if (builtinClass != null)
                                {
                                    test = test.Union(builtinClass.Instance.SelfSet, ref madeSet);
                                }
                            }

                            _eval.AssignTo(handler, handler.Target, test);
                        }
                    }

                    handler.Body.Walk(this);
                }
            }

            if (node.Finally != null)
            {
                node.Finally.Walk(this);
            }

            if (node.Else != null)
            {
                node.Else.Walk(this);
            }

            return(false);
        }
Exemplo n.º 16
0
 public override bool Walk(TryStatement node)
 {
     if (base.Walk(node))
     {
         if (!Save(node, true, "try"))
         {
             return(false);
         }
         // TODO: except, finally and else locations
         // These cannot be trivially obtained from the node
         return(true);
     }
     return(base.Walk(node));
 }
Exemplo n.º 17
0
            internal bool Match()
            {
                ExpressionStatement expressionStatement = null;

                theTry = null;

                if (statement.CodeNodeType == CodeNodeType.TryStatement)
                {
                    theTry = statement as TryStatement;
                }
                else if (nextStatement.CodeNodeType == CodeNodeType.TryStatement)
                {
                    theTry = nextStatement as TryStatement;
                    expressionStatement = statement as ExpressionStatement;
                    hasExpression       = true;
                }

                if (theTry == null)
                {
                    return(false);
                }

                if (!IsTryFinallyStatement(theTry))
                {
                    return(false);
                }

                if (theTry.Finally.Body.Statements.Count != 1)
                {
                    return(false);
                }

                var firstFinallyStatement = theTry.Finally.Body.Statements[0];

                if (firstFinallyStatement.CodeNodeType != CodeNodeType.IfStatement)
                {
                    return(false);
                }

                var ifStatement = (IfStatement)firstFinallyStatement;

                if (!CheckStandardUsingBlock(ifStatement, theTry, expressionStatement))
                {
                    return(false);
                }

                FixExpression();
                return(true);
            }
Exemplo n.º 18
0
        override public void OnTryStatement(TryStatement node)
        {
            _state.EnterTryBlock();
            Visit(node.ProtectedBlock);

            _state.EnterTryBlock();
            Visit(node.ExceptionHandlers);

            _state.EnterTryBlock();
            Visit(node.EnsureBlock);
            _state.LeaveTryBlock();

            _state.LeaveTryBlock();
            _state.LeaveTryBlock();
        }
Exemplo n.º 19
0
			private void PrepareUsingBlock(BinaryExpression binaryExpression, TryStatement try, ExpressionStatement expressionStatement)
			{
				this.expression = binaryExpression.get_Left();
				V_0 = 0;
				while (V_0 < try.get_Try().get_Statements().get_Count())
				{
					this.blockStatement.AddStatement(try.get_Try().get_Statements().get_Item(V_0));
					V_0 = V_0 + 1;
				}
				if (expressionStatement != null)
				{
					this.VisitAssignExpression(expressionStatement);
				}
				return;
			}
Exemplo n.º 20
0
        public CSharpSyntaxNode Convert(TryStatement node)
        {
            TryStatementSyntax csTryStatement = SyntaxFactory.TryStatement().WithBlock(node.TryBlock.ToCsNode <BlockSyntax>());

            if (node.CatchClause != null)
            {
                csTryStatement = csTryStatement.AddCatches(node.CatchClause.ToCsNode <CatchClauseSyntax>());
            }
            if (node.FinallyBlock != null)
            {
                csTryStatement = csTryStatement.WithFinally(SyntaxFactory.FinallyClause(node.FinallyBlock.ToCsNode <BlockSyntax>()));
            }

            return(csTryStatement);
        }
Exemplo n.º 21
0
 override public void OnTryStatement(TryStatement node)
 {
     WriteIndented();
     WriteKeyword("try:");
     WriteLine();
     WriteBlock(node.ProtectedBlock);
     Visit(node.ExceptionHandlers);
     if (null != node.EnsureBlock)
     {
         WriteIndented();
         WriteKeyword("ensure:");
         WriteLine();
         WriteBlock(node.EnsureBlock);
     }
 }
Exemplo n.º 22
0
        public override bool Walk(TryStatement node)
        {
            AddTagIfNecessary(node.HeaderIndex, node.Body?.EndIndex);
            if (node.Handlers != null)
            {
                foreach (var h in node.Handlers)
                {
                    AddTagIfNecessary(h.HeaderIndex, h.EndIndex);
                }
            }
            AddTagIfNecessary(node.FinallyIndex, node.Finally?.EndIndex);
            AddTagIfNecessary(node.ElseIndex, node.Else?.EndIndex);

            return(base.Walk(node));
        }
Exemplo n.º 23
0
 public override ICodeNode VisitTryStatement(TryStatement node)
 {
     if (node.get_Finally() != null && node.get_Finally().get_Body().get_Statements().get_Count() == 1 && node.get_Finally().get_Body().get_Statements().get_Item(0).get_CodeNodeType() == 5)
     {
         V_0 = node.get_Finally().get_Body().get_Statements().get_Item(0) as ExpressionStatement;
         if (V_0.get_Expression().get_CodeNodeType() == 19)
         {
             V_1 = (V_0.get_Expression() as MethodInvocationExpression).get_MethodExpression();
             if (V_1 != null && V_1.get_Method() != null && V_1.get_Method().get_DeclaringType() != null && (object)V_1.get_Method().get_DeclaringType().Resolve() == (object)this.yieldDeclaringType)
             {
                 node.set_Finally(new FinallyClause(V_1.get_Method().Resolve().get_Body().Decompile(this.decompilationContext.get_Language(), null), node.get_Finally().get_UnderlyingSameMethodInstructions()));
             }
         }
     }
     return(this.VisitTryStatement(node));
 }
 public override void VisitTryStatement(TryStatement node)
 {
     if (!foundEnumeratorAssignment)
     {
         insideTry = false;
         base.VisitTryStatement(node);
         return;
     }
     if (CanContainForeach(node))
     {
         insideTry = true;
         theTry    = node;
         base.VisitTryStatement(node);
     }
     insideTry = false;
 }
        private bool Match(StatementCollection statements, int statementIndex)
        {
            PrepareMatcher(statements, statementIndex);

            Statement currentStatement = statements[statementIndex];

            if (currentStatement.CodeNodeType == CodeNodeType.TryStatement)
            {
                @try     = currentStatement as TryStatement;
                lockType = LockType.WithFlag;
            }
            else if (currentStatement.CodeNodeType == CodeNodeType.ExpressionStatement &&
                     CheckTheMethodInvocation((currentStatement as ExpressionStatement).Expression as MethodInvocationExpression, "Enter"))
            {
                MethodReference methodReference = ((currentStatement as ExpressionStatement).Expression as MethodInvocationExpression).MethodExpression.Method;
                if (methodReference.Parameters.Count != 1)
                {
                    return(false);
                }

                if (statementIndex + 1 >= statements.Count || statementIndex - 2 < 0)
                {
                    return(false);
                }
                @try     = statements[statementIndex + 1] as TryStatement;
                lockType = LockType.Simple;
                if (!CheckTheAssignExpressions(statements[statementIndex - 2], statements[statementIndex - 1]))
                {
                    return(false);
                }
                lockingInstructions.AddRange(currentStatement.UnderlyingSameMethodInstructions);
            }

            if (@try == null)
            {
                return(false);
            }

            if (!IsLockStatement(@try))
            {
                return(false);
            }

            this.body = @try.Try;

            return(true);
        }
Exemplo n.º 26
0
        public int Visit(TryStatement statement)
        {
            _writer.WriteLine("try");
            statement.Block.Accept(this);

            foreach (var branch in statement.Branches)
            {
                _writer.Write("catch (");
                _writer.Write(branch.Type);
                _writer.Write(" ");
                _writer.Write(branch.Name);
                _writer.WriteLine(")");
                branch.Block.Accept(this);
            }

            return(0);
        }
Exemplo n.º 27
0
        void CreateMoveNext()
        {
            Method generator = _generator.Method;

            BooMethodBuilder methodBuilder = _enumerator.AddVirtualMethod("MoveNext", TypeSystemServices.BoolType);

            methodBuilder.Method.LexicalInfo = generator.LexicalInfo;
            _moveNext = methodBuilder.Entity;

            TransformLocalsIntoFields(generator);

            TransformParametersIntoFieldsInitializedByConstructor(generator);

            methodBuilder.Body.Add(CreateLabel(generator));

            // Visit() needs to know the number of the finished state
            _finishedStateNumber = _labels.Count;
            LabelStatement finishedLabel = CreateLabel(generator);

            methodBuilder.Body.Add(generator.Body);
            generator.Body.Clear();

            Visit(methodBuilder.Body);

            methodBuilder.Body.Add(CreateYieldInvocation(LexicalInfo.Empty, _finishedStateNumber, null));
            methodBuilder.Body.Add(finishedLabel);

            methodBuilder.Body.Insert(0,
                                      CodeBuilder.CreateSwitch(
                                          this.LexicalInfo,
                                          CodeBuilder.CreateMemberReference(_state),
                                          _labels));

            // if the method contains converted try statements, put it in a try/failure block
            if (_convertedTryStatements.Count > 0)
            {
                IMethod dispose = CreateDisposeMethod();

                var tryFailure = new TryStatement();
                tryFailure.ProtectedBlock.Add(methodBuilder.Body);
                tryFailure.FailureBlock = new Block();
                tryFailure.FailureBlock.Add(CallMethodOnSelf(dispose));
                methodBuilder.Body.Clear();
                methodBuilder.Body.Add(tryFailure);
            }
        }
Exemplo n.º 28
0
        public bool HandleTryExcept(TryStatement node)
        {
            node.Body.Walk(Walker);
            foreach (var handler in node.Handlers.MaybeEnumerate())
            {
                if (handler.Test != null && handler.Target is NameExpression nex)
                {
                    var value = Eval.GetValueFromExpression(handler.Test);
                    Eval.DeclareVariable(nex.Name, value ?? Eval.UnknownType, VariableSource.Declaration, nex);
                }
                handler.Body.Walk(Walker);
            }

            node.Finally?.Walk(Walker);
            node.Else?.Walk(Walker);
            return(false);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Initializes a new instance of the CatchStatement class.
        /// </summary>
        /// <param name="tokens">The list of tokens that form the statement.</param>
        /// <param name="tryStatement">The try-statement that this catch-statement is attached to.</param>
        /// <param name="classExpression">The inner expression.</param>
        /// <param name="embeddedStatement">The statement embedded within the catch-statement.</param>
        /// <param name="whenStatement">The when statement.</param>
        internal CatchStatement(CsTokenList tokens, TryStatement tryStatement, Expression classExpression, BlockStatement embeddedStatement, WhenStatement whenStatement)
            : base(StatementType.Catch, tokens)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tryStatement, "tryStatement");
            Param.Ignore(classExpression);
            Param.AssertNotNull(embeddedStatement, "embeddedStatement");
            Param.Ignore(whenStatement); // When statement can be null and not found for a try catch.

            this.tryStatement      = tryStatement;
            this.catchExpression   = classExpression;
            this.embeddedStatement = embeddedStatement;
            this.whenStatement     = whenStatement;

            if (classExpression != null)
            {
                this.AddExpression(classExpression);

                if (classExpression != null)
                {
                    if (classExpression.ExpressionType == ExpressionType.Literal)
                    {
                        this.classType = ((LiteralExpression)classExpression).Token as TypeToken;
                    }
                    else if (classExpression.ExpressionType == ExpressionType.VariableDeclaration)
                    {
                        VariableDeclarationExpression variableDeclaration = (VariableDeclarationExpression)classExpression;

                        this.classType = variableDeclaration.Type;

                        foreach (VariableDeclaratorExpression declarator in variableDeclaration.Declarators)
                        {
                            this.identifier = declarator.Identifier;
                            break;
                        }
                    }
                }
            }

            if (whenStatement != null)
            {
                this.AddStatement(whenStatement);
            }

            this.AddStatement(embeddedStatement);
        }
Exemplo n.º 30
0
        private static bool ShouldWalkNormally(TryStatement node)
        {
            if (node.Handlers == null)
            {
                return(true);
            }

            foreach (var handler in node.Handlers)
            {
                if (handler.Test == null || IsImportError(handler.Test))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 31
0
 public virtual object Walk(TryStatement node)
 {
     if (Enter(node))
     {
         node.Body.Accept(this);
         if (node.Rescue != null)
         {
             node.Rescue.Accept(this);
         }
         if (node.Finally != null)
         {
             node.Finally.Accept(this);
         }
     }
     Exit(node);
     return(null);
 }
        /// <summary>
        /// Initializes a new instance of the CatchStatement class.
        /// </summary>
        /// <param name="tokens">The list of tokens that form the statement.</param>
        /// <param name="tryStatement">The try-statement that this catch-statement is attached to.</param>
        /// <param name="classExpression">The inner expression.</param>
        /// <param name="embeddedStatement">The statement embedded within the catch-statement.</param>
        /// <param name="whenStatement">The when statement.</param>
        internal CatchStatement(CsTokenList tokens, TryStatement tryStatement, Expression classExpression, BlockStatement embeddedStatement, WhenStatement whenStatement)
            : base(StatementType.Catch, tokens)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tryStatement, "tryStatement");
            Param.Ignore(classExpression);
            Param.AssertNotNull(embeddedStatement, "embeddedStatement");
            Param.Ignore(whenStatement); // When statement can be null and not found for a try catch.

            this.tryStatement = tryStatement;
            this.catchExpression = classExpression;
            this.embeddedStatement = embeddedStatement;
            this.whenStatement = whenStatement;

            if (classExpression != null)
            {
                this.AddExpression(classExpression);

                if (classExpression != null)
                {
                    if (classExpression.ExpressionType == ExpressionType.Literal)
                    {
                        this.classType = ((LiteralExpression)classExpression).Token as TypeToken;
                    }
                    else if (classExpression.ExpressionType == ExpressionType.VariableDeclaration)
                    {
                        VariableDeclarationExpression variableDeclaration = (VariableDeclarationExpression)classExpression;

                        this.classType = variableDeclaration.Type;

                        foreach (VariableDeclaratorExpression declarator in variableDeclaration.Declarators)
                        {
                            this.identifier = declarator.Identifier;
                            break;
                        }
                    }
                }
            }

            this.AddStatement(embeddedStatement);
        }
Exemplo n.º 33
0
 public override void PostWalk(TryStatement node) { }
Exemplo n.º 34
0
 public virtual void PostWalk(TryStatement node) { }
Exemplo n.º 35
0
 private void Process_Try_Statement(StringBuilder sb, TryStatement statement)
 {
     sb.Append("try");
     sb.Append(ProcessStatement(statement.TryBlock));
     Process_Catch_Clauses(sb, statement.CatchClauses);
 }
Exemplo n.º 36
0
 // TryStatement
 protected internal virtual bool Walk(TryStatement node) { return true; }
		public virtual void Visit(TryStatement.CatchStatement s)
		{
			VisitChildren(s);

			if (s.CatchParameter != null)
				s.CatchParameter.Accept(this);
		}
Exemplo n.º 38
0
 public override void Exit(TryStatement node)
 {
     level--;
 }
Exemplo n.º 39
0
        // TryStatement
        public override bool Walk(TryStatement node)
        {
            // we manually walk the TryStatement so we can track finally blocks.
            node.Parent = _currentScope;
            _currentScope.ContainsExceptionHandling = true;

            node.Body.Walk(this);

            if (node.Handlers != null) {
                foreach (TryStatementHandler tsh in node.Handlers) {
                    if (tsh.Target != null) {
                        tsh.Target.Walk(_define);
                    }
                    tsh.Parent = _currentScope;
                    tsh.Walk(this);
                }
            }

            if (node.Else != null) {
                node.Else.Walk(this);
            }

            if (node.Finally != null) {
                _finallyCount[_finallyCount.Count - 1]++;
                node.Finally.Walk(this);
                _finallyCount[_finallyCount.Count - 1]--;
            }

            return false;
        }
Exemplo n.º 40
0
 public virtual bool Enter(TryStatement node)
 {
     return true;
 }
Exemplo n.º 41
0
 public void VisitTry(TryStatement t)
 {
     w.Write("try");
     w.WriteLine(":");
     ++w.IndentLevel;
     t.body.Accept(this);
     --w.IndentLevel;
     foreach (var h in t.exHandlers)
     {
         w.Write("except");
         w.Write(" ");
         h.type.Write(writer);
         if (h.name != null)
         {
             w.Write(" ");
             w.Write("as");
             w.Write(" ");
             w.Write(h.name.Name);
         }
         w.WriteLine(":");
         ++w.IndentLevel;
         h.body.Accept(this);
         --w.IndentLevel;
     }
 }
Exemplo n.º 42
0
 public void Visit(TryStatement tryStatement)
 {
 }
Exemplo n.º 43
0
        public IStatement Statement(bool BlocksAllowed = true, bool EmptyAllowed = true, IBlockNode Scope = null, IStatement Parent=null)
        {
            switch (laKind)
            {
                case Semicolon:
                    if (!EmptyAllowed)
                        goto default;
                    Step();
                    return null;
                case OpenCurlyBrace:
                    if (!BlocksAllowed)
                        goto default;
                    return BlockStatement(Scope,Parent);
                // LabeledStatement (loc:... goto loc;)
                case Identifier:
                    if (Lexer.CurrentPeekToken.Kind != Colon)
                        goto default;
                    Step();

                    var ls = new LabeledStatement() { Location = t.Location, Identifier = t.Value, Parent = Parent };
                    Step();
                    ls.EndLocation = t.EndLocation;

                    return ls;
                // IfStatement
                case If:
                    Step();

                    var iS = new IfStatement{	Location = t.Location, Parent = Parent	};

                    Expect(OpenParenthesis);
                    // IfCondition
                    IfCondition(iS);

                    // ThenStatement
                    if(Expect(CloseParenthesis))
                        iS.ThenStatement = Statement(Scope: Scope, Parent: iS);

                    // ElseStatement
                    if (laKind == (Else))
                    {
                        Step();
                        iS.ElseStatement = Statement(Scope: Scope, Parent: iS);
                    }

                    if(t != null)
                        iS.EndLocation = t.EndLocation;

                    return iS;
                // Conditions
                case Version:
                case Debug:
                    return StmtCondition(Parent, Scope);
                case Static:
                    if (Lexer.CurrentPeekToken.Kind == If)
                        return StmtCondition(Parent, Scope);
                    else if (Lexer.CurrentPeekToken.Kind == Assert)
                        goto case Assert;
                    else if (Lexer.CurrentPeekToken.Kind == Import)
                        goto case Import;
                    goto default;
                case For:
                    return ForStatement(Scope, Parent);
                case Foreach:
                case Foreach_Reverse:
                    return ForeachStatement(Scope, Parent);
                case While:
                    Step();

                    var ws = new WhileStatement() { Location = t.Location, Parent = Parent };

                    Expect(OpenParenthesis);
                    ws.Condition = Expression(Scope);
                    Expect(CloseParenthesis);

                    if(!IsEOF)
                    {
                        ws.ScopedStatement = Statement(Scope: Scope, Parent: ws);
                        ws.EndLocation = t.EndLocation;
                    }

                    return ws;
                case Do:
                    Step();

                    var dws = new WhileStatement() { Location = t.Location, Parent = Parent };
                    if(!IsEOF)
                        dws.ScopedStatement = Statement(true, false, Scope, dws);

                    if(Expect(While) && Expect(OpenParenthesis))
                    {
                        dws.Condition = Expression(Scope);
                        Expect(CloseParenthesis);
                        Expect(Semicolon);

                        dws.EndLocation = t.EndLocation;
                    }

                    return dws;
                // [Final] SwitchStatement
                case Final:
                    if (Lexer.CurrentPeekToken.Kind != Switch)
                        goto default;
                    goto case Switch;
                case Switch:
                    var ss = new SwitchStatement { Location = la.Location, Parent = Parent };
                    if (laKind == (Final))
                    {
                        ss.IsFinal = true;
                        Step();
                    }
                    Step();
                    Expect(OpenParenthesis);
                    ss.SwitchExpression = Expression(Scope);
                    Expect(CloseParenthesis);

                    if(!IsEOF)
                        ss.ScopedStatement = Statement(Scope: Scope, Parent: ss);
                    ss.EndLocation = t.EndLocation;

                    return ss;
                case Case:
                    Step();

                    var sscs = new SwitchStatement.CaseStatement() { Location = la.Location, Parent = Parent };
                    sscs.ArgumentList = Expression(Scope);

                    Expect(Colon);

                    // CaseRangeStatement
                    if (laKind == DoubleDot)
                    {
                        Step();
                        Expect(Case);
                        sscs.LastExpression = AssignExpression();
                        Expect(Colon);
                    }

                    var sscssl = new List<IStatement>();

                    while (laKind != Case && laKind != Default && laKind != CloseCurlyBrace && !IsEOF)
                    {
                        var stmt = Statement(Scope: Scope, Parent: sscs);

                        if (stmt != null)
                        {
                            stmt.Parent = sscs;
                            sscssl.Add(stmt);
                        }
                    }

                    sscs.ScopeStatementList = sscssl.ToArray();
                    sscs.EndLocation = t.EndLocation;

                    return sscs;
                case Default:
                    Step();

                    var ssds = new SwitchStatement.DefaultStatement()
                    {
                        Location = la.Location,
                        Parent = Parent
                    };

                    Expect(Colon);

                    var ssdssl = new List<IStatement>();

                    while (laKind != Case && laKind != Default && laKind != CloseCurlyBrace && !IsEOF)
                    {
                        var stmt = Statement(Scope: Scope, Parent: ssds);

                        if (stmt != null)
                        {
                            stmt.Parent = ssds;
                            ssdssl.Add(stmt);
                        }
                    }

                    ssds.ScopeStatementList = ssdssl.ToArray();
                    ssds.EndLocation = t.EndLocation;

                    return ssds;
                case Continue:
                    Step();
                    var cs = new ContinueStatement() { Location = t.Location, Parent = Parent };
                    if (laKind == (Identifier))
                    {
                        Step();
                        cs.Identifier = t.Value;
                    }
                    else if(IsEOF)
                        cs.IdentifierHash = DTokens.IncompleteIdHash;

                    Expect(Semicolon);
                    cs.EndLocation = t.EndLocation;

                    return cs;
                case Break:
                    Step();
                    var bs = new BreakStatement() { Location = t.Location, Parent = Parent };

                    if (laKind == (Identifier))
                    {
                        Step();
                        bs.Identifier = t.Value;
                    }
                    else if(IsEOF)
                        bs.IdentifierHash = DTokens.IncompleteIdHash;

                    Expect(Semicolon);

                    bs.EndLocation = t.EndLocation;

                    return bs;
                case Return:
                    Step();
                    var rs = new ReturnStatement() { Location = t.Location, Parent = Parent };

                    if (laKind != (Semicolon))
                        rs.ReturnExpression = Expression(Scope);

                    Expect(Semicolon);
                    rs.EndLocation = t.EndLocation;

                    return rs;
                case Goto:
                    Step();
                    var gs = new GotoStatement() { Location = t.Location, Parent = Parent };

                    switch(laKind)
                    {
                        case Identifier:
                            Step();
                            gs.StmtType = GotoStatement.GotoStmtType.Identifier;
                            gs.LabelIdentifier = t.Value;
                            break;
                        case Default:
                            Step();
                            gs.StmtType = GotoStatement.GotoStmtType.Default;
                            break;
                        case Case:
                            Step();
                            gs.StmtType = GotoStatement.GotoStmtType.Case;

                            if (laKind != (Semicolon))
                                gs.CaseExpression = Expression(Scope);
                            break;
                        default:
                            if (IsEOF)
                                gs.LabelIdentifierHash = DTokens.IncompleteIdHash;
                            break;
                    }
                    Expect(Semicolon);
                    gs.EndLocation = t.EndLocation;

                    return gs;
                case With:
                    Step();

                    var wS = new WithStatement() { Location = t.Location, Parent = Parent };

                    if(Expect(OpenParenthesis))
                    {
                        // Symbol
                        wS.WithExpression = Expression(Scope);

                        Expect(CloseParenthesis);

                        if(!IsEOF)
                            wS.ScopedStatement = Statement(Scope: Scope, Parent: wS);
                    }
                    wS.EndLocation = t.EndLocation;
                    return wS;
                case Synchronized:
                    Step();
                    var syncS = new SynchronizedStatement() { Location = t.Location, Parent = Parent };

                    if (laKind == (OpenParenthesis))
                    {
                        Step();
                        syncS.SyncExpression = Expression(Scope);
                        Expect(CloseParenthesis);
                    }

                    if(!IsEOF)
                        syncS.ScopedStatement = Statement(Scope: Scope, Parent: syncS);
                    syncS.EndLocation = t.EndLocation;

                    return syncS;
                case Try:
                    Step();

                    var ts = new TryStatement() { Location = t.Location, Parent = Parent };

                    ts.ScopedStatement = Statement(Scope: Scope, Parent: ts);

                    if (!(laKind == (Catch) || laKind == (Finally)))
                        SemErr(Catch, "At least one catch or a finally block expected!");

                    var catches = new List<TryStatement.CatchStatement>();
                    // Catches
                    while (laKind == (Catch))
                    {
                        Step();

                        var c = new TryStatement.CatchStatement() { Location = t.Location, Parent = ts };

                        // CatchParameter
                        if (laKind == (OpenParenthesis))
                        {
                            Step();

                            if (laKind == CloseParenthesis || IsEOF)
                            {
                                SemErr(CloseParenthesis, "Catch parameter expected, not ')'");
                                Step();
                            }
                            else
                            {
                                var catchVar = new DVariable { Parent = Scope, Location = t.Location };

                                Lexer.PushLookAheadBackup();
                                catchVar.Type = BasicType();
                                if (laKind == CloseParenthesis)
                                {
                                    Lexer.RestoreLookAheadBackup();
                                    catchVar.Type = new IdentifierDeclaration("Exception");
                                }
                                else
                                    Lexer.PopLookAheadBackup();

                                if (Expect(Identifier))
                                {
                                    catchVar.Name = t.Value;
                                    catchVar.NameLocation = t.Location;
                                    Expect(CloseParenthesis);
                                }
                                else if(IsEOF)
                                    catchVar.NameHash = DTokens.IncompleteIdHash;

                                catchVar.EndLocation = t.EndLocation;
                                c.CatchParameter = catchVar;
                            }
                        }

                        if(!IsEOF)
                            c.ScopedStatement = Statement(Scope: Scope, Parent: c);
                        c.EndLocation = t.EndLocation;

                        catches.Add(c);
                    }

                    if (catches.Count > 0)
                        ts.Catches = catches.ToArray();

                    if (laKind == (Finally))
                    {
                        Step();

                        var f = new TryStatement.FinallyStatement() { Location = t.Location, Parent = Parent };

                        f.ScopedStatement = Statement();
                        f.EndLocation = t.EndLocation;

                        ts.FinallyStmt = f;
                    }

                    ts.EndLocation = t.EndLocation;
                    return ts;
                case Throw:
                    Step();
                    var ths = new ThrowStatement() { Location = t.Location, Parent = Parent };

                    ths.ThrowExpression = Expression(Scope);
                    Expect(Semicolon);
                    ths.EndLocation = t.EndLocation;

                    return ths;
                case DTokens.Scope:
                    Step();

                    if (laKind == OpenParenthesis)
                    {
                        var s = new ScopeGuardStatement() {
                            Location = t.Location,
                            Parent = Parent
                        };

                        Step();

                        if (Expect(Identifier) && t.Value != null) // exit, failure, success
                            s.GuardedScope = t.Value.ToLower();
                        else if (IsEOF)
                            s.GuardedScope = DTokens.IncompleteId;

                        Expect(CloseParenthesis);

                        s.ScopedStatement = Statement(Scope: Scope, Parent: s);

                        s.EndLocation = t.EndLocation;
                        return s;
                    }
                    else
                        PushAttribute(new Modifier(DTokens.Scope), false);
                    goto default;
                case Asm:
                    return ParseAsmStatement(Scope, Parent);
                case Pragma:
                    var ps = new PragmaStatement { Location = la.Location };

                    ps.Pragma = _Pragma();
                    ps.Parent = Parent;

                    ps.ScopedStatement = Statement(Scope: Scope, Parent: ps);
                    ps.EndLocation = t.EndLocation;
                    return ps;
                case Mixin:
                    if (Peek(1).Kind == OpenParenthesis)
                    {
                        OverPeekBrackets(OpenParenthesis);
                        if (Lexer.CurrentPeekToken.Kind != Semicolon)
                            return ExpressionStatement(Scope, Parent);
                        return MixinDeclaration(Scope, Parent);
                    }
                    else
                    {
                        var tmx = TemplateMixin(Scope, Parent);
                        if (tmx.MixinId == null)
                            return tmx;
                        else
                            return new DeclarationStatement { Declarations = new[] { new NamedTemplateMixinNode(tmx) }, Parent = Parent };
                    }
                case Assert:
                    var isStatic = laKind == Static;
                    AssertStatement asS;
                    if (isStatic)
                    {
                        Step();
                        asS = new StaticAssertStatement { Location = la.Location, Parent = Parent };
                    }
                    else
                        asS = new AssertStatement() { Location = la.Location, Parent = Parent };

                    Step();

                    if (Expect(OpenParenthesis))
                    {
                        asS.AssertedExpression = Expression(Scope);
                        Expect(CloseParenthesis);
                        Expect(Semicolon);
                    }
                    asS.EndLocation = t.EndLocation;

                    return asS;
                case Volatile:
                    Step();
                    var vs = new VolatileStatement() { Location = t.Location, Parent = Parent };

                    vs.ScopedStatement = Statement(Scope: Scope, Parent: vs);
                    vs.EndLocation = t.EndLocation;

                    return vs;
                case Import:
                    if(laKind == Static)
                        Step(); // Will be handled in ImportDeclaration

                    return ImportDeclaration(Scope);
                case Enum:
                case Alias:
                case Typedef:
                    var ds = new DeclarationStatement() { Location = la.Location, Parent = Parent, ParentNode = Scope };
                    ds.Declarations = Declaration(Scope);

                    ds.EndLocation = t.EndLocation;
                    return ds;
                default:
                    if (IsClassLike(laKind) || (IsBasicType(laKind) && Lexer.CurrentPeekToken.Kind != Dot) || IsModifier(laKind))
                        goto case Typedef;
                    if (IsAssignExpression())
                        return ExpressionStatement(Scope, Parent);
                    goto case Typedef;

            }
        }
Exemplo n.º 44
0
        IStatement Statement(bool BlocksAllowed = true, bool EmptyAllowed = true, IBlockNode Scope = null, IStatement Parent=null)
        {
            if (EmptyAllowed && laKind == Semicolon)
            {
                LastParsedObject = null;
                Step();
                return null;
            }

            if (BlocksAllowed && laKind == OpenCurlyBrace)
                return BlockStatement(Scope,Parent);

            #region LabeledStatement (loc:... goto loc;)
            if (laKind == Identifier && Lexer.CurrentPeekToken.Kind == Colon)
            {
                Step();

                var ret = new LabeledStatement() { Location = t.Location, Identifier = t.Value, Parent = Parent };
                LastParsedObject = ret;
                Step();
                ret.EndLocation = t.EndLocation;

                return ret;
            }
            #endregion

            #region IfStatement
            else if (laKind == (If) || (laKind == Static && Lexer.CurrentPeekToken.Kind == If))
            {
                bool isStatic = laKind == Static;
                if (isStatic)
                    Step();

                Step();

                var dbs = new IfStatement() { Location = t.Location, IsStatic = isStatic, Parent = Parent };
                LastParsedObject = dbs;
                Expect(OpenParenthesis);

                // IfCondition
                IfCondition(dbs);

                // ThenStatement
                if(Expect(CloseParenthesis))
                    dbs.ThenStatement = Statement(Scope: Scope, Parent: dbs);

                // ElseStatement
                if (laKind == (Else))
                {
                    Step();
                    dbs.ElseStatement = Statement(Scope: Scope, Parent: dbs);
                }

                dbs.EndLocation = t.EndLocation;

                return dbs;
            }
            #endregion

            #region WhileStatement
            else if (laKind == While)
            {
                Step();

                var dbs = new WhileStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = dbs;
                Expect(OpenParenthesis);
                dbs.Condition = Expression(Scope);
                Expect(CloseParenthesis);

                dbs.ScopedStatement = Statement(Scope: Scope, Parent: dbs);
                dbs.EndLocation = t.EndLocation;

                return dbs;
            }
            #endregion

            #region DoStatement
            else if (laKind == (Do))
            {
                Step();

                var dbs = new WhileStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = dbs;
                dbs.ScopedStatement = Statement(Scope: Scope, Parent: dbs);

                Expect(While);
                Expect(OpenParenthesis);
                dbs.Condition = Expression(Scope);
                Expect(CloseParenthesis);

                dbs.EndLocation = t.EndLocation;

                return dbs;
            }
            #endregion

            #region ForStatement
            else if (laKind == (For))
            {
                Step();

                var dbs = new ForStatement { Location = t.Location, Parent = Parent };
                LastParsedObject = dbs;
                Expect(OpenParenthesis);

                // Initialize
                if (laKind != Semicolon)
                    dbs.Initialize = Statement(false, Scope: Scope, Parent: dbs); // Against the D language theory, blocks aren't allowed here!
                else
                    Step();
                // Enforce a trailing semi-colon only if there hasn't been an expression (the ; gets already skipped in there)
                //	Expect(Semicolon);

                // Test
                if (laKind != (Semicolon))
                    dbs.Test = Expression(Scope);

                Expect(Semicolon);

                // Increment
                if (laKind != (CloseParenthesis))
                    dbs.Increment = Expression(Scope);

                Expect(CloseParenthesis);

                dbs.ScopedStatement = Statement(Scope: Scope, Parent: dbs);
                dbs.EndLocation = t.EndLocation;

                return dbs;
            }
            #endregion

            #region ForeachStatement
            else if (laKind == Foreach || laKind == Foreach_Reverse)
                return ForeachStatement(Scope, Parent);
            #endregion

            #region [Final] SwitchStatement
            else if ((laKind == (Final) && Lexer.CurrentPeekToken.Kind == (Switch)) || laKind == (Switch))
            {
                var dbs = new SwitchStatement { Location = la.Location, Parent = Parent };
                LastParsedObject = dbs;
                if (laKind == (Final))
                {
                    dbs.IsFinal = true;
                    Step();
                }
                Step();
                Expect(OpenParenthesis);
                dbs.SwitchExpression = Expression(Scope);
                Expect(CloseParenthesis);

                dbs.ScopedStatement = Statement(Scope: Scope, Parent: dbs);
                dbs.EndLocation = t.EndLocation;

                return dbs;
            }
            #endregion

            #region CaseStatement
            else if (laKind == (Case))
            {
                Step();

                var dbs = new SwitchStatement.CaseStatement() { Location = la.Location, Parent = Parent };
                LastParsedObject = dbs;
                dbs.ArgumentList = Expression(Scope);

                Expect(Colon);

                // CaseRangeStatement
                if (laKind == DoubleDot)
                {
                    Step();
                    Expect(Case);
                    dbs.LastExpression = AssignExpression();
                    Expect(Colon);
                }

                var sl = new List<IStatement>();

                while (laKind != Case && laKind != Default && laKind != CloseCurlyBrace && !IsEOF)
                {
                    var stmt = Statement(Scope: Scope, Parent: dbs);

                    if (stmt != null)
                    {
                        stmt.Parent = dbs;
                        sl.Add(stmt);
                    }
                }

                dbs.ScopeStatementList = sl.ToArray();
                dbs.EndLocation = t.EndLocation;

                return dbs;
            }
            #endregion

            #region Default
            else if (laKind == (Default))
            {
                Step();

                var dbs = new SwitchStatement.DefaultStatement()
                {
                    Location = la.Location,
                    Parent = Parent
                };
                LastParsedObject = dbs;

                Expect(Colon);

                var sl = new List<IStatement>();

                while (laKind != Case && laKind != Default && laKind != CloseCurlyBrace && !IsEOF)
                {
                    var stmt = Statement(Scope: Scope, Parent: dbs);

                    if (stmt != null)
                    {
                        stmt.Parent = dbs;
                        sl.Add(stmt);
                    }
                }

                dbs.ScopeStatementList = sl.ToArray();
                dbs.EndLocation = t.EndLocation;

                return dbs;
            }
            #endregion

            #region Continue | Break
            else if (laKind == (Continue))
            {
                Step();
                var s = new ContinueStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;
                if (laKind == (Identifier))
                {
                    Step();
                    s.Identifier = t.Value;
                }
                Expect(Semicolon);
                s.EndLocation = t.EndLocation;

                return s;
            }

            else if (laKind == (Break))
            {
                Step();
                var s = new BreakStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;
                if (laKind == (Identifier))
                {
                    Step();
                    s.Identifier = t.Value;
                }
                Expect(Semicolon);
                s.EndLocation = t.EndLocation;

                return s;
            }
            #endregion

            #region Return
            else if (laKind == (Return))
            {
                Step();
                var s = new ReturnStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;
                if (laKind != (Semicolon))
                    s.ReturnExpression = Expression(Scope);

                Expect(Semicolon);
                s.EndLocation = t.EndLocation;

                return s;
            }
            #endregion

            #region Goto
            else if (laKind == (Goto))
            {
                Step();
                var s = new GotoStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;

                if (laKind == (Identifier))
                {
                    Step();
                    s.StmtType = GotoStatement.GotoStmtType.Identifier;
                    s.LabelIdentifier = t.Value;
                }
                else if (laKind == Default)
                {
                    Step();
                    s.StmtType = GotoStatement.GotoStmtType.Default;
                }
                else if (laKind == (Case))
                {
                    Step();
                    s.StmtType = GotoStatement.GotoStmtType.Case;

                    if (laKind != (Semicolon))
                        s.CaseExpression = Expression(Scope);
                }

                Expect(Semicolon);
                s.EndLocation = t.EndLocation;

                return s;
            }
            #endregion

            #region WithStatement
            else if (laKind == (With))
            {
                Step();

                var dbs = new WithStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = dbs;
                Expect(OpenParenthesis);

                // Symbol
                dbs.WithExpression = Expression(Scope);

                Expect(CloseParenthesis);

                dbs.ScopedStatement = Statement(Scope: Scope, Parent: dbs);

                dbs.EndLocation = t.EndLocation;
                return dbs;
            }
            #endregion

            #region SynchronizedStatement
            else if (laKind == (Synchronized))
            {
                Step();
                var dbs = new SynchronizedStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = dbs;

                if (laKind == (OpenParenthesis))
                {
                    Step();
                    dbs.SyncExpression = Expression(Scope);
                    Expect(CloseParenthesis);
                }

                dbs.ScopedStatement = Statement(Scope: Scope, Parent: dbs);

                dbs.EndLocation = t.EndLocation;
                return dbs;
            }
            #endregion

            #region TryStatement
            else if (laKind == (Try))
            {
                Step();

                var s = new TryStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;

                s.ScopedStatement = Statement(Scope: Scope, Parent: s);

                if (!(laKind == (Catch) || laKind == (Finally)))
                    SemErr(Catch, "At least one catch or a finally block expected!");

                var catches = new List<TryStatement.CatchStatement>();
                // Catches
                while (laKind == (Catch))
                {
                    Step();

                    var c = new TryStatement.CatchStatement() { Location = t.Location, Parent = s };
                    LastParsedObject = c;

                    // CatchParameter
                    if (laKind == (OpenParenthesis))
                    {
                        Step();

                        if (laKind == CloseParenthesis)
                        {
                            SemErr(CloseParenthesis, "Catch parameter expected, not ')'");
                            Step();
                        }
                        else
                        {
                            var catchVar = new DVariable();
                            LastParsedObject = catchVar;
                            var tt = la; //TODO?
                            catchVar.Type = BasicType();
                            if (laKind != Identifier)
                            {
                                la = tt;
                                catchVar.Type = new IdentifierDeclaration("Exception");
                            }
                            Expect(Identifier);
                            catchVar.Name = t.Value;
                            Expect(CloseParenthesis);

                            c.CatchParameter = catchVar;
                        }
                    }

                    c.ScopedStatement = Statement(Scope: Scope, Parent: c);
                    c.EndLocation = t.EndLocation;

                    catches.Add(c);
                }

                if (catches.Count > 0)
                    s.Catches = catches.ToArray();

                if (laKind == (Finally))
                {
                    Step();

                    var f = new TryStatement.FinallyStatement() { Location = t.Location, Parent = Parent };
                    LastParsedObject = f;

                    f.ScopedStatement = Statement();
                    f.EndLocation = t.EndLocation;

                    s.FinallyStmt = f;
                }

                s.EndLocation = t.EndLocation;
                return s;
            }
            #endregion

            #region ThrowStatement
            else if (laKind == (Throw))
            {
                Step();
                var s = new ThrowStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;

                s.ThrowExpression = Expression(Scope);
                Expect(Semicolon);
                s.EndLocation = t.EndLocation;

                return s;
            }
            #endregion

            #region ScopeGuardStatement
            else if (laKind == DTokens.Scope)
            {
                Step();

                if (laKind == OpenParenthesis)
                {
                    var s = new ScopeGuardStatement() { Location = t.Location, Parent = Parent };
                    LastParsedObject = s;

                    Step();

                    if (Expect(Identifier) && t.Value != null) // exit, failure, success
                        s.GuardedScope = t.Value.ToLower();

                    if (Expect(CloseParenthesis))
                        TrackerVariables.ExpectingIdentifier = false;

                    if (!IsEOF)
                        s.ScopedStatement = Statement(Scope: Scope, Parent: s);

                    s.EndLocation = t.EndLocation;
                    return s;
                }
                else
                    PushAttribute(new DAttribute(DTokens.Scope), false);
            }
            #endregion

            #region AsmStmt
            else if (laKind == Asm)
                return AsmStatement(Parent);
            #endregion

            #region PragmaStatement
            else if (laKind == (Pragma))
            {
                var s = new PragmaStatement { Location = la.Location };

                s.Pragma = _Pragma();
                s.Parent = Parent;

                s.ScopedStatement = Statement(Scope: Scope, Parent: s);
                s.EndLocation = t.EndLocation;
                return s;
            }
            #endregion

            #region MixinStatement
            //TODO: Handle this one in terms of adding it to the node structure
            else if (laKind == (Mixin))
            {
                if (Peek(1).Kind == OpenParenthesis)
                    return MixinDeclaration();
                else
                    return TemplateMixin();
            }
            #endregion

            #region Conditions
            if (laKind == Debug)
                return DebugStatement(Scope, Parent);

            if (laKind == Version)
                return VersionStatement(Scope, Parent);
            #endregion

            #region (Static) AssertExpression
            else if (laKind == Assert || (laKind == Static && PK(Assert)))
            {
                var s = new AssertStatement() { Location = la.Location, IsStatic = laKind == Static, Parent = Parent };
                LastParsedObject = s;

                if (s.IsStatic)
                    Step();

                Step();

                if (Expect(OpenParenthesis))
                {
                    s.AssertedExpression = Expression(Scope);
                    Expect(CloseParenthesis);
                    Expect(Semicolon);
                }
                s.EndLocation = t.EndLocation;

                return s;
            }
            #endregion

            #region D1: VolatileStatement
            else if (laKind == Volatile)
            {
                Step();
                var s = new VolatileStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;
                s.ScopedStatement = Statement(Scope: Scope, Parent: s);
                s.EndLocation = t.EndLocation;

                return s;
            }
            #endregion

            // ImportDeclaration
            else if (laKind == Import)
                return ImportDeclaration();

            else if (!(ClassLike[laKind] || BasicTypes[laKind] || laKind == Enum || Modifiers[laKind] || laKind == PropertyAttribute || laKind == Alias || laKind == Typedef) && IsAssignExpression())
            {
                var s = new ExpressionStatement() { Location = la.Location, Parent = Parent };

                if (!IsEOF)
                    LastParsedObject = s;
                // a==b, a=9; is possible -> Expressions can be there, not only single AssignExpressions!
                s.Expression = Expression(Scope);

                if (Expect(Semicolon))
                    LastParsedObject = null;

                s.EndLocation = t.EndLocation;
                return s;
            }
            else
            {
                var s = new DeclarationStatement() { Location = la.Location, Parent = Parent };
                LastParsedObject = s;
                s.Declarations = Declaration(Scope);

                s.EndLocation = t.EndLocation;
                return s;
            }
        }
Exemplo n.º 45
0
 public virtual void Exit(TryStatement node)
 {
 }
Exemplo n.º 46
0
 public void Visit(TryStatement.FinallyStatement finallyStatement)
 {
 }
Exemplo n.º 47
0
 public override bool Enter(TryStatement node)
 {
     Print("TryStatement");
     level++;
     return true;
 }
Exemplo n.º 48
0
        /// <summary>
        /// Checks the given try statement to make sure that it is needed.
        /// </summary>
        /// <param name="tryStatement">The try statement to check.</param>
        /// <returns>Returns true if the try statement is not needed, false otherwise.</returns>
        private static bool IsUnnecessaryTryStatement(TryStatement tryStatement)
        {
            Param.AssertNotNull(tryStatement, "tryStatement");

            // If the body of the try-statement is empty, it is not needed.
            if (IsEmptyParentOfBlockStatement(tryStatement))
            {
                // If the try-statement contains a non-empty finally or a non-empty catch statement, then it is allowed to be empty.
                // This is because an empty try-statement can be used to create a critical execution region and the finally or catch areas
                // will run even in the case of a ThreadAbortException.
                if (tryStatement.FinallyStatement != null && !IsEmptyParentOfBlockStatement(tryStatement.FinallyStatement))
                {
                    return false;
                }

                if (tryStatement.CatchStatements != null && tryStatement.CatchStatements.Count > 0)
                {
                    foreach (CatchStatement catchStatement in tryStatement.CatchStatements)
                    {
                        if (!IsEmptyParentOfBlockStatement(catchStatement))
                        {
                            return false;
                        }
                    }
                }

                return true;
            }
            else
            {
                // If the try-statement does not contain any catch statements or finally statements, it is not needed.
                if (tryStatement.CatchStatements == null || tryStatement.CatchStatements.Count == 0)
                {
                    if (tryStatement.FinallyStatement == null || IsEmptyParentOfBlockStatement(tryStatement.FinallyStatement))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
		public virtual void Visit(TryStatement s)
		{
			VisitChildren(s);
		}
Exemplo n.º 50
0
 /**
  * Call back method that must be called when the given <code>TryStatement
  * </code> will become the next <i>traverse candidate</i>.
  *
  * @param pTryStatement  The <code>TryStatement</code> object that will
  *                       become the next <i>traverse candidate</i>.
  */
 public void performAction(
      TryStatement pTryStatement)
 {
     // Nothing to do.
 }
Exemplo n.º 51
0
 // TryStatement
 public override bool Walk(TryStatement node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
Exemplo n.º 52
0
 /**
  * Call back method that must be called as soon as the given <code>
  * TryStatement</code> object has been traversed.
  *
  * @param pTryStatement  The <code>TryStatement</code> object that has just
  *                       been traversed.
  */
 public void actionPerformed(
      TryStatement pTryStatement)
 {
     // Nothing to do.
 }
Exemplo n.º 53
0
 protected internal virtual void PostWalk(TryStatement node) { }
Exemplo n.º 54
0
 public override object Walk(TryStatement node)
 {
     object result = null;
     try
     {
         result = node.Body.Accept(this);
     }
     catch (Exception e)
     {
         if (e is ControlFlow || node.Rescue == null)
             throw;
         Action body = () => node.Rescue.Accept(this);
         Action<ScopeFrame> init = scopeFrame => scopeFrame.Define(node.Rescue.Identifier.Value, e);
         Context.OpenScopeFor(body, withInit: init, when: node.Rescue.Identifier != null);
     }
     finally
     {
         if (node.Finally != null)
             node.Finally.Accept(this);
     }
     return result;
 }
Exemplo n.º 55
0
 // TryStatement
 public virtual bool Walk(TryStatement node) { return true; }
Exemplo n.º 56
0
        public void Visit(TryStatement expression)
        {
            outStream.WriteLine("try {");
            expression.Statement.Accept(this);            
            if (expression.Catch != null)
            {
                outStream.WriteLine("}} catch ({0}) {{", expression.Catch.Identifier);
                expression.Catch.Statement.Accept(this);
            }

            if (expression.Finally != null)
            {
                outStream.WriteLine("} finally {");
                expression.Finally.Statement.Accept(this);
            }

            outStream.WriteLine("}");
        }
Exemplo n.º 57
0
 // TryStatement
 public override bool Walk(TryStatement node) { return false; }
Exemplo n.º 58
0
 public void VisitTry(TryStatement t)
 {
     var tryStmt = gen.Try(
         () => t.body.Accept(this),
         t.exHandlers.Select(eh => GenerateClause(eh)),
         () =>
         {
             if (t.finallyHandler != null)
                 t.finallyHandler.Accept(this);
         });
 }
Exemplo n.º 59
0
 public void Visit(TryStatement.CatchStatement catchStatement)
 {
 }
Exemplo n.º 60
0
        public IStatement Statement(bool BlocksAllowed = true, bool EmptyAllowed = true, IBlockNode Scope = null, IStatement Parent=null)
        {
            if (EmptyAllowed && laKind == Semicolon)
            {
                LastParsedObject = null;
                Step();
                return null;
            }

            if (BlocksAllowed && laKind == OpenCurlyBrace)
                return BlockStatement(Scope,Parent);

            #region LabeledStatement (loc:... goto loc;)
            if (laKind == Identifier && Lexer.CurrentPeekToken.Kind == Colon)
            {
                Step();

                var ret = new LabeledStatement() { Location = t.Location, Identifier = t.Value, Parent = Parent };
                LastParsedObject = null;
                Step();
                ret.EndLocation = t.EndLocation;

                return ret;
            }
            #endregion

            #region IfStatement
            else if (laKind == (If))
            {
                Step();

                var dbs = new IfStatement{	Location = t.Location, Parent = Parent	};

                LastParsedObject = dbs;
                Expect(OpenParenthesis);

                // IfCondition
                IfCondition(dbs);

                // ThenStatement
                if(Expect(CloseParenthesis))
                    dbs.ThenStatement = Statement(Scope: Scope, Parent: dbs);

                // ElseStatement
                if (laKind == (Else))
                {
                    Step();
                    dbs.ElseStatement = Statement(Scope: Scope, Parent: dbs);
                }

                if(t != null)
                    dbs.EndLocation = t.EndLocation;

                return dbs;
            }
            #endregion

            #region Conditions
            else if ((laKind == Static && Lexer.CurrentPeekToken.Kind == If) || laKind == Version || laKind == Debug)
                return StmtCondition(Parent, Scope);
            #endregion

            #region WhileStatement
            else if (laKind == While)
            {
                Step();

                var dbs = new WhileStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = dbs;
                Expect(OpenParenthesis);
                dbs.Condition = Expression(Scope);
                Expect(CloseParenthesis);

                if(!IsEOF)
                {
                    dbs.ScopedStatement = Statement(Scope: Scope, Parent: dbs);
                    dbs.EndLocation = t.EndLocation;
                }

                return dbs;
            }
            #endregion

            #region DoStatement
            else if (laKind == (Do))
            {
                Step();

                var dbs = new WhileStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = dbs;
                if(!IsEOF)
                    dbs.ScopedStatement = Statement(true, false, Scope, dbs);

                if(Expect(While) && Expect(OpenParenthesis))
                {
                    dbs.Condition = Expression(Scope);
                    Expect(CloseParenthesis);
                    if (Expect(Semicolon))
                        LastParsedObject = null;

                    dbs.EndLocation = t.EndLocation;
                }

                return dbs;
            }
            #endregion

            #region ForStatement
            else if (laKind == (For))
                return ForStatement(Scope, Parent);
            #endregion

            #region ForeachStatement
            else if (laKind == Foreach || laKind == Foreach_Reverse)
                return ForeachStatement(Scope, Parent);
            #endregion

            #region [Final] SwitchStatement
            else if ((laKind == (Final) && Lexer.CurrentPeekToken.Kind == (Switch)) || laKind == (Switch))
            {
                var dbs = new SwitchStatement { Location = la.Location, Parent = Parent };
                LastParsedObject = dbs;
                if (laKind == (Final))
                {
                    dbs.IsFinal = true;
                    Step();
                }
                Step();
                Expect(OpenParenthesis);
                dbs.SwitchExpression = Expression(Scope);
                Expect(CloseParenthesis);

                if(!IsEOF)
                    dbs.ScopedStatement = Statement(Scope: Scope, Parent: dbs);
                dbs.EndLocation = t.EndLocation;

                return dbs;
            }
            #endregion

            #region CaseStatement
            else if (laKind == (Case))
            {
                Step();

                var dbs = new SwitchStatement.CaseStatement() { Location = la.Location, Parent = Parent };
                LastParsedObject = dbs;
                dbs.ArgumentList = Expression(Scope);

                if (Expect(Colon))
                    LastParsedObject = null;

                // CaseRangeStatement
                if (laKind == DoubleDot)
                {
                    Step();
                    Expect(Case);
                    dbs.LastExpression = AssignExpression();
                    if (Expect(Colon))
                        LastParsedObject = null;
                }

                var sl = new List<IStatement>();

                while (laKind != Case && laKind != Default && laKind != CloseCurlyBrace && !IsEOF)
                {
                    var stmt = Statement(Scope: Scope, Parent: dbs);

                    if (stmt != null)
                    {
                        stmt.Parent = dbs;
                        sl.Add(stmt);
                    }
                }

                dbs.ScopeStatementList = sl.ToArray();
                dbs.EndLocation = t.EndLocation;

                return dbs;
            }
            #endregion

            #region Default
            else if (laKind == (Default))
            {
                Step();

                var dbs = new SwitchStatement.DefaultStatement()
                {
                    Location = la.Location,
                    Parent = Parent
                };
                LastParsedObject = dbs;

                Expect(Colon);

                var sl = new List<IStatement>();

                while (laKind != Case && laKind != Default && laKind != CloseCurlyBrace && !IsEOF)
                {
                    var stmt = Statement(Scope: Scope, Parent: dbs);

                    if (stmt != null)
                    {
                        stmt.Parent = dbs;
                        sl.Add(stmt);
                    }
                }

                dbs.ScopeStatementList = sl.ToArray();
                dbs.EndLocation = t.EndLocation;

                return dbs;
            }
            #endregion

            #region Continue | Break
            else if (laKind == (Continue))
            {
                Step();
                var s = new ContinueStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;
                if (laKind == (Identifier))
                {
                    Step();
                    s.Identifier = t.Value;
                }
                if (Expect(Semicolon))
                    LastParsedObject = null;
                s.EndLocation = t.EndLocation;

                return s;
            }

            else if (laKind == (Break))
            {
                Step();
                var s = new BreakStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;
                if (laKind == (Identifier))
                {
                    Step();
                    s.Identifier = t.Value;
                }
                if (Expect(Semicolon))
                    LastParsedObject = null;
                s.EndLocation = t.EndLocation;

                return s;
            }
            #endregion

            #region Return
            else if (laKind == (Return))
            {
                Step();
                var s = new ReturnStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;
                if (laKind != (Semicolon))
                    s.ReturnExpression = Expression(Scope);

                if (Expect(Semicolon))
                    LastParsedObject = null;
                s.EndLocation = t.EndLocation;

                return s;
            }
            #endregion

            #region Goto
            else if (laKind == (Goto))
            {
                Step();
                var s = new GotoStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;

                if (laKind == (Identifier))
                {
                    Step();
                    s.StmtType = GotoStatement.GotoStmtType.Identifier;
                    s.LabelIdentifier = t.Value;
                }
                else if (laKind == Default)
                {
                    Step();
                    s.StmtType = GotoStatement.GotoStmtType.Default;
                }
                else if (laKind == (Case))
                {
                    Step();
                    s.StmtType = GotoStatement.GotoStmtType.Case;

                    if (laKind != (Semicolon))
                        s.CaseExpression = Expression(Scope);
                }

                if (Expect(Semicolon))
                    LastParsedObject = null;
                s.EndLocation = t.EndLocation;

                return s;
            }
            #endregion

            #region WithStatement
            else if (laKind == (With))
            {
                Step();

                var dbs = new WithStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = dbs;
                if(Expect(OpenParenthesis))
                {
                    // Symbol
                    dbs.WithExpression = Expression(Scope);

                    Expect(CloseParenthesis);

                    if(!IsEOF)
                        dbs.ScopedStatement = Statement(Scope: Scope, Parent: dbs);
                }
                dbs.EndLocation = t.EndLocation;
                return dbs;
            }
            #endregion

            #region SynchronizedStatement
            else if (laKind == (Synchronized))
            {
                Step();
                var dbs = new SynchronizedStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = dbs;

                if (laKind == (OpenParenthesis))
                {
                    Step();
                    dbs.SyncExpression = Expression(Scope);
                    Expect(CloseParenthesis);
                }

                if(!IsEOF)
                    dbs.ScopedStatement = Statement(Scope: Scope, Parent: dbs);
                dbs.EndLocation = t.EndLocation;

                return dbs;
            }
            #endregion

            #region TryStatement
            else if (laKind == (Try))
            {
                Step();

                var s = new TryStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;

                s.ScopedStatement = Statement(Scope: Scope, Parent: s);

                if (!(laKind == (Catch) || laKind == (Finally)))
                    SemErr(Catch, "At least one catch or a finally block expected!");

                var catches = new List<TryStatement.CatchStatement>();
                // Catches
                while (laKind == (Catch))
                {
                    Step();

                    var c = new TryStatement.CatchStatement() { Location = t.Location, Parent = s };
                    LastParsedObject = c;

                    // CatchParameter
                    if (laKind == (OpenParenthesis))
                    {
                        Step();

                        if (laKind == CloseParenthesis || IsEOF)
                        {
                            SemErr(CloseParenthesis, "Catch parameter expected, not ')'");
                            Step();
                        }
                        else
                        {
                            var catchVar = new DVariable { Parent = Scope, Location = t.Location };
                            LastParsedObject = catchVar;
                            Lexer.PushLookAheadBackup();
                            catchVar.Type = BasicType();
                            if (laKind == CloseParenthesis)
                            {
                                Lexer.RestoreLookAheadBackup();
                                catchVar.Type = new IdentifierDeclaration("Exception");
                            }
                            else
                                Lexer.PopLookAheadBackup();

                            if (Expect(Identifier))
                            {
                                catchVar.Name = t.Value;
                                catchVar.NameLocation = t.Location;
                                Expect(CloseParenthesis);
                            }
                            else if(IsEOF)
                                ExpectingNodeName = true;

                            catchVar.EndLocation = t.EndLocation;
                            c.CatchParameter = catchVar;
                        }
                    }

                    if(!IsEOF)
                        c.ScopedStatement = Statement(Scope: Scope, Parent: c);
                    c.EndLocation = t.EndLocation;

                    catches.Add(c);
                }

                if (catches.Count > 0)
                    s.Catches = catches.ToArray();

                if (laKind == (Finally))
                {
                    Step();

                    var f = new TryStatement.FinallyStatement() { Location = t.Location, Parent = Parent };
                    LastParsedObject = f;

                    f.ScopedStatement = Statement();
                    f.EndLocation = t.EndLocation;

                    s.FinallyStmt = f;
                }

                s.EndLocation = t.EndLocation;
                return s;
            }
            #endregion

            #region ThrowStatement
            else if (laKind == (Throw))
            {
                Step();
                var s = new ThrowStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;

                s.ThrowExpression = Expression(Scope);
                Expect(Semicolon);
                s.EndLocation = t.EndLocation;

                return s;
            }
            #endregion

            #region ScopeGuardStatement
            else if (laKind == DTokens.Scope)
            {
                Step();

                if (laKind == OpenParenthesis)
                {
                    var s = new ScopeGuardStatement() { Location = t.Location, Parent = Parent };
                    LastParsedObject = s;

                    Step();

                    if (Expect(Identifier) && t.Value != null) // exit, failure, success
                        s.GuardedScope = t.Value.ToLower();

                    if (Expect(CloseParenthesis))
                        TrackerVariables.ExpectingIdentifier = false;

                    if (!IsEOF)
                        s.ScopedStatement = Statement(Scope: Scope, Parent: s);

                    s.EndLocation = t.EndLocation;
                    return s;
                }
                else
                    PushAttribute(new Modifier(DTokens.Scope), false);
            }
            #endregion

            #region AsmStmt
            else if (laKind == Asm)
                return AsmStatement(Parent);
            #endregion

            #region PragmaStatement
            else if (laKind == (Pragma))
            {
                var s = new PragmaStatement { Location = la.Location };

                s.Pragma = _Pragma();
                s.Parent = Parent;

                s.ScopedStatement = Statement(Scope: Scope, Parent: s);
                s.EndLocation = t.EndLocation;
                return s;
            }
            #endregion

            #region MixinStatement
            else if (laKind == (Mixin))
            {
                if (Peek(1).Kind == OpenParenthesis)
                {
                    OverPeekBrackets(OpenParenthesis);
                    if (Lexer.CurrentPeekToken.Kind != Semicolon)
                        return ExpressionStatement(Scope, Parent);
                    return MixinDeclaration(Scope, Parent);
                }
                else
                {
                    var tmx = TemplateMixin(Scope, Parent);
                    if (tmx.MixinId == null)
                        return tmx;
                    else
                        return new DeclarationStatement { Declarations = new[] { new NamedTemplateMixinNode(tmx) }, Parent = Parent };
                }
            }
            #endregion

            #region (Static) AssertExpression
            else if (laKind == Assert || (laKind == Static && Lexer.CurrentPeekToken.Kind == Assert))
            {
                var isStatic = laKind == Static;
                AssertStatement s;
                if (isStatic)
                {
                    Step();
                    s = new StaticAssertStatement { Location = la.Location, Parent = Parent };
                }
                else
                    s = new AssertStatement() { Location = la.Location, Parent = Parent };
                LastParsedObject = s;

                Step();

                if (Expect(OpenParenthesis))
                {
                    s.AssertedExpression = Expression(Scope);
                    if(Expect(CloseParenthesis) && Expect(Semicolon))
                        LastParsedObject = null;
                }
                s.EndLocation = t.EndLocation;

                return s;
            }
            #endregion

            #region D1: VolatileStatement
            else if (laKind == Volatile)
            {
                Step();
                var s = new VolatileStatement() { Location = t.Location, Parent = Parent };
                LastParsedObject = s;
                s.ScopedStatement = Statement(Scope: Scope, Parent: s);
                s.EndLocation = t.EndLocation;

                return s;
            }
            #endregion

            // ImportDeclaration
            else if (laKind == Import || (laKind == Static && Lexer.CurrentPeekToken.Kind == Import))
            {
                if(laKind == Static)
                    Step(); // Will be handled in ImportDeclaration

                return ImportDeclaration(Scope);
            }

            else if (!(ClassLike[laKind] || BasicTypes[laKind] || laKind == Enum || Modifiers[laKind] || IsAtAttribute || laKind == Alias || laKind == Typedef) && IsAssignExpression())
                return ExpressionStatement(Scope, Parent);

            var ds = new DeclarationStatement() { Location = la.Location, Parent = Parent, ParentNode = Scope };
            LastParsedObject = ds;
            ds.Declarations = Declaration(Scope);

            ds.EndLocation = t.EndLocation;
            return ds;
        }