fix reference type inference

This commit is contained in:
Nathan Braswell
2015-07-15 13:56:57 -04:00
parent 06f36f2a87
commit 51adf491fa
8 changed files with 65 additions and 30 deletions

View File

@@ -709,7 +709,8 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
// for type inferencing
if (!identifierType) {
if (toAssign) {
identifierType = toAssign->getDataRef()->valueType;
// no reference variables
identifierType = toAssign->getDataRef()->valueType->withoutReference();
newIdentifier->getDataRef()->valueType = identifierType;
} else
throw "have to inference but no expression";

View File

@@ -568,7 +568,7 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
output.value += ValueTypeToCType(children[0]->getData().valueType, assignedTo) + ";\n";
// we put the thing about to be copy constructed in a variable so we can for sure take its address
std::string toAssignTemp = "copy_construct_param" + getID();
output.value += ValueTypeToCType(children[1]->getData().valueType, toAssignTemp) + " = " + toAssign.value + ";\n";
output.value += ValueTypeToCType(children[1]->getData().valueType->withoutReference(), toAssignTemp) + " = " + toAssign.value + ";\n";
output.value += generateMethodIfExists(children[0]->getDataRef()->valueType, "copy_construct", "&" + assignedTo + ", &" + toAssignTemp, std::vector<Type>{children[1]->getDataRef()->valueType->withIncreasedIndirection()}) + ";\n" + output.postValue;
output.value += toAssign.postValue;