compiler/resolution/lowerIterators.cpp
//
// cleanup leader and follower iterator calls
//
// Fixes uses of formals outside of their function.
// Such formals were temporarily added (e.g. in preFold for PRIM_TO_FOLLOWER)
//
cleanup leader and follower iterator calls
Fixes uses of formals outside of their function.
Such formals were temporarily added
cleanup leader and follower iterator calls Fixes uses of formals outside of their function . Such formals were temporarily added
forv_Vec(CallExpr, call, gCallExprs) {
    if (call->parentSymbol) {
      if (FnSymbol* fn = call->resolvedFunction()) {
        if (fn->retType->symbol->hasFlag(FLAG_ITERATOR_RECORD) ||
            (isDefExpr(fn->formals.tail) &&
             !strcmp(toDefExpr(fn->formals.tail)->sym->name, "_retArg") &&
             toDefExpr(fn->formals.tail)->sym->getValType() &&
             toDefExpr(fn->formals.tail)->sym->getValType()->symbol->hasFlag(FLAG_ITERATOR_RECORD))) {
          if (!strcmp(call->parentSymbol->name, "_toLeader") ||
              !strcmp(call->parentSymbol->name, "_toFollower") ||
              !strcmp(call->parentSymbol->name, "_toFastFollower") ||
              !strcmp(call->parentSymbol->name, "_toStandalone")) {
            ArgSymbol* iterator = toFnSymbol(call->parentSymbol)->getFormal(1);
            Type* iteratorType = iterator->getValType();
            int i = 2; 
            for_actuals(actual, call) {
              SymExpr* se = toSymExpr(actual);
              if (isArgSymbol(se->symbol()) &&
                  call->parentSymbol != se->symbol()->defPoint->parentSymbol) {
                Symbol* field = toAggregateType(iteratorType)->getField(i);
                VarSymbol* tmp = NULL;
                SET_LINENO(call);
                if (field->type->refType == se->symbol()->type) {
                  tmp = newTemp(field->name, field->type->refType);
                  call->getStmtExpr()->insertBefore(new DefExpr(tmp));
                  call->getStmtExpr()->insertBefore(new CallExpr(PRIM_MOVE, tmp, new CallExpr(PRIM_GET_MEMBER, iterator, field)));
                } else {
                  tmp = newTemp(field->name, field->qualType());
                  call->getStmtExpr()->insertBefore(new DefExpr(tmp));
                  call->getStmtExpr()->insertBefore(new CallExpr(PRIM_MOVE, tmp, new CallExpr(PRIM_GET_MEMBER_VALUE, iterator, field)));
                }
                actual->replace(new SymExpr(tmp));
                i++;
              }
            }
          }
        }
      }
    }
  }
forv_Vec ( CallExpr , call , gCallExprs ) { if ( call -> parentSymbol ) { if ( FnSymbol * fn = call -> resolvedFunction ( ) ) { if ( fn -> retType -> symbol -> hasFlag ( FLAG_ITERATOR_RECORD ) || ( isDefExpr ( fn -> formals . tail ) && ! strcmp ( toDefExpr ( fn -> formals . tail ) -> sym -> name , " " ) && toDefExpr ( fn -> formals . tail ) -> sym -> getValType ( ) && toDefExpr ( fn -> formals . tail ) -> sym -> getValType ( ) -> symbol -> hasFlag ( FLAG_ITERATOR_RECORD ) ) ) { if ( ! strcmp ( call -> parentSymbol -> name , " " ) || ! strcmp ( call -> parentSymbol -> name , " " ) || ! strcmp ( call -> parentSymbol -> name , " " ) || ! strcmp ( call -> parentSymbol -> name , " " ) ) { ArgSymbol * iterator = toFnSymbol ( call -> parentSymbol ) -> getFormal ( 1 ) ; Type * iteratorType = iterator -> getValType ( ) ; int i = 2 ; for_actuals ( actual , call ) { SymExpr * se = toSymExpr ( actual ) ; if ( isArgSymbol ( se -> symbol ( ) ) && call -> parentSymbol != se -> symbol ( ) -> defPoint -> parentSymbol ) { Symbol * field = toAggregateType ( iteratorType ) -> getField ( i ) ; VarSymbol * tmp = NULL ; SET_LINENO ( call ) ; if ( field -> type -> refType == se -> symbol ( ) -> type ) { tmp = newTemp ( field -> name , field -> type -> refType ) ; call -> getStmtExpr ( ) -> insertBefore ( new DefExpr ( tmp ) ) ; call -> getStmtExpr ( ) -> insertBefore ( new CallExpr ( PRIM_MOVE , tmp , new CallExpr ( PRIM_GET_MEMBER , iterator , field ) ) ) ; } else { tmp = newTemp ( field -> name , field -> qualType ( ) ) ; call -> getStmtExpr ( ) -> insertBefore ( new DefExpr ( tmp ) ) ; call -> getStmtExpr ( ) -> insertBefore ( new CallExpr ( PRIM_MOVE , tmp , new CallExpr ( PRIM_GET_MEMBER_VALUE , iterator , field ) ) ) ; } actual -> replace ( new SymExpr ( tmp ) ) ; i ++ ; } } } } } } }
cleanup leader and follower iterator calls
Fixes uses of formals outside of their function.
cleanup leader and follower iterator calls Fixes uses of formals outside of their function .
// first field is super