Support sir import of hints and restrictions

master
Marko Semet 2019-06-14 12:36:47 +02:00
parent 4ec4927156
commit 938e9d9368
2 changed files with 23 additions and 15 deletions

View File

@ -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;
}
}

View File

@ -61,6 +61,8 @@ inline std::unique_ptr<sirEdit::data::TypeWithFields> _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<sirEdit::data::TypeWithFields> fields = std::move(_loadFields(static_cast<sir::ClassType*>(&uf)));
result = new TypeClass(std::move(*(fields.get())), std::vector<sirEdit::data::TypeInterface*>(), 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<string>())).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<string>())).first;
for(auto& j : *(i->getArguments()))
tmp->second.push_back(*j);
}
return result;
}