aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/language
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/corelib/language')
-rw-r--r--src/lib/corelib/language/moduleloader.cpp58
-rw-r--r--src/lib/corelib/language/moduleproviderloader.cpp7
-rw-r--r--src/lib/corelib/language/propertydeclaration.cpp56
-rw-r--r--src/lib/corelib/language/propertydeclaration.h7
4 files changed, 74 insertions, 54 deletions
diff --git a/src/lib/corelib/language/moduleloader.cpp b/src/lib/corelib/language/moduleloader.cpp
index 72e248433..3ffd0736e 100644
--- a/src/lib/corelib/language/moduleloader.cpp
+++ b/src/lib/corelib/language/moduleloader.cpp
@@ -3194,55 +3194,6 @@ QStringList &ModuleLoader::getModuleFileNames(const QString &dirPath)
return moduleFileNames;
}
-// returns QMetaType::UnknownType for types that do not need conversion
-static QMetaType::Type variantType(PropertyDeclaration::Type t)
-{
- switch (t) {
- case PropertyDeclaration::UnknownType:
- break;
- case PropertyDeclaration::Boolean:
- return QMetaType::Bool;
- case PropertyDeclaration::Integer:
- return QMetaType::Int;
- case PropertyDeclaration::Path:
- return QMetaType::QString;
- case PropertyDeclaration::PathList:
- return QMetaType::QStringList;
- case PropertyDeclaration::String:
- return QMetaType::QString;
- case PropertyDeclaration::StringList:
- return QMetaType::QStringList;
- case PropertyDeclaration::VariantList:
- return QMetaType::QVariantList;
- case PropertyDeclaration::Variant:
- break;
- }
- return QMetaType::UnknownType;
-}
-
-static QVariant convertToPropertyType(const QVariant &v, PropertyDeclaration::Type t,
- const QStringList &namePrefix, const QString &key)
-{
- if (v.isNull() || !v.isValid())
- return v;
- const auto vt = variantType(t);
- if (vt == QMetaType::UnknownType)
- return v;
-
- // Handle the foo,bar,bla stringlist syntax.
- if (t == PropertyDeclaration::StringList && v.userType() == QMetaType::QString)
- return v.toString().split(QLatin1Char(','));
-
- QVariant c = v;
- if (!qVariantConvert(c, vt)) {
- QStringList name = namePrefix;
- name << key;
- throw ErrorInfo(Tr::tr("Value '%1' of property '%2' has incompatible type.")
- .arg(v.toString(), name.join(QLatin1Char('.'))));
- }
- return c;
-}
-
static Item *findDeepestModuleInstance(Item *instance)
{
while (instance->prototype() && instance->prototype()->type() == ItemType::ModuleInstance)
@@ -3324,8 +3275,9 @@ std::pair<Item *, bool> ModuleLoader::getModulePrototype(ProductContext *product
continue;
}
const PropertyDeclaration decl = module->propertyDeclaration(it.key());
- VariantValuePtr v = VariantValue::create(convertToPropertyType(it.value(), decl.type(),
- QStringList(fullModuleName), it.key()));
+ VariantValuePtr v = VariantValue::create(
+ PropertyDeclaration::convertToPropertyType(it.value(), decl.type(),
+ QStringList(fullModuleName), it.key()));
module->setProperty(it.key(), v);
}
@@ -3813,8 +3765,8 @@ void ModuleLoader::overrideItemProperties(Item *item, const QString &buildConfig
continue;
}
item->setProperty(it.key(),
- VariantValue::create(convertToPropertyType(it.value(), decl.type(),
- QStringList(buildConfigKey), it.key())));
+ VariantValue::create(PropertyDeclaration::convertToPropertyType(
+ it.value(), decl.type(), QStringList(buildConfigKey), it.key())));
}
}
diff --git a/src/lib/corelib/language/moduleproviderloader.cpp b/src/lib/corelib/language/moduleproviderloader.cpp
index f036e36ab..d8acad651 100644
--- a/src/lib/corelib/language/moduleproviderloader.cpp
+++ b/src/lib/corelib/language/moduleproviderloader.cpp
@@ -302,13 +302,18 @@ QStringList ModuleProviderLoader::getProviderSearchPaths(
BuiltinDeclarations::instance().nameForType(ItemType::ModuleProvider)));
}
providerItem->setParent(product.item);
+
+ // TODO: this looks like ModuleLoader::overrideItemProperties(), merge them?
for (auto it = moduleConfig.begin(); it != moduleConfig.end(); ++it) {
const PropertyDeclaration decl = providerItem->propertyDeclaration(it.key());
if (!decl.isValid()) {
throw ErrorInfo(Tr::tr("No such property '%1' in module provider '%2'.")
.arg(it.key(), name.toString()));
}
- providerItem->setProperty(it.key(), VariantValue::create(it.value()));
+ VariantValuePtr v = VariantValue::create(
+ PropertyDeclaration::convertToPropertyType(it.value(), decl.type(),
+ QStringList(name), it.key()));
+ providerItem->setProperty(it.key(), v);
}
EvalContextSwitcher contextSwitcher(m_evaluator->engine(), EvalContext::ModuleProvider);
return m_evaluator->stringListValue(providerItem, QStringLiteral("searchPaths"));
diff --git a/src/lib/corelib/language/propertydeclaration.cpp b/src/lib/corelib/language/propertydeclaration.cpp
index 14ed52d1e..2dbe41afd 100644
--- a/src/lib/corelib/language/propertydeclaration.cpp
+++ b/src/lib/corelib/language/propertydeclaration.cpp
@@ -42,14 +42,46 @@
#include "deprecationinfo.h"
#include <api/languageinfo.h>
+#include <logging/translator.h>
+
+#include <tools/error.h>
+#include <tools/qttools.h>
#include <tools/stringconstants.h>
+#include <QtCore/qmetatype.h>
#include <QtCore/qshareddata.h>
#include <QtCore/qstringlist.h>
+#include <QtCore/qvariant.h>
namespace qbs {
namespace Internal {
+// returns QMetaType::UnknownType for types that do not need conversion
+static QMetaType::Type variantType(PropertyDeclaration::Type t)
+{
+ switch (t) {
+ case PropertyDeclaration::UnknownType:
+ break;
+ case PropertyDeclaration::Boolean:
+ return QMetaType::Bool;
+ case PropertyDeclaration::Integer:
+ return QMetaType::Int;
+ case PropertyDeclaration::Path:
+ return QMetaType::QString;
+ case PropertyDeclaration::PathList:
+ return QMetaType::QStringList;
+ case PropertyDeclaration::String:
+ return QMetaType::QString;
+ case PropertyDeclaration::StringList:
+ return QMetaType::QStringList;
+ case PropertyDeclaration::VariantList:
+ return QMetaType::QVariantList;
+ case PropertyDeclaration::Variant:
+ break;
+ }
+ return QMetaType::UnknownType;
+}
+
class PropertyDeclarationData : public QSharedData
{
public:
@@ -243,5 +275,29 @@ void PropertyDeclaration::setDeprecationInfo(const DeprecationInfo &deprecationI
d->deprecationInfo = deprecationInfo;
}
+// see also: EvaluatorScriptClass::convertToPropertyType()
+QVariant PropertyDeclaration::convertToPropertyType(const QVariant &v, Type t,
+ const QStringList &namePrefix, const QString &key)
+{
+ if (v.isNull() || !v.isValid())
+ return v;
+ const auto vt = variantType(t);
+ if (vt == QMetaType::UnknownType)
+ return v;
+
+ // Handle the foo,bar,bla stringlist syntax.
+ if (t == PropertyDeclaration::StringList && v.userType() == QMetaType::QString)
+ return v.toString().split(QLatin1Char(','));
+
+ QVariant c = v;
+ if (!qVariantConvert(c, vt)) {
+ QStringList name = namePrefix;
+ name << key;
+ throw ErrorInfo(Tr::tr("Value '%1' of property '%2' has incompatible type.")
+ .arg(v.toString(), name.join(QLatin1Char('.'))));
+ }
+ return c;
+}
+
} // namespace Internal
} // namespace qbs
diff --git a/src/lib/corelib/language/propertydeclaration.h b/src/lib/corelib/language/propertydeclaration.h
index 77b6837f5..137315d14 100644
--- a/src/lib/corelib/language/propertydeclaration.h
+++ b/src/lib/corelib/language/propertydeclaration.h
@@ -43,6 +43,10 @@
#include <QtCore/qshareddata.h>
#include <QtCore/qstring.h>
+QT_BEGIN_NAMESPACE
+class QVariant;
+QT_END_NAMESPACE
+
namespace qbs {
namespace Internal {
class DeprecationInfo;
@@ -113,6 +117,9 @@ public:
const DeprecationInfo &deprecationInfo() const;
void setDeprecationInfo(const DeprecationInfo &deprecationInfo);
+ static QVariant convertToPropertyType(
+ const QVariant &v, Type t, const QStringList &namePrefix, const QString &key);
+
private:
QSharedDataPointer<PropertyDeclarationData> d;
};