MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / sv_simulateLetInit

Method sv_simulateLetInit

src/ast/ast_simulate.cpp:3365–3441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3363 }
3364
3365 SimNode * SimulateVisitor::sv_simulateLetInit(const VariablePtr & var, bool local) {
3366 gc_guard _guard;
3367 SimNode * get;
3368 if ( local ) {
3369 if ( var->init && var->init->rtti_isMakeLocal() ) {
3370 return getE(var->init);
3371 } else {
3372 get = context.code->makeNode<SimNode_GetLocal>(var->init->at, var->stackTop);
3373 }
3374 } else {
3375 if ( var->init && var->init->rtti_isMakeLocal() ) {
3376 return getE(var->init);
3377 } else {
3378 if ( !var->module->isSolidContext ) {
3379 if ( var->global_shared ) {
3380 get = context.code->makeNode<SimNode_GetSharedMnh>(var->init->at, var->index, var->getMangledNameHash());
3381 } else {
3382 get = context.code->makeNode<SimNode_GetGlobalMnh>(var->init->at, var->index, var->getMangledNameHash());
3383 }
3384 } else {
3385 if ( var->global_shared ) {
3386 get = context.code->makeNode<SimNode_GetShared>(var->init->at, var->index, var->getMangledNameHash());
3387 } else {
3388 get = context.code->makeNode<SimNode_GetGlobal>(var->init->at, var->index, var->getMangledNameHash());
3389 }
3390 }
3391 }
3392 }
3393 if ( var->type->ref ) {
3394 return context.code->makeNode<SimNode_CopyReference>(var->init->at, get,
3395 getE(var->init));
3396 } else if ( var->init_via_move && (var->type->canMove() || var->type->isGoodBlockType()) ) {
3397 auto varExpr = new ExprVar(var->at, var->name);
3398 varExpr->variable = var;
3399 varExpr->local = local;
3400 varExpr->type = new TypeDecl(*var->type);
3401 simulateExpression(varExpr);
3402 auto retN = sv_makeMove(var->init->at, varExpr, var->init);
3403 if ( !retN ) {
3404 context.thisProgram->error("internal compilation error, can't generate move", "", "", var->at, CompilationError::internal_expression);
3405 }
3406 return retN;
3407 } else if ( !var->init_via_move && (var->type->canCopy() || var->type->isGoodBlockType()) ) {
3408 auto varExpr = new ExprVar(var->at, var->name);
3409 varExpr->variable = var;
3410 varExpr->local = local;
3411 varExpr->type = new TypeDecl(*var->type);
3412 simulateExpression(varExpr);
3413 auto retN = sv_makeCopy(var->init->at, varExpr, var->init);
3414 if ( !retN ) {
3415 context.thisProgram->error("internal compilation error, can't generate copy", "", "", var->at, CompilationError::internal_expression);
3416 }
3417 return retN;
3418 } else if ( var->isCtorInitialized() ) {
3419 auto varExpr = new ExprVar(var->at, var->name);
3420 varExpr->variable = var;
3421 varExpr->local = local;
3422 varExpr->type = new TypeDecl(*var->type);

Callers 1

simulateLetInitFunction · 0.80

Calls 8

simulateExpressionFunction · 0.85
getCallBaseFunction · 0.85
isGoodBlockTypeMethod · 0.80
isCtorInitializedMethod · 0.80
getMangledNameHashMethod · 0.45
canMoveMethod · 0.45
errorMethod · 0.45
canCopyMethod · 0.45

Tested by

no test coverage detected