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

Method hasUserDefaultConstructor

src/ast/ast.cpp:319–343  ·  view source on GitHub ↗

True if this structure has a non-generated 0-arg-callable ctor (no args, or all args default-initialized). Used by the synth-derived-ctor gate to verify the parent has a default constructor reachable as Parent`Parent(self).

Source from the content-addressed store, hash-verified

317 // all args default-initialized). Used by the synth-derived-ctor gate to verify
318 // the parent has a default constructor reachable as Parent`Parent(self).
319 bool Structure::hasUserDefaultConstructor() const {
320 if ( !module ) return false;
321 string ctorName = name + "`" + name;
322 uint64_t hName = hash64z(ctorName.c_str());
323 auto matches = [this]( Function * fn ) -> bool {
324 if ( fn->generated ) return false;
325 if ( fn->classParent != this ) return false;
326 // arg 0 is always 'self'; arg 1+ must be default-initialized
327 for ( size_t i=1; i<fn->arguments.size(); ++i ) {
328 if ( !fn->arguments[i]->init ) return false;
329 }
330 return true;
331 };
332 if ( auto kv = module->functionsByName.find(hName) ) {
333 for ( auto * fn : kv->second ) {
334 if ( matches(fn) ) return true;
335 }
336 }
337 if ( auto kv = module->genericsByName.find(hName) ) {
338 for ( auto * fn : kv->second ) {
339 if ( matches(fn) ) return true;
340 }
341 }
342 return false;
343 }
344
345 // True if this class has a non-generated finalizer method. Class finalizers keep
346 // the plain name "finalize" (parser: ast_structVarDef), so the registry lookup is

Callers 2

visitMethod · 0.80
makeConstructorFunction · 0.80

Calls 4

hash64zFunction · 0.85
c_strMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected