Skip to content

Commit

Permalink
PRIM_NEW as statement :- PRIM_NEW for a non-generic class
Browse files Browse the repository at this point in the history
  • Loading branch information
noakesmichael committed Mar 15, 2018
1 parent 60bb637 commit d7a0bd0
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions compiler/resolution/functionResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5859,8 +5859,6 @@ static void resolveNewHandleNonGenericInitializer(CallExpr* call) {

SymExpr* typeExpr = resolveNewFindTypeExpr(call);
AggregateType* at = toAggregateType(resolveTypeAlias(typeExpr));
VarSymbol* newTmp = newTemp("new_temp", at);
DefExpr* def = new DefExpr(newTmp);

if (isCallExpr(call->get(1)) == true) {
// Happens when the type on which we are calling new is a nested type.
Expand All @@ -5873,16 +5871,39 @@ static void resolveNewHandleNonGenericInitializer(CallExpr* call) {
}

if (at->isClass() == true) {
// Convert PRIM_NEW(...) to _new(...)
call->setUnresolvedFunction("_new");

if (isBlockStmt(call->parentExpr) == true) {
// Either
// 1) a statement that is a standalone new expr
// 2) the typeExpr/initExpr for a formal
//
// Introduce a tmp and wrap the call to _new() in a move to that tmp
//

VarSymbol* newTmp = newTemp("new_temp", at);
DefExpr* def = new DefExpr(newTmp);
CallExpr* move = NULL;

call->insertBefore(def);

} else {
call->parentExpr->insertBefore(def);
// Remove the _new() call from the tree and wrap it in a move
move = new CallExpr(PRIM_MOVE, newTmp, call->remove());

// Insert the move back in the correct position
def->insertAfter(move);

// If this is formal default then the block must end with the tmp
if (isArgSymbol(call->parentSymbol) == true) {
move->insertAfter(new SymExpr(newTmp));
}
}

} else {
VarSymbol* newTmp = newTemp("new_temp", at);
DefExpr* def = new DefExpr(newTmp);

call->setUnresolvedFunction("init");

if (isBlockStmt(call->parentExpr) == true) {
Expand Down

0 comments on commit d7a0bd0

Please sign in to comment.