From 17b80d4102b7d3df92b97f5fe711d1a500eecbca Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Tue, 20 May 2014 23:53:19 -0400 Subject: [PATCH] Fixed a typo that caused indirection operators to do the reverse on types. Also cleaned up some comments. One more test working. --- main.cpp | 41 +++++---------------------------------- src/ASTTransformation.cpp | 11 ++--------- 2 files changed, 7 insertions(+), 45 deletions(-) diff --git a/main.cpp b/main.cpp index ace2966..4f6f8b7 100644 --- a/main.cpp +++ b/main.cpp @@ -48,13 +48,13 @@ int main(int argc, char* argv[]) { } std::string krakenDir = argv[0]; krakenDir = strSlice(krakenDir, 0, -(std::string("kraken").length()+1)); - includePaths.push_back(krakenDir + "stdlib/"); + includePaths.push_back(krakenDir + "stdlib/"); //Add the stdlib directory that exists in the same directory as the kraken executable to the path std::string programName = argv[1]; std::string grammerFileString = argv[2]; std::string outputName = argv[3]; std::ifstream grammerInFile, compiledGrammerInFile; - std::ofstream /*outFileC,*/ compiledGrammerOutFile; + std::ofstream compiledGrammerOutFile; grammerInFile.open(grammerFileString); if (!grammerInFile.is_open()) { @@ -63,17 +63,9 @@ int main(int argc, char* argv[]) { } compiledGrammerInFile.open(grammerFileString + ".comp", std::ios::binary | std::ios::ate); - if (!compiledGrammerInFile.is_open()) { + if (!compiledGrammerInFile.is_open()) std::cout << "Problem opening compiledGrammerInFile " << grammerFileString + ".comp" << "\n"; - //return(1); - } -/* - outFileC.open((outputName + ".c").c_str()); - if (!outFileC.is_open()) { - std::cout << "Probelm opening third output file " << outputName + ".c" << "\n"; - return(1); - } - */ + //Read the input file into a string std::string grammerInputFileString; std::string line; @@ -86,8 +78,6 @@ int main(int argc, char* argv[]) { //LALRParser parser; RNGLRParser parser; parser.loadGrammer(grammerInputFileString); - //std::cout << "Creating State Set from Main" << std::endl; - //std::cout << "\nState Set" << std::endl; //Start binary stuff bool compGramGood = false; @@ -111,7 +101,6 @@ int main(int argc, char* argv[]) { } else { compGramGood = true; std::cout << "Grammer file is up to date." << std::endl; - //int tableLength = *((int*)(binaryTablePointer + 4 + sizeof(int) + gramStringLength)); parser.importTable(binaryTablePointer + 4 + sizeof(int) + gramStringLength); //Load table starting at the table section } } else { @@ -141,43 +130,23 @@ int main(int argc, char* argv[]) { } //End binary stuff - //std::cout << "finished State Set from Main" << std::endl; - //std::cout << "Doing stateSetToString from Main" << std::endl; - // std::cout << "\n\n\n\n\n\n\n\n\n\nState Set toString" << std::endl; - // std::cout << parser.stateSetToString() << std::endl; - // std::cout << "finished stateSetToString from Main" << std::endl; - // std::cout << "\n\n\n\n\n\n\n\n\n\nTable" << std::endl; - // std::cout << parser.tableToString() << std::endl; - // std::cout << "\n\n\n\n\n\n\n\n\n\nGrammer Input File" << std::endl; - // std::cout << grammerInputFileString << std::endl; - // std::cout << "\n\n\n\n\n\n\n\n\n\nGrammer toString" << std::endl; - // std::cout << parser.grammerToString() << std::endl; - //std::cout << parser.grammerToDOT() << std::endl; - - //outFile << parser.grammerToDOT() << std::endl; std::cout << "\nParsing" << std::endl; Importer importer(&parser, includePaths); - /*NodeTree* AST =*/ for (auto i : includePaths) std::cout << i << std::endl; importer.import(programName); std::map*> ASTs = importer.getASTMap(); - //Do optomization, etc. here. + //Do optimization, etc. here. //None at this time, instead going straight to C in this first (more naive) version //Code generation //For right now, just C CGenerator().generateCompSet(ASTs, outputName); - /* - std::string c_code = CGenerator().generate(AST); - outFileC << c_code << std::endl; - outFileC.close(); -*/ return(0); } diff --git a/src/ASTTransformation.cpp b/src/ASTTransformation.cpp index eca685e..a97d7dc 100644 --- a/src/ASTTransformation.cpp +++ b/src/ASTTransformation.cpp @@ -70,11 +70,7 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree if (newNode == NULL) { std::cout << "scope lookup error! Could not find " << lookupName << " in identifier " << std::endl; throw "LOOKUP ERROR: " + lookupName; - } else if (newNode->getDataRef()->symbol.getName() !=lookupName) { - //This happens when the lookup name denotes a member of an object, i.e. obj.foo - //The newNode points to obj, not foo. } - //newNode = new NodeTree(name, ASTData(identifier, Symbol(concatSymbolTree(children[0]), true))); } else if (name == "type_def") { //If it is an alisis of a type std::string typeAlias; @@ -93,8 +89,6 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree //So we give this typedef its name without any template types and make its type template_type, and point to this from node. //Then, when this template is instantiated, it will run transform on from with the types filled in. objectType = new Type(template_type, from); - // skipChildren.insert(0); //Don't try to transform the template - // skipChildren.insert(1); //Identifier lookup will be ourselves, as we just added ourselves to the scope } else { typeAlias = concatSymbolTree(children[0]); newNode = new NodeTree(name, ASTData(type_def, Symbol(typeAlias, true, typeAlias))); @@ -110,7 +104,6 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree if (children[0]->getData().getName() == "template_dec") return newNode; scope = newNode; - //return newNode; } else if (name == "function") { std::string functionName; //If this is a function template @@ -451,9 +444,9 @@ NodeTree* ASTTransformation::doFunction(NodeTree* scope, std:: if ((nodes.size() != 2 && lookup == "*") || lookup == "&" || lookup == "[]") { Type* newType = oldTypes[0].clone(); if (lookup == "*" || lookup == "[]") - newType->increaseIndirection(); - else newType->decreaseIndirection(); + else + newType->increaseIndirection(); newNode->getDataRef()->valueType = newType, std::cout << "Operator " + lookup << " is altering indirection "<< std::endl; } else {