X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogramsyntax.h;h=9a0cc6ea3f4bc8c867a2d381494b816b937495eb;hb=a48aaa402e2aacab780805f529cde4ded7ae3f59;hp=c645a60a442ec91a616060f11c55327e9a34d4f6;hpb=a29cc14162e911b36d18d1d1896216697c7dc0c1;p=libs%2Fgl.git diff --git a/source/programsyntax.h b/source/programsyntax.h index c645a60a..9a0cc6ea 100644 --- a/source/programsyntax.h +++ b/source/programsyntax.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include "extension.h" namespace Msp { namespace GL { @@ -23,35 +25,13 @@ public: virtual void visit(NodeVisitor &) = 0; }; -template -class NodePtr -{ -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; } - -private: - static T *clone(T *n) { return n ? n->clone() : 0; } - -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; } -}; - struct StructDeclaration; struct VariableDeclaration; +struct FunctionDeclaration; struct Block: Node { - std::list > body; + std::list > body; bool use_braces; std::map types; std::map variables; @@ -77,7 +57,7 @@ struct Literal: Expression struct ParenthesizedExpression: Expression { - NodePtr expression; + RefPtr expression; virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); } virtual void visit(NodeVisitor &); @@ -96,7 +76,7 @@ struct VariableReference: Expression struct MemberAccess: Expression { - NodePtr left; + RefPtr left; std::string member; VariableDeclaration *declaration; @@ -107,7 +87,7 @@ struct MemberAccess: Expression struct UnaryExpression: Expression { std::string oper; - NodePtr expression; + RefPtr expression; bool prefix; UnaryExpression(); @@ -118,23 +98,32 @@ struct UnaryExpression: Expression struct BinaryExpression: Expression { - NodePtr left; + RefPtr left; std::string oper; - NodePtr right; + RefPtr 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; + std::vector > arguments; FunctionCall(); @@ -144,12 +133,20 @@ struct FunctionCall: Expression struct ExpressionStatement: Node { - NodePtr expression; + RefPtr expression; virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); } 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 +156,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; @@ -185,9 +190,10 @@ struct VariableDeclaration: Node StructDeclaration *type_declaration; std::string name; bool array; - NodePtr array_size; - NodePtr init_expression; + RefPtr array_size; + RefPtr init_expression; VariableDeclaration *linked_declaration; + RefPtr layout; VariableDeclaration(); @@ -200,6 +206,8 @@ struct InterfaceBlock: Node std::string interface; std::string name; Block members; + std::string instance_name; + bool array; InterfaceBlock(); @@ -211,11 +219,12 @@ struct FunctionDeclaration: Node { std::string return_type; std::string name; - std::vector > parameters; - bool definition; + std::vector > parameters; + FunctionDeclaration *definition; Block body; FunctionDeclaration(); + FunctionDeclaration(const FunctionDeclaration &); virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); } virtual void visit(NodeVisitor &); @@ -223,7 +232,7 @@ struct FunctionDeclaration: Node struct Conditional: Node { - Expression *condition; + RefPtr condition; Block body; Block else_body; @@ -233,9 +242,9 @@ struct Conditional: Node struct Iteration: Node { - NodePtr init_statement; - NodePtr condition; - NodePtr loop_expression; + RefPtr init_statement; + RefPtr condition; + RefPtr loop_expression; Block body; virtual Iteration *clone() const { return new Iteration(*this); } @@ -244,7 +253,7 @@ struct Iteration: Node struct Passthrough: Node { - NodePtr subscript; + RefPtr subscript; virtual Passthrough *clone() const { return new Passthrough(*this); } virtual void visit(NodeVisitor &); @@ -252,7 +261,7 @@ struct Passthrough: Node struct Return: Node { - NodePtr expression; + RefPtr expression; virtual Return *clone() const { return new Return(*this); } virtual void visit(NodeVisitor &); @@ -269,9 +278,12 @@ 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 &) { } @@ -291,6 +303,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 &); @@ -316,6 +329,8 @@ struct Stage ProgramSyntax::Block content; std::map in_variables; std::map out_variables; + std::map locations; + Version required_version; Stage(StageType); };