From f90a9bf51f300dd277071b1461d00411d7c21b89 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Thu, 22 Jan 2015 02:45:57 +0100 Subject: Rethought task of the Project class: Only keeps track of the included documents -- does not have references to typesystems, domains etc. (this allows instances of these classes to be freed as soon as no document refers to them). Project should be a parent of Document. Project should resolve documents as composita (this allows to have between-document references). --- src/core/model/Project.cpp | 38 +++++++--------------------------- src/core/model/Project.hpp | 51 +++++++--------------------------------------- 2 files changed, 14 insertions(+), 75 deletions(-) (limited to 'src/core/model') diff --git a/src/core/model/Project.cpp b/src/core/model/Project.cpp index fc08660..56a3af2 100644 --- a/src/core/model/Project.cpp +++ b/src/core/model/Project.cpp @@ -38,9 +38,7 @@ Project::Project(Manager &mgr) bool Project::doValidate(Logger &logger) const { - return continueValidation(documents, logger) & - continueValidation(domains, logger) & - continueValidation(typesystems, logger); + return continueValidation(documents, logger); } Rooted Project::getSystemTypesystem() @@ -50,58 +48,36 @@ Rooted Project::getSystemTypesystem() Rooted Project::createTypesystem(const std::string &name) { - Rooted typesystem{ + return Rooted{ new Typesystem{getManager(), systemTypesystem, name}}; - addTypesystem(typesystem); - return typesystem; -} - -void Project::addTypesystem(Handle typesystem) -{ - invalidate(); - typesystems.push_back(typesystem); } Rooted Project::createDocument(const std::string &name) { - Rooted document{new Document(getManager(), name)}; + return Rooted document{new Document(getManager(), name)}; addDocument(document); return document; } -void Project::addDocument(Handle document) -{ - invalidate(); - documents.push_back(document); -} - Rooted Project::createDomain(const std::string &name) { - Rooted domain{new Domain(getManager(), systemTypesystem, name)}; - addDomain(domain); - return domain; + return Rooted{new Domain(getManager(), systemTypesystem, name)}; } -void Project::addDomain(Handle domain) +void Project::addDocument(Handle document) { invalidate(); - domains.push_back(domain); + documents.push_back(document); } const NodeVector &Project::getDocuments() { return documents; } - -const NodeVector &Project::getDomains() { return domains; } - -const NodeVector &Project::getTypesystems() { return typesystems; } } namespace RttiTypes { const Rtti Project = RttiBuilder("Project") .parent(&Node) .composedOf(&Document) - .composedOf(&Typesystem) - .composedOf(&SystemTypesystem) - .composedOf(&Domain); + .composedOf(&SystemTypesystem); } } diff --git a/src/core/model/Project.hpp b/src/core/model/Project.hpp index 576bd60..4e2a43b 100644 --- a/src/core/model/Project.hpp +++ b/src/core/model/Project.hpp @@ -44,8 +44,9 @@ class Document; class Domain; /** - * The Project class constitutes the top-level node in which documents, domains, - * typesystems and other resources are embedded. + * The Project class constitutes the top-level node in which a collection of + * documents are stored. It also contains an instance of the SystemTypesystem + * and allows for simple creation of new Typesystem and Domain instances. */ class Project : public Node { private: @@ -60,16 +61,6 @@ private: */ NodeVector documents; - /** - * List containing all loaded domains. - */ - NodeVector domains; - - /** - * List containing all loaded typesystems. - */ - NodeVector typesystems; - protected: /** * Validates the project and all parts it consists of. @@ -102,13 +93,6 @@ public: */ Rooted createTypesystem(const std::string &name); - /** - * Adds a single new typesystem to the project. - * - * @param typesystem is the typesystem that should be added to the project. - */ - void addTypesystem(Handle typesystem); - /** * Returns a new document with the given name and adds it to the list of * documents. @@ -117,13 +101,6 @@ public: */ Rooted createDocument(const std::string &name); - /** - * Adds the given document to the list of documents in the project. - * - * @param document is the document that should be added to the project. - */ - void addDocument(Handle document); - /** * Returns a new domain with the given name and adds it to the list of * domains. Provides a reference of the system typesystem to the domain. @@ -133,32 +110,18 @@ public: Rooted createDomain(const std::string &name); /** - * Adds the given domain to the list of domains in the project. + * Adds the given document to the list of documents in the project. * - * @param domain is the document that should be added to the project. + * @param document is the document that should be added to the project. */ - void addDomain(Handle domain); + void addDocument(Handle document); /** * Returns all documents of this project. * * @return a reference pointing at the document list. */ - const NodeVector &getDocuments(); - - /** - * Returns all domains of this project. - * - * @return a reference pointing at the domain list. - */ - const NodeVector &getDomains(); - - /** - * Returns all typesystems of this project. - * - * @return a reference pointing at the typesystem list. - */ - const NodeVector &getTypesystems(); + const NodeVector &getDocuments() const; }; } -- cgit v1.2.3 From 17f4fb572a0493679342077c36ff8eb3116cb222 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 23 Jan 2015 00:32:39 +0100 Subject: Atatching Location to Node --- src/core/model/Node.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/core/model') diff --git a/src/core/model/Node.hpp b/src/core/model/Node.hpp index c5761a8..af92a50 100644 --- a/src/core/model/Node.hpp +++ b/src/core/model/Node.hpp @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -136,6 +137,12 @@ private: */ Owned parent; + /** + * Location from which the node was read (specifies the source file and the + * range in that source file). + */ + SourceLocation location; + /** * A "dirty" flag that signifies if this Node has been already validated * or not. @@ -519,6 +526,21 @@ public: * @return the current ValidationState of this Node. */ ValidationState getValidationState() const { return validationState; } + + /** + * Returns the location in the source file. + * + * @return a source location descriptor. + */ + SourceLocation getLocation() { return location; } + + /** + * Sets the location of the node to the given value. + * + * @param location describes the exact position of the Node in a source + * file. + */ + void setLocation(const SourceLocation &location) {this->location = location;} }; /** -- cgit v1.2.3 From 7610f2d1bc6c7b263ef41e765d571ac460709a7e Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 23 Jan 2015 12:09:05 +0100 Subject: Made getLocation const --- src/core/model/Node.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/model') diff --git a/src/core/model/Node.hpp b/src/core/model/Node.hpp index af92a50..6fc7dba 100644 --- a/src/core/model/Node.hpp +++ b/src/core/model/Node.hpp @@ -532,7 +532,7 @@ public: * * @return a source location descriptor. */ - SourceLocation getLocation() { return location; } + SourceLocation getLocation() const { return location; } /** * Sets the location of the node to the given value. -- cgit v1.2.3 From 01edb481fe5919ffde18b9081a0de1a3f94b317c Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 23 Jan 2015 15:29:53 +0100 Subject: Compiles now --- src/core/model/Project.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/core/model') diff --git a/src/core/model/Project.cpp b/src/core/model/Project.cpp index 56a3af2..a0f1f08 100644 --- a/src/core/model/Project.cpp +++ b/src/core/model/Project.cpp @@ -30,9 +30,7 @@ namespace model { Project::Project(Manager &mgr) : Node(mgr), systemTypesystem(acquire(new SystemTypesystem(mgr))), - documents(this), - domains(this), - typesystems(this) + documents(this) { } @@ -54,7 +52,7 @@ Rooted Project::createTypesystem(const std::string &name) Rooted Project::createDocument(const std::string &name) { - return Rooted document{new Document(getManager(), name)}; + Rooted document{new Document(getManager(), name)}; addDocument(document); return document; } @@ -70,7 +68,7 @@ void Project::addDocument(Handle document) documents.push_back(document); } -const NodeVector &Project::getDocuments() { return documents; } +const NodeVector &Project::getDocuments() const { return documents; } } namespace RttiTypes { -- cgit v1.2.3 From aa817d3bfd90aa39b6fd8a915bc78a8bb210cd3d Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 23 Jan 2015 15:43:36 +0100 Subject: Referencing the nodes in which the validation fails --- src/core/model/Node.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/model') diff --git a/src/core/model/Node.cpp b/src/core/model/Node.cpp index eb0e4a7..dbc85e2 100644 --- a/src/core/model/Node.cpp +++ b/src/core/model/Node.cpp @@ -363,7 +363,7 @@ bool Node::checkDuplicate(Handle elem, logger.error(std::string("Element with name \"") + name + std::string("\" defined multiple times in parent ") + type().name + std::string(" \"") + - Utils::join(path(), ".") + std::string("\"")); + Utils::join(path(), ".") + std::string("\""), *elem); return false; } return true; @@ -375,7 +375,7 @@ bool Node::validateName(Logger &logger) const { if (!Utils::isIdentifier(name)) { logger.error(type().name + std::string(" name \"") + name + - std::string("\" is not a valid identifier")); + std::string("\" is not a valid identifier"), this); return false; } return true; -- cgit v1.2.3