From 3a66f0140547016b59fbb27be257aa456d0a11e1 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Sat, 15 Jun 2013 23:37:37 -0700 Subject: [PATCH] more implementation work --- std/d/ast.d | 16 +++++++++++++--- std/d/parser.d | 33 +++++++++++++++++++++++++++------ std/d/tester.d | 11 +++++++++++ 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/std/d/ast.d b/std/d/ast.d index 348093f..111fbaf 100755 --- a/std/d/ast.d +++ b/std/d/ast.d @@ -238,8 +238,7 @@ interface ASTNode /** */ void accept(ASTVisitor visitor); } -immutable string DEFAULT_ACCEPT = q{void accept(ASTVisitor visitor) { visitor.visit(this); }}; - +immutable string DEFAULT_ACCEPT = q{void accept(ASTVisitor visitor) {}}; immutable string SHIFT_SHIFT_BODY = q{ /** */ Token operator; @@ -577,7 +576,16 @@ public: class AttributedDeclaration : ASTNode { public: - mixin(DEFAULT_ACCEPT); + override void accept(ASTVisitor visitor) + { + if (attribute !is null) + visitor.visit(attribute); + foreach (dec; declarations) + { + if (dec !is null) + visitor.visit(dec); + } + } /** */Attribute attribute; /** */Declaration[] declarations; } @@ -848,6 +856,7 @@ public: if (sharedStaticConstructor !is null) visitor.visit(sharedStaticConstructor); if (conditionalDeclaration !is null) visitor.visit(conditionalDeclaration); if (pragmaDeclaration !is null) visitor.visit(pragmaDeclaration); + if (versionSpecification !is null) visitor.visit(versionSpecification); } /** */ AttributedDeclaration attributedDeclaration; @@ -873,6 +882,7 @@ public: /** */ SharedStaticConstructor sharedStaticConstructor; /** */ ConditionalDeclaration conditionalDeclaration; /** */ PragmaDeclaration pragmaDeclaration; + /** */ VersionSpecification versionSpecification; } /// diff --git a/std/d/parser.d b/std/d/parser.d index 5834192..956ba5b 100755 --- a/std/d/parser.d +++ b/std/d/parser.d @@ -1344,7 +1344,7 @@ class ClassFour(A, B) if (someTest()) : Super {}}; ConditionalDeclaration parseConditionalDeclaration() { auto node = new ConditionalDeclaration; - // TODO + node.compileCondition = parseCompileCondition(); return node; } @@ -1586,6 +1586,16 @@ class ClassFour(A, B) if (someTest()) : Super {}}; node.variableDeclaration = parseVariableDeclaration(type); break; case TokenType.version_: + if (peekIs(TokenType.lParen)) + node.conditionalDeclaration = parseConditionalDeclaration(); + else if (peekIs(TokenType.assign)) + node.versionSpecification = parseVersionSpecification(); + else + { + error(`"=" or "(" expected following "version"`); + return null; + } + break; case TokenType.debug_: node.conditionalDeclaration = parseConditionalDeclaration(); break; @@ -2982,6 +2992,12 @@ interface "Four" { auto node = new NonVoidInitializer; // TODO + if (curentIs(TokenType.lBrace)) + node.structInitializer = parseStructInitializer() + else if (currentIs(TokenType.lBracket)) + node.arrayInitializer = parseArrayInitializer() + else + node.assignExpression = parseAssignExpression(); return node; } @@ -3025,7 +3041,8 @@ interface "Four" OrOrExpression parseOrOrExpression() { auto node = new OrOrExpression; - // TODO + node.andAndExpression = parseAndAndExpression(); + return node; } @@ -3525,8 +3542,12 @@ interface "Four" { auto node = new StructBody; expect(TokenType.lBrace); - while (tokens[index] != TokenType.rBrace && moreTokens()) - node.structBodyItems ~= parseStructBodyItem(); + version (development) + skipBraceContent(); + else + assert (0); + //while (tokens[index] != TokenType.rBrace && moreTokens()) + // node.structBodyItems ~= parseStructBodyItem(); expect(TokenType.rBrace); return node; } @@ -3967,9 +3988,9 @@ interface "Four" { auto node = new TernaryExpression; node.orOrExpression = parseOrOrExpression(); - if (tokens[index] == TokenType.ternary) + if (currentIs(TokenType.ternary)) { - ++index; + advance(); node.expression = parseExpression(); expect(TokenType.colon); node.ternaryExpression = parseTernaryExpression(); diff --git a/std/d/tester.d b/std/d/tester.d index c873c95..5382152 100644 --- a/std/d/tester.d +++ b/std/d/tester.d @@ -33,6 +33,17 @@ class TestVisitor : ASTVisitor writeln("import declaration found"); } + override void visit(InterfaceDeclaration intDec) + { + writeln("Interface ", intDec.identifier.value, + " on line ", intDec.identifier.line); + } + + override void visit(VersionSpecification verSpec) + { + writeln("Version specification"); + } + alias ASTVisitor.visit visit; }