protected BlockStatNode AssertBlock(string src, bool empty = false) { BlockStatNode block = this.GenerateAST(src).As <BlockStatNode>(); Assert.That(block, Is.Not.Null); Assert.That(block.Children, empty ? Is.Empty : Is.Not.Empty); this.AssertChildrenParentProperties(block); return(block); }
public void SimpleBlockTest() { BlockStatNode block = this.AssertBlock(@" { // line 2 // line 3 int x; // line 4, block begins } "); Assert.That(block.Line, Is.EqualTo(4)); Assert.That(block.Children.Single(), Is.InstanceOf <DeclStatNode>()); }
public override ASTNode VisitFunctionDefinition([NotNull] FunctionDefinitionContext ctx) { DeclSpecsNode declSpecs = this.Visit(ctx.declarationSpecifiers()).As <DeclSpecsNode>(); ASTNode decl = this.Visit(ctx.declarator()); if (decl is IdNode fname) { decl = new FuncDeclNode(fname.Line, fname); } FuncDeclNode fdecl = decl.As <FuncDeclNode>(); BlockStatNode body = this.Visit(ctx.compoundStatement()).As <BlockStatNode>(); return(new FuncDefNode(ctx.Start.Line, declSpecs, fdecl, body)); }
public void ComplexBlockTest() { BlockStatNode block = this.AssertBlock(@" { // line 2 int x; // line 3, block begins if (x) { int z = y + 4; ; } else { float x, y = x + 3; ; ; } float w, h; } "); Assert.That(block.Line, Is.EqualTo(3)); Assert.That(block.Children, Has.Exactly(3).Items); Assert.That(block.Children.ElementAt(0), Is.InstanceOf <DeclStatNode>()); Assert.That(block.Children.ElementAt(1), Is.InstanceOf <IfStatNode>()); Assert.That(block.Children.ElementAt(2), Is.InstanceOf <DeclStatNode>()); }
public virtual TResult Visit(BlockStatNode node) => this.VisitChildren(node);
public override ASTNode VisitChunk([NotNull] ChunkContext ctx) { BlockStatNode block = this.Visit(ctx.block()).As <BlockStatNode>(); return(new SourceNode(this.AddDeclarations(block.Children))); }
public override MatchIssues Compare(SourceNode n1, SourceNode n2) { BlockStatNode b1 = FormBlock(n1); BlockStatNode b2 = FormBlock(n2); return(new BlockStatNodeComparer().Compare(b1, b2));