private static AstNode ParseGiven(TokenStream stream) { GivenStatement switchStmt = new GivenStatement (stream.Location); stream.Expect (TokenClass.Keyword, "given"); stream.Expect (TokenClass.OpenParan); switchStmt.Add (ParseExpression (stream)); stream.Expect (TokenClass.CloseParan); stream.Expect (TokenClass.OpenBrace); AstNode defaultBlock = new AstRoot (stream.Location); AstRoot caseStatements = new AstRoot (stream.Location); while (!stream.EndOfStream && !stream.Match (TokenClass.CloseBrace)) { caseStatements.Add (ParseWhen (stream)); if (stream.Accept (TokenClass.Keyword, "default")) { defaultBlock = ParseStatement (stream); } } switchStmt.Add (caseStatements); switchStmt.Add (defaultBlock); stream.Expect (TokenClass.CloseBrace); return switchStmt; }
public override void Accept (GivenStatement switchStmt) { foreach (AstNode node in switchStmt.WhenStatements.Children) { WhenStatement caseStmt = node as WhenStatement; caseStmt.Values.Visit (this); caseStmt.Body.Visit (this); } switchStmt.GivenValue.Visit (this); methodBuilder.EmitInstruction (switchStmt.Location, Opcode.SwitchLookup, switchStmt.WhenStatements.Children.Count); IodineLabel endLabel = methodBuilder.CreateLabel (); methodBuilder.EmitInstruction (switchStmt.Location, Opcode.JumpIfTrue, endLabel); switchStmt.DefaultStatement.Visit (this); methodBuilder.MarkLabelPosition (endLabel); }
public void Accept(GivenStatement switchStmt) { }
public override void Accept (GivenStatement switchStmt) { errorLog.AddError (ErrorType.ParserError, switchStmt.Location, "statement can not exist inside pattern!"); }
public void Accept(GivenStatement switchStmt) { switchStmt.VisitChildren (this); }
public void Accept(GivenStatement switchStmt) { errorLog.AddError (ErrorType.ParserError, switchStmt.Location, "Statement not allowed outside function body!"); }