1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
|
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
// Qt-Security score:significant
#include "qqmljsregistercontent_p.h"
#include <variant>
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
struct QQmlJSRegisterContentPrivate
{
public:
using ContentVariant = QQmlJSRegisterContent::ContentVariant;
enum class Kind : size_t {
Type, Property, Enum, Method, ImportNamespace, Conversion, MethodCall
};
struct ConvertedTypes
{
QList<QQmlJSRegisterContent> origins;
QQmlJSScope::ConstPtr result;
QQmlJSRegisterContent resultScope;
friend size_t qHash(const ConvertedTypes &types, size_t seed = 0)
{
return qHashMulti(seed, types.origins, types.result, types.resultScope);
}
friend bool operator==(const ConvertedTypes &a, const ConvertedTypes &b)
{
return a.origins == b.origins && a.result == b.result && a.resultScope == b.resultScope;
}
friend bool operator!=(const ConvertedTypes &a, const ConvertedTypes &b)
{
return !(a == b);
}
};
struct PropertyLookup
{
QQmlJSMetaProperty property;
int baseLookupIndex = QQmlJSRegisterContent::InvalidLookupIndex;
int resultLookupIndex = QQmlJSRegisterContent::InvalidLookupIndex;
friend size_t qHash(const PropertyLookup &property, size_t seed = 0)
{
return qHashMulti(
seed, property.property, property.baseLookupIndex, property.resultLookupIndex);
}
friend bool operator==(const PropertyLookup &a, const PropertyLookup &b)
{
return a.baseLookupIndex == b.baseLookupIndex
&& a.resultLookupIndex == b.resultLookupIndex
&& a.property == b.property;
}
friend bool operator!=(const PropertyLookup &a, const PropertyLookup &b)
{
return !(a == b);
}
};
using Content = std::variant<
std::pair<QQmlJSScope::ConstPtr, int>,
PropertyLookup,
std::pair<QQmlJSMetaEnum, QString>,
std::pair<QList<QQmlJSMetaMethod>, QQmlJSScope::ConstPtr>,
std::pair<uint, QQmlJSScope::ConstPtr>,
ConvertedTypes,
QQmlJSMetaMethod
>;
friend size_t qHash(const QQmlJSRegisterContentPrivate ®isterContent, size_t seed = 0)
{
seed = qHashMulti(
seed, registerContent.m_storage, registerContent.m_content.index(),
registerContent.m_variant, registerContent.m_scope);
switch (Kind(registerContent.m_content.index())) {
case Kind::Type:
return qHash(std::get<std::pair<QQmlJSScope::ConstPtr, int>>(registerContent.m_content),
seed);
case Kind::Property:
return qHash(std::get<PropertyLookup>(registerContent.m_content), seed);
case Kind::Enum:
return qHash(std::get<std::pair<QQmlJSMetaEnum, QString>>(registerContent.m_content),
seed);
case Kind::Method:
return qHash(std::get<std::pair<QList<QQmlJSMetaMethod>, QQmlJSScope::ConstPtr>>(
registerContent.m_content), seed);
case Kind::ImportNamespace:
return qHash(std::get<std::pair<uint, QQmlJSScope::ConstPtr>>(
registerContent.m_content), seed);
case Kind::Conversion:
return qHash(std::get<ConvertedTypes>(registerContent.m_content), seed);
case Kind::MethodCall:
return qHash(std::get<QQmlJSMetaMethod>(registerContent.m_content), seed);
}
Q_UNREACHABLE_RETURN(seed);
}
friend bool operator==(
const QQmlJSRegisterContentPrivate &a, const QQmlJSRegisterContentPrivate &b)
{
return a.m_storage == b.m_storage && a.m_variant == b.m_variant
&& a.m_scope == b.m_scope && a.m_content == b.m_content;
}
friend bool operator!=(
const QQmlJSRegisterContentPrivate &a, const QQmlJSRegisterContentPrivate &b)
{
return !(a == b);
}
QQmlJSRegisterContent m_storage;
QQmlJSRegisterContent m_scope;
Content m_content;
ContentVariant m_variant = ContentVariant::Unknown;
QQmlJSRegisterContent m_original;
QQmlJSRegisterContent m_shadowed;
int resultLookupIndex() const
{
switch (Kind(m_content.index())) {
case Kind::Type:
return std::get<std::pair<QQmlJSScope::ConstPtr, int>>(m_content).second;
case Kind::Property:
return std::get<PropertyLookup>(m_content).resultLookupIndex;
default:
return QQmlJSRegisterContent::InvalidLookupIndex;
}
}
void setType(const QQmlJSScope::ConstPtr &type)
{
switch (Kind(m_content.index())) {
case Kind::Type:
std::get<std::pair<QQmlJSScope::ConstPtr, int>>(m_content).first = type;
return;
case Kind::Property:
std::get<PropertyLookup>(m_content).property.setType(type);
return;
case Kind::Enum:
std::get<std::pair<QQmlJSMetaEnum, QString>>(m_content).first.setType(type);
return;
case Kind::Method:
std::get<std::pair<QList<QQmlJSMetaMethod>, QQmlJSScope::ConstPtr>>(m_content)
.second = type;
return;
case Kind::ImportNamespace:
std::get<std::pair<uint, QQmlJSScope::ConstPtr>>(m_content).second = type;
return;
case Kind::Conversion:
std::get<ConvertedTypes>(m_content).result = type;
return;
case Kind::MethodCall:
std::get<QQmlJSMetaMethod>(m_content).setReturnType({ type });
return;
}
Q_UNREACHABLE_RETURN();
}
private:
friend class QQmlJSRegisterContentPool;
QQmlJSRegisterContentPrivate() = default;
~QQmlJSRegisterContentPrivate() = default;
QQmlJSRegisterContentPrivate(const QQmlJSRegisterContentPrivate &) = default;
QQmlJSRegisterContentPrivate(QQmlJSRegisterContentPrivate &&) = default;
QQmlJSRegisterContentPrivate &operator=(const QQmlJSRegisterContentPrivate &) = default;
QQmlJSRegisterContentPrivate &operator=(QQmlJSRegisterContentPrivate &&) = default;
};
bool QQmlJSRegisterContent::isValid() const
{
return !containedType().isNull();
};
QString QQmlJSRegisterContent::descriptiveName() const
{
using Kind = QQmlJSRegisterContentPrivate::Kind;
if (!d || (!d->m_storage.isValid() && containedType().isNull()))
return u"(invalid type)"_s;
const auto scope = [this]() -> QString {
if (!d->m_scope.isValid())
return u"(invalid type)::"_s;
const QQmlJSScope::ConstPtr scopeContained = d->m_scope.containedType();
if (scopeContained.isNull())
return u"(invalid type)::"_s;
return (scopeContained->internalName().isEmpty()
? (scopeContained->filePath().isEmpty()
? u"??"_s
: (u"(component in "_s + scopeContained->filePath() + u")"_s))
: scopeContained->internalName())
+ u"::"_s;
};
QString result;
switch (Kind(d->m_content.index())) {
case Kind::Type: {
const QQmlJSScope::ConstPtr contained = type();
result += contained->internalName();
const QQmlJSScope::ConstPtr stored = d->m_storage.containedType();
if (stored && stored->internalName() != contained->internalName())
result += u" stored as "_s + stored->internalName();
return result;
}
case Kind::Property: {
const QQmlJSMetaProperty prop = property();
result += scope() + prop.propertyName() + u" with type "_s + prop.typeName();
QStringList details;
if (original().isValid() && !prop.type()->internalName().isEmpty())
details.append(u"adjusted to " + prop.type()->internalName());
const QQmlJSScope::ConstPtr stored = d->m_storage.containedType();
if (stored && stored->internalName() != prop.typeName())
details.append(u"stored as "_s + stored->internalName());
if (!details.isEmpty())
result += u" (%1)"_s.arg(details.join(u", "));
return result;
}
case Kind::Method: {
const auto methods = method();
if (methods.isEmpty())
result = scope() + u"(unknown method)"_s;
else
result = scope() + methods[0].methodName() + u"(...)"_s;
if (d->m_storage.isValid())
return result + u" (stored as "_s + d->m_storage.containedType()->internalName() + u")";
return result;
}
case Kind::Enum: {
const QString enumName = enumeration().name();
const QString memberName = enumMember();
if (memberName.isEmpty())
result = scope() + enumName;
else
result = scope() + enumName + u"::"_s + memberName;
if (d->m_storage.isValid())
return result + u" (stored as "_s + d->m_storage.containedType()->internalName() + u")";
return result;
}
case Kind::ImportNamespace: {
return u"import namespace %1"_s.arg(importNamespace());
}
case Kind::Conversion: {
return u"conversion to %1"_s.arg(conversionResultType()->internalName());
}
case Kind::MethodCall: {
const QQmlJSMetaMethod &method = std::get<QQmlJSMetaMethod>(d->m_content);
return u"call to method %1, returning %2"_s.arg(
method.methodName(), method.returnTypeName());
}
}
Q_UNREACHABLE_RETURN(result + u"wat?"_s);
}
QString QQmlJSRegisterContent::containedTypeName() const
{
QQmlJSScope::ConstPtr type;
switch (variant()) {
case QQmlJSRegisterContent::MetaType:
type = scopeType();
break;
default:
type = containedType();
break;
}
return QQmlJSScope::prettyName(
type->internalName().isEmpty() ? type->baseTypeName() : type->internalName());
}
bool QQmlJSRegisterContent::isType() const
{
return d && d->m_content.index() == size_t(QQmlJSRegisterContentPrivate::Kind::Type);
}
bool QQmlJSRegisterContent::isProperty() const
{
return d && d->m_content.index() == size_t(QQmlJSRegisterContentPrivate::Kind::Property);
}
bool QQmlJSRegisterContent::isEnumeration() const
{
return d && d->m_content.index() == size_t(QQmlJSRegisterContentPrivate::Kind::Enum);
}
bool QQmlJSRegisterContent::isMethod() const
{
return d && d->m_content.index() == size_t(QQmlJSRegisterContentPrivate::Kind::Method);
}
bool QQmlJSRegisterContent::isImportNamespace() const
{
return d && d->m_content.index() == size_t(QQmlJSRegisterContentPrivate::Kind::ImportNamespace);
}
bool QQmlJSRegisterContent::isConversion() const
{
return d && d->m_content.index() == size_t(QQmlJSRegisterContentPrivate::Kind::Conversion);
}
bool QQmlJSRegisterContent::isMethodCall() const
{
return d && d->m_content.index() == size_t(QQmlJSRegisterContentPrivate::Kind::MethodCall);
}
bool QQmlJSRegisterContent::isList() const
{
using Kind = QQmlJSRegisterContentPrivate::Kind;
if (!d)
return false;
switch (Kind(d->m_content.index())) {
case Kind::Type:
return std::get<std::pair<QQmlJSScope::ConstPtr, int>>(d->m_content).first
->accessSemantics() == QQmlJSScope::AccessSemantics::Sequence;
case Kind::Property:
return std::get<QQmlJSRegisterContentPrivate::PropertyLookup>(d->m_content).property.type()
->accessSemantics() == QQmlJSScope::AccessSemantics::Sequence;
case Kind::Conversion:
return std::get<QQmlJSRegisterContentPrivate::ConvertedTypes>(d->m_content).result
->accessSemantics() == QQmlJSScope::AccessSemantics::Sequence;
case Kind::MethodCall:
return std::get<QQmlJSMetaMethod>(d->m_content).returnType()
->accessSemantics() == QQmlJSScope::AccessSemantics::Sequence;
default:
return false;
}
}
bool QQmlJSRegisterContent::isWritable() const
{
using Kind = QQmlJSRegisterContentPrivate::Kind;
if (!d)
return false;
switch (Kind(d->m_content.index())) {
case Kind::Property:
return std::get<QQmlJSRegisterContentPrivate::PropertyLookup>(d->m_content)
.property.isWritable();
// TODO: What can we actually write?
default:
break;
}
return true;
}
bool QQmlJSRegisterContent::isJavaScriptReturnValue() const
{
return d && isMethodCall() && std::get<QQmlJSMetaMethod>(d->m_content).isJavaScriptFunction();
}
/*!
* \internal
* Precondition: This is an attachment.
* Return the type that does the attaching.
*/
QQmlJSRegisterContent QQmlJSRegisterContent::attacher() const
{
Q_ASSERT(d);
Q_ASSERT(d->m_variant == Attachment);
return scope();
}
/*!
* \internal
* Precondition: This is an attachment.
* Return the type of the object the attachment is attached to.
*/
QQmlJSRegisterContent QQmlJSRegisterContent::attachee() const
{
Q_ASSERT(d);
Q_ASSERT(d->m_variant == Attachment);
QQmlJSRegisterContent attachee = attacher().scope();
while (attachee.variant() == ModulePrefix)
attachee = attachee.scope();
return attachee;
}
QQmlJSScope::ConstPtr QQmlJSRegisterContent::storedType() const
{
return d ? d->m_storage.containedType() : QQmlJSScope::ConstPtr();
}
QQmlJSScope::ConstPtr QQmlJSRegisterContent::containedType() const
{
if (!d)
return QQmlJSScope::ConstPtr();
if (isType())
return type();
if (isProperty())
return std::get<QQmlJSRegisterContentPrivate::PropertyLookup>(d->m_content).property.type();
if (isEnumeration())
return std::get<std::pair<QQmlJSMetaEnum, QString>>(d->m_content).first.type();
if (isMethod())
return methodType();
if (isImportNamespace())
return importNamespaceType();
if (isConversion())
return conversionResultType();
if (isMethodCall())
return std::get<QQmlJSMetaMethod>(d->m_content).returnType();
Q_UNREACHABLE_RETURN({});
}
QQmlJSScope::ConstPtr QQmlJSRegisterContent::scopeType() const
{
return d ? d->m_scope.containedType() : QQmlJSScope::ConstPtr();
}
QQmlJSScope::ConstPtr QQmlJSRegisterContent::type() const
{
Q_ASSERT(isType());
return std::get<std::pair<QQmlJSScope::ConstPtr, int>>(d->m_content).first;
}
QQmlJSMetaProperty QQmlJSRegisterContent::property() const
{
Q_ASSERT(isProperty());
return std::get<QQmlJSRegisterContentPrivate::PropertyLookup>(d->m_content).property;
}
int QQmlJSRegisterContent::baseLookupIndex() const
{
Q_ASSERT(isProperty());
return std::get<QQmlJSRegisterContentPrivate::PropertyLookup>(d->m_content).baseLookupIndex;
}
int QQmlJSRegisterContent::resultLookupIndex() const
{
return d ? d->resultLookupIndex() : InvalidLookupIndex;
}
QQmlJSMetaEnum QQmlJSRegisterContent::enumeration() const
{
Q_ASSERT(isEnumeration());
return std::get<std::pair<QQmlJSMetaEnum, QString>>(d->m_content).first;
}
QString QQmlJSRegisterContent::enumMember() const
{
Q_ASSERT(isEnumeration());
return std::get<std::pair<QQmlJSMetaEnum, QString>>(d->m_content).second;
}
QList<QQmlJSMetaMethod> QQmlJSRegisterContent::method() const
{
Q_ASSERT(isMethod());
return std::get<std::pair<QList<QQmlJSMetaMethod>, QQmlJSScope::ConstPtr>>(d->m_content).first;
}
QQmlJSScope::ConstPtr QQmlJSRegisterContent::methodType() const
{
Q_ASSERT(isMethod());
return std::get<std::pair<QList<QQmlJSMetaMethod>, QQmlJSScope::ConstPtr>>(d->m_content).second;
}
uint QQmlJSRegisterContent::importNamespace() const
{
Q_ASSERT(isImportNamespace());
return std::get<std::pair<uint, QQmlJSScope::ConstPtr>>(d->m_content).first;
}
QQmlJSScope::ConstPtr QQmlJSRegisterContent::importNamespaceType() const
{
Q_ASSERT(isImportNamespace());
return std::get<std::pair<uint, QQmlJSScope::ConstPtr>>(d->m_content).second;
}
QQmlJSScope::ConstPtr QQmlJSRegisterContent::conversionResultType() const
{
Q_ASSERT(isConversion());
return std::get<QQmlJSRegisterContentPrivate::ConvertedTypes>(d->m_content).result;
}
QQmlJSRegisterContent QQmlJSRegisterContent::conversionResultScope() const
{
Q_ASSERT(isConversion());
return std::get<QQmlJSRegisterContentPrivate::ConvertedTypes>(d->m_content).resultScope;
}
QList<QQmlJSRegisterContent> QQmlJSRegisterContent::conversionOrigins() const
{
Q_ASSERT(isConversion());
return std::get<QQmlJSRegisterContentPrivate::ConvertedTypes>(d->m_content).origins;
}
QQmlJSMetaMethod QQmlJSRegisterContent::methodCall() const
{
Q_ASSERT(isMethodCall());
return std::get<QQmlJSMetaMethod>(d->m_content);
}
QQmlJSRegisterContent::ContentVariant QQmlJSRegisterContent::variant() const
{
return d ? d->m_variant : Unknown;
}
QQmlJSRegisterContent QQmlJSRegisterContent::scope() const
{
return d ? d->m_scope : QQmlJSRegisterContent();
}
QQmlJSRegisterContent QQmlJSRegisterContent::storage() const
{
return d ? d->m_storage : QQmlJSRegisterContent();
}
QQmlJSRegisterContent QQmlJSRegisterContent::original() const
{
return d ? d->m_original : QQmlJSRegisterContent();
}
QQmlJSRegisterContent QQmlJSRegisterContent::shadowed() const
{
return d ? d->m_shadowed : QQmlJSRegisterContent();
}
QQmlJSRegisterContentPool::QQmlJSRegisterContentPool() = default;
QQmlJSRegisterContentPool::~QQmlJSRegisterContentPool() = default;
QQmlJSRegisterContent QQmlJSRegisterContentPool::createType(
const QQmlJSScope::ConstPtr &type, int resultLookupIndex,
QQmlJSRegisterContent::ContentVariant variant, QQmlJSRegisterContent scope)
{
QQmlJSRegisterContentPrivate *result = create(scope, variant);
result->m_content = std::make_pair(type, resultLookupIndex);
return result;
}
QQmlJSRegisterContent QQmlJSRegisterContentPool::createProperty(
const QQmlJSMetaProperty &property, int baseLookupIndex, int resultLookupIndex,
QQmlJSRegisterContent::ContentVariant variant, QQmlJSRegisterContent scope)
{
QQmlJSRegisterContentPrivate *result = create(scope, variant);
result->m_content = QQmlJSRegisterContentPrivate::PropertyLookup {
property,
baseLookupIndex,
resultLookupIndex
};
return result;
}
QQmlJSRegisterContent QQmlJSRegisterContentPool::createEnumeration(
const QQmlJSMetaEnum &enumeration, const QString &enumMember,
QQmlJSRegisterContent::ContentVariant variant, QQmlJSRegisterContent scope)
{
QQmlJSRegisterContentPrivate *result = create(scope, variant);
result->m_content = std::make_pair(enumeration, enumMember);
return result;
}
QQmlJSRegisterContent QQmlJSRegisterContentPool::createMethod(
const QList<QQmlJSMetaMethod> &methods, const QQmlJSScope::ConstPtr &methodType,
QQmlJSRegisterContent::ContentVariant variant, QQmlJSRegisterContent scope)
{
// Methods can only be stored in QJSValue.
Q_ASSERT(methodType->internalName() == u"QJSValue"_s);
QQmlJSRegisterContentPrivate *result = create(scope, variant);
result->m_content = std::make_pair(methods, methodType);
return result;
}
QQmlJSRegisterContent QQmlJSRegisterContentPool::createMethodCall(
const QQmlJSMetaMethod &method, const QQmlJSScope::ConstPtr &returnType,
QQmlJSRegisterContent scope)
{
QQmlJSRegisterContentPrivate *result = create(scope, ContentVariant::MethodCall);
QQmlJSMetaMethod resultMethod = method;
resultMethod.setReturnType({ returnType });
resultMethod.setReturnTypeName(returnType->internalName());
result->m_content = std::move(resultMethod);
return result;
}
QQmlJSRegisterContent QQmlJSRegisterContentPool::createImportNamespace(
uint importNamespaceStringId, const QQmlJSScope::ConstPtr &importNamespaceType,
QQmlJSRegisterContent::ContentVariant variant, QQmlJSRegisterContent scope)
{
QQmlJSRegisterContentPrivate *result = create(scope, variant);
result->m_content = std::make_pair(importNamespaceStringId, importNamespaceType);
return result;
}
QQmlJSRegisterContent QQmlJSRegisterContentPool::createConversion(
const QList<QQmlJSRegisterContent> &origins, const QQmlJSScope::ConstPtr &conversion,
QQmlJSRegisterContent conversionScope, ContentVariant variant,
QQmlJSRegisterContent scope)
{
QQmlJSRegisterContentPrivate *result = create(scope, variant);
result->m_content = QQmlJSRegisterContentPrivate::ConvertedTypes {
origins,
conversion,
conversionScope
};
return result;
}
QQmlJSRegisterContent QQmlJSRegisterContentPool::storedIn(
QQmlJSRegisterContent content, const QQmlJSScope::ConstPtr &newStoredType)
{
Q_ASSERT(content.d);
QQmlJSRegisterContentPrivate *result = clone(content.d);
result->m_storage = createType(
newStoredType, QQmlJSRegisterContent::InvalidLookupIndex, ContentVariant::Storage);
return result;
}
QQmlJSRegisterContent QQmlJSRegisterContentPool::castTo(
QQmlJSRegisterContent content, const QQmlJSScope::ConstPtr &newContainedType)
{
// This is not a conversion but a run time cast. It may result in null or undefined.
QQmlJSRegisterContentPrivate *result = create(content, ContentVariant::Cast);
result->m_content = std::make_pair(newContainedType, result->resultLookupIndex());
return result;
}
void QQmlJSRegisterContentPool::storeType(
QQmlJSRegisterContent content, const QQmlJSScope::ConstPtr &stored)
{
QQmlJSRegisterContentPrivate *d = content.d;
Q_ASSERT(d);
Q_ASSERT(d->m_storage.isNull());
d->m_storage = createType(
stored, QQmlJSRegisterContent::InvalidLookupIndex, ContentVariant::Storage);
}
void QQmlJSRegisterContentPool::adjustType(
QQmlJSRegisterContent content, const QQmlJSScope::ConstPtr &adjusted)
{
QQmlJSRegisterContentPrivate *d = content.d;
Q_ASSERT(d);
Q_ASSERT(d->m_original.isNull());
d->m_original = clone(d);
d->setType(adjusted);
}
void QQmlJSRegisterContentPool::generalizeType(
QQmlJSRegisterContent content, const QQmlJSScope::ConstPtr &generalized)
{
QQmlJSRegisterContentPrivate *d = content.d;
Q_ASSERT(d);
Q_ASSERT(d->m_shadowed.isNull());
d->m_shadowed = clone(d);
d->setType(generalized);
}
void QQmlJSRegisterContentPool::setAllocationMode(AllocationMode mode)
{
m_checkpoint = (mode == Temporary) ? m_pool.size() : -1;
}
void QQmlJSRegisterContentPool::clearTemporaries()
{
if (m_checkpoint != -1)
m_pool.resize(m_checkpoint);
}
QQmlJSRegisterContentPrivate *QQmlJSRegisterContentPool::clone(
const QQmlJSRegisterContentPrivate *from)
{
m_pool.push_back(std::unique_ptr<QQmlJSRegisterContentPrivate, Deleter>(from
? new QQmlJSRegisterContentPrivate(*from)
: new QQmlJSRegisterContentPrivate));
return m_pool.back().get();
}
QQmlJSRegisterContentPrivate *QQmlJSRegisterContentPool::create(
QQmlJSRegisterContent scope, ContentVariant variant)
{
QQmlJSRegisterContentPrivate *result = create();
result->m_scope = scope;
result->m_variant = variant;
return result;
}
QT_END_NAMESPACE
|