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

Function generatePointerFinalizer

src/ast/ast_generate.cpp:447–524  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

445 }
446
447 FunctionPtr generatePointerFinalizer ( const TypeDeclPtr & ptrType, const LineInfo & at ) {
448 auto pFunc = new Function();
449 pFunc->privateFunction = true;
450 pFunc->generated = true;
451 pFunc->at = pFunc->atDecl = at;
452 pFunc->name = "finalize";
453 auto THIS0 = new ExprVar(at, "__this");
454 auto NULLP0 = new ExprConstPtr(at);
455 auto NEQ = new ExprOp2(at, "!=", THIS0, NULLP0);
456 auto ifb = new ExprBlock();
457 ifb->at = at;
458 if ( ptrType->firstType && ptrType->firstType->isClass() ) {
459 if ( ptrType->firstType->structType->macroInterface ) pFunc->macroFunction = true;
460 auto sizvar = new ExprLet(); // let __size = class_rtti_size(__this)
461 sizvar->at = at;
462 auto vsiz = new Variable();
463 vsiz->at = at;
464 vsiz->name = "__size";
465 vsiz->type = new TypeDecl(Type::autoinfer);
466 vsiz->type->constant = true;
467 auto crs = new ExprCall(at,"class_rtti_size");
468 crs->arguments.push_back(new ExprVar(at,"__this"));
469 vsiz->init = crs;
470 //vsiz->init = make_sm
471 sizvar->variables.push_back(vsiz);
472 ifb->list.push_back(sizvar);
473 auto invk = new ExprInvoke(at, "invoke"); // invoke(__this,__this.__finalize)
474 auto THISA = new ExprVar(at, "__this");
475 auto pAt = new ExprField(at, THISA, "__finalize");
476 invk->arguments.push_back(pAt);
477 auto pCast = new ExprCast();
478 pCast->at = at;
479 pCast->castType = new TypeDecl(Type::autoinfer);
480 auto THISAA = new ExprVar(at, "__this");
481 pCast->subexpr = new ExprPtr2Ref(at,THISAA);
482 pCast->subexpr->alwaysSafe = true;
483 invk->arguments.push_back(pCast);
484 ifb->list.push_back(invk);
485 auto THISA1 = new ExprVar(at, "__this"); // delete /*native*/ this, __size
486 auto delit1 = new ExprDelete(at, THISA1);
487 delit1->native = true;
488 delit1->sizeexpr = new ExprVar(at,"__size");
489 ifb->list.push_back(delit1);
490
491 } else {
492 auto THISA = new ExprVar(at, "__this"); // delete * this
493 auto THISR = new ExprPtr2Ref(at, THISA);
494 auto delit = new ExprDelete(at, THISR);
495 ifb->list.push_back(delit);
496 auto THISA1 = new ExprVar(at, "__this"); // delete /*native*/ this
497 auto delit1 = new ExprDelete(at, THISA1);
498 delit1->native = true;
499 ifb->list.push_back(delit1);
500 }
501 auto THISB = new ExprVar(at, "__this"); // *THIS = null
502 auto NULLP = new ExprConstPtr(at);
503 auto SETB = new ExprCopy(at, THISB, NULLP);
504 ifb->list.push_back(SETB);

Callers 1

visitMethod · 0.85

Calls 4

wrapInUnsafeFunction · 0.85
verifyGeneratedFunction · 0.85
isClassMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected