static bool check_type(compile_t* c, LLVMValueRef ptr, LLVMValueRef desc, ast_t* pattern_type, LLVMBasicBlockRef next_block) { switch(ast_id(pattern_type)) { case TK_NOMINAL: // We are trying to capture the match expression as a nominal. return check_nominal(c, desc, pattern_type, next_block); case TK_TUPLETYPE: // We are trying to capture the match expression as a tuple. return check_tuple(c, ptr, desc, pattern_type, next_block); case TK_UNIONTYPE: // We are trying to capture the match expression as a union. return check_union(c, ptr, desc, pattern_type, next_block); case TK_ISECTTYPE: // We are trying to capture the match expression as an intersection. return check_isect(c, ptr, desc, pattern_type, next_block); case TK_ARROW: // We are trying to capture the match expression as a viewpoint type, so // try again with the right-hand side of the arrow. return check_type(c, ptr, desc, ast_childidx(pattern_type, 1), next_block); default: {} } assert(0); return false; }
/* pick up information(startTime, stopTime, dt) from model data to optimizer struct * author: Vitalij Ruge */ static inline void pickUpBounds(OptDataBounds * bounds, OptDataDim * dim, DATA* data){ char ** inputName; double min, max, nominal, x0; double *umin, *umax, *unom; modelica_boolean nominalWasSet; modelica_boolean * nominalWasSetInput; const int nx = dim->nx; const int nv = dim->nv; const int nu = dim->nu; const int nt = dim->nt; const int NV = dim->NV; long double tmp; int i, j; dim->inputName = (char**) malloc(nv*sizeof(char*)); bounds->vnom = malloc(nv*sizeof(double)); bounds->scalF = malloc(nv*sizeof(long double)); bounds->vmin = malloc(nv*sizeof(double)); bounds->vmax = malloc(nv*sizeof(double)); bounds->u0 = malloc(nu*sizeof(double)); nominalWasSetInput = (modelica_boolean*)malloc(nv*sizeof(modelica_boolean)); inputName = dim->inputName; umin = bounds->vmin + nx; umax = bounds->vmax + nx; unom = bounds->vnom + nx; data->callback->pickUpBoundsForInputsInOptimization(data,umin, umax, unom, nominalWasSetInput, inputName, bounds->u0, &bounds->preSim); for(i = 0; i < nx; ++i){ min = data->modelData.realVarsData[i].attribute.min; max = data->modelData.realVarsData[i].attribute.max; nominal = data->modelData.realVarsData[i].attribute.nominal; nominalWasSet = data->modelData.realVarsData[i].attribute.useNominal; x0 = data->localData[1]->realVars[i]; check_nominal(bounds, min, max, nominal, nominalWasSet, i, x0); data->modelData.realVarsData[i].attribute.nominal = bounds->vnom[i]; bounds->scalF[i] = 1.0/bounds->vnom[i]; bounds->vmin[i] = min * bounds->scalF[i]; bounds->vmax[i] = max * bounds->scalF[i]; } for(j=0; i<dim->nv; ++i,++j){ bounds->u0[j] = fmin(fmax(bounds->u0[j], umin[j]), umax[j]); check_nominal(bounds, umin[j], umax[j], unom[j], nominalWasSetInput[j], i, fabs(bounds->u0[j])); bounds->scalF[i] = 1.0 / bounds->vnom[i]; bounds->vmin[i] *= bounds->scalF[i]; bounds->vmax[i] *= bounds->scalF[i]; } free(nominalWasSetInput); bounds->Vmin = malloc(NV*sizeof(double)); bounds->Vmax = malloc(NV*sizeof(double)); for(i = 0, j = 0; i < nt ; ++i, j += nv){ memcpy(bounds->Vmin + j, bounds->vmin, nv*sizeof(double)); memcpy(bounds->Vmax + j, bounds->vmax, nv*sizeof(double)); } }