19#include <qqmldomlinewriterfactory_p.h>
21#include <QtQml/private/qqmljslexer_p.h>
22#include <QtQml/private/qqmljsparser_p.h>
23#include <QtQml/private/qqmljsengine_p.h>
24#include <QtQml/private/qqmljsastvisitor_p.h>
25#include <QtQml/private/qqmljsast_p.h>
27#include <QtCore/QCborArray>
28#include <QtCore/QCborMap>
29#include <QtCore/QDebug>
31#include <QtCore/QFile>
32#include <QtCore/QFileInfo>
33#include <QtCore/QJsonDocument>
34#include <QtCore/QJsonValue>
35#include <QtCore/QMutexLocker>
36#include <QtCore/QRegularExpression>
37#include <QtCore/QScopeGuard>
38#include <QtCore/QtGlobal>
39#include <QtCore/QTimeZone>
46Q_LOGGING_CATEGORY(writeOutLog,
"qt.qmldom.writeOut", QtWarningMsg);
52template<
class... TypeList>
61
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
79 "Types in ElementT must either be a pointer to a class inheriting "
80 "from DomBase or (for internal Dom structures) implement a smart "
81 "pointer pointing to a class inheriting from DomBase");
85
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
137 static QMap<DomType,QString> map = [](){
138 QMetaEnum metaEnum = QMetaEnum::fromType<DomType>();
139 QMap<DomType,QString> res;
140 for (
int i = 0; i < metaEnum.keyCount(); ++ i) {
141 res[
DomType(metaEnum.value(i))] = QString::fromUtf8(metaEnum.key(i));
150 QString res = domTypeToStringMap().value(k);
152 return QString::number(
int(k));
159 static QMap<DomKind, QString> map = []() {
160 QMetaEnum metaEnum = QMetaEnum::fromType<DomKind>();
161 QMap<DomKind, QString> res;
162 for (
int i = 0; i < metaEnum.keyCount(); ++i) {
163 res[DomKind(metaEnum.value(i))] = QString::fromUtf8(metaEnum.key(i));
172 return domKindToStringMap().value(k, QString::number(
int(k)));
230 return parent.canonicalFilePath();
236 qCWarning(writeOutLog) <<
"Ignoring unsupported writeOut for " << domTypeToString(kind()) <<
":"
237 << self.canonicalPath();
246 if (m_value.isMap()) {
247 QCborMap map = m_value.toMap();
248 auto it = map.cbegin();
249 auto end = map.cend();
251 QString key = it.key().toString();
255 auto val = it.value();
256 if (!self.invokeVisitorOnValue(visitor, comp, val))
261 }
else if (m_value.isArray()){
262 QCborArray array = m_value.toArray();
263 auto it = array.cbegin();
264 auto end = array.cend();
267 if (!self.invokeVisitorOnValue(visitor,
PathEls::Index(i++), *it++))
285 if (m_value.isArray())
286 return DomKind::List;
287 return DomKind::Value;
290
291
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
326 const QString &canonicalPath,
const QString &logicalPath,
336 const QString &path,
const QString &code)
338 const QString canonicalPath = QFileInfo(path).canonicalFilePath();
343 canonicalPath.isEmpty() ? path : canonicalPath,
353 const QString canonicalPath = QFileInfo(path).canonicalFilePath();
379 Path res = visitEl([
this](
auto &&el) {
return el->canonicalPath(*
this); });
381 qCWarning(domLog) <<
"non anchored canonical path:" << res.toString();
390 return visitEl([
this](
auto &&el) {
return el->containingObject(*
this); });
394
395
396
397
398
401 if (
DomItem res = filterUp([](DomType k,
const DomItem &) {
return k == DomType::QmlObject; },
404 if (options == GoTo::MostLikely) {
405 if (
DomItem comp = component(options))
419 if (k == DomType::ExternalItemInfo || (options == GoTo::MostLikely && k == DomType::ExternalItemPair))
435 return qmlObject(options, FilterUpOptions::ReturnInner);
444 if (s.pathFromSource.length() > 1)
450
451
452
457 return std::visit([
this](
auto &&el) {
458 if constexpr (std::is_same_v<std::decay_t<
decltype(el)>, std::monostate>)
461 return DomItem(
this->m_top, el,
this->m_ownerPath, el.get());
469 return std::visit([](
auto &&el) {
470 if constexpr (std::is_same_v<std::decay_t<
decltype(el)>, std::monostate>)
487 const std::shared_ptr<DomEnvironment> environmentPtr = environment().ownerAs<DomEnvironment>();
490 return environmentPtr->semanticAnalysis().m_mapper;
504
505
506
507
508
511 if (
DomItem res = filterUp([](DomType k,
const DomItem &) {
return k == DomType::ScriptExpression; },
512 FilterUpOptions::ReturnOuter))
518
519
520
521
522
525 if (
DomItem res = filterUp([](DomType k,
const DomItem &) {
return k == DomType::QmlFile; },
526 FilterUpOptions::ReturnOuter))
532
533
534
535
538 Q_UNUSED(canonicalPath);
545
546
547
560
561
562
569
570
571
572
593 for (
const Path ¤tPath : canonicalPath()) {
594 current = current.path(currentPath);
595 if (filter(current.internalKind(), current))
606 DomItem res = filterUp([](DomType,
const DomItem &el) {
return el.isScope(); }, options);
612 QQmlJSScope::ConstPtr scope;
613 visitUp([&scope](
const DomItem &item) {
614 scope = item.semanticScope();
622 QQmlJSScope::ConstPtr scope = std::visit(
623 [](
auto &&e) -> QQmlJSScope::ConstPtr {
624 using T = std::remove_cv_t<std::remove_reference_t<
decltype(e)>>;
625 if constexpr (std::is_same_v<T,
const QmlObject *>) {
626 return e->semanticScope();
627 }
else if constexpr (std::is_same_v<T,
const QmlComponent *>) {
628 return e->semanticScope();
629 }
else if constexpr (std::is_same_v<T, SimpleObjectWrap>) {
630 if (
const MethodInfo *mi = e->
template as<MethodInfo>()) {
631 return mi->semanticScope();
633 if (
const auto *propertyDefinition = e->
template as<PropertyDefinition>()) {
634 return propertyDefinition->semanticScope();
636 }
else if constexpr (std::is_same_v<T, ScriptElementDomWrapper>) {
637 return e.element().base()->semanticScope();
648 return refPtr->get(*
this, h, visitedRefs);
655 return refPtr->getAll(*
this, h, visitedRefs);
662 visitPrototypeChain([&pInfo, name](
const DomItem &obj) {
663 return obj.visitLocalSymbolsNamed(name, [&pInfo, name](
const DomItem &el) {
664 switch (el.internalKind()) {
665 case DomType::Binding:
666 pInfo.bindings.append(el);
668 case DomType::PropertyDefinition:
669 pInfo.propertyDefs.append(el);
683 visitPrototypeChain([&res](
const DomItem &obj) {
684 res += obj.propertyDefs().keys();
685 res += obj.bindings().keys();
694 [](DomType kind,
const DomItem &) {
695 return kind == DomType::QmlComponent || kind == DomType::GlobalComponent;
697 FilterUpOptions::ReturnInner))
699 if (options == GoTo::MostLikely) {
709 item = fileObject(options);
727 static auto map = []() {
728 QMetaEnum metaEnum = QMetaEnum::fromType<LookupType>();
729 QMap<QString, LookupType> res;
730 for (
int i = 0; i < metaEnum.keyCount(); ++i) {
731 res[QString::fromUtf8(metaEnum.key(i)).toLower()] = LookupType(metaEnum.value(i));
757
758
759
760
761
765 if (visitedRefs->contains(refRef)) {
767 .error([visitedRefs, refRef](
const Sink &sink) {
768 const QString msg = DomItem::tr(
"Circular reference:") + QLatin1Char(
'\n');
769 sink(QStringView{ msg });
770 for (
const Path &vPath : *visitedRefs) {
783 visitedRefs->append(refRef);
786 ref->referredObjectPath,
791 errorHandler, ref->referredObjectPath, visitedRefs);
797 LookupOptions opt = LookupOption::Normal;
799 return opt | LookupOption::Strict;
805 DomItem strict = comp
[u"~strictLookup~"
];
808 strict = env
[u"defaultStrictLookup"
];
810 if (strict && strict.value().toBool())
811 opt = opt | LookupOption::Strict;
818 const auto &map = stringToLookupTypeMap();
819 auto it = map.find(expectedType.toLower());
826 const Path &fullPath, QList<Path> *visitedRefs)
const
829 Path fPath = fullPath;
833 return visitor(fPath, *
this);
834 QList<QSet<quintptr>> visited(path.length() + 1);
836 QList<ResolveToDo> toDos(1);
842 .error(tr(
"Root context %1 is not known").arg(path.headName())
)
843 .handle(errorHandler);
846 toDos[0] = {std::move(root), 1};
848 toDos[0] = {*
this, 0};
850 while (!toDos.isEmpty()) {
853 auto idNow = toDo.item.id();
854 if (idNow == quintptr(0) && toDo.item == *
this)
855 idNow = quintptr(
this);
856 if (idNow != quintptr(0) && visited[0].contains(idNow))
861 bool branchExhausted =
false;
862 while (iPath < path
.length() && it && !branchExhausted) {
863 auto idNow = it.id();
864 if (idNow == quintptr() && toDo.item == *
this)
865 idNow = quintptr(
this);
866 if (idNow != quintptr(0)) {
867 auto vPair = std::make_pair(idNow, iPath);
868 if (visited[vPair.second].contains(vPair.first))
870 visited[vPair.second].insert(vPair.first);
872 auto cNow = components
[iPath++
];
875 it = it.key(cNow.headName());
879 it = resolveReference(it, it.canonicalPath(),
880 visitedRefs ==
nullptr ? &vRefs : visitedRefs,
881 errorHandler, myResolveErrors());
882 }
else if (
auto fn = cNow.headField()) {
890 it = it.index(*cNow.headIndex());
894 .error(tr(
"Empty is not supported inside paths")
)
895 .handle(errorHandler);
899 .arg(cNow.toString()).arg(iPath -1).arg(path.toString())
).handle(errorHandler);
907 if (domKind() != DomKind::Object)
915 it = it.component().ids();
918 it = it.component()[
Fields::exports];
923 const LookupOptions opt = resolveLookupOptions(current, it);
926 .error(tr(
"Javascript lookups not yet implemented")
)
927 .handle(errorHandler);
931 auto idNow = it.id();
932 if (idNow == quintptr(0) && toDo.item == *
this)
933 idNow = quintptr(
this);
934 if (idNow != quintptr(0)) {
935 auto vPair = std::make_pair(idNow, iPath);
936 if (visited[vPair.second].contains(vPair.first))
938 visited[vPair.second].insert(vPair.first);
942 .error(tr(
"Premature end of path, expected a field specifying the "
943 "type, and a key specifying the name to search after a "
944 "lookup directive in %2")
945 .arg(path.toString())
)
946 .handle(errorHandler);
949 Path cNow = components
[iPath++
];
952 .error(tr(
"Expected a key path specifying the type to search after "
953 "a lookup directive, not %1 at component %2 of %3")
954 .arg(cNow.toString())
956 .arg(path.toString())
)
957 .handle(errorHandler);
960 QString expectedType = cNow.headName();
961 auto lookupType = lookupTypeFromString(expectedType);
964 .error(tr(
"Type for lookup was expected to be one of '%1', not "
966 .arg(stringToLookupTypeMap().keys().join(
", "_L1),
968 .handle(errorHandler);
971 cNow = components
[iPath++
];
974 .error(tr(
"Expected a key specifying the path to search after the "
975 "@lookup directive and type, not %1 at component %2 of "
977 .arg(cNow.toString())
979 .arg(path.toString())
)
980 .handle(errorHandler);
983 QString target = cNow.headName();
984 if (target.isEmpty()) {
986 .warning(tr(
"Path with empty lookup at component %1 of %2 will "
987 "match nothing in %3.")
989 .arg(path.toString())
991 .handle(errorHandler);
996 [&toDos, iPath](
const DomItem &subEl) {
997 toDos.append({ subEl, iPath });
1000 *(
std::move(lookupType)), opt, errorHandler, &(visited[iPath]),
1002 branchExhausted =
true;
1011 if (!branchExhausted && iPath == path
.length() && !visitor(fPath, it))
1022 resolve(p, [&res](
const Path &,
const DomItem &it) {
1031 return visitEl([
this](
auto &&el) {
return el->fields(*
this); });
1036 return visitEl([
this, name](
auto &&el) {
return el->field(*
this, name); });
1041 return visitEl([
this](
auto &&el) {
return el->indexes(*
this); });
1046 return visitEl([
this, i](
auto &&el) {
return el->index(*
this, i); });
1052 int nIndexes = indexes();
1053 for (
int i = 0; i < nIndexes; ++i) {
1063 return visitEl([
this](
auto &&el) {
return el->keys(*
this); });
1068 QSet<QString> ks = keys();
1069 QStringList sortedKs(ks.begin(), ks.end());
1070 std::sort(sortedKs.begin(), sortedKs.end());
1076 return visitEl([
this, name](
auto &&el) {
return el->key(*
this, name); });
1082 const QStringList keys = sortedKeys();
1083 for (
const QString &k : keys) {
1094 iterateDirectSubpaths([&res](
const PathEls::PathComponent &, function_ref<DomItem()> item) {
1105 for (
const auto &ann : anns.values()) {
1106 if (ann.annotations().indexes() == 0) {
1111 DomItem annAnn = ann.annotations();
1112 Q_ASSERT_X(annAnn.indexes() == 1 && annAnn.index(0).name() == u"duplicate",
1113 "DomItem::writeOutPre",
"Unexpected annotation of annotation");
1117 ow.itemStart(*
this);
1123 visitEl([
this, &ow](
auto &&el) { el->writeOut(*
this, ow); });
1134 WriteOutChecks extraChecks)
const
1136 auto compare = [
this](
const DomItem &obj1,
const DomItem &obj2, QStringView obj2Name,
1138 const auto diffList = domCompareStrList(obj1, obj2, filter, DomCompareStrList::AllDiffs);
1139 if (!diffList.isEmpty()) {
1140 qCWarning(writeOutLog).noquote().nospace()
1141 << obj2Name <<
" writeOut of " <<
this->canonicalFilePath() <<
" has changes:\n"
1142 << diffList.join(QString());
1147 auto checkStability = [&ow,
this](
const QString &expected,
const DomItem &obj,
1148 QStringView objName) {
1151 ow2.indentNextlines =
true;
1154 if (ow2.writtenStr != expected) {
1155 qCWarning(writeOutLog).noquote().nospace()
1156 << objName <<
" non stable writeOut of " <<
this->canonicalFilePath() <<
":"
1157 << lineDiff(expected, ow2.writtenStr, 2);
1166 std::shared_ptr<DomEnvironment> newEnvPtr = newEnv.ownerAs<DomEnvironment>();
1168 return WriteOutCheckResult::Failed;
1170 auto newFilePtr =
std::make_shared<QmlFile>(canonicalFilePath(), ow.writtenStr);
1174 if (newFilePtr->isValid()) {
1176 newEnvPtr->populateFromQmlFile(newFile);
1178 && !compare(reformatted, newFile, u"reparsed",
1180 return WriteOutCheckResult::Failed;
1182 checkStability(ow.writtenStr, newFile, u"reparsed");
1185 const auto iterateErrors = [&newFile](
const Sink &s) {
1186 newFile.iterateErrors(
1195 qCWarning(writeOutLog).noquote().nospace()
1196 <<
"writeOut of " << canonicalFilePath()
1197 <<
" created invalid code:\n----------\n"
1198 << ow.writtenStr <<
"\n----------" << iterateErrors;
1199 return WriteOutCheckResult::Failed;
1202 return WriteOutCheckResult::Success;
1206
1207
1208
1209
1210
1211
1212
1213
1214
1217 ow.indentNextlines =
true;
1218 auto currentFileItem = fileObject();
1221 WriteOutCheckResult result = WriteOutCheckResult::Success;
1223 result = performWriteOutChecks(currentFileItem, ow, extraChecks);
1224 return result == WriteOutCheckResult::Success ?
bool(currentFileItem) :
false;
1228 WriteOutChecks extraChecks)
const
1233 auto status = fw->write(path, [
this, path, &options, extraChecks](QTextStream &ts) {
1234 auto lw = createLineWriter([&ts](QStringView s) { ts << s; }, path, options);
1235 OutWriter ow(getFileItemOwner(fileObject()), *lw);
1236 return writeOutForFile(ow, extraChecks);
1239 case FileWriter::Status::DidWrite:
1240 case FileWriter::Status::SkippedEqual:
1242 case FileWriter::Status::ShouldWrite:
1243 case FileWriter::Status::SkippedDueToFailure:
1244 qCWarning(writeOutLog) <<
"failure reformatting " << path;
1247 qCWarning(writeOutLog) <<
"Unknown FileWriter::Status ";
1255 bool isChild =
false;
1268 bool hasAnnotations =
false;
1272 if (
const Id *myPtr = as<
Id>())
1273 hasAnnotations = !myPtr->annotations.isEmpty();
1277 hasAnnotations = !myPtr->annotations.isEmpty();
1281 hasAnnotations = !myPtr->annotations.isEmpty();
1285 hasAnnotations = !myPtr->annotations().isEmpty();
1289 hasAnnotations = !myPtr->annotations().isEmpty();
1294 return hasAnnotations;
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1320 VisitOptions options, DomItem::ChildrenVisitor openingVisitor,
1321 DomItem::ChildrenVisitor closingVisitor,
const FieldFilter &filter)
const
1329 auto atEnd = qScopeGuard([closingVisitor, basePath,
this, options]() {
1331 closingVisitor(basePath, *
this,
true);
1334 return iterateDirectSubpaths(
1335 [
this, basePath, visitor, openingVisitor, closingVisitor, options,
1336 &filter](
const PathEls::PathComponent &c, function_ref<DomItem()> itemF) {
1338 if (!(options & VisitOption::NoPath)) {
1340 pNow = pNow.withComponent(c);
1342 if (!filter(*
this, c, DomItem{}))
1344 DomItem item = itemF();
1345 bool directChild = isCanonicalChild(item);
1346 if (!directChild && !(options & VisitOption::VisitAdopted))
1348 if (!directChild || !(options & VisitOption::Recurse)) {
1349 if (!visitor(pNow, item, directChild))
1354 if (!openingVisitor(pNow, item, directChild))
1356 closingVisitor(pNow, item, directChild);
1358 return item.visitTree(pNow, visitor, options | VisitOption::VisitSelf,
1359 openingVisitor, closingVisitor, filter);
1366 QList<Path> *visitedRefs, VisitPrototypesOptions options,
1370 if (visitedRefs->contains(elId))
1373 visitedRefs->append(elId);
1374 QList<DomItem> protos = prototype.getAll(h, visitedRefs);
1375 if (protos.isEmpty()) {
1376 if (std::shared_ptr<DomEnvironment> envPtr =
1377 derivedFromPrototype.environment().ownerAs<DomEnvironment>())
1380 .warning(derivedFromPrototype.tr(
"could not resolve prototype %1 (%2)")
1385 .withItem(derivedFromPrototype)
1388 if (protos.size() > 1) {
1389 QStringList protoPaths;
1390 for (
const DomItem &p : protos)
1391 protoPaths.append(p.canonicalPath().toString());
1394 .tr(
"Multiple definitions found, using first only, resolving "
1395 "prototype %1 (%2): %3")
1400 protoPaths.join(QLatin1String(
", ")))
)
1401 .withItem(derivedFromPrototype)
1406 for (
int i = nProtos; i != 0;) {
1407 DomItem proto = protos.at(--i);
1410 proto = proto.proceedToScope(h, visitedRefs);
1417 .warning(derivedFromPrototype.tr(
"Unexpected prototype type %1 (%2)")
1422 .withItem(derivedFromPrototype)
1432 QSet<quintptr> *visited, QList<Path> *visitedRefs)
const
1434 QSet<quintptr> visitedLocal;
1436 visited = &visitedLocal;
1437 QList<Path> refsLocal;
1439 visitedRefs = &refsLocal;
1441 DomItem current = qmlObject();
1446 QList<DomItem> toDo({ current });
1447 while (!toDo.isEmpty()) {
1448 current = toDo.takeLast();
1449 current = current.proceedToScope(h, visitedRefs);
1450 if (visited->contains(current.id())) {
1456 .warning(tr(
"Detected multiple visit of %1 visiting prototypes of %2")
1463 visited->insert(current.id());
1464 if (shouldVisit && !visitor(current))
1468 .visitIndexes([&toDo, ¤t,
this, &h, visitedRefs, options](
const DomItem &el) {
1469 return visitPrototypeIndex(toDo, current, *
this, h, visitedRefs, options, el);
1476 function_ref<
bool(
const DomItem &)> visitor, VisitPrototypesOptions options,
1477 const ErrorHandler &h, QSet<quintptr> *visited, QList<Path> *visitedRefs)
const
1482 if (k == DomType::QmlObject)
1483 return visitPrototypeChain(visitor, options, h, visited, visitedRefs);
1484 if (visited && id() != 0) {
1485 if (visited->contains(id()))
1487 visited->insert(id());
1491 DomItem v = proceedToScope(h, visitedRefs);
1493 return v.visitPrototypeChain(visitor, options, h, visited, visitedRefs);
1499 return v.visitPrototypeChain(visitor, options, h, visited, visitedRefs);
1505 return t.visitPrototypeChain(visitor, options, h, visited, visitedRefs);
1513
1514
1515
1516
1517
1518
1519
1520
1521
1523 function_ref<
bool(
const DomItem &)> visitor, VisitPrototypesOptions options,
1524 const ErrorHandler &h, QSet<quintptr> *visited, QList<Path> *visitedRefs)
const
1526 QSet<quintptr> visitedLocal;
1528 visited = &visitedLocal;
1529 DomItem current = qmlObject();
1530 DomItem comp = current.component();
1532 && !current.visitPrototypeChain(visitor, options, h, visited, visitedRefs))
1534 if (
DomItem attachedT = current.component().field(
Fields::attachedType).field(
Fields::get))
1535 if (!attachedT.visitPrototypeChain(
1537 visited, visitedRefs))
1543
1544
1550 if (!visitor(current))
1558
1559
1561 function_ref<
bool(
const DomItem &)> visitor, LookupOptions options,
const ErrorHandler &h,
1562 QSet<quintptr> *visited, QList<Path> *visitedRefs)
const
1564 QSet<quintptr> visitedLocal;
1566 visited = &visitedLocal;
1567 QList<Path> visitedRefsLocal;
1569 visitedRefs = &visitedRefsLocal;
1575 QList<DomItem> toDo { current };
1576 bool visitFirst = !(options & LookupOption::SkipFirstScope);
1577 bool visitCurrent = visitFirst;
1579 QSet<quintptr> alreadyAddedComponentMaps;
1580 while (!toDo.isEmpty()) {
1581 DomItem current = toDo.takeLast();
1582 if (visited->contains(current.id()))
1584 visited->insert(current.id());
1585 if (visitCurrent && !visitor(current))
1587 visitCurrent =
true;
1593 DomItem root = current.rootQmlObject();
1594 if (root && root
!= current) {
1608 if ((options & LookupOption::Strict) == 0) {
1612 if (first && visitFirst && (options & LookupOption::VisitTopClassType)
1613 && *
this == current) {
1615 toDo.append(attachedT);
1623 if (alreadyAddedComponentMaps.contains(componentMap.id()))
1625 alreadyAddedComponentMaps.insert(componentMap.id());
1626 const auto keys = componentMap.keys();
1627 for (
const QString &x : keys) {
1628 DomItem componentList = componentMap.key(x);
1629 for (
int i = 0; i < componentList.indexes(); ++i) {
1630 DomItem component = componentList.index(i);
1631 if (component != current && !visited->contains(component.id()))
1632 toDo.append(component);
1641 toDo.append(iScope);
1658 .error(tr(
"Unexpected non scope object %1 (%2) reached in visitScopeChain")
1659 .arg(domTypeToString(current.internalKind()),
1670 const QString &symbolName, function_ref<
bool(
const DomItem &)> visitor, LookupOptions opts,
1671 const ErrorHandler &h, QSet<quintptr> *visited, QList<Path> *visitedRefs)
const
1673 return visitScopeChain(
1674 [symbolName, visitor](
const DomItem &obj) {
1675 return obj.visitLocalSymbolsNamed(symbolName,
1676 [visitor](
const DomItem &el) {
return visitor(el); });
1678 opts, h, visited, visitedRefs);
1690 QRegularExpression reTarget = QRegularExpression(QRegularExpression::anchoredPattern(
1691 uR"(QList<(?<list>[a-zA-Z_0-9:]+) *(?<listPtr>\*?)>|QMap< *(?<mapKey>[a-zA-Z_0-9:]+) *, *(?<mapValue>[a-zA-Z_0-9:]+) *(?<mapPtr>\*?)>|(?<baseType>[a-zA-Z_0-9:]+) *(?<ptr>\*?))"));
1693 QRegularExpressionMatch m = reTarget.matchView(target);
1694 if (!m.hasMatch()) {
1696 .error(tr(
"Unexpected complex CppType %1").arg(target)
)
1699 res.baseType = m.captured(u"baseType");
1700 res
.isPointer = !m.captured(u"ptr").isEmpty();
1701 if (!m.captured(u"list").isEmpty()) {
1703 res.baseType = m.captured(u"list");
1704 res
.isPointer = !m.captured(u"listPtr").isEmpty();
1706 if (!m.captured(u"mapValue").isEmpty()) {
1708 if (m.captured(u"mapKey") != u"QString") {
1710 .error(tr(
"Unexpected complex CppType %1 (map with non QString key)")
1714 res.baseType = m.captured(u"mapValue");
1715 res
.isPointer = !m.captured(u"mapPtr").isEmpty();
1727 function_ref<
bool(
const DomItem &)> visitor)
1729 bool correctType =
false;
1731 switch (lookupType) {
1732 case LookupType::Binding:
1735 case LookupType::Method:
1738 case LookupType::Property:
1741 case LookupType::PropertyDef:
1744 case LookupType::Type:
1757 const DomItem &newIt,
const QStringList &subpath,
1758 function_ref<
bool(
const DomItem &)> visitor, LookupType lookupType,
1759 const ErrorHandler &errorHandler, QList<Path> *visitedRefs)
1761 QList<ResolveToDo> lookupToDos(
1762 { ResolveToDo{ newIt, 1 } });
1764 QList<QSet<quintptr>> lookupVisited(subpath.size() + 1);
1765 while (!lookupToDos.isEmpty()) {
1767 auto vNow = std::make_pair(tNow.item.id(), tNow.pathIndex);
1770 Q_ASSERT(iSubPath < subpath.size());
1771 QString subPathNow = subpath[iSubPath++];
1772 DomItem scope = subNow.proceedToScope();
1773 if (iSubPath < subpath.size()) {
1774 if (vNow.first != 0) {
1775 if (lookupVisited[vNow.second].contains(vNow.first))
1778 lookupVisited[vNow.second].insert(vNow.first);
1781 scope.visitDirectAccessibleScopes(
1782 [&lookupToDos, &subPathNow, iSubPath](
const DomItem &el) {
1783 return el.visitLocalSymbolsNamed(
1784 subPathNow, [&lookupToDos, iSubPath](
const DomItem &subEl) {
1785 lookupToDos.append({ subEl, iSubPath });
1792 bool cont = scope.visitDirectAccessibleScopes(
1793 [&visitor, &subPathNow, lookupType](
const DomItem &el) ->
bool {
1794 if (lookupType == LookupType::Symbol)
1795 return el.visitLocalSymbolsNamed(subPathNow, visitor);
1797 return el.visitLocalSymbolsNamed(
1798 subPathNow, [lookupType, &visitor](
const DomItem &el) ->
bool {
1799 return visitForLookupType(el, lookupType, visitor);
1812 const QString &target, function_ref<
bool(
const DomItem &)> visitor, LookupType lookupType,
1813 LookupOptions opts,
const ErrorHandler &errorHandler, QSet<quintptr> *visited,
1814 QList<Path> *visitedRefs)
const
1816 if (target.isEmpty())
1818 switch (lookupType) {
1819 case LookupType::Binding:
1820 case LookupType::Method:
1821 case LookupType::Property:
1822 case LookupType::PropertyDef:
1823 case LookupType::Symbol:
1824 case LookupType::Type: {
1825 QStringList subpath = target.split(QChar::fromLatin1(
'.'));
1826 if (subpath.size() == 1) {
1827 return visitLookup1(subpath.first(), visitor, opts, errorHandler, visited, visitedRefs);
1829 return visitLookup1(
1831 [&subpath, visitor, lookupType, &errorHandler,
1832 visitedRefs](
const DomItem &newIt) ->
bool {
1833 return visitQualifiedNameLookup(newIt, subpath, visitor, lookupType,
1834 errorHandler, visitedRefs);
1836 opts, errorHandler, visited, visitedRefs);
1840 case LookupType::CppType:
1848
1849
1850
1851
1852
1853
1854
1863 current = current.get(h, visitedRefs);
1886 [&res](
const DomItem &el) {
1890 type, opts, errorHandler);
1900 [&res](
const DomItem &el) {
1904 type, opts, errorHandler);
1910 return visitEl([](
auto &&b) {
return b->id(); });
1915 return visitEl([](
auto &&e) {
return e->pathFromOwner(); });
1920 return visitEl([
this](
auto &&e) {
return e->canonicalFilePath(*
this); });
1929 DomItem newItem =
std::visit([
this, &o](
auto &&el) {
1930 if constexpr (std::is_same_v<std::decay_t<
decltype(el)>, std::monostate>) {
1933 auto copyPtr = el->makeCopy(o);
1934 return DomItem(m_top, copyPtr, m_ownerPath, copyPtr.get());
1940 std::shared_ptr<DomEnvironment> newEnvPtr;
1941 if (std::shared_ptr<DomEnvironment> envPtr = env.ownerAs<DomEnvironment>()) {
1942 newEnvPtr =
std::make_shared<DomEnvironment>(envPtr, envPtr->loadPaths(), envPtr->options(),
1943 envPtr->domCreationOption());
1944 DomBase *eBase = envPtr.get();
1945 if (
std::holds_alternative<
const DomEnvironment *>(m_element) && eBase
1946 &&
std::get<
const DomEnvironment *>(m_element) == eBase)
1948 }
else if (std::shared_ptr<DomUniverse> univPtr = top().ownerAs<DomUniverse>()) {
1949 newEnvPtr =
std::make_shared<DomEnvironment>(
1958 [
this, newEnvPtr, &o](
auto &&el) {
1959 if constexpr (std::is_same_v<std::decay_t<
decltype(el)>, std::monostate>) {
1962 auto copyPtr = el->makeCopy(o);
1963 return DomItem(newEnvPtr, copyPtr, m_ownerPath, copyPtr.get());
1975 case DomType::ScriptExpression:
1976 case DomType::AstComments:
1977 case DomType::LoadInfo:
1978 case DomType::FileLocationsNode:
1979 case DomType::DomEnvironment:
1980 case DomType::DomUniverse:
1981 qCWarning(domLog) <<
"DomItem::makeCopy " << internalKindStr()
1982 <<
" does not support binding to environment";
1986 qCWarning(domLog) <<
"DomItem::makeCopy(" << internalKindStr()
1987 <<
") is not an known OwningItem";
1999 if (std::shared_ptr<DomEnvironment> envPtr = env.ownerAs<DomEnvironment>()) {
2000 return envPtr->commitToBase(env, validEnvPtr);
2018 if (!v.visitIndexes(visitor))
2022 if (!v.visitIndexes(visitor))
2026 if (!v.visitIndexes(visitor))
2035 if (!v.visitIndexes(visitor))
2042 if (!params.visitIndexes([name, visitor](
const DomItem &p) {
2044 if (pPtr->name == name && !visitor(p))
2054 if (!v.visitIndexes(visitor))
2067 if (internalKind() == DomType::Map)
2069 if (
auto fn = fieldNameFromString(cName))
2076 if (internalKind() == DomType::Map)
2077 return key(cName.toString());
2078 if (
auto fn = fieldNameFromString(cName))
2090 return base()->value();
2095 sink(u"DomItem{ topPtr:");
2096 sink(QString::number((quintptr)topPtr().get(), 16));
2097 sink(u", ownerPtr:");
2098 sink(QString::number((quintptr)owningItemPtr().get(), 16));
2099 sink(u", ownerPath:");
2100 m_ownerPath.dump(sink);
2102 sink(QString::number((quintptr)base(),16));
2107 const Sink &s,
int indent,
2108 function_ref<
bool(
const DomItem &,
const PathEls::PathComponent &,
const DomItem &)> filter)
const
2110 visitEl([
this, s, indent, filter](
auto &&e) { e->dump(*
this, s, indent, filter); });
2114 const QString &path,
2115 function_ref<
bool(
const DomItem &,
const PathEls::PathComponent &,
const DomItem &)> filter,
2121 switch (fw->write(path, [
this, indent, filter](QTextStream &ts) {
2122 this->dump([&ts](QStringView s) { ts << s; }, indent, filter);
2125 case FileWriter::Status::ShouldWrite:
2126 case FileWriter::Status::SkippedDueToFailure:
2127 qWarning() <<
"Failure dumping " <<
canonicalPath() <<
" to " << path;
2129 case FileWriter::Status::DidWrite:
2130 case FileWriter::Status::SkippedEqual:
2138 return dumperToString([
this](
const Sink &s){ dump(s); });
2143 return std::visit([](
auto &&ow) {
2144 if constexpr (std::is_same_v<std::decay_t<
decltype(ow)>, std::monostate>)
2147 return ow->derivedFrom();
2153 return std::visit([](
auto &&ow) {
2154 if constexpr (std::is_same_v<std::decay_t<
decltype(ow)>, std::monostate>)
2157 return ow->revision();
2163 return std::visit([](
auto &&ow) {
2164 if constexpr (std::is_same_v<std::decay_t<
decltype(ow)>, std::monostate>)
2165 return QDateTime::fromMSecsSinceEpoch(0, QTimeZone::UTC);
2167 return ow->createdAt();
2173 return std::visit([](
auto &&ow) {
2174 if constexpr (std::is_same_v<std::decay_t<
decltype(ow)>, std::monostate>)
2175 return QDateTime::fromMSecsSinceEpoch(0, QTimeZone::UTC);
2177 return ow->frozenAt();
2183 return std::visit([](
auto &&ow) {
2184 if constexpr (std::is_same_v<std::decay_t<
decltype(ow)>, std::monostate>)
2185 return QDateTime::fromMSecsSinceEpoch(0, QTimeZone::UTC);
2187 return ow->lastDataUpdateAt();
2193 std::visit([
this, &msg](
auto &&ow) {
2194 if constexpr (std::is_same_v<std::decay_t<
decltype(ow)>, std::monostate>)
2209 std::visit([&groups](
auto &&ow) {
2210 if constexpr (!std::is_same_v<std::decay_t<
decltype(ow)>, std::monostate>)
2211 ow->clearErrors(groups);
2215 iterateSubOwners([groups](
const DomItem &i){
2216 i.clearErrors(groups,
true);
2223 function_ref<
bool(
const DomItem &,
const ErrorMessage &)> visitor,
bool iterate,
2226 if (!
std::visit([
this, visitor, inPath](
auto &&el) {
2227 if constexpr (std::is_same_v<std::decay_t<
decltype(el)>, std::monostate>)
2230 return el->iterateErrors(
owner(), visitor, inPath);
2235 if (iterate && !iterateSubOwners([inPath, visitor](
const DomItem &i) {
2236 return i.iterateErrors(visitor,
true, inPath);
2246 return std::visit([
this, visitor](
auto &&o) {
2247 if constexpr (std::is_same_v<std::decay_t<
decltype(o)>, std::monostate>)
2250 return o->iterateSubOwners(
owner(), visitor);
2257 [
this, v](
auto &&el) {
return el->iterateDirectSubpaths(*
this, v); });
2263 List::fromQList<Path>(pathFromOwner().withComponent(c), paths,
2264 [](
const DomItem &list,
const PathEls::PathComponent &p,
const Path &el) {
2265 return list.subReferenceItem(p, el);
2272 return DomItem(m_top, m_owner, m_ownerPath, Reference(referencedObject, Path::fromComponent(c)));
2274 return DomItem(m_top, m_owner, m_ownerPath,
2275 Reference(referencedObject, pathFromOwner().withComponent(c)));
2281 return std::visit([](
auto &&el) -> shared_ptr<
DomTop> {
2282 if constexpr (std::is_same_v<std::decay_t<
decltype(el)>, std::monostate>)
2292 if constexpr (std::is_same_v<std::decay_t<
decltype(el)>, std::monostate>)
2300
2301
2302
2305 return visitEl([](
auto &&el) ->
const DomBase * {
return el->domBase(); });
2314 DomItem(universePtr, universePtr,
Path(), universePtr.get())
2319
2320
2321
2322
2323
2324
2325
2334 FileToLoad::fromMemory(env, QString(), code),
2336 std::make_optional(fileType));
2337 return tFile.fileObject();
2364 const DomItem &,
const Sink &s,
int,
2371 const Keys &keys,
const QString &targetType)
2382 QSet<QString> ksSet = keys(self);
2383 QStringList ksList = QStringList(ksSet.begin(), ksSet.end());
2384 std::sort(ksList.begin(), ksList.end());
2385 for (
const QString &k : std::as_const(ksList)) {
2386 if (!visitor(PathEls::Key(k), [&self,
this, k]() {
return key(self, k); }))
2394 return m_keys(self);
2399 return m_lookup(self, name);
2403 const DomItem &self,
const Sink &sink,
int indent,
2404 function_ref<
bool(
const DomItem &,
const PathEls::PathComponent &,
const DomItem &)> filter)
const
2407 DomKind dK = self.domKind();
2409 case DomKind::Object:
2410 sink(u"{ \"~type~\":");
2411 sinkEscaped(sink, typeName());
2414 case DomKind::Value:
2416 sink(QString::fromUtf8(value().toJsonValue().toJson()));
2419 case DomKind::Empty:
2428 case DomKind::ScriptElement:
2432 auto closeParens = qScopeGuard(
2435 case DomKind::Object:
2436 sinkNewline(sink, indent);
2439 case DomKind::Value:
2441 case DomKind::Empty:
2444 sinkNewline(sink, indent);
2448 sinkNewline(sink, indent);
2451 case DomKind::ScriptElement:
2457 self.iterateDirectSubpaths(
2459 function_ref<DomItem()> itemF) {
2461 if (!filter(self, c, i))
2469 sinkNewline(sink, indent + 2);
2470 if (dK != DomKind::Object)
2471 sink(u"UNEXPECTED ENTRY ERROR:");
2472 sinkEscaped(sink, c.name());
2476 sinkNewline(sink, indent + 2);
2477 if (dK != DomKind::Map)
2478 sink(u"UNEXPECTED ENTRY ERROR:");
2479 sinkEscaped(sink, c.name());
2483 sinkNewline(sink, indent + 2);
2484 if (dK != DomKind::List)
2485 sink(u"UNEXPECTED ENTRY ERROR:");
2486 else if (idx++ != c.index())
2487 sink(u"OUT OF ORDER ARRAY:");
2490 sinkNewline(sink, indent + 2);
2491 sink(u"UNEXPECTED PATH KIND ERROR (ignored)");
2495 i.dump(sink, indent + 2, filter);
2497 sink(uR"({ "~type~": "Reference", "immediate": true, "referredObjectPath":")");
2509 const QString &elType):
2520 const DomItem &self,
const Sink &sink,
int indent,
2521 function_ref<
bool(
const DomItem &,
const PathEls::PathComponent &,
const DomItem &)> filter)
const
2525 iterateDirectSubpaths(
2527 [&self, indent, &first, sink, filter](
const PathEls::PathComponent &c,
2528 function_ref<DomItem()> itemF) {
2529 DomItem item = itemF();
2530 if (!filter(self, c, item))
2536 sinkNewline(sink, indent + 2);
2537 item.dump(sink, indent + 2, filter);
2546 return m_iterator(self, [visitor](index_type i, function_ref<DomItem()> itemF) {
2547 return visitor(PathEls::Index(i), itemF);
2550 index_type len = indexes(self);
2551 for (index_type i = 0; i < len; ++i) {
2552 if (!visitor(
PathEls::Index(i), [
this, &self, i]() {
return index(self, i); }))
2560 return m_length(self);
2565 return m_lookup(self, index);
2571 ow.writeRegion(fLoc, LeftBracketRegion);
2573 iterateDirectSubpaths(self,
2574 [&ow, &first, &fLoc, compact](
const PathEls::PathComponent &,
2575 function_ref<DomItem()> elF) {
2579 ow.writeRegion(fLoc, CommaTokenRegion).ensureSpace();
2581 ow.ensureNewline(1);
2586 if (!compact && !first)
2588 ow.writeRegion(fLoc, RightBracketRegion);
2595 Q_ASSERT(m_pathFromOwner &&
"uninitialized DomElement");
2601 Q_ASSERT(m_pathFromOwner &&
"uninitialized DomElement");
2608 m_pathFromOwner = newPath;
2613 for (
const Path &p : referredObjectPath) {
2614 switch (p.headKind()) {
2615 case Path::Kind::Current:
2617 switch (*p.headCurrent()) {
2618 case PathCurrent::Lookup:
2619 case PathCurrent::LookupDynamic:
2620 case PathCurrent::LookupStrict:
2626 case Path::Kind::Empty:
2648 cont = cont && self.invokeVisitorOnLazyField(visitor,
Fields::referredObjectPath, [
this]() {
2649 return referredObjectPath.toString();
2651 cont = cont && visitor(
Fields::get, [
this, &self]() {
return this->get(self); });
2657 if (
Fields::referredObjectPath == name) {
2658 return self.subDataItem(
Fields::referredObjectPath,
2659 referredObjectPath.toString());
2661 if (Fields::get == name)
2668 return QList<QString>({fieldNameToQString(Fields::referredObjectPath), fieldNameToQString(Fields::get)});
2684 if (referredObjectPath) {
2693 switch (cached.cached) {
2694 case RefCacheEntry::Cached::None:
2696 case RefCacheEntry::Cached::First:
2697 case RefCacheEntry::Cached::All:
2698 if (!cached.canonicalPaths.isEmpty())
2699 cachedPath = cached.canonicalPaths.first();
2707 qCWarning(refLog) <<
"referenceCache outdated, reference at " << selfPath
2708 <<
" leads to invalid path " << cachedPath;
2714 QList<Path> visitedRefsLocal;
2721 h, referredObjectPath, (visitedRefs ? visitedRefs : &visitedRefsLocal));
2724 env, selfPath, RefCacheEntry { RefCacheEntry::Cached::First, { cachedPath } });
2733 if (referredObjectPath) {
2736 QList<Path> cachedPaths;
2741 switch (cached.cached) {
2742 case RefCacheEntry::Cached::None:
2743 case RefCacheEntry::Cached::First:
2745 case RefCacheEntry::Cached::All:
2746 cachedPaths += cached.canonicalPaths;
2747 if (cachedPaths.isEmpty())
2751 if (!cachedPaths.isEmpty()) {
2752 bool outdated =
false;
2753 for (
const Path &p : cachedPaths) {
2754 DomItem newEl = env.path(p);
2757 qCWarning(refLog) <<
"referenceCache outdated, reference at " << selfPath
2758 <<
" leads to invalid path " << p;
2776 h, referredObjectPath, visitedRefs);
2778 QList<Path> canonicalPaths;
2779 for (
const DomItem &i : res) {
2781 canonicalPaths.append(i.canonicalPath());
2784 <<
"getAll of reference at " << selfPath <<
" visits empty items.";
2788 RefCacheEntry { RefCacheEntry::Cached::All, std::move(canonicalPaths) });
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2812 : m_derivedFrom(derivedFrom),
2820 : m_derivedFrom(derivedFrom),
2834 QMultiMap<Path, ErrorMessage> my_errors;
2836 QMutexLocker l1(o.mutex());
2837 my_errors = o.m_errors;
2841 QMutexLocker l2(mutex());
2842 m_errors = my_errors;
2849 static QAtomicInt nextRev(0);
2856 cont = cont && visitor(
Fields::errors, [&self,
this]() {
2859 QMap<QString, ErrorMessage> myErrors;
2860 for (
const auto &[path, msg] : localErrors().asKeyValueRange())
2861 myErrors.insert(path.toString(), msg);
2862 return self.subMapItem(Map(
2863 self.pathFromOwner().withField(Fields::errors),
2864 [myErrors](
const DomItem &map,
const QString &name) {
2865 auto it = myErrors.find(name);
2866 if (it != myErrors.end())
2867 return map.subDataItem(PathEls::Key(name), it->toCbor());
2870 [myErrors](
const DomItem &) {
2871 return QSet<QString>(myErrors.keyBegin(), myErrors.keyEnd());
2873 QLatin1String(
"ErrorMessages")));
2881 if (s.pathFromSource) {
2882 if (!s.pathToSource)
2884 return self
.path(s.pathToSource
);
2891 return m_derivedFrom;
2901 return m_frozenAt > m_createdAt;
2907 m_frozenAt = QDateTime::currentDateTimeUtc();
2908 if (m_frozenAt <= m_createdAt)
2909 m_frozenAt = m_createdAt.addSecs(1);
2922 return m_lastDataUpdateAt;
2932 if (m_lastDataUpdateAt < tNew)
2933 m_lastDataUpdateAt = tNew;
2943 QMutexLocker l(mutex());
2944 quint32 &c = m_errorsCounts[msg];
2947 m_errors.insert(msg.path, msg);
2952 QMutexLocker l(mutex());
2953 auto it = m_errors.begin();
2954 while (it != m_errors.end()) {
2955 if (it->errorGroups == groups)
2956 it = m_errors.erase(it);
2963 const DomItem &self, function_ref<
bool(
const DomItem &,
const ErrorMessage &)> visitor,
2966 QMultiMap<Path, ErrorMessage> myErrors;
2968 QMutexLocker l(mutex());
2969 myErrors = m_errors;
2971 auto it = myErrors.lowerBound(inPath);
2972 auto end = myErrors.end();
2973 while (it != end && it.key().mid(0, inPath
.length()) == inPath) {
2974 if (!visitor(self, *it++))
2982 return self.iterateDirectSubpaths(
2985 if (i.owningItemPtr() != self.owningItemPtr()) {
2987 if (container.id() == self.id())
2996 if (o1.m_kind != o2.m_kind)
2998 return o1.visitEl([&o1, &o2](
auto &&el1) {
2999 auto &&el2 = std::get<std::decay_t<
decltype(el1)>>(o2.m_element);
3000 auto id1 = el1->id();
3001 auto id2 = el2->id();
3004 if (id1 != quintptr(0))
3006 if (o1.m_owner != o2.m_owner)
3008 Path p1 = el1->pathFromOwner();
3009 Path p2 = el2->pathFromOwner();
3028 Q_ASSERT(
false &&
"addPropertyDef on non qml scope");
3037 Q_ASSERT(
false &&
"addBinding on non qml scope");
3046 Q_ASSERT(
false &&
"addMethod on non qml scope");
3054 }
else if (QmlComponent *el = mutableAs<QmlComponent>()) {
3058 Q_ASSERT(
false &&
"addChild on non qml scope");
3066 dumperToQDebug([&c](
const Sink &s) { c.dump(s); }, debug);
3073 return debug.noquote().nospace() <<
"MutableDomItem(" << domTypeToString(cc.internalKind())
3074 <<
", " << cc.canonicalPath().toString() <<
")";
3079 index_type len = index_type(m_pList.size());
3080 for (index_type i = 0; i < len; ++i) {
3081 if (!v(
PathEls::Index(i), [
this, &self, i] {
return this->index(self, i); }))
3090 ow.writeRegion(fLoc, LeftBracketRegion);
3092 index_type len = index_type(m_pList.size());
3093 for (index_type i = 0; i < len; ++i) {
3097 ow.writeRegion(fLoc, CommaTokenRegion).ensureSpace();
3099 ow.ensureNewline(1);
3103 if (!compact && !first)
3105 ow.writeRegion(fLoc, RightBracketRegion);
3118
3119
3120
3121
3122
3141 return fileItem.ownerAs<JsFile>();
3143 return fileItem.ownerAs<QmlFile>();
3145 Q_UNREACHABLE_RETURN({});
3154#include "moc_qqmldomitem_p.cpp"
Path addObject(const QmlObject &object, QmlObject **oPtr=nullptr)
DomKind domKind() const override
quintptr id() const override
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
ConstantData(const Path &pathFromOwner, const QCborValue &value)
static CppTypeInfo fromString(QStringView target, const ErrorHandler &h=nullptr)
virtual DomItem containingObject(const DomItem &self) const
virtual void writeOut(const DomItem &self, OutWriter &lw) const
virtual QString canonicalFilePath(const DomItem &self) const
virtual void dump(const DomItem &, const Sink &sink, int indent, FilterT filter) const
virtual void updatePathFromOwner(const Path &newPath)
Path canonicalPath(const DomItem &self) const override
DomElement(const Path &pathFromOwner=Path())
DomItem containingObject(const DomItem &self) const override
A value type that references any element of the Dom.
QDateTime createdAt() const
std::shared_ptr< OwningItem > owningItemPtr() const
DomItem operator[](const QString &component) const
void writeOutPost(OutWriter &lw) const
bool visitTree(const Path &basePath, ChildrenVisitor visitor, VisitOptions options=VisitOption::Default, ChildrenVisitor openingVisitor=emptyChildrenVisitor, ChildrenVisitor closingVisitor=emptyChildrenVisitor, const FieldFilter &filter=FieldFilter::noFilter()) const
Visits recursively all the children of this item using the given visitors.
bool resolve(const Path &path, Visitor visitor, const ErrorHandler &errorHandler, const Path &fullPath=Path(), QList< Path > *visitedRefs=nullptr) const
DomItem path(const Path &p, const ErrorHandler &h=&defaultErrorHandler) const
DomItem containingFile() const
DomItem filterUp(function_ref< bool(DomType k, const DomItem &)> filter, FilterUpOptions options) const
DomItem scope(FilterUpOptions options=FilterUpOptions::ReturnOuter) const
bool visitLookup1(const QString &symbolName, function_ref< bool(const DomItem &)> visitor, LookupOptions=LookupOption::Normal, const ErrorHandler &h=nullptr, QSet< quintptr > *visited=nullptr, QList< Path > *visitedRefs=nullptr) const
DomItem get(const ErrorHandler &h=nullptr, QList< Path > *visitedRefs=nullptr) const
static ErrorGroups myErrors()
DomItem operator[](const char16_t *component) const
bool visitUp(function_ref< bool(const DomItem &)> visitor) const
Let the visitor visit the Dom Tree hierarchy of this DomItem.
index_type indexes() const
bool hasAnnotations() const
bool iterateSubOwners(function_ref< bool(const DomItem &owner)> visitor) const
MutableDomItem makeCopy(CopyOption option=CopyOption::EnvConnected) const
bool iterateErrors(function_ref< bool(const DomItem &, const ErrorMessage &)> visitor, bool iterate, Path inPath=Path()) const
DomItem proceedToScope(const ErrorHandler &h=nullptr, QList< Path > *visitedRefs=nullptr) const
Dereference DomItems pointing to other DomItems.
QList< DomItem > values() const
bool iterateDirectSubpaths(DirectVisitor v) const
DomItem container() const
void clearErrors(const ErrorGroups &groups=ErrorGroups({}), bool iterate=true) const
QList< QString > fields() const
bool writeOut(const QString &path, const LineWriterOptions &opt=LineWriterOptions(), FileWriter *fw=nullptr, WriteOutChecks extraChecks=WriteOutCheck::Default) const
DomItem(const std::shared_ptr< DomEnvironment > &)
FileWriter::Status dump(const QString &path, function_ref< bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter=noFilter, int indent=0, FileWriter *fw=nullptr) const
bool visitScopeChain(function_ref< bool(const DomItem &)> visitor, LookupOptions=LookupOption::Normal, const ErrorHandler &h=nullptr, QSet< quintptr > *visited=nullptr, QList< Path > *visitedRefs=nullptr) const
Let the visitor visit the QML scope hierarchy of this DomItem.
std::shared_ptr< DomTop > topPtr() const
QDateTime frozenAt() const
DomItem subListItem(const List &list) const
DomItem component(GoTo option=GoTo::Strict) const
bool visitLookup(const QString &symbolName, function_ref< bool(const DomItem &)> visitor, LookupType type=LookupType::Symbol, LookupOptions=LookupOption::Normal, const ErrorHandler &errorHandler=nullptr, QSet< quintptr > *visited=nullptr, QList< Path > *visitedRefs=nullptr) const
void writeOutPre(OutWriter &lw) const
DomItem lookupFirst(const QString &symbolName, LookupType type=LookupType::Symbol, LookupOptions=LookupOption::Normal, const ErrorHandler &errorHandler=nullptr) const
bool visitIndexes(function_ref< bool(const DomItem &)> visitor) const
DomItem fileObject(GoTo option=GoTo::Strict) const
bool visitKeys(function_ref< bool(const QString &, const DomItem &)> visitor) const
bool visitStaticTypePrototypeChains(function_ref< bool(const DomItem &)> visitor, VisitPrototypesOptions options=VisitPrototypesOption::Normal, const ErrorHandler &h=nullptr, QSet< quintptr > *visited=nullptr, QList< Path > *visitedRefs=nullptr) const
DomItem::visitStaticTypePrototypeChains.
QQmlJSScope::ConstPtr semanticScope() const
bool writeOutForFile(OutWriter &ow, WriteOutChecks extraChecks) const
bool commitToBase(const std::shared_ptr< DomEnvironment > &validPtr=nullptr) const
DomItem operator[](FieldName name) const
DomItem field(FieldName name) const
QList< DomItem > lookup(const QString &symbolName, LookupType type=LookupType::Symbol, LookupOptions=LookupOption::Normal, const ErrorHandler &errorHandler=nullptr) const
void dump(const Sink &, int indent=0, function_ref< bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter=noFilter) const
friend QMLDOM_EXPORT bool operator==(const DomItem &, const DomItem &)
QSet< QString > propertyInfoNames() const
static ErrorGroups myResolveErrors()
bool visitDirectAccessibleScopes(function_ref< bool(const DomItem &)> visitor, VisitPrototypesOptions options=VisitPrototypesOption::Normal, const ErrorHandler &h=nullptr, QSet< quintptr > *visited=nullptr, QList< Path > *visitedRefs=nullptr) const
DomItem environment() const
bool isCanonicalChild(const DomItem &child) const
DomItem operator[](QStringView component) const
DomItem rootQmlObject(GoTo option=GoTo::Strict) const
DomItem directParent() const
Path canonicalPath() const
QStringList sortedKeys() const
void addError(ErrorMessage &&msg) const
DomItem containingObject() const
DomItem containingScriptExpression() const
QList< DomItem > getAll(const ErrorHandler &h=nullptr, QList< Path > *visitedRefs=nullptr) const
bool visitPrototypeChain(function_ref< bool(const DomItem &)> visitor, VisitPrototypesOptions options=VisitPrototypesOption::Normal, const ErrorHandler &h=nullptr, QSet< quintptr > *visited=nullptr, QList< Path > *visitedRefs=nullptr) const
DomItem index(index_type) const
DomItem subReferencesItem(const PathEls::PathComponent &c, const QList< Path > &paths) const
bool visitLocalSymbolsNamed(const QString &name, function_ref< bool(const DomItem &)> visitor) const
DomItem subReferenceItem(const PathEls::PathComponent &c, const Path &referencedObject) const
void dumpPtr(const Sink &sink) const
InternalKind internalKind() const
bool isOwningItem() const
DomItem owner() const
The owner of an element, for an qmlObject this is the containing qml file.
ErrorHandler errorHandler() const
DomItem operator[](const Path &path) const
QQmlJSScope::ConstPtr nearestSemanticScope() const
QString canonicalFilePath() const
void writeOut(OutWriter &lw) const
Path pathFromOwner() const
DomItem qmlObject(GoTo option=GoTo::Strict, FilterUpOptions options=FilterUpOptions::ReturnOuter) const
Returns the QmlObject that this belongs to.
DomItem key(const QString &name) const
PropertyInfo propertyInfoWithName(const QString &name) const
QSet< QString > keys() const
std::shared_ptr< QQmlJSResourceFileMapper > resourceFileMapper() const
DomItem goToFile(const QString &filePath) const
QDateTime lastDataUpdateAt() const
DomItem(const std::shared_ptr< DomUniverse > &)
static ErrorGroup domErrorGroup
void dump(const DomItem &, const Sink &s, int indent, function_ref< bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter) const override
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
Path pathFromOwner() const override
Path canonicalPath(const DomItem &self) const override
DomItem containingObject(const DomItem &self) const override
convenience macro creating a new ErrorGroup and registering its groupId as translatable string
Represents a set of tags grouping a set of related error messages.
ErrorMessage warning(const Dumper &message) const
ErrorMessage error(const Dumper &message) const
Represents an error message connected to the dom.
ErrorMessage handle(const ErrorHandler &errorHandler=nullptr)
ErrorMessage & withItem(const DomItem &)
static FieldFilter compareNoCommentsFilter()
FileToLoad(const std::weak_ptr< DomEnvironment > &environment, const QString &canonicalPath, const QString &logicalPath, const std::optional< InMemoryContents > &content)
const LineWriterOptions & options() const
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor v) const override
void writeOut(const DomItem &self, OutWriter &ow, bool compact) const
void writeOut(const DomItem &self, OutWriter &ow, bool compact) const
std::function< bool(const DomItem &, function_ref< bool(index_type, function_ref< DomItem()>)>)> IteratorFunction
List(const Path &pathFromOwner, const LookupFunction &lookup, const Length &length, const IteratorFunction &iterator, const QString &elType)
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
void dump(const DomItem &, const Sink &s, int indent, function_ref< bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)>) const override
std::function< DomItem(const DomItem &, index_type)> LookupFunction
quintptr id() const override
index_type indexes(const DomItem &self) const override
DomItem index(const DomItem &self, index_type index) const override
std::function< index_type(const DomItem &)> Length
std::function< DomItem(const DomItem &, QString)> LookupFunction
Map(const Path &pathFromOwner, const LookupFunction &lookup, const Keys &keys, const QString &targetType)
std::function< QSet< QString >(const DomItem &)> Keys
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
QSet< QString > const keys(const DomItem &self) const override
quintptr id() const override
DomItem key(const DomItem &self, const QString &name) const override
MutableDomItem addChild(QmlObject child)
MutableDomItem addPropertyDef(const PropertyDefinition &propertyDef, AddOption option=AddOption::Overwrite)
ErrorHandler errorHandler()
MutableDomItem addMethod(const MethodInfo &functionDef, AddOption option=AddOption::Overwrite)
void addError(ErrorMessage &&msg)
MutableDomItem path(const Path &p)
MutableDomItem addBinding(Binding binding, AddOption option=AddOption::Overwrite)
A DomItem that owns other DomItems and is managed through a shared pointer.
QDateTime createdAt() const
virtual bool iterateSubOwners(const DomItem &self, function_ref< bool(const DomItem &owner)> visitor)
virtual int revision() const
DomItem containingObject(const DomItem &self) const override
bool iterateErrors(const DomItem &self, function_ref< bool(const DomItem &source, const ErrorMessage &msg)> visitor, const Path &inPath=Path())
virtual void addError(const DomItem &self, ErrorMessage &&msg)
static int nextRevision()
QDateTime frozenAt() const
void addErrorLocal(ErrorMessage &&msg)
virtual QDateTime lastDataUpdateAt() const
void clearErrors(const ErrorGroups &groups=ErrorGroups({}))
OwningItem(int derivedFrom, const QDateTime &lastDataUpdateAt)
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
virtual bool frozen() const
virtual void refreshedDataAt(QDateTime tNew)
OwningItem(int derivedFrom=0)
OwningItem(const OwningItem &o)
Path operator[](difference_type n) const
Represents an immutable JsonPath like path in the Qml code model (from a DomItem to another DomItem).
Path dropTail(int n=1) const
Source split() const
Splits the path at the last field or current component, or right after a root anchor.
PathIterator begin() const
Path withPath(const Path &toAdd) const
Returns a copy of this with toAdd appended to it.
std::optional< FieldName > headField() const
std::optional< PathRoot > headRoot() const
std::optional< PathCurrent > headCurrent() const
MutableDomItem addBinding(MutableDomItem &self, const Binding &binding, AddOption option)
MutableDomItem addChild(MutableDomItem &self, const QmlObject &child)
MutableDomItem addPropertyDef(MutableDomItem &self, const PropertyDefinition &propertyDef, AddOption option)
MutableDomItem addMethod(MutableDomItem &self, const MethodInfo &functionDef, AddOption option)
QList< std::pair< SourceLocation, DomItem > > Attributes
static bool addForPath(const DomItem &el, const Path &canonicalPath, const RefCacheEntry &entry, AddOption addOption=AddOption::KeepExisting)
static RefCacheEntry forPath(const DomItem &el, const Path &canonicalPath)
QList< QString > fields(const DomItem &self) const override
quintptr id() const override
static constexpr DomType kindValue
DomItem index(const DomItem &, index_type) const override
DomItem get(const DomItem &self, const ErrorHandler &h=nullptr, QList< Path > *visitedRefs=nullptr) const
DomItem field(const DomItem &self, FieldName name) const override
QList< DomItem > getAll(const DomItem &self, const ErrorHandler &h=nullptr, QList< Path > *visitedRefs=nullptr) const
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
Reference(const Path &referredObject=Path(), const Path &pathFromOwner=Path(), const SourceLocation &loc=SourceLocation())
DomItem key(const DomItem &, const QString &) const override
Use this to contain any script element.
ScriptElement::PointerType< ScriptElement > base() const
Returns a pointer to the virtual base for virtual method calls.
Provides entities to maintain mappings between elements and their location in a file.
Tree treeOf(const DomItem &)
QMLDOM_EXPORT bool domTypeIsContainer(DomType k)
static QMap< QString, LookupType > stringToLookupTypeMap()
constexpr bool domTypeIsOwningItem(DomType)
static std::optional< LookupType > lookupTypeFromString(const QString &expectedType)
static bool visitForLookupType(const DomItem &el, LookupType lookupType, function_ref< bool(const DomItem &)> visitor)
static DomItem rootFromContext(const DomItem &root, PathRoot contextId)
QMLDOM_EXPORT QMap< DomKind, QString > domKindToStringMap()
std::shared_ptr< ExternalOwningItem > getFileItemOwner(const DomItem &fileItem)
static bool visitQualifiedNameLookup(const DomItem &newIt, const QStringList &subpath, function_ref< bool(const DomItem &)> visitor, LookupType lookupType, const ErrorHandler &errorHandler, QList< Path > *visitedRefs)
bool operator!=(const DomItem &o1, const DomItem &o2)
QMLDOM_EXPORT bool domTypeIsExternalItem(DomType k)
QMLDOM_EXPORT QMap< DomType, QString > domTypeToStringMap()
QMLDOM_EXPORT bool domTypeIsScope(DomType k)
static LookupOptions resolveLookupOptions(const PathCurrent ¤t, const DomItem &it)
QMLDOM_EXPORT QString domTypeToString(DomType k)
QMLDOM_EXPORT QString domKindToString(DomKind k)
bool operator!=(const Path &lhs, const Path &rhs)
std::function< void(const ErrorMessage &)> ErrorHandler
QMLDOM_EXPORT bool domTypeIsTopItem(DomType k)
QMLDOM_EXPORT void defaultErrorHandler(const ErrorMessage &)
Calls the default error handler (by default errorToQDebug).
static bool visitPrototypeIndex(QList< DomItem > &toDo, const DomItem ¤t, const DomItem &derivedFromPrototype, const ErrorHandler &h, QList< Path > *visitedRefs, VisitPrototypesOptions options, const DomItem &prototype)
bool operator==(const Path &lhs, const Path &rhs)
static DomItem resolveReference(const DomItem &it, const Path &refRef, QList< Path > *visitedRefs, const ErrorHandler &errorHandler, const ErrorGroups &errorGroup)
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
#define NewErrorGroup(name)
A common base class for all the script elements.
void setSemanticScope(const QQmlJSScope::ConstPtr &scope)
QQmlJSScope::ConstPtr semanticScope()