diff --git a/src/headers/parsing/ParseComponents.hpp b/src/headers/parsing/ParseComponents.hpp index 33c8426..9d708c0 100644 --- a/src/headers/parsing/ParseComponents.hpp +++ b/src/headers/parsing/ParseComponents.hpp @@ -81,8 +81,8 @@ public: } IS(StandardComponents::NamedIdentifier) optional> findReferenceByName(const string& name) const { - auto identifiers = findById(); - for (const auto& identifier: identifiers) { + const vector identifiers = findById(); + for (T* identifier: identifiers) { if (identifier->getId() == typeid(T) && identifier->name == name) { return make_optional(ref(static_cast(*identifier))); } diff --git a/src/headers/parsing/Parser.hpp b/src/headers/parsing/Parser.hpp index fb9bc0a..f93551d 100644 --- a/src/headers/parsing/Parser.hpp +++ b/src/headers/parsing/Parser.hpp @@ -36,6 +36,10 @@ namespace Parser { } else { bool isFinalDefine = nextAre({TAG, DEFINE}); if (isFinalDefine || next.toktype == DEFINE) { + const optional previousDefinition = parseTree.findReferenceByName(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); i += 1 + isFinalDefine; } else {