From: Mikko Rasa Date: Tue, 6 Dec 2016 21:31:07 +0000 (+0200) Subject: Recognize various nonlinear flow control statement X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f02daac8305327d403e947e23c4f2d231eced417;p=libs%2Fgl.git Recognize various nonlinear flow control statement --- diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index 0e749c97..c7da6c55 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -452,6 +452,12 @@ void ProgramCompiler::Formatter::visit(Return &ret) formatted += ';'; } +void ProgramCompiler::Formatter::visit(Jump &jump) +{ + formatted += jump.keyword; + formatted += ';'; +} + ProgramCompiler::DeclarationCombiner::DeclarationCombiner(): toplevel(true), diff --git a/source/programcompiler.h b/source/programcompiler.h index 46c37930..e43b3a2d 100644 --- a/source/programcompiler.h +++ b/source/programcompiler.h @@ -60,6 +60,7 @@ private: virtual void visit(ProgramSyntax::Conditional &); virtual void visit(ProgramSyntax::Iteration &); virtual void visit(ProgramSyntax::Return &); + virtual void visit(ProgramSyntax::Jump &); }; template diff --git a/source/programparser.cpp b/source/programparser.cpp index da3ee0b9..bf5d5dff 100644 --- a/source/programparser.cpp +++ b/source/programparser.cpp @@ -388,6 +388,14 @@ RefPtr ProgramParser::parse_statement() return parse_passthrough(); else if(token=="return") return parse_return(); + else if(token=="break" || token=="continue" || token=="discard") + { + RefPtr jump = new Jump; + jump->keyword = parse_token(); + expect(";"); + + return jump; + } else if(is_qualifier(token) || is_type(token)) return parse_variable_declaration(); else if(!token.empty()) diff --git a/source/programsyntax.cpp b/source/programsyntax.cpp index 4438c16e..18545395 100644 --- a/source/programsyntax.cpp +++ b/source/programsyntax.cpp @@ -193,6 +193,12 @@ void Return::visit(NodeVisitor &visitor) } +void Jump::visit(NodeVisitor &visitor) +{ + visitor.visit(*this); +} + + void NodeVisitor::visit(Assignment &assign) { visit(static_cast(assign)); diff --git a/source/programsyntax.h b/source/programsyntax.h index 14e5d8e7..d681c50b 100644 --- a/source/programsyntax.h +++ b/source/programsyntax.h @@ -298,6 +298,14 @@ struct Return: Node virtual void visit(NodeVisitor &); }; +struct Jump: Node +{ + std::string keyword; + + virtual Jump *clone() const { return new Jump(*this); } + virtual void visit(NodeVisitor &); +}; + struct NodeVisitor { virtual ~NodeVisitor() { } @@ -323,6 +331,7 @@ struct NodeVisitor virtual void visit(Iteration &) { } virtual void visit(Passthrough &) { } virtual void visit(Return &) { } + virtual void visit(Jump &) { } }; struct TraversingVisitor: NodeVisitor