diff --git a/include/daScript/ast/ast.h b/include/daScript/ast/ast.h index aec61c7a9..3532cbf2b 100644 --- a/include/daScript/ast/ast.h +++ b/include/daScript/ast/ast.h @@ -1185,11 +1185,17 @@ namespace das bool addModule ( Module * module ); void foreach ( const callable & func, const string & name ) const; void foreach_in_order ( const callable & func, Module * thisM ) const; + + void findWithCallback ( const string & name, Module * inWhichModule, const callable & func ) const; + void findAlias ( vector & ptr, Module * pm, const string & aliasName, Module * inWhichModule ) const; vector findAlias ( const string & name, Module * inWhichModule ) const; + void findAnnotation ( vector & ptr, Module * pm, const string & annotationName, Module * inWhichModule ) const; vector findAnnotation ( const string & name, Module * inWhichModule ) const; vector findStaticAnnotation ( const string & name ) const; vector findTypeInfoMacro ( const string & name, Module * inWhichModule ) const; + void findEnum ( vector & ptr, Module * pm, const string & enumName, Module * inWhichModule ) const; vector findEnum ( const string & name, Module * inWhichModule ) const; + void findStructure ( vector & ptr, Module * pm, const string & funcName, Module * inWhichModule ) const; vector findStructure ( const string & name, Module * inWhichModule ) const; Module * findModule ( const string & name ) const; TypeDeclPtr makeStructureType ( const string & name ) const; diff --git a/include/daScript/ast/ast_handle.h b/include/daScript/ast/ast_handle.h index cabe5c4b0..9f03edbb7 100644 --- a/include/daScript/ast/ast_handle.h +++ b/include/daScript/ast/ast_handle.h @@ -98,7 +98,7 @@ namespace das virtual void aotVisitGetField(TextWriter & ss, const string & fieldName) override; virtual void aotVisitGetFieldPtr(TextWriter & ss, const string & fieldName) override; virtual bool canSubstitute(TypeAnnotation * ann) const override; - StructureField & addFieldEx(const string & na, const string & cppNa, off_t offset, TypeDeclPtr pT); + StructureField & addFieldEx(const string & na, const string & cppNa, off_t offset, const TypeDeclPtr & pT); virtual void walk(DataWalker & walker, void * data) override; void updateTypeInfo() const; int32_t fieldCount() const { return int32_t(fields.size()); } diff --git a/include/daScript/ast/ast_typedecl.h b/include/daScript/ast/ast_typedecl.h index c48b43e54..1712890cf 100644 --- a/include/daScript/ast/ast_typedecl.h +++ b/include/daScript/ast/ast_typedecl.h @@ -630,7 +630,7 @@ namespace das { bool isCircularType ( const TypeDeclPtr & type ); bool hasImplicit ( const TypeDeclPtr & type ); - bool isMatchingArgumentType (TypeDeclPtr argType, TypeDeclPtr passType); + bool isMatchingArgumentType ( const TypeDeclPtr & argType, const TypeDeclPtr & passType ); enum class CpptSubstitureRef { no, yes }; enum class CpptSkipRef { no, yes }; diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 67e0c1fd0..1f9c6793b 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -2740,10 +2740,18 @@ namespace das { } TypeDecl * Program::makeTypeDeclaration(const LineInfo &at, const string &name) { - auto structs = library.findStructure(name,thisModule.get()); - auto handles = library.findAnnotation(name,thisModule.get()); - auto enums = library.findEnum(name,thisModule.get()); - auto aliases = library.findAlias(name,thisModule.get()); + + das::vector structs; + das::vector handles; + das::vector enums; + das::vector aliases; + library.findWithCallback(name, thisModule.get(), [&](Module * pm, const string &name, Module * inWhichModule) { + library.findStructure(structs, pm, name, inWhichModule); + library.findAnnotation(handles, pm, name, inWhichModule); + library.findEnum(enums, pm, name, inWhichModule); + library.findAlias(aliases, pm, name, inWhichModule); + }); + if ( ((structs.size()!=0)+(handles.size()!=0)+(enums.size()!=0)+(aliases.size()!=0)) > 1 ) { string candidates = describeCandidates(structs); candidates += describeCandidates(handles, false); diff --git a/src/ast/ast_handle.cpp b/src/ast/ast_handle.cpp index 0203a2967..d96ea1005 100644 --- a/src/ast/ast_handle.cpp +++ b/src/ast/ast_handle.cpp @@ -125,7 +125,7 @@ namespace das { } } - BasicStructureAnnotation::StructureField & BasicStructureAnnotation::addFieldEx ( const string & na, const string & cppNa, off_t offset, TypeDeclPtr pT ) { + BasicStructureAnnotation::StructureField & BasicStructureAnnotation::addFieldEx ( const string & na, const string & cppNa, off_t offset, const TypeDeclPtr & pT ) { auto & field = fields[na]; if ( field.decl ) { DAS_FATAL_ERROR("structure field %s already exist in structure %s\n", na.c_str(), name.c_str() ); diff --git a/src/ast/ast_module.cpp b/src/ast/ast_module.cpp index 47db8204b..a39efb078 100644 --- a/src/ast/ast_module.cpp +++ b/src/ast/ast_module.cpp @@ -759,38 +759,57 @@ namespace das { return it!=modules.end() ? *it : nullptr; } + void ModuleLibrary::findWithCallback ( const string & name, Module * inWhichModule, const callable & func ) const { + string moduleName, funcName; + splitTypeName(name, moduleName, funcName); + foreach([&](Module * pm) -> bool { + if ( !inWhichModule || inWhichModule->isVisibleDirectly(pm) ) { + func(pm, funcName, inWhichModule); + } + return true; + }, moduleName); + } + + void ModuleLibrary::findAlias ( vector & ptr, Module * pm, const string & aliasName, Module * inWhichModule ) const { + if ( auto pp = pm->findAlias(aliasName) ) { + if ( pp->isEnumT() ) { + if ( !pp->enumType->isPrivate || pp->enumType->module==inWhichModule ) { + ptr.push_back(das::move(pp)); + } + } else if ( pp->baseType==Type::tStructure ) { + if ( !pp->structType->privateStructure || pp->structType->module==inWhichModule ) { + ptr.push_back(das::move(pp)); + } + } else { + ptr.push_back(das::move(pp)); + } + } + } + vector ModuleLibrary::findAlias ( const string & name, Module * inWhichModule ) const { vector ptr; string moduleName, aliasName; splitTypeName(name, moduleName, aliasName); foreach([&](Module * pm) -> bool { if ( !inWhichModule || inWhichModule->isVisibleDirectly(pm) ) - if ( auto pp = pm->findAlias(aliasName) ) { - if ( pp->isEnumT() ) { - if ( !pp->enumType->isPrivate || pp->enumType->module==inWhichModule ) { - ptr.push_back(pp); - } - } else if ( pp->baseType==Type::tStructure ) { - if ( !pp->structType->privateStructure || pp->structType->module==inWhichModule ) { - ptr.push_back(pp); - } - } else { - ptr.push_back(pp); - } - } + findAlias(ptr, pm, aliasName, inWhichModule); return true; }, moduleName); return ptr; } + void ModuleLibrary::findAnnotation ( vector & ptr, Module * pm, const string & annotationName, Module * ) const { + if ( auto pp = pm->findAnnotation(annotationName) ) + ptr.push_back(das::move(pp)); + } + vector ModuleLibrary::findAnnotation ( const string & name, Module * inWhichModule ) const { vector ptr; string moduleName, annName; splitTypeName(name, moduleName, annName); foreach([&](Module * pm) -> bool { if ( !inWhichModule || inWhichModule->isVisibleDirectly(pm) ) - if ( auto pp = pm->findAnnotation(annName) ) - ptr.push_back(pp); + findAnnotation(ptr, pm, annName, inWhichModule); return true; }, moduleName); return ptr; @@ -809,34 +828,42 @@ namespace das { return ptr; } + void ModuleLibrary::findStructure ( vector & ptr, Module * pm, const string & structName, Module * inWhichModule ) const { + if ( auto pp = pm->findStructure(structName) ) { + if ( !pp->privateStructure || pp->module==inWhichModule ) { + ptr.push_back(das::move(pp)); + } + } + } + vector ModuleLibrary::findStructure ( const string & name, Module * inWhichModule ) const { vector ptr; string moduleName, funcName; splitTypeName(name, moduleName, funcName); foreach([&](Module * pm) -> bool { if ( !inWhichModule || inWhichModule->isVisibleDirectly(pm) ) { - if ( auto pp = pm->findStructure(funcName) ) { - if ( !pp->privateStructure || pp->module==inWhichModule ) { - ptr.push_back(pp); - } - } + findStructure(ptr, pm, funcName, inWhichModule); } return true; }, moduleName); return ptr; } + void ModuleLibrary::findEnum ( vector & ptr, Module * pm, const string & enumName, Module * inWhichModule ) const { + if ( auto pp = pm->findEnum(enumName) ) { + if ( !pp->isPrivate || pp->module==inWhichModule ) { + ptr.push_back(das::move(pp)); + } + } + } + vector ModuleLibrary::findEnum ( const string & name, Module * inWhichModule ) const { vector ptr; string moduleName, enumName; splitTypeName(name, moduleName, enumName); foreach([&](Module * pm) -> bool { if ( !inWhichModule || inWhichModule->isVisibleDirectly(pm) ) { - if ( auto pp = pm->findEnum(enumName) ) { - if ( !pp->isPrivate || pp->module==inWhichModule ) { - ptr.push_back(pp); - } - } + findEnum(ptr, pm, enumName, inWhichModule); } return true; }, moduleName); diff --git a/src/ast/ast_typedecl.cpp b/src/ast/ast_typedecl.cpp index 1ea98ad6f..534f72d76 100644 --- a/src/ast/ast_typedecl.cpp +++ b/src/ast/ast_typedecl.cpp @@ -3136,7 +3136,7 @@ namespace das return false; } - bool isMatchingArgumentType (TypeDeclPtr argType, TypeDeclPtr passType) { + bool isMatchingArgumentType ( const TypeDeclPtr & argType, const TypeDeclPtr & passType ) { if (!passType) { return false; }