4#ifndef QV4COMPILEDDATA_P_H
5#define QV4COMPILEDDATA_P_H
20#include <QtCore/qcryptographichash.h>
21#include <QtCore/qhash.h>
22#include <QtCore/qhashfunctions.h>
23#include <QtCore/qlocale.h>
24#include <QtCore/qscopeguard.h>
25#include <QtCore/qstring.h>
26#include <QtCore/qstringlist.h>
27#include <QtCore/qurl.h>
28#include <QtCore/qvector.h>
29#include <QtCore/qversionnumber.h>
31#if QT_CONFIG(temporaryfile)
32#include <QtCore/qsavefile.h>
35#include <private/qendian_p.h>
36#include <private/qqmlnullablevalue_p.h>
37#include <private/qqmlpropertycachevector_p.h>
38#include <private/qqmlrefcount_p.h>
39#include <private/qqmltype_p.h>
40#include <private/qv4compilationunitmapper_p.h>
41#include <private/qv4staticvalue_p.h>
55#define QV4_DATA_STRUCTURE_VERSION 0x4c
58class QQmlTypeNameCache;
91 bool addToHash(QCryptographicHash *hash, QHash<quintptr, QByteArray> *checksums)
const;
100template <
typename ItemType,
typename Container,
const ItemType *(Container::*IndexedGetter)(
int index)
const>
119 m_data.set<LineField>(l);
120 m_data.set<ColumnField>(c);
121 Q_ASSERT(m_data.get<LineField>() == l);
122 Q_ASSERT(m_data.get<ColumnField>() == c);
126 return m_data.get<LineField>() < other.m_data.get<LineField>()
127 || (m_data.get<LineField>() == other.m_data.get<LineField>()
128 && m_data.get<ColumnField>() < other.m_data.get<ColumnField>());
133 return QT_PREPEND_NAMESPACE(qHash)(location.m_data.data(), seed);
138 return a.m_data.data()== b.m_data.data();
155 quint32_le_bitfield_union<LineField, ColumnField> m_data;
157static_assert(
sizeof(
Location) == 4,
"Location structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
175 m_data.set<FlagsField>(flags);
176 m_data.set<StringIndexField>(stringIndex);
185 quint32_le_bitfield_union<FlagsField, StringIndexField> m_data;
187static_assert(
sizeof(
RegExp) == 4,
"RegExp structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
210 m_data.set<TypeField>(type);
211 m_data.set<ModeField>(mode);
212 m_data.set<NameIndexField>(nameIndex);
220 quint32_le_bitfield_union<TypeField, ModeField, NameIndexField> m_data;
222static_assert(
sizeof(
Lookup) == 4,
"Lookup structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
228 void set(quint32 nameOffset,
bool isAccessor)
230 m_data.set<NameOffsetField>(nameOffset);
231 m_data.set<IsAccessorField>(isAccessor ? 1 : 0);
235 bool isAccessor()
const {
return m_data.get<IsAccessorField>() != 0; }
240 quint32_le_bitfield_union<NameOffsetField, IsAccessorField> m_data;
242static_assert(
sizeof(
JSClassMember) == 4,
"JSClassMember structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
251static_assert(
sizeof(
JSClass) == 4,
"JSClass structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
260 return (
sizeof(String) + (
int(str.size()) + 1) *
sizeof(quint16) + 7) & ~0x7;
264static_assert (
sizeof (
String) == 4,
"String structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
271static_assert(
sizeof(
CodeOffsetToLineAndStatement) == 12,
"CodeOffsetToLineAndStatement structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
280 const quint32_le *
localsTable()
const {
return reinterpret_cast<
const quint32_le *>(
reinterpret_cast<
const char *>(
this) + localsOffset); }
283 int trailingData = nLocals*
sizeof (quint32);
284 size_t size = align(align(
sizeof(
Block)) + size_t(trailingData));
285 Q_ASSERT(size < INT_MAX);
290 return (a + 7) & ~size_t(7);
293static_assert(
sizeof(
Block) == 12,
"Block structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
327 void set(Flags flags, quint32 typeNameIndexOrCommonType)
329 m_data.set<IsListField>(flags.testFlag(List) ? 1 : 0);
330 m_data.set<IndexIsCommonTypeField>(flags.testFlag(Common) ? 1 : 0);
331 m_data.set<TypeNameIndexOrCommonTypeField>(typeNameIndexOrCommonType);
336 return m_data.get<IndexIsCommonTypeField>() != 0;
341 return m_data.get<IsListField>() != 0;
346 return m_data.get<TypeNameIndexOrCommonTypeField>();
353 quint32_le_bitfield_union<IndexIsCommonTypeField, IsListField, TypeNameIndexOrCommonTypeField> m_data;
355static_assert(
sizeof(
ParameterType) == 4,
"ParameterType structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
362static_assert(
sizeof(
Parameter) == 8,
"Parameter structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
400 return lineAndStatementNumberOffset() + nLineAndStatementNumbers *
sizeof(CodeOffsetToLineAndStatement);
412 return reinterpret_cast<
const Parameter *>(
413 reinterpret_cast<
const char *>(
this) + formalsOffset);
417 return reinterpret_cast<
const quint32_le *>(
418 reinterpret_cast<
const char *>(
this) + localsOffset);
422 return reinterpret_cast<
const CodeOffsetToLineAndStatement *>(
423 reinterpret_cast<
const char *>(
this) + lineAndStatementNumberOffset());
431 const quint32_le *
labelInfoTable()
const {
return reinterpret_cast<
const quint32_le *>(
reinterpret_cast<
const char *>(
this) + labelInfosOffset()); }
433 const char *
code()
const {
return reinterpret_cast<
const char *>(
this) + codeOffset; }
436 int nFormals,
int nLocals,
int nLinesAndStatements,
int labelInfoSize,
int codeSize)
438 const size_t trailingData = nFormals *
sizeof(Parameter)
439 + (nLocals + labelInfoSize) *
sizeof (quint32)
440 + nLinesAndStatements *
sizeof(CodeOffsetToLineAndStatement);
441 size_t size = align(align(
sizeof(
Function)) + size_t(trailingData)) + align(codeSize);
442 Q_ASSERT(size < INT_MAX);
447 return (a + 7) & ~size_t(7);
450static_assert(
sizeof(
Function) == 56,
"Function structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
463static_assert(
sizeof(
Method) == 12,
"Method structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
474 const Method *
methodTable()
const {
return reinterpret_cast<
const Method *>(
reinterpret_cast<
const char *>(
this) + methodTableOffset); }
477 int trailingData = (nStaticMethods + nMethods) *
sizeof(
Method);
478 size_t size = align(
sizeof(
Class) + trailingData);
479 Q_ASSERT(size < INT_MAX);
484 return (a + 7) & ~size_t(7);
487static_assert(
sizeof(
Class) == 24,
"Class structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
494 int trailingData = 2 * size *
sizeof(quint32_le);
496 Q_ASSERT(s < INT_MAX);
501 return (a + 7) & ~size_t(7);
505 return reinterpret_cast<
const quint32_le *>(
reinterpret_cast<
const char *>(
this + 1));
509 return stringTable()[i];
512 return stringTable()[size + i];
515static_assert(
sizeof(
TemplateObject) == 4,
"Template object structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
525static_assert(
sizeof(
ExportEntry) == 20,
"ExportEntry structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
534static_assert(
sizeof(
ImportEntry) == 16,
"ImportEntry structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
546static_assert(
sizeof(
TranslationData) == 16,
"TranslationData structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
586 void setFlag(
Flag flag) { flagsAndType.set<FlagsField>(flagsAndType.get<FlagsField>() | flag); }
587 bool hasFlag(
Flag flag)
const {
return Flags(flagsAndType.get<FlagsField>()) & flag; }
588 Flags flags()
const {
return Flags(flagsAndType.get<FlagsField>()); }
591 Type type()
const {
return Type(flagsAndType.get<TypeField>()); }
608 const Flags bindingFlags = flags();
666 QString tmp = QLatin1String(
"\"");
667 for (
int i = 0; i < string.size(); ++i) {
668 const QChar &c = string.at(i);
669 switch (c.unicode()) {
671 tmp += QLatin1String(
"\\b");
674 tmp += QLatin1String(
"\\t");
677 tmp += QLatin1String(
"\\n");
680 tmp += QLatin1String(
"\\v");
683 tmp += QLatin1String(
"\\f");
686 tmp += QLatin1String(
"\\r");
689 tmp += QLatin1String(
"\\\"");
692 tmp += QLatin1String(
"\\\'");
695 tmp += QLatin1String(
"\\\\");
702 tmp += QLatin1Char(
'\"');
717 if (type() == Type_Boolean)
723static_assert(
sizeof(
Binding) == 24,
"Binding structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
732static_assert(
sizeof(
InlineComponent) == 12,
"InlineComponent structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
739static_assert(
sizeof(
EnumValue) == 8,
"EnumValue structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
748 return reinterpret_cast<
const EnumValue*>(
this + 1) + idx;
763static_assert(
sizeof(
Enum) == 12,
"Enum structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
773 return reinterpret_cast<
const Parameter*>(
this + 1) + idx;
788static_assert(
sizeof(
Signal) == 12,
"Signal structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
836 void setNameIndex(
int nameIndex) { nameIndexAndVirtSpecifiers.set<NameIndexField>(nameIndex); }
838 bool isVirtual()
const {
return nameIndexAndVirtSpecifiers.get<IsVirtualField>(); }
841 nameIndexAndVirtSpecifiers.set<IsVirtualField>(isVirtual ? 1 : 0);
844 bool isOverride()
const {
return nameIndexAndVirtSpecifiers.get<IsOverrideField>(); }
847 nameIndexAndVirtSpecifiers.set<IsOverrideField>(isOverride ? 1 : 0);
850 bool isFinal()
const {
return nameIndexAndVirtSpecifiers.get<IsFinalField>(); }
851 void setIsFinal(
bool isFinal) { nameIndexAndVirtSpecifiers.set<IsFinalField>(isFinal ? 1 : 0); }
855 data.set<CommonTypeOrTypeNameIndexField>(
static_cast<quint32>(t));
856 data.set<IsCommonTypeField>(
true);
861 return CommonType(data.get<CommonTypeOrTypeNameIndexField>());
867 data.set<CommonTypeOrTypeNameIndexField>(nameIndex);
868 data.set<IsCommonTypeField>(
false);
873 return data.get<IsCommonTypeField>() ? -1 : data.get<CommonTypeOrTypeNameIndexField>();
879 bool isList()
const {
return data.get<IsListField>(); }
880 void setIsList(
bool isList) { data.set<IsListField>(isList); }
882 bool isRequired()
const {
return data.get<IsRequiredField>(); }
883 void setIsRequired(
bool isRequired) { data.set<IsRequiredField>(isRequired); }
885 bool isReadOnly()
const {
return data.get<IsReadOnlyField>(); }
886 void setIsReadOnly(
bool isReadOnly) { data.set<IsReadOnlyField>(isReadOnly); }
888static_assert(
sizeof(
Property) == 12,
"Property structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
894static_assert (
sizeof(
RequiredPropertyExtraData) == 4,
"RequiredPropertyExtraData structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
898 bool isReadOnly()
const {
return m_nameIndexAndFlags.get<IsReadOnlyField>(); }
899 void setIsReadOnly(
bool isReadOnly) { m_nameIndexAndFlags.set<IsReadOnlyField>(isReadOnly); }
904 m_nameIndexAndFlags.set<NameIndexField>(nameIndex);
908 void setIdIndex(quint32 idIndex) { m_idIndexField = idIndex; }
913 m_propertyNameIndex = propertyNameIndex;
922 m_referenceLocation = referenceLocation;
929 quint32_le_bitfield_union<NameIndexField, IsReadOnlyField> m_nameIndexAndFlags;
930 quint32_le m_idIndexField;
931 quint32_le m_propertyNameIndex;
935static_assert(
sizeof(
Alias) == 20,
"Alias structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
991 return Flags(flagsAndDefaultPropertyIsAliasAndId.get<FlagsField>());
996 return flagsAndDefaultPropertyIsAliasAndId.get<FlagsField>() & flag;
1001 flagsAndDefaultPropertyIsAliasAndId.set<FlagsField>(
1002 flagsAndDefaultPropertyIsAliasAndId.get<FlagsField>() | flag);
1007 flagsAndDefaultPropertyIsAliasAndId.set<FlagsField>(flags);
1012 return flagsAndDefaultPropertyIsAliasAndId.get<DefaultPropertyIsAliasField>();
1017 flagsAndDefaultPropertyIsAliasAndId.set<DefaultPropertyIsAliasField>(defaultAlias);
1022 return flagsAndDefaultPropertyIsAliasAndId.get<IdField>();
1027 flagsAndDefaultPropertyIsAliasAndId.set<IdField>(id);
1031 static int calculateSizeExcludingSignalsAndEnums(
int nFunctions,
int nProperties,
int nAliases,
int nEnums,
int nSignals,
int nBindings,
int nNamedObjectsInComponent,
int nInlineComponents,
int nRequiredPropertyExtraData)
1033 return (
sizeof(Object)
1034 + nFunctions *
sizeof(quint32)
1035 + nProperties *
sizeof(Property)
1036 + nAliases *
sizeof(Alias)
1037 + nEnums *
sizeof(quint32)
1038 + nSignals *
sizeof(quint32)
1039 + nBindings *
sizeof(Binding)
1040 + nNamedObjectsInComponent *
sizeof(
int)
1041 + nInlineComponents *
sizeof(InlineComponent)
1042 + nRequiredPropertyExtraData *
sizeof(RequiredPropertyExtraData)
1049 return reinterpret_cast<
const quint32_le*>(
reinterpret_cast<
const char *>(
this) + offsetToFunctions);
1054 return reinterpret_cast<
const Property*>(
reinterpret_cast<
const char *>(
this) + offsetToProperties);
1059 return reinterpret_cast<
const Alias*>(
reinterpret_cast<
const char *>(
this) + offsetToAliases);
1064 return reinterpret_cast<
const Binding*>(
reinterpret_cast<
const char *>(
this) + offsetToBindings);
1069 const quint32_le *offsetTable =
reinterpret_cast<
const quint32_le*>((
reinterpret_cast<
const char *>(
this)) + offsetToEnums);
1070 const quint32_le offset = offsetTable[idx];
1071 return reinterpret_cast<
const Enum*>(
reinterpret_cast<
const char*>(
this) + offset);
1076 const quint32_le *offsetTable =
reinterpret_cast<
const quint32_le*>((
reinterpret_cast<
const char *>(
this)) + offsetToSignals);
1077 const quint32_le offset = offsetTable[idx];
1078 return reinterpret_cast<
const Signal*>(
reinterpret_cast<
const char*>(
this) + offset);
1088 return reinterpret_cast<
const quint32_le*>(
reinterpret_cast<
const char *>(
this) + offsetToNamedObjectsInComponent);
1093 return reinterpret_cast<
const InlineComponent*>(
reinterpret_cast<
const char *>(
this) + offsetToInlineComponents);
1103 return reinterpret_cast<
const RequiredPropertyExtraData*>(
reinterpret_cast<
const char *>(
this) + offsetToRequiredPropertyExtraData);
1143static_assert(
sizeof(
Object) == 84,
"Object structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
1164 type = 0; uriIndex = 0; qualifierIndex = 0; version = QTypeRevision::zero(); reserved = 0;
1167static_assert(
sizeof(
Import) == 20,
"Import structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
1177 return reinterpret_cast<
const Import*>((
reinterpret_cast<
const char *>(
this)) + offsetToImports + idx *
sizeof(Import));
1181 const quint32_le *offsetTable =
reinterpret_cast<
const quint32_le*>((
reinterpret_cast<
const char *>(
this)) + offsetToObjects);
1182 const quint32_le offset = offsetTable[idx];
1183 return reinterpret_cast<
const Object*>(
reinterpret_cast<
const char*>(
this) + offset);
1186static_assert(
sizeof(
QmlUnit) == 16,
"QmlUnit structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
1204 enum :
unsigned int {
1263 return reinterpret_cast<
const QmlUnit *>(
reinterpret_cast<
const char *>(
this) + offsetToQmlUnit);
1267 return reinterpret_cast<QmlUnit *>(
reinterpret_cast<
char *>(
this) + offsetToQmlUnit);
1271 return flags & Unit::IsSingleton;
1276 Q_ASSERT(idx < stringTableSize);
1277 const quint32_le *offsetTable =
reinterpret_cast<
const quint32_le*>((
reinterpret_cast<
const char *>(
this)) + offsetToStringTable);
1278 const quint32_le offset = offsetTable[idx];
1279 const String *str =
reinterpret_cast<
const String*>(
reinterpret_cast<
const char *>(
this) + offset);
1280 Q_ASSERT(str->size >= 0);
1281#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
1282 const QChar *characters =
reinterpret_cast<
const QChar *>(str + 1);
1283 if (flags & StaticData)
1284 return QString::fromRawData(characters, str->size);
1285 return QString(characters, str->size);
1287 const quint16_le *characters =
reinterpret_cast<
const quint16_le *>(str + 1);
1288 QString qstr(str->size, Qt::Uninitialized);
1289 QChar *ch = qstr.data();
1290 for (
int i = 0; i < str->size; ++i)
1291 ch[i] = QChar(quint16(characters[i]));
1297 const quint32_le *
classOffsetTable()
const {
return reinterpret_cast<
const quint32_le*>((
reinterpret_cast<
const char *>(
this)) + offsetToClassTable); }
1299 const quint32_le *
blockOffsetTable()
const {
return reinterpret_cast<
const quint32_le*>((
reinterpret_cast<
const char *>(
this)) + offsetToBlockTable); }
1302 const quint32_le *offsetTable = functionOffsetTable();
1303 const quint32_le offset = offsetTable[idx];
1304 return reinterpret_cast<
const Function*>(
reinterpret_cast<
const char *>(
this) + offset);
1308 const quint32_le *offsetTable = classOffsetTable();
1309 const quint32_le offset = offsetTable[idx];
1310 return reinterpret_cast<
const Class *>(
reinterpret_cast<
const char *>(
this) + offset);
1314 const quint32_le *offsetTable = templateObjectOffsetTable();
1315 const quint32_le offset = offsetTable[idx];
1316 return reinterpret_cast<
const TemplateObject *>(
reinterpret_cast<
const char *>(
this) + offset);
1320 const quint32_le *offsetTable = blockOffsetTable();
1321 const quint32_le offset = offsetTable[idx];
1322 return reinterpret_cast<
const Block *>(
reinterpret_cast<
const char *>(
this) + offset);
1325 const Lookup *
lookupTable()
const {
return reinterpret_cast<
const Lookup*>(
reinterpret_cast<
const char *>(
this) + offsetToLookupTable); }
1327 return reinterpret_cast<
const RegExp*>(
reinterpret_cast<
const char *>(
this) + offsetToRegexpTable + index *
sizeof(RegExp));
1330 return reinterpret_cast<
const quint64_le*>(
reinterpret_cast<
const char *>(
this) + offsetToConstantTable);
1334 const quint32_le *offsetTable =
reinterpret_cast<
const quint32_le *>(
reinterpret_cast<
const char *>(
this) + offsetToJSClassTable);
1335 const quint32_le offset = offsetTable[idx];
1336 const char *ptr =
reinterpret_cast<
const char *>(
this) + offset;
1338 *nMembers = klass->nMembers;
1343 return reinterpret_cast<
const TranslationData *>(
reinterpret_cast<
const char *>(
this) + offsetToTranslationTable);
1347 if ( translationTableSize == 0)
1349 return reinterpret_cast<
const quint32_le*>((
reinterpret_cast<
const char *>(
this))
1350 + offsetToTranslationTable
1351 + translationTableSize *
sizeof(CompiledData::TranslationData)); }
1354 if ( translationTableSize == 0)
1356 return reinterpret_cast<quint32_le*>((
reinterpret_cast<
char *>(
this))
1357 + offsetToTranslationTable
1358 + translationTableSize *
sizeof(CompiledData::TranslationData)); }
1360 const ImportEntry *
importEntryTable()
const {
return reinterpret_cast<
const ImportEntry *>(
reinterpret_cast<
const char *>(
this) + offsetToImportEntryTable); }
1365 const quint32_le *
moduleRequestTable()
const {
return reinterpret_cast<
const quint32_le*>((
reinterpret_cast<
const char *>(
this)) + offsetToModuleRequestTable); }
1367 bool verifyHeader(QDateTime expectedSourceTimeStamp, QString *errorString)
const;
1370static_assert(
sizeof(
Unit) == 200,
"Unit structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target");
1388 Iterator it = find(nameIndex);
1391 return *insert(nameIndex, loc);
1394 template <
typename CompiledObject>
1397 if (obj->inheritedTypeNameIndex != 0) {
1403 auto binding = obj->bindingsBegin();
1404 auto const bindingEnd = obj->bindingsEnd();
1405 for ( ; binding != bindingEnd; ++binding) {
1407 this->add(binding->propertyNameIndex
, binding->location
);
1410 auto ic = obj->inlineComponentsBegin();
1411 auto const icEnd = obj->inlineComponentsEnd();
1412 for (; ic != icEnd; ++ic) {
1413 this->add(ic->nameIndex
, ic->location
);
1417 template <
typename Iterator>
1420 for (; it != end; ++it)
1421 collectFromObject(*it);
1489 const QString &fileName = QString(),
const QString &finalUrlString = QString())
1504 const QString &fileName = QString(),
const QString &finalUrlString = QString())
1508#if Q_BYTE_ORDER == Q_BIG_ENDIAN
1509 delete [] constants;
1511 constants =
nullptr;
1513 m_finalUrlString.clear();
1517 qmlData = qmlUnit ? qmlUnit : data->qmlUnit();
1519#if Q_BYTE_ORDER == Q_BIG_ENDIAN
1520 StaticValue *bigEndianConstants =
new StaticValue[data->constantTableSize];
1521 const quint64_le *littleEndianConstants = data->constants();
1522 for (uint i = 0; i < data->constantTableSize; ++i)
1523 bigEndianConstants[i] = StaticValue::fromReturnedValue(littleEndianConstants[i]);
1524 constants = bigEndianConstants;
1526 constants =
reinterpret_cast<
const StaticValue*>(data->constants());
1529 m_fileName = !fileName.isEmpty() ? fileName : stringAt(data->sourceFileIndex);
1530 m_finalUrlString = !finalUrlString.isEmpty() ? finalUrlString : stringAt(data->finalUrlIndex);
1535 if (index < data->stringTableSize)
1536 return data->stringAtInternal(index);
1538 const qsizetype dynamicIndex = index - data->stringTableSize;
1539 Q_ASSERT(dynamicIndex < dynamicStrings.size());
1540 return dynamicStrings.at(dynamicIndex);
1550 case Binding::Type_Script:
1551 case Binding::Type_String:
1552 return stringAt(binding->stringIndex);
1554 return QStringLiteral(
"null");
1556 return binding->value.b ? QStringLiteral(
"true") : QStringLiteral(
"false");
1557 case Binding::Type_Number:
1558 return QString::number(bindingValueAsNumber(binding),
'g', QLocale::FloatingPointShortest);
1561 case Binding::Type_TranslationById:
1562 case Binding::Type_Translation:
1563 return stringAt(data->translations()[binding->value.translationDataIndex].stringIndex);
1572 return (binding->type() == CompiledData::Binding::Type_String)
1573 ? CompiledData::Binding::escapedString(stringAt(binding->stringIndex))
1574 : bindingValueAsString(binding);
1581 return constants[binding->value.constantValueIndex].doubleValue();
1586 const QUrl &url,
const QDateTime &sourceTimeStamp, QString *errorString);
1603 if (!m_url.isValid())
1604 m_url = QUrl(fileName());
1610 if (!m_finalUrl.isValid())
1611 m_finalUrl = QUrl(finalUrlString());
1620 return propertyCaches.isEmpty()
1621 ? QQmlPropertyCache::ConstPtr()
1622 : propertyCaches.at(0);
1634 Q_ASSERT(p && p->isComponentWrapper());
1635 return p->wrappedObjectIndex();
1647 for (
int i =
objectCount(), end = propertyCaches.count(); i < end; ++i) {
1649 Q_ASSERT(p && p->isComponentWrapper());
1650 if (p->wrappedObjectIndex() == index)
1658 for (uint i = 0; i <
qmlData->nObjects; ++i) {
1660 for (
auto it = object->inlineComponentsBegin(), end = object->inlineComponentsEnd();
1662 if (stringAt(it->nameIndex) == inlineComponentName)
1663 return it->objectIndex;
1671 bool verifyChecksum(
const CompiledData::DependentTypesHasher &dependencyHasher)
const;
1756 QString m_finalUrlString;
1758 mutable QQmlNullableValue<QUrl> m_url;
1759 mutable QQmlNullableValue<QUrl> m_finalUrl;
1774 template<
typename Char>
1777 const quint32_le oldFlags = mutableFlags();
1778 auto cleanup = qScopeGuard([
this, oldFlags]() { mutableFlags() = oldFlags; });
1779 mutableFlags() |= temporaryFlags;
1780 return writer(data<Char>(), size());
1783 static bool writeDataToFile(
const QString &outputFileName,
const char *data, quint32 size,
1784 QString *errorString)
1786#if QT_CONFIG(temporaryfile)
1787 QSaveFile cacheFile(outputFileName);
1788 if (!cacheFile.open(QIODevice::WriteOnly | QIODevice::Truncate)
1789 || cacheFile.write(data, size) != size
1790 || !cacheFile.commit()) {
1791 *errorString = cacheFile.errorString();
1795 errorString->clear();
1798 Q_UNUSED(outputFileName);
1799 *errorString = QStringLiteral(
"features.temporaryfile is disabled.");
1806 quint32 temporaryFlags;
1808 quint32_le &mutableFlags()
const
1810 return const_cast<
Unit *>(unit)->flags;
1813 template<
typename Char>
1814 const Char *data()
const
1816 Q_STATIC_ASSERT(
sizeof(Char) == 1);
1817 const Char *dataPtr;
1818 memcpy(&dataPtr, &unit,
sizeof(dataPtr));
1822 quint32 size()
const
1824 return unit->unitSize;
static bool writeDataToFile(const QString &outputFileName, const char *data, quint32 size, QString *errorString)
bool saveToDisk(const std::function< bool(const Char *, quint32)> &writer) const
Combined button and popup list for selecting options.
static const char magic_str[]
Q_DECLARE_TYPEINFO(QV4::CompiledData::JSClassMember, Q_PRIMITIVE_TYPE)
#define QV4_DATA_STRUCTURE_VERSION
Q_DECLARE_OPERATORS_FOR_FLAGS(QV4::CompiledData::ParameterType::Flags)
void setPropertyNameIndex(quint32 propertyNameIndex)
quint32 propertyNameIndex() const
void setIsReadOnly(bool isReadOnly)
Location location() const
void setReferenceLocation(Location referenceLocation)
void setNameIndex(quint32 nameIndex)
Location referenceLocation() const
void setIdIndex(quint32 idIndex)
void setLocation(Location location)
quint32 nameIndex() const
quint32_le propertyNameIndex
bool isNumberBinding() const
bool isSignalHandler() const
bool isFunctionExpression() const
bool hasSignalHandlerBindingFlag() const
bool evaluatesToString() const
bool isAttachedProperty() const
quint32_le_bitfield_union< FlagsField, TypeField > flagsAndType
bool hasFlag(Flag flag) const
bool isGroupProperty() const
bool isValueBindingNoAlias() const
bool isTranslationBinding() const
bool valueAsBoolean() const
static QString escapedString(const QString &string)
bool isValueBinding() const
quint32_le translationDataIndex
quint32_le constantValueIndex
bool isValueBindingToAlias() const
Q_DECLARE_FLAGS(Flags, Flag)
@ InitializerForReadOnlyDeclaration
@ IsSignalHandlerExpression
quint32_le compiledScriptIndex
const quint32_le * localsTable() const
quint16_le sizeOfLocalTemporalDeadZone
static size_t align(size_t a)
static int calculateSize(int nLocals)
static int calculateSize(int nStaticMethods, int nMethods)
static size_t align(size_t a)
quint32_le methodTableOffset
const Method * methodTable() const
quint32_le nStaticMethods
quint32_le constructorFunction
const CompiledObject * object
const CompiledData::Unit * unit
bool operator!=(const FunctionIterator &rhs) const
bool operator==(const FunctionIterator &rhs) const
FunctionIterator(const CompiledData::Unit *unit, const CompiledObject *object, int index)
const CompiledFunction * operator->() const
QString stringAt(uint index) const
std::unique_ptr< CompilationUnitMapper > backingFile
Q_QML_EXPORT bool saveToDisk(const QUrl &unitUrl, QString *errorString) const
QString bindingValueAsScriptString(const CompiledData::Binding *binding) const
QHash< QString, InlineComponentData > inlineComponentData
Q_QML_EXPORT ~CompilationUnit()
void setUnitData(const Unit *unitData, const QmlUnit *qmlUnit=nullptr, const QString &fileName=QString(), const QString &finalUrlString=QString())
int inlineComponentId(const QString &inlineComponentName) const
QMetaType metaType() const
double bindingValueAsNumber(const CompiledData::Binding *binding) const
void finalizeCompositeType(const QQmlType &type)
ResolvedTypeReference * resolvedType(int id) const
const CompiledData::Function CompiledFunction
const QQmlPrivate::AOTCompiledFunction * aotCompiledFunctions
bool valueTypesAreAssertable() const
CompilationUnit(const Unit *unitData, const QQmlPrivate::AOTCompiledFunction *aotCompiledFunctions, const QString &fileName=QString(), const QString &finalUrlString=QString())
int implicitComponentForObject(int index) const
ResolvedTypeReferenceMap resolvedTypes
bool isSharedLibrary() const
bool componentsAreBound() const
QList< BindingPropertyData > bindingPropertyDataPerObject
bool verifyChecksum(const CompiledData::DependentTypesHasher &dependencyHasher) const
QQmlType qmlTypeForComponent(const QString &inlineComponentName=QString()) const
FunctionIterator objectFunctionsBegin(const CompiledObject *object) const
QString finalUrlString() const
QQmlRefPointer< QQmlTypeNameCache > typeNameCache
FunctionIterator objectFunctionsEnd(const CompiledObject *object) const
bool nativeMethodsAcceptThisObjects() const
ListPropertyAssignBehavior listPropertyAssignBehavior() const
const Unit * unitData() const
ListPropertyAssignBehavior
const CompiledObject * objectAt(int index) const
int resolvedIndex(int index) const
bool valueTypesAreAddressable() const
const CompiledData::Object CompiledObject
bool ignoresFunctionSignature() const
bool valueTypesAreCopied() const
const CompiledData::Binding CompiledBinding
const CompiledData::Import * importAt(int index) const
QQmlPropertyCacheVector propertyCaches
QList< QQmlRefPointer< QQmlScriptData > > dependentScripts
QStringList dynamicStrings
Q_QML_EXPORT bool loadFromDisk(const QUrl &url, const QDateTime &sourceTimeStamp, QString *errorString)
QString bindingValueAsString(const CompiledData::Binding *binding) const
QQmlPropertyCache::ConstPtr rootPropertyCache() const
const StaticValue * constants
const EnumValue * enumValueAt(int idx) const
const EnumValue * enumValuesEnd() const
const EnumValue * enumValuesBegin() const
static int calculateSize(int nEnumValues)
int enumValueCount() const
quint32_le nestedFunctionIndex
quint16_le firstTemporalDeadZoneRegister
size_t labelInfosOffset() const
const quint32_le * localsTable() const
static size_t align(size_t a)
const CodeOffsetToLineAndStatement * lineAndStatementNumberTable() const
quint16_le sizeOfRegisterTemporalDeadZone
quint16_le sizeOfLocalTemporalDeadZone
const char * code() const
size_t lineAndStatementNumberOffset() const
static int calculateSize(int nFormals, int nLocals, int nLinesAndStatements, int labelInfoSize, int codeSize)
const Parameter * formalsTable() const
const Parameter * formalsEnd() const
const Parameter * formalsBegin() const
const quint32_le * labelInfoTable() const
quint16_le nLineAndStatementNumbers
quint32_le qualifierIndex
InlineComponentData(const QQmlType &qmlType, int objectIndex, int nameIndex)
InlineComponentData()=default
void set(quint32 nameOffset, bool isAccessor)
quint32 nameOffset() const
static int calculateSize(int nMembers)
Location(quint32 l, quint32 c)
friend size_t qHash(const Location &location, size_t seed=0)
bool operator<(const Location &other) const
friend bool comparesEqual(const Location &a, const Location &b) noexcept
Lookup(Type type, Mode mode, quint32 nameIndex)
quint32 nameIndex() const
@ Type_QmlContextPropertyGetter
void setFlags(Flags flags)
quint32_le offsetToBindings
TableIterator< Enum, Object, &Object::enumAt > EnumIterator
EnumIterator enumsBegin() const
Q_DECLARE_FLAGS(Flags, Flag)
quint32_le offsetToAliases
quint32_le offsetToProperties
int propertyCount() const
quint32_le offsetToSignals
const RequiredPropertyExtraData * requiredPropertyExtraDataAt(int idx) const
EnumIterator enumsEnd() const
const Enum * enumAt(int idx) const
RequiredPropertyExtraDataIterator requiredPropertyExtraDataEnd() const
bool hasAliasAsDefaultProperty() const
quint32_le offsetToInlineComponents
const RequiredPropertyExtraData * requiredPropertyExtraDataTable() const
TableIterator< Signal, Object, &Object::signalAt > SignalIterator
const Binding * bindingsEnd() const
quint32_le inheritedTypeNameIndex
bool hasFlag(Flag flag) const
const Property * propertyTable() const
@ HasCustomParserBindings
@ IsPartOfInlineComponent
SignalIterator signalsBegin() const
quint32_le_bitfield_union< FlagsField, DefaultPropertyIsAliasField, IdField > flagsAndDefaultPropertyIsAliasAndId
quint32_le offsetToNamedObjectsInComponent
int namedObjectsInComponentCount() const
InlineComponentIterator inlineComponentsEnd() const
qint32_le indexOfDefaultPropertyOrAlias
int functionCount() const
const Alias * aliasTable() const
quint16_le nInlineComponents
void setObjectId(qint32 id)
quint32_le offsetToRequiredPropertyExtraData
const InlineComponent * inlineComponentAt(int idx) const
const Property * propertiesEnd() const
quint32_le nNamedObjectsInComponent
const Binding * bindingTable() const
quint16_le nRequiredPropertyExtraData
const Signal * signalAt(int idx) const
const Property * propertiesBegin() const
Location locationOfIdProperty
const quint32_le * functionOffsetTable() const
static int calculateSizeExcludingSignalsAndEnums(int nFunctions, int nProperties, int nAliases, int nEnums, int nSignals, int nBindings, int nNamedObjectsInComponent, int nInlineComponents, int nRequiredPropertyExtraData)
TableIterator< InlineComponent, Object, &Object::inlineComponentAt > InlineComponentIterator
const InlineComponent * inlineComponentTable() const
InlineComponentIterator inlineComponentsBegin() const
TableIterator< RequiredPropertyExtraData, Object, &Object::requiredPropertyExtraDataAt > RequiredPropertyExtraDataIterator
SignalIterator signalsEnd() const
const Alias * aliasesEnd() const
quint32_le offsetToFunctions
const Binding * bindingsBegin() const
RequiredPropertyExtraDataIterator requiredPropertyExtraDataBegin() const
void setHasAliasAsDefaultProperty(bool defaultAlias)
int inlineComponentCount() const
const Alias * aliasesBegin() const
const quint32_le * namedObjectsInComponentTable() const
quint32 typeNameIndexOrCommonType() const
void set(Flags flags, quint32 typeNameIndexOrCommonType)
bool indexIsCommonType() const
Q_DECLARE_FLAGS(Flags, Flag)
void setNameIndex(int nameIndex)
void setIsList(bool isList)
void setIsReadOnly(bool isReadOnly)
bool isCommonType() const
void setTypeNameIndex(int nameIndex)
void setIsVirtual(bool isVirtual)
void setIsFinal(bool isFinal)
quint32 nameIndex() const
quint32_le_bitfield_union< CommonTypeOrTypeNameIndexField, IsRequiredField, IsCommonTypeField, IsListField, IsReadOnlyField > data
quint32_le_bitfield_union< NameIndexField, IsVirtualField, IsOverrideField, IsFinalField > nameIndexAndVirtSpecifiers
void setIsOverride(bool isOverride)
uint commonTypeOrTypeNameIndex() const
int typeNameIndex() const
void setIsRequired(bool isRequired)
void setCommonType(CommonType t)
CommonType commonType() const
quint32_le offsetToObjects
const Object * objectAt(int idx) const
const Import * importAt(int idx) const
quint32_le offsetToImports
quint32 stringIndex() const
RegExp(quint32 flags, quint32 stringIndex)
Q_DECLARE_FLAGS(Flags, Flag)
bool addToHash(QCryptographicHash *hash, QHash< quintptr, QByteArray > *checksums) const
int parameterCount() const
const Parameter * parametersBegin() const
static int calculateSize(int nParameters)
const Parameter * parametersEnd() const
const Parameter * parameterAt(int idx) const
static int calculateSize(const QString &str)
bool operator==(const TableIterator &rhs) const
const Container * container
const ItemType * operator->()
bool operator!=(const TableIterator &rhs) const
TableIterator(const Container *container, int index)
static int calculateSize(int size)
uint stringIndexAt(uint i) const
static size_t align(size_t a)
uint rawStringIndexAt(uint i) const
const quint32_le * stringTable() const
void collectFromObject(const CompiledObject *obj)
TypeReference & add(int nameIndex, const Location &loc)
void collectFromObjects(Iterator it, Iterator end)
TypeReference(const Location &loc)
quint32_le offsetToLookupTable
quint32_le offsetToIndirectExportEntryTable
quint32_le offsetToJSClassTable
quint32_le jsClassTableSize
quint32_le * translationContextIndex()
quint32_le offsetToTemplateObjectTable
quint32_le functionTableSize
const TranslationData * translations() const
quint32_le offsetToRegexpTable
quint32_le importEntryTableSize
const ExportEntry * indirectExportEntryTable() const
const quint64_le * constants() const
quint32_le starExportEntryTableSize
quint32_le lookupTableSize
qint32_le indexOfRootFunction
QString stringAtInternal(uint idx) const
quint32_le offsetToLocalExportEntryTable
const quint32_le * functionOffsetTable() const
bool verifyHeader(QDateTime expectedSourceTimeStamp, QString *errorString) const
quint32_le offsetToClassTable
quint32_le classTableSize
quint32_le offsetToStringTable
quint32_le offsetToQmlUnit
const Function * functionAt(int idx) const
const TemplateObject * templateObjectAt(int idx) const
quint32_le offsetToFunctionTable
quint32_le offsetToStarExportEntryTable
const ExportEntry * starExportEntryTable() const
const Lookup * lookupTable() const
quint32_le offsetToModuleRequestTable
quint32_le translationTableSize
const RegExp * regexpAt(int index) const
const Block * blockAt(int idx) const
const ExportEntry * localExportEntryTable() const
const quint32_le * translationContextIndex() const
const quint32_le * classOffsetTable() const
@ ListPropertyAssignReplace
@ FunctionSignaturesIgnored
@ ListPropertyAssignReplaceIfDefault
@ ListPropertyAssignReplaceIfNotDefault
@ NativeMethodsAcceptThisObject
const quint32_le * moduleRequestTable() const
quint32_le sourceFileIndex
quint32_le moduleRequestTableSize
quint32_le offsetToTranslationTable
quint32_le blockTableSize
quint32_le templateObjectTableSize
quint32_le localExportEntryTableSize
const Class * classAt(int idx) const
quint32_le regexpTableSize
quint32_le offsetToImportEntryTable
quint32_le stringTableSize
quint32_le constantTableSize
const ImportEntry * importEntryTable() const
qint64_le sourceTimeStamp
char dependencyMD5Checksum[16]
const QmlUnit * qmlUnit() const
quint32_le offsetToConstantTable
quint32_le offsetToBlockTable
const quint32_le * blockOffsetTable() const
quint32_le indirectExportEntryTableSize
const JSClassMember * jsClassAt(int idx, int *nMembers) const
const quint32_le * templateObjectOffsetTable() const