From 76ee5876723b96989ef7554a54f55769a1bbb4ed Mon Sep 17 00:00:00 2001 From: Stefano Sanfilippo Date: Thu, 27 Nov 2014 21:51:20 +0100 Subject: [PATCH] Use std::unique_ptr whenever possible. --- Nodes.cpp | 2 +- Nodes.hpp | 53 +++++++++++++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Nodes.cpp b/Nodes.cpp index e5cae31..5e92f08 100644 --- a/Nodes.cpp +++ b/Nodes.cpp @@ -29,7 +29,7 @@ void ExpNode::emit(std::ostream &stream, int indent) { } void SemiExpNode::emit(std::ostream &stream, int indent) { - SimpleExpression *e = dynamic_cast(left); + SimpleExpression *e = dynamic_cast(left.get()); bool braces = (e == nullptr); stream << ' ' << getSym() << ' '; diff --git a/Nodes.hpp b/Nodes.hpp index ac9dddf..504f2ab 100644 --- a/Nodes.hpp +++ b/Nodes.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace monicelli { @@ -115,7 +116,7 @@ public: virtual void emit(std::ostream &stream, int indent = 0); private: - Expression *expression; + std::unique_ptr expression; }; @@ -125,8 +126,8 @@ public: virtual void emit(std::ostream &stream, int indent = 0); private: - StatementList *body; - Expression *condition; + std::unique_ptr body; + std::unique_ptr condition; }; @@ -137,9 +138,9 @@ public: virtual void emit(std::ostream &stream, int indent = 0); private: - Id *name; + std::unique_ptr name; bool point; - Expression *init; + std::unique_ptr init; Type type; }; @@ -150,8 +151,8 @@ public: virtual void emit(std::ostream &stream, int indent = 0); private: - Id *name; - Expression *value; + std::unique_ptr name; + std::unique_ptr value; }; @@ -161,7 +162,7 @@ public: virtual void emit(std::ostream &stream, int indent = 0); private: - Expression *expression; + std::unique_ptr expression; }; @@ -171,7 +172,7 @@ public: virtual void emit(std::ostream &stream, int indent = 0); private: - Id *variable; + std::unique_ptr variable; }; @@ -187,7 +188,7 @@ public: virtual void emit(std::ostream &stream, int indent = 0); private: - Expression *expression; + std::unique_ptr expression; }; @@ -197,8 +198,8 @@ public: virtual void emit(std::ostream &stream, int indent = 0); private: - Id *name; - ExpressionList *args; + std::unique_ptr name; + std::unique_ptr args; }; @@ -208,8 +209,8 @@ public: virtual void emit(std::ostream &stream, int indent = 0); private: - SemiExpression *condition; - StatementList *body; + std::unique_ptr condition; + std::unique_ptr body; }; @@ -223,9 +224,9 @@ public: virtual void emit(std::ostream &stream, int indent = 0); private: - Id *var; - BranchCaseList *cases; - StatementList *els; + std::unique_ptr var; + std::unique_ptr cases; + std::unique_ptr els; }; @@ -235,7 +236,7 @@ public: virtual void emit(std::ostream &stream, int indent = 0); private: - StatementList *body; + std::unique_ptr body; }; @@ -246,9 +247,9 @@ public: virtual void emit(std::ostream &stream, int indent = 0); private: - Id *name; - IdList *args; - StatementList *body; + std::unique_ptr name; + std::unique_ptr args; + std::unique_ptr body; }; class Program: public Emittable { @@ -256,7 +257,7 @@ public: virtual void emit(std::ostream &stream, int indent = 0); void setMain(Main *m) { - main = m; + main = std::unique_ptr
(m); } void addFunction(Function *f) { @@ -264,7 +265,7 @@ public: } private: - Main *main; + std::unique_ptr
main; std::vector functions; }; @@ -278,8 +279,8 @@ protected: virtual std::string getSym() = 0; private: - Expression *left; - Expression *right; + std::unique_ptr left; + std::unique_ptr right; }; @@ -402,7 +403,7 @@ protected: virtual std::string getSym() = 0; private: - Expression *left; + std::unique_ptr left; };