Add a transpileTree function to Target.hpp

Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404 2022-02-14 13:32:10 +01:00
parent 3c130529a4
commit 56e1db5fcc
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 14 additions and 11 deletions

View File

@ -74,6 +74,17 @@ protected:
typedef pair<const char*, const char*> print_functions_pair;
virtual unordered_task_map getTaskMap() = 0;
virtual print_functions_pair printFunctions() = 0;
void transpileTree(const derived_from<ParseTree> 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<const char*> 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 << ')';
)
}));