From 938e9d9368f07340f630e49ad1ed8d11115de79b Mon Sep 17 00:00:00 2001 From: Marko Semet Date: Fri, 14 Jun 2019 12:36:47 +0200 Subject: [PATCH] Support sir import of hints and restrictions --- sirSpec/annotations.skill | 16 +--------------- src/data/serializeSIR.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/sirSpec/annotations.skill b/sirSpec/annotations.skill index c6167d1..f05d747 100644 --- a/sirSpec/annotations.skill +++ b/sirSpec/annotations.skill @@ -11,38 +11,24 @@ interface Annotations { /** * A hint including name and parsed arguments */ -@abstract Hint { string name; -} -HintValues extends Hint { /** * if a string has arguments at all, they are stored as plain text */ string[] arguments; } -HintTypes extends Hint { - Type[] types; -} - /** * Base of type and field restrictions. */ -@abstract Restriction { string name; -} -RestrictionValues extends Restriction { /** * restriction arguments are stored as strings, because I do not want * to introduce a million restriction types just for range restrictions. */ string[] arguments; -} - -RestrictionTypes extends Restriction { - Type[] types; -} +} \ No newline at end of file diff --git a/src/data/serializeSIR.cpp b/src/data/serializeSIR.cpp index 9811385..8a45e30 100644 --- a/src/data/serializeSIR.cpp +++ b/src/data/serializeSIR.cpp @@ -61,6 +61,8 @@ inline std::unique_ptr _loadFields(SOURCE* source inline sirEdit::data::Type* genBaseType(sir::UserdefinedType& uf) { std::string skillType = uf.skillName(); sirEdit::data::Type* result; + + // Create type if(skillType == sir::ClassType::typeName) { std::unique_ptr fields = std::move(_loadFields(static_cast(&uf))); result = new TypeClass(std::move(*(fields.get())), std::vector(), nullptr); @@ -71,6 +73,26 @@ inline sirEdit::data::Type* genBaseType(sir::UserdefinedType& uf) { } else throw std::invalid_argument(std::string("Unknown skill class type ") + skillType); + + // Hints + if(uf.getHints() != nullptr) + for(auto& i : *(uf.getHints())) { + auto tmp = result->getHints().find(*(i->getName())); + if(tmp == result->getHints().end()) + tmp = result->getHints().insert(make_pair(string(*(i->getName())), vector())).first; + for(auto& j : *(i->getArguments())) + tmp->second.push_back(*j); + + } + if(uf.getRestrictions() != nullptr) + for(auto& i : *(uf.getRestrictions())) { + auto tmp = result->getRestrictions().find(*(i->getName())); + if(tmp == result->getRestrictions().end()) + tmp = result->getRestrictions().insert(make_pair(string(*(i->getName())), vector())).first; + for(auto& j : *(i->getArguments())) + tmp->second.push_back(*j); + + } return result; }