X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramsyntax.h;h=3db059c4f4d79c4e6252537c5a1cfc27b90e223e;hp=c8b0e1f74ed9d1679e8c652ddb1f52f896872df5;hb=16a9d75c8e124a0faf89c56533792cb97a214e37;hpb=961715848c111907b5f443c5b545a429b40583e6 diff --git a/source/programsyntax.h b/source/programsyntax.h index c8b0e1f7..3db059c4 100644 --- a/source/programsyntax.h +++ b/source/programsyntax.h @@ -5,6 +5,12 @@ #include #include #include +#include +#include "extension.h" +#include "uniform.h" + +#pragma push_macro("interface") +#undef interface namespace Msp { namespace GL { @@ -24,34 +30,48 @@ public: }; template -class NodePtr +class NodePtr: public RefPtr { -private: - T *node; - public: - NodePtr(T *n = 0): node(n) { } - NodePtr(const NodePtr &p): node(clone(p.node)) { } - NodePtr &operator=(const NodePtr &p) { delete node; node = clone(p.node); return *this; } - ~NodePtr() { delete node; } + NodePtr() { } + NodePtr(T *p): RefPtr(p) { } + NodePtr(const NodePtr &p): RefPtr(p ? p->clone() : 0) { } -private: - static T *clone(T *n) { return n ? n->clone() : 0; } + template + NodePtr(const RefPtr &p): RefPtr(p) { } + + template + NodePtr(const NodePtr &p): RefPtr(p ? p->clone() : 0) { } +}; +template +class NodeContainer: public C +{ public: - T *operator->() { return node; } - const T *operator->() const { return node; } - T &operator*() { return *node; } - const T &operator*() const { return *node; } - operator void *() const { return node; } + NodeContainer() { } + NodeContainer(const NodeContainer &); }; +template +class NodeList: public NodeContainer > > +{ }; + +template +class NodeArray: public NodeContainer > > +{ }; + struct StructDeclaration; struct VariableDeclaration; +struct FunctionDeclaration; + +struct Statement: Node +{ + virtual Statement *clone() const = 0; +}; struct Block: Node { - std::list > body; + NodeList body; bool use_braces; std::map types; std::map variables; @@ -122,19 +142,28 @@ struct BinaryExpression: Expression std::string oper; NodePtr right; std::string after; - bool assignment; - - BinaryExpression(); virtual BinaryExpression *clone() const { return new BinaryExpression(*this); } virtual void visit(NodeVisitor &); }; +struct Assignment: BinaryExpression +{ + bool self_referencing; + VariableDeclaration *target_declaration; + + Assignment(); + + virtual Assignment *clone() const { return new Assignment(*this); } + virtual void visit(NodeVisitor &); +}; + struct FunctionCall: Expression { std::string name; + FunctionDeclaration *declaration; bool constructor; - std::vector > arguments; + NodeArray arguments; FunctionCall(); @@ -142,7 +171,7 @@ struct FunctionCall: Expression virtual void visit(NodeVisitor &); }; -struct ExpressionStatement: Node +struct ExpressionStatement: Statement { NodePtr expression; @@ -150,22 +179,48 @@ struct ExpressionStatement: Node virtual void visit(NodeVisitor &); }; +struct Import: Statement +{ + std::string module; + + virtual Import *clone() const { return new Import(*this); } + virtual void visit(NodeVisitor &); +}; + +struct Precision: Statement +{ + std::string precision; + std::string type; + + virtual Precision *clone() const { return new Precision(*this); } + virtual void visit(NodeVisitor &); +}; + struct Layout: Node { struct Qualifier { + // TODO the standard calls this name, not identifier std::string identifier; std::string value; }; std::vector qualifiers; - std::string interface; virtual Layout *clone() const { return new Layout(*this); } virtual void visit(NodeVisitor &); }; -struct StructDeclaration: Node +struct InterfaceLayout: Statement +{ + std::string interface; + Layout layout; + + virtual InterfaceLayout *clone() const { return new InterfaceLayout(*this); } + virtual void visit(NodeVisitor &); +}; + +struct StructDeclaration: Statement { std::string name; Block members; @@ -176,11 +231,13 @@ struct StructDeclaration: Node virtual void visit(NodeVisitor &); }; -struct VariableDeclaration: Node +struct VariableDeclaration: Statement { bool constant; std::string sampling; + std::string interpolation; std::string interface; + std::string precision; std::string type; StructDeclaration *type_declaration; std::string name; @@ -188,6 +245,7 @@ struct VariableDeclaration: Node NodePtr array_size; NodePtr init_expression; VariableDeclaration *linked_declaration; + NodePtr layout; VariableDeclaration(); @@ -195,11 +253,13 @@ struct VariableDeclaration: Node virtual void visit(NodeVisitor &); }; -struct InterfaceBlock: Node +struct InterfaceBlock: Statement { std::string interface; std::string name; Block members; + std::string instance_name; + bool array; InterfaceBlock(); @@ -207,23 +267,24 @@ struct InterfaceBlock: Node virtual void visit(NodeVisitor &); }; -struct FunctionDeclaration: Node +struct FunctionDeclaration: Statement { std::string return_type; std::string name; - std::vector > parameters; - bool definition; + NodeArray parameters; + FunctionDeclaration *definition; Block body; FunctionDeclaration(); + FunctionDeclaration(const FunctionDeclaration &); virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); } virtual void visit(NodeVisitor &); }; -struct Conditional: Node +struct Conditional: Statement { - Expression *condition; + NodePtr condition; Block body; Block else_body; @@ -231,7 +292,7 @@ struct Conditional: Node virtual void visit(NodeVisitor &); }; -struct Iteration: Node +struct Iteration: Statement { NodePtr init_statement; NodePtr condition; @@ -242,7 +303,7 @@ struct Iteration: Node virtual void visit(NodeVisitor &); }; -struct Passthrough: Node +struct Passthrough: Statement { NodePtr subscript; @@ -250,7 +311,7 @@ struct Passthrough: Node virtual void visit(NodeVisitor &); }; -struct Return: Node +struct Return: Statement { NodePtr expression; @@ -258,6 +319,14 @@ struct Return: Node virtual void visit(NodeVisitor &); }; +struct Jump: Statement +{ + std::string keyword; + + virtual Jump *clone() const { return new Jump(*this); } + virtual void visit(NodeVisitor &); +}; + struct NodeVisitor { virtual ~NodeVisitor() { } @@ -269,9 +338,13 @@ struct NodeVisitor virtual void visit(MemberAccess &) { } virtual void visit(UnaryExpression &) { } virtual void visit(BinaryExpression &) { } + virtual void visit(Assignment &); virtual void visit(FunctionCall &) { } virtual void visit(ExpressionStatement &) { } + virtual void visit(Import &) { } + virtual void visit(Precision &) { } virtual void visit(Layout &) { } + virtual void visit(InterfaceLayout &) { } virtual void visit(StructDeclaration &) { } virtual void visit(VariableDeclaration &) { } virtual void visit(InterfaceBlock &) { } @@ -280,10 +353,12 @@ struct NodeVisitor virtual void visit(Iteration &) { } virtual void visit(Passthrough &) { } virtual void visit(Return &) { } + virtual void visit(Jump &) { } }; struct TraversingVisitor: NodeVisitor { + using NodeVisitor::visit; virtual void visit(Block &); virtual void visit(ParenthesizedExpression &); virtual void visit(MemberAccess &); @@ -291,6 +366,7 @@ struct TraversingVisitor: NodeVisitor virtual void visit(BinaryExpression &); virtual void visit(FunctionCall &); virtual void visit(ExpressionStatement &); + virtual void visit(InterfaceLayout &); virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); virtual void visit(InterfaceBlock &); @@ -301,32 +377,32 @@ struct TraversingVisitor: NodeVisitor virtual void visit(Return &); }; -enum ContextType +enum StageType { - GLOBAL, + SHARED, VERTEX, GEOMETRY, FRAGMENT }; -struct Context +struct Stage { - ContextType type; - bool present; - Context *previous; + StageType type; + Stage *previous; ProgramSyntax::Block content; std::map in_variables; std::map out_variables; + std::map locations; + Version required_version; + std::vector required_extensions; - Context(ContextType); + Stage(StageType); }; struct Module { - Context global_context; - Context vertex_context; - Context geometry_context; - Context fragment_context; + Stage shared; + std::list stages; Module(); }; @@ -335,4 +411,6 @@ struct Module } // namespace GL } // namespace Msp +#pragma pop_macro("interface") + #endif