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

Method replaceFunction

src/ast/ast_module.cpp:635–663  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

633 }
634
635 bool Module::replaceFunction ( const FunctionPtr & fn ) {
636 fn->module = this;
637 auto mangledName = fn->getMangledName();
638 auto mangledHash = hash64z(mangledName.c_str());
639 auto nameHashX = hash64z(fn->name.c_str());
640 // get old function pointer before replacing (avoid touching stale types)
641 auto oldFn = functions.find(mangledHash);
642 if ( !oldFn ) return false;
643 auto oldFnPtr = oldFn;
644 // replace in safebox objects map
645 functions.replace(mangledHash, fn);
646 // replace in objectsInOrder (compare by pointer, not by mangled name)
647 functions.foreach([&](auto & ofn){
648 if ( ofn == oldFnPtr ) {
649 ofn = fn;
650 }
651 });
652 // replace in functionsByName
653 auto kv = functionsByName.find(nameHashX);
654 if ( kv ) {
655 for ( auto & fp : kv->second ) {
656 if ( fp == oldFnPtr ) {
657 fp = fn;
658 break;
659 }
660 }
661 }
662 return true;
663 }
664
665 bool Module::addGeneric ( const FunctionPtr & fn, bool canFail ) {
666 fn->module = this;

Callers 1

applyMethod · 0.80

Calls 6

hash64zFunction · 0.85
replaceMethod · 0.80
getMangledNameMethod · 0.45
c_strMethod · 0.45
findMethod · 0.45
foreachMethod · 0.45

Tested by

no test coverage detected