Added in basic transformation and generation for functions
This commit is contained in:
@@ -287,9 +287,8 @@ NodeTree<ASTData>* ASTTransformation::secondPassFunction(NodeTree<Symbol>* from,
|
||||
//If this is a function template
|
||||
std::vector<NodeTree<Symbol>*> children = from->getChildren();
|
||||
NodeTree<ASTData>* functionDef = NULL;
|
||||
std::string functionName;
|
||||
std::string functionName = concatSymbolTree(children[0]);
|
||||
if (children[1]->getData().getName() == "template_dec") {
|
||||
functionName = concatSymbolTree(children[0]);
|
||||
functionDef = new NodeTree<ASTData>("function", ASTData(function, Symbol(functionName, true), new Type(template_type, from)));
|
||||
addToScope("~enclosing_scope", scope, functionDef);
|
||||
addToScope(functionName, functionDef, scope);
|
||||
@@ -304,7 +303,6 @@ NodeTree<ASTData>* ASTTransformation::secondPassFunction(NodeTree<Symbol>* from,
|
||||
//std::cout << "Finished Non-Instantiated Template function " << functionName << std::endl;
|
||||
return functionDef;
|
||||
}
|
||||
functionName = concatSymbolTree(children[0]);
|
||||
auto returnTypeNode = getNode("type", getNode("typed_return", children)); // if null, the typed_return had no children and we're supposed to automatically do a void type
|
||||
auto returnType = returnTypeNode ? typeFromTypeNode(returnTypeNode, scope, templateTypeReplacements): new Type(void_type);
|
||||
if (!returnType)
|
||||
@@ -1629,7 +1627,15 @@ Type* ASTTransformation::typeFromTypeNode(NodeTree<Symbol>* typeNode, NodeTree<A
|
||||
|
||||
auto possibleMatches = scopeLookup(scope, edited);
|
||||
if (possibleMatches.size()) {
|
||||
typeDefinition = possibleMatches[0];
|
||||
// so the scope lookup can find things that aren't types. We could have an entirely differnt lookup function for them,
|
||||
// but at this point (deep in the self-hosting process) I think it's better that I just prune out the ones that aren't types
|
||||
// here
|
||||
for (auto definition : possibleMatches) {
|
||||
if (definition->getDataRef()->type == type_def || definition->getDataRef()->type == adt_def) {
|
||||
typeDefinition = definition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
traits = typeDefinition->getDataRef()->valueType->traits;
|
||||
}
|
||||
//So either this is an uninstatiated template class type, or this is literally a template type T, and we should get it from our
|
||||
|
||||
@@ -625,7 +625,9 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
||||
output.postValue += thingToMatch.postValue;
|
||||
for (auto case_stmt : slice(children, 1, -1)) {
|
||||
auto case_children = case_stmt->getChildren();
|
||||
std::string option = generate(case_children[0], enclosingObject, false, enclosingFunction).oneString();
|
||||
// was accidntally adding in prefix when it shouldn't, though maybe it should when both option and ADT name are identical, deal with this later
|
||||
//std::string option = generate(case_children[0], enclosingObject, false, enclosingFunction).oneString();
|
||||
std::string option = case_children[0]->getDataRef()->symbol.getName();
|
||||
std::string parentName = case_children[0]->getDataRef()->scope["~enclosing_scope"][0]->getDataRef()->symbol.getName();
|
||||
output += "/* case " + option + " if " + thingToMatch.value + " */\n";
|
||||
output += tabs() + "if ((" + thingToMatch.value + ").flag == " + parentName + "__" + option + ") {\n";
|
||||
|
||||
Reference in New Issue
Block a user