Parser.hpp: Prevent the reuse of identifiers

Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404 2022-05-26 13:32:41 +02:00
parent a8e514d67f
commit 46a09217fe
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 16 additions and 2 deletions

View File

@ -88,8 +88,6 @@ namespace Parser {
i += parametersDistance;
}
if (nextAre({LCOMP, LCOMP, LBRACE})) {
if (parseTree.template findReferenceByName<Function>(current.toktext).has_value())
parsingError(current, " is already defined", true);
Function function(current.toktext);
if (parametersDistance > 2) {
function.parameters = parse(filter_comma_list(lexed.begin() + ((i + 2) - parametersDistance), lexed.begin() + i));
@ -140,6 +138,22 @@ namespace Parser {
}
default: parsingError(current, " \u27F5 Unexpected character", true);
}
try {
const auto& last = parseTree.cend() - 1;
const type_info& lastId = last->get()->getId();
const auto& last_identifier = dynamic_cast<NamedIdentifier&>(**last);
if (lastId != typeid(Reference) &&
lastId != typeid(Call) &&
lastId != typeid(Define) and
any_of(parseTree.cbegin(), last, [&last_identifier](const component_ptr& pointer){
try {
return dynamic_cast<NamedIdentifier&>(*pointer).name == last_identifier.name;
} catch (const bad_cast&) {
return false;
}
}))
{ parsingError(current, " has already been defined previously", true); }
} catch (const bad_cast&) {}
}
return parseTree;
}