From 988fac434d2450998cbce85e338cb1534acfa808 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Sun, 15 Feb 2015 23:09:18 +0100 Subject: changed order of fields in StructuredClass::getFieldDescriptors --- src/core/model/Domain.cpp | 44 ++++++++++++++++++++++++++------------------ src/core/model/Domain.hpp | 14 +++++++++----- 2 files changed, 35 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index ae20068..8bacdb8 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -778,36 +778,40 @@ void StructuredClass::removeSubclass(Handle sc, Logger &logger) sc->setSuperclass(nullptr, logger); } -void StructuredClass::gatherFieldDescriptors( +Rooted StructuredClass::gatherFieldDescriptors( NodeVector ¤t, std::set &overriddenFields, bool hasTREE) const { - // append all FieldDescriptors that are not overridden. - for (auto &f : Descriptor::getFieldDescriptors()) { + Rooted mainField; + NodeVector tmp; + // first gather the non-overridden fields. + for (auto f : Descriptor::getFieldDescriptors()) { if (overriddenFields.insert(f->getName()).second) { bool isTREE = f->getFieldType() == FieldDescriptor::FieldType::TREE; - if (hasTREE) { - if (!isTREE) { - /* - * If we already have a tree field it has to be at the end - * of the current vector. So ensure that all new non-TREE - * fields are inserted before the TREE field such that after - * this method the TREE field is still at the end. - */ - current.insert(current.end() - 1, f); - } + if (!isTREE) { + tmp.push_back(f); } else { - if (isTREE) { + if (!hasTREE) { hasTREE = true; + mainField = f; } - current.push_back(f); } } } - // if we have a superclass, go there. + // append all non-overridden superclass fields. + if (superclass != nullptr) { - superclass->gatherFieldDescriptors(current, overriddenFields, hasTREE); + Rooted super_main_field = + superclass->gatherFieldDescriptors(current, overriddenFields, + hasTREE); + if (!hasTREE) { + mainField = super_main_field; + } } + // then append all subtree fields of this level. + current.insert(current.end(), tmp.begin(), tmp.end()); + // and return the main field. + return mainField; } NodeVector StructuredClass::getFieldDescriptors() const @@ -815,7 +819,11 @@ NodeVector StructuredClass::getFieldDescriptors() const // in this case we return a NodeVector of Rooted entries without owner. NodeVector vec; std::set overriddenFields; - gatherFieldDescriptors(vec, overriddenFields, false); + Rooted mainField = + gatherFieldDescriptors(vec, overriddenFields, false); + if (mainField != nullptr) { + vec.push_back(mainField); + } return vec; } diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index 081435a..350c7ba 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -791,9 +791,9 @@ private: /** * Helper method for getFieldDescriptors. */ - void gatherFieldDescriptors(NodeVector ¤t, - std::set &overriddenFields, - bool hasTREE) const; + Rooted gatherFieldDescriptors( + NodeVector ¤t, + std::set &overriddenFields, bool hasTREE) const; protected: bool doValidate(Logger &logger) const override; @@ -915,10 +915,14 @@ public: void removeSubclass(Handle sc, Logger &logger); /** - * Returns a const reference to the NodeVector of all FieldDescriptors of + * Returns a NodeVector of all FieldDescriptors of * this StructuredClass. This also merges the FieldDescriptors directly * belonging to this StructuredClass with all FieldDescritptors of its - * Superclass (and so on recurvively). + * Superclass (and so on recurvively). The order of field descriptors is + * as follows: + * 1.) non-overridden SUBTREE FieldDescriptors of super classes. + * 2.) SUBTREE FieldDescriptors of this class. + * 3.) TREE FieldDescriptor (either inherited from super class or direct) * * @return a NodeVector of all FieldDescriptors of this StructuredClass. */ -- cgit v1.2.3 From a18012702fa6f9ff593c180112cbbc64c2ee0c41 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Sun, 15 Feb 2015 23:09:28 +0100 Subject: got rid of some unnecessary warnings. --- src/core/model/Domain.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index 8bacdb8..ac0699e 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -569,17 +569,22 @@ void Descriptor::addAndSortFieldDescriptor(Handle fd, if (!fds.empty() && fds.back()->getFieldType() == FieldDescriptor::FieldType::TREE && fd->getFieldType() != FieldDescriptor::FieldType::TREE) { - // if so we add the new field before the TREE field and log a - // warning. - - logger.warning( - std::string("Field \"") + fd->getName() + - "\" was declared after main field \"" + - fds.back()->getName() + - "\". The order of fields was changed to make the " - "main field the last field.", - *fd); + // if so we add the new field before the TREE field. fieldDescriptors.insert(fieldDescriptors.end() - 1, fd); + + // if the new field was from the same domain we warn the user + // because that is bad coding style. + if (fd->getParent() != nullptr && + fd->getParent().cast()->getParent() == + getParent()) { + logger.warning( + std::string("Field \"") + fd->getName() + + "\" was declared after main field \"" + + fds.back()->getName() + + "\". The order of fields was changed to make the " + "main field the last field.", + *fd); + } } else { fieldDescriptors.push_back(fd); } -- cgit v1.2.3