compiler/resolution/wrappers.cpp
/************************************* | **************************************
*                                                                             *
* reorder the actuals to match the order of the formals                       *
*                                                                             *
************************************** | *************************************/
|
reorder the actuals to match the order of the formals


| reorder the actuals to match the order of the formals
static void reorderActuals(FnSymbol*                fn,
                           CallInfo&                info,
                           std::vector<ArgSymbol*>& actualFormals) {
  int              numArgs       = actualFormals.size();
  std::vector<int> formalsToFormals(numArgs);
  bool             needToReorder = false;
  int              i             = 0;
  for_formals(formal, fn) {
    int j = 0;
    i++;
    for_vector(ArgSymbol, af, actualFormals) {
      j++;
      if (af == formal) {
        if (i != j) {
          needToReorder = true;
        }
        formalsToFormals[i - 1] = j - 1;
      }
    }
  }
  if (needToReorder == true) {
    std::vector<Expr*>       savedActuals(numArgs);
    std::vector<Symbol*>     ciActuals(numArgs);
    std::vector<const char*> ciActualNames(numArgs);
    int                      index = 0;
    for_actuals(actual, info.call) {
      savedActuals[index++] = actual->remove();
    }
    for (int i = 0; i < numArgs; i++) {
      info.call->insertAtTail(savedActuals[formalsToFormals[i]]);
    }
    INT_ASSERT(info.actuals.n == numArgs);
    for (int i = 0; i < numArgs; i++) {
      ciActuals[i]     = info.actuals.v[i];
      ciActualNames[i] = info.actualNames.v[i];
    }
    for (int i = 0; i < numArgs; i++) {
      info.actuals.v[i]     = ciActuals[formalsToFormals[i]];
      info.actualNames.v[i] = ciActualNames[formalsToFormals[i]];
    }
  }
}
static void reorderActuals ( FnSymbol * fn , CallInfo & info , std :: vector < ArgSymbol * > & actualFormals ) { int numArgs = actualFormals . size ( ) ; std :: vector < int > formalsToFormals ( numArgs ) ; bool needToReorder = false ; int i = 0 ; for_formals ( formal , fn ) { int j = 0 ; i ++ ; for_vector ( ArgSymbol , af , actualFormals ) { j ++ ; if ( af == formal ) { if ( i != j ) { needToReorder = true ; } formalsToFormals [ i - 1 ] = j - 1 ; } } } if ( needToReorder == true ) { std :: vector < Expr * > savedActuals ( numArgs ) ; std :: vector < Symbol * > ciActuals ( numArgs ) ; std :: vector < const char * > ciActualNames ( numArgs ) ; int index = 0 ; for_actuals ( actual , info . call ) { savedActuals [ index ++ ] = actual -> remove ( ) ; } for ( int i = 0 ; i < numArgs ; i ++ ) { info . call -> insertAtTail ( savedActuals [ formalsToFormals [ i ] ] ) ; } INT_ASSERT ( info . actuals . n == numArgs ) ; for ( int i = 0 ; i < numArgs ; i ++ ) { ciActuals [ i ] = info . actuals . v [ i ] ; ciActualNames [ i ] = info . actualNames . v [ i ] ; } for ( int i = 0 ; i < numArgs ; i ++ ) { info . actuals . v [ i ] = ciActuals [ formalsToFormals [ i ] ] ; info . actualNames . v [ i ] = ciActualNames [ formalsToFormals [ i ] ] ; } } }
|
reorder the actuals to match the order of the formals
| reorder the actuals to match the order of the formals
// remove all actuals in an order // reinsert them in the desired order // reorder CallInfo data as well // ideally this would be encapsulated in within the CallInfo class