diff --git a/src/headers/SemanticAnalysis.hpp b/src/headers/SemanticAnalysis.hpp index c126fd6..d1feadb 100644 --- a/src/headers/SemanticAnalysis.hpp +++ b/src/headers/SemanticAnalysis.hpp @@ -21,18 +21,28 @@ struct SemanticAnalyser final: public Tasking { return tree; } private: - unordered_task_map getTaskMapInstance() final { // TODO Include line in error messages + unordered_task_map getTaskMapInstance() final { using namespace StandardComponents; return { make_nonlocal_task(Function, - if (index > 0 and any_of(parsedTree.cbegin(), parsedTree.cbegin() + index + 1, [&parseComponent](const component_ptr& pointer){ + if (index > 0 and any_of(parsedTree.cbegin(), parsedTree.cbegin() + index, [&parseComponent](const component_ptr& pointer){ if (pointer->getId() != typeid(Reference)) { + string_view ptr_name; try { - return dynamic_cast&>(*pointer).name == parseComponent.name; - } catch (const bad_cast&) {}; + ptr_name = dynamic_cast&>(*pointer).name; + } catch (const bad_cast&) { + try { + ptr_name = dynamic_cast&>(*pointer).name; + } catch (const bad_cast&) { + return false; + } + }; + if (ptr_name == parseComponent.name) { + return true; + } } return false; - })) { error(parseComponent.name + " has already been defined previously"); } + })) { error(parseComponent.name + " has already been defined previously", parseComponent.line); } ), share_task(Function, Class), share_task(Function, Define), diff --git a/src/headers/parsing/ParseComponents.hpp b/src/headers/parsing/ParseComponents.hpp index eaa07d3..0484f10 100644 --- a/src/headers/parsing/ParseComponents.hpp +++ b/src/headers/parsing/ParseComponents.hpp @@ -24,6 +24,7 @@ template struct NamedIdentifier: virtual ParseComponent { struct identifier_reserved_exception: exception {}; const string name; + unsigned long line = 0; explicit NamedIdentifier(const string_view nameText): name(nameText) { if (disallow_reserved and reserved(name)) { throw identifier_reserved_exception(); diff --git a/src/headers/parsing/Parser.hpp b/src/headers/parsing/Parser.hpp index 6974403..a2be489 100644 --- a/src/headers/parsing/Parser.hpp +++ b/src/headers/parsing/Parser.hpp @@ -184,6 +184,16 @@ namespace Parser { } catch (const NamedIdentifier::identifier_reserved_exception&) { parsingError(current, " is a reserved identifier", true); } + if (!parseTree.empty()) { + const component_ptr& last = parseTree[parseTree.size() - 1]; + try { + dynamic_cast&>(*last).line = current.line; + } catch (const bad_cast&) { + try { + dynamic_cast&>(*last).line = current.line; + } catch (const bad_cast&) {} + } + } } return parseTree; }