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

Function makeClone

src/ast/ast_generate.cpp:402–436  ·  view source on GitHub ↗

def clone(a,b:structure) a.f1 := b.f1 a.f2 := b.f2 ...

Source from the content-addressed store, hash-verified

400 // a.f2 := b.f2
401 // ...
402 FunctionPtr makeClone ( Structure * str ) {
403 auto varA = new Variable();
404 varA->name = "a";
405 varA->type = new TypeDecl(str);
406 varA->type->isExplicit = true;
407 varA->at = str->at;
408 auto varB = new Variable();
409 varB->name = "b";
410 varB->type = new TypeDecl(str);
411 varB->type->constant = str->canCloneFromConst(); // allow to clone from const
412 varB->type->implicit = true;
413 varB->at = str->at;
414 auto fn = new Function();
415 fn->name = "clone";
416 fn->generated = true;
417 fn->safeImplicit = true;
418 fn->privateFunction = true;
419 fn->at = fn->atDecl = str->at;
420 fn->result = new TypeDecl();
421 fn->arguments.push_back(varA);
422 fn->arguments.push_back(varB);
423 auto block = new ExprBlock();
424 block->at = str->at;
425 for ( auto & fi : str->fields ) {
426 auto lA = new ExprVar(fi.at, "a");
427 auto lAdotF = new ExprField(fi.at, lA, fi.name);
428 auto lB = new ExprVar(fi.at, "b");
429 auto lBdotF = new ExprField(fi.at, lB, fi.name);
430 auto cl = new ExprClone(fi.at, lAdotF, lBdotF);
431 block->list.push_back(cl);
432 }
433 fn->body = block;
434 verifyGenerated(fn->body);
435 return fn;
436 }
437
438 void wrapInUnsafe ( const FunctionPtr & func ) {
439 auto blk = new ExprBlock();

Callers 1

visitMethod · 0.85

Calls 3

verifyGeneratedFunction · 0.85
canCloneFromConstMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected