topLevelVarInit finally works, even with infrencing
This commit is contained in:
@@ -210,17 +210,7 @@ void ASTTransformation::secondPassDoClassInsides(NodeTree<ASTData>* typeDef, std
|
||||
|
||||
//This function may need to partially instantiate a class template
|
||||
NodeTree<ASTData>* ASTTransformation::secondPassDeclaration(NodeTree<Symbol>* from, NodeTree<ASTData>* scope, std::map<std::string, Type*> templateTypeReplacements) {
|
||||
//Check here for method call (an error here)
|
||||
NodeTree<ASTData>* decStmt = addToScope("~enclosing_scope", scope, new NodeTree<ASTData>("declaration_statement", ASTData(declaration_statement)));
|
||||
std::string newIdentifierStr = concatSymbolTree(from->getChildren()[0]);
|
||||
Type* identifierType = typeFromTypeNode(from->getChildren()[2], scope, templateTypeReplacements);
|
||||
std::cout << "Declaring an identifier " << newIdentifierStr << " to be of type " << identifierType->toString() << std::endl;
|
||||
NodeTree<ASTData>* newIdentifier = addToScope("~enclosing_scope", decStmt, new NodeTree<ASTData>("identifier", ASTData(identifier, Symbol(newIdentifierStr, true), identifierType)));
|
||||
//scope->getDataRef()->scope[newIdentifierStr].push_back(newIdentifier);
|
||||
addToScope(newIdentifierStr, newIdentifier, scope); // NEW WAY!
|
||||
decStmt->addChild(newIdentifier);
|
||||
|
||||
return decStmt;
|
||||
return transform(from, scope, std::vector<Type>(), false, templateTypeReplacements);
|
||||
}
|
||||
|
||||
//This function may need to partially instantiate a class template
|
||||
|
||||
@@ -182,9 +182,15 @@ std::pair<std::string, std::string> CGenerator::generateTranslationUnit(std::str
|
||||
ASTData declarationData = declaration->getData();
|
||||
switch(declarationData.type) {
|
||||
case identifier:
|
||||
{
|
||||
auto parent = declaration->getDataRef()->scope["~enclosing_scope"][0];
|
||||
if (parent->getChildren().size() == 1)
|
||||
variableDeclarations += ValueTypeToCType(declarationData.valueType, scopePrefix(declaration) + declarationData.symbol.getName()) + "; /*identifier*/\n";
|
||||
else
|
||||
variableDeclarations += ValueTypeToCType(declarationData.valueType, generate(parent->getChildren()[0], nullptr, true).oneString()) + " = " + generate(parent->getChildren()[1], nullptr, true).oneString() + ";";
|
||||
variableExternDeclarations += "extern " + ValueTypeToCType(declarationData.valueType, declarationData.symbol.getName()) + "; /*extern identifier*/\n";
|
||||
break;
|
||||
}
|
||||
case function:
|
||||
{
|
||||
if (declarationData.valueType->baseType == template_type)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
Qualified io!
|
||||
0
|
||||
7
|
||||
9
|
||||
11
|
||||
Qualified Container!
|
||||
Even template functions qualified!
|
||||
|
||||
Unqualified io!
|
||||
0
|
||||
8
|
||||
10
|
||||
12
|
||||
Unqualified Container!
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
42
|
||||
hi
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import io;
|
||||
|
||||
var a: int = 42;
|
||||
var b = "hi";
|
||||
|
||||
fun main(): int {
|
||||
io::println(a);
|
||||
io::println(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user