RE: Complicated AST manipulation looks ugly in C++. How to refactor it?
January 25, 2022 at 3:12 am
(This post was last modified: January 25, 2022 at 3:38 am by GrandizerII.)
Do you actually use an IDE for your coding, Flat? Or is it all written in a standard text doc?
Nevermind, seems like it's the former.
Maybe avoid hardcoding URLs? Or if they're just part of comments, don't explicitly state the URLs and instead come up with something shorthand
Other than that, I don't see the issue. I'd rather you do what you did in that coding than try to crunch them all in into one statement.
ETA: How about this? Still some possible misalignments, but I'm done trying
Nevermind, seems like it's the former.
Maybe avoid hardcoding URLs? Or if they're just part of comments, don't explicitly state the URLs and instead come up with something shorthand
Other than that, I don't see the issue. I'd rather you do what you did in that coding than try to crunch them all in into one statement.
ETA: How about this? Still some possible misalignments, but I'm done trying
Code:
} else if (text.size() == 2 and text[1] == '=') // The assignment operators "+=", "-=", "*=" and "/="...
{
if (children.at(0).text.back() == '[') {
// https://github.com/FlatAssembler/AECforWebAssembly/issues/15
// https://discord.com/channels/530598289813536771/847014270922391563/934823770307301416
TreeNode fakeInnerFunctionNode("Does", lineNumber, columnNumber);
std::string subscriptName = "tmp" + std::to_string(rand());
TreeNode declarationOfSubscript("Integer32", lineNumber, columnNumber);
declarationOfSubscript.children.push_back(TreeNode(subscriptName, lineNumber, columnNumber));
fakeInnerFunctionNode.children.push_back(declarationOfSubscript);
TreeNode subscriptAssignment(":=", lineNumber, columnNumber);
subscriptAssignment.children.push_back(TreeNode(subscriptName, lineNumber, columnNumber));
subscriptAssignment.children.push_back(children[0].children.at(0));
fakeInnerFunctionNode.children.push_back(subscriptAssignment);
TreeNode convertedToSimpleAssignment(":=", lineNumber, columnNumber);
convertedToSimpleAssignment.children.push_back(TreeNode(children[0].text, children[0].lineNumber, children[0].columnNumber));
convertedToSimpleAssignment.children[0].children.push_back(TreeNode(subscriptName, lineNumber, columnNumber));
convertedToSimpleAssignment.children.push_back(TreeNode(text.substr(0, 1), lineNumber, columnNumber));
convertedToSimpleAssignment.children[1].children.push_back(TreeNode(children[0].text, children[0].lineNumber, children[0].columnNumber));
convertedToSimpleAssignment.children[1].children[0].children.push_back(TreeNode(subscriptName, lineNumber, columnNumber));
convertedToSimpleAssignment.children[1].children.push_back(children.at(1));
fakeInnerFunctionNode.children.push_back(convertedToSimpleAssignment);
CompilationContext fakeContext = context;
fakeContext.stackSizeOfThisScope = 0;
fakeContext.stackSizeOfThisFunction = 0;
assembly += fakeInnerFunctionNode.compile(fakeContext) + "\n";
} else {
TreeNode convertedToSimpleAssignment(":=", lineNumber, columnNumber);
convertedToSimpleAssignment.children.push_back(children[0]);
convertedToSimpleAssignment.children.push_back(*this);
convertedToSimpleAssignment.children[1].text = convertedToSimpleAssignment.children[1].text.substr(0, 1);
assembly += convertedToSimpleAssignment.compile(context);
}