private UstStmts.LabelStatement VisitLabeledStatement(LabeledStatement labeledStatement) { var identifier = VisitIdentifier(labeledStatement.Label); var body = VisitStatement(labeledStatement.Body); return(new UstStmts.LabelStatement(identifier, body, GetTextSpan(labeledStatement))); }
private bool RemoveEndFinallyFrom(DecompiledBlock block, LabeledStatement labelToGoto) { Contract.Requires(block != null); Contract.Requires(labelToGoto != null); for (int i = 0; i < block.Statements.Count; i++) { if (block.Statements[i] is EndFinally) { var gotoFinally = new GotoStatement() { TargetStatement = labelToGoto }; block.Statements[i] = gotoFinally; var gotos = new List <IGotoStatement>(1); gotos.Add(gotoFinally); this.gotosThatTarget[(uint)labelToGoto.Label.UniqueKey] = gotos; return(true); } var nestedBlock = block.Statements[i] as DecompiledBlock; if (nestedBlock != null && this.RemoveEndFinallyFrom(nestedBlock, labelToGoto)) { return(true); } } return(false); }
private List <IStatement> CreateUnifiedReturnPoint(List <IStatement> statements, ITypeReference returnType) { var returnLabel = new LabeledStatement() { Statement = new EmptyStatement() }; var localForReturnValue = new LocalDefinition() { Name = this.nameTable.GetNameFor("_returnValue"), Type = returnType, }; var rr = new ReplaceReturns(this.host, localForReturnValue, returnLabel); statements = rr.Rewrite(statements); statements.Add(returnLabel); var returnStatement = new ReturnStatement(); if (returnType.TypeCode != PrimitiveTypeCode.Void) { returnStatement.Expression = new BoundExpression() { Definition = localForReturnValue } } ; statements.Add(returnStatement); return(statements); }
public FlowBranchingLabeled StartFlowBranching(LabeledStatement stmt) { FlowBranchingLabeled branching = new FlowBranchingLabeled(CurrentBranching, stmt); current_flow_branching = branching; return(branching); }
public override void Visit(LabeledStatement s) { if (s.IdentifierHash != 0) { gen.AddTextItem(s.Identifier, "Jump label"); } }
// [36] LabeledStatement = 'case' ConstantExpression ':' Statement | 'default' ':' Statement. private bool IsLabeledStatement(out LabeledStatement labeledStatement) { labeledStatement = new LabeledStatement(); if (CheckToken(SyntaxKind.CaseKeyword)) { if (!IsConstantExpression(out var constantExpression)) { return(false); } if (!CheckToken(SyntaxKind.ColonToken)) { return(false); } if (!IsStatement(out var statement)) { return(false); } return(true); } else if (CheckToken(SyntaxKind.DefaultKeyword)) { if (!CheckToken(SyntaxKind.ColonToken)) { return(false); } if (!IsStatement(out var statement)) { return(false); } return(true); } return(false); }
protected override void VisitLabeledStatement(LabeledStatement labeledStatement) { using (StartNodeObject(labeledStatement)) { Member("label", labeledStatement.Label); Member("body", labeledStatement.Body); } }
public override void VisitLabeledStatement(LabeledStatement node) { Outdent(); Write(node.Label); WriteToken(":"); WriteLine(); Indent(); }
public override void eSet(int featureID, object newValue) { switch (featureID) { case Java_PackageImpl.BREAKSTATEMENT_LABEL: label = (LabeledStatement)newValue; return; } base.eSet(featureID, newValue); }
public virtual void Visit(LabeledStatement node) { if (node != null) { if (node.Statement != null) { node.Statement.Accept(this); } } }
/// <summary> /// Makes other goto constructions unique, because they may overlap the existing goto in the method, /// where we are inlining /// </summary> /// <param name="node"> /// A <see cref="LabeledStatement"/> /// </param> /// <returns> /// A <see cref="ICodeNode"/> /// </returns> public override ICodeNode VisitLabeledStatement(LabeledStatement node) { node.Label = "@_" + source.Method.Name + "@" + exitNumber + node.Label; // if (lastGoTo.Label == node.Label) { // currentBlock.Statements.Remove(lastGoTo); // return null; // } return(base.VisitLabeledStatement(node)); }
public override Statement VisitLabeledStatement(LabeledStatement lStatement){ if (lStatement == null) return null; this.labelList.Add(lStatement.Label); lStatement.Scope = this.scope as BlockScope; if (this.localLabels == null) this.localLabels = new TrivialHashtable(); if (this.localLabels[lStatement.Label.UniqueIdKey] == null){ this.localLabels[lStatement.Label.UniqueIdKey] = lStatement; this.targetFor[lStatement.Label.UniqueIdKey] = lStatement; }else this.HandleError(lStatement.Label, Error.LabelIdentiferAlreadyInUse, lStatement.Label.ToString()); lStatement.Statement = (Statement)this.Visit(lStatement.Statement); return lStatement; }
public void Visit(LabeledStatement node) { if (node != null) { // requires a separator if the statement does if (node.Statement != null) { node.Statement.Accept(this); } else { DoesRequire = false; } } }
protected LabeledStatement /*?*/ FindLabeledStatement(List <IStatement> statements, int i, IName name) { while (i < statements.Count) { BasicBlock /*?*/ bb = statements[i] as BasicBlock; if (bb != null) { return(this.FindLabeledStatement(bb.Statements, 0, name)); } LabeledStatement /*?*/ result = statements[i] as LabeledStatement; if (result != null && result.Label == name) { return(result); } i++; } return(null); }
void Add(Statement statement) { if (statement == null) { throw new ArgumentNullException("statement"); } var block_statements = GetOrCreateStatementListAt(current_block.Index); if (current_label != null) { var label = new LabeledStatement(current_label); current_label = null; block_statements.Add(label); } block_statements.Add(statement); }
public override IStatement VisitGotoStatement(GotoStatementSyntax node) { var e = node.Expression as IdentifierNameSyntax; ILabeledStatement l; if (!this.labelTable.TryGetValue(e.Identifier.Value, out l)) { l = new LabeledStatement() { Label = this.host.NameTable.GetNameFor(e.GetText().ToString()), Locations = Helper.SourceLocation(this.tree, node), }; this.labelTable.Add(e.Identifier.Value, l); } return(new GotoStatement() { TargetStatement = l, }); }
public NotificationChain basicSetLabel(LabeledStatement newobj, NotificationChain msgs) { var oldobj = _label; _label = newobj; if (eNotificationRequired()) { var notification = new ENotificationImpl(this, NotificationImpl.SET, Java_PackageImpl.BREAKSTATEMENT_LABEL, oldobj, newobj); if (msgs == null) { msgs = notification; } else { msgs.add(notification); } } return(msgs); }
public void ExecuteLabeledStatement(RuntimeState state) { LabeledStatement labeledStatement = (LabeledStatement)state.arg; // TODO: Esprima added Statement.Label, maybe not necessary as this line is finding the // containing label and could keep a table per program with all the labels // labeledStatement.Body.LabelSet = labeledStatement.Label; if (state.calleeReturned) { Completion result = (Completion)state.calleeReturnValue; if (result.Type == CompletionType.Break && result.Identifier == labeledStatement.Label.Name) { var value = result.Value; Return(new Completion(CompletionType.Normal, value, null)); return; } Return(result); return; } Call(_engine.ExecuteStatement, labeledStatement.Body); }
FixUp(AstMethodDefinition source, Dictionary <ParameterDefinition, Expression> paramVarSubstitution, Expression thisSubstitution) { this.source = source; this.paramVarSubstitution = paramVarSubstitution; this.thisSubstitution = thisSubstitution; exitNumber++; this.exitLabel = this.source.CecilBlock.Statements[this.source.Block.Statements.Count - 1] as LabeledStatement; if (exitLabel == null) { this.exitLabel = new LabeledStatement("@_exit" + exitNumber); this.source.CecilBlock.Statements.Add(exitLabel); this.source.CecilBlock = (BlockStatement)Visit(this.source.CecilBlock); } else { this.source.CecilBlock = (BlockStatement)Visit(this.source.CecilBlock); } return(this.source); }
private bool RemoveEndFinallyFrom(DecompiledBlock block) { Contract.Requires(block != null); Contract.Assume(block.Statements.Count > 0); //There must be an endfinally if (block.Statements[block.Statements.Count - 1] is EndFinally) { block.Statements.RemoveAt(block.Statements.Count - 1); return(true); } var lastBlock = block.Statements[block.Statements.Count - 1] as DecompiledBlock; if (lastBlock != null && this.RemoveEndFinallyFrom(lastBlock)) { return(true); } LabeledStatement endFinally = new LabeledStatement() { Label = this.host.NameTable.GetNameFor("__endfinally#" + this.endFinallyCounter++), Statement = new EmptyStatement() }; block.Statements.Add(endFinally); return(this.RemoveEndFinallyFrom(block, endFinally)); }
public override IStatement VisitLabeledStatement(LabeledStatementSyntax node) { ILabeledStatement l; var id = node.Identifier; if (!this.labelTable.TryGetValue(id.Value, out l)) { l = new LabeledStatement() { Label = this.host.NameTable.GetNameFor(id.ValueText), Locations = Helper.SourceLocation(this.tree, node), }; this.labelTable.Add(id.Value, l); } var s_prime = this.Visit(node.Statement); return(new BlockStatement() { Statements = new List <IStatement>() { l, s_prime, }, }); }
internal void ReplaceInitialLabel(LabeledStatement labeledStatement) { Contract.Requires(labeledStatement != null); for (int i = 0, n = this.Statements.Count; i < n; i++) { var s = this.Statements[i]; var ls = s as LabeledStatement; if (ls != null) { this.Statements[i] = labeledStatement; return; } var b = s as DecompiledBlock; if (b != null) { b.ReplaceInitialLabel(labeledStatement); } var d = s as LocalDeclarationStatement; if (d != null && d.InitialValue == null) { continue; } break; } }
public override Statement VisitLabeledStatement(LabeledStatement lStatement) { if (lStatement == null) { return(null); } this.labelList.Add(lStatement.Label); lStatement.Scope = this.scope as BlockScope; if (this.localLabels == null) { this.localLabels = new TrivialHashtable(); } if (this.localLabels[lStatement.Label.UniqueIdKey] == null) { this.localLabels[lStatement.Label.UniqueIdKey] = lStatement; this.targetFor[lStatement.Label.UniqueIdKey] = lStatement; } else { this.HandleError(lStatement.Label, Error.LabelIdentiferAlreadyInUse, lStatement.Label.ToString()); } lStatement.Statement = (Statement)this.Visit(lStatement.Statement); return(lStatement); }
public void Visit(LabeledStatement node) { ReportError(node); }
private LabeledStatement ParseLabeledStatement(SimpleName label, TokenSet followers) //^ requires this.currentToken == Token.Colon; //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { SourceLocationBuilder slb = new SourceLocationBuilder(label.SourceLocation); this.GetNextToken(); Statement statement; if (Parser.StatementStart[this.currentToken]) { statement = this.ParseStatement(followers); } else { statement = new EmptyStatement(false, this.scanner.SourceLocationOfLastScannedToken); this.SkipTo(followers, Error.ExpectedSemicolon); } //^ assert followers[this.currentToken] || this.currentToken == Token.EndOfFile; slb.UpdateToSpan(statement.SourceLocation); LabeledStatement result = new LabeledStatement(new NameDeclaration(label.Name, label.SourceLocation), statement, slb); //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile; return result; }
public virtual Differences VisitLabeledStatement(LabeledStatement lStatement1, LabeledStatement lStatement2){ Differences differences = new Differences(lStatement1, lStatement2); if (lStatement1 == null || lStatement2 == null){ if (lStatement1 != lStatement2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++; return differences; } LabeledStatement changes = (LabeledStatement)lStatement2.Clone(); LabeledStatement deletions = (LabeledStatement)lStatement2.Clone(); LabeledStatement insertions = (LabeledStatement)lStatement2.Clone(); Differences diff = this.VisitIdentifier(lStatement1.Label, lStatement2.Label); if (diff == null){Debug.Assert(false); return differences;} changes.Label = diff.Changes as Identifier; deletions.Label = diff.Deletions as Identifier; insertions.Label = diff.Insertions as Identifier; Debug.Assert(diff.Changes == changes.Label && diff.Deletions == deletions.Label && diff.Insertions == insertions.Label); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; diff = this.VisitStatement(lStatement1.Statement, lStatement2.Statement); if (diff == null){Debug.Assert(false); return differences;} changes.Statement = diff.Changes as Statement; deletions.Statement = diff.Deletions as Statement; insertions.Statement = diff.Insertions as Statement; Debug.Assert(diff.Changes == changes.Statement && diff.Deletions == deletions.Statement && diff.Insertions == insertions.Statement); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; if (differences.NumberOfDifferences == 0){ differences.Changes = null; differences.Deletions = null; differences.Insertions = null; }else{ differences.Changes = changes; differences.Deletions = deletions; differences.Insertions = insertions; } return differences; }
/** * Call back method that must be called when the given <code> * LabeledStatement</code> will become the next <i>traverse candidate</i>. * * @param pLabeledStatement The <code>LabeledStatement</code> object that * will become the next <i>traverse candidate</i>. */ public void performAction( LabeledStatement pLabeledStatement) { // Nothing to do. }
public virtual void PostWalk(LabeledStatement node) { }
public override Statement VisitLabeledStatement(LabeledStatement lStatement) { if (lStatement == null) return null; if (this.referencedLabels != null && this.referencedLabels[lStatement.UniqueKey] == null) this.HandleError(lStatement.Label, Error.UnreferencedLabel); lStatement.Statement = (Statement)this.Visit(lStatement.Statement); return lStatement; }
public FlowBranchingLabeled (FlowBranching parent, LabeledStatement stmt) : base (parent, BranchingType.Labeled, SiblingType.Conditional, null, stmt.loc) { this.stmt = stmt; CurrentUsageVector.MergeOrigins (stmt.JumpOrigins); actual = CurrentUsageVector.Clone (); // stand-in for backward jumps CurrentUsageVector.ResetBarrier (); }
public virtual void Visit(LabeledStatement node) { if (node != null) { AcceptChildren(node); } }
protected internal virtual void PostWalk(LabeledStatement node) { }
public virtual object Visit(LabeledStatement labeledStatement) { return(null); }
public override Statement VisitLabeledStatement(LabeledStatement lStatement) { this.scopeFor[lStatement.UniqueKey] = this.scope; return base.VisitLabeledStatement(lStatement); }
public override Statement VisitLabeledStatement(LabeledStatement lStatement) { if (lStatement == null) return null; return base.VisitLabeledStatement((LabeledStatement)lStatement.Clone()); }
public virtual Statement VisitLabeledStatement(LabeledStatement lStatement1, LabeledStatement lStatement2) { if (lStatement1 == null) return null; if (lStatement2 == null) lStatement1.Statement = (Statement)this.Visit(lStatement1.Statement, null); else lStatement1.Statement = (Statement)this.Visit(lStatement1.Statement, lStatement2.Statement); return lStatement1; }
public void Visit(LabeledStatement labeledStatement) { }
public void Visit(LabeledStatement node) { // starts with a label identifier, so we don't care }
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 Statement VisitLabeledStatement(LabeledStatement lStatement) { throw new ApplicationException("unimplemented"); }
public virtual void VisitLabeledStatement(LabeledStatement lStatement) { if (lStatement == null) return; this.Visit(lStatement.Statement); }
private void Process_Labeled_Statement(StringBuilder sb, LabeledStatement statement) { sb.Append(FormatExpression(statement.Label)).Append(": "); sb.Append(ProcessStatement(statement.Statement)); }
void case_860() #line 5781 "cs-parser.jay" { var lt = (LocatedToken) yyVals[-1+yyTop]; LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location); lbag.AddLocation (labeled, GetLocation (yyVals[0+yyTop])); current_block.AddLabel (labeled); current_block.AddStatement (labeled); }
public void Visit(LabeledStatement node) { Debug.Fail("shouldn't get here"); }
public virtual Statement VisitLabeledStatement(LabeledStatement lStatement){ if (lStatement == null) return null; lStatement.Statement = (Statement)this.Visit(lStatement.Statement); return lStatement; }
public virtual void Visit(LabeledStatement s) { VisitAbstractStmt(s); }
/** * Call back method that must be called as soon as the given <code> * LabeledStatement</code> object has been traversed. * * @param pLabeledStatement The <code>LabeledStatement</code> object that * has just been traversed. */ public void actionPerformed( LabeledStatement pLabeledStatement) { // Nothing to do. }
public override Statement VisitLabeledStatement(LabeledStatement lStatement){ if (lStatement == null) return null; if (lStatement.Statements == null) lStatement.Statements = new StatementList(1); if (lStatement.Statement is Try && lStatement.Label != null) lStatement.Statements.Add(new Statement(NodeType.Nop, lStatement.Label.SourceContext)); lStatement.Statements.Add((Statement)this.Visit(lStatement.Statement)); lStatement.NodeType = NodeType.Block; return lStatement; }
private Statement Translate(CodeLabeledStatement statement){ if (statement == null) return null; LabeledStatement ls = new LabeledStatement(); ls.Label = Identifier.For(statement.Label); ls.Statement = this.Translate(statement.Statement); return ls; }
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 static void report(Node node, int shift) { if (node == null) { indent(shift); Console.WriteLine("NULL ENTITY"); return; } switch (node.NodeType) { case NodeType.AliasDefinition: { AliasDefinition alias = node as AliasDefinition; indent(shift); Console.WriteLine("using {0} = {1};", alias.Alias.Name, alias.AliasedUri.Name); break; } case NodeType.CompilationUnit: case NodeType.CompilationUnitSnippet: { CompilationUnit cu = node as CompilationUnit; for (int i = 0, n = cu.Nodes.Length; i < n; i++) { report(cu.Nodes[i], 0); } break; } case NodeType.Namespace: { Namespace ns = node as Namespace; if (ns.UsedNamespaces != null && ns.UsedNamespaces.Length != 0) { indent(shift); Console.WriteLine("using "); for (int i = 0, n = ns.UsedNamespaces.Length; i < n; i++) { Console.Write("{0}", ns.UsedNamespaces[i].Namespace.Name); if (i < n - 1) { Console.Write(", "); } } Console.WriteLine(); } indent(shift); Console.WriteLine("namespace {0}", ns.FullNameId.Name); indent(shift); Console.WriteLine("{"); if (ns.AliasDefinitions != null && ns.AliasDefinitions.Length != 0) { for (int i = 0, n = ns.AliasDefinitions.Length; i < n; i++) { report(ns.AliasDefinitions[i], shift + ind); } } if (ns.NestedNamespaces != null && ns.NestedNamespaces.Length != 0) { for (int i = 0, n = ns.NestedNamespaces.Length; i < n; i++) { report(ns.NestedNamespaces[i], shift + ind); } } if (ns.Types != null && ns.Types.Length != 0) { for (int i = 0, n = ns.Types.Length; i < n; i++) { report(ns.Types[i], shift + ind); } } indent(shift); Console.WriteLine("}"); break; } case NodeType.Class: { Class cls = node as Class; if (cls == SystemTypes.Object) { Console.Write(cls.Name); break; } indent(shift); if (cls.IsAbstract) { Console.Write("abstract "); } if (cls.IsPrivate) { Console.Write("private "); } else if (cls.IsPublic) { Console.Write("public "); } else { Console.Write("internal "); // ?????????????? } if (cls.IsSealed) { Console.Write("sealed "); } Console.Write("class "); if (cls.DeclaringType != null) { Console.Write("{0}::", cls.DeclaringType.Name.Name); } Console.Write("{0}", cls.Name != null?cls.Name.Name:"<NONAME>"); if (cls.BaseClass != null) { Console.Write(" : {0}", cls.BaseClass.Name.Name); } if (cls.Interfaces != null && cls.Interfaces.Length != 0) { if (cls.BaseClass != null) { Console.Write(","); } else { Console.Write(" :"); } for (int i = 0, n = cls.Interfaces.Length; i < n; i++) { Interface interfac = cls.Interfaces[i]; if (interfac != null) { Console.Write(" {0}", interfac.Name.Name); } if (i < n - 1) { Console.Write(","); } } } Console.WriteLine(); indent(shift); Console.WriteLine("{"); if (cls.Members != null && cls.Members.Length != 0) { for (int i = 0, n = cls.Members.Length; i < n; i++) { Member member = cls.Members[i]; if (member == null) { indent(shift + ind); Console.WriteLine("<UNRESOLVED MEMBER>"); continue; } report(member, shift + ind); } } indent(shift); Console.WriteLine("}"); break; } case NodeType.Struct: { Struct struc = node as Struct; indent(shift); if (struc.IsAbstract) { Console.Write("abstract "); } if (struc.IsPrivate) { Console.Write("private "); } else if (struc.IsPublic) { Console.Write("public "); } else { Console.Write("internal "); // ?????????????? } if (struc.IsSealed) { Console.Write("sealed "); } Console.Write("struct "); if (struc.DeclaringType != null) { Console.Write("{0}::", struc.DeclaringType.Name.Name); } Console.Write("{0}", struc.Name != null?struc.Name.Name:"<NONAME>"); if (struc.Interfaces != null && struc.Interfaces.Length != 0) { Console.Write(" :"); for (int i = 0, n = struc.Interfaces.Length; i < n; i++) { Interface interfac = struc.Interfaces[i]; if (interfac != null) { Console.Write(" {0}", interfac.Name.Name); } if (i < n - 1) { Console.Write(","); } } } Console.WriteLine(); indent(shift); Console.WriteLine("{"); if (struc.Members != null && struc.Members.Length != 0) { for (int i = 0, n = struc.Members.Length; i < n; i++) { Member member = struc.Members[i]; if (member == null) { indent(shift + ind); Console.WriteLine("<UNRESOLVED MEMBER>"); continue; } report(member, shift + ind); } } indent(shift); Console.WriteLine("}"); break; } case NodeType.EnumNode: { EnumNode enume = node as EnumNode; indent(shift); if (enume.Name != null && enume.Name.Name != null) { Console.Write("enum {0} = ", enume.Name.Name); } else { Console.Write("enum <NONAME> = "); } Console.Write("{"); for (int i = 0, n = enume.Members.Length; i < n; i++) { Field enumerator = (Field)enume.Members[i]; Console.Write("{0}", enumerator.Name.Name); if (enumerator.DefaultValue != null) { Console.Write(" = {0}", enumerator.DefaultValue.ToString()); } if (i < n - 1) { Console.Write(", "); } } Console.WriteLine("};"); break; } case NodeType.Interface: { Interface interfac = node as Interface; indent(shift); if (interfac.IsAbstract) { Console.Write("abstract "); } if (interfac.IsPrivate) { Console.Write("private "); } else if (interfac.IsPublic) { Console.Write("public "); } else { Console.Write("internal "); // ??????????? } Console.WriteLine("interface {0}", interfac.Name.Name); indent(shift); Console.WriteLine("{"); if (interfac.Members != null && interfac.Members.Length != 0) { for (int i = 0, n = interfac.Members.Length; i < n; i++) { Member member = interfac.Members[i]; if (member == null) { indent(shift + ind); Console.WriteLine("<UNRESOLVED MEMBER>"); continue; } report(member, shift + ind); } } indent(shift); Console.WriteLine("}"); break; } case NodeType.Method: case NodeType.InstanceInitializer: { Method method = node as Method; indent(shift); if (method.IsAbstract) { Console.Write("abstract "); } if (method.IsPublic) { Console.Write("public "); } if (method.IsStatic) { Console.Write("static "); } if (method.IsVirtual) { Console.Write("virtual "); } if (method.IsPrivate) { Console.Write("private "); } if (method.OverriddenMethod != null) { Console.Write("override "); } if (method.ReturnType != null && method.ReturnType.Name != null) { Console.Write("{0} ", method.ReturnType.Name.Name); } if (method.Name != null) { if (method.ImplementedInterfaceMethods != null && method.ImplementedInterfaceMethods.Length != 0) { Method interf = method.ImplementedInterfaceMethods[0]; if (interf != null) { string name = interf.DeclaringType.Name.Name; Console.Write("{0}.", name); } } Console.Write("{0}", method.Name.Name); } Console.Write(" ("); if (method.Parameters != null && method.Parameters.Length != 0) { for (int i = 0, n = method.Parameters.Length; i < n; i++) { Parameter par = method.Parameters[i]; if (par == null) { continue; } if ((par.Flags & ParameterFlags.In) != 0) { Console.Write("in "); } if ((par.Flags & ParameterFlags.Out) != 0) { Console.Write("out "); } if (par.Type != null && par.Type.Name != null) { Console.Write("{0}", par.Type.Name.Name); } else { report(par.Type, 0); } Console.Write(" {0}", par.Name.Name); if (i < n - 1) { Console.Write(", "); } } } Console.Write(" )"); // method body if (method.Body != null) { Console.WriteLine(); report(method.Body, shift); } else { Console.WriteLine(";"); } break; } case NodeType.DelegateNode: { DelegateNode dn = node as DelegateNode; indent(shift); Console.Write("delegate "); if (dn.ReturnType != null && dn.ReturnType.Name != null) { Console.Write("{0} ", dn.ReturnType.Name.Name); } if (dn.Name != null) { Console.Write("{0}", dn.Name.Name); } Console.Write(" ("); if (dn.Parameters != null && dn.Parameters.Length != 0) { for (int i = 0, n = dn.Parameters.Length; i < n; i++) { Parameter par = dn.Parameters[i]; if (par == null) { continue; } if ((par.Flags & ParameterFlags.In) != 0) { Console.Write("in "); } if ((par.Flags & ParameterFlags.Out) != 0) { Console.Write("out "); } if (par.Type != null && par.Type.Name != null) { Console.Write("{0}", par.Type.Name.Name); } else { report(par.Type, 0); } Console.Write(" {0}", par.Name.Name); if (i < n - 1) { Console.Write(", "); } } } Console.WriteLine(" );"); break; } case NodeType.StaticInitializer: { StaticInitializer si = node as StaticInitializer; indent(shift); Console.WriteLine("static {0} ( )", si.Name.Name); // body if (si.Body != null) { report(si.Body, shift); } else { Console.WriteLine("NO BODY"); } break; } case NodeType.FieldInitializerBlock: { FieldInitializerBlock initializers = node as FieldInitializerBlock; indent(shift); if (initializers.IsStatic) { Console.Write("static "); } Console.WriteLine("init {"); for (int i = 0, n = initializers.Statements.Length; i < n; i++) { report(initializers.Statements[i], shift + ind); } indent(shift); Console.WriteLine("}"); break; } case NodeType.Base: { Console.Write("base"); break; } case NodeType.Field: { Field field = node as Field; indent(shift); if (field.IsPrivate) { Console.Write("private "); } else if (field.IsPublic) { Console.Write("public "); } if (field.IsStatic) { Console.Write("static "); } if (field.IsInitOnly) { Console.Write("readonly "); } if (field.Type != null) { if (field.Type.Name != null) { Console.Write("{0}", field.Type.Name.Name); } else { report(field.Type, 0); } } Console.Write(" {0}", field.Name.Name); if (field.Initializer != null) { Console.Write(" = "); report(field.Initializer, 0); } Console.WriteLine(";"); break; } case NodeType.VariableDeclaration: { VariableDeclaration variable = node as VariableDeclaration; indent(shift); if (variable.Type != null && variable.Type.Name != null) { Console.Write("{0}", variable.Type.Name.Name); } else { report(variable.Type, 0); } Console.Write(" {0}", variable.Name.Name); if (variable.Initializer != null) { Console.Write(" = "); report(variable.Initializer, 0); } Console.WriteLine(";"); break; } case NodeType.LocalDeclarationsStatement: { LocalDeclarationsStatement stmt = node as LocalDeclarationsStatement; indent(shift); TypeNode type = stmt.Type; if (type != null && type.Name != null) { Console.Write("{0}", type.Name.Name); } else { report(type, 0); } Console.Write(" "); LocalDeclarationList list = stmt.Declarations; for (int i = 0, n = list.Length; i < n; i++) { LocalDeclaration local = list[i]; Console.Write("{0}", local.Name.Name); if (local.InitialValue != null) { Console.Write(" = "); report(local.InitialValue, 0); } if (i < n - 1) { Console.Write(", "); } } Console.WriteLine(";"); break; } case NodeType.Property: { Property property = node as Property; indent(shift); if (property.IsPrivate) { Console.Write("private "); } else if (property.IsPublic) { Console.Write("public "); } if (property.IsStatic) { Console.Write("static "); } if (property != null) { if (property.Type != null && property.Type.Name != null) { Console.Write("{0} ", property.Type.Name.Name); } if (property.ImplementedTypes != null) { TypeNode typ = property.ImplementedTypes[0]; Console.Write("{0}.", typ.Name.Name); } if (property.Name != null) { Console.WriteLine("{0}", property.Name.Name); } } indent(shift); Console.WriteLine("{"); if (property.Getter != null) { report(property.Getter, shift + ind); } if (property.Setter != null) { report(property.Setter, shift + ind); } indent(shift); Console.WriteLine("}"); break; } case NodeType.Lock: { Lock _lock = node as Lock; indent(shift); Console.Write("lock("); report(_lock.Guard, shift); Console.WriteLine(")"); report(_lock.Body, shift + ind); indent(shift); Console.WriteLine("}"); break; } case NodeType.Block: { Block block = node as Block; if (block == null || block.Statements == null) { break; } indent(shift); Console.WriteLine("{"); for (int i = 0, n = block.Statements.Length; i < n; i++) { report(block.Statements[i], shift + ind); Console.WriteLine(); } indent(shift); Console.WriteLine("}"); break; } case NodeType.MemberBinding: { MemberBinding mb = node as MemberBinding; if (mb.TargetObject != null) { report(mb.TargetObject, 0); } else if (mb.BoundMember != null && mb.BoundMember.DeclaringType != null) { Console.Write(mb.BoundMember.DeclaringType.Name); } Console.Write("."); if (mb.BoundMember.Name != null) { Console.Write(mb.BoundMember.Name.Name); } else { report(mb.BoundMember, 0); } break; } case NodeType.AssignmentStatement: { AssignmentStatement assignment = node as AssignmentStatement; indent(shift); report(assignment.Target, 0); switch (assignment.Operator) { case NodeType.Nop: Console.Write(" = "); break; case NodeType.Add: Console.Write(" += "); break; case NodeType.Add_Ovf: Console.Write(" += "); break; case NodeType.Add_Ovf_Un: Console.Write(" += "); break; case NodeType.Sub: Console.Write(" -= "); break; case NodeType.Sub_Ovf: Console.Write(" -= "); break; case NodeType.Sub_Ovf_Un: Console.Write(" -= "); break; case NodeType.Mul: Console.Write(" *= "); break; case NodeType.Mul_Ovf: Console.Write(" *= "); break; case NodeType.Mul_Ovf_Un: Console.Write(" *= "); break; } report(assignment.Source, 0); Console.Write(";"); break; } case NodeType.ExpressionStatement: { ExpressionStatement exprStatement = node as ExpressionStatement; indent(shift); report(exprStatement.Expression, 0); Console.Write(";"); break; } case NodeType.Return: { Return return_stmt = node as Return; indent(shift); Console.Write("return"); if (return_stmt.Expression != null) { Console.Write(" "); report(return_stmt.Expression, 0); } Console.Write(";"); break; } case NodeType.Branch: { Branch branch = node as Branch; indent(shift); Console.WriteLine("break; (???)"); break; } case NodeType.For: { For for_stmt = node as For; indent(shift); Console.Write("for ( "); for (int i = 0, n = for_stmt.Initializer.Length; i < n; i++) { report(for_stmt.Initializer[i], 0); } report(for_stmt.Condition, 0); Console.Write("; "); for (int i = 0, n = for_stmt.Incrementer.Length; i < n; i++) { report(for_stmt.Incrementer[i], 0); } Console.WriteLine(")"); indent(shift); Console.WriteLine("{"); report(for_stmt.Body, shift + ind); indent(shift); Console.WriteLine("}"); break; } case NodeType.While: { While while_loop = node as While; indent(shift); Console.Write("while ( "); report(while_loop.Condition, 0); Console.WriteLine(" )"); report(while_loop.Body, shift); break; } case NodeType.DoWhile: { DoWhile repeat = node as DoWhile; indent(shift); Console.WriteLine("do"); report(repeat.Body, shift); indent(shift); Console.Write("while ("); report(repeat.Condition, 0); Console.WriteLine(" );"); break; } case NodeType.If: { If if_stmt = node as If; indent(shift); Console.Write("if ( "); report(if_stmt.Condition, 0); Console.WriteLine(" )"); report(if_stmt.TrueBlock, shift); if (if_stmt.FalseBlock == null || if_stmt.FalseBlock.Statements == null || if_stmt.FalseBlock.Statements.Length == 0) { break; } indent(shift); Console.WriteLine("else"); report(if_stmt.FalseBlock, shift); break; } case NodeType.Switch: { Switch swtch = node as Switch; indent(shift); Console.Write("switch ( "); report(swtch.Expression, 0); Console.WriteLine(" )"); indent(shift); Console.WriteLine("{"); for (int i = 0, n = swtch.Cases.Length; i < n; i++) { indent(shift + ind); if (swtch.Cases[i].Label != null) { Console.Write("case "); report(swtch.Cases[i].Label, 0); Console.WriteLine(":"); } else { Console.WriteLine("default:"); } report(swtch.Cases[i].Body, shift + ind); } indent(shift); Console.WriteLine("}"); break; } case NodeType.Throw: { Throw thro = node as Throw; indent(shift); Console.Write("throw ("); report(thro.Expression, 0); Console.Write(");"); break; } case NodeType.Exit: { indent(shift); Console.WriteLine("exit;"); break; } case NodeType.Continue: { indent(shift); Console.WriteLine("continue;"); break; } case NodeType.Try: { Try trys = node as Try; indent(shift); Console.WriteLine("try {"); report(trys.TryBlock, shift + ind); indent(shift); Console.WriteLine("}"); if (trys.Catchers != null) { for (int i = 0, n = trys.Catchers.Length; i < n; i++) { indent(shift); if (trys.Catchers[i].Type != null) { Console.Write("catch ( {0} ", trys.Catchers[i].Type.FullName); } else { Console.Write("catch ( "); } if (trys.Catchers[i].Variable != null) { report(trys.Catchers[i].Variable, 0); } Console.WriteLine(" ) {"); report(trys.Catchers[i].Block, shift + ind); indent(shift); Console.WriteLine("}"); } } if (trys.Finally != null && trys.Finally.Block != null) { indent(shift); Console.WriteLine("finally"); report(trys.Finally.Block, shift); } break; } case NodeType.BlockExpression: { BlockExpression be = node as BlockExpression; Console.WriteLine("("); StatementList sl = be.Block.Statements; for (int i = 0, n = sl.Length; i < n; i++) { report(sl[i], shift + ind); } indent(shift); Console.Write(")"); break; } case NodeType.ArrayTypeExpression: { ArrayTypeExpression array = node as ArrayTypeExpression; indent(shift); if (array.ElementType != null && array.ElementType.Name != null && array.ElementType.Name.Name != null) { Console.Write(array.ElementType.Name.Name); } else { report(array.ElementType, 0); } Console.Write("["); for (int i = 0, n = array.Rank; i < n; i++) { if (array.Sizes != null) { Console.Write(array.Sizes[i]); } if (i < n - 1) { Console.Write(","); } } Console.Write("]"); break; } case NodeType.Construct: { Construct construct = node as Construct; indent(shift); Console.Write("new "); report(construct.Constructor, 0); Console.Write("("); if (construct.Operands != null) { for (int i = 0, n = construct.Operands.Length; i < n; i++) { report(construct.Operands[i], 0); if (i < n - 1) { Console.Write(","); } } } Console.Write(")"); break; } case NodeType.ConstructArray: { ConstructArray initializer = node as ConstructArray; Console.Write("new "); if (initializer.ElementType != null && initializer.ElementType.Name != null && initializer.ElementType.Name.Name != null) { Console.Write(initializer.ElementType.Name.Name); } else { report(initializer.ElementType, 0); } Console.Write("["); for (int i = 0, n = initializer.Operands.Length; i < n; i++) { report(initializer.Operands[i], 0); if (i < n - 1) { Console.Write(","); } } Console.Write("]"); break; } case NodeType.ConstructDelegate: { ConstructDelegate cd = node as ConstructDelegate; // Console.Write("new {0}({1})",cd.DelegateType.Name.Name,cd.MethodName.Name); Console.Write("new {0}(", cd.DelegateType.Name.Name); report(cd.TargetObject, 0); Console.Write(".{0})", cd.MethodName.Name); // cd.Type; break; } default: { if (node is ZonnonCompilation) { ZonnonCompilation zc = node as ZonnonCompilation; report(zc.CompilationUnits[0], shift); } // Expression? else if (node is MethodCall) { MethodCall call = node as MethodCall; report(call.Callee, 0); Console.Write("("); if (call.Operands != null && call.Operands.Length != 0) { for (int i = 0, n = call.Operands.Length; i < n; i++) { report(call.Operands[i], 0); if (i < n - 1) { Console.Write(","); } } } Console.Write(")"); } else if (node is Variable) { Variable variable = node as Variable; Console.Write("{0}", variable.Name.Name); } else if (node is Identifier) { Identifier identifier = node as Identifier; Console.Write("{0}", identifier.Name); } else if (node is QualifiedIdentifier) { QualifiedIdentifier qualid = node as QualifiedIdentifier; report(qualid.Qualifier, 0); Console.Write(".{0}", qualid.Identifier == null?"<UNRESOLVED>":qualid.Identifier.Name); } else if (node is Literal) { Literal literal = node as Literal; if (literal.Value == null) { Console.Write("null"); } else { if (literal.Value is string) { Console.Write("\""); } else if (literal.Value is char) { Console.Write("'"); } Console.Write("{0}", literal.Value.ToString()); if (literal.Value is string) { Console.Write("\""); } else if (literal.Value is char) { Console.Write("'"); } } } else if (node is Indexer) { Indexer indexer = node as Indexer; report(indexer.Object, 0); Console.Write("["); for (int i = 0, n = indexer.Operands.Length; i < n; i++) { report(indexer.Operands[i], 0); if (i < n - 1) { Console.Write(","); } } Console.Write("]"); } else if (node is UnaryExpression) { UnaryExpression unexpr = node as UnaryExpression; bool add_pars = unexpr.Operand is BinaryExpression || unexpr.Operand is UnaryExpression; switch (unexpr.NodeType) { case NodeType.Add: Console.Write("+"); break; case NodeType.Sub: Console.Write("-"); break; case NodeType.Neg: Console.Write("-"); break; case NodeType.Not: Console.Write("~"); break; case NodeType.UnaryPlus: Console.Write("+"); break; case NodeType.LogicalNot: Console.Write("!"); break; case NodeType.Conv_U2: Console.Write("(UInt16)"); break; case NodeType.RefAddress: Console.Write("ref "); break; case NodeType.Ckfinite: Console.Write("(Ckfinite)"); break; default: Console.Write("???"); break; } if (add_pars) { Console.Write("("); } report(unexpr.Operand, 0); if (add_pars) { Console.Write(")"); } } else if (node is BinaryExpression) { BinaryExpression binexpr = node as BinaryExpression; bool add_pars = binexpr.Operand1 is BinaryExpression || binexpr.Operand1 is UnaryExpression; if (binexpr.NodeType == NodeType.Castclass) { Console.Write("("); report(binexpr.Operand2, 0); Console.Write(")"); if (add_pars) { Console.Write("("); } report(binexpr.Operand1, 0); if (add_pars) { Console.Write(")"); } break; } if (add_pars) { Console.Write("("); } report(binexpr.Operand1, 0); if (add_pars) { Console.Write(")"); } switch (binexpr.NodeType) { case NodeType.Add: Console.Write(" + "); break; case NodeType.Add_Ovf: Console.Write(" + "); break; case NodeType.Add_Ovf_Un: Console.Write(" + "); break; case NodeType.Sub: Console.Write(" - "); break; case NodeType.Sub_Ovf: Console.Write(" - "); break; case NodeType.Sub_Ovf_Un: Console.Write(" - "); break; case NodeType.Mul: Console.Write(" * "); break; case NodeType.Mul_Ovf: Console.Write(" * "); break; case NodeType.Mul_Ovf_Un: Console.Write(" * "); break; case NodeType.Div: Console.Write(" / "); break; // case NodeType.Div : Console.Write(" DIV "); break; // "DIV" ????? case NodeType.Rem: Console.Write(" % "); break; // "MOD" ????? case NodeType.Or: Console.Write(" | "); break; case NodeType.And: Console.Write(" & "); break; case NodeType.Eq: Console.Write(" == "); break; case NodeType.Ne: Console.Write(" != "); break; case NodeType.Lt: Console.Write(" < "); break; case NodeType.Le: Console.Write(" <= "); break; case NodeType.Gt: Console.Write(" > "); break; case NodeType.Ge: Console.Write(" >= "); break; case NodeType.LogicalOr: Console.Write(" || "); break; case NodeType.LogicalAnd: Console.Write(" && "); break; case NodeType.Is: Console.Write(" is "); break; case NodeType.Comma: Console.Write(","); break; // case OPERATORS.In : expression.NodeType = NodeType // "IN" break; // case OPERATORS.Implements : expression.NodeType = NodeType // "IMPLEMENTS" break; default: Console.Write(" !! "); break; } add_pars = binexpr.Operand2 is BinaryExpression || binexpr.Operand2 is UnaryExpression; if (add_pars) { Console.Write("("); } report(binexpr.Operand2, 0); if (add_pars) { Console.Write(")"); } } else if (node is TernaryExpression) { TernaryExpression ter = node as TernaryExpression; if (ter.NodeType == NodeType.Conditional) { report(ter.Operand1, 0); Console.Write(" ? "); report(ter.Operand2, 0); Console.Write(" : "); report(ter.Operand3, 0); } } else if (node is PostfixExpression) { PostfixExpression postfixExpr = node as PostfixExpression; report(postfixExpr.Expression, 0); switch (postfixExpr.Operator) { case NodeType.Increment: Console.Write("++"); break; case NodeType.Decrement: Console.Write("--"); break; default: Console.Write("???"); break; } } else if (node is LabeledStatement) { LabeledStatement lbst = node as LabeledStatement; indent(shift); report(lbst.Label, 0); Console.Write(" : "); report(lbst.Statement, 0); } else if (node is Goto) { Goto gt = node as Goto; indent(shift); Console.Write("goto "); report(gt.TargetLabel, 0); } else { indent(shift); Console.WriteLine("No code for reporting {0}:{1}", node.UniqueKey, node.ToString()); } break; } } }
public override void Visit(LabeledStatement s) { if(s.IdentifierHash != 0) gen.AddTextItem (s.Identifier, "Jump label"); }
public override object Visit (LabeledStatement labeledStatement) { var result = new LabelStatement (); result.AddChild (Identifier.Create (labeledStatement.Name, Convert (labeledStatement.loc)), Roles.Identifier); var location = LocationsBag.GetLocations (labeledStatement); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.Colon), Roles.Colon); return result; }
public override void TraverseChildren(IBlockStatement block) { Contract.Assume(block is BlockStatement); var decompiledBlock = (BlockStatement)block; var statements = decompiledBlock.Statements; for (int i = 0; i < statements.Count; i++) { var statement = statements[i]; var conditionalStatement = statement as ConditionalStatement; if (conditionalStatement == null) { continue; } var condition = conditionalStatement.Condition; var gotoStatement = conditionalStatement.FalseBranch as GotoStatement; if (gotoStatement == null) { gotoStatement = conditionalStatement.TrueBranch as GotoStatement; if (gotoStatement == null) { continue; } if (!(conditionalStatement.FalseBranch is EmptyStatement)) { continue; } condition = InvertCondition(condition); } else { if (!(conditionalStatement.TrueBranch is EmptyStatement)) { continue; } } var gotosThatTarget = this.gotosThatTarget[(uint)gotoStatement.TargetStatement.Label.UniqueKey]; Contract.Assume(gotosThatTarget != null && gotosThatTarget.Count > 0); var trueBlock = ExtractBlock(statements, i + 1, gotoStatement.TargetStatement, gotosThatTarget.Count == 1); if (trueBlock == null) { continue; } if (conditionalStatement.TrueBranch is EmptyStatement) { conditionalStatement.FalseBranch = conditionalStatement.TrueBranch; } conditionalStatement.TrueBranch = trueBlock; conditionalStatement.Condition = condition; gotosThatTarget.Remove(gotoStatement); } for (int i = statements.Count - 2; i >= 0; i--) { Contract.Assume(i < statements.Count); var statement = statements[i]; var conditionalStatement = statement as ConditionalStatement; if (conditionalStatement == null || !(conditionalStatement.FalseBranch is EmptyStatement)) { continue; } var trueBlock = conditionalStatement.TrueBranch as BlockStatement; if (trueBlock == null) { continue; } var gotoEndif = ReturnLastGoto(trueBlock); if (gotoEndif == null) { continue; } var gotosThatTarget = this.gotosThatTarget[(uint)gotoEndif.TargetStatement.Label.UniqueKey]; Contract.Assume(gotosThatTarget != null && gotosThatTarget.Count > 0); var falseBlock = ExtractBlock(statements, i + 1, gotoEndif.TargetStatement, gotosThatTarget.Count == 1); if (falseBlock == null) { continue; } conditionalStatement.FalseBranch = falseBlock; gotosThatTarget.Remove(gotoEndif); RemoveLastGoto(trueBlock); } var savedLabelImmediatelyFollowingCurrentBlock = this.labelImmediatelyFollowingCurrentBlock; for (int i = 0, n = decompiledBlock.Statements.Count; i < n; i++) { var statement = decompiledBlock.Statements[i]; Contract.Assume(statement != null); if (statement is BlockStatement || statement is ConditionalStatement) { if (i < n - 1) { this.labelImmediatelyFollowingCurrentBlock = decompiledBlock.Statements[i + 1] as LabeledStatement; if (this.labelImmediatelyFollowingCurrentBlock == null) { var blk = decompiledBlock.Statements[i + 1] as BlockStatement; if (blk != null && blk.Statements.Count > 0) { this.labelImmediatelyFollowingCurrentBlock = blk.Statements[0] as LabeledStatement; } } } else { this.labelImmediatelyFollowingCurrentBlock = savedLabelImmediatelyFollowingCurrentBlock; } } this.Traverse(statement); } this.labelImmediatelyFollowingCurrentBlock = savedLabelImmediatelyFollowingCurrentBlock; }
public void Visit(LabeledStatement node) { // not applicable; terminate }
public virtual void VisitLabeledStatement(LabeledStatement labeledStatement) { VisitStatement(labeledStatement.Body); }
// LabeledStatement protected internal virtual bool Walk(LabeledStatement node) { return true; }
public virtual object Visit (LabeledStatement labeledStatement) { return null; }
public virtual Statement VisitLabeledStatement(LabeledStatement lStatement, LabeledStatement changes, LabeledStatement deletions, LabeledStatement insertions){ this.UpdateSourceContext(lStatement, changes); if (lStatement == null) return changes; if (changes != null){ if (deletions == null || insertions == null) Debug.Assert(false); else{ } }else if (deletions != null) return null; return lStatement; }
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; }