]> git.tdb.fi Git - libs/gl.git/commitdiff
Recognize various nonlinear flow control statement
authorMikko Rasa <tdb@tdb.fi>
Tue, 6 Dec 2016 21:31:07 +0000 (23:31 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 7 Dec 2016 00:28:09 +0000 (02:28 +0200)
source/programcompiler.cpp
source/programcompiler.h
source/programparser.cpp
source/programsyntax.cpp
source/programsyntax.h

index 0e749c9736588ddaa5192d74a70fb9719dc16f05..c7da6c5535b96bf649c8640522f9cdc07d459f1d 100644 (file)
@@ -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),
index 46c37930d6d4e948299f6ef43b637746dc3e4256..e43b3a2d45c0e1c272976de51abd6c643cff0054 100644 (file)
@@ -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<typename T>
index da3ee0b99f5c383b5f9475676dd2d7b3eeb8c3ff..bf5d5dffb103fea9b554afa0940f607d12b21ac4 100644 (file)
@@ -388,6 +388,14 @@ RefPtr<Node> ProgramParser::parse_statement()
                return parse_passthrough();
        else if(token=="return")
                return parse_return();
+       else if(token=="break" || token=="continue" || token=="discard")
+       {
+               RefPtr<Jump> 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())
index 4438c16ed03cb7bd7a3c5c94e86fe01d98235e25..185453952a006fdf591b9bf64b6306d37efe0989 100644 (file)
@@ -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<BinaryExpression &>(assign));
index 14e5d8e786cb679e36c448cf5ca68b1dfe387fd3..d681c50b924065f69a1ae990381af884d00bef0e 100644 (file)
@@ -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