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 = 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, int nBackups = 2,
983 const LineWriterOptions &opt = LineWriterOptions(), 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 &)> filter = noFilter,
1047 int nBackups = 2, int indent = 0, FileWriter *fw = nullptr) const;
1048 QString toString() const;
1049
1050 // OwnigItem elements
1051 int derivedFrom() const;
1052 int revision() const;
1053 QDateTime createdAt() const;
1054 QDateTime frozenAt() const;
1056
1057 void addError(ErrorMessage &&msg) const;
1058 ErrorHandler errorHandler() const;
1059 void clearErrors(const ErrorGroups &groups = ErrorGroups({}), bool iterate = true) const;
1060 // return false if a quick exit was requested
1061 bool iterateErrors(
1062 function_ref<bool (const DomItem &, const ErrorMessage &)> visitor, bool iterate,
1063 Path inPath = Path()) const;
1064
1065 bool iterateSubOwners(function_ref<bool(const DomItem &owner)> visitor) const;
1066 bool iterateDirectSubpaths(DirectVisitor v) const;
1067
1068 template<typename T>
1069 DomItem subDataItem(const PathEls::PathComponent &c, const T &value,
1070 ConstantData::Options options = ConstantData::Options::MapIsMap) const;
1071 template<typename T>
1072 DomItem subValueItem(const PathEls::PathComponent &c, const T &value,
1073 ConstantData::Options options = ConstantData::Options::MapIsMap) const;
1074 template <typename T>
1075 bool invokeVisitorOnValue(DirectVisitor visitor, const PathEls::PathComponent &c, const T &value,
1076 ConstantData::Options options = ConstantData::Options::MapIsMap) const;
1077 template <typename F>
1078 bool invokeVisitorOnLazyField(DirectVisitor visitor, QStringView f, F valueF,
1079 ConstantData::Options options = ConstantData::Options::MapIsMap) const
1080 {
1081 PathEls::PathComponent c = PathEls::Field(f);
1082 auto lazyWrap = [this, &c, &valueF, options]() {
1083 return this->subValueItem<decltype(valueF())>(c, valueF(), options);
1084 };
1085 return visitor(c, lazyWrap);
1086 }
1087 DomItem subReferencesItem(const PathEls::PathComponent &c, const QList<Path> &paths) const;
1088 DomItem subReferenceItem(const PathEls::PathComponent &c, const Path &referencedObject) const;
1089 bool invokeVisitorOnReference(DirectVisitor visitor, QStringView f,
1090 const Path &referencedObject) const
1091 {
1092 PathEls::PathComponent c = PathEls::Field(f);
1093 return visitor(c, [c, this, referencedObject]() {
1094 return this->subReferenceItem(c, referencedObject);
1095 });
1096 }
1097 bool invokeVisitorOnReferences(DirectVisitor visitor, QStringView f,
1098 const QList<Path> &paths) const
1099 {
1100 PathEls::PathComponent c = PathEls::Field(f);
1101 return visitor(c, [c, this, paths]() { return this->subReferencesItem(c, paths); });
1102 }
1103 DomItem subListItem(const List &list) const;
1104 DomItem subMapItem(const Map &map) const;
1105
1107 {
1108 Q_ASSERT(obj);
1109 return DomItem(m_top, m_owner, m_ownerPath, ScriptElementDomWrapper(obj));
1110 }
1111
1112 template<typename Owner>
1113 DomItem subOwnerItem(const PathEls::PathComponent &c, Owner o) const
1114 {
1115 if constexpr (domTypeIsUnattachedOwningItem(Owner::element_type::kindValue))
1116 return DomItem(m_top, o, canonicalPath().withComponent(c), o.get());
1117 else
1118 return DomItem(m_top, o, Path(), o.get());
1119 }
1120 template <typename T>
1121 DomItem wrap(const PathEls::PathComponent &c, const T &obj) const;
1122 template <typename T>
1123 bool invokeVisitorOnField(DirectVisitor visitor, QStringView f, T &obj) const
1124 {
1125 PathEls::PathComponent c = PathEls::Field(f);
1126 auto lazyWrap = [this, &c, &obj]() { return this->wrap<T>(c, obj); };
1127 return visitor(c, lazyWrap);
1128 }
1129
1130 DomItem() = default;
1131 DomItem(const std::shared_ptr<DomEnvironment> &);
1132 DomItem(const std::shared_ptr<DomUniverse> &);
1133
1134 // TODO move to DomEnvironment?
1135 static DomItem fromCode(const QString &code, DomType fileType = DomType::QmlFile);
1136
1137 // --- start of potentially dangerous stuff, make private? ---
1138
1139 std::shared_ptr<DomTop> topPtr() const;
1140 std::shared_ptr<OwningItem> owningItemPtr() const;
1141
1142 // keep the DomItem around to ensure that it doesn't get deleted
1143 template<typename T, typename std::enable_if<std::is_base_of_v<DomBase, T>, bool>::type = true>
1144 T const *as() const
1145 {
1146 if (m_kind == T::kindValue) {
1147 if constexpr (domTypeIsObjWrap(T::kindValue) || domTypeIsValueWrap(T::kindValue))
1148 return std::get<SimpleObjectWrap>(m_element)->as<T>();
1149 else
1150 return static_cast<T const *>(base());
1151 }
1152 return nullptr;
1153 }
1154
1155 template<typename T, typename std::enable_if<!std::is_base_of_v<DomBase, T>, bool>::type = true>
1156 T const *as() const
1157 {
1158 if (m_kind == T::kindValue) {
1159 Q_ASSERT(domTypeIsObjWrap(m_kind) || domTypeIsValueWrap(m_kind));
1160 return std::get<SimpleObjectWrap>(m_element)->as<T>();
1161 }
1162 return nullptr;
1163 }
1164
1165 template<typename T>
1166 std::shared_ptr<T> ownerAs() const;
1167
1168 template<typename Owner, typename T>
1169 DomItem copy(const Owner &owner, const Path &ownerPath, const T &base) const
1170 {
1171 Q_ASSERT(!std::holds_alternative<std::monostate>(m_top));
1172 static_assert(IsInlineDom<std::decay_t<T>>::value, "Expected an inline item or pointer");
1173 return DomItem(m_top, owner, ownerPath, base);
1174 }
1175
1176 template<typename Owner>
1177 DomItem copy(const Owner &owner, const Path &ownerPath) const
1178 {
1179 Q_ASSERT(!std::holds_alternative<std::monostate>(m_top));
1180 return DomItem(m_top, owner, ownerPath, owner.get());
1181 }
1182
1183 template<typename T>
1184 DomItem copy(const T &base) const
1185 {
1186 Q_ASSERT(!std::holds_alternative<std::monostate>(m_top));
1187 using BaseT = std::decay_t<T>;
1188 static_assert(!std::is_same_v<BaseT, ElementT>,
1189 "variant not supported, pass in the stored types");
1190 static_assert(IsInlineDom<BaseT>::value || std::is_same_v<BaseT, std::monostate>,
1191 "expected either a pointer or an inline item");
1192
1193 if constexpr (IsSharedPointerToDomObject<BaseT>::value)
1194 return DomItem(m_top, base, Path(), base.get());
1195 else if constexpr (IsInlineDom<BaseT>::value)
1196 return DomItem(m_top, m_owner, m_ownerPath, base);
1197
1198 Q_UNREACHABLE_RETURN(DomItem(m_top, m_owner, m_ownerPath, nullptr));
1199 }
1200
1201private:
1202 enum class WriteOutCheckResult { Success, Failed };
1203 WriteOutCheckResult performWriteOutChecks(const DomItem &, OutWriter &, WriteOutChecks) const;
1204 const DomBase *base() const;
1205
1206 template<typename Env, typename Owner>
1207 DomItem(Env, Owner, Path, std::nullptr_t) : DomItem()
1208 {
1209 }
1210
1211 template<typename Env, typename Owner, typename T,
1212 typename = std::enable_if_t<IsInlineDom<std::decay_t<T>>::value>>
1213 DomItem(Env env, Owner owner, const Path &ownerPath, const T &el)
1214 : m_top(env), m_owner(owner), m_ownerPath(ownerPath), m_element(el)
1215 {
1216 using BaseT = std::decay_t<T>;
1217 if constexpr (std::is_pointer_v<BaseT>) {
1218 if (!el || el->kind() == DomType::Empty) { // avoid null ptr, and allow only a
1219 // single kind of Empty
1220 m_kind = DomType::Empty;
1221 m_top = std::monostate();
1222 m_owner = std::monostate();
1223 m_ownerPath = Path();
1224 m_element = Empty();
1225 } else {
1226 using DomT = std::remove_pointer_t<BaseT>;
1227 m_element = el;
1228 m_kind = DomT::kindValue;
1229 }
1230 } else {
1231 static_assert(!std::is_same_v<BaseT, ElementT>,
1232 "variant not supported, pass in the internal type");
1233 m_kind = el->kind();
1234 }
1235 }
1236 friend class DomBase;
1237 friend class DomElement;
1238 friend class Map;
1239 friend class List;
1240 friend class QmlObject;
1241 friend class DomUniverse;
1242 friend class DomEnvironment;
1244 friend class ConstantData;
1245 friend class MutableDomItem;
1246 friend class ScriptExpression;
1247 friend class AstComments;
1248 friend class FileLocations::Node;
1249 friend class TestDomItem;
1250 friend QMLDOM_EXPORT bool operator==(const DomItem &, const DomItem &);
1251 DomType m_kind = DomType::Empty;
1252 TopT m_top;
1253 OwnerT m_owner;
1254 Path m_ownerPath;
1255 ElementT m_element = Empty();
1256};
1257
1258QMLDOM_EXPORT bool operator==(const DomItem &o1, const DomItem &o2);
1259
1260inline bool operator!=(const DomItem &o1, const DomItem &o2)
1261{
1262 return !(o1 == o2);
1263}
1264
1265template<typename T>
1266static DomItem keyMultiMapHelper(const DomItem &self, const QString &key,
1267 const QMultiMap<QString, T> &mmap)
1268{
1269 auto it = mmap.find(key);
1270 auto end = mmap.cend();
1271 if (it == end)
1272 return DomItem();
1273 else {
1274 // special case single element (++it == end || it.key() != key)?
1275 QList<const T *> values;
1276 while (it != end && it.key() == key)
1277 values.append(&(*it++));
1278 ListP ll(self.pathFromOwner().withComponent(PathEls::Key(key)), values, QString(),
1280 return self.copy(ll);
1281 }
1282}
1283
1284template<typename T>
1285Map Map::fromMultiMapRef(const Path &pathFromOwner, const QMultiMap<QString, T> &mmap)
1286{
1287 return Map(
1288 pathFromOwner,
1289 [&mmap](const DomItem &self, const QString &key) {
1290 return keyMultiMapHelper(self, key, mmap);
1291 },
1292 [&mmap](const DomItem &) { return QSet<QString>(mmap.keyBegin(), mmap.keyEnd()); },
1293 QLatin1String(typeid(T).name()));
1294}
1295
1296template<typename T>
1297Map Map::fromMapRef(
1298 const Path &pathFromOwner, const QMap<QString, T> &map,
1299 const std::function<DomItem(const DomItem &, const PathEls::PathComponent &, const T &)> &elWrapper)
1300{
1301 return Map(
1302 pathFromOwner,
1303 [&map, elWrapper](const DomItem &self, const QString &key) {
1304 const auto it = map.constFind(key);
1305 if (it == map.constEnd())
1306 return DomItem();
1307 return elWrapper(self, PathEls::Key(key), it.value());
1308 },
1309 [&map](const DomItem &) { return QSet<QString>(map.keyBegin(), map.keyEnd()); },
1310 QLatin1String(typeid(T).name()));
1311}
1312
1313template<typename MapT>
1314QSet<QString> Map::fileRegionKeysFromMap(const MapT &map)
1315{
1316 QSet<QString> keys;
1317 std::transform(map.keyBegin(), map.keyEnd(), std::inserter(keys, keys.begin()), fileLocationRegionName);
1318 return keys;
1319}
1320
1321template<typename T>
1322Map Map::fromFileRegionMap(const Path &pathFromOwner, const QMap<FileLocationRegion, T> &map)
1323{
1324 auto result = Map(
1325 pathFromOwner,
1326 [&map](const DomItem &mapItem, const QString &key) -> DomItem {
1327 auto it = map.constFind(fileLocationRegionValue(key));
1328 if (it == map.constEnd())
1329 return {};
1330
1331 return mapItem.wrap(PathEls::Key(key), *it);
1332 },
1333 [&map](const DomItem &) { return fileRegionKeysFromMap(map); },
1334 QString::fromLatin1(typeid(T).name()));
1335 return result;
1336}
1337
1338template<typename T>
1339List List::fromQList(
1340 const Path &pathFromOwner, const QList<T> &list,
1341 const std::function<DomItem(const DomItem &, const PathEls::PathComponent &, const T &)> &elWrapper,
1342 ListOptions options)
1343{
1344 index_type len = list.size();
1345 if (options == ListOptions::Reverse) {
1346 return List(
1347 pathFromOwner,
1348 [list, elWrapper](const DomItem &self, index_type i) mutable {
1349 if (i < 0 || i >= list.size())
1350 return DomItem();
1351 return elWrapper(self, PathEls::Index(i), list[list.size() - i - 1]);
1352 },
1353 [len](const DomItem &) { return len; }, nullptr, QLatin1String(typeid(T).name()));
1354 } else {
1355 return List(
1356 pathFromOwner,
1357 [list, elWrapper](const DomItem &self, index_type i) mutable {
1358 if (i < 0 || i >= list.size())
1359 return DomItem();
1360 return elWrapper(self, PathEls::Index(i), list[i]);
1361 },
1362 [len](const DomItem &) { return len; }, nullptr, QLatin1String(typeid(T).name()));
1363 }
1364}
1365
1366template<typename T>
1367List List::fromQListRef(
1368 const Path &pathFromOwner, const QList<T> &list,
1369 const std::function<DomItem(const DomItem &, const PathEls::PathComponent &, const T &)> &elWrapper,
1370 ListOptions options)
1371{
1372 if (options == ListOptions::Reverse) {
1373 return List(
1374 pathFromOwner,
1375 [&list, elWrapper](const DomItem &self, index_type i) {
1376 if (i < 0 || i >= list.size())
1377 return DomItem();
1378 return elWrapper(self, PathEls::Index(i), list[list.size() - i - 1]);
1379 },
1380 [&list](const DomItem &) { return list.size(); }, nullptr,
1381 QLatin1String(typeid(T).name()));
1382 } else {
1383 return List(
1384 pathFromOwner,
1385 [&list, elWrapper](const DomItem &self, index_type i) {
1386 if (i < 0 || i >= list.size())
1387 return DomItem();
1388 return elWrapper(self, PathEls::Index(i), list[i]);
1389 },
1390 [&list](const DomItem &) { return list.size(); }, nullptr,
1391 QLatin1String(typeid(T).name()));
1392 }
1393}
1394
1396protected:
1397 virtual std::shared_ptr<OwningItem> doCopy(const DomItem &self) const = 0;
1398
1399public:
1400 OwningItem(const OwningItem &o);
1401 OwningItem(int derivedFrom=0);
1402 OwningItem(int derivedFrom, const QDateTime &lastDataUpdateAt);
1403 OwningItem(const OwningItem &&) = delete;
1404 OwningItem &operator=(const OwningItem &&) = delete;
1405 static int nextRevision();
1406
1407 Path canonicalPath(const DomItem &self) const override = 0;
1408
1409 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
1410 std::shared_ptr<OwningItem> makeCopy(const DomItem &self) const { return doCopy(self); }
1411 Path pathFromOwner() const override final { return Path(); }
1412 DomItem containingObject(const DomItem &self) const override;
1413 int derivedFrom() const;
1414 virtual int revision() const;
1415
1416 QDateTime createdAt() const;
1417 virtual QDateTime lastDataUpdateAt() const;
1418 virtual void refreshedDataAt(QDateTime tNew);
1419
1420 // explicit freeze handling needed?
1421 virtual bool frozen() const;
1422 virtual bool freeze();
1423 QDateTime frozenAt() const;
1424
1425 virtual void addError(const DomItem &self, ErrorMessage &&msg);
1426 void addErrorLocal(ErrorMessage &&msg);
1427 void clearErrors(const ErrorGroups &groups = ErrorGroups({}));
1428 // return false if a quick exit was requested
1429 bool iterateErrors(
1430 const DomItem &self,
1431 function_ref<bool(const DomItem &source, const ErrorMessage &msg)> visitor,
1432 const Path &inPath = Path());
1434 QMutexLocker l(mutex());
1435 return m_errors;
1436 }
1437
1438 virtual bool iterateSubOwners(const DomItem &self, function_ref<bool(const DomItem &owner)> visitor);
1439
1440 QBasicMutex *mutex() const { return &m_mutex; }
1441private:
1442 mutable QBasicMutex m_mutex;
1443 int m_derivedFrom;
1444 int m_revision;
1445 QDateTime m_createdAt;
1446 QDateTime m_lastDataUpdateAt;
1447 QDateTime m_frozenAt;
1448 QMultiMap<Path, ErrorMessage> m_errors;
1449 QMap<ErrorMessage, quint32> m_errorsCounts;
1450};
1451
1452template<typename T>
1453std::shared_ptr<T> DomItem::ownerAs() const
1454{
1455 if constexpr (domTypeIsOwningItem(T::kindValue)) {
1456 if (!std::holds_alternative<std::monostate>(m_owner)) {
1457 if constexpr (T::kindValue == DomType::FileLocationsNode) {
1458 if (std::holds_alternative<std::shared_ptr<FileLocations::Node>>(m_owner))
1459 return std::static_pointer_cast<T>(
1460 std::get<std::shared_ptr<FileLocations::Node>>(m_owner));
1461 } else if constexpr (T::kindValue == DomType::ExternalItemInfo) {
1462 if (std::holds_alternative<std::shared_ptr<ExternalItemInfoBase>>(m_owner))
1463 return std::static_pointer_cast<T>(
1464 std::get<std::shared_ptr<ExternalItemInfoBase>>(m_owner));
1465 } else if constexpr (T::kindValue == DomType::ExternalItemPair) {
1466 if (std::holds_alternative<std::shared_ptr<ExternalItemPairBase>>(m_owner))
1467 return std::static_pointer_cast<T>(
1468 std::get<std::shared_ptr<ExternalItemPairBase>>(m_owner));
1469 } else {
1470 if (std::holds_alternative<std::shared_ptr<T>>(m_owner)) {
1471 return std::get<std::shared_ptr<T>>(m_owner);
1472 }
1473 }
1474 }
1475 } else {
1476 Q_ASSERT_X(false, "DomItem::ownerAs", "unexpected non owning value in ownerAs");
1477 }
1478 return std::shared_ptr<T> {};
1479}
1480
1481template<int I>
1482struct rank : rank<I - 1>
1483{
1484 static_assert(I > 0, "");
1485};
1486template<>
1487struct rank<0>
1488{
1489};
1490
1491template<typename T>
1492auto writeOutWrap(const T &t, const DomItem &self, OutWriter &lw, rank<1>)
1493 -> decltype(t.writeOut(self, lw))
1494{
1495 t.writeOut(self, lw);
1496}
1497
1498template<typename T>
1499auto writeOutWrap(const T &, const DomItem &, OutWriter &, rank<0>) -> void
1500{
1501 qCWarning(writeOutLog) << "Ignoring writeout to wrapped object not supporting it ("
1502 << typeid(T).name();
1503}
1504template<typename T>
1505auto writeOutWrap(const T &t, const DomItem &self, OutWriter &lw) -> void
1506{
1507 writeOutWrap(t, self, lw, rank<1>());
1508}
1509
1510template<typename T>
1511void SimpleObjectWrapT<T>::writeOut(const DomItem &self, OutWriter &lw) const
1512{
1513 writeOutWrap<T>(*asT(), self, lw);
1514}
1515
1516QMLDOM_EXPORT QDebug operator<<(QDebug debug, const DomItem &c);
1517
1518// TODO QTBUG-121518 quite some methods are used only in the "examples"
1519// Even though MutableDomItem provides some API for modifying internal data,
1520// de-facto it's not very helpful / convinient / intuitive to use
1521// Moreover it just amplifies and repeats issues of DomItem interface,
1522// a.k.a. abuse or misuse of type erasure technique
1524public:
1526
1527 explicit operator bool() const
1528 {
1529 return bool(m_owner);
1530 } // this is weaker than item(), but normally correct
1532 QString internalKindStr() { return domTypeToString(internalKind()); }
1533 DomKind domKind() { return kind2domKind(internalKind()); }
1534
1535 Path canonicalPath() const { return m_owner.canonicalPath().withPath(m_pathFromOwner); }
1537 {
1538 if (m_pathFromOwner)
1539 return MutableDomItem(m_owner, m_pathFromOwner.split().pathToSource);
1540 else {
1541 DomItem cObj = m_owner.containingObject();
1543 }
1544 }
1545
1547 {
1548 if (m_pathFromOwner)
1549 return MutableDomItem(m_owner, m_pathFromOwner.dropTail());
1550 else {
1552 }
1553 }
1554
1557 {
1558 return MutableDomItem(item().qmlObject(option, fOptions));
1559 }
1561 {
1562 return MutableDomItem(item().fileObject(option));
1563 }
1565 {
1566 return MutableDomItem(item().rootQmlObject(option));
1567 }
1570
1572 {
1573 return MutableDomItem { item().component(option) };
1574 }
1575 MutableDomItem owner() { return MutableDomItem(m_owner); }
1579 Path pathFromOwner() { return m_pathFromOwner; }
1581 MutableDomItem operator[](QStringView component) { return MutableDomItem(item()[component]); }
1582 MutableDomItem operator[](const QString &component)
1583 {
1584 return MutableDomItem(item()[component]);
1585 }
1586 MutableDomItem operator[](const char16_t *component)
1587 {
1588 // to avoid clash with stupid builtin ptrdiff_t[MutableDomItem&], coming from C
1589 return MutableDomItem(item()[QStringView(component)]);
1590 }
1591 MutableDomItem operator[](index_type i) { return MutableDomItem(item().index(i)); }
1592
1594 MutableDomItem path(const QString &p) { return path(Path::fromString(p)); }
1595 MutableDomItem path(QStringView p) { return path(Path::fromString(p)); }
1596
1597 QList<QString> const fields() { return item().fields(); }
1598 MutableDomItem field(QStringView name) { return MutableDomItem(item().field(name)); }
1599 index_type indexes() { return item().indexes(); }
1600 MutableDomItem index(index_type i) { return MutableDomItem(item().index(i)); }
1601
1602 QSet<QString> const keys() { return item().keys(); }
1603 MutableDomItem key(const QString &name) { return MutableDomItem(item().key(name)); }
1604 MutableDomItem key(QStringView name) { return key(name.toString()); }
1605
1606 void
1607 dump(const Sink &s, int indent = 0,
1608 function_ref<bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter = noFilter)
1609 {
1610 item().dump(s, indent, filter);
1611 }
1613 dump(const QString &path,
1614 function_ref<bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter = noFilter,
1615 int nBackups = 2, int indent = 0, FileWriter *fw = nullptr)
1616 {
1617 return item().dump(path, filter, nBackups, indent, fw);
1618 }
1619 void writeOut(OutWriter &lw) { return item().writeOut(lw); }
1620 bool writeOut(const QString &path, int nBackups = 2,
1621 const LineWriterOptions &opt = LineWriterOptions(), FileWriter *fw = nullptr)
1622 {
1623 return item().writeOut(path, nBackups, opt, fw);
1624 }
1625
1630 bool commitToBase(const std::shared_ptr<DomEnvironment> &validEnvPtr = nullptr)
1631 {
1632 return item().commitToBase(validEnvPtr);
1633 }
1634 QString canonicalFilePath() const { return item().canonicalFilePath(); }
1635
1637
1638 QCborValue value() { return item().value(); }
1639
1640 QString toString() { return item().toString(); }
1641
1642 // convenience getters
1643 QString name() { return item().name(); }
1646 QString idStr() { return item().idStr(); }
1651 MutableDomItem child(index_type i) { return MutableDomItem(item().child(i)); }
1653
1654 // // OwnigItem elements
1655 int derivedFrom() { return m_owner.derivedFrom(); }
1656 int revision() { return m_owner.revision(); }
1657 QDateTime createdAt() { return m_owner.createdAt(); }
1658 QDateTime frozenAt() { return m_owner.frozenAt(); }
1659 QDateTime lastDataUpdateAt() { return m_owner.lastDataUpdateAt(); }
1660
1661 void addError(ErrorMessage &&msg) { item().addError(std::move(msg)); }
1663
1664 // convenience setters
1669 const MethodInfo &functionDef, AddOption option = AddOption::Overwrite);
1671
1672 MutableDomItem() = default;
1673 MutableDomItem(const DomItem &owner, const Path &pathFromOwner):
1675 {}
1679
1680 std::shared_ptr<DomTop> topPtr() { return m_owner.topPtr(); }
1681 std::shared_ptr<OwningItem> owningItemPtr() { return m_owner.owningItemPtr(); }
1682
1683 template<typename T>
1684 T const *as()
1685 {
1686 return item().as<T>();
1687 }
1688
1689 template <typename T>
1691 Q_ASSERT(!m_owner || !m_owner.owningItemPtr()->frozen());
1692
1693 DomItem self = item();
1694 if (self.m_kind != T::kindValue)
1695 return nullptr;
1696
1697 const T *t = nullptr;
1698 if constexpr (domTypeIsObjWrap(T::kindValue) || domTypeIsValueWrap(T::kindValue))
1699 t = static_cast<const SimpleObjectWrapBase *>(self.base())->as<T>();
1700 else if constexpr (std::is_base_of<DomBase, T>::value)
1701 t = static_cast<const T *>(self.base());
1702 else
1703 Q_UNREACHABLE_RETURN(nullptr);
1704
1705 // Nasty. But since ElementT has to store the const pointers, we allow it in this one place.
1706 return const_cast<T *>(t);
1707 }
1708
1709 template<typename T>
1710 std::shared_ptr<T> ownerAs() const
1711 {
1712 return m_owner.ownerAs<T>();
1713 }
1714 // it is dangerous to assume it stays valid when updates are preformed...
1715 DomItem item() const { return m_owner.path(m_pathFromOwner); }
1716
1717 friend bool operator==(const MutableDomItem &o1, const MutableDomItem &o2)
1718 {
1719 return o1.m_owner == o2.m_owner && o1.m_pathFromOwner == o2.m_pathFromOwner;
1720 }
1721 friend bool operator!=(const MutableDomItem &o1, const MutableDomItem &o2)
1722 {
1723 return !(o1 == o2);
1724 }
1725
1726private:
1727 DomItem m_owner;
1728 Path m_pathFromOwner;
1729};
1730
1731QMLDOM_EXPORT QDebug operator<<(QDebug debug, const MutableDomItem &c);
1732
1733template<typename K, typename T>
1734Path insertUpdatableElementInMultiMap(const Path &mapPathFromOwner, QMultiMap<K, T> &mmap, K key,
1735 const T &value, AddOption option = AddOption::KeepExisting,
1736 T **valuePtr = nullptr)
1737{
1738 if (option == AddOption::Overwrite) {
1739 auto it = mmap.find(key);
1740 if (it != mmap.end()) {
1741 T &v = *it;
1742 v = value;
1743 if (++it != mmap.end() && it.key() == key) {
1744 qWarning() << " requested overwrite of " << key
1745 << " that contains aleready multiple entries in" << mapPathFromOwner;
1746 }
1747 Path newPath = mapPathFromOwner.withKey(key).withIndex(0);
1748 v.updatePathFromOwner(newPath);
1749 if (valuePtr)
1750 *valuePtr = &v;
1751 return newPath;
1752 }
1753 }
1754 mmap.insert(key, value);
1755 auto it = mmap.find(key);
1756 auto it2 = it;
1757 int nVal = 0;
1758 while (it2 != mmap.end() && it2.key() == key) {
1759 ++nVal;
1760 ++it2;
1761 }
1762 Path newPath = mapPathFromOwner.withKey(key).withIndex(nVal-1);
1763 T &v = *it;
1764 v.updatePathFromOwner(newPath);
1765 if (valuePtr)
1766 *valuePtr = &v;
1767 return newPath;
1768}
1769
1770template<typename T>
1771Path appendUpdatableElementInQList(const Path &listPathFromOwner, QList<T> &list, const T &value,
1772 T **vPtr = nullptr)
1773{
1774 int idx = list.size();
1775 list.append(value);
1776 Path newPath = listPathFromOwner.withIndex(idx);
1777 T &targetV = list[idx];
1778 targetV.updatePathFromOwner(newPath);
1779 if (vPtr)
1780 *vPtr = &targetV;
1781 return newPath;
1782}
1783
1784template <typename T, typename K = QString>
1785void updatePathFromOwnerMultiMap(QMultiMap<K, T> &mmap, const Path &newPath)
1786{
1787 auto it = mmap.begin();
1788 auto end = mmap.end();
1789 index_type i = 0;
1790 K name;
1791 QList<T*> els;
1792 while (it != end) {
1793 if (i > 0 && name != it.key()) {
1794 Path pName = newPath.withKey(QString(name));
1795 for (T *el : els)
1796 el->updatePathFromOwner(pName.withIndex(--i));
1797 els.clear();
1798 els.append(&(*it));
1799 name = it.key();
1800 i = 1;
1801 } else {
1802 els.append(&(*it));
1803 name = it.key();
1804 ++i;
1805 }
1806 ++it;
1807 }
1808 Path pName = newPath.withKey(name);
1809 for (T *el : els)
1810 el->updatePathFromOwner(pName.withIndex(--i));
1811}
1812
1813template <typename T>
1814void updatePathFromOwnerQList(QList<T> &list, const Path &newPath)
1815{
1816 auto it = list.begin();
1817 auto end = list.end();
1818 index_type i = 0;
1819 while (it != end)
1820 (it++)->updatePathFromOwner(newPath.withIndex(i++));
1821}
1822
1823constexpr bool domTypeIsObjWrap(DomType k)
1824{
1825 switch (k) {
1826 case DomType::Binding:
1827 case DomType::EnumItem:
1829 case DomType::Export:
1830 case DomType::Id:
1831 case DomType::Import:
1836 case DomType::Pragma:
1838 case DomType::Version:
1839 case DomType::Comment:
1843 return true;
1844 default:
1845 return false;
1846 }
1847}
1848
1850{
1851 switch (k) {
1853 return true;
1854 default:
1855 return false;
1856 }
1857}
1858
1860{
1861 switch (k) {
1863 case DomType::QmlObject:
1866 case DomType::Reference:
1867 case DomType::Map:
1868 case DomType::List:
1869 case DomType::ListP:
1870 case DomType::EnumDecl:
1876 return true;
1877 default:
1878 return false;
1879 }
1880}
1881
1883{
1884 switch (k) {
1886
1887 case DomType::MockOwner:
1888
1891
1894 case DomType::JsFile:
1895 case DomType::QmlFile:
1898
1901
1902 case DomType::LoadInfo:
1904
1907 return true;
1908 default:
1909 return false;
1910 }
1911}
1912
1914{
1915 switch (k) {
1919 return true;
1920 default:
1921 return false;
1922 }
1923}
1924
1926{
1928}
1929
1930template<typename T>
1932 ConstantData::Options options) const
1933{
1934 using BaseT = std::remove_cv_t<std::remove_reference_t<T>>;
1935 if constexpr (
1936 std::is_base_of_v<
1937 QCborValue,
1938 BaseT> || std::is_base_of_v<QCborArray, BaseT> || std::is_base_of_v<QCborMap, BaseT>) {
1939 return DomItem(m_top, m_owner, m_ownerPath,
1940 ConstantData(pathFromOwner().withComponent(c), value, options));
1941 } else if constexpr (std::is_same_v<DomItem, BaseT>) {
1942 Q_UNUSED(options);
1943 return value;
1944 } else if constexpr (IsList<T>::value && !std::is_convertible_v<BaseT, QStringView>) {
1945 return subListItem(List::fromQList<typename BaseT::value_type>(
1946 pathFromOwner().withComponent(c), value,
1947 [options](const DomItem &list, const PathEls::PathComponent &p,
1948 const typename T::value_type &v) { return list.subValueItem(p, v, options); }));
1949 } else if constexpr (IsSharedPointerToDomObject<BaseT>::value) {
1950 Q_UNUSED(options);
1951 return subOwnerItem(c, value);
1952 } else {
1953 return subDataItem(c, value, options);
1954 }
1955}
1956
1957template<typename T>
1959 ConstantData::Options options) const
1960{
1961 using BaseT = std::remove_cv_t<std::remove_reference_t<T>>;
1962 if constexpr (std::is_same_v<BaseT, ConstantData>) {
1963 return this->copy(value);
1964 } else if constexpr (std::is_base_of_v<QCborValue, BaseT>) {
1965 return DomItem(m_top, m_owner, m_ownerPath,
1966 ConstantData(pathFromOwner().withComponent(c), value, options));
1967 } else {
1968 return DomItem(
1969 m_top, m_owner, m_ownerPath,
1970 ConstantData(pathFromOwner().withComponent(c), QCborValue(value), options));
1971 }
1972}
1973
1974template <typename T>
1975bool DomItem::invokeVisitorOnValue(DirectVisitor visitor, const PathEls::PathComponent &c,
1976 const T &value, ConstantData::Options options) const
1977{
1978 auto lazyWrap = [this, &c, &value, options]() {
1979 return this->subValueItem<T>(c, value, options);
1980 };
1981 return visitor(c, lazyWrap);
1982}
1983
1984template<typename T>
1985DomItem DomItem::wrap(const PathEls::PathComponent &c, const T &obj) const
1986{
1987 using BaseT = std::decay_t<T>;
1988 if constexpr (std::is_same_v<QString, BaseT> || std::is_arithmetic_v<BaseT>) {
1989 return this->subDataItem(c, QCborValue(obj));
1990 } else if constexpr (std::is_same_v<SourceLocation, BaseT>) {
1991 return this->subDataItem(c, sourceLocationToQCborValue(obj));
1992 } else if constexpr (std::is_same_v<BaseT, Reference>) {
1993 Q_ASSERT_X(false, "DomItem::wrap",
1994 "wrapping a reference object, probably an error (wrap the target path instead)");
1995 return this->copy(obj);
1996 } else if constexpr (std::is_same_v<BaseT, ConstantData>) {
1997 return this->subDataItem(c, obj);
1998 } else if constexpr (std::is_same_v<BaseT, Map>) {
1999 return this->subMapItem(obj);
2000 } else if constexpr (std::is_same_v<BaseT, List>) {
2001 return this->subListItem(obj);
2002 } else if constexpr (std::is_base_of_v<ListPBase, BaseT>) {
2003 return this->subListItem(obj);
2004 } else if constexpr (std::is_same_v<BaseT, SimpleObjectWrap>) {
2005 return DomItem(m_top, m_owner, m_ownerPath, obj);
2006 } else if constexpr (IsDomObject<BaseT>::value) {
2007 if constexpr (domTypeIsObjWrap(BaseT::kindValue) || domTypeIsValueWrap(BaseT::kindValue)) {
2008 return DomItem(
2009 m_top, m_owner, m_ownerPath,
2010 SimpleObjectWrap::fromObjectRef(this->pathFromOwner().withComponent(c), obj));
2011 } else if constexpr (domTypeIsDomElement(BaseT::kindValue)) {
2012 return this->copy(&obj);
2013 } else {
2014 qCWarning(domLog) << "Unhandled object of type " << domTypeToString(BaseT::kindValue)
2015 << " in DomItem::wrap, not using a shared_ptr for an "
2016 << "OwningItem, or unexpected wrapped object?";
2017 return DomItem();
2018 }
2019 } else if constexpr (IsSharedPointerToDomObject<BaseT>::value) {
2020 if constexpr (domTypeIsOwningItem(BaseT::element_type::kindValue)) {
2021 return this->subOwnerItem(c, obj);
2022 } else {
2023 Q_ASSERT_X(false, "DomItem::wrap", "shared_ptr with non owning item");
2024 return DomItem();
2025 }
2026 } else if constexpr (IsMultiMap<BaseT>::value) {
2027 if constexpr (std::is_same_v<typename BaseT::key_type, QString>) {
2028 return subMapItem(Map::fromMultiMapRef<typename BaseT::mapped_type>(
2029 pathFromOwner().withComponent(c), obj));
2030 } else {
2031 Q_ASSERT_X(false, "DomItem::wrap", "non string keys not supported (try .toString()?)");
2032 }
2033 } else if constexpr (IsMap<BaseT>::value) {
2034 if constexpr (std::is_same_v<typename BaseT::key_type, QString>) {
2035 return subMapItem(Map::fromMapRef<typename BaseT::mapped_type>(
2036 pathFromOwner().withComponent(c), obj,
2037 [](const DomItem &map, const PathEls::PathComponent &p,
2038 const typename BaseT::mapped_type &el) { return map.wrap(p, el); }));
2039 } else {
2040 Q_ASSERT_X(false, "DomItem::wrap", "non string keys not supported (try .toString()?)");
2041 }
2042 } else if constexpr (IsList<BaseT>::value) {
2043 if constexpr (IsDomObject<typename BaseT::value_type>::value) {
2044 return subListItem(List::fromQListRef<typename BaseT::value_type>(
2045 pathFromOwner().withComponent(c), obj,
2046 [](const DomItem &list, const PathEls::PathComponent &p,
2047 const typename BaseT::value_type &el) { return list.wrap(p, el); }));
2048 } else {
2049 Q_ASSERT_X(false, "DomItem::wrap", "Unsupported list type T");
2050 return DomItem();
2051 }
2052 } else {
2053 qCWarning(domLog) << "Cannot wrap " << typeid(BaseT).name();
2054 Q_ASSERT_X(false, "DomItem::wrap", "Do not know how to wrap type T");
2055 return DomItem();
2056 }
2057}
2058
2059template<typename T>
2060bool ListPT<T>::iterateDirectSubpaths(const DomItem &self, DirectVisitor v) const
2061{
2062 index_type len = index_type(m_pList.size());
2063 for (index_type i = 0; i < len; ++i) {
2064 if (!v(PathEls::Index(i), [this, &self, i] { return this->index(self, i); }))
2065 return false;
2066 }
2067 return true;
2068}
2069
2070template<typename T>
2071DomItem ListPT<T>::index(const DomItem &self, index_type index) const
2072{
2073 if (index >= 0 && index < m_pList.size())
2074 return self.wrap(PathEls::Index(index), *static_cast<const T *>(m_pList.value(index)));
2075 return DomItem();
2076}
2077
2078// allow inlining of DomBase
2079inline DomKind DomBase::domKind() const
2080{
2081 return kind2domKind(kind());
2082}
2083
2084inline DomItem DomBase::containingObject(const DomItem &self) const
2085{
2086 Path path = pathFromOwner();
2087 DomItem base = self.owner();
2088 if (!path) {
2089 path = canonicalPath(self);
2090 base = self;
2091 }
2092 Source source = path.split();
2093 return base.path(source.pathToSource);
2094}
2095
2096inline quintptr DomBase::id() const
2097{
2098 return quintptr(this);
2099}
2100
2101inline QString DomBase::typeName() const
2102{
2103 return domTypeToString(kind());
2104}
2105
2106inline QList<QString> DomBase::fields(const DomItem &self) const
2107{
2108 QList<QString> res;
2109 self.iterateDirectSubpaths([&res](const PathEls::PathComponent &c, function_ref<DomItem()>) {
2110 if (c.kind() == Path::Kind::Field)
2111 res.append(c.name());
2112 return true;
2113 });
2114 return res;
2115}
2116
2117inline DomItem DomBase::field(const DomItem &self, QStringView name) const
2118{
2119 DomItem res;
2120 self.iterateDirectSubpaths(
2121 [&res, name](const PathEls::PathComponent &c, function_ref<DomItem()> obj) {
2122 if (c.kind() == Path::Kind::Field && c.checkName(name)) {
2123 res = obj();
2124 return false;
2125 }
2126 return true;
2127 });
2128 return res;
2129}
2130
2131inline index_type DomBase::indexes(const DomItem &self) const
2132{
2133 index_type res = 0;
2134 self.iterateDirectSubpaths([&res](const PathEls::PathComponent &c, function_ref<DomItem()>) {
2135 if (c.kind() == Path::Kind::Index) {
2136 index_type i = c.index() + 1;
2137 if (res < i)
2138 res = i;
2139 }
2140 return true;
2141 });
2142 return res;
2143}
2144
2145inline DomItem DomBase::index(const DomItem &self, qint64 index) const
2146{
2147 DomItem res;
2148 self.iterateDirectSubpaths(
2149 [&res, index](const PathEls::PathComponent &c, function_ref<DomItem()> obj) {
2150 if (c.kind() == Path::Kind::Index && c.index() == index) {
2151 res = obj();
2152 return false;
2153 }
2154 return true;
2155 });
2156 return res;
2157}
2158
2159inline QSet<QString> const DomBase::keys(const DomItem &self) const
2160{
2161 QSet<QString> res;
2162 self.iterateDirectSubpaths([&res](const PathEls::PathComponent &c, function_ref<DomItem()>) {
2163 if (c.kind() == Path::Kind::Key)
2164 res.insert(c.name());
2165 return true;
2166 });
2167 return res;
2168}
2169
2170inline DomItem DomBase::key(const DomItem &self, const QString &name) const
2171{
2172 DomItem res;
2173 self.iterateDirectSubpaths(
2174 [&res, name](const PathEls::PathComponent &c, function_ref<DomItem()> obj) {
2175 if (c.kind() == Path::Kind::Key && c.checkName(name)) {
2176 res = obj();
2177 return false;
2178 }
2179 return true;
2180 });
2181 return res;
2182}
2183
2184inline DomItem DomItem::subListItem(const List &list) const
2185{
2186 return DomItem(m_top, m_owner, m_ownerPath, list);
2187}
2188
2189inline DomItem DomItem::subMapItem(const Map &map) const
2190{
2191 return DomItem(m_top, m_owner, m_ownerPath, map);
2192}
2193
2194// TODO
2195// refactor this workaround. ExternalOWningItem is not recognized as an owning type
2196// in ownerAs.
2197std::shared_ptr<ExternalOwningItem> getFileItemOwner(const DomItem &fileItem);
2198
2199} // end namespace Dom
2200} // end namespace QQmlJS
2201
2202QT_END_NAMESPACE
2203#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
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
function< void(const Path &, const DomItem &, const DomItem &)> Callback
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
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 > &)
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
FileWriter::Status dump(const QString &path, function_ref< bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter=noFilter, int nBackups=2, int indent=0, FileWriter *fw=nullptr) 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
bool writeOut(const QString &path, int nBackups=2, const LineWriterOptions &opt=LineWriterOptions(), FileWriter *fw=nullptr, WriteOutChecks extraChecks=WriteOutCheck::Default) 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)
FileWriter::Status dump(const QString &path, function_ref< bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter=noFilter, int nBackups=2, int indent=0, FileWriter *fw=nullptr)
bool writeOut(const QString &path, int nBackups=2, const LineWriterOptions &opt=LineWriterOptions(), FileWriter *fw=nullptr)
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)
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()
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(const QQmlJSScope::Ptr &current, 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)
static constexpr DomType kindValue
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)
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 writeOutSortedAttributes(const DomItem &self, OutWriter &ow, const DomItem &component) const
MutableDomItem addMethod(MutableDomItem &self, const MethodInfo &functionDef, AddOption option)
void writeOutAttributes(const DomItem &self, OutWriter &ow, const DomItem &component, const QString &code) const
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
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)