diff --git a/src/headers/transpiler/Target.hpp b/src/headers/transpiler/Target.hpp index 535ae5d..235b3e0 100644 --- a/src/headers/transpiler/Target.hpp +++ b/src/headers/transpiler/Target.hpp @@ -74,6 +74,17 @@ protected: typedef pair print_functions_pair; virtual unordered_task_map getTaskMap() = 0; virtual print_functions_pair printFunctions() = 0; + void transpileTree(const derived_from auto& parseTree) { + if (parseTree.size() > 0) { + unsigned int subIndex = 0; + for (auto pointer_iterator = parseTree.cbegin(); pointer_iterator < parseTree.cend(); ++pointer_iterator) { + getTaskMapInstance().at(pointer_iterator->get()->getId())(parseTree, subIndex); ++subIndex; + if ((pointer_iterator + 1) != parseTree.cend() && parseTree.getId() == typeid(StandardComponents::Call)) { + output << ", "; + } + } + } + } typedef optional optional_string; virtual optional_string uniqueLineSeparator() { return ";"; }; const bool newLines; @@ -83,22 +94,14 @@ public: static unordered_task_map staticMap = getTaskMap(); // Default / Shared tasks: staticMap.merge(unordered_task_map({ - make_task(ParseTree, - unsigned int subIndex = 0; - for (auto pointer_iterator = parseComponent.cbegin(); pointer_iterator < parseComponent.cend(); ++pointer_iterator) { - staticMap[pointer_iterator->get()->getId()](parseComponent, subIndex); ++subIndex; - if ((pointer_iterator + 1) != parseComponent.cend() && parseComponent.getId() == typeid(StandardComponents::Call)) { - output << ", "; - } - } - ), + make_task(ParseTree, transpileTree(parseComponent);), make_task(StandardComponents::Reference, const auto print_functions = printFunctions(); output << ((parseComponent.name == "print") ? print_functions.first : (parseComponent.name == "print_line") ? print_functions.second : parseComponent.name); ), - make_task_noR(StandardComponents::Call, + make_task(StandardComponents::Call, output << '('; - staticMap[typeid(ParseTree)](parsedTree, index); + transpileTree(parseComponent); output << ')'; ) }));