diff --git a/src/sw/builder/file_storage.cpp b/src/sw/builder/file_storage.cpp index b4b18be19..030d873cf 100644 --- a/src/sw/builder/file_storage.cpp +++ b/src/sw/builder/file_storage.cpp @@ -46,7 +46,7 @@ FileStorage::FileStorage(const SwContext &swctx, const String &config) { //if (config.empty()) //throw SW_RUNTIME_ERROR("Empty config"); - //load(); + load(); } FileStorage::file_holder *FileStorage::getFileLog() diff --git a/src/sw/driver/compiler.cpp b/src/sw/driver/compiler.cpp index 4eb619387..04e36e4cb 100644 --- a/src/sw/driver/compiler.cpp +++ b/src/sw/driver/compiler.cpp @@ -1139,7 +1139,7 @@ void VisualStudioCompiler::prepareCommand1(const TargetBase &t) //cmd->out.capture = true; getCommandLineOptions(cmd.get(), *this); - iterate([this](auto &v, auto &gs) { v.addEverything(*cmd); }); + addEverything(*cmd); if (PreprocessToFile) { @@ -1189,7 +1189,7 @@ void VisualStudioASMCompiler::prepareCommand1(const TargetBase &t) //cmd->base = clone(); // defs and idirs for asm must go before file - iterate([this](auto &v, auto &gs) { v.addEverything(*cmd); }); + addEverything(*cmd); getCommandLineOptions(cmd.get(), *this); } @@ -1236,7 +1236,7 @@ void ClangCompiler::prepareCommand1(const TargetBase &t) CPPStandard.skip = true; getCommandLineOptions(cmd.get(), *this); - iterate([this](auto &v, auto &gs) { v.addEverything(*this->cmd); }); + addEverything(*this->cmd); getCommandLineOptions(cmd.get(), *this, "", true); } @@ -1297,7 +1297,7 @@ void ClangClCompiler::prepareCommand1(const TargetBase &t) getCommandLineOptions(cmd.get(), *this); getCommandLineOptions(cmd.get(), *this/*, "-Xclang"*/); - iterate([this](auto &v, auto &gs) { v.addEverything(*cmd); }); + addEverything(*cmd); } void ClangClCompiler::setOutputFile(const path &output_file) @@ -1341,7 +1341,7 @@ void GNUASMCompiler::prepareCommand1(const TargetBase &t) getCommandLineOptions(cmd.get(), *this); if (!InputFile && !assembly) - iterate([this](auto & v, auto & gs) { v.addEverything(*cmd); }); + addEverything(*cmd); } SW_DEFINE_PROGRAM_CLONE(GNUASMCompiler) @@ -1394,7 +1394,7 @@ void GNUCompiler::prepareCommand1(const TargetBase &t) CPPStandard.skip = true; getCommandLineOptions(cmd.get(), *this); - iterate([this](auto &v, auto &gs) { v.addEverything(*this->cmd); }); + addEverything(*this->cmd); getCommandLineOptions(cmd.get(), *this, "", true); } @@ -1419,36 +1419,34 @@ void GNUCompiler::setSourceFile(const path &input_file, path &output_file) FilesOrdered NativeLinker::gatherLinkDirectories() const { FilesOrdered dirs; - iterate([&dirs](auto &v, auto &gs) + + auto get_ldir = [&dirs](const auto &a) { - auto get_ldir = [&dirs](const auto &a) - { - for (auto &d : a) - dirs.push_back(d); - }; + for (auto &d : a) + dirs.push_back(d); + }; + + get_ldir(NativeLinkerOptions::gatherLinkDirectories()); + get_ldir(NativeLinkerOptions::System.gatherLinkDirectories()); - get_ldir(v.gatherLinkDirectories()); - get_ldir(v.System.gatherLinkDirectories()); - }); return dirs; } FilesOrdered NativeLinker::gatherLinkLibraries(bool system) const { FilesOrdered dirs; - iterate([&dirs, &system](auto &v, auto &gs) + + auto get_ldir = [&dirs](const auto &a) { - auto get_ldir = [&dirs](const auto &a) - { - for (auto &d : a) - dirs.push_back(d); - }; + for (auto &d : a) + dirs.push_back(d); + }; + + if (system) + get_ldir(NativeLinkerOptions::System.gatherLinkLibraries()); + else + get_ldir(NativeLinkerOptions::gatherLinkLibraries()); - if (system) - get_ldir(v.System.gatherLinkLibraries()); - else - get_ldir(v.gatherLinkLibraries()); - }); return dirs; } @@ -1511,7 +1509,7 @@ void VisualStudioLibraryTool::prepareCommand1(const TargetBase &t) ((VisualStudioLibraryTool*)this)->VisualStudioLibraryToolOptions::LinkDirectories() = gatherLinkDirectories(); getCommandLineOptions(cmd.get(), *this); - iterate([this](auto &v, auto &gs) { v.addEverything(*cmd); }); + addEverything(*cmd); getAdditionalOptions(cmd.get()); } @@ -1559,7 +1557,7 @@ void VisualStudioLinker::prepareCommand1(const TargetBase &t) ((VisualStudioLibraryTool*)this)->VisualStudioLibraryToolOptions::LinkDirectories() = gatherLinkDirectories(); getCommandLineOptions(cmd.get(), *this); - iterate([this](auto &v, auto &gs) { v.addEverything(*cmd); }); + addEverything(*cmd); getAdditionalOptions(cmd.get()); } @@ -1722,7 +1720,7 @@ void GNULinker::prepareCommand1(const TargetBase &t) //((GNULibraryTool*)this)->GNULibraryToolOptions::LinkDirectories() = gatherLinkDirectories(); getCommandLineOptions(cmd.get(), *this); - iterate([this](auto &v, auto &gs) { v.addEverything(*cmd); }); + addEverything(*cmd); //getAdditionalOptions(cmd.get()); } @@ -1796,7 +1794,7 @@ void GNULibrarian::prepareCommand1(const TargetBase &t) //((GNULibraryTool*)this)->GNULibraryToolOptions::LinkDirectories() = gatherLinkDirectories(); getCommandLineOptions(cmd.get(), *this); - iterate([this](auto &v, auto &gs) { v.addEverything(*cmd); }); + addEverything(*cmd); //getAdditionalOptions(cmd.get()); } diff --git a/src/sw/driver/compiler.h b/src/sw/driver/compiler.h index b18f8c72a..95e05be6b 100644 --- a/src/sw/driver/compiler.h +++ b/src/sw/driver/compiler.h @@ -117,8 +117,10 @@ struct SW_DRIVER_CPP_API NativeToolchain }; struct SDK SDK; + // also OS SDK (win sdk, macos sdk, linux headers etc.) + //std::optional os sdk std::optional libc; - //std::optional libcpp; // ? + //std::optional libcpp; std::shared_ptr Librarian; std::shared_ptr Linker; diff --git a/src/sw/driver/options.h b/src/sw/driver/options.h index eca274ab6..382731ab8 100644 --- a/src/sw/driver/options.h +++ b/src/sw/driver/options.h @@ -249,8 +249,7 @@ struct SW_DRIVER_CPP_API NativeLinkerOptionsData void remove(const LinkLibrary &l); }; -struct SW_DRIVER_CPP_API NativeCompilerOptions : IterableOptions, - NativeCompilerOptionsData +struct SW_DRIVER_CPP_API NativeCompilerOptions : NativeCompilerOptionsData { NativeCompilerOptionsData System; @@ -265,8 +264,7 @@ struct SW_DRIVER_CPP_API NativeCompilerOptions : IterableOptions, - NativeLinkerOptionsData +struct SW_DRIVER_CPP_API NativeLinkerOptions : NativeLinkerOptionsData { // 1. remove dups somewhere: implement unique_vector // 2. move Dependencies out - ??? @@ -308,16 +306,13 @@ struct SW_DRIVER_CPP_API NativeLinkerOptions : IterableOptions; struct SW_DRIVER_CPP_API NativeOptions : NativeCompilerOptions, - NativeLinkerOptions, - IterableOptions + NativeLinkerOptions { using NativeCompilerOptions::add; using NativeCompilerOptions::remove; using NativeLinkerOptions::add; using NativeLinkerOptions::remove; - using IterableOptions::iterate; - void merge(const NativeOptions &o, const GroupSettings &s = GroupSettings()); }; @@ -470,36 +465,15 @@ struct InheritanceGroup : T //Public.merge(g.Interface); } - template - void iterate(F &&f, const GroupSettings &s = GroupSettings()) - { - auto s2 = s; - - s2.Inheritance = InheritanceType::Private; - //T::template iterate(std::forward(f), s); - Private.template iterate(std::forward(f), s); - s2.Inheritance = InheritanceType::Protected; - Protected.template iterate(std::forward(f), s2); - s2.Inheritance = InheritanceType::Public; - Public.template iterate(std::forward(f), s2); - s2.Inheritance = InheritanceType::Interface; - Interface.template iterate(std::forward(f), s2); - } - - template - void iterate(F &&f, const GroupSettings &s = GroupSettings()) const + template + void iterate(F &&f) const { - auto s2 = s; - - s2.Inheritance = InheritanceType::Private; - //T::template iterate(std::forward(f), s); - Private.template iterate(std::forward(f), s); - s2.Inheritance = InheritanceType::Protected; - Protected.template iterate(std::forward(f), s2); - s2.Inheritance = InheritanceType::Public; - Public.template iterate(std::forward(f), s2); - s2.Inheritance = InheritanceType::Interface; - Interface.template iterate(std::forward(f), s2); + for (int i = toIndex(InheritanceType::Min); i < toIndex(InheritanceType::Max); i++) + { + auto s = getInheritanceStorage().raw()[i]; + if (s) + f(*s, (InheritanceType)i); + } } // merge to T, always w/o interface diff --git a/src/sw/driver/source_file.h b/src/sw/driver/source_file.h index ba26225aa..2e02d632d 100644 --- a/src/sw/driver/source_file.h +++ b/src/sw/driver/source_file.h @@ -41,8 +41,7 @@ using SourceFileMap = std::unordered_map>; * */ //template -struct SW_DRIVER_CPP_API SourceFileStorage : protected SourceFileMap, - IterableOptions +struct SW_DRIVER_CPP_API SourceFileStorage : protected SourceFileMap { public: using SourceFileMapThis = SourceFileMap; diff --git a/src/sw/driver/sw.h b/src/sw/driver/sw.h index a537ea49a..fb2a3a06c 100644 --- a/src/sw/driver/sw.h +++ b/src/sw/driver/sw.h @@ -109,11 +109,6 @@ using sw::NativeLanguage; using sw::NativeSourceFile; using sw::NativeLinkerOptions; -// TODO: remove -using sw::WithSourceFileStorage; -using sw::WithoutSourceFileStorage; -using sw::WithNativeOptions; -using sw::WithoutNativeOptions; // using sw::CommandLineOption; diff --git a/src/sw/driver/target/base.h b/src/sw/driver/target/base.h index 6978c2f37..bba75658d 100644 --- a/src/sw/driver/target/base.h +++ b/src/sw/driver/target/base.h @@ -469,11 +469,6 @@ struct SW_DRIVER_CPP_API ProjectTarget : ProjDirBase TargetType getType() const override { return TargetType::Project; } }; -struct WithSourceFileStorage {}; -struct WithoutSourceFileStorage {}; -struct WithNativeOptions {}; -struct WithoutNativeOptions {}; - //template //struct SW_DRIVER_CPP_API TargetOptions : Args... struct SW_DRIVER_CPP_API TargetOptions : SourceFileStorage, NativeOptions @@ -489,22 +484,6 @@ struct SW_DRIVER_CPP_API TargetOptions : SourceFileStorage, NativeOptions void add(const IncludeDirectory &i); void remove(const IncludeDirectory &i); - template - void iterate(F &&f, const GroupSettings &s = GroupSettings()) - { - SourceFileStorage::iterate(std::forward(f), s); - NativeOptions::iterate(std::forward(f), s); - } - - template - void iterate(F &&f, const GroupSettings &s = GroupSettings()) - { - if constexpr (std::is_same_v) - SourceFileStorage::iterate(std::forward(f), s); - if constexpr (std::is_same_v) - NativeOptions::iterate(std::forward(f), s); - } - void merge(const TargetOptions &g, const GroupSettings &s = GroupSettings()) { SourceFileStorage::merge(g, s); @@ -560,12 +539,6 @@ struct SW_DRIVER_CPP_API TargetOptionsGroup : InheritanceGroup::inheritance(g, s); } - template - void iterate(F &&f, const GroupSettings &s = GroupSettings()) - { - InheritanceGroup::iterate(std::forward(f), s); - } - // self merge void merge(const GroupSettings &s = GroupSettings()) { diff --git a/src/sw/driver/target/native.cpp b/src/sw/driver/target/native.cpp index f6f83089b..78f8299c7 100644 --- a/src/sw/driver/target/native.cpp +++ b/src/sw/driver/target/native.cpp @@ -82,11 +82,10 @@ bool NativeExecutedTarget::init() Target::init(); // propagate this pointer to all - TargetOptionsGroup::iterate([this](auto &v, auto &gs) + TargetOptionsGroup::iterate([this](auto &v, auto i) { v.target = this; }); - //LanguageStorage::target = this; Librarian = std::dynamic_pointer_cast(getSolution()->Settings.Native.Librarian->clone()); Linker = std::dynamic_pointer_cast(getSolution()->Settings.Native.Linker->clone()); @@ -342,8 +341,8 @@ std::unordered_set NativeExecutedTarget::gatherSourceFiles() Files NativeExecutedTarget::gatherIncludeDirectories() const { Files idirs; - ((NativeExecutedTarget*)this)->TargetOptionsGroup::iterate( - [this, &idirs](auto &v, auto &s) + TargetOptionsGroup::iterate( + [this, &idirs](auto &v, auto i) { auto idirs2 = v.gatherIncludeDirectories(); for (auto &i2 : idirs2) @@ -1418,8 +1417,8 @@ bool NativeExecutedTarget::prepare() std::vector deps_ordered; // set our initial deps - TargetOptionsGroup::iterate( - [this, &deps, &deps_ordered](auto &v, auto &s) + TargetOptionsGroup::iterate( + [this, &deps, &deps_ordered](auto &v, auto i) { //DEBUG_BREAK_IF_STRING_HAS(getPackage().ppath.toString(), "sw.server.protos"); @@ -1430,7 +1429,7 @@ bool NativeExecutedTarget::prepare() if (d->isDummy()) continue; - deps.emplace(d, s.Inheritance); + deps.emplace(d, i); deps_ordered.push_back(d); } }); @@ -1450,11 +1449,11 @@ bool NativeExecutedTarget::prepare() } // iterate over child deps - (*(NativeExecutedTarget*)d->target).TargetOptionsGroup::iterate( - [this, &new_dependency, &deps, d = d.get(), &deps_ordered](auto &v, auto &s) + (*(NativeExecutedTarget*)d->target).TargetOptionsGroup::iterate( + [this, &new_dependency, &deps, d = d.get(), &deps_ordered](auto &v, auto Inheritance) { // nothing to do with private inheritance - if (s.Inheritance == InheritanceType::Private) + if (Inheritance == InheritanceType::Private) return; for (auto &d2 : v.Dependencies) @@ -1464,13 +1463,13 @@ bool NativeExecutedTarget::prepare() if (d2->isDummy()) continue; - if (s.Inheritance == InheritanceType::Protected && !hasSameParent(d2->target)) + if (Inheritance == InheritanceType::Protected && !hasSameParent(d2->target)) continue; auto copy = std::make_shared(*d2); auto[i, inserted] = deps.emplace(copy, - s.Inheritance == InheritanceType::Interface ? - InheritanceType::Public : s.Inheritance + Inheritance == InheritanceType::Interface ? + InheritanceType::Public : Inheritance ); if (inserted) deps_ordered.push_back(copy); diff --git a/src/sw/driver/target/other.cpp b/src/sw/driver/target/other.cpp index 145e9099b..15b6f4fd9 100644 --- a/src/sw/driver/target/other.cpp +++ b/src/sw/driver/target/other.cpp @@ -13,11 +13,10 @@ bool CSharpTarget::init() Target::init(); // propagate this pointer to all - TargetOptionsGroup::iterate([this](auto &v, auto &gs) + TargetOptionsGroup::iterate([this](auto &v, auto i) { v.target = this; }); - //LanguageStorage::target = this; if (auto p = SourceFileStorage::findProgramByExtension(".cs"); p) compiler = std::dynamic_pointer_cast(p->clone()); @@ -68,11 +67,10 @@ bool RustTarget::init() Target::init(); // propagate this pointer to all - TargetOptionsGroup::iterate([this](auto &v, auto &gs) + TargetOptionsGroup::iterate([this](auto &v, auto i) { v.target = this; }); - //LanguageStorage::target = this; if (auto p = SourceFileStorage::findProgramByExtension(".rs"); p) compiler = std::dynamic_pointer_cast(p->clone()); @@ -123,11 +121,10 @@ bool GoTarget::init() Target::init(); // propagate this pointer to all - TargetOptionsGroup::iterate([this](auto &v, auto &gs) + TargetOptionsGroup::iterate([this](auto &v, auto i) { v.target = this; }); - //LanguageStorage::target = this; if (auto p = SourceFileStorage::findProgramByExtension(".go"); p) compiler = std::dynamic_pointer_cast(p->clone()); @@ -178,11 +175,10 @@ bool FortranTarget::init() Target::init(); // propagate this pointer to all - TargetOptionsGroup::iterate([this](auto &v, auto &gs) + TargetOptionsGroup::iterate([this](auto &v, auto i) { v.target = this; }); - //LanguageStorage::target = this; if (auto p = SourceFileStorage::findProgramByExtension(".f"); p) compiler = std::dynamic_pointer_cast(p->clone()); @@ -233,11 +229,10 @@ bool JavaTarget::init() Target::init(); // propagate this pointer to all - TargetOptionsGroup::iterate([this](auto &v, auto &gs) + TargetOptionsGroup::iterate([this](auto &v, auto i) { v.target = this; }); - //LanguageStorage::target = this; if (auto p = SourceFileStorage::findProgramByExtension(".java"); p) compiler = std::dynamic_pointer_cast(p->clone()); @@ -291,11 +286,10 @@ bool KotlinTarget::init() Target::init(); // propagate this pointer to all - TargetOptionsGroup::iterate([this](auto &v, auto &gs) + TargetOptionsGroup::iterate([this](auto &v, auto i) { v.target = this; }); - //LanguageStorage::target = this; if (auto p = SourceFileStorage::findProgramByExtension(".kt"); p) compiler = std::dynamic_pointer_cast(p->clone()); @@ -346,11 +340,10 @@ bool DTarget::init() Target::init(); // propagate this pointer to all - TargetOptionsGroup::iterate([this](auto &v, auto &gs) + TargetOptionsGroup::iterate([this](auto &v, auto i) { v.target = this; }); - //LanguageStorage::target = this; if (auto p = SourceFileStorage::findProgramByExtension(".d"); p) compiler = std::dynamic_pointer_cast(p->clone()); diff --git a/src/sw/driver/types.h b/src/sw/driver/types.h index 4d3a6ef5e..33ec0cfc9 100644 --- a/src/sw/driver/types.h +++ b/src/sw/driver/types.h @@ -218,22 +218,6 @@ struct SW_DRIVER_CPP_API GroupSettings bool include_directories_only = false; }; -template -struct SW_DRIVER_CPP_API IterableOptions -{ - template - auto iterate(F &&f, const GroupSettings &s = GroupSettings()) - { - std::forward(f)(*(T *)this, s); - } - - template - auto iterate(F &&f, const GroupSettings &s = GroupSettings()) const - { - std::forward(f)(*(T *)this, s); - } -}; - template struct stream_list_inserter : boost::assign::list_inserter {