Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type#GetLoadDependencies(): VERIFY() that no nullptr is returned #10155

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions tools/mkclass/classcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,32 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
<< "}" << std::endl << std::endl;

/* GetLoadDependencies */
m_Header << "\t" << "const std::unordered_set<Type*>& GetLoadDependencies() const override;" << std::endl;
if (!klass.LoadDependencies.empty()) {
m_Header << "\tconst std::unordered_set<Type*>& GetLoadDependencies() const override;" << std::endl;

m_Impl << "const std::unordered_set<Type*>& TypeImpl<" << klass.Name << ">::GetLoadDependencies() const" << std::endl
<< "{" << std::endl
<< "\t" << "static const std::unordered_set<Type*> deps ({" << std::endl;
m_Impl << "const std::unordered_set<Type*>& TypeImpl<" << klass.Name << ">::GetLoadDependencies() const" << std::endl
<< "{" << std::endl
<< "\tstatic const auto deps ([] {" << std::endl;

for (const std::string& dep : klass.LoadDependencies)
m_Impl << "\t\t" << "GetByName(\"" << dep << "\").get()," << std::endl;
for (auto& dep : klass.LoadDependencies)
m_Impl << "\t\tauto type" << dep << " (GetByName(\"" << dep << "\").get());" << std::endl;
Comment on lines +386 to +387
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's much better, but why are you using two different loops for declaring and verifying them? Can't you just combine them like that?

Suggested change
for (auto& dep : klass.LoadDependencies)
m_Impl << "\t\tauto type" << dep << " (GetByName(\"" << dep << "\").get());" << std::endl;
for (auto& dep : klass.LoadDependencies) {
m_Impl << "\t\tauto type" << dep << " (GetByName(\"" << dep << "\").get());" << std::endl;
m_Impl << "\t\tVERIFY(type" << dep << ");" << std::endl;
}
m_Impl << std::endl << "\t\treturn std::unordered_set<Type*>{";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I prefer this:

const std::unordered_set<Type*>& TypeImpl<Service>::GetLoadDependencies() const
{
	static const auto deps ([] {
		auto typeApiListener (GetByName("ApiListener").get());
		auto typeEndpoint (GetByName("Endpoint").get());
		auto typeHost (GetByName("Host").get());
		auto typeZone (GetByName("Zone").get());

		VERIFY(typeApiListener);
		VERIFY(typeEndpoint);
		VERIFY(typeHost);
		VERIFY(typeZone);

		return std::unordered_set{ typeApiListener, typeEndpoint, typeHost, typeZone, };
	}());

	return deps;
}


m_Impl << "\t" << "});" << std::endl;
m_Impl << std::endl;

m_Impl << "\t" << "return deps;" << std::endl
<< "}" << std::endl << std::endl;
for (auto& dep : klass.LoadDependencies)
m_Impl << "\t\tVERIFY(type" << dep << ");" << std::endl;

m_Impl << std::endl
<< "\t\treturn std::unordered_set<Type*>{";

for (const std::string& dep : klass.LoadDependencies)
m_Impl << " type" << dep << ",";

m_Impl << " };" << std::endl
<< "\t}());" << std::endl << std::endl
<< "\treturn deps;" << std::endl
<< "}" << std::endl << std::endl;
}

/* GetActivationPriority */
m_Header << "\t" << "int GetActivationPriority() const override;" << std::endl;
Expand Down Expand Up @@ -1463,6 +1476,7 @@ void ClassCompiler::CompileStream(const std::string& path, std::istream& input,
<< "#include \"base/objectlock.hpp\"" << std::endl
<< "#include \"base/utility.hpp\"" << std::endl
<< "#include \"base/convert.hpp\"" << std::endl
<< "#include \"base/debug.hpp\"" << std::endl
<< "#include \"base/dependencygraph.hpp\"" << std::endl
<< "#include \"base/logger.hpp\"" << std::endl
<< "#include \"base/function.hpp\"" << std::endl
Expand Down
Loading