X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramsyntax.h;h=9a0cc6ea3f4bc8c867a2d381494b816b937495eb;hp=c502ba47a90f32701bc885e44006ff48a8d93c24;hb=57c1139e4fe21aeca7118b18eb3ba6fa43d7bf90;hpb=1a561b4e8d77fd14711b2304152e0b2408a49fdf diff --git a/source/programsyntax.h b/source/programsyntax.h index c502ba47..9a0cc6ea 100644 --- a/source/programsyntax.h +++ b/source/programsyntax.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "extension.h" namespace Msp { @@ -24,40 +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; } -#if __cplusplus>=201103L - NodePtr(NodePtr &&p): node(p.node) { p.node = 0; } - NodePtr &operator=(NodePtr &&p) { delete node; node = p.node; p.node = 0; return *this; } -#endif - ~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; @@ -83,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 &); @@ -102,7 +76,7 @@ struct VariableReference: Expression struct MemberAccess: Expression { - NodePtr left; + RefPtr left; std::string member; VariableDeclaration *declaration; @@ -113,7 +87,7 @@ struct MemberAccess: Expression struct UnaryExpression: Expression { std::string oper; - NodePtr expression; + RefPtr expression; bool prefix; UnaryExpression(); @@ -124,9 +98,9 @@ struct UnaryExpression: Expression struct BinaryExpression: Expression { - NodePtr left; + RefPtr left; std::string oper; - NodePtr right; + RefPtr right; std::string after; virtual BinaryExpression *clone() const { return new BinaryExpression(*this); } @@ -149,7 +123,7 @@ struct FunctionCall: Expression std::string name; FunctionDeclaration *declaration; bool constructor; - std::vector > arguments; + std::vector > arguments; FunctionCall(); @@ -159,7 +133,7 @@ struct FunctionCall: Expression struct ExpressionStatement: Node { - NodePtr expression; + RefPtr expression; virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); } virtual void visit(NodeVisitor &); @@ -216,10 +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; - NodePtr layout; + RefPtr layout; VariableDeclaration(); @@ -245,7 +219,7 @@ struct FunctionDeclaration: Node { std::string return_type; std::string name; - std::vector > parameters; + std::vector > parameters; FunctionDeclaration *definition; Block body; @@ -258,7 +232,7 @@ struct FunctionDeclaration: Node struct Conditional: Node { - NodePtr condition; + RefPtr condition; Block body; Block else_body; @@ -268,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); } @@ -279,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 &); @@ -287,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 &);