From f1b0d46ca0ec7c0310ba6ef6a5471bcf898faa07 Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Sat, 14 Mar 2015 16:53:00 -0400 Subject: [PATCH] WOW. NodeTree deletes duplicate nodes. So x+x didn't work.... --- include/NodeTree.h | 6 +++--- src/ASTTransformation.cpp | 8 ++++++++ tests/test_badMath.expected_results | 6 ++++++ tests/test_badMath.krak | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 tests/test_badMath.expected_results create mode 100644 tests/test_badMath.krak diff --git a/include/NodeTree.h b/include/NodeTree.h index b7573f7..a04d008 100644 --- a/include/NodeTree.h +++ b/include/NodeTree.h @@ -130,7 +130,7 @@ template void NodeTree::addChild(NodeTree* child) { if (!child) throw "Help, NULL child"; - if (findChild(child) == -1) + //if (findChild(child) == -1) children.push_back(child); } @@ -138,7 +138,7 @@ template void NodeTree::insertChild(int i, NodeTree* child) { if (!child) throw "Help, NULL child"; - if (findChild(child) == -1) + //if (findChild(child) == -1) children.insert(children.begin()+i,child); } @@ -274,4 +274,4 @@ std::string NodeTree::getDOTName() { return(replaceExEscape(DOTName, "\n", "\\n")); } -#endif \ No newline at end of file +#endif diff --git a/src/ASTTransformation.cpp b/src/ASTTransformation.cpp index 5497641..edcece1 100644 --- a/src/ASTTransformation.cpp +++ b/src/ASTTransformation.cpp @@ -775,16 +775,23 @@ NodeTree* ASTTransformation::doFunction(NodeTree* scope, std:: newNode = new NodeTree(lookup, ASTData(function_call, Symbol(lookup, true))); NodeTree* function = functionLookup(scope, lookup, mapNodesToTypes(nodes)); + std::cout << "Num of newNode children " << newNode->getChildren().size() << std::endl; newNode->addChild(function); + std::cout << "Num of newNode children " << newNode->getChildren().size() << std::endl; newNode->addChildren(nodes); + std::cout << "Num of newNode children " << newNode->getChildren().size() << std::endl; + std::cout << "nodes " << nodes.size() << std::endl; //Specially handle dereference and address of to assign the correct type //We need some significant other type corrections here, maybe to the point of being their own function. (int + float, etc.) + std::cout << "the passed in nodes" << std::endl; for (auto i : nodes) std::cout << i->getDataRef()->toString() << " "; std::cout< oldTypes = mapNodesToTypes(nodes); + std::cout << "the oldtypes size" << oldTypes.size() << std::endl; if ((nodes.size() != 2 && lookup == "*") || lookup == "&" || lookup == "[]") { Type* newType = oldTypes[0].clone(); if (lookup == "*" || lookup == "[]") @@ -796,6 +803,7 @@ NodeTree* ASTTransformation::doFunction(NodeTree* scope, std:: } else { newNode->getDataRef()->valueType = function->getDataRef()->valueType, std::cout << "Some other ||" << lookup << "||" << std::endl; } + std::cout << "Num of newNode children " << newNode->getChildren().size() << std::endl; return newNode; } diff --git a/tests/test_badMath.expected_results b/tests/test_badMath.expected_results new file mode 100644 index 0000000..8ae1da9 --- /dev/null +++ b/tests/test_badMath.expected_results @@ -0,0 +1,6 @@ +Spam +12 +14 +28 +We'll find out. +34 diff --git a/tests/test_badMath.krak b/tests/test_badMath.krak new file mode 100644 index 0000000..5fdf244 --- /dev/null +++ b/tests/test_badMath.krak @@ -0,0 +1,18 @@ +import io; +|int| main() { + io::println("Spam"); + |int| x = 4; + x += 3; + x++; + |int| y = 6; + |int| z = x + y; + |int| q = z+z; + |int| q2 = z*3; + |int| q3 = y + y; + io::println(q3); + io::println(z); + io::println(q); + for (|int| i = 0; i < 20; i++;) z++; + if (z > 20) io::println("We'll find out."); + io::println(z); +}