/// <summary> /// http://www.ecma-international.org/ecma-262/5.1/#sec-12.10 /// </summary> /// <param name="withStatement"></param> /// <returns></returns> public Completion ExecuteWithStatement(WithStatement withStatement) { var val = _engine.EvaluateExpression(withStatement.Object); var obj = TypeConverter.ToObject(_engine, _engine.GetValue(val)); var oldEnv = _engine.ExecutionContext.LexicalEnvironment; var newEnv = LexicalEnvironment.NewObjectEnvironment(_engine, obj, oldEnv, true); _engine.ExecutionContext.LexicalEnvironment = newEnv; Completion c; try { c = ExecuteStatement(withStatement.Body); } catch (JavaScriptException e) { c = new Completion(Completion.Throw, e.Error, null); c.Location = withStatement.Location; } finally { _engine.ExecutionContext.LexicalEnvironment = oldEnv; } return(c); }
public void HandleWith(WithStatement node) { foreach (var item in node.Items.Where(x => x.Variable != null)) { var contextManager = Eval.GetValueFromExpression(item.ContextManager); var cmType = contextManager?.GetPythonType(); IMember context = Eval.UnknownType; var enter = cmType?.GetMember(node.IsAsync ? @"__aenter__" : @"__enter__")?.GetPythonType <IPythonFunctionType>(); if (enter != null) { var instance = contextManager as IPythonInstance; var callExpr = item.ContextManager as CallExpression; context = Eval.GetValueFromFunctionType(enter, instance, callExpr); // If fetching context from __enter__ failed, annotation in the stub may be using // type from typing that we haven't specialized yet or there may be an issue in // the stub itself, such as type or incorrect type. Try using context manager then. context = context.IsUnknown() ? contextManager : context; } switch (item.Variable) { case NameExpression nameExpr when !string.IsNullOrEmpty(nameExpr.Name): Eval.DeclareVariable(nameExpr.Name, context, VariableSource.Declaration, item); break; case ParenthesisExpression parExpr: case SequenceExpression seqExpr: var sequenceHandler = new SequenceExpressionHandler(Walker); SequenceExpressionHandler.Assign(new[] { item.Variable }, context, Eval); break; } } }
private UstSpecific.WithStatement VisitWithStatement(WithStatement withStatement) { var expr = VisitExpression(withStatement.Object); var stmt = VisitStatement(withStatement.Body); return(new UstSpecific.WithStatement(expr, stmt, GetTextSpan(withStatement))); }
public override object VisitWithStatement(WithStatement withStatement, object data) { withStatement.Body.AcceptVisitor(new ReplaceWithAccessTransformer(withStatement.Expression), data); base.VisitWithStatement(withStatement, data); ReplaceCurrentNode(withStatement.Body); return(null); }
public override bool Visit(WithStatement node) { Visit((Statement)node); TraversePrint(node.with); TraversePrint(node.body); return(true); }
public virtual Statement visit(WithStatement withStatement) { withStatement.expression = visitExpression(withStatement.expression); withStatement.statement = visitStatement(withStatement.statement); return(withStatement); }
public override object VisitWithStatement(WithStatement withStatement, object data) { withStatementCount++; string varName = "_with" + withStatementCount; WithConvertVisitor converter = new WithConvertVisitor(varName); LocalVariableDeclaration withVariable = new LocalVariableDeclaration(new VariableDeclaration(varName, withStatement.Expression, new TypeReference("var", true))); withStatement.Body.AcceptVisitor(converter, null); base.VisitWithStatement(withStatement, data); var statements = withStatement.Body.Children; statements.Insert(0, withVariable); withVariable.Parent = withStatement.Body; statements.Reverse(); foreach (var stmt in statements) { InsertAfterSibling(withStatement, stmt); } RemoveCurrentNode(); return(null); }
public override bool Walk(WithStatement node) { CanComplete = true; CommitByDefault = true; if (node.Items != null) { var item = node.Items.LastOrDefault(); if (item != null) { if (item.Variable != null) { CanComplete = false; } else { item.Walk(this); } } } if (node.Body != null) { node.Body.Walk(this); } return(false); }
public void WithStatementHelpersRequiresStatement() { WithStatement statement = null; Expect.Throw <ArgumentNullException>(() => statement.Do()); Expect.Throw <ArgumentNullException>(() => statement.Do(new List <Statement>())); }
private SyntaxResult <SyntaxNode> TranslateStatement_With(WithStatement withStatement, TranslatorState state) { var contextManager = TranslateExpression(withStatement.ContextManager, state); var body = TranslateBlock_Block(withStatement.Body, state); if (contextManager.IsError) { return(SyntaxResult <SyntaxNode> .WithErrors(contextManager.Errors)); } var usingStatement = SyntaxFactory.UsingStatement(body).WithExpression(contextManager.Syntax); if (withStatement.Variable != null) { if (withStatement.Variable is NameExpression nameExpression) { var declarationType = SyntaxFactory.ParseTypeName("object"); var variable = SyntaxFactory.VariableDeclarator(nameExpression.Name); var declaration = SyntaxFactory.VariableDeclaration(declarationType, SyntaxFactory.SingletonSeparatedList(variable)); usingStatement = usingStatement.WithDeclaration(declaration); } else { return(SyntaxResult <SyntaxNode> .WithError($"// py2cs: Unknown with statment variable ({withStatement.Variable})")); } } return(usingStatement); }
public void HandleWith(WithStatement node) { foreach (var item in node.Items.Where(x => x.Variable != null)) { var contextManager = Eval.GetValueFromExpression(item.ContextManager); var cmType = contextManager?.GetPythonType(); IMember context = Eval.UnknownType; var enter = cmType?.GetMember(node.IsAsync ? @"__aenter__" : @"__enter__")?.GetPythonType <IPythonFunctionType>(); if (enter != null) { var instance = contextManager as IPythonInstance; var callExpr = item.ContextManager as CallExpression; context = Eval.GetValueFromFunctionType(enter, instance, callExpr); // If fetching context from __enter__ failed, annotation in the stub may be using // type from typing that we haven't specialized yet or there may be an issue in // the stub itself, such as type or incorrect type. Try using context manager then. context = context ?? contextManager; } if (item.Variable is NameExpression nex && !string.IsNullOrEmpty(nex.Name)) { Eval.DeclareVariable(nex.Name, context, VariableSource.Declaration, Eval.GetLoc(item)); } } }
protected override void VisitWithStatement(WithStatement withStatement) { using (StartNodeObject(withStatement)) { Member("object", withStatement.Object); Member("body", withStatement.Body); } }
public void Visit(WithStatement expression) { outStream.Write("with ("); expression.Expression.Accept(this); outStream.WriteLine(") {"); expression.Statement.Accept(this); outStream.Write("}"); }
public override bool Walk(WithStatement node) { if (node.IsAsync) { AddSpan(Tuple.Create("", new Span(node.StartIndex, 5)), Classifications.Keyword); } return(base.Walk(node)); }
public virtual object Visit(WithStatement withStatement, object data) { Debug.Assert(withStatement != null); Debug.Assert(withStatement.Expression != null); Debug.Assert(withStatement.Body != null); withStatement.Expression.AcceptVisitor(this, data); withStatement.Body.AcceptVisitor(this, data); return(data); }
internal InsertStatement(DbContext ctx, Entity entityExecutedOn, List <Column> insertColumns, WithStatement withStatement, List <T> pocos) { _ctx = ctx; _entityExecutedOn = entityExecutedOn; _insertColumns = insertColumns; _pocos = pocos; _namedParameters = BuildNamedParams(_insertColumns); _with = withStatement; }
public override void Accept(WithStatement withStmt) { symbolTable.NextScope(); withStmt.Expression.Visit(this); methodBuilder.EmitInstruction(withStmt.Location, Opcode.BeginWith); withStmt.Body.Visit(this); methodBuilder.EmitInstruction(withStmt.Location, Opcode.EndWith); symbolTable.LeaveScope(); }
public override bool Walk(WithStatement node) { var ctxMgr = _eval.Evaluate(node.ContextManager); if (node.Variable != null) { _eval.AssignTo(node, node.Variable, ctxMgr); } return(true); }
public override bool Walk(WithStatement node) { CanComplete = true; if (node.Items != null) { var item = node.Items.LastOrDefault(); CanComplete = item != null && item.Variable == null; } return(base.Walk(node)); }
public override object VisitWithStatement(WithStatement withStatement, object data) { // skip any nested with statement var block = withStatement.Body; withStatement.Body = BlockStatement.Null; base.VisitWithStatement(withStatement, data); withStatement.Body = block; return(null); }
public DataType VisitWith(WithStatement w) { foreach (var item in w.items) { DataType val = item.t.Accept(this); if (item.e != null) { scope.BindByScope(analyzer, item.e, val); } } return(w.body.Accept(this)); }
public override bool Walk(WithStatement node) { if (base.Walk(node)) { if (node.IsAsync && !Save(node, true, "async")) { return(false); } return(Save(node.GetIndexOfWith(_ast), true, "with") && node.Items.MaybeEnumerate().All(item => Save(item.AsIndex, true, "as"))); } return(false); }
public virtual void Visit(WithStatement s) { VisitChildren(s); if (s.WithExpression != null) { s.WithExpression.Accept(this); } if (s.WithSymbol != null) { s.WithSymbol.Accept(this); } }
public override bool Walk(WithStatement node) { UpdateChildRanges(node); foreach (var item in node.Items) { var assignTo = item.Variable as NameExpression; if (assignTo != null) { _scope.AddVariable(assignTo.Name, CreateVariableInDeclaredScope(assignTo)); } } return(base.Walk(node)); }
public override bool Walk(WithStatement node) { foreach (var item in node.Items) { var ctxMgr = _eval.Evaluate(item.ContextManager); if (item.Variable != null) { _eval.AssignTo(node, item.Variable, ctxMgr); } } return(true); }
public void Visit(WithStatement node) { if (node != null) { if (node.Body == null || node.Body.Count == 0) { DoesRequire = false; } else { node.Body.Accept(this); } } }
public virtual void Visit(WithStatement node) { if (node != null) { if (node.WithObject != null) { node.WithObject.Accept(this); } if (node.Body != null) { node.Body.Accept(this); } } }
public async Task HandleWithAsync(WithStatement node, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); foreach (var item in node.Items.Where(x => x.Variable != null)) { var contextManager = await Eval.GetValueFromExpressionAsync(item.ContextManager, cancellationToken); var cmType = contextManager.GetPythonType(); var enter = cmType?.GetMember(node.IsAsync ? @"__aenter__" : @"__enter__")?.GetPythonType<IPythonFunctionType>(); if (enter != null) { var context = await Eval.GetValueFromFunctionTypeAsync(enter, null, null, cancellationToken); if (item.Variable is NameExpression nex && !string.IsNullOrEmpty(nex.Name)) { Eval.DeclareVariable(nex.Name, context, Eval.GetLoc(item)); } } } }
public void WithStatementRequiresExpressionAndStatement() { var statement = new WithStatement(); Expect.Throw <InvalidOperationException>(() => statement.ToString()); statement.Expression = JS.Id("a"); Expect.Throw <InvalidOperationException>(() => statement.ToString()); statement.Statement = JS.Block(); Assert.AreEqual("a;", statement.Expression.ToString()); Assert.AreEqual("{}", statement.Statement.ToString()); Assert.AreEqual("with(a){}", statement.ToString()); }
public void WithStatementRequiresExpressionAndStatement() { var statement = new WithStatement(); Expect.Throw<InvalidOperationException>(() => statement.ToString()); statement.Expression = JS.Id("a"); Expect.Throw<InvalidOperationException>(() => statement.ToString()); statement.Statement = JS.Block(); Assert.AreEqual("a;", statement.Expression.ToString()); Assert.AreEqual("{}", statement.Statement.ToString()); Assert.AreEqual("with(a){}", statement.ToString()); }
public InsertStatementBuilder(DbContext ctx, Type intoType, IEnumerable <T> pocos) { _ctx = ctx; _entityExecutedOn = _ctx.Schema.GetByType(intoType); _pocos = pocos; if (_entityExecutedOn.SuperClasses.Any()) { var superEntity = _entityExecutedOn.SuperClasses.Select(superCl => _ctx.Schema.GetByType(superCl)).First(); var sEInsertColumns = superEntity.Columns.Where(c => c.IsDbColumn && !c.IsPkColumn).ToList(); _insertColumns = _entityExecutedOn.Columns.Where(c => c.IsDbColumn).ToList(); _with = new WithStatement(new InsertStatement <T>(_ctx, superEntity, sEInsertColumns, null, _pocos.ToList())); } else { _insertColumns = _entityExecutedOn.Columns.Where(c => c.IsDbColumn && !c.IsPkColumn).ToList(); } }
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; } }
public override object VisitWithStatement(WithStatement withStatement, object data) { withStatement.Body.AcceptVisitor(new ReplaceWithAccessTransformer(withStatement.Expression), data); base.VisitWithStatement(withStatement, data); ReplaceCurrentNode(withStatement.Body); return null; }
public virtual void PostWalk(WithStatement node) { }
public void Visit(WithStatement expression) { throw new System.NotImplementedException(); }
public void VisitWith(WithStatement w) { gen.Using( w.items.Select(wi => Translate(wi)), () => w.body.Accept(this)); }
public void VisitWith(WithStatement w) { this.w.Write("with"); this.w.Write(" "); var sep = ""; foreach (var ws in w.items) { this.w.Write(sep); sep = ", "; ws.t.Write(writer); if (ws.e != null) { this.w.Write(" "); this.w.Write("as"); this.w.Write(" "); ws.e.Write(writer); } } this.w.Write(":"); this.w.WriteLine(); ++this.w.IndentLevel; w.body.Accept(this); --this.w.IndentLevel; }
public virtual object VisitWithStatement(WithStatement withStatement, object data) { Debug.Assert((withStatement != null)); Debug.Assert((withStatement.Expression != null)); Debug.Assert((withStatement.Body != null)); nodeStack.Push(withStatement.Expression); withStatement.Expression.AcceptVisitor(this, data); withStatement.Expression = ((Expression)(nodeStack.Pop())); nodeStack.Push(withStatement.Body); withStatement.Body.AcceptVisitor(this, data); withStatement.Body = ((BlockStatement)(nodeStack.Pop())); return null; }
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; }
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; } }
public void Visit(WithStatement withStatement) { }
void WithStatement( #line 3225 "VBNET.ATG" out Statement withStatement) { #line 3227 "VBNET.ATG" Statement blockStmt = null; Expression expr = null; Expect(218); #line 3230 "VBNET.ATG" Location start = t.Location; Expr( #line 3231 "VBNET.ATG" out expr); EndOfStmt(); #line 3233 "VBNET.ATG" withStatement = new WithStatement(expr); withStatement.StartLocation = start; Block( #line 3236 "VBNET.ATG" out blockStmt); #line 3238 "VBNET.ATG" ((WithStatement)withStatement).Body = (BlockStatement)blockStmt; Expect(100); Expect(218); #line 3241 "VBNET.ATG" withStatement.EndLocation = t.Location; }
// WithStatement public override bool Walk(WithStatement node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
public virtual void VisitWithStatement(WithStatement withStatement) { VisitStatement(withStatement.Body); }
void Analyze(WithStatement Stmt) { SetCurrentLineAndCharNos(Stmt); if (Stmt.Expression != null) { if (Stmt.Expression.GetType().Name.Equals("ValueExpression")) { ValueExpression ValStmt = (ValueExpression)Stmt.Expression; if (ValStmt.Value != null) AddToJintStack(Stmt.Source, JintState.WithStringValue, ValStmt.Value.ToString()); } else { AddToJintStack(Stmt.Source, JintState.WithExpression); } Analyze(Stmt.Expression); } if (Stmt.Statement != null) Analyze(Stmt.Statement); }
public override object VisitWithStatement(WithStatement withStatement, object data) { withStatements.Add(withStatement); return base.VisitWithStatement(withStatement, data); }
private Node TransformWith(WithStatement node) { decompiler.AddToken(Token.WITH); decompiler.AddToken(Token.LP); Node expr = Transform(node.GetExpression()); decompiler.AddToken(Token.RP); decompiler.AddEOL(Token.LC); Node stmt = Transform(node.GetStatement()); decompiler.AddEOL(Token.RC); return CreateWith(expr, stmt, node.GetLineno()); }
public sealed override object VisitWithStatement(WithStatement withStatement, object data) { BeginVisit(withStatement); object result = TrackedVisitWithStatement(withStatement, data); EndVisit(withStatement); return result; }
public virtual object VisitWithStatement(WithStatement withStatement, object data) { Debug.Assert((withStatement != null)); Debug.Assert((withStatement.Expression != null)); Debug.Assert((withStatement.Body != null)); withStatement.Expression.AcceptVisitor(this, data); return withStatement.Body.AcceptVisitor(this, data); }
public override void PostWalk(WithStatement node) { }
public virtual void Visit(WithStatement s) { VisitChildren(s); if (s.WithExpression != null) s.WithExpression.Accept(this); if (s.WithSymbol != null) s.WithSymbol.Accept(this); }
public override object VisitWithStatement(WithStatement withStatement, object data) { // do not visit the body of the WithStatement return withStatement.Expression.AcceptVisitor(this, data); }
// WithStatement public virtual bool Walk(WithStatement node) { return true; }
public virtual object VisitWithStatement(WithStatement withStatement, object data) { throw new global::System.NotImplementedException("WithStatement"); }
// WithStatement public override bool Walk(WithStatement node) { return false; }
public virtual object TrackedVisitWithStatement(WithStatement withStatement, object data) { return base.VisitWithStatement(withStatement, data); }
public void Visit(WithStatement statement) { statement.Expression.Accept(this); if (!(Result is JsDictionaryObject)) { throw new JsException(Global.StringClass.New("Invalid expression in 'with' statement")); } EnterScope((JsDictionaryObject)Result); try { statement.Statement.Accept(this); } finally { ExitScope(); } }
// $ANTLR start "withStatement" // JavaScript.g:164:1: withStatement : 'with' ( LT )* '(' ( LT )* expression ( LT )* ')' ( LT )* statement ; public JavaScriptParser.withStatement_return withStatement() // throws RecognitionException [1] { JavaScriptParser.withStatement_return retval = new JavaScriptParser.withStatement_return(); retval.Start = input.LT(1); object root_0 = null; IToken string_literal165 = null; IToken LT166 = null; IToken char_literal167 = null; IToken LT168 = null; IToken LT170 = null; IToken char_literal171 = null; IToken LT172 = null; JavaScriptParser.expression_return expression169 = default(JavaScriptParser.expression_return); JavaScriptParser.statement_return statement173 = default(JavaScriptParser.statement_return); object string_literal165_tree=null; object LT166_tree=null; object char_literal167_tree=null; object LT168_tree=null; object LT170_tree=null; object char_literal171_tree=null; object LT172_tree=null; try { // JavaScript.g:165:2: ( 'with' ( LT )* '(' ( LT )* expression ( LT )* ')' ( LT )* statement ) // JavaScript.g:165:4: 'with' ( LT )* '(' ( LT )* expression ( LT )* ')' ( LT )* statement { root_0 = (object)adaptor.GetNilNode(); string_literal165=(IToken)Match(input,57,FOLLOW_57_in_withStatement1331); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal165_tree = new WithStatement(string_literal165) ; root_0 = (object)adaptor.BecomeRoot(string_literal165_tree, root_0); } // JavaScript.g:165:29: ( LT )* do { int alt85 = 2; int LA85_0 = input.LA(1); if ( (LA85_0 == LT) ) { alt85 = 1; } switch (alt85) { case 1 : // JavaScript.g:165:29: LT { LT166=(IToken)Match(input,LT,FOLLOW_LT_in_withStatement1337); if (state.failed) return retval; } break; default: goto loop85; } } while (true); loop85: ; // Stops C# compiler whining that label 'loop85' has no statements char_literal167=(IToken)Match(input,42,FOLLOW_42_in_withStatement1341); if (state.failed) return retval; // JavaScript.g:165:39: ( LT )* do { int alt86 = 2; int LA86_0 = input.LA(1); if ( (LA86_0 == LT) ) { alt86 = 1; } switch (alt86) { case 1 : // JavaScript.g:165:39: LT { LT168=(IToken)Match(input,LT,FOLLOW_LT_in_withStatement1344); if (state.failed) return retval; } break; default: goto loop86; } } while (true); loop86: ; // Stops C# compiler whining that label 'loop86' has no statements PushFollow(FOLLOW_expression_in_withStatement1348); expression169 = expression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, expression169.Tree); // JavaScript.g:165:55: ( LT )* do { int alt87 = 2; int LA87_0 = input.LA(1); if ( (LA87_0 == LT) ) { alt87 = 1; } switch (alt87) { case 1 : // JavaScript.g:165:55: LT { LT170=(IToken)Match(input,LT,FOLLOW_LT_in_withStatement1350); if (state.failed) return retval; } break; default: goto loop87; } } while (true); loop87: ; // Stops C# compiler whining that label 'loop87' has no statements char_literal171=(IToken)Match(input,44,FOLLOW_44_in_withStatement1354); if (state.failed) return retval; // JavaScript.g:165:65: ( LT )* do { int alt88 = 2; int LA88_0 = input.LA(1); if ( (LA88_0 == LT) ) { alt88 = 1; } switch (alt88) { case 1 : // JavaScript.g:165:65: LT { LT172=(IToken)Match(input,LT,FOLLOW_LT_in_withStatement1357); if (state.failed) return retval; } break; default: goto loop88; } } while (true); loop88: ; // Stops C# compiler whining that label 'loop88' has no statements PushFollow(FOLLOW_statement_in_withStatement1361); statement173 = statement(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, statement173.Tree); } retval.Stop = input.LT(-1); if ( (state.backtracking==0) ) { retval.Tree = (object)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);} } catch (RecognitionException re) { ReportError(re); Recover(input,re); // Conversion of the second argument necessary, but harmless retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re); } finally { } return retval; }