From fb6116c041a3c640a895487d5b515475c96eb5d0 Mon Sep 17 00:00:00 2001 From: Liran Zvibel Date: Thu, 24 Apr 2014 21:05:00 +0300 Subject: [PATCH 1/3] ASTPrinter: Support empty goto case; support goto case; with out an expression. currently running dscanner --ast std/d/parser.d fails with a segfault --- astprinter.d | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/astprinter.d b/astprinter.d index e1bff6d..c577de0 100644 --- a/astprinter.d +++ b/astprinter.d @@ -592,7 +592,9 @@ class XMLPrinter : ASTVisitor { output.writeln(""); output.writeln(""); - visit(gotoStatement.expression); + if (gotoStatement.expression) { + visit(gotoStatement.expression); + } output.writeln(""); output.writeln(""); } From 2f4d53338e40c8da7191ac0ce07620770b981984 Mon Sep 17 00:00:00 2001 From: Liran Zvibel Date: Thu, 24 Apr 2014 21:11:46 +0300 Subject: [PATCH 2/3] Parser: Support {start,end}Location for ReturnStatement --- std/d/ast.d | 2 ++ std/d/parser.d | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/std/d/ast.d b/std/d/ast.d index 9e508bf..a44b473 100644 --- a/std/d/ast.d +++ b/std/d/ast.d @@ -2302,6 +2302,8 @@ public: mixin (visitIfNotNull!(expression)); } /** */ Expression expression; + /** */ size_t startLocation; + /** */ size_t endLocation; mixin OpEquals; } diff --git a/std/d/parser.d b/std/d/parser.d index 65cdc51..22b81d3 100644 --- a/std/d/parser.d +++ b/std/d/parser.d @@ -4425,10 +4425,14 @@ q{(int a, ...) { mixin(traceEnterAndExit!(__FUNCTION__)); auto node = allocate!ReturnStatement; - if (expect(tok!"return") is null) return null; + auto start = expect(tok!"return"); + if (start is null) return null; + node.startLocation = start.index; if (!currentIs(tok!";")) node.expression = parseExpression(); - if (expect(tok!";") is null) return null; + auto semicolon = expect(tok!";"); + if (semicolon is null) return null; + node.endLocation = semicolon.index; return node; } From fafb383e6696eb1e8fb88721edf7d4b0048c3440 Mon Sep 17 00:00:00 2001 From: liranz Date: Thu, 24 Apr 2014 22:12:10 +0300 Subject: [PATCH 3/3] Update astprinter.d Removed baraces for single if expression changed spaces to tabs --- astprinter.d | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/astprinter.d b/astprinter.d index c577de0..33c2165 100644 --- a/astprinter.d +++ b/astprinter.d @@ -592,9 +592,8 @@ class XMLPrinter : ASTVisitor { output.writeln(""); output.writeln(""); - if (gotoStatement.expression) { - visit(gotoStatement.expression); - } + if (gotoStatement.expression) + visit(gotoStatement.expression); output.writeln(""); output.writeln(""); }