compiler/resolution/preFold.cpp
//
// determine field associated with query expression
//
determine field associated with query expression
determine field associated with query expression
static Symbol* determineQueriedField(CallExpr* call) {
  AggregateType* at     =
    toAggregateType(canonicalClassType(call->get(1)->getValType()));
  SymExpr*       last   = toSymExpr(call->get(call->numActuals()));
  VarSymbol*     var    = toVarSymbol(last->symbol());
  Symbol*        retval = NULL;
  if (var->immediate->const_kind == CONST_KIND_STRING) {
    retval = at->getField(var->immediate->v_string, false);
  } else {
    Vec<ArgSymbol*> args;
    int             position      = var->immediate->int_value();
    FnSymbol*       typeConstruct = at->typeConstructor;
    AggregateType*  source        = at->instantiatedFrom;
    while (typeConstruct == NULL) {
      typeConstruct = source->typeConstructor;
      source        = source->instantiatedFrom;
    }
    for_formals(arg, typeConstruct) {
      args.add(arg);
    }
    for (int i = 2; i < call->numActuals(); i++) {
      SymExpr*   actual = toSymExpr(call->get(i));
      VarSymbol* var    = toVarSymbol(actual->symbol());
      INT_ASSERT(var->immediate->const_kind == CONST_KIND_STRING);
      for (int j = 0; j < args.n; j++) {
        if (args.v[j]                                         != NULL &&
            strcmp(args.v[j]->name, var->immediate->v_string) ==    0) {
          args.v[j] = NULL;
        }
      }
    }
    forv_Vec(ArgSymbol, arg, args) {
      if (arg != NULL) {
        if (position == 1) {
          retval = at->getField(arg->name, false);
          break;
        } else {
          position--;
        }
      }
    }
  }
  return retval;
}
static Symbol * determineQueriedField ( CallExpr * call ) { AggregateType * at = toAggregateType ( canonicalClassType ( call -> get ( 1 ) -> getValType ( ) ) ) ; SymExpr * last = toSymExpr ( call -> get ( call -> numActuals ( ) ) ) ; VarSymbol * var = toVarSymbol ( last -> symbol ( ) ) ; Symbol * retval = NULL ; if ( var -> immediate -> const_kind == CONST_KIND_STRING ) { retval = at -> getField ( var -> immediate -> v_string , false ) ; } else { Vec < ArgSymbol * > args ; int position = var -> immediate -> int_value ( ) ; FnSymbol * typeConstruct = at -> typeConstructor ; AggregateType * source = at -> instantiatedFrom ; while ( typeConstruct == NULL ) { typeConstruct = source -> typeConstructor ; source = source -> instantiatedFrom ; } for_formals ( arg , typeConstruct ) { args . add ( arg ) ; } for ( int i = 2 ; i < call -> numActuals ( ) ; i ++ ) { SymExpr * actual = toSymExpr ( call -> get ( i ) ) ; VarSymbol * var = toVarSymbol ( actual -> symbol ( ) ) ; INT_ASSERT ( var -> immediate -> const_kind == CONST_KIND_STRING ) ; for ( int j = 0 ; j < args . n ; j ++ ) { if ( args . v [ j ] != NULL && strcmp ( args . v [ j ] -> name , var -> immediate -> v_string ) == 0 ) { args . v [ j ] = NULL ; } } } forv_Vec ( ArgSymbol , arg , args ) { if ( arg != NULL ) { if ( position == 1 ) { retval = at -> getField ( arg -> name , false ) ; break ; } else { position -- ; } } } } return retval ; }
determine field associated with query expression
determine field associated with query expression