Throw an exception when a final variable is being redefined, and use types instead of auto in the ParseTree::findReferenceByName() method and when calling it in Parser.hpp
This commit is contained in:
parent
47b5135402
commit
a73c7a9608
|
@ -81,8 +81,8 @@ public:
|
||||||
}
|
}
|
||||||
IS(StandardComponents::NamedIdentifier)
|
IS(StandardComponents::NamedIdentifier)
|
||||||
optional<reference_wrapper<T>> findReferenceByName(const string& name) const {
|
optional<reference_wrapper<T>> findReferenceByName(const string& name) const {
|
||||||
auto identifiers = findById<T>();
|
const vector<T*> identifiers = findById<T>();
|
||||||
for (const auto& identifier: identifiers) {
|
for (T* identifier: identifiers) {
|
||||||
if (identifier->getId() == typeid(T) && identifier->name == name) {
|
if (identifier->getId() == typeid(T) && identifier->name == name) {
|
||||||
return make_optional(ref(static_cast<T&>(*identifier)));
|
return make_optional(ref(static_cast<T&>(*identifier)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,10 @@ namespace Parser {
|
||||||
} else {
|
} else {
|
||||||
bool isFinalDefine = nextAre({TAG, DEFINE});
|
bool isFinalDefine = nextAre({TAG, DEFINE});
|
||||||
if (isFinalDefine || next.toktype == DEFINE) {
|
if (isFinalDefine || next.toktype == DEFINE) {
|
||||||
|
const optional previousDefinition = parseTree.findReferenceByName<Define>(current.toktext);
|
||||||
|
if (previousDefinition.has_value() && previousDefinition.value().get().final) {
|
||||||
|
throw ParsingException(current.toktext + " cannot be redefined as it is final", current.line);
|
||||||
|
}
|
||||||
parseTree << Define(isFinalDefine, current.toktext);
|
parseTree << Define(isFinalDefine, current.toktext);
|
||||||
i += 1 + isFinalDefine;
|
i += 1 + isFinalDefine;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue