summaryrefslogtreecommitdiff
path: root/src/core/parser
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-16 11:57:08 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-16 11:57:08 +0100
commit3cca090a650d2e8268977b57aa0dfdb0fb2cae85 (patch)
tree761eba26c204dfdf6b1d34eee345bc18a0fd13db /src/core/parser
parent884c7d772da6ad9869866f8a7a15bd08a15376ba (diff)
added return value in addFieldDescriptor related methods to indicate whether the order of fields had to be changed.
Diffstat (limited to 'src/core/parser')
-rw-r--r--src/core/parser/stack/DocumentHandler.cpp2
-rw-r--r--src/core/parser/stack/DomainHandler.cpp60
2 files changed, 43 insertions, 19 deletions
diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp
index d514701..41ca8ec 100644
--- a/src/core/parser/stack/DocumentHandler.cpp
+++ b/src/core/parser/stack/DocumentHandler.cpp
@@ -348,4 +348,4 @@ namespace RttiTypes {
const Rtti DocumentField = RttiBuilder<ousia::parser_stack::DocumentField>(
"DocumentField").parent(&Node);
}
-}
+} \ No newline at end of file
diff --git a/src/core/parser/stack/DomainHandler.cpp b/src/core/parser/stack/DomainHandler.cpp
index a2c8eec..ddec1ee 100644
--- a/src/core/parser/stack/DomainHandler.cpp
+++ b/src/core/parser/stack/DomainHandler.cpp
@@ -133,11 +133,18 @@ bool DomainFieldHandler::start(Variant::mapType &args)
Rooted<Descriptor> parent = scope().selectOrThrow<Descriptor>();
- Rooted<FieldDescriptor> field = parent->createFieldDescriptor(
+ auto res = parent->createFieldDescriptor(
logger(), type, args["name"].asString(), args["optional"].asBool());
- field->setLocation(location());
+ res.first->setLocation(location());
+ if (res.second) {
+ logger().warning(
+ std::string("Field \"") + res.first->getName() +
+ "\" was declared after main field. The order of fields "
+ "was changed to make the main field the last field.",
+ *res.first);
+ }
- scope().push(field);
+ scope().push(res.first);
return true;
}
@@ -150,14 +157,24 @@ bool DomainFieldRefHandler::start(Variant::mapType &args)
Rooted<Descriptor> parent = scope().selectOrThrow<Descriptor>();
const std::string &name = args["ref"].asString();
- scope().resolveFieldDescriptor(
- name, parent, logger(),
- [](Handle<Node> field, Handle<Node> parent, Logger &logger) {
- if (field != nullptr) {
- parent.cast<StructuredClass>()->addFieldDescriptor(
- field.cast<FieldDescriptor>(), logger);
- }
- });
+
+ auto loc = location();
+
+ scope().resolveFieldDescriptor(name, parent, logger(),
+ [loc](Handle<Node> field,
+ Handle<Node> parent, Logger &logger) {
+ if (field != nullptr) {
+ if (parent.cast<StructuredClass>()->addFieldDescriptor(
+ field.cast<FieldDescriptor>(), logger)) {
+ logger.warning(
+ std::string("Field \"") + field->getName() +
+ "\" was referenced after main field was declared. The "
+ "order of fields was changed to make the main field "
+ "the last field.",
+ loc);
+ }
+ }
+ });
return true;
}
@@ -176,13 +193,20 @@ bool DomainPrimitiveHandler::start(Variant::mapType &args)
fieldType = FieldDescriptor::FieldType::TREE;
}
- Rooted<FieldDescriptor> field = parent->createPrimitiveFieldDescriptor(
+ auto res = parent->createPrimitiveFieldDescriptor(
new UnknownType(manager()), logger(), fieldType,
args["name"].asString(), args["optional"].asBool());
- field->setLocation(location());
+ res.first->setLocation(location());
+ if (res.second) {
+ logger().warning(
+ std::string("Field \"") + res.first->getName() +
+ "\" was declared after main field. The order of fields "
+ "was changed to make the main field the last field.",
+ *res.first);
+ }
const std::string &type = args["type"].asString();
- scope().resolve<Type>(type, field, logger(),
+ scope().resolve<Type>(type, res.first, logger(),
[](Handle<Node> type, Handle<Node> field,
Logger &logger) {
if (type != nullptr) {
@@ -190,7 +214,7 @@ bool DomainPrimitiveHandler::start(Variant::mapType &args)
}
});
- scope().push(field);
+ scope().push(res.first);
return true;
}
@@ -254,8 +278,8 @@ bool DomainParentFieldHandler::start(Variant::mapType &args)
Logger &logger) {
if (parent != nullptr) {
Rooted<FieldDescriptor> field =
- parent.cast<Descriptor>()->createFieldDescriptor(
- logger, type, name, optional);
+ (parent.cast<Descriptor>()->createFieldDescriptor(
+ logger, type, name, optional)).first;
field->addChild(strct.cast<StructuredClass>());
}
});
@@ -390,4 +414,4 @@ namespace RttiTypes {
const Rtti DomainParent = RttiBuilder<ousia::parser_stack::DomainParent>(
"DomainParent").parent(&Node);
}
-}
+} \ No newline at end of file