X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogramsyntax.h;h=14e5d8e786cb679e36c448cf5ca68b1dfe387fd3;hb=0ab875bdc9fbf84ecfce883b188410bb45882447;hp=11a67430926849adee88a32cb636bcde544d1736;hpb=a36992487d018d8801ead6980b362b00a2f5f5c5;p=libs%2Fgl.git diff --git a/source/programsyntax.h b/source/programsyntax.h index 11a67430..14e5d8e7 100644 --- a/source/programsyntax.h +++ b/source/programsyntax.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include "extension.h" namespace Msp { namespace GL { @@ -24,34 +26,43 @@ 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 Block: Node { - std::list > body; + NodeList body; bool use_braces; std::map types; std::map variables; @@ -122,19 +133,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(); @@ -150,6 +170,14 @@ struct ExpressionStatement: Node virtual void visit(NodeVisitor &); }; +struct Import: Node +{ + std::string module; + + virtual Import *clone() const { return new Import(*this); } + virtual void visit(NodeVisitor &); +}; + struct Layout: Node { struct Qualifier @@ -159,12 +187,20 @@ struct Layout: Node }; std::vector qualifiers; - std::string interface; virtual Layout *clone() const { return new Layout(*this); } virtual void visit(NodeVisitor &); }; +struct InterfaceLayout: Node +{ + std::string interface; + Layout layout; + + virtual InterfaceLayout *clone() const { return new InterfaceLayout(*this); } + virtual void visit(NodeVisitor &); +}; + struct StructDeclaration: Node { std::string name; @@ -187,6 +223,8 @@ struct VariableDeclaration: Node bool array; NodePtr array_size; NodePtr init_expression; + VariableDeclaration *linked_declaration; + NodePtr layout; VariableDeclaration(); @@ -199,6 +237,8 @@ struct InterfaceBlock: Node std::string interface; std::string name; Block members; + std::string instance_name; + bool array; InterfaceBlock(); @@ -210,11 +250,12 @@ struct FunctionDeclaration: Node { 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 &); @@ -222,7 +263,7 @@ struct FunctionDeclaration: Node struct Conditional: Node { - Expression *condition; + NodePtr condition; Block body; Block else_body; @@ -241,6 +282,14 @@ struct Iteration: Node virtual void visit(NodeVisitor &); }; +struct Passthrough: Node +{ + NodePtr subscript; + + virtual Passthrough *clone() const { return new Passthrough(*this); } + virtual void visit(NodeVisitor &); +}; + struct Return: Node { NodePtr expression; @@ -260,15 +309,19 @@ 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(Layout &) { } + virtual void visit(InterfaceLayout &) { } virtual void visit(StructDeclaration &) { } virtual void visit(VariableDeclaration &) { } virtual void visit(InterfaceBlock &) { } virtual void visit(FunctionDeclaration &) { } virtual void visit(Conditional &) { } virtual void visit(Iteration &) { } + virtual void visit(Passthrough &) { } virtual void visit(Return &) { } }; @@ -281,38 +334,42 @@ 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 &); virtual void visit(FunctionDeclaration &); virtual void visit(Conditional &); virtual void visit(Iteration &); + virtual void visit(Passthrough &); virtual void visit(Return &); }; -enum ContextType +enum StageType { - GLOBAL, + SHARED, VERTEX, GEOMETRY, FRAGMENT }; -struct Context +struct Stage { - ContextType type; - bool present; + StageType type; + Stage *previous; ProgramSyntax::Block content; + std::map in_variables; + std::map out_variables; + std::map locations; + Version required_version; - Context(ContextType); + Stage(StageType); }; struct Module { - Context global_context; - Context vertex_context; - Context geometry_context; - Context fragment_context; + Stage shared; + std::list stages; Module(); };