aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Komissarov <abbapoh@gmail.com>2020-09-15 00:26:38 +0200
committerIvan Komissarov <ABBAPOH@gmail.com>2020-09-16 14:22:18 +0000
commit575829ca20574db6f4287a674e0b14b72d09440c (patch)
treedabbc6c3bf0af17d7c04dd198bc1fb9a2397ebe6
parent627c870fd097f41635864be740f71bf1901f2f63 (diff)
Do not use return argument in loadModuleFile()
Generally, return arguments make code harder to understand as they intoroduce unneseccary compexity and addidional states. Use std::pair and structured bindings to return the value. Change-Id: I7c387a346958e1df1174027574fa5797ee221429 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--src/lib/corelib/language/moduleloader.cpp33
-rw-r--r--src/lib/corelib/language/moduleloader.h9
2 files changed, 22 insertions, 20 deletions
diff --git a/src/lib/corelib/language/moduleloader.cpp b/src/lib/corelib/language/moduleloader.cpp
index eda40516b..f8c03ddf6 100644
--- a/src/lib/corelib/language/moduleloader.cpp
+++ b/src/lib/corelib/language/moduleloader.cpp
@@ -3151,9 +3151,8 @@ Item *ModuleLoader::searchAndLoadModuleFile(ProductContext *productContext,
QStringList &moduleFileNames = getModuleFileNames(dirPath);
for (auto it = moduleFileNames.begin(); it != moduleFileNames.end(); ) {
const QString &filePath = *it;
- bool triedToLoad = true;
- Item *module = loadModuleFile(productContext, fullName, isBaseModule(moduleName),
- filePath, &triedToLoad, moduleInstance);
+ const auto [module, triedToLoad] = loadModuleFile(
+ productContext, fullName, isBaseModule(moduleName), filePath, moduleInstance);
if (module)
candidates.emplace_back(module, 0, i);
if (!triedToLoad)
@@ -3267,22 +3266,24 @@ static Item *findDeepestModuleInstance(Item *instance)
return instance;
}
-Item *ModuleLoader::loadModuleFile(ProductContext *productContext, const QString &fullModuleName,
- bool isBaseModule, const QString &filePath, bool *triedToLoad, Item *moduleInstance)
+std::pair<Item *, bool> ModuleLoader::loadModuleFile(
+ ProductContext *productContext, const QString &fullModuleName, bool isBaseModule,
+ const QString &filePath, Item *moduleInstance)
{
checkCancelation();
qCDebug(lcModuleLoader) << "loadModuleFile" << fullModuleName << "from" << filePath;
- Item * const module = getModulePrototype(productContext, fullModuleName, filePath, triedToLoad);
+ const auto [module, triedToLoad] =
+ getModulePrototype(productContext, fullModuleName, filePath);
if (!module)
- return nullptr;
+ return {nullptr, triedToLoad};
const auto key = std::make_pair(module, productContext);
const auto it = m_modulePrototypeEnabledInfo.find(key);
if (it != m_modulePrototypeEnabledInfo.end()) {
qCDebug(lcModuleLoader) << "prototype cache hit (level 2)";
- return it.value() ? module : nullptr;
+ return {it.value() ? module : nullptr, triedToLoad};
}
// Set the name before evaluating any properties. EvaluatorScriptClass reads the module name.
@@ -3296,7 +3297,7 @@ Item *ModuleLoader::loadModuleFile(ProductContext *productContext, const QString
if (!enabled) {
qCDebug(lcModuleLoader) << "condition of module" << fullModuleName << "is false";
m_modulePrototypeEnabledInfo.insert(key, false);
- return nullptr;
+ return {nullptr, triedToLoad};
}
if (isBaseModule)
@@ -3305,17 +3306,18 @@ Item *ModuleLoader::loadModuleFile(ProductContext *productContext, const QString
resolveParameterDeclarations(module);
m_modulePrototypeEnabledInfo.insert(key, true);
- return module;
+ return {module, triedToLoad};
}
-Item *ModuleLoader::getModulePrototype(ProductContext *productContext,
- const QString &fullModuleName, const QString &filePath, bool *triedToLoad)
+// Returns the module prototype item and a boolean indicating if we tried to load it from the file
+std::pair<Item *, bool> ModuleLoader::getModulePrototype(ProductContext *productContext,
+ const QString &fullModuleName, const QString &filePath)
{
auto &prototypeList = m_modulePrototypes[filePath];
for (const auto &prototype : prototypeList) {
if (prototype.second == productContext->profileName) {
qCDebug(lcModuleLoader) << "prototype cache hit (level 1)";
- return prototype.first;
+ return {prototype.first, true};
}
}
Item * const module = loadItemFromFile(filePath, CodeLocation());
@@ -3323,8 +3325,7 @@ Item *ModuleLoader::getModulePrototype(ProductContext *productContext,
qCDebug(lcModuleLoader).nospace()
<< "Alleged module " << fullModuleName << " has type '"
<< module->typeName() << "', so it's not a module after all.";
- *triedToLoad = false;
- return nullptr;
+ return {nullptr, false};
}
prototypeList.emplace_back(module, productContext->profileName);
@@ -3344,7 +3345,7 @@ Item *ModuleLoader::getModulePrototype(ProductContext *productContext,
module->setProperty(it.key(), v);
}
- return module;
+ return {module, true};
}
Item::Module ModuleLoader::loadBaseModule(ProductContext *productContext, Item *item)
diff --git a/src/lib/corelib/language/moduleloader.h b/src/lib/corelib/language/moduleloader.h
index f831e8fe1..b6d8143e0 100644
--- a/src/lib/corelib/language/moduleloader.h
+++ b/src/lib/corelib/language/moduleloader.h
@@ -320,10 +320,11 @@ private:
const CodeLocation &dependsItemLocation, const QualifiedId &moduleName,
FallbackMode fallbackMode, bool isRequired, Item *moduleInstance);
QStringList &getModuleFileNames(const QString &dirPath);
- Item *loadModuleFile(ProductContext *productContext, const QString &fullModuleName,
- bool isBaseModule, const QString &filePath, bool *triedToLoad, Item *moduleInstance);
- Item *getModulePrototype(ProductContext *productContext, const QString &fullModuleName,
- const QString &filePath, bool *triedToLoad);
+ std::pair<Item *, bool> loadModuleFile(
+ ProductContext *productContext, const QString &fullModuleName, bool isBaseModule,
+ const QString &filePath, Item *moduleInstance);
+ std::pair<Item *, bool> getModulePrototype(ProductContext *productContext,
+ const QString &fullModuleName, const QString &filePath);
Item::Module loadBaseModule(ProductContext *productContext, Item *item);
void setupBaseModulePrototype(Item *prototype);
template <typename T, typename F>