aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/common
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-04-02 11:48:21 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-04-03 09:12:10 +0200
commitf1fd2b982a2ceae92da9b4a3875c65ed8a49560d (patch)
tree44c24fc3a81ec5d3797abae015391f463e3d8a43 /src/qml/common
parentc3b6e81388fa02a8e3b99ee6f3fa3e9c7dba1772 (diff)
V4: Move constant evaluation of doubles and strings into base CU
We don't need to execute anything for that. The translation evaluation is kept in the executable CU because we might not have a QCoreApplication. Change-Id: I2ee39b220305e74b8c8f5540b8e59a91e2ed2b4c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/common')
-rw-r--r--src/qml/common/qv4compileddata_p.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/qml/common/qv4compileddata_p.h b/src/qml/common/qv4compileddata_p.h
index 52ef6aaf5e..7d44126b13 100644
--- a/src/qml/common/qv4compileddata_p.h
+++ b/src/qml/common/qv4compileddata_p.h
@@ -58,6 +58,7 @@
#include <QtCore/qstringlist.h>
#include <QtCore/qhash.h>
#include <QtCore/qversionnumber.h>
+#include <QtCore/qlocale.h>
#if QT_CONFIG(temporaryfile)
#include <QtCore/qsavefile.h>
@@ -1293,6 +1294,44 @@ public:
Heap::Module *module() const { return m_module; }
void setModule(Heap::Module *module) { m_module = module; }
+ QString bindingValueAsString(const CompiledData::Binding *binding) const
+ {
+ using namespace CompiledData;
+ switch (binding->type) {
+ case Binding::Type_Script:
+ case Binding::Type_String:
+ return stringAt(binding->stringIndex);
+ case Binding::Type_Null:
+ return QStringLiteral("null");
+ case Binding::Type_Boolean:
+ return binding->value.b ? QStringLiteral("true") : QStringLiteral("false");
+ case Binding::Type_Number:
+ return QString::number(bindingValueAsNumber(binding), 'g', QLocale::FloatingPointShortest);
+ case Binding::Type_Invalid:
+ return QString();
+ case Binding::Type_TranslationById:
+ case Binding::Type_Translation:
+ return stringAt(data->translations()[binding->value.translationDataIndex].stringIndex);
+ default:
+ break;
+ }
+ return QString();
+ }
+
+ QString bindingValueAsScriptString(const CompiledData::Binding *binding) const
+ {
+ return (binding->type == CompiledData::Binding::Type_String)
+ ? CompiledData::Binding::escapedString(stringAt(binding->stringIndex))
+ : bindingValueAsString(binding);
+ }
+
+ double bindingValueAsNumber(const CompiledData::Binding *binding) const
+ {
+ if (binding->type != CompiledData::Binding::Type_Number)
+ return 0.0;
+ return constants[binding->value.constantValueIndex].doubleValue();
+ }
+
private:
QString m_fileName; // initialized from data->sourceFileIndex
QString m_finalUrlString; // initialized from data->finalUrlIndex