WOW. NodeTree deletes duplicate nodes. So x+x didn't work....

This commit is contained in:
Nathan Braswell
2015-03-14 16:53:00 -04:00
parent e04cf03858
commit f1b0d46ca0
4 changed files with 35 additions and 3 deletions

View File

@@ -130,7 +130,7 @@ template<class T>
void NodeTree<T>::addChild(NodeTree<T>* child) { void NodeTree<T>::addChild(NodeTree<T>* child) {
if (!child) if (!child)
throw "Help, NULL child"; throw "Help, NULL child";
if (findChild(child) == -1) //if (findChild(child) == -1)
children.push_back(child); children.push_back(child);
} }
@@ -138,7 +138,7 @@ template<class T>
void NodeTree<T>::insertChild(int i, NodeTree<T>* child) { void NodeTree<T>::insertChild(int i, NodeTree<T>* child) {
if (!child) if (!child)
throw "Help, NULL child"; throw "Help, NULL child";
if (findChild(child) == -1) //if (findChild(child) == -1)
children.insert(children.begin()+i,child); children.insert(children.begin()+i,child);
} }
@@ -274,4 +274,4 @@ std::string NodeTree<T>::getDOTName() {
return(replaceExEscape(DOTName, "\n", "\\n")); return(replaceExEscape(DOTName, "\n", "\\n"));
} }
#endif #endif

View File

@@ -775,16 +775,23 @@ NodeTree<ASTData>* ASTTransformation::doFunction(NodeTree<ASTData>* scope, std::
newNode = new NodeTree<ASTData>(lookup, ASTData(function_call, Symbol(lookup, true))); newNode = new NodeTree<ASTData>(lookup, ASTData(function_call, Symbol(lookup, true)));
NodeTree<ASTData>* function = functionLookup(scope, lookup, mapNodesToTypes(nodes)); NodeTree<ASTData>* function = functionLookup(scope, lookup, mapNodesToTypes(nodes));
std::cout << "Num of newNode children " << newNode->getChildren().size() << std::endl;
newNode->addChild(function); newNode->addChild(function);
std::cout << "Num of newNode children " << newNode->getChildren().size() << std::endl;
newNode->addChildren(nodes); 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 //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.) //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) for (auto i : nodes)
std::cout << i->getDataRef()->toString() << " "; std::cout << i->getDataRef()->toString() << " ";
std::cout<<std::endl; std::cout<<std::endl;
std::vector<Type> oldTypes = mapNodesToTypes(nodes); std::vector<Type> oldTypes = mapNodesToTypes(nodes);
std::cout << "the oldtypes size" << oldTypes.size() << std::endl;
if ((nodes.size() != 2 && lookup == "*") || lookup == "&" || lookup == "[]") { if ((nodes.size() != 2 && lookup == "*") || lookup == "&" || lookup == "[]") {
Type* newType = oldTypes[0].clone(); Type* newType = oldTypes[0].clone();
if (lookup == "*" || lookup == "[]") if (lookup == "*" || lookup == "[]")
@@ -796,6 +803,7 @@ NodeTree<ASTData>* ASTTransformation::doFunction(NodeTree<ASTData>* scope, std::
} else { } else {
newNode->getDataRef()->valueType = function->getDataRef()->valueType, std::cout << "Some other ||" << lookup << "||" << std::endl; 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; return newNode;
} }

View File

@@ -0,0 +1,6 @@
Spam
12
14
28
We'll find out.
34

18
tests/test_badMath.krak Normal file
View File

@@ -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);
}