Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmldomitem_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QMLDOMITEM_H
5#define QMLDOMITEM_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qqmldom_global.h"
19#include "qqmldom_fwd_p.h"
23#include "qqmldompath_p.h"
29
30#include <QtCore/QMap>
31#include <QtCore/QMultiMap>
32#include <QtCore/QSet>
33#include <QtCore/QString>
34#include <QtCore/QStringView>
35#include <QtCore/QDebug>
36#include <QtCore/QDateTime>
37#include <QtCore/QMutex>
38#include <QtCore/QCborValue>
39#include <QtCore/QTimeZone>
40#include <QtQml/private/qqmljssourcelocation_p.h>
41#include <QtQmlCompiler/private/qqmljsscope_p.h>
42
43#include <memory>
44#include <typeinfo>
45#include <utility>
46#include <type_traits>
47#include <variant>
48#include <optional>
49#include <cstddef>
50
52
54
55namespace QQmlJS {
56// we didn't have enough 'O's to properly name everything...
57namespace Dom {
58
59class Path;
60
61constexpr bool domTypeIsObjWrap(DomType k);
62constexpr bool domTypeIsValueWrap(DomType k);
63constexpr bool domTypeIsDomElement(DomType);
64constexpr bool domTypeIsOwningItem(DomType);
66constexpr bool domTypeIsScriptElement(DomType);
70constexpr bool domTypeCanBeInline(DomType k)
71{
72 switch (k) {
73 case DomType::Empty:
74 case DomType::Map:
75 case DomType::List:
76 case DomType::ListP:
81 return true;
82 default:
83 return false;
84 }
85}
87
92
93inline bool noFilter(const DomItem &, const PathEls::PathComponent &, const DomItem &)
94{
95 return true;
96}
97
99// using DirectVisitor = function_ref<bool(Path, const DomItem &)>;
100
101namespace {
102template<typename T>
103struct IsMultiMap : std::false_type
104{
105};
106
107template<typename Key, typename T>
108struct IsMultiMap<QMultiMap<Key, T>> : std::true_type
109{
110};
111
112template<typename T>
113struct IsMap : std::false_type
114{
115};
116
117template<typename Key, typename T>
118struct IsMap<QMap<Key, T>> : std::true_type
119{
120};
121
122template<typename... Ts>
123using void_t = void;
124
125template<typename T, typename = void>
126struct IsDomObject : std::false_type
127{
128};
129
130template<typename T>
131struct IsDomObject<T, void_t<decltype(T::kindValue)>> : std::true_type
132{
133};
134
135template<typename T, typename = void>
136struct IsInlineDom : std::false_type
137{
138};
139
140template<typename T>
141struct IsInlineDom<T, void_t<decltype(T::kindValue)>>
142 : std::integral_constant<bool, domTypeCanBeInline(T::kindValue)>
143{
144};
145
146template<typename T>
147struct IsInlineDom<T *, void_t<decltype(T::kindValue)>> : std::true_type
148{
149};
150
151template<typename T>
152struct IsInlineDom<std::shared_ptr<T>, void_t<decltype(T::kindValue)>> : std::true_type
153{
154};
155
156template<typename T>
157struct IsSharedPointerToDomObject : std::false_type
158{
159};
160
161template<typename T>
162struct IsSharedPointerToDomObject<std::shared_ptr<T>> : IsDomObject<T>
163{
164};
165
166template<typename T, typename = void>
167struct IsList : std::false_type
168{
169};
170
171template<typename T>
172struct IsList<T, void_t<typename T::value_type>> : std::true_type
173{
174};
175
176}
177
178template<typename T>
180 int i;
181 T lp;
182
183 // TODO: these are extremely nasty. What is this int doing in here?
184 T *data() { return reinterpret_cast<T *>(this); }
185 const T *data() const { return reinterpret_cast<const T *>(this); }
186
188 SubclassStorage(T &&el) { el.moveTo(data()); }
189 SubclassStorage(const T *el) { el->copyTo(data()); }
193 {
194 data()->~T();
195 o.data()->copyTo(data());
196 return *this;
197 }
198 ~SubclassStorage() { data()->~T(); }
199};
200
202{
203public:
204 using FilterT = function_ref<bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)>;
205
206 virtual ~DomBase() = default;
207
208 DomBase *domBase() { return this; }
209 const DomBase *domBase() const { return this; }
210
211 // minimal overload set:
212 virtual DomType kind() const = 0;
213 virtual DomKind domKind() const;
214 virtual Path pathFromOwner() const = 0;
215 virtual Path canonicalPath(const DomItem &self) const = 0;
216 virtual bool
218 DirectVisitor visitor) const = 0; // iterates the *direct* subpaths, returns
219 // false if a quick end was requested
220
222 const DomItem &self) const; // the DomItem corresponding to the canonicalSource source
223 virtual void dump(const DomItem &, const Sink &sink, int indent, FilterT filter) const;
224 virtual quintptr id() const;
225 QString typeName() const;
226
227 virtual QList<QString> fields(const DomItem &self) const;
228 virtual DomItem field(const DomItem &self, QStringView name) const;
229
230 virtual index_type indexes(const DomItem &self) const;
231 virtual DomItem index(const DomItem &self, index_type index) const;
232
233 virtual QSet<QString> const keys(const DomItem &self) const;
234 virtual DomItem key(const DomItem &self, const QString &name) const;
235
236 virtual QString canonicalFilePath(const DomItem &self) const;
237
238 virtual void writeOut(const DomItem &self, OutWriter &lw) const;
239
240 virtual QCborValue value() const {
241 return QCborValue();
242 }
243};
244
246{
247 switch (k) {
248 case DomType::Empty:
249 return DomKind::Empty;
250 case DomType::List:
251 case DomType::ListP:
252 return DomKind::List;
253 case DomType::Map:
254 return DomKind::Map;
255 case DomType::ConstantData:
256 return DomKind::Value;
257 default:
258 return DomKind::Object;
259 }
260}
261
262class QMLDOM_EXPORT Empty final : public DomBase
263{
264public:
265 constexpr static DomType kindValue = DomType::Empty;
266 DomType kind() const override { return kindValue; }
267
268 Empty *operator->() { return this; }
269 const Empty *operator->() const { return this; }
270 Empty &operator*() { return *this; }
271 const Empty &operator*() const { return *this; }
272
273 Empty();
274 quintptr id() const override { return ~quintptr(0); }
275 Path pathFromOwner() const override;
276 Path canonicalPath(const DomItem &self) const override;
277 DomItem containingObject(const DomItem &self) const override;
278 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
279 void dump(const DomItem &, const Sink &s, int indent,
280 function_ref<bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter)
281 const override;
282};
283
285protected:
286 DomElement& operator=(const DomElement&) = default;
287public:
288 DomElement(const Path &pathFromOwner = Path());
289 DomElement(const DomElement &o) = default;
290 Path pathFromOwner() const override { return m_pathFromOwner; }
291 Path canonicalPath(const DomItem &self) const override;
292 DomItem containingObject(const DomItem &self) const override;
293 virtual void updatePathFromOwner(const Path &newPath);
294
295private:
296 Path m_pathFromOwner;
297};
298
299class QMLDOM_EXPORT Map final : public DomElement
300{
301public:
302 constexpr static DomType kindValue = DomType::Map;
303 DomType kind() const override { return kindValue; }
304
305 Map *operator->() { return this; }
306 const Map *operator->() const { return this; }
307 Map &operator*() { return *this; }
308 const Map &operator*() const { return *this; }
309
310 using LookupFunction = std::function<DomItem(const DomItem &, QString)>;
311 using Keys = std::function<QSet<QString>(const DomItem &)>;
312 Map(const Path &pathFromOwner, const LookupFunction &lookup,
313 const Keys &keys, const QString &targetType);
314 quintptr id() const override;
315 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
316 QSet<QString> const keys(const DomItem &self) const override;
317 DomItem key(const DomItem &self, const QString &name) const override;
318
319 template<typename T>
320 static Map fromMultiMapRef(const Path &pathFromOwner, const QMultiMap<QString, T> &mmap);
321 template<typename T>
322 static Map fromMultiMap(const Path &pathFromOwner, const QMultiMap<QString, T> &mmap);
323 template<typename T>
324 static Map
326 const Path &pathFromOwner, const QMap<QString, T> &mmap,
327 const std::function<DomItem(const DomItem &, const PathEls::PathComponent &, const T &)> &elWrapper);
328
329 template<typename T>
330 static Map fromFileRegionMap(
331 const Path &pathFromOwner, const QMap<FileLocationRegion, T> &map);
332
333private:
334 template<typename MapT>
335 static QSet<QString> fileRegionKeysFromMap(const MapT &map);
336 LookupFunction m_lookup;
337 Keys m_keys;
338 QString m_targetType;
339};
340
341class QMLDOM_EXPORT List final : public DomElement
342{
343public:
344 constexpr static DomType kindValue = DomType::List;
345 DomType kind() const override { return kindValue; }
346
347 List *operator->() { return this; }
348 const List *operator->() const { return this; }
349 List &operator*() { return *this; }
350 const List &operator*() const { return *this; }
351
352 using LookupFunction = std::function<DomItem(const DomItem &, index_type)>;
355 std::function<bool(const DomItem &, function_ref<bool(index_type, function_ref<DomItem()>)>)>;
356
357 List(const Path &pathFromOwner, const LookupFunction &lookup, const Length &length,
358 const IteratorFunction &iterator, const QString &elType);
359 quintptr id() const override;
360 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
361 void
362 dump(const DomItem &, const Sink &s, int indent,
363 function_ref<bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)>) const override;
364 index_type indexes(const DomItem &self) const override;
365 DomItem index(const DomItem &self, index_type index) const override;
366
367 template<typename T>
368 static List
369 fromQList(const Path &pathFromOwner, const QList<T> &list,
370 const std::function<DomItem(const DomItem &, const PathEls::PathComponent &, const T &)> &elWrapper,
372 template<typename T>
373 static List
374 fromQListRef(const Path &pathFromOwner, const QList<T> &list,
375 const std::function<DomItem(const DomItem &, const PathEls::PathComponent &, const T &)> &elWrapper,
377 void writeOut(const DomItem &self, OutWriter &ow, bool compact) const;
378 void writeOut(const DomItem &self, OutWriter &ow) const override { writeOut(self, ow, true); }
379
380private:
381 LookupFunction m_lookup;
382 Length m_length;
383 IteratorFunction m_iterator;
384 QString m_elType;
385};
386
388{
389public:
390 constexpr static DomType kindValue = DomType::ListP;
391 DomType kind() const override { return kindValue; }
392
393 ListPBase(const Path &pathFromOwner, const QList<const void *> &pList, const QString &elType)
394 : DomElement(pathFromOwner), m_pList(pList), m_elType(elType)
395 {
396 }
397 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor v) const override;
398 virtual void copyTo(ListPBase *) const { Q_ASSERT(false); };
399 virtual void moveTo(ListPBase *) const { Q_ASSERT(false); };
400 quintptr id() const override { return quintptr(0); }
401 index_type indexes(const DomItem &) const override { return index_type(m_pList.size()); }
402 void writeOut(const DomItem &self, OutWriter &ow, bool compact) const;
403 void writeOut(const DomItem &self, OutWriter &ow) const override { writeOut(self, ow, true); }
404
405protected:
406 QList<const void *> m_pList;
408};
409
410template<typename T>
411class ListPT final : public ListPBase
412{
413public:
414 constexpr static DomType kindValue = DomType::ListP;
415
416 ListPT(const Path &pathFromOwner, const QList<T *> &pList, const QString &elType = QString(),
418 : ListPBase(pathFromOwner, {},
419 (elType.isEmpty() ? QLatin1String(typeid(T).name()) : elType))
420 {
421 static_assert(sizeof(ListPBase) == sizeof(ListPT),
422 "ListPT does not have the same size as ListPBase");
423 static_assert(alignof(ListPBase) == alignof(ListPT),
424 "ListPT does not have the same size as ListPBase");
425 m_pList.reserve(pList.size());
426 if (options == ListOptions::Normal) {
427 for (const void *p : pList)
428 m_pList.append(p);
429 } else if (options == ListOptions::Reverse) {
430 for (qsizetype i = pList.size(); i-- != 0;)
431 // probably writing in reverse and reading sequentially would be better
432 m_pList.append(pList.at(i));
433 } else {
434 Q_ASSERT(false);
435 }
436 }
437 void copyTo(ListPBase *t) const override { new (t) ListPT(*this); }
438 void moveTo(ListPBase *t) const override { new (t) ListPT(std::move(*this)); }
439 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor v) const override;
440
441 DomItem index(const DomItem &self, index_type index) const override;
442};
443
445{
446public:
447 constexpr static DomType kindValue = DomType::ListP;
448 template<typename T>
449 ListP(const Path &pathFromOwner, const QList<T *> &pList, const QString &elType = QString(),
452 {
453 }
454 ListP() = delete;
455
456 ListPBase *operator->() { return list.data(); }
457 const ListPBase *operator->() const { return list.data(); }
458 ListPBase &operator*() { return *list.data(); }
459 const ListPBase &operator*() const { return *list.data(); }
460
461private:
463};
464
465class QMLDOM_EXPORT ConstantData final : public DomElement
466{
467public:
469 DomType kind() const override { return kindValue; }
470
475
476 ConstantData *operator->() { return this; }
477 const ConstantData *operator->() const { return this; }
478 ConstantData &operator*() { return *this; }
479 const ConstantData &operator*() const { return *this; }
480
481 ConstantData(const Path &pathFromOwner, const QCborValue &value,
482 Options options = Options::MapIsMap);
483 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
484 quintptr id() const override;
485 DomKind domKind() const override;
486 QCborValue value() const override { return m_value; }
487 Options options() const { return m_options; }
488private:
489 QCborValue m_value;
490 Options m_options;
491};
492
494{
495public:
497 DomType kind() const final override { return m_kind; }
498
499 quintptr id() const final override { return m_id; }
500 DomKind domKind() const final override { return m_domKind; }
501
502 template <typename T>
503 T const *as() const
504 {
505 if (m_options & SimpleWrapOption::ValueType) {
506 if (m_value.metaType() == QMetaType::fromType<T>())
507 return static_cast<const T *>(m_value.constData());
508 return nullptr;
509 } else {
510 return m_value.value<const T *>();
511 }
512 }
513
515 virtual void copyTo(SimpleObjectWrapBase *) const { Q_ASSERT(false); }
516 virtual void moveTo(SimpleObjectWrapBase *) const { Q_ASSERT(false); }
517 bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override
518 {
519 Q_ASSERT(false);
520 return true;
521 }
522
523protected:
524 friend class TestDomItem;
525 SimpleObjectWrapBase(const Path &pathFromOwner, const QVariant &value, quintptr idValue,
526 DomType kind = kindValue,
527 SimpleWrapOptions options = SimpleWrapOption::None)
528 : DomElement(pathFromOwner),
529 m_kind(kind),
531 m_value(value),
532 m_id(idValue),
534 {
535 }
536
542};
543
544template<typename T>
545class SimpleObjectWrapT final : public SimpleObjectWrapBase
546{
547public:
549
550 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override
551 {
552 return asT()->iterateDirectSubpaths(self, visitor);
553 }
554
555 void writeOut(const DomItem &self, OutWriter &lw) const override;
556
557 const T *asT() const
558 {
559 if constexpr (domTypeIsValueWrap(T::kindValue)) {
560 if (m_value.metaType() == QMetaType::fromType<T>())
561 return static_cast<const T *>(m_value.constData());
562 return nullptr;
563 } else if constexpr (domTypeIsObjWrap(T::kindValue)) {
564 return m_value.value<const T *>();
565 } else {
566 // need dependent static assert to not unconditially trigger
567 static_assert(!std::is_same_v<T, T>, "wrapping of unexpected type");
568 return nullptr; // necessary to avoid warnings on INTEGRITY
569 }
570 }
571
572 void copyTo(SimpleObjectWrapBase *target) const override
573 {
574 static_assert(sizeof(SimpleObjectWrapBase) == sizeof(SimpleObjectWrapT),
575 "Size mismatch in SimpleObjectWrapT");
576 static_assert(alignof(SimpleObjectWrapBase) == alignof(SimpleObjectWrapT),
577 "Size mismatch in SimpleObjectWrapT");
578 new (target) SimpleObjectWrapT(*this);
579 }
580
581 void moveTo(SimpleObjectWrapBase *target) const override
582 {
583 static_assert(sizeof(SimpleObjectWrapBase) == sizeof(SimpleObjectWrapT),
584 "Size mismatch in SimpleObjectWrapT");
585 static_assert(alignof(SimpleObjectWrapBase) == alignof(SimpleObjectWrapT),
586 "Size mismatch in SimpleObjectWrapT");
587 new (target) SimpleObjectWrapT(std::move(*this));
588 }
589
590 SimpleObjectWrapT(const Path &pathFromOwner, const QVariant &v,
591 quintptr idValue, SimpleWrapOptions o)
592 : SimpleObjectWrapBase(pathFromOwner, v, idValue, T::kindValue, o)
593 {
594 Q_ASSERT(domTypeIsValueWrap(T::kindValue) == bool(o & SimpleWrapOption::ValueType));
595 }
596};
597
599{
600public:
602
603 SimpleObjectWrapBase *operator->() { return wrap.data(); }
604 const SimpleObjectWrapBase *operator->() const { return wrap.data(); }
605 SimpleObjectWrapBase &operator*() { return *wrap.data(); }
606 const SimpleObjectWrapBase &operator*() const { return *wrap.data(); }
607
608 template<typename T>
609 static SimpleObjectWrap fromObjectRef(const Path &pathFromOwner, T &value)
610 {
611 return SimpleObjectWrap(pathFromOwner, value);
612 }
614
615private:
616 template<typename T>
617 SimpleObjectWrap(const Path &pathFromOwner, T &value)
618 {
619 using BaseT = std::decay_t<T>;
620 if constexpr (domTypeIsObjWrap(BaseT::kindValue)) {
621 new (wrap.data()) SimpleObjectWrapT<BaseT>(pathFromOwner, QVariant::fromValue(&value),
622 quintptr(&value), SimpleWrapOption::None);
623 } else if constexpr (domTypeIsValueWrap(BaseT::kindValue)) {
624 new (wrap.data()) SimpleObjectWrapT<BaseT>(pathFromOwner, QVariant::fromValue(value),
625 quintptr(0), SimpleWrapOption::ValueType);
626 } else {
627 qCWarning(domLog) << "Unexpected object to wrap in SimpleObjectWrap: "
628 << domTypeToString(BaseT::kindValue);
629 Q_ASSERT_X(false, "SimpleObjectWrap",
630 "simple wrap of unexpected object"); // allow? (mocks for testing,...)
631 new (wrap.data())
632 SimpleObjectWrapT<BaseT>(pathFromOwner, nullptr, 0, SimpleWrapOption::None);
633 }
634 }
636};
637
639{
641public:
642 constexpr static DomType kindValue = DomType::Reference;
643 DomType kind() const override { return kindValue; }
644
645 Reference *operator->() { return this; }
646 const Reference *operator->() const { return this; }
647 Reference &operator*() { return *this; }
648 const Reference &operator*() const { return *this; }
649
650 bool shouldCache() const;
651 Reference(const Path &referredObject = Path(), const Path &pathFromOwner = Path(),
652 const SourceLocation &loc = SourceLocation());
653 quintptr id() const override;
654 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
655 DomItem field(const DomItem &self, QStringView name) const override;
656 QList<QString> fields(const DomItem &self) const override;
657 index_type indexes(const DomItem &) const override { return 0; }
658 DomItem index(const DomItem &, index_type) const override;
659 QSet<QString> const keys(const DomItem &) const override { return {}; }
660 DomItem key(const DomItem &, const QString &) const override;
661
662 DomItem get(const DomItem &self, const ErrorHandler &h = nullptr,
663 QList<Path> *visitedRefs = nullptr) const;
664 QList<DomItem> getAll(const DomItem &self, const ErrorHandler &h = nullptr,
665 QList<Path> *visitedRefs = nullptr) const;
666
668};
669
670namespace FileLocations {
671struct Info;
672}
673
674/*!
675 \internal
676 \brief A common base class for all the script elements.
677
678 This marker class allows to use all the script elements as a ScriptElement*, using virtual
679 dispatch. For now, it does not add any extra functionality, compared to a DomElement, but allows
680 to forbid DomElement* at the places where only script elements are required.
681 */
682// TODO: do we need another marker struct like this one to differentiate expressions from
683// statements? This would allow to avoid mismatchs between script expressions and script statements,
684// using type-safety.
686{
687 template<typename T>
688 using PointerType = std::shared_ptr<T>;
689
690 using DomElement::DomElement;
691 virtual void
692 createFileLocations(const std::shared_ptr<FileLocations::Node> &fileLocationOfOwner) = 0;
693
695 void setSemanticScope(const QQmlJSScope::ConstPtr &scope);
696
697private:
698 QQmlJSScope::ConstPtr m_scope;
699};
700
701/*!
702 \internal
703 \brief Use this to contain any script element.
704 */
706{
707private:
708 template<typename... T>
710
711 template<typename T, typename Variant>
712 struct TypeIsInVariant;
713
714 template<typename T, typename... Ts>
715 struct TypeIsInVariant<T, std::variant<Ts...>> : public std::disjunction<std::is_same<T, Ts>...>
716 {
717 };
718
719public:
726
727 template<typename T>
728 static ScriptElementVariant fromElement(const T &element)
729 {
730 static_assert(TypeIsInVariant<T, ScriptElementT>::value,
731 "Cannot construct ScriptElementVariant from T, as it is missing from the "
732 "ScriptElementT.");
734 p.m_data = element;
735 return p;
736 }
737
739
740 operator bool() const { return m_data.has_value(); }
741
742 template<typename F>
743 void visitConst(F &&visitor) const
744 {
745 if (m_data)
746 std::visit(std::forward<F>(visitor), *m_data);
747 }
748
749 template<typename F>
750 void visit(F &&visitor)
751 {
752 if (m_data)
753 std::visit(std::forward<F>(visitor), *m_data);
754 }
755 std::optional<ScriptElementT> data() { return m_data; }
756 void setData(const ScriptElementT &data) { m_data = data; }
757
758private:
759 std::optional<ScriptElementT> m_data;
760};
761
762/*!
763 \internal
764
765 To avoid cluttering the already unwieldy \l ElementT type below with all the types that the
766 different script elements can have, wrap them in an extra class. It will behave like an internal
767 Dom structure (e.g. like a List or a Map) and contain a pointer the the script element.
768 */
770{
771public:
773
775
776 DomBase *operator->() { return m_element.base().get(); }
777 const DomBase *operator->() const { return m_element.base().get(); }
778 DomBase &operator*() { return *m_element.base(); }
779 const DomBase &operator*() const { return *m_element.base(); }
780
781 ScriptElementVariant element() const { return m_element; }
782
783private:
784 ScriptElementVariant m_element;
785};
786
787// TODO: create more "groups" to simplify this variant? Maybe into Internal, ScriptExpression, ???
788using ElementT =
789 std::variant<ConstantData, Empty, List, ListP, Map, Reference, ScriptElementDomWrapper,
791 const DomEnvironment *, const DomUniverse *, const EnumDecl *,
793 const GlobalComponent *, const GlobalScope *, const JsFile *,
794 const JsResource *, const LoadInfo *, const MockObject *, const MockOwner *,
795 const ModuleIndex *, const ModuleScope *, const QmlComponent *,
796 const QmlDirectory *, const QmlFile *, const QmlObject *, const QmldirFile *,
797 const QmltypesComponent *, const QmltypesFile *, const ScriptExpression *>;
798
799using TopT = std::variant<
800 std::monostate,
801 std::shared_ptr<DomEnvironment>,
802 std::shared_ptr<DomUniverse>>;
803
804using OwnerT =
805 std::variant<std::monostate, std::shared_ptr<ModuleIndex>, std::shared_ptr<MockOwner>,
806 std::shared_ptr<ExternalItemInfoBase>, std::shared_ptr<ExternalItemPairBase>,
807 std::shared_ptr<QmlDirectory>, std::shared_ptr<QmldirFile>,
808 std::shared_ptr<JsFile>, std::shared_ptr<QmlFile>,
809 std::shared_ptr<QmltypesFile>, std::shared_ptr<GlobalScope>,
810 std::shared_ptr<ScriptExpression>, std::shared_ptr<AstComments>,
811 std::shared_ptr<LoadInfo>, std::shared_ptr<FileLocations::Node>,
812 std::shared_ptr<DomEnvironment>, std::shared_ptr<DomUniverse>>;
813
814inline bool emptyChildrenVisitor(Path, const DomItem &, bool)
815{
816 return true;
817}
818
819class MutableDomItem;
820
822{
823public:
829
830 FileToLoad(const std::weak_ptr<DomEnvironment> &environment, const QString &canonicalPath,
831 const QString &logicalPath, const std::optional<InMemoryContents> &content);
832 FileToLoad() = default;
833
834 static FileToLoad fromMemory(const std::weak_ptr<DomEnvironment> &environment,
835 const QString &path, const QString &data);
836 static FileToLoad fromFileSystem(const std::weak_ptr<DomEnvironment> &environment,
837 const QString &canonicalPath);
838
839 std::shared_ptr<DomEnvironment> environment() const { return m_environment.lock(); }
840 QString canonicalPath() const { return m_canonicalPath; }
841 QString logicalPath() const { return m_logicalPath; }
842 void setCanonicalPath(const QString &canonicalPath) { m_canonicalPath = canonicalPath; }
843 void setLogicalPath(const QString &logicalPath) { m_logicalPath = logicalPath; }
844 std::optional<InMemoryContents> content() const { return m_content; }
845
846private:
847 std::weak_ptr<DomEnvironment> m_environment;
848 QString m_canonicalPath;
849 QString m_logicalPath;
850 std::optional<InMemoryContents> m_content;
851};
852
855public:
856 using Callback = std::function<void(const Path &, const DomItem &, const DomItem &)>;
857
859 using Visitor = function_ref<bool(const Path &, const DomItem &)>;
860 using ChildrenVisitor = function_ref<bool(const Path &, const DomItem &, bool)>;
861
863 static ErrorGroups myErrors();
866
868
869 template<typename F>
870 auto visitEl(F f) const
871 {
872 return std::visit(f, this->m_element);
873 }
874
875 explicit operator bool() const { return m_kind != DomType::Empty; }
877 return m_kind;
878 }
879 QString internalKindStr() const { return domTypeToString(internalKind()); }
881 {
882 if (m_kind == DomType::ConstantData)
883 return std::get<ConstantData>(m_element).domKind();
884 else
885 return kind2domKind(m_kind);
886 }
887
888 Path canonicalPath() const;
889
890 DomItem filterUp(function_ref<bool(DomType k, const DomItem &)> filter, FilterUpOptions options) const;
892 DomItem container() const;
893 DomItem owner() const;
894 DomItem top() const;
895 DomItem environment() const;
896 DomItem universe() const;
897 DomItem containingFile() const;
899 DomItem goToFile(const QString &filePath) const;
900 DomItem goUp(int) const;
901 DomItem directParent() const;
902
903 DomItem qmlObject(GoTo option = GoTo::Strict,
905 DomItem fileObject(GoTo option = GoTo::Strict) const;
906 DomItem rootQmlObject(GoTo option = GoTo::Strict) const;
907 DomItem globalScope() const;
908 DomItem component(GoTo option = GoTo::Strict) const;
912
913 // convenience getters
914 DomItem get(const ErrorHandler &h = nullptr, QList<Path> *visitedRefs = nullptr) const;
915 QList<DomItem> getAll(const ErrorHandler &h = nullptr, QList<Path> *visitedRefs = nullptr) const;
921 bool isCanonicalChild(const DomItem &child) const;
922 bool hasAnnotations() const;
923 QString name() const { return field(Fields::name).value().toString(); }
924 DomItem pragmas() const { return field(Fields::pragmas); }
925 DomItem ids() const { return field(Fields::ids); }
926 QString idStr() const { return field(Fields::idStr).value().toString(); }
927 DomItem propertyInfos() const { return field(Fields::propertyInfos); }
928 PropertyInfo propertyInfoWithName(const QString &name) const;
930 DomItem propertyDefs() const { return field(Fields::propertyDefs); }
931 DomItem bindings() const { return field(Fields::bindings); }
932 DomItem methods() const { return field(Fields::methods); }
933 DomItem enumerations() const { return field(Fields::enumerations); }
934 DomItem children() const { return field(Fields::children); }
935 DomItem child(index_type i) const { return field(Fields::children).index(i); }
937 {
939 return field(Fields::annotations);
940 else
941 return DomItem();
942 }
943
944 bool resolve(const Path &path, Visitor visitor, const ErrorHandler &errorHandler,
945 ResolveOptions options = ResolveOption::None, const Path &fullPath = Path(),
946 QList<Path> *visitedRefs = nullptr) const;
947
948 DomItem operator[](const Path &path) const;
949 DomItem operator[](QStringView component) const;
950 DomItem operator[](const QString &component) const;
951 DomItem operator[](const char16_t *component) const
952 {
953 return (*this)[QStringView(component)];
954 } // to avoid clash with stupid builtin ptrdiff_t[DomItem&], coming from C
955 DomItem operator[](index_type i) const { return index(i); }
956 DomItem operator[](int i) const { return index(i); }
957 index_type size() const { return indexes() + keys().size(); }
958 index_type length() const { return size(); }
959
960 DomItem path(const Path &p, const ErrorHandler &h = &defaultErrorHandler) const;
961 DomItem path(const QString &p, const ErrorHandler &h = &defaultErrorHandler) const;
962 DomItem path(QStringView p, const ErrorHandler &h = &defaultErrorHandler) const;
963
964 QList<QString> fields() const;
965 DomItem field(QStringView name) const;
966
967 index_type indexes() const;
968 DomItem index(index_type) const;
969 bool visitIndexes(function_ref<bool(const DomItem &)> visitor) const;
970
971 QSet<QString> keys() const;
972 QStringList sortedKeys() const;
973 DomItem key(const QString &name) const;
974 DomItem key(QStringView name) const { return key(name.toString()); }
975 bool visitKeys(function_ref<bool(const QString &, const DomItem &)> visitor) const;
976
977 QList<DomItem> values() const;
978 void writeOutPre(OutWriter &lw) const;
979 void writeOut(OutWriter &lw) const;
980 void writeOutPost(OutWriter &lw) const;
981 bool writeOutForFile(OutWriter &ow, WriteOutChecks extraChecks) const;
982 bool writeOut(const QString &path, const LineWriterOptions &opt = LineWriterOptions(),
983 FileWriter *fw = nullptr,
984 WriteOutChecks extraChecks = WriteOutCheck::Default) const;
985
986 bool visitTree(const Path &basePath, ChildrenVisitor visitor,
987 VisitOptions options = VisitOption::Default,
988 ChildrenVisitor openingVisitor = emptyChildrenVisitor,
989 ChildrenVisitor closingVisitor = emptyChildrenVisitor,
990 const FieldFilter &filter = FieldFilter::noFilter()) const;
991 bool visitPrototypeChain(function_ref<bool(const DomItem &)> visitor,
992 VisitPrototypesOptions options = VisitPrototypesOption::Normal,
993 const ErrorHandler &h = nullptr, QSet<quintptr> *visited = nullptr,
994 QList<Path> *visitedRefs = nullptr) const;
995 bool visitDirectAccessibleScopes(function_ref<bool(const DomItem &)> visitor,
996 VisitPrototypesOptions options = VisitPrototypesOption::Normal,
997 const ErrorHandler &h = nullptr, QSet<quintptr> *visited = nullptr,
998 QList<Path> *visitedRefs = nullptr) const;
999 bool
1000 visitStaticTypePrototypeChains(function_ref<bool(const DomItem &)> visitor,
1001 VisitPrototypesOptions options = VisitPrototypesOption::Normal,
1002 const ErrorHandler &h = nullptr, QSet<quintptr> *visited = nullptr,
1003 QList<Path> *visitedRefs = nullptr) const;
1004
1005 bool visitUp(function_ref<bool(const DomItem &)> visitor) const;
1006 bool visitScopeChain(
1007 function_ref<bool(const DomItem &)> visitor, LookupOptions = LookupOption::Normal,
1008 const ErrorHandler &h = nullptr, QSet<quintptr> *visited = nullptr,
1009 QList<Path> *visitedRefs = nullptr) const;
1011 const QString &name, function_ref<bool(const DomItem &)> visitor) const;
1012 bool visitLookup1(
1013 const QString &symbolName, function_ref<bool(const DomItem &)> visitor,
1014 LookupOptions = LookupOption::Normal, const ErrorHandler &h = nullptr,
1015 QSet<quintptr> *visited = nullptr, QList<Path> *visitedRefs = nullptr) const;
1016 bool visitLookup(
1017 const QString &symbolName, function_ref<bool(const DomItem &)> visitor,
1018 LookupType type = LookupType::Symbol, LookupOptions = LookupOption::Normal,
1019 const ErrorHandler &errorHandler = nullptr, QSet<quintptr> *visited = nullptr,
1020 QList<Path> *visitedRefs = nullptr) const;
1022 const QString &name, function_ref<bool(const DomItem &)> visitor) const;
1024 const ErrorHandler &h = nullptr, QList<Path> *visitedRefs = nullptr) const;
1026 const QString &symbolName, LookupType type = LookupType::Symbol,
1027 LookupOptions = LookupOption::Normal, const ErrorHandler &errorHandler = nullptr) const;
1029 const QString &symbolName, LookupType type = LookupType::Symbol,
1030 LookupOptions = LookupOption::Normal, const ErrorHandler &errorHandler = nullptr) const;
1031
1032 quintptr id() const;
1033 Path pathFromOwner() const;
1034 QString canonicalFilePath() const;
1036 bool commitToBase(const std::shared_ptr<DomEnvironment> &validPtr = nullptr) const;
1038 QCborValue value() const;
1039
1040 void dumpPtr(const Sink &sink) const;
1041 void dump(const Sink &, int indent = 0,
1042 function_ref<bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter =
1043 noFilter) const;
1045 dump(const QString &path,
1046 function_ref<bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)>
1047 filter = noFilter,
1048 int indent = 0, FileWriter *fw = nullptr) const;
1049 QString toString() const;
1050
1051 // OwnigItem elements
1052 int derivedFrom() const;
1053 int revision() const;
1054 QDateTime createdAt() const;
1055 QDateTime frozenAt() const;
1057
1058 void addError(ErrorMessage &&msg) const;
1059 ErrorHandler errorHandler() const;
1060 void clearErrors(const ErrorGroups &groups = ErrorGroups({}), bool iterate = true) const;
1061 // return false if a quick exit was requested
1062 bool iterateErrors(
1063 function_ref<bool (const DomItem &, const ErrorMessage &)> visitor, bool iterate,
1064 Path inPath = Path()) const;
1065
1066 bool iterateSubOwners(function_ref<bool(const DomItem &owner)> visitor) const;
1067 bool iterateDirectSubpaths(DirectVisitor v) const;
1068
1069 template<typename T>
1070 DomItem subDataItem(const PathEls::PathComponent &c, const T &value,
1071 ConstantData::Options options = ConstantData::Options::MapIsMap) const;
1072 template<typename T>
1073 DomItem subValueItem(const PathEls::PathComponent &c, const T &value,
1074 ConstantData::Options options = ConstantData::Options::MapIsMap) const;
1075 template <typename T>
1076 bool invokeVisitorOnValue(DirectVisitor visitor, const PathEls::PathComponent &c, const T &value,
1077 ConstantData::Options options = ConstantData::Options::MapIsMap) const;
1078 template <typename F>
1079 bool invokeVisitorOnLazyField(DirectVisitor visitor, QStringView f, F valueF,
1080 ConstantData::Options options = ConstantData::Options::MapIsMap) const
1081 {
1082 PathEls::PathComponent c = PathEls::Field(f);
1083 auto lazyWrap = [this, &c, &valueF, options]() {
1084 return this->subValueItem<decltype(valueF())>(c, valueF(), options);
1085 };
1086 return visitor(c, lazyWrap);
1087 }
1088 DomItem subReferencesItem(const PathEls::PathComponent &c, const QList<Path> &paths) const;
1089 DomItem subReferenceItem(const PathEls::PathComponent &c, const Path &referencedObject) const;
1090 bool invokeVisitorOnReference(DirectVisitor visitor, QStringView f,
1091 const Path &referencedObject) const
1092 {
1093 PathEls::PathComponent c = PathEls::Field(f);
1094 return visitor(c, [c, this, referencedObject]() {
1095 return this->subReferenceItem(c, referencedObject);
1096 });
1097 }
1098 bool invokeVisitorOnReferences(DirectVisitor visitor, QStringView f,
1099 const QList<Path> &paths) const
1100 {
1101 PathEls::PathComponent c = PathEls::Field(f);
1102 return visitor(c, [c, this, paths]() { return this->subReferencesItem(c, paths); });
1103 }
1104 DomItem subListItem(const List &list) const;
1105 DomItem subMapItem(const Map &map) const;
1106
1108 {
1109 Q_ASSERT(obj);
1110 return DomItem(m_top, m_owner, m_ownerPath, ScriptElementDomWrapper(obj));
1111 }
1112
1113 template<typename Owner>
1114 DomItem subOwnerItem(const PathEls::PathComponent &c, Owner o) const
1115 {
1116 if constexpr (domTypeIsUnattachedOwningItem(Owner::element_type::kindValue))
1117 return DomItem(m_top, o, canonicalPath().withComponent(c), o.get());
1118 else
1119 return DomItem(m_top, o, Path(), o.get());
1120 }
1121 template <typename T>
1122 DomItem wrap(const PathEls::PathComponent &c, const T &obj) const;
1123 template <typename T>
1124 bool invokeVisitorOnField(DirectVisitor visitor, QStringView f, T &obj) const
1125 {
1126 PathEls::PathComponent c = PathEls::Field(f);
1127 auto lazyWrap = [this, &c, &obj]() { return this->wrap<T>(c, obj); };
1128 return visitor(c, lazyWrap);
1129 }
1130
1131 DomItem() = default;
1132 DomItem(const std::shared_ptr<DomEnvironment> &);
1133 DomItem(const std::shared_ptr<DomUniverse> &);
1134
1135 // TODO move to DomEnvironment?
1136 static DomItem fromCode(const QString &code, DomType fileType = DomType::QmlFile);
1137
1138 // --- start of potentially dangerous stuff, make private? ---
1139
1140 std::shared_ptr<DomTop> topPtr() const;
1141 std::shared_ptr<OwningItem> owningItemPtr() const;
1142
1143 // keep the DomItem around to ensure that it doesn't get deleted
1144 template<typename T, typename std::enable_if<std::is_base_of_v<DomBase, T>, bool>::type = true>
1145 T const *as() const
1146 {
1147 if (m_kind == T::kindValue) {
1148 if constexpr (domTypeIsObjWrap(T::kindValue) || domTypeIsValueWrap(T::kindValue))
1149 return std::get<SimpleObjectWrap>(m_element)->as<T>();
1150 else
1151 return static_cast<T const *>(base());
1152 }
1153 return nullptr;
1154 }
1155
1156 template<typename T, typename std::enable_if<!std::is_base_of_v<DomBase, T>, bool>::type = true>
1157 T const *as() const
1158 {
1159 if (m_kind == T::kindValue) {
1160 Q_ASSERT(domTypeIsObjWrap(m_kind) || domTypeIsValueWrap(m_kind));
1161 return std::get<SimpleObjectWrap>(m_element)->as<T>();
1162 }
1163 return nullptr;
1164 }
1165
1166 template<typename T>
1167 std::shared_ptr<T> ownerAs() const;
1168
1169 template<typename Owner, typename T>
1170 DomItem copy(const Owner &owner, const Path &ownerPath, const T &base) const
1171 {
1172 Q_ASSERT(!std::holds_alternative<std::monostate>(m_top));
1173 static_assert(IsInlineDom<std::decay_t<T>>::value, "Expected an inline item or pointer");
1174 return DomItem(m_top, owner, ownerPath, base);
1175 }
1176
1177 template<typename Owner>
1178 DomItem copy(const Owner &owner, const Path &ownerPath) const
1179 {
1180 Q_ASSERT(!std::holds_alternative<std::monostate>(m_top));
1181 return DomItem(m_top, owner, ownerPath, owner.get());
1182 }
1183
1184 template<typename T>
1185 DomItem copy(const T &base) const
1186 {
1187 Q_ASSERT(!std::holds_alternative<std::monostate>(m_top));
1188 using BaseT = std::decay_t<T>;
1189 static_assert(!std::is_same_v<BaseT, ElementT>,
1190 "variant not supported, pass in the stored types");
1191 static_assert(IsInlineDom<BaseT>::value || std::is_same_v<BaseT, std::monostate>,
1192 "expected either a pointer or an inline item");
1193
1194 if constexpr (IsSharedPointerToDomObject<BaseT>::value)
1195 return DomItem(m_top, base, Path(), base.get());
1196 else if constexpr (IsInlineDom<BaseT>::value)
1197 return DomItem(m_top, m_owner, m_ownerPath, base);
1198
1199 Q_UNREACHABLE_RETURN(DomItem(m_top, m_owner, m_ownerPath, nullptr));
1200 }
1201
1202private:
1203 enum class WriteOutCheckResult { Success, Failed };
1204 WriteOutCheckResult performWriteOutChecks(const DomItem &, OutWriter &, WriteOutChecks) const;
1205 const DomBase *base() const;
1206
1207 template<typename Env, typename Owner>
1208 DomItem(Env, Owner, Path, std::nullptr_t) : DomItem()
1209 {
1210 }
1211
1212 template<typename Env, typename Owner, typename T,
1213 typename = std::enable_if_t<IsInlineDom<std::decay_t<T>>::value>>
1214 DomItem(Env env, Owner owner, const Path &ownerPath, const T &el)
1215 : m_top(env), m_owner(owner), m_ownerPath(ownerPath), m_element(el)
1216 {
1217 using BaseT = std::decay_t<T>;
1218 if constexpr (std::is_pointer_v<BaseT>) {
1219 if (!el || el->kind() == DomType::Empty) { // avoid null ptr, and allow only a
1220 // single kind of Empty
1221 m_kind = DomType::Empty;
1222 m_top = std::monostate();
1223 m_owner = std::monostate();
1224 m_ownerPath = Path();
1225 m_element = Empty();
1226 } else {
1227 using DomT = std::remove_pointer_t<BaseT>;
1228 m_element = el;
1229 m_kind = DomT::kindValue;
1230 }
1231 } else {
1232 static_assert(!std::is_same_v<BaseT, ElementT>,
1233 "variant not supported, pass in the internal type");
1234 m_kind = el->kind();
1235 }
1236 }
1237 friend class DomBase;
1238 friend class DomElement;
1239 friend class Map;
1240 friend class List;
1241 friend class QmlObject;
1242 friend class DomUniverse;
1243 friend class DomEnvironment;
1245 friend class ConstantData;
1246 friend class MutableDomItem;
1247 friend class ScriptExpression;
1248 friend class AstComments;
1249 friend class FileLocations::Node;
1250 friend class TestDomItem;
1251 friend QMLDOM_EXPORT bool operator==(const DomItem &, const DomItem &);
1252 DomType m_kind = DomType::Empty;
1253 TopT m_top;
1254 OwnerT m_owner;
1255 Path m_ownerPath;
1256 ElementT m_element = Empty();
1257};
1258
1259QMLDOM_EXPORT bool operator==(const DomItem &o1, const DomItem &o2);
1260
1261inline bool operator!=(const DomItem &o1, const DomItem &o2)
1262{
1263 return !(o1 == o2);
1264}
1265
1266template<typename T>
1267static DomItem keyMultiMapHelper(const DomItem &self, const QString &key,
1268 const QMultiMap<QString, T> &mmap)
1269{
1270 auto it = mmap.find(key);
1271 auto end = mmap.cend();
1272 if (it == end)
1273 return DomItem();
1274 else {
1275 // special case single element (++it == end || it.key() != key)?
1276 QList<const T *> values;
1277 while (it != end && it.key() == key)
1278 values.append(&(*it++));
1279 ListP ll(self.pathFromOwner().withComponent(PathEls::Key(key)), values, QString(),
1281 return self.copy(ll);
1282 }
1283}
1284
1285template<typename T>
1286Map Map::fromMultiMapRef(const Path &pathFromOwner, const QMultiMap<QString, T> &mmap)
1287{
1288 return Map(
1289 pathFromOwner,
1290 [&mmap](const DomItem &self, const QString &key) {
1291 return keyMultiMapHelper(self, key, mmap);
1292 },
1293 [&mmap](const DomItem &) { return QSet<QString>(mmap.keyBegin(), mmap.keyEnd()); },
1294 QLatin1String(typeid(T).name()));
1295}
1296
1297template<typename T>
1298Map Map::fromMapRef(
1299 const Path &pathFromOwner, const QMap<QString, T> &map,
1300 const std::function<DomItem(const DomItem &, const PathEls::PathComponent &, const T &)> &elWrapper)
1301{
1302 return Map(
1303 pathFromOwner,
1304 [&map, elWrapper](const DomItem &self, const QString &key) {
1305 const auto it = map.constFind(key);
1306 if (it == map.constEnd())
1307 return DomItem();
1308 return elWrapper(self, PathEls::Key(key), it.value());
1309 },
1310 [&map](const DomItem &) { return QSet<QString>(map.keyBegin(), map.keyEnd()); },
1311 QLatin1String(typeid(T).name()));
1312}
1313
1314template<typename MapT>
1315QSet<QString> Map::fileRegionKeysFromMap(const MapT &map)
1316{
1317 QSet<QString> keys;
1318 std::transform(map.keyBegin(), map.keyEnd(), std::inserter(keys, keys.begin()), fileLocationRegionName);
1319 return keys;
1320}
1321
1322template<typename T>
1323Map Map::fromFileRegionMap(const Path &pathFromOwner, const QMap<FileLocationRegion, T> &map)
1324{
1325 auto result = Map(
1326 pathFromOwner,
1327 [&map](const DomItem &mapItem, const QString &key) -> DomItem {
1328 auto it = map.constFind(fileLocationRegionValue(key));
1329 if (it == map.constEnd())
1330 return {};
1331
1332 return mapItem.wrap(PathEls::Key(key), *it);
1333 },
1334 [&map](const DomItem &) { return fileRegionKeysFromMap(map); },
1335 QString::fromLatin1(typeid(T).name()));
1336 return result;
1337}
1338
1339template<typename T>
1340List List::fromQList(
1341 const Path &pathFromOwner, const QList<T> &list,
1342 const std::function<DomItem(const DomItem &, const PathEls::PathComponent &, const T &)> &elWrapper,
1343 ListOptions options)
1344{
1345 index_type len = list.size();
1346 if (options == ListOptions::Reverse) {
1347 return List(
1348 pathFromOwner,
1349 [list, elWrapper](const DomItem &self, index_type i) mutable {
1350 if (i < 0 || i >= list.size())
1351 return DomItem();
1352 return elWrapper(self, PathEls::Index(i), list[list.size() - i - 1]);
1353 },
1354 [len](const DomItem &) { return len; }, nullptr, QLatin1String(typeid(T).name()));
1355 } else {
1356 return List(
1357 pathFromOwner,
1358 [list, elWrapper](const DomItem &self, index_type i) mutable {
1359 if (i < 0 || i >= list.size())
1360 return DomItem();
1361 return elWrapper(self, PathEls::Index(i), list[i]);
1362 },
1363 [len](const DomItem &) { return len; }, nullptr, QLatin1String(typeid(T).name()));
1364 }
1365}
1366
1367template<typename T>
1368List List::fromQListRef(
1369 const Path &pathFromOwner, const QList<T> &list,
1370 const std::function<DomItem(const DomItem &, const PathEls::PathComponent &, const T &)> &elWrapper,
1371 ListOptions options)
1372{
1373 if (options == ListOptions::Reverse) {
1374 return List(
1375 pathFromOwner,
1376 [&list, elWrapper](const DomItem &self, index_type i) {
1377 if (i < 0 || i >= list.size())
1378 return DomItem();
1379 return elWrapper(self, PathEls::Index(i), list[list.size() - i - 1]);
1380 },
1381 [&list](const DomItem &) { return list.size(); }, nullptr,
1382 QLatin1String(typeid(T).name()));
1383 } else {
1384 return List(
1385 pathFromOwner,
1386 [&list, elWrapper](const DomItem &self, index_type i) {
1387 if (i < 0 || i >= list.size())
1388 return DomItem();
1389 return elWrapper(self, PathEls::Index(i), list[i]);
1390 },
1391 [&list](const DomItem &) { return list.size(); }, nullptr,
1392 QLatin1String(typeid(T).name()));
1393 }
1394}
1395
1397protected:
1398 virtual std::shared_ptr<OwningItem> doCopy(const DomItem &self) const = 0;
1399
1400public:
1401 OwningItem(const OwningItem &o);
1402 OwningItem(int derivedFrom=0);
1403 OwningItem(int derivedFrom, const QDateTime &lastDataUpdateAt);
1404 OwningItem(const OwningItem &&) = delete;
1405 OwningItem &operator=(const OwningItem &&) = delete;
1406 static int nextRevision();
1407
1408 Path canonicalPath(const DomItem &self) const override = 0;
1409
1410 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
1411 std::shared_ptr<OwningItem> makeCopy(const DomItem &self) const { return doCopy(self); }
1412 Path pathFromOwner() const override final { return Path(); }
1413 DomItem containingObject(const DomItem &self) const override;
1414 int derivedFrom() const;
1415 virtual int revision() const;
1416
1417 QDateTime createdAt() const;
1418 virtual QDateTime lastDataUpdateAt() const;
1419 virtual void refreshedDataAt(QDateTime tNew);
1420
1421 // explicit freeze handling needed?
1422 virtual bool frozen() const;
1423 virtual bool freeze();
1424 QDateTime frozenAt() const;
1425
1426 virtual void addError(const DomItem &self, ErrorMessage &&msg);
1427 void addErrorLocal(ErrorMessage &&msg);
1428 void clearErrors(const ErrorGroups &groups = ErrorGroups({}));
1429 // return false if a quick exit was requested
1430 bool iterateErrors(
1431 const DomItem &self,
1432 function_ref<bool(const DomItem &source, const ErrorMessage &msg)> visitor,
1433 const Path &inPath = Path());
1435 QMutexLocker l(mutex());
1436 return m_errors;
1437 }
1438
1439 virtual bool iterateSubOwners(const DomItem &self, function_ref<bool(const DomItem &owner)> visitor);
1440
1441 QBasicMutex *mutex() const { return &m_mutex; }
1442private:
1443 mutable QBasicMutex m_mutex;
1444 int m_derivedFrom;
1445 int m_revision;
1446 QDateTime m_createdAt;
1447 QDateTime m_lastDataUpdateAt;
1448 QDateTime m_frozenAt;
1449 QMultiMap<Path, ErrorMessage> m_errors;
1450 QMap<ErrorMessage, quint32> m_errorsCounts;
1451};
1452
1453template<typename T>
1454std::shared_ptr<T> DomItem::ownerAs() const
1455{
1456 if constexpr (domTypeIsOwningItem(T::kindValue)) {
1457 if (!std::holds_alternative<std::monostate>(m_owner)) {
1458 if constexpr (T::kindValue == DomType::FileLocationsNode) {
1459 if (std::holds_alternative<std::shared_ptr<FileLocations::Node>>(m_owner))
1460 return std::static_pointer_cast<T>(
1461 std::get<std::shared_ptr<FileLocations::Node>>(m_owner));
1462 } else if constexpr (T::kindValue == DomType::ExternalItemInfo) {
1463 if (std::holds_alternative<std::shared_ptr<ExternalItemInfoBase>>(m_owner))
1464 return std::static_pointer_cast<T>(
1465 std::get<std::shared_ptr<ExternalItemInfoBase>>(m_owner));
1466 } else if constexpr (T::kindValue == DomType::ExternalItemPair) {
1467 if (std::holds_alternative<std::shared_ptr<ExternalItemPairBase>>(m_owner))
1468 return std::static_pointer_cast<T>(
1469 std::get<std::shared_ptr<ExternalItemPairBase>>(m_owner));
1470 } else {
1471 if (std::holds_alternative<std::shared_ptr<T>>(m_owner)) {
1472 return std::get<std::shared_ptr<T>>(m_owner);
1473 }
1474 }
1475 }
1476 } else {
1477 Q_ASSERT_X(false, "DomItem::ownerAs", "unexpected non owning value in ownerAs");
1478 }
1479 return std::shared_ptr<T> {};
1480}
1481
1482template<int I>
1483struct rank : rank<I - 1>
1484{
1485 static_assert(I > 0, "");
1486};
1487template<>
1488struct rank<0>
1489{
1490};
1491
1492template<typename T>
1493auto writeOutWrap(const T &t, const DomItem &self, OutWriter &lw, rank<1>)
1494 -> decltype(t.writeOut(self, lw))
1495{
1496 t.writeOut(self, lw);
1497}
1498
1499template<typename T>
1500auto writeOutWrap(const T &, const DomItem &, OutWriter &, rank<0>) -> void
1501{
1502 qCWarning(writeOutLog) << "Ignoring writeout to wrapped object not supporting it ("
1503 << typeid(T).name();
1504}
1505template<typename T>
1506auto writeOutWrap(const T &t, const DomItem &self, OutWriter &lw) -> void
1507{
1508 writeOutWrap(t, self, lw, rank<1>());
1509}
1510
1511template<typename T>
1512void SimpleObjectWrapT<T>::writeOut(const DomItem &self, OutWriter &lw) const
1513{
1514 writeOutWrap<T>(*asT(), self, lw);
1515}
1516
1517QMLDOM_EXPORT QDebug operator<<(QDebug debug, const DomItem &c);
1518
1519// TODO QTBUG-121518 quite some methods are used only in the "examples"
1520// Even though MutableDomItem provides some API for modifying internal data,
1521// de-facto it's not very helpful / convinient / intuitive to use
1522// Moreover it just amplifies and repeats issues of DomItem interface,
1523// a.k.a. abuse or misuse of type erasure technique
1525public:
1527
1528 explicit operator bool() const
1529 {
1530 return bool(m_owner);
1531 } // this is weaker than item(), but normally correct
1533 QString internalKindStr() { return domTypeToString(internalKind()); }
1534 DomKind domKind() { return kind2domKind(internalKind()); }
1535
1536 Path canonicalPath() const { return m_owner.canonicalPath().withPath(m_pathFromOwner); }
1538 {
1539 if (m_pathFromOwner)
1540 return MutableDomItem(m_owner, m_pathFromOwner.split().pathToSource);
1541 else {
1542 DomItem cObj = m_owner.containingObject();
1544 }
1545 }
1546
1548 {
1549 if (m_pathFromOwner)
1550 return MutableDomItem(m_owner, m_pathFromOwner.dropTail());
1551 else {
1553 }
1554 }
1555
1558 {
1559 return MutableDomItem(item().qmlObject(option, fOptions));
1560 }
1562 {
1563 return MutableDomItem(item().fileObject(option));
1564 }
1566 {
1567 return MutableDomItem(item().rootQmlObject(option));
1568 }
1571
1573 {
1574 return MutableDomItem { item().component(option) };
1575 }
1576 MutableDomItem owner() { return MutableDomItem(m_owner); }
1580 Path pathFromOwner() { return m_pathFromOwner; }
1582 MutableDomItem operator[](QStringView component) { return MutableDomItem(item()[component]); }
1583 MutableDomItem operator[](const QString &component)
1584 {
1585 return MutableDomItem(item()[component]);
1586 }
1587 MutableDomItem operator[](const char16_t *component)
1588 {
1589 // to avoid clash with stupid builtin ptrdiff_t[MutableDomItem&], coming from C
1590 return MutableDomItem(item()[QStringView(component)]);
1591 }
1592 MutableDomItem operator[](index_type i) { return MutableDomItem(item().index(i)); }
1593
1595 MutableDomItem path(const QString &p) { return path(Path::fromString(p)); }
1596 MutableDomItem path(QStringView p) { return path(Path::fromString(p)); }
1597
1598 QList<QString> const fields() { return item().fields(); }
1599 MutableDomItem field(QStringView name) { return MutableDomItem(item().field(name)); }
1600 index_type indexes() { return item().indexes(); }
1601 MutableDomItem index(index_type i) { return MutableDomItem(item().index(i)); }
1602
1603 QSet<QString> const keys() { return item().keys(); }
1604 MutableDomItem key(const QString &name) { return MutableDomItem(item().key(name)); }
1605 MutableDomItem key(QStringView name) { return key(name.toString()); }
1606
1607 void
1608 dump(const Sink &s, int indent = 0,
1609 function_ref<bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter = noFilter)
1610 {
1611 item().dump(s, indent, filter);
1612 }
1614 dump(const QString &path,
1615 function_ref<bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)>
1616 filter = noFilter,
1617 int indent = 0, FileWriter *fw = nullptr)
1618 {
1619 return item().dump(path, filter, indent, fw);
1620 }
1621 void writeOut(OutWriter &lw) { return item().writeOut(lw); }
1622 bool writeOut(const QString &path, const LineWriterOptions &opt = LineWriterOptions(),
1623 FileWriter *fw = nullptr)
1624 {
1625 return item().writeOut(path, opt, fw);
1626 }
1627
1632 bool commitToBase(const std::shared_ptr<DomEnvironment> &validEnvPtr = nullptr)
1633 {
1634 return item().commitToBase(validEnvPtr);
1635 }
1636 QString canonicalFilePath() const { return item().canonicalFilePath(); }
1637
1639
1640 QCborValue value() { return item().value(); }
1641
1642 QString toString() { return item().toString(); }
1643
1644 // convenience getters
1645 QString name() { return item().name(); }
1648 QString idStr() { return item().idStr(); }
1653 MutableDomItem child(index_type i) { return MutableDomItem(item().child(i)); }
1655
1656 // // OwnigItem elements
1657 int derivedFrom() { return m_owner.derivedFrom(); }
1658 int revision() { return m_owner.revision(); }
1659 QDateTime createdAt() { return m_owner.createdAt(); }
1660 QDateTime frozenAt() { return m_owner.frozenAt(); }
1661 QDateTime lastDataUpdateAt() { return m_owner.lastDataUpdateAt(); }
1662
1663 void addError(ErrorMessage &&msg) { item().addError(std::move(msg)); }
1665
1666 // convenience setters
1671 const MethodInfo &functionDef, AddOption option = AddOption::Overwrite);
1673
1674 MutableDomItem() = default;
1675 MutableDomItem(const DomItem &owner, const Path &pathFromOwner):
1677 {}
1681
1682 std::shared_ptr<DomTop> topPtr() { return m_owner.topPtr(); }
1683 std::shared_ptr<OwningItem> owningItemPtr() { return m_owner.owningItemPtr(); }
1684
1685 template<typename T>
1686 T const *as()
1687 {
1688 return item().as<T>();
1689 }
1690
1691 template <typename T>
1693 Q_ASSERT(!m_owner || !m_owner.owningItemPtr()->frozen());
1694
1695 DomItem self = item();
1696 if (self.m_kind != T::kindValue)
1697 return nullptr;
1698
1699 const T *t = nullptr;
1700 if constexpr (domTypeIsObjWrap(T::kindValue) || domTypeIsValueWrap(T::kindValue))
1701 t = static_cast<const SimpleObjectWrapBase *>(self.base())->as<T>();
1702 else if constexpr (std::is_base_of<DomBase, T>::value)
1703 t = static_cast<const T *>(self.base());
1704 else
1705 Q_UNREACHABLE_RETURN(nullptr);
1706
1707 // Nasty. But since ElementT has to store the const pointers, we allow it in this one place.
1708 return const_cast<T *>(t);
1709 }
1710
1711 template<typename T>
1712 std::shared_ptr<T> ownerAs() const
1713 {
1714 return m_owner.ownerAs<T>();
1715 }
1716 // it is dangerous to assume it stays valid when updates are preformed...
1717 DomItem item() const { return m_owner.path(m_pathFromOwner); }
1718
1719 friend bool operator==(const MutableDomItem &o1, const MutableDomItem &o2)
1720 {
1721 return o1.m_owner == o2.m_owner && o1.m_pathFromOwner == o2.m_pathFromOwner;
1722 }
1723 friend bool operator!=(const MutableDomItem &o1, const MutableDomItem &o2)
1724 {
1725 return !(o1 == o2);
1726 }
1727
1728private:
1729 DomItem m_owner;
1730 Path m_pathFromOwner;
1731};
1732
1733QMLDOM_EXPORT QDebug operator<<(QDebug debug, const MutableDomItem &c);
1734
1735template<typename K, typename T>
1736Path insertUpdatableElementInMultiMap(const Path &mapPathFromOwner, QMultiMap<K, T> &mmap, K key,
1737 const T &value, AddOption option = AddOption::KeepExisting,
1738 T **valuePtr = nullptr)
1739{
1740 if (option == AddOption::Overwrite) {
1741 auto it = mmap.find(key);
1742 if (it != mmap.end()) {
1743 T &v = *it;
1744 v = value;
1745 if (++it != mmap.end() && it.key() == key) {
1746 qWarning() << " requested overwrite of " << key
1747 << " that contains aleready multiple entries in" << mapPathFromOwner;
1748 }
1749 Path newPath = mapPathFromOwner.withKey(key).withIndex(0);
1750 v.updatePathFromOwner(newPath);
1751 if (valuePtr)
1752 *valuePtr = &v;
1753 return newPath;
1754 }
1755 }
1756 mmap.insert(key, value);
1757 auto it = mmap.find(key);
1758 auto it2 = it;
1759 int nVal = 0;
1760 while (it2 != mmap.end() && it2.key() == key) {
1761 ++nVal;
1762 ++it2;
1763 }
1764 Path newPath = mapPathFromOwner.withKey(key).withIndex(nVal-1);
1765 T &v = *it;
1766 v.updatePathFromOwner(newPath);
1767 if (valuePtr)
1768 *valuePtr = &v;
1769 return newPath;
1770}
1771
1772template<typename T>
1773Path appendUpdatableElementInQList(const Path &listPathFromOwner, QList<T> &list, const T &value,
1774 T **vPtr = nullptr)
1775{
1776 int idx = list.size();
1777 list.append(value);
1778 Path newPath = listPathFromOwner.withIndex(idx);
1779 T &targetV = list[idx];
1780 targetV.updatePathFromOwner(newPath);
1781 if (vPtr)
1782 *vPtr = &targetV;
1783 return newPath;
1784}
1785
1786template <typename T, typename K = QString>
1787void updatePathFromOwnerMultiMap(QMultiMap<K, T> &mmap, const Path &newPath)
1788{
1789 auto it = mmap.begin();
1790 auto end = mmap.end();
1791 index_type i = 0;
1792 K name;
1793 QList<T*> els;
1794 while (it != end) {
1795 if (i > 0 && name != it.key()) {
1796 Path pName = newPath.withKey(QString(name));
1797 for (T *el : els)
1798 el->updatePathFromOwner(pName.withIndex(--i));
1799 els.clear();
1800 els.append(&(*it));
1801 name = it.key();
1802 i = 1;
1803 } else {
1804 els.append(&(*it));
1805 name = it.key();
1806 ++i;
1807 }
1808 ++it;
1809 }
1810 Path pName = newPath.withKey(name);
1811 for (T *el : els)
1812 el->updatePathFromOwner(pName.withIndex(--i));
1813}
1814
1815template <typename T>
1816void updatePathFromOwnerQList(QList<T> &list, const Path &newPath)
1817{
1818 auto it = list.begin();
1819 auto end = list.end();
1820 index_type i = 0;
1821 while (it != end)
1822 (it++)->updatePathFromOwner(newPath.withIndex(i++));
1823}
1824
1825constexpr bool domTypeIsObjWrap(DomType k)
1826{
1827 switch (k) {
1828 case DomType::Binding:
1829 case DomType::EnumItem:
1831 case DomType::Export:
1832 case DomType::Id:
1833 case DomType::Import:
1838 case DomType::Pragma:
1840 case DomType::Version:
1841 case DomType::Comment:
1845 return true;
1846 default:
1847 return false;
1848 }
1849}
1850
1852{
1853 switch (k) {
1855 return true;
1856 default:
1857 return false;
1858 }
1859}
1860
1862{
1863 switch (k) {
1865 case DomType::QmlObject:
1868 case DomType::Reference:
1869 case DomType::Map:
1870 case DomType::List:
1871 case DomType::ListP:
1872 case DomType::EnumDecl:
1878 return true;
1879 default:
1880 return false;
1881 }
1882}
1883
1885{
1886 switch (k) {
1888
1889 case DomType::MockOwner:
1890
1893
1896 case DomType::JsFile:
1897 case DomType::QmlFile:
1900
1903
1904 case DomType::LoadInfo:
1906
1909 return true;
1910 default:
1911 return false;
1912 }
1913}
1914
1916{
1917 switch (k) {
1921 return true;
1922 default:
1923 return false;
1924 }
1925}
1926
1928{
1930}
1931
1932template<typename T>
1934 ConstantData::Options options) const
1935{
1936 using BaseT = std::remove_cv_t<std::remove_reference_t<T>>;
1937 if constexpr (
1938 std::is_base_of_v<
1939 QCborValue,
1940 BaseT> || std::is_base_of_v<QCborArray, BaseT> || std::is_base_of_v<QCborMap, BaseT>) {
1941 return DomItem(m_top, m_owner, m_ownerPath,
1942 ConstantData(pathFromOwner().withComponent(c), value, options));
1943 } else if constexpr (std::is_same_v<DomItem, BaseT>) {
1944 Q_UNUSED(options);
1945 return value;
1946 } else if constexpr (IsList<T>::value && !std::is_convertible_v<BaseT, QStringView>) {
1947 return subListItem(List::fromQList<typename BaseT::value_type>(
1948 pathFromOwner().withComponent(c), value,
1949 [options](const DomItem &list, const PathEls::PathComponent &p,
1950 const typename T::value_type &v) { return list.subValueItem(p, v, options); }));
1951 } else if constexpr (IsSharedPointerToDomObject<BaseT>::value) {
1952 Q_UNUSED(options);
1953 return subOwnerItem(c, value);
1954 } else {
1955 return subDataItem(c, value, options);
1956 }
1957}
1958
1959template<typename T>
1961 ConstantData::Options options) const
1962{
1963 using BaseT = std::remove_cv_t<std::remove_reference_t<T>>;
1964 if constexpr (std::is_same_v<BaseT, ConstantData>) {
1965 return this->copy(value);
1966 } else if constexpr (std::is_base_of_v<QCborValue, BaseT>) {
1967 return DomItem(m_top, m_owner, m_ownerPath,
1968 ConstantData(pathFromOwner().withComponent(c), value, options));
1969 } else {
1970 return DomItem(
1971 m_top, m_owner, m_ownerPath,
1972 ConstantData(pathFromOwner().withComponent(c), QCborValue(value), options));
1973 }
1974}
1975
1976template <typename T>
1977bool DomItem::invokeVisitorOnValue(DirectVisitor visitor, const PathEls::PathComponent &c,
1978 const T &value, ConstantData::Options options) const
1979{
1980 auto lazyWrap = [this, &c, &value, options]() {
1981 return this->subValueItem<T>(c, value, options);
1982 };
1983 return visitor(c, lazyWrap);
1984}
1985
1986template<typename T>
1987DomItem DomItem::wrap(const PathEls::PathComponent &c, const T &obj) const
1988{
1989 using BaseT = std::decay_t<T>;
1990 if constexpr (std::is_same_v<QString, BaseT> || std::is_arithmetic_v<BaseT>) {
1991 return this->subDataItem(c, QCborValue(obj));
1992 } else if constexpr (std::is_same_v<SourceLocation, BaseT>) {
1993 return this->subDataItem(c, sourceLocationToQCborValue(obj));
1994 } else if constexpr (std::is_same_v<BaseT, Reference>) {
1995 Q_ASSERT_X(false, "DomItem::wrap",
1996 "wrapping a reference object, probably an error (wrap the target path instead)");
1997 return this->copy(obj);
1998 } else if constexpr (std::is_same_v<BaseT, ConstantData>) {
1999 return this->subDataItem(c, obj);
2000 } else if constexpr (std::is_same_v<BaseT, Map>) {
2001 return this->subMapItem(obj);
2002 } else if constexpr (std::is_same_v<BaseT, List>) {
2003 return this->subListItem(obj);
2004 } else if constexpr (std::is_base_of_v<ListPBase, BaseT>) {
2005 return this->subListItem(obj);
2006 } else if constexpr (std::is_same_v<BaseT, SimpleObjectWrap>) {
2007 return DomItem(m_top, m_owner, m_ownerPath, obj);
2008 } else if constexpr (IsDomObject<BaseT>::value) {
2009 if constexpr (domTypeIsObjWrap(BaseT::kindValue) || domTypeIsValueWrap(BaseT::kindValue)) {
2010 return DomItem(
2011 m_top, m_owner, m_ownerPath,
2012 SimpleObjectWrap::fromObjectRef(this->pathFromOwner().withComponent(c), obj));
2013 } else if constexpr (domTypeIsDomElement(BaseT::kindValue)) {
2014 return this->copy(&obj);
2015 } else {
2016 qCWarning(domLog) << "Unhandled object of type " << domTypeToString(BaseT::kindValue)
2017 << " in DomItem::wrap, not using a shared_ptr for an "
2018 << "OwningItem, or unexpected wrapped object?";
2019 return DomItem();
2020 }
2021 } else if constexpr (IsSharedPointerToDomObject<BaseT>::value) {
2022 if constexpr (domTypeIsOwningItem(BaseT::element_type::kindValue)) {
2023 return this->subOwnerItem(c, obj);
2024 } else {
2025 Q_ASSERT_X(false, "DomItem::wrap", "shared_ptr with non owning item");
2026 return DomItem();
2027 }
2028 } else if constexpr (IsMultiMap<BaseT>::value) {
2029 if constexpr (std::is_same_v<typename BaseT::key_type, QString>) {
2030 return subMapItem(Map::fromMultiMapRef<typename BaseT::mapped_type>(
2031 pathFromOwner().withComponent(c), obj));
2032 } else {
2033 Q_ASSERT_X(false, "DomItem::wrap", "non string keys not supported (try .toString()?)");
2034 }
2035 } else if constexpr (IsMap<BaseT>::value) {
2036 if constexpr (std::is_same_v<typename BaseT::key_type, QString>) {
2037 return subMapItem(Map::fromMapRef<typename BaseT::mapped_type>(
2038 pathFromOwner().withComponent(c), obj,
2039 [](const DomItem &map, const PathEls::PathComponent &p,
2040 const typename BaseT::mapped_type &el) { return map.wrap(p, el); }));
2041 } else {
2042 Q_ASSERT_X(false, "DomItem::wrap", "non string keys not supported (try .toString()?)");
2043 }
2044 } else if constexpr (IsList<BaseT>::value) {
2045 if constexpr (IsDomObject<typename BaseT::value_type>::value) {
2046 return subListItem(List::fromQListRef<typename BaseT::value_type>(
2047 pathFromOwner().withComponent(c), obj,
2048 [](const DomItem &list, const PathEls::PathComponent &p,
2049 const typename BaseT::value_type &el) { return list.wrap(p, el); }));
2050 } else {
2051 Q_ASSERT_X(false, "DomItem::wrap", "Unsupported list type T");
2052 return DomItem();
2053 }
2054 } else {
2055 qCWarning(domLog) << "Cannot wrap " << typeid(BaseT).name();
2056 Q_ASSERT_X(false, "DomItem::wrap", "Do not know how to wrap type T");
2057 return DomItem();
2058 }
2059}
2060
2061template<typename T>
2062bool ListPT<T>::iterateDirectSubpaths(const DomItem &self, DirectVisitor v) const
2063{
2064 index_type len = index_type(m_pList.size());
2065 for (index_type i = 0; i < len; ++i) {
2066 if (!v(PathEls::Index(i), [this, &self, i] { return this->index(self, i); }))
2067 return false;
2068 }
2069 return true;
2070}
2071
2072template<typename T>
2073DomItem ListPT<T>::index(const DomItem &self, index_type index) const
2074{
2075 if (index >= 0 && index < m_pList.size())
2076 return self.wrap(PathEls::Index(index), *static_cast<const T *>(m_pList.value(index)));
2077 return DomItem();
2078}
2079
2080// allow inlining of DomBase
2081inline DomKind DomBase::domKind() const
2082{
2083 return kind2domKind(kind());
2084}
2085
2086inline DomItem DomBase::containingObject(const DomItem &self) const
2087{
2088 Path path = pathFromOwner();
2089 DomItem base = self.owner();
2090 if (!path) {
2091 path = canonicalPath(self);
2092 base = self;
2093 }
2094 Source source = path.split();
2095 return base.path(source.pathToSource);
2096}
2097
2098inline quintptr DomBase::id() const
2099{
2100 return quintptr(this);
2101}
2102
2103inline QString DomBase::typeName() const
2104{
2105 return domTypeToString(kind());
2106}
2107
2108inline QList<QString> DomBase::fields(const DomItem &self) const
2109{
2110 QList<QString> res;
2111 self.iterateDirectSubpaths([&res](const PathEls::PathComponent &c, function_ref<DomItem()>) {
2112 if (c.kind() == Path::Kind::Field)
2113 res.append(c.name());
2114 return true;
2115 });
2116 return res;
2117}
2118
2119inline DomItem DomBase::field(const DomItem &self, QStringView name) const
2120{
2121 DomItem res;
2122 self.iterateDirectSubpaths(
2123 [&res, name](const PathEls::PathComponent &c, function_ref<DomItem()> obj) {
2124 if (c.kind() == Path::Kind::Field && c.checkName(name)) {
2125 res = obj();
2126 return false;
2127 }
2128 return true;
2129 });
2130 return res;
2131}
2132
2133inline index_type DomBase::indexes(const DomItem &self) const
2134{
2135 index_type res = 0;
2136 self.iterateDirectSubpaths([&res](const PathEls::PathComponent &c, function_ref<DomItem()>) {
2137 if (c.kind() == Path::Kind::Index) {
2138 index_type i = c.index() + 1;
2139 if (res < i)
2140 res = i;
2141 }
2142 return true;
2143 });
2144 return res;
2145}
2146
2147inline DomItem DomBase::index(const DomItem &self, qint64 index) const
2148{
2149 DomItem res;
2150 self.iterateDirectSubpaths(
2151 [&res, index](const PathEls::PathComponent &c, function_ref<DomItem()> obj) {
2152 if (c.kind() == Path::Kind::Index && c.index() == index) {
2153 res = obj();
2154 return false;
2155 }
2156 return true;
2157 });
2158 return res;
2159}
2160
2161inline QSet<QString> const DomBase::keys(const DomItem &self) const
2162{
2163 QSet<QString> res;
2164 self.iterateDirectSubpaths([&res](const PathEls::PathComponent &c, function_ref<DomItem()>) {
2165 if (c.kind() == Path::Kind::Key)
2166 res.insert(c.name());
2167 return true;
2168 });
2169 return res;
2170}
2171
2172inline DomItem DomBase::key(const DomItem &self, const QString &name) const
2173{
2174 DomItem res;
2175 self.iterateDirectSubpaths(
2176 [&res, name](const PathEls::PathComponent &c, function_ref<DomItem()> obj) {
2177 if (c.kind() == Path::Kind::Key && c.checkName(name)) {
2178 res = obj();
2179 return false;
2180 }
2181 return true;
2182 });
2183 return res;
2184}
2185
2186inline DomItem DomItem::subListItem(const List &list) const
2187{
2188 return DomItem(m_top, m_owner, m_ownerPath, list);
2189}
2190
2191inline DomItem DomItem::subMapItem(const Map &map) const
2192{
2193 return DomItem(m_top, m_owner, m_ownerPath, map);
2194}
2195
2196// TODO
2197// refactor this workaround. ExternalOWningItem is not recognized as an owning type
2198// in ownerAs.
2199std::shared_ptr<ExternalOwningItem> getFileItemOwner(const DomItem &fileItem);
2200
2201} // end namespace Dom
2202} // end namespace QQmlJS
2203
2204QT_END_NAMESPACE
2205#endif // QMLDOMITEM_H
std::pair< AST::Node *, CommentAnchor > CommentKey
void setSemanticScope(const QQmlJSScope::ConstPtr &scope)
QQmlJSScope::ConstPtr m_semanticScope
void updatePathFromOwner(const Path &newPath)
QQmlJSScope::ConstPtr semanticScope() const
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
Path addAnnotation(const Path &selfPathFromOwner, const QmlObject &annotation, QmlObject **aPtr=nullptr)
BindingValue(const QList< QmlObject > &l)
void updatePathFromOwner(const Path &newPath)
BindingValue(const std::shared_ptr< ScriptExpression > &o)
BindingValue(const BindingValue &o)
DomItem value(const DomItem &binding) const
BindingValue & operator=(const BindingValue &o)
std::shared_ptr< ScriptExpression > scriptExpression
BindingValue(const QmlObject &o)
void setValue(std::unique_ptr< BindingValue > &&value)
BindingType bindingType() const
std::shared_ptr< ScriptExpression > scriptExpressionValue() const
RegionComments & comments()
Binding & operator=(const Binding &)
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const
void setBindingIdentifiers(const ScriptElementVariant &bindingIdentifiers)
Path addAnnotation(const Path &selfPathFromOwner, const QmlObject &a, QmlObject **aPtr=nullptr)
QList< QmlObject > annotations() const
void updatePathFromOwner(const Path &newPath)
static QString preCodeForName(QStringView n)
QmlObject const * objectValue() const
DomItem valueItem(const DomItem &self) const
QList< QmlObject > * arrayValue()
Binding(const Binding &o)
QList< QmlObject > const * arrayValue() const
static QString postCodeForName(QStringView)
void setAnnotations(const QList< QmlObject > &annotations)
Binding & operator=(Binding &&)=default
void writeOut(const DomItem &self, OutWriter &lw) const
Binding(const QString &m_name, const QString &scriptCode, BindingType bindingType=BindingType::Normal)
const RegionComments & comments() const
Binding(const QString &m_name, std::unique_ptr< BindingValue > &&value, BindingType bindingType=BindingType::Normal)
void writeOutValue(const DomItem &self, OutWriter &lw) const
Binding(const QString &m_name=QString())
static constexpr DomType kindValue
Binding(const QString &m_name, const QmlObject &value, BindingType bindingType=BindingType::Normal)
Binding(Binding &&o)=default
std::shared_ptr< ScriptExpression > scriptExpressionValue()
ScriptElementVariant bindingIdentifiers() const
BindingValueKind valueKind() const
Binding(const QString &m_name, const std::shared_ptr< ScriptExpression > &value, BindingType bindingType=BindingType::Normal)
const RegionComments & comments() const
CommentableDomElement & operator=(const CommentableDomElement &o)=default
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
CommentableDomElement(const CommentableDomElement &o)
CommentableDomElement(const Path &pathFromOwner=Path())
void setIsSingleton(bool isSingleton)
void updatePathFromOwner(const Path &newPath) override
Component(const Path &pathFromOwner=Path())
void setIsComposite(bool isComposite)
Component & operator=(const Component &)=default
void setIsCreatable(bool isCreatable)
void setObjects(const QList< QmlObject > &objects)
const QMultiMap< QString, EnumDecl > & enumerations() const &
Component(const Component &o)=default
Path addObject(const QmlObject &object, QmlObject **oPtr=nullptr)
void setName(const QString &name)
Path attachedTypePath(const DomItem &) const
void setEnumerations(const QMultiMap< QString, EnumDecl > &enumerations)
DomItem field(const DomItem &self, QStringView name) const override
Path addEnumeration(const EnumDecl &enumeration, AddOption option=AddOption::Overwrite, EnumDecl **ePtr=nullptr)
void setAttachedTypeName(const QString &name)
bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override
QString attachedTypeName() const
Component(const QString &name)
void setAttachedTypePath(const Path &p)
const QList< QmlObject > & objects() const &
DomKind domKind() const override
ConstantData(const Path &pathFromOwner, const QCborValue &value, Options options=Options::MapIsMap)
QCborValue value() const override
quintptr id() const override
static constexpr DomType kindValue
DomType kind() const override
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
ConstantData & operator*()
const ConstantData & operator*() const
const ConstantData * operator->() const
ConstantData * operator->()
QString typeName() const
virtual DomType kind() const =0
virtual DomKind domKind() const
virtual Path canonicalPath(const DomItem &self) const =0
virtual Path pathFromOwner() const =0
virtual QList< QString > fields(const DomItem &self) const
virtual bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const =0
virtual index_type indexes(const DomItem &self) const
const DomBase * domBase() const
virtual DomItem containingObject(const DomItem &self) const
virtual void writeOut(const DomItem &self, OutWriter &lw) const
virtual QSet< QString > const keys(const DomItem &self) const
virtual DomItem field(const DomItem &self, QStringView name) const
virtual quintptr id() const
virtual QCborValue value() const
virtual QString canonicalFilePath(const DomItem &self) const
virtual ~DomBase()=default
virtual void dump(const DomItem &, const Sink &sink, int indent, FilterT filter) const
virtual DomItem key(const DomItem &self, const QString &name) const
virtual DomItem index(const DomItem &self, index_type index) const
DomElement & operator=(const DomElement &)=default
virtual void updatePathFromOwner(const Path &newPath)
Path canonicalPath(const DomItem &self) const override
Path pathFromOwner() const override
DomElement(const DomElement &o)=default
DomElement(const Path &pathFromOwner=Path())
DomItem containingObject(const DomItem &self) const override
A value type that references any element of the Dom.
DomItem bindings() const
DomItem top() const
DomItem goUp(int) const
QDateTime createdAt() const
T const * as() const
bool resolve(const Path &path, Visitor visitor, const ErrorHandler &errorHandler, ResolveOptions options=ResolveOption::None, const Path &fullPath=Path(), QList< Path > *visitedRefs=nullptr) const
std::shared_ptr< OwningItem > owningItemPtr() const
DomItem operator[](const QString &component) const
std::function< void(const Path &, const DomItem &, const DomItem &)> Callback
QString toString() 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.
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 methods() const
QString internalKindStr() const
DomItem scope(FilterUpOptions options=FilterUpOptions::ReturnOuter) const
DomItem enumerations() const
DomItem subOwnerItem(const PathEls::PathComponent &c, Owner o) 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 child(index_type i) const
DomItem key(QStringView name) const
std::shared_ptr< T > ownerAs() 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
DomItem refreshed() const
bool iterateErrors(function_ref< bool(const DomItem &, const ErrorMessage &)> visitor, bool iterate, Path inPath=Path()) const
DomItem pragmas() const
DomItem proceedToScope(const ErrorHandler &h=nullptr, QList< Path > *visitedRefs=nullptr) const
Dereference DomItems pointing to other DomItems.
QList< DomItem > values() const
DomItem universe() const
bool iterateDirectSubpaths(DirectVisitor v) const
DomItem container() const
void clearErrors(const ErrorGroups &groups=ErrorGroups({}), bool iterate=true) const
quintptr id() const
QList< QString > fields() const
bool writeOut(const QString &path, const LineWriterOptions &opt=LineWriterOptions(), FileWriter *fw=nullptr, WriteOutChecks extraChecks=WriteOutCheck::Default) const
DomItem globalScope() const
static DomItem fromCode(const QString &code, DomType fileType=DomType::QmlFile)
Creates a new document with the given code.
QString idStr() 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
DomItem copy(const T &base) 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
QCborValue value() const
index_type size() 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
bool invokeVisitorOnField(DirectVisitor visitor, QStringView f, T &obj) 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 invokeVisitorOnValue(DirectVisitor visitor, const PathEls::PathComponent &c, const T &value, ConstantData::Options options=ConstantData::Options::MapIsMap) const
bool writeOutForFile(OutWriter &ow, WriteOutChecks extraChecks) const
bool commitToBase(const std::shared_ptr< DomEnvironment > &validPtr=nullptr) const
DomItem ids() const
DomItem copy(const Owner &owner, const Path &ownerPath) const
bool visitSubSymbolsNamed(const QString &name, function_ref< bool(const DomItem &)> visitor) const
DomItem wrap(const PathEls::PathComponent &c, const T &obj) 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
index_type length() const
DomItem operator[](QStringView component) const
DomItem rootQmlObject(GoTo option=GoTo::Strict) const
DomItem subValueItem(const PathEls::PathComponent &c, const T &value, ConstantData::Options options=ConstantData::Options::MapIsMap) const
bool invokeVisitorOnLazyField(DirectVisitor visitor, QStringView f, F valueF, ConstantData::Options options=ConstantData::Options::MapIsMap) const
DomItem directParent() const
DomItem annotations() 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
DomKind domKind() const
bool isContainer() const
DomItem index(index_type) const
DomItem subReferencesItem(const PathEls::PathComponent &c, const QList< Path > &paths) const
DomItem subMapItem(const Map &map) const
bool invokeVisitorOnReference(DirectVisitor visitor, QStringView f, const Path &referencedObject) const
bool visitLocalSymbolsNamed(const QString &name, function_ref< bool(const DomItem &)> visitor) const
bool isExternalItem() const
DomItem subReferenceItem(const PathEls::PathComponent &c, const Path &referencedObject) const
void dumpPtr(const Sink &sink) const
auto visitEl(F f) const
InternalKind internalKind() const
DomItem path(const QString &p, const ErrorHandler &h=&defaultErrorHandler) 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
static DomItem empty
DomItem subDataItem(const PathEls::PathComponent &c, const T &value, ConstantData::Options options=ConstantData::Options::MapIsMap) 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 subScriptElementWrapperItem(const ScriptElementVariant &obj) const
DomItem path(QStringView p, const ErrorHandler &h=&defaultErrorHandler) const
DomItem copy(const Owner &owner, const Path &ownerPath, const T &base) const
DomItem key(const QString &name) const
PropertyInfo propertyInfoWithName(const QString &name) const
QSet< QString > keys() const
QString name() const
DomItem children() const
DomItem field(QStringView name) const
DomItem propertyDefs() const
bool invokeVisitorOnReferences(DirectVisitor visitor, QStringView f, const QList< Path > &paths) const
DomItem goToFile(const QString &filePath) const
QDateTime lastDataUpdateAt() const
DomItem(const std::shared_ptr< DomUniverse > &)
static ErrorGroup domErrorGroup
DomItem propertyInfos() const
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
static constexpr DomType kindValue
Path pathFromOwner() const override
Path canonicalPath(const DomItem &self) const override
const Empty & operator*() const
const Empty * operator->() const
DomType kind() const override
DomItem containingObject(const DomItem &self) const override
quintptr id() const override
const QList< QmlObject > & annotations() const &
const QList< EnumItem > & values() const &
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override
void setAlias(const QString &aliasName)
void setAnnotations(const QList< QmlObject > &annotations)
EnumDecl(const QString &name=QString(), const QList< EnumItem > &values=QList< EnumItem >(), const Path &pathFromOwner=Path())
void writeOut(const DomItem &self, OutWriter &lw) const override
void updatePathFromOwner(const Path &newP) override
void setName(const QString &name)
Path addAnnotation(const QmlObject &child, QmlObject **cPtr=nullptr)
Path addValue(const EnumItem &value)
static constexpr DomType kindValue
void setValues(const QList< EnumItem > &values)
DomType kind() const override
EnumItem(const QString &name=QString(), int value=0, ValueKind valueKind=ValueKind::ImplicitValue)
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
const RegionComments & comments() const
RegionComments & comments()
void writeOut(const DomItem &self, OutWriter &lw) const
static constexpr DomType kindValue
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.
Represents an error message connected to the dom.
static Export fromString(const Path &source, QStringView exp, const Path &typePath, const ErrorHandler &h)
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
static FieldFilter noFilter()
Represents a Node of FileLocations tree.
QString logicalPath() const
QString canonicalPath() const
std::shared_ptr< DomEnvironment > environment() const
void setCanonicalPath(const QString &canonicalPath)
void setLogicalPath(const QString &logicalPath)
std::optional< InMemoryContents > content() const
static FileToLoad fromFileSystem(const std::weak_ptr< DomEnvironment > &environment, const QString &canonicalPath)
static FileToLoad fromMemory(const std::weak_ptr< DomEnvironment > &environment, const QString &path, const QString &data)
FileToLoad(const std::weak_ptr< DomEnvironment > &environment, const QString &canonicalPath, const QString &logicalPath, const std::optional< InMemoryContents > &content)
GlobalComponent(const Path &pathFromOwner=Path())
DomType kind() const override
static constexpr DomType kindValue
Path addAnnotation(const Path &selfPathFromOwner, const QmlObject &ann, QmlObject **aPtr=nullptr)
RegionComments comments
std::shared_ptr< ScriptExpression > value
static constexpr DomType kindValue
Id(const QString &idName=QString(), const Path &referredObject=Path())
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const
void updatePathFromOwner(const Path &pathFromOwner)
QList< QmlObject > annotations
const QList< Path > & importSourcePaths() const &
const QMap< QString, ImportScope > & subImports() const &
QList< DomItem > importedItemsWithName(const DomItem &self, const QString &name) const
QList< Export > importedExportsWithName(const DomItem &self, const QString &name) const
QSet< QString > importedNames(const DomItem &self) const
void addImport(const QStringList &p, const Path &targetExports)
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
QList< Path > allSources(const DomItem &self) const
Import(const QmlUri &uri=QmlUri(), Version version=Version(), const QString &importId=QString())
Import baseImport() const
friend bool operator==(const Import &i1, const Import &i2)
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const
static QRegularExpression importRe()
void writeOut(const DomItem &self, OutWriter &ow) const
static Import fromFileString(const QString &importStr, const QString &importId=QString(), const ErrorHandler &handler=nullptr)
friend bool operator!=(const Import &i1, const Import &i2)
static Import fromUriString(const QString &importStr, Version v=Version(), const QString &importId=QString(), const ErrorHandler &handler=nullptr)
JsResource(const Path &pathFromOwner=Path())
DomType kind() const override
bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override
static constexpr DomType kindValue
quintptr id() const override
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor v) const override
void writeOut(const DomItem &self, OutWriter &ow, bool compact) const
static constexpr DomType kindValue
index_type indexes(const DomItem &) const override
virtual void copyTo(ListPBase *) const
virtual void moveTo(ListPBase *) const
void writeOut(const DomItem &self, OutWriter &ow) const override
DomType kind() const override
QList< const void * > m_pList
ListPBase(const Path &pathFromOwner, const QList< const void * > &pList, const QString &elType)
void moveTo(ListPBase *t) const override
ListPT(const Path &pathFromOwner, const QList< T * > &pList, const QString &elType=QString(), ListOptions options=ListOptions::Normal)
DomItem index(const DomItem &self, index_type index) const override
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor v) const override
void copyTo(ListPBase *t) const override
static constexpr DomType kindValue
static constexpr DomType kindValue
ListPBase & operator*()
ListPBase * operator->()
const ListPBase * operator->() const
ListP(const Path &pathFromOwner, const QList< T * > &pList, const QString &elType=QString(), ListOptions options=ListOptions::Normal)
const ListPBase & operator*() 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)
DomType kind() const override
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
const List & operator*() const
static List fromQList(const Path &pathFromOwner, const QList< T > &list, const std::function< DomItem(const DomItem &, const PathEls::PathComponent &, const T &)> &elWrapper, ListOptions options=ListOptions::Normal)
static List fromQListRef(const Path &pathFromOwner, const QList< T > &list, const std::function< DomItem(const DomItem &, const PathEls::PathComponent &, const T &)> &elWrapper, ListOptions options=ListOptions::Normal)
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
void writeOut(const DomItem &self, OutWriter &ow) const override
quintptr id() const override
static constexpr DomType kindValue
const List * operator->() const
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
static Map fromMultiMapRef(const Path &pathFromOwner, const QMultiMap< QString, T > &mmap)
const Map * operator->() const
static Map fromFileRegionMap(const Path &pathFromOwner, const QMap< FileLocationRegion, T > &map)
Map(const Path &pathFromOwner, const LookupFunction &lookup, const Keys &keys, const QString &targetType)
const Map & operator*() const
static Map fromMapRef(const Path &pathFromOwner, const QMap< QString, T > &mmap, const std::function< DomItem(const DomItem &, const PathEls::PathComponent &, const T &)> &elWrapper)
static Map fromMultiMap(const Path &pathFromOwner, const QMultiMap< QString, T > &mmap)
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
static constexpr DomType kindValue
DomType kind() const override
std::shared_ptr< ScriptExpression > body
Path typePath(const DomItem &) const
QList< MethodParameter > parameters
std::shared_ptr< ScriptExpression > returnType
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
void writeOut(const DomItem &self, OutWriter &ow) const
void writePre(const DomItem &self, OutWriter &ow) const
QString signature(const DomItem &self) const
std::shared_ptr< ScriptExpression > defaultValue
void writeOut(const DomItem &self, OutWriter &ow) const
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
void writeOutSignal(const DomItem &self, OutWriter &ow) const
TypeAnnotationStyle typeAnnotationStyle
static constexpr DomType kindValue
std::shared_ptr< ScriptExpression > value
QMap< QString, QMap< QString, MockObject > > subMaps
friend bool operator==(const ModuleAutoExport &i1, const ModuleAutoExport &i2)
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
friend bool operator!=(const ModuleAutoExport &i1, const ModuleAutoExport &i2)
static constexpr DomType kindValue
std::shared_ptr< T > ownerAs() const
MutableDomItem addChild(QmlObject child)
friend bool operator==(const MutableDomItem &o1, const MutableDomItem &o2)
MutableDomItem addPropertyDef(const PropertyDefinition &propertyDef, AddOption option=AddOption::Overwrite)
bool commitToBase(const std::shared_ptr< DomEnvironment > &validEnvPtr=nullptr)
QString canonicalFilePath() const
MutableDomItem fileObject(GoTo option=GoTo::Strict)
MutableDomItem operator[](const char16_t *component)
FileWriter::Status dump(const QString &path, function_ref< bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter=noFilter, int indent=0, FileWriter *fw=nullptr)
MutableDomItem key(QStringView name)
MutableDomItem operator[](const QString &component)
MutableDomItem addMethod(const MethodInfo &functionDef, AddOption option=AddOption::Overwrite)
MutableDomItem field(QStringView name)
void dump(const Sink &s, int indent=0, function_ref< bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter=noFilter)
void writeOut(OutWriter &lw)
MutableDomItem(const DomItem &owner, const Path &pathFromOwner)
MutableDomItem containingObject()
void addError(ErrorMessage &&msg)
MutableDomItem path(const QString &p)
std::shared_ptr< DomTop > topPtr()
MutableDomItem key(const QString &name)
QSet< QString > const keys()
MutableDomItem qmlObject(GoTo option=GoTo::Strict, FilterUpOptions fOptions=FilterUpOptions::ReturnOuter)
QList< QString > const fields()
MutableDomItem component(GoTo option=GoTo::Strict)
MutableDomItem path(const Path &p)
MutableDomItem makeCopy(CopyOption option=CopyOption::EnvConnected)
MutableDomItem operator[](const Path &path)
MutableDomItem index(index_type i)
MutableDomItem child(index_type i)
MutableDomItem(const DomItem &item)
std::shared_ptr< OwningItem > owningItemPtr()
bool writeOut(const QString &path, const LineWriterOptions &opt=LineWriterOptions(), FileWriter *fw=nullptr)
friend bool operator!=(const MutableDomItem &o1, const MutableDomItem &o2)
MutableDomItem rootQmlObject(GoTo option=GoTo::Strict)
DomItem::CopyOption CopyOption
MutableDomItem operator[](QStringView component)
MutableDomItem path(QStringView 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
QBasicMutex * mutex() const
DomItem containingObject(const DomItem &self) const override
virtual std::shared_ptr< OwningItem > doCopy(const DomItem &self) const =0
std::shared_ptr< OwningItem > makeCopy(const DomItem &self) const
Path pathFromOwner() const override final
OwningItem(const OwningItem &&)=delete
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)
QDateTime frozenAt() const
void addErrorLocal(ErrorMessage &&msg)
virtual QDateTime lastDataUpdateAt() const
void clearErrors(const ErrorGroups &groups=ErrorGroups({}))
Path canonicalPath(const DomItem &self) const override=0
QMultiMap< Path, ErrorMessage > localErrors() const
OwningItem & operator=(const OwningItem &&)=delete
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)
Source split() const
Splits the path at the last field, root or current Component.
PathEls::Kind Kind
static Path fromRoot(PathRoot r)
Path withComponent(const PathEls::PathComponent &c)
Path operator[](int i) const
Path mid(int offset, int length) const
Path last() const
Kind headKind() const
static Path fromCurrent(PathCurrent c)
Pragma(const QString &pragmaName=QString(), const QStringList &pragmaValues={})
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
void writeOut(const DomItem &self, OutWriter &ow) const
static constexpr DomType kindValue
static constexpr DomType kindValue
ScriptElementVariant m_nameIdentifiers
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
void writeOut(const DomItem &self, OutWriter &lw) const
ScriptElementVariant nameIdentifiers() const
void setNameIdentifiers(const ScriptElementVariant &name)
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
static constexpr DomType kindValue
QQmlDomAstCreatorBase(const MutableDomItem &qmlFile)
void endVisit(AST::UiProgram *) override
void throwRecursionDepthError() override
void endVisitHelper(AST::PatternElement *pe, const std::shared_ptr< ScriptElements::GenericScriptElement > &element)
void loadAnnotations(AST::UiObjectMember *el)
bool visit(AST::UiProgram *program) override
void enableLoadFileLazily(bool enable=true)
void enableScriptExpressions(bool enable=true)
virtual QQmlJSASTClassListToVisit void throwRecursionDepthError() override
QQmlDomAstCreatorWithQQmlJSScope(MutableDomItem &qmlFile, QQmlJSLogger *logger, QQmlJSImporter *importer)
QQmlJSScope::ConstPtr semanticScope() const
void setIds(const QMultiMap< QString, Id > &ids)
void setNextComponentPath(const Path &p)
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
QList< DomItem > subComponents(const DomItem &self) const
const QMultiMap< QString, Id > & ids() const &
void updatePathFromOwner(const Path &newPath) override
void setNameIdentifiers(const ScriptElementVariant &name)
static constexpr DomType kindValue
void writeOut(const DomItem &self, OutWriter &) const override
void setSemanticScope(const QQmlJSScope::ConstPtr &scope)
QmlComponent(const QString &name=QString())
QList< QString > subComponentsNames(const DomItem &self) const
Path addId(const Id &id, AddOption option=AddOption::Overwrite, Id **idPtr=nullptr)
ScriptElementVariant nameIdentifiers() const
DomType kind() const override
QList< QString > fields(const DomItem &) const override
void setNameIdentifiers(const ScriptElementVariant &name)
Path addChild(const QmlObject &child, QmlObject **cPtr=nullptr)
MutableDomItem addBinding(MutableDomItem &self, const Binding &binding, AddOption option)
void setMethods(const QMultiMap< QString, MethodInfo > &functionDefs)
void writeOutSortedEnumerations(const QList< DomItem > &descs, OutWriter &ow) const
void writeOut(const DomItem &self, OutWriter &ow, const QString &onTarget) const
ScriptElementVariant nameIdentifiers() const
void setName(const QString &name)
QList< std::pair< SourceLocation, DomItem > > orderOfAttributes(const DomItem &self, const DomItem &component) const
bool iterateSubOwners(const DomItem &self, function_ref< bool(const DomItem &owner)> visitor) const
MutableDomItem addChild(MutableDomItem &self, const QmlObject &child)
void setAnnotations(const QList< QmlObject > &annotations)
const QMultiMap< QString, Binding > & bindings() const &
DomType kind() const override
void setNextScopePath(const Path &nextScopePath)
void updatePathFromOwner(const Path &newPath) override
void setChildren(const QList< QmlObject > &children)
Path addBinding(const Binding &binding, AddOption option, Binding **bPtr=nullptr)
Path addAnnotation(const QmlObject &annotation, QmlObject **aPtr=nullptr)
LocallyResolvedAlias resolveAlias(const DomItem &self, std::shared_ptr< ScriptExpression > accessSequence) const
void writeOutId(const DomItem &self, OutWriter &ow) const
QList< QmlObject > children() const
LocallyResolvedAlias resolveAlias(const DomItem &self, const QStringList &accessSequence) const
const QList< Path > & prototypePaths() const &
void writeOutSortedPropertyDefinition(const DomItem &self, OutWriter &ow, QSet< QString > &mergedDefBinding, const QStringList &keys) const
Path addPropertyDef(const PropertyDefinition &propertyDef, AddOption option, PropertyDefinition **pDef=nullptr)
void writeOutSortedAttributes(const DomItem &self, OutWriter &ow, const DomItem &component, const Attributes &attribs) const
const QMultiMap< QString, MethodInfo > & methods() const &
MutableDomItem addPropertyDef(MutableDomItem &self, const PropertyDefinition &propertyDef, AddOption option)
DomItem field(const DomItem &self, QStringView name) const override
void setBindings(const QMultiMap< QString, Binding > &bindings)
QString localDefaultPropertyName() const
QString defaultPropertyName(const DomItem &self) const
void setPropertyDefs(const QMultiMap< QString, PropertyDefinition > &propertyDefs)
QmlObject(const Path &pathFromOwner=Path())
void writeOutAttributes(OutWriter &ow, const Attributes &attribs, const QString &code) const
MutableDomItem addMethod(MutableDomItem &self, const MethodInfo &functionDef, AddOption option)
void setIdStr(const QString &id)
QQmlJSScope::ConstPtr semanticScope() const
const QMultiMap< QString, PropertyDefinition > & propertyDefs() const &
void writeOut(const DomItem &self, OutWriter &lw) const override
Path addPrototypePath(const Path &prototypePath)
void setSemanticScope(const QQmlJSScope::ConstPtr &scope)
void setDefaultPropertyName(const QString &name)
void setPrototypePaths(const QList< Path > &prototypePaths)
QList< QmlObject > annotations() const
QList< QString > fields() const
QList< std::pair< SourceLocation, DomItem > > Attributes
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
Path addMethod(const MethodInfo &functionDef, AddOption option, MethodInfo **mPtr=nullptr)
bool iterateBaseDirectSubpaths(const DomItem &self, DirectVisitor) const
static QmlUri fromString(const QString &importStr)
QString absoluteLocalPath(const QString &basePath=QString()) const
QString directoryString() const
static QmlUri fromUriString(const QString &importStr)
QString localPath() const
QString moduleUri() const
friend bool operator==(const QmlUri &i1, const QmlUri &i2)
static QmlUri fromDirectoryString(const QString &importStr)
friend bool operator!=(const QmlUri &i1, const QmlUri &i2)
void setInterfaceNames(const QStringList &interfaces)
void setMetaRevisions(const QList< int > &metaRevisions)
QQmlJSScope::AccessSemantics accessSemantics() const
void setFileName(const QString &fileName)
static constexpr DomType kindValue
QQmlJSScope::ConstPtr semanticScope() const
void setAccessSemantics(QQmlJSScope::AccessSemantics v)
void setSemanticScope(const QQmlJSScope::ConstPtr &scope)
bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override
void setExtensionTypeName(const QString &name)
void setElementTypeName(const QString &name)
const QList< int > & metaRevisions() const &
const QList< Export > & exports() const &
void setExports(const QList< Export > &exports)
void addExport(const Export &exportedEntry)
const QStringList & interfaceNames() const &
QmltypesComponent(const Path &pathFromOwner=Path())
DomType kind() const override
QList< QString > fields(const DomItem &self) const override
quintptr id() const override
static constexpr DomType kindValue
const Reference & operator*() const
DomItem index(const DomItem &, index_type) const override
DomItem field(const DomItem &self, QStringView name) const override
DomItem get(const DomItem &self, const ErrorHandler &h=nullptr, QList< Path > *visitedRefs=nullptr) const
QList< DomItem > getAll(const DomItem &self, const ErrorHandler &h=nullptr, QList< Path > *visitedRefs=nullptr) const
index_type indexes(const DomItem &) const override
DomType kind() const override
QSet< QString > const keys(const DomItem &) const override
const Reference * operator->() 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
Keeps the comments associated with a DomItem.
const DomBase & operator*() const
const DomBase * operator->() const
static constexpr DomType kindValue
ScriptElementVariant element() const
ScriptElementDomWrapper(const ScriptElementVariant &element)
Use this to contain any script element.
void visitConst(F &&visitor) const
std::optional< ScriptElementT > data()
ScriptElement::PointerType< ScriptElement > base() const
Returns a pointer to the virtual base for virtual method calls.
static ScriptElementVariant fromElement(const T &element)
void setData(const ScriptElementT &data)
void replaceKindForGenericChildren(DomType oldType, DomType newType)
QStringView loc2Str(const SourceLocation &) const
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override
DomType kind() const override
std::shared_ptr< AstComments > astComments() const
std::shared_ptr< QQmlJS::Engine > engine() const
ScriptExpression(const QString &code, ExpressionType expressionType)
static constexpr DomType kindValue
SourceLocation locationToLocal(const SourceLocation &x) const
std::shared_ptr< ScriptExpression > makeCopy(const DomItem &self) const
ScriptExpression(const ScriptExpression &e)
ExpressionType expressionType() const
void writeOut(const DomItem &self, OutWriter &lw) const override
SourceLocation globalLocation(const DomItem &self) const
ScriptExpression(QStringView code, const std::shared_ptr< QQmlJS::Engine > &engine, AST::Node *ast, const std::shared_ptr< AstComments > &comments, ExpressionType expressionType, const SourceLocation &localOffset=SourceLocation())
void setScriptElement(const ScriptElementVariant &p)
std::shared_ptr< OwningItem > doCopy(const DomItem &) const override
ScriptElementVariant scriptElement()
void astDumper(const Sink &s, AstDumperOptions options) const
SourceLocation localOffset() const
Path canonicalPath(const DomItem &self) const override
static constexpr DomType kindValue
bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override
SimpleObjectWrapBase(const Path &pathFromOwner, const QVariant &value, quintptr idValue, DomType kind=kindValue, SimpleWrapOptions options=SimpleWrapOption::None)
virtual void moveTo(SimpleObjectWrapBase *) const
DomKind domKind() const final override
virtual void copyTo(SimpleObjectWrapBase *) const
DomType kind() const final override
quintptr id() const final override
SimpleObjectWrapT(const Path &pathFromOwner, const QVariant &v, quintptr idValue, SimpleWrapOptions o)
void moveTo(SimpleObjectWrapBase *target) const override
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override
static constexpr DomType kindValue
void writeOut(const DomItem &self, OutWriter &lw) const override
void copyTo(SimpleObjectWrapBase *target) const override
const SimpleObjectWrapBase & operator*() const
SimpleObjectWrapBase & operator*()
static SimpleObjectWrap fromObjectRef(const Path &pathFromOwner, T &value)
const SimpleObjectWrapBase * operator->() const
static constexpr DomType kindValue
SimpleObjectWrapBase * operator->()
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const
QString majorString() const
static constexpr DomType kindValue
Version(qint32 majorVersion=Undefined, qint32 minorVersion=Undefined)
QString minorString() const
int compare(Version o) const
static Version fromString(QStringView v)
QString stringValue() const
static constexpr qint32 Undefined
static constexpr qint32 Latest
QString majorSymbolicString() const
Provides entities to maintain mappings between elements and their location in a file.
void addRegion(const Tree &fLoc, FileLocationRegion region, SourceLocation loc)
Tree ensure(const Tree &base, const Path &basePath)
Path lookupTypePath(const QString &name)
Path loadInfoPath(const Path &el)
Path moduleScopePath(const QString &uri, const ErrorHandler &errorHandler=nullptr)
Path qmltypesFilePath(const QString &path)
Path jsFilePath(const QString &path)
Path lookupCppTypePath(const QString &name)
Path qmlFileInfoPath(const QString &canonicalFilePath)
Path moduleIndexPath(const QString &uri, int majorVersion, const ErrorHandler &errorHandler=nullptr)
Path qmlFilePath(const QString &canonicalFilePath)
Path globalScopePath(const QString &name)
Path moduleScopePath(const QString &uri, const QString &version, const ErrorHandler &errorHandler=nullptr)
Path lookupSymbolPath(const QString &name)
Path jsFileInfoPath(const QString &path)
Path lookupPropertyPath(const QString &name)
Path moduleScopePath(const QString &uri, Version version, const ErrorHandler &errorHandler=nullptr)
Path qmlDirPath(const QString &path)
Path qmlDirectoryPath(const QString &path)
Path qmldirFilePath(const QString &path)
Path qmlDirectoryInfoPath(const QString &path)
Path qmltypesFileInfoPath(const QString &path)
Path qmldirFileInfoPath(const QString &path)
Path qmlDirInfoPath(const QString &path)
Path qmlFileObjectPath(const QString &canonicalFilePath)
Path globalScopeInfoPath(const QString &name)
bool operator>(Version v1, Version v2)
QMLDOM_EXPORT bool domTypeIsContainer(DomType k)
bool operator==(Version v1, Version v2)
constexpr bool domTypeIsOwningItem(DomType)
Path appendUpdatableElementInQList(const Path &listPathFromOwner, QList< T > &list, const T &value, T **vPtr=nullptr)
constexpr bool domTypeIsValueWrap(DomType k)
Path insertUpdatableElementInMultiMap(const Path &mapPathFromOwner, QMultiMap< K, T > &mmap, K key, const T &value, AddOption option=AddOption::KeepExisting, T **valuePtr=nullptr)
bool noFilter(const DomItem &, const PathEls::PathComponent &, const DomItem &)
QMLDOM_EXPORT QMap< DomKind, QString > domKindToStringMap()
QMLDOM_EXPORT QDebug operator<<(QDebug debug, const DomItem &c)
std::shared_ptr< ExternalOwningItem > getFileItemOwner(const DomItem &fileItem)
DomKind kind2domKind(DomType k)
static DomItem keyMultiMapHelper(const DomItem &self, const QString &key, const QMultiMap< QString, T > &mmap)
bool operator!=(const DomItem &o1, const DomItem &o2)
QMLDOM_EXPORT bool domTypeIsExternalItem(DomType k)
constexpr bool domTypeIsUnattachedOwningItem(DomType)
QMLDOM_EXPORT QMap< DomType, QString > domTypeToStringMap()
QMLDOM_EXPORT bool domTypeIsScope(DomType k)
QMLDOM_EXPORT QDebug operator<<(QDebug debug, const MutableDomItem &c)
std::disjunction< std::is_same< U, V >... > IsInList
QMLDOM_EXPORT QString domTypeToString(DomType k)
auto writeOutWrap(const T &, const DomItem &, OutWriter &, rank< 0 >) -> void
constexpr bool domTypeIsScriptElement(DomType)
QMLDOM_EXPORT QString domKindToString(DomKind k)
constexpr bool domTypeIsDomElement(DomType)
void updatePathFromOwnerQList(QList< T > &list, const Path &newPath)
constexpr bool domTypeCanBeInline(DomType k)
bool operator<(Version v1, Version v2)
bool operator<=(Version v1, Version v2)
auto writeOutWrap(const T &t, const DomItem &self, OutWriter &lw) -> void
auto writeOutWrap(const T &t, const DomItem &self, OutWriter &lw, rank< 1 >) -> decltype(t.writeOut(self, lw))
bool operator!=(Version v1, Version v2)
bool operator>=(Version v1, Version v2)
std::variant< std::monostate, std::shared_ptr< ModuleIndex >, std::shared_ptr< MockOwner >, std::shared_ptr< ExternalItemInfoBase >, std::shared_ptr< ExternalItemPairBase >, std::shared_ptr< QmlDirectory >, std::shared_ptr< QmldirFile >, std::shared_ptr< JsFile >, std::shared_ptr< QmlFile >, std::shared_ptr< QmltypesFile >, std::shared_ptr< GlobalScope >, std::shared_ptr< ScriptExpression >, std::shared_ptr< AstComments >, std::shared_ptr< LoadInfo >, std::shared_ptr< FileLocations::Node >, std::shared_ptr< DomEnvironment >, std::shared_ptr< DomUniverse > > OwnerT
bool visitWithCustomListIteration(T *t, AST::Visitor *visitor)
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).
std::variant< ConstantData, Empty, List, ListP, Map, Reference, ScriptElementDomWrapper, SimpleObjectWrap, const AstComments *, const FileLocations::Node *, const DomEnvironment *, const DomUniverse *, const EnumDecl *, const ExternalItemInfoBase *, const ExternalItemPairBase *, const GlobalComponent *, const GlobalScope *, const JsFile *, const JsResource *, const LoadInfo *, const MockObject *, const MockOwner *, const ModuleIndex *, const ModuleScope *, const QmlComponent *, const QmlDirectory *, const QmlFile *, const QmlObject *, const QmldirFile *, const QmltypesComponent *, const QmltypesFile *, const ScriptExpression * > ElementT
void updatePathFromOwnerMultiMap(QMultiMap< K, T > &mmap, const Path &newPath)
constexpr bool domTypeIsObjWrap(DomType k)
bool emptyChildrenVisitor(Path, const DomItem &, bool)
static ErrorGroups importErrors
std::variant< std::monostate, std::shared_ptr< DomEnvironment >, std::shared_ptr< DomUniverse > > TopT
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
#define QMLDOM_EXPORT
#define Q_SCRIPTELEMENT_EXIT_IF(check)
#define Q_SCRIPTELEMENT_DISABLE()
#define NewErrorGroup(name)
QT_BEGIN_NAMESPACE QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY(writeOutLog, QMLDOM_EXPORT)
A common base class for all the script elements.
void setSemanticScope(const QQmlJSScope::ConstPtr &scope)
virtual void createFileLocations(const std::shared_ptr< FileLocations::Node > &fileLocationOfOwner)=0
std::shared_ptr< T > PointerType
QQmlJSScope::ConstPtr semanticScope()
SubclassStorage & operator=(const SubclassStorage &o)
SubclassStorage(const SubclassStorage &&o)
SubclassStorage(const SubclassStorage &o)