work on ast_transformation, fix adt depending on type CGenerator order bug (correctly add poset dependencies)
This commit is contained in:
@@ -30,8 +30,6 @@ std::string ASTData::ASTTypeToString(ASTType type) {
|
||||
switch (type) {
|
||||
case translation_unit:
|
||||
return "translation_unit";
|
||||
case interpreter_directive:
|
||||
return "interpreter_directive";
|
||||
case identifier:
|
||||
return "identifier";
|
||||
case import:
|
||||
|
||||
@@ -119,7 +119,7 @@ NodeTree<ASTData>* ASTTransformation::firstPass(std::string fileName, NodeTree<S
|
||||
for (NodeTree<Symbol>* i : children) {
|
||||
if (i->getDataRef()->getName() == "import") {
|
||||
auto importChildren = i->getChildren();
|
||||
std::string toImport = concatSymbolTree(importChildren[0]);
|
||||
std::string toImport = concatSymbolTree(importChildren[1]);
|
||||
auto importNode = addToScope("~enclosing_scope", translationUnit, new NodeTree<ASTData>("import", ASTData(import, Symbol(toImport, true))));
|
||||
translationUnit->addChild(importNode);
|
||||
//Do the imported file too
|
||||
@@ -130,7 +130,7 @@ NodeTree<ASTData>* ASTTransformation::firstPass(std::string fileName, NodeTree<S
|
||||
// Note that import affects scope in two ways:
|
||||
// (1) The other file's translationUnit is added to our translationUnit's scope under it's name
|
||||
// (2) The import node's scope contains the nodes indicated by the qualifiers after the import (i.e. the import a:b; or import a:*;)
|
||||
for (auto importQualifer : slice(importChildren, 1, -1)) { // Not the first child, that's the name of the file
|
||||
for (auto importQualifer : slice(importChildren, 2, -1)) { // Not the first child, import, or the second that's the name of the file
|
||||
auto name = concatSymbolTree(importQualifer);
|
||||
if (name == "*") {
|
||||
std::vector<NodeTree<ASTData>*> tmp;
|
||||
@@ -823,6 +823,7 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
|
||||
} else if (name == "simple_passthrough") {
|
||||
newNode = new NodeTree<ASTData>(name, ASTData(simple_passthrough));
|
||||
addToScope("~enclosing_scope", scope, newNode);
|
||||
skipChildren.insert(0); //Don't do the identifier. The identifier lookup will fail. That's why we do it here.
|
||||
} else if (name == "passthrough_params") {
|
||||
newNode = new NodeTree<ASTData>(name, ASTData(passthrough_params));
|
||||
addToScope("~enclosing_scope", scope, newNode);
|
||||
|
||||
@@ -64,7 +64,7 @@ std::string CGenerator::generateTypeStruct(NodeTree<ASTData>* from) {
|
||||
structString = "struct __struct_dummy_";
|
||||
structString += prefixIfNeeded(scopePrefix(from), CifyName(data.symbol.getName())+"__") + " {\n";
|
||||
if (data.type == adt_def) {
|
||||
structString = "typedef " + structString + " enum " + enumName + " flag;\n union { \n";
|
||||
structString = structString + " enum " + enumName + " flag;\n union { \n";
|
||||
tabLevel++;
|
||||
}
|
||||
tabLevel++;
|
||||
@@ -87,7 +87,7 @@ std::string CGenerator::generateTypeStruct(NodeTree<ASTData>* from) {
|
||||
if (data.type == adt_def) {
|
||||
//structString += "} data; /*end union*/ \n";
|
||||
tabLevel--;
|
||||
structString += " }; /*end union*/\n} " + CifyName(data.symbol.getName()) + "; /* end struct */";
|
||||
structString += " }; /*end union*/\n};";
|
||||
} else {
|
||||
structString += "};";
|
||||
}
|
||||
@@ -204,8 +204,17 @@ std::pair<std::string, std::string> CGenerator::generateTranslationUnit(std::str
|
||||
}
|
||||
}
|
||||
} else if (children[i]->getDataRef()->type == adt_def) {
|
||||
//
|
||||
typedefPoset.addVertex(children[i]); // We add this definition by itself just in case there are no dependencies.
|
||||
std::vector<NodeTree<ASTData>*> adtChildren = children[i]->getChildren();
|
||||
for (auto j : adtChildren) {
|
||||
if (j->getDataRef()->type == identifier) {
|
||||
Type* decType = j->getDataRef()->valueType; // Type of the declaration
|
||||
if (decType->typeDefinition == children[i])
|
||||
continue;
|
||||
if (decType->typeDefinition && decType->getIndirection() == 0) // If this is a custom type and not a pointer
|
||||
typedefPoset.addRelationship(children[i], decType->typeDefinition); // Add a dependency
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -298,6 +307,9 @@ std::pair<std::string, std::string> CGenerator::generateTranslationUnit(std::str
|
||||
break;
|
||||
case adt_def:
|
||||
{
|
||||
plainTypedefs += "typedef struct __struct_dummy_" +
|
||||
prefixIfNeeded(scopePrefix(declaration), CifyName(declarationData.symbol.getName()) + "__") + " " +
|
||||
prefixIfNeeded(scopePrefix(declaration), CifyName(declarationData.symbol.getName())) + ";\n";
|
||||
for (auto child : decChildren) {
|
||||
if (child->getName() == "function") {
|
||||
std::string orig_fun_name = child->getDataRef()->symbol.getName();
|
||||
@@ -452,9 +464,6 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
||||
throw "That's not gonna work";
|
||||
}
|
||||
break;
|
||||
case interpreter_directive:
|
||||
//Do nothing
|
||||
break;
|
||||
case import:
|
||||
return CCodeTriple("/* never reached import? */\n");
|
||||
case identifier:
|
||||
|
||||
@@ -33,12 +33,11 @@ Importer::Importer(Parser* parserIn, std::vector<std::string> includePaths, std:
|
||||
removeSymbols.push_back(Symbol("}", true));
|
||||
removeSymbols.push_back(Symbol("(", true));
|
||||
removeSymbols.push_back(Symbol(")", true));
|
||||
removeSymbols.push_back(Symbol("import", true));
|
||||
removeSymbols.push_back(Symbol("interpreter_directive", false));
|
||||
//removeSymbols.push_back(Symbol("import", true));
|
||||
removeSymbols.push_back(Symbol("if", true));
|
||||
removeSymbols.push_back(Symbol("while", true));
|
||||
removeSymbols.push_back(Symbol("__if_comp__", true));
|
||||
removeSymbols.push_back(Symbol("simple_passthrough", true));
|
||||
//removeSymbols.push_back(Symbol("simple_passthrough", true));
|
||||
removeSymbols.push_back(Symbol("comp_simple_passthrough", true));
|
||||
removeSymbols.push_back(Symbol("def_nonterm", false));
|
||||
removeSymbols.push_back(Symbol("obj_nonterm", false));
|
||||
|
||||
Reference in New Issue
Block a user