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

Method hasUserConstructor

src/ast/ast.cpp:299–314  ·  view source on GitHub ↗

True if this structure has any non-generated ctor method (Klass`Klass). Ctor methods always live in the same module as the class (parser registers them together), so we look up by name hash via functionsByName / genericsByName. The `classParent == this` identity check defends against same-named classes in other modules bleeding in through generic instantiation.

Source from the content-addressed store, hash-verified

297 // The `classParent == this` identity check defends against same-named classes
298 // in other modules bleeding in through generic instantiation.
299 bool Structure::hasUserConstructor() const {
300 if ( !module ) return false;
301 string ctorName = name + "`" + name;
302 uint64_t hName = hash64z(ctorName.c_str());
303 if ( auto kv = module->functionsByName.find(hName) ) {
304 for ( auto * fn : kv->second ) {
305 if ( !fn->generated && fn->classParent == this ) return true;
306 }
307 }
308 if ( auto kv = module->genericsByName.find(hName) ) {
309 for ( auto * fn : kv->second ) {
310 if ( !fn->generated && fn->classParent == this ) return true;
311 }
312 }
313 return false;
314 }
315
316 // True if this structure has a non-generated 0-arg-callable ctor (no args, or
317 // all args default-initialized). Used by the synth-derived-ctor gate to verify

Callers 3

visitMethod · 0.80
findChainCtorAncestorFunction · 0.80
makeConstructorFunction · 0.80

Calls 3

hash64zFunction · 0.85
c_strMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected