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
qqmldomelements_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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// Qt-Security score:significant
4
5#ifndef QQMLDOMELEMENTS_P_H
6#define QQMLDOMELEMENTS_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "qqmldomitem_p.h"
23
24#include <QtQml/private/qqmljsast_p.h>
25#include <QtQml/private/qqmljsengine_p.h>
26#include <QtQml/private/qqmlsignalnames_p.h>
27
28#include <QtCore/QCborValue>
29#include <QtCore/QCborMap>
30#include <QtCore/QMutexLocker>
31
32#include <memory>
33#include <private/qqmljsscope_p.h>
34
35#include <functional>
36#include <limits>
37#include <utility>
38
39QT_BEGIN_NAMESPACE
40
41namespace QQmlJS {
42namespace Dom {
43
44// namespace for utility methods building specific paths
45// using a namespace one can reopen it and add more methods in other places
46namespace Paths {
48 const QString &uri, int majorVersion, const ErrorHandler &errorHandler = nullptr);
50 const QString &uri, Version version, const ErrorHandler &errorHandler = nullptr);
52 const QString &uri, const QString &version, const ErrorHandler &errorHandler = nullptr);
54 const QString &uri, const ErrorHandler &errorHandler = nullptr)
55{
56 return moduleScopePath(uri, QString(), errorHandler);
57}
58inline Path qmlDirInfoPath(const QString &path)
59{
60 return Path::fromRoot(PathRoot::Top).withField(Fields::qmldirWithPath).withKey(path);
61}
62inline Path qmlDirPath(const QString &path)
63{
64 return qmlDirInfoPath(path).withField(Fields::currentItem);
65}
66inline Path qmldirFileInfoPath(const QString &path)
67{
68 return Path::fromRoot(PathRoot::Top).withField(Fields::qmldirFileWithPath).withKey(path);
69}
70inline Path qmldirFilePath(const QString &path)
71{
72 return qmldirFileInfoPath(path).withField(Fields::currentItem);
73}
74inline Path qmlFileInfoPath(const QString &canonicalFilePath)
75{
76 return Path::fromRoot(PathRoot::Top).withField(Fields::qmlFileWithPath).withKey(canonicalFilePath);
77}
78inline Path qmlFilePath(const QString &canonicalFilePath)
79{
80 return qmlFileInfoPath(canonicalFilePath).withField(Fields::currentItem);
81}
82inline Path qmlFileObjectPath(const QString &canonicalFilePath)
83{
84 return qmlFilePath(canonicalFilePath)
85 .withField(Fields::components)
86 .withKey(QString())
87 .withIndex(0)
88 .withField(Fields::objects)
89 .withIndex(0);
90}
91inline Path qmltypesFileInfoPath(const QString &path)
92{
93 return Path::fromRoot(PathRoot::Top).withField(Fields::qmltypesFileWithPath).withKey(path);
94}
95inline Path qmltypesFilePath(const QString &path)
96{
97 return qmltypesFileInfoPath(path).withField(Fields::currentItem);
98}
99inline Path jsFileInfoPath(const QString &path)
100{
101 return Path::fromRoot(PathRoot::Top).withField(Fields::jsFileWithPath).withKey(path);
102}
103inline Path jsFilePath(const QString &path)
104{
105 return jsFileInfoPath(path).withField(Fields::currentItem);
106}
107inline Path qmlDirectoryInfoPath(const QString &path)
108{
109 return Path::fromRoot(PathRoot::Top).withField(Fields::qmlDirectoryWithPath).withKey(path);
110}
111inline Path qmlDirectoryPath(const QString &path)
112{
113 return qmlDirectoryInfoPath(path).withField(Fields::currentItem);
114}
115inline Path globalScopeInfoPath(const QString &name)
116{
117 return Path::fromRoot(PathRoot::Top).withField(Fields::globalScopeWithName).withKey(name);
118}
119inline Path globalScopePath(const QString &name)
120{
121 return globalScopeInfoPath(name).withField(Fields::currentItem);
122}
123inline Path lookupCppTypePath(const QString &name)
124{
125 return Path::fromCurrent(PathCurrent::Lookup).withField(Fields::cppType).withKey(name);
126}
127inline Path lookupPropertyPath(const QString &name)
128{
129 return Path::fromCurrent(PathCurrent::Lookup).withField(Fields::propertyDef).withKey(name);
130}
131inline Path lookupSymbolPath(const QString &name)
132{
133 return Path::fromCurrent(PathCurrent::Lookup).withField(Fields::symbol).withKey(name);
134}
135inline Path lookupTypePath(const QString &name)
136{
137 return Path::fromCurrent(PathCurrent::Lookup).withField(Fields::type).withKey(name);
138}
139inline Path loadInfoPath(const Path &el)
140{
141 return Path::fromRoot(PathRoot::Env).withField(Fields::loadInfo).withKey(el.toString());
142}
143} // end namespace Paths
144
146{
147public:
148 CommentableDomElement(const Path &pathFromOwner = Path()) : DomElement(pathFromOwner) { }
153 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
154 RegionComments &comments() { return m_comments; }
155 const RegionComments &comments() const { return m_comments; }
156
157private:
158 RegionComments m_comments;
159};
160
162{
163public:
165 constexpr static qint32 Undefined = -1;
166 constexpr static qint32 Latest = -2;
167
168 Version(qint32 majorVersion = Undefined, qint32 minorVersion = Undefined);
169 static Version fromString(QStringView v);
170
171 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const;
172
173 bool isLatest() const;
174 bool isValid() const;
175 QString stringValue() const;
177 {
178 if (majorVersion >= 0 || majorVersion == Undefined)
179 return QString::number(majorVersion);
180 return QString();
181 }
183 {
184 if (majorVersion == Version::Latest)
185 return QLatin1String("Latest");
186 if (majorVersion >= 0 || majorVersion == Undefined)
187 return QString::number(majorVersion);
188 return QString();
189 }
191 {
192 if (minorVersion >= 0 || minorVersion == Undefined)
193 return QString::number(minorVersion);
194 return QString();
195 }
196 int compare(Version o) const
197 {
198 int c = majorVersion - o.majorVersion;
199 if (c != 0)
200 return c;
201 return minorVersion - o.minorVersion;
202 }
203
206};
207inline bool operator==(Version v1, Version v2)
208{
209 return v1.compare(v2) == 0;
210}
211inline bool operator!=(Version v1, Version v2)
212{
213 return v1.compare(v2) != 0;
214}
215inline bool operator<(Version v1, Version v2)
216{
217 return v1.compare(v2) < 0;
218}
219inline bool operator<=(Version v1, Version v2)
220{
221 return v1.compare(v2) <= 0;
222}
223inline bool operator>(Version v1, Version v2)
224{
225 return v1.compare(v2) > 0;
226}
227inline bool operator>=(Version v1, Version v2)
228{
229 return v1.compare(v2) >= 0;
230}
231
233{
234public:
236 QmlUri() = default;
237 static QmlUri fromString(const QString &importStr);
238 static QmlUri fromUriString(const QString &importStr);
239 static QmlUri fromDirectoryString(const QString &importStr);
240 bool isValid() const;
241 bool isDirectory() const;
242 bool isModule() const;
243 QString moduleUri() const;
244 QString localPath() const;
245 QString absoluteLocalPath(const QString &basePath = QString()) const;
246 QUrl directoryUrl() const;
247 QString directoryString() const;
248 QString toString() const;
249 Kind kind() const;
250
251 friend bool operator==(const QmlUri &i1, const QmlUri &i2)
252 {
253 return i1.m_kind == i2.m_kind && i1.m_value == i2.m_value;
254 }
255 friend bool operator!=(const QmlUri &i1, const QmlUri &i2) { return !(i1 == i2); }
256
257private:
258 QmlUri(const QUrl &url) : m_kind(Kind::DirectoryUrl), m_value(url) { }
259 QmlUri(Kind kind, const QString &value) : m_kind(kind), m_value(value) { }
260 Kind m_kind = Kind::Invalid;
261 std::variant<QString, QUrl> m_value;
262};
263
265{
267public:
268 constexpr static DomType kindValue = DomType::Import;
269
270 static Import fromUriString(
271 const QString &importStr, Version v = Version(),
272 const QString &importId = QString(), const ErrorHandler &handler = nullptr);
273 static Import fromFileString(
274 const QString &importStr, const QString &importId = QString(),
275 const ErrorHandler &handler = nullptr);
276
277 Import(const QmlUri &uri = QmlUri(), Version version = Version(),
278 const QString &importId = QString())
280 {
281 }
282
283 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const;
285 {
286 if (uri.isDirectory()) {
287 QString path = uri.absoluteLocalPath();
288 if (!path.isEmpty()) {
289 return Paths::qmlDirPath(path);
290 } else {
291 Q_ASSERT_X(false, "Import", "url imports not supported");
292 return Paths::qmldirFilePath(uri.directoryString());
293 }
294 } else {
295 return Paths::moduleScopePath(uri.moduleUri(), version);
296 }
297 }
298 Import baseImport() const { return Import { uri, version }; }
299
300 friend bool operator==(const Import &i1, const Import &i2)
301 {
302 return i1.uri == i2.uri && i1.version == i2.version && i1.importId == i2.importId
303 && i1.comments == i2.comments && i1.implicit == i2.implicit;
304 }
305 friend bool operator!=(const Import &i1, const Import &i2) { return !(i1 == i2); }
306
307 void writeOut(const DomItem &self, OutWriter &ow) const;
308
310
315 bool implicit = false;
316};
317
319{
320public:
322
323 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
324 {
325 bool cont = true;
326 cont = cont && self.dvWrapField(visitor, Fields::import, import);
327 cont = cont && self.dvValueField(visitor, Fields::inheritVersion, inheritVersion);
328 return cont;
329 }
330
331 friend bool operator==(const ModuleAutoExport &i1, const ModuleAutoExport &i2)
332 {
333 return i1.import == i2.import && i1.inheritVersion == i2.inheritVersion;
334 }
335 friend bool operator!=(const ModuleAutoExport &i1, const ModuleAutoExport &i2)
336 {
337 return !(i1 == i2);
338 }
339
341 bool inheritVersion = false;
342};
343
345{
346public:
348
349 Pragma(const QString &pragmaName = QString(), const QStringList &pragmaValues = {})
351 {
352 }
353
354 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
355 {
356 bool cont = self.dvValueField(visitor, Fields::name, name);
357 cont = cont && self.dvValueField(visitor, Fields::values, values);
358 cont = cont && self.dvWrapField(visitor, Fields::comments, comments);
359 return cont;
360 }
361
362 void writeOut(const DomItem &self, OutWriter &ow) const;
363
367};
368
370{
371public:
372 constexpr static DomType kindValue = DomType::Id;
373
374 Id(const QString &idName = QString(), const Path &referredObject = Path());
375
376 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const;
377 void updatePathFromOwner(const Path &pathFromOwner);
378 Path addAnnotation(const Path &selfPathFromOwner, const QmlObject &ann, QmlObject **aPtr = nullptr);
379
385};
386
387// TODO: rename? it may contain statements and stuff, not only expressions
388// TODO QTBUG-121933
390{
391 Q_GADGET
392 Q_DECLARE_TR_FUNCTIONS(ScriptExpression)
393public:
394 enum class ExpressionType {
400 JSCode, // Used for storing the content of the whole .js file as "one" Expression
401 ESMCode, // Used for storing the content of the whole ECMAScript module (.mjs) as "one"
402 // Expression
403 };
406 DomType kind() const override { return kindValue; }
407
408 explicit ScriptExpression(QStringView code, const std::shared_ptr<QQmlJS::Engine> &engine,
409 AST::Node *ast, const std::shared_ptr<AstComments> &comments,
410 ExpressionType expressionType,
411 const SourceLocation &localOffset = SourceLocation());
412
419
420 explicit ScriptExpression(const QString &code, ExpressionType expressionType)
422 {
423 setCode(code);
424 }
425
427
428 std::shared_ptr<ScriptExpression> makeCopy(const DomItem &self) const
429 {
430 return std::static_pointer_cast<ScriptExpression>(doCopy(self));
431 }
432
433 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override;
434
435 Path canonicalPath(const DomItem &self) const override { return self.m_ownerPath; }
436 // parsed and created if not available
437 AST::Node *ast() const { return m_ast; }
438 // dump of the ast (without locations)
439 void astDumper(const Sink &s, AstDumperOptions options) const;
441
442 // definedSymbols name, value, from
443 // usedSymbols name, locations
445 {
446 QMutexLocker l(mutex());
447 return m_code;
448 }
449
451 {
452 QMutexLocker l(mutex());
453 return m_expressionType;
454 }
455
456 bool isNull() const
457 {
458 QMutexLocker l(mutex());
459 return m_code.isNull();
460 }
462 {
463 QMutexLocker l(mutex());
464 return m_engine;
465 }
466 QStringView loc2Str(const SourceLocation &) const;
467 std::shared_ptr<AstComments> astComments() const { return m_astComments; }
468 void writeOut(const DomItem &self, OutWriter &lw) const override;
469 SourceLocation globalLocation(const DomItem &self) const;
470 SourceLocation localOffset() const { return m_localOffset; }
472 ScriptElementVariant scriptElement() { return m_element; }
473
474protected:
475 std::shared_ptr<OwningItem> doCopy(const DomItem &) const override
476 {
477 return std::make_shared<ScriptExpression>(*this);
478 }
479
480 SourceLocation locationToLocal(const SourceLocation &x) const
481 {
482 return SourceLocation(
483 x.offset - m_localOffset.offset, x.length, x.startLine - m_localOffset.startLine,
484 ((x.startLine == m_localOffset.startLine)
485 ? x.startColumn - m_localOffset.startColumn
486 : x.startColumn)); // are line and column 1 based? then we should + 1
487 }
488
489private:
490 void setCode(const QString &code);
491 [[nodiscard]] AST::Node *parse();
492
493 ExpressionType m_expressionType;
494 QString m_codeStr;
495 QStringView m_code;
496 mutable std::shared_ptr<QQmlJS::Engine> m_engine;
497 mutable AST::Node *m_ast;
498 std::shared_ptr<AstComments> m_astComments;
499 SourceLocation m_localOffset;
500 ScriptElementVariant m_element;
501};
502
503class BindingValue;
504
506{
507public:
509
510 Binding(const QString &m_name = QString());
511 Binding(const QString &m_name, std::unique_ptr<BindingValue> &&value,
512 BindingType bindingType = BindingType::Normal);
513 Binding(const QString &m_name, const std::shared_ptr<ScriptExpression> &value,
514 BindingType bindingType = BindingType::Normal);
515 Binding(const QString &m_name, const QString &scriptCode,
516 BindingType bindingType = BindingType::Normal);
517 Binding(const QString &m_name, const QmlObject &value,
518 BindingType bindingType = BindingType::Normal);
519 Binding(const QString &m_name, const QList<QmlObject> &value,
520 BindingType bindingType = BindingType::Normal);
521 Binding(const Binding &o);
522 Binding(Binding &&o) = default;
523 ~Binding();
524 Binding &operator=(const Binding &);
525 Binding &operator=(Binding &&) = default;
526
527 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const;
528 DomItem valueItem(const DomItem &self) const; // ### REVISIT: consider replacing return value with variant
530 QString name() const { return m_name; }
531 BindingType bindingType() const { return m_bindingType; }
532 QmlObject const *objectValue() const;
533 QList<QmlObject> const *arrayValue() const;
534 std::shared_ptr<ScriptExpression> scriptExpressionValue() const;
538 QList<QmlObject> annotations() const { return m_annotations; }
539 void setAnnotations(const QList<QmlObject> &annotations) { m_annotations = annotations; }
540 void setValue(std::unique_ptr<BindingValue> &&value);
541 Path addAnnotation(const Path &selfPathFromOwner, const QmlObject &a, QmlObject **aPtr = nullptr);
542 const RegionComments &comments() const { return m_comments; }
543 RegionComments &comments() { return m_comments; }
544 void updatePathFromOwner(const Path &newPath);
545 void writeOut(const DomItem &self, OutWriter &lw) const;
546 void writeOutValue(const DomItem &self, OutWriter &lw) const;
547 bool isSignalHandler() const
548 {
549 QString baseName = m_name.split(QLatin1Char('.')).last();
550 return QQmlSignalNames::isHandlerName(baseName);
551 }
552 static QString preCodeForName(QStringView n)
553 {
554 return QStringLiteral(u"QtObject{\n %1: ").arg(n.split(u'.').last());
555 }
556 static QString postCodeForName(QStringView) { return QStringLiteral(u"\n}\n"); }
557 QString preCode() const { return preCodeForName(m_name); }
558 QString postCode() const { return postCodeForName(m_name); }
559
560 ScriptElementVariant bindingIdentifiers() const { return m_bindingIdentifiers; }
561 void setBindingIdentifiers(const ScriptElementVariant &bindingIdentifiers) { m_bindingIdentifiers = bindingIdentifiers; }
562
563private:
565 BindingType m_bindingType;
566 QString m_name;
567 std::unique_ptr<BindingValue> m_value;
568 QList<QmlObject> m_annotations;
569 RegionComments m_comments;
570 ScriptElementVariant m_bindingIdentifiers;
571};
572
574{
575public:
577
578 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
579
580 Path addAnnotation(const Path &selfPathFromOwner, const QmlObject &annotation,
581 QmlObject **aPtr = nullptr);
582 void updatePathFromOwner(const Path &newPath);
583
584 QQmlJSScope::ConstPtr semanticScope() const { return m_semanticScope; }
585 void setSemanticScope(const QQmlJSScope::ConstPtr &scope) { m_semanticScope = scope; }
586
590 bool isReadonly = false;
591 bool isList = false;
595};
596
617
619{
620public:
622
623 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
624 {
625 bool cont = AttributeInfo::iterateDirectSubpaths(self, visitor);
626 cont = cont && self.dvValueField(visitor, Fields::isPointer, isPointer);
627 cont = cont && self.dvValueField(visitor, Fields::isFinal, isFinal);
628 cont = cont && self.dvValueField(visitor, Fields::isAlias, isAlias());
629 cont = cont && self.dvValueField(visitor, Fields::isDefaultMember, isDefaultMember);
630 cont = cont && self.dvValueField(visitor, Fields::isRequired, isRequired);
631 cont = cont && self.dvValueField(visitor, Fields::read, read);
632 cont = cont && self.dvValueField(visitor, Fields::write, write);
633 cont = cont && self.dvValueField(visitor, Fields::bindable, bindable);
634 cont = cont && self.dvValueField(visitor, Fields::notify, notify);
635 cont = cont && self.dvReferenceField(visitor, Fields::type, typePath());
636 if (m_nameIdentifiers) {
637 cont = cont && self.dvItemField(visitor, Fields::nameIdentifiers, [this, &self]() {
638 return self.subScriptElementWrapperItem(m_nameIdentifiers);
639 });
640 }
641 return cont;
642 }
643
644 Path typePath() const { return Paths::lookupTypePath(typeName); }
645
646 bool isAlias() const { return typeName == u"alias"; }
647 bool isParametricType() const;
648 void writeOut(const DomItem &self, OutWriter &lw) const;
649 ScriptElementVariant nameIdentifiers() const { return m_nameIdentifiers; }
650 void setNameIdentifiers(const ScriptElementVariant &name) { m_nameIdentifiers = name; }
651
656 bool isFinal = false;
657 bool isPointer = false;
658 bool isDefaultMember = false;
659 bool isRequired = false;
661};
662
664{
665public:
666 constexpr static DomType kindValue = DomType::PropertyInfo; // used to get the correct kind in ObjectWrapper
667
668 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
669
672};
673
675{
676public:
679 Prefix, // a(int x)
680 Suffix, // a(x : int)
681 };
682 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
683
684 void writeOut(const DomItem &self, OutWriter &ow) const;
685 void writeOutSignal(const DomItem &self, OutWriter &ow) const;
686
689 bool isPointer = false;
690 bool isReadonly = false;
691 bool isList = false;
692 bool isRestElement = false;
694 /*!
695 \internal
696 Contains the scriptElement representing this argument, inclusive default value,
697 deconstruction, etc.
698 */
703};
704
705// TODO (QTBUG-128423)
706// Refactor to differentiate between Signals and Methods easily,
707// considering their distinct handling and formatting needs.
708// Explore separating Signal functionality or unifying shared methods.
710{
712public:
714 Q_ENUM(MethodType)
715
716 constexpr static DomType kindValue = DomType::MethodInfo;
717
718 Path typePath(const DomItem &) const
719 {
720 return (typeName.isEmpty() ? Path() : Paths::lookupTypePath(typeName));
721 }
722
723 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
724 void writePre(const DomItem &self, OutWriter &ow) const;
725 void writeOut(const DomItem &self, OutWriter &ow) const;
726 QString signature(const DomItem &self) const;
727
728 MethodInfo() = default;
729
730 // TODO: make private + add getters/setters
735 bool isConstructor = false;
736
737private:
738 void writeOutArguments(const DomItem &self, OutWriter &ow) const;
739 void writeOutReturnType(const DomItem &self, OutWriter &ow) const;
740 void writeOutBody(const DomItem &self, OutWriter &ow) const;
741};
742
744{
745public:
751 EnumItem(const QString &name = QString(), int value = 0, ValueKind valueKind = ValueKind::ImplicitValue)
752 : m_name(name), m_value(value), m_valueKind(valueKind)
753 {
754 }
755
756 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
757
758 QString name() const { return m_name; }
759 double value() const { return m_value; }
760 RegionComments &comments() { return m_comments; }
761 const RegionComments &comments() const { return m_comments; }
762 void writeOut(const DomItem &self, OutWriter &lw) const;
763
764private:
765 QString m_name;
766 double m_value;
767 ValueKind m_valueKind;
768 RegionComments m_comments;
769};
770
771class QMLDOM_EXPORT EnumDecl final : public CommentableDomElement
772{
773public:
775 DomType kind() const override { return kindValue; }
776
777 EnumDecl(const QString &name = QString(), const QList<EnumItem> &values = QList<EnumItem>(),
778 const Path &pathFromOwner = Path())
780 {
781 }
782
783 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override;
784
785 QString name() const { return m_name; }
786 void setName(const QString &name) { m_name = name; }
787 const QList<EnumItem> &values() const & { return m_values; }
788 bool isFlag() const { return m_isFlag; }
789 void setIsFlag(bool flag) { m_isFlag = flag; }
790 QString alias() const { return m_alias; }
791 void setAlias(const QString &aliasName) { m_alias = aliasName; }
792 void setValues(const QList<EnumItem> &values) { m_values = values; }
793 Path addValue(const EnumItem &value)
794 {
795 m_values.append(value);
796 return Path::fromField(Fields::values).withIndex(index_type(m_values.size() - 1));
797 }
798 void updatePathFromOwner(const Path &newP) override;
799
800 const QList<QmlObject> &annotations() const & { return m_annotations; }
801 void setAnnotations(const QList<QmlObject> &annotations);
802 Path addAnnotation(const QmlObject &child, QmlObject **cPtr = nullptr);
803 void writeOut(const DomItem &self, OutWriter &lw) const override;
804
805private:
806 QString m_name;
807 bool m_isFlag = false;
808 QString m_alias;
809 QList<EnumItem> m_values;
810 QList<QmlObject> m_annotations;
811};
812
814{
816public:
817 constexpr static DomType kindValue = DomType::QmlObject;
818 DomType kind() const override { return kindValue; }
819
820 QmlObject(const Path &pathFromOwner = Path());
821 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
822 bool iterateBaseDirectSubpaths(const DomItem &self, DirectVisitor) const;
823 QList<QString> fields() const;
824 QList<QString> fields(const DomItem &) const override { return fields(); }
825 DomItem field(const DomItem &self, QStringView name) const override;
826 void updatePathFromOwner(const Path &newPath) override;
828 QString defaultPropertyName(const DomItem &self) const;
829 bool iterateSubOwners(const DomItem &self,
830 function_ref<bool(const DomItem &owner)> visitor) const;
831
832 QString idStr() const { return m_idStr; }
833 QString name() const { return m_name; }
834 const QList<Path> &prototypePaths() const & { return m_prototypePaths; }
835 Path nextScopePath() const { return m_nextScopePath; }
836 const QMultiMap<QString, PropertyDefinition> &propertyDefs() const & { return m_propertyDefs; }
837 const QMultiMap<QString, Binding> &bindings() const & { return m_bindings; }
838 const QMultiMap<QString, MethodInfo> &methods() const & { return m_methods; }
839 QList<QmlObject> children() const { return m_children; }
840 QList<QmlObject> annotations() const { return m_annotations; }
841
842 void setIdStr(const QString &id) { m_idStr = id; }
843 void setName(const QString &name) { m_name = name; }
844 void setDefaultPropertyName(const QString &name) { m_defaultPropertyName = name; }
845 void setPrototypePaths(const QList<Path> &prototypePaths) { m_prototypePaths = prototypePaths; }
846 Path addPrototypePath(const Path &prototypePath)
847 {
848 index_type idx = index_type(m_prototypePaths.indexOf(prototypePath));
849 if (idx == -1) {
850 idx = index_type(m_prototypePaths.size());
851 m_prototypePaths.append(prototypePath);
852 }
853 return Path::fromField(Fields::prototypes).withIndex(idx);
854 }
855 void setNextScopePath(const Path &nextScopePath) { m_nextScopePath = nextScopePath; }
856 void setPropertyDefs(const QMultiMap<QString, PropertyDefinition> &propertyDefs)
857 {
858 m_propertyDefs = propertyDefs;
859 }
860 void setBindings(const QMultiMap<QString, Binding> &bindings) { m_bindings = bindings; }
861 void setMethods(const QMultiMap<QString, MethodInfo> &functionDefs)
862 {
863 m_methods = functionDefs;
864 }
865 void setChildren(const QList<QmlObject> &children)
866 {
867 m_children = children;
868 if (pathFromOwner())
870 }
871 void setAnnotations(const QList<QmlObject> &annotations)
872 {
873 m_annotations = annotations;
874 if (pathFromOwner())
876 }
878 PropertyDefinition **pDef = nullptr)
879 {
880 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::propertyDefs),
881 m_propertyDefs, propertyDef.name, propertyDef,
882 option, pDef);
883 }
885 AddOption option);
886
887 Path addBinding(const Binding &binding, AddOption option, Binding **bPtr = nullptr)
888 {
889 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::bindings), m_bindings,
890 binding.name(), binding, option, bPtr);
891 }
892 MutableDomItem addBinding(MutableDomItem &self, const Binding &binding, AddOption option);
893 Path addMethod(const MethodInfo &functionDef, AddOption option, MethodInfo **mPtr = nullptr)
894 {
895 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::methods), m_methods,
896 functionDef.name, functionDef, option, mPtr);
897 }
898 MutableDomItem addMethod(MutableDomItem &self, const MethodInfo &functionDef, AddOption option);
899 Path addChild(const QmlObject &child, QmlObject **cPtr = nullptr)
900 {
901 return appendUpdatableElementInQList(pathFromOwner().withField(Fields::children), m_children,
902 child, cPtr);
903 }
905 {
906 Path p = addChild(child);
908 }
909 Path addAnnotation(const QmlObject &annotation, QmlObject **aPtr = nullptr)
910 {
911 return appendUpdatableElementInQList(pathFromOwner().withField(Fields::annotations),
912 m_annotations, annotation, aPtr);
913 }
914
916 const DomItem &component) const;
917 void writeOutAttributes(const DomItem &self, OutWriter &ow, const DomItem &component,
918 const QString &code) const;
919
920 void writeOutSortedEnumerations(const DomItem &component, OutWriter &ow) const;
921 void writeOutSortedAttributes(const DomItem &self, OutWriter &ow,
922 const DomItem &component) const;
923 void writeOutSortedPropertyDefinition(const DomItem &self, OutWriter &ow,
924 QSet<QString> &mergedDefBinding) const;
925
926 void writeOutId(const DomItem &self, OutWriter &ow) const;
927 void writeOut(const DomItem &self, OutWriter &ow, const QString &onTarget) const;
928 void writeOut(const DomItem &self, OutWriter &lw) const override { writeOut(self, lw, QString()); }
929
931 std::shared_ptr<ScriptExpression> accessSequence) const;
932 LocallyResolvedAlias resolveAlias(const DomItem &self, const QStringList &accessSequence) const;
933
934 QQmlJSScope::ConstPtr semanticScope() const { return m_scope; }
935 void setSemanticScope(const QQmlJSScope::ConstPtr &scope) { m_scope = scope; }
936
937 ScriptElementVariant nameIdentifiers() const { return m_nameIdentifiers; }
938 void setNameIdentifiers(const ScriptElementVariant &name) { m_nameIdentifiers = name; }
939
940private:
942 QString m_idStr;
943 QString m_name;
944 QList<Path> m_prototypePaths;
945 Path m_nextScopePath;
946 QString m_defaultPropertyName;
947 QMultiMap<QString, PropertyDefinition> m_propertyDefs;
948 QMultiMap<QString, Binding> m_bindings;
949 QMultiMap<QString, MethodInfo> m_methods;
950 QList<QmlObject> m_children;
951 QList<QmlObject> m_annotations;
952 QQmlJSScope::ConstPtr m_scope;
953 ScriptElementVariant m_nameIdentifiers;
954
955 static constexpr quint32 posOfNewElements = std::numeric_limits<quint32>::max();
956};
957
959{
961public:
962 constexpr static DomType kindValue = DomType::Export;
963 static Export fromString(
964 const Path &source, QStringView exp, const Path &typePath, const ErrorHandler &h);
965 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
966 {
967 bool cont = true;
968 cont = cont && self.dvValueField(visitor, Fields::uri, uri);
969 cont = cont && self.dvValueField(visitor, Fields::typeName, typeName);
970 cont = cont && self.dvWrapField(visitor, Fields::version, version);
971 if (typePath)
972 cont = cont && self.dvReferenceField(visitor, Fields::type, typePath);
973 cont = cont && self.dvValueField(visitor, Fields::isInternal, isInternal);
974 cont = cont && self.dvValueField(visitor, Fields::isSingleton, isSingleton);
975 if (exportSourcePath)
976 cont = cont && self.dvReferenceField(visitor, Fields::exportSource, exportSourcePath);
977 return cont;
978 }
979
985 bool isInternal = false;
986 bool isSingleton = false;
987};
988
990{
991public:
992 Component(const QString &name);
993 Component(const Path &pathFromOwner = Path());
994 Component(const Component &o) = default;
995 Component &operator=(const Component &) = default;
996
997 bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override;
998 void updatePathFromOwner(const Path &newPath) override;
999 DomItem field(const DomItem &self, QStringView name) const override;
1000
1001 QString name() const { return m_name; }
1002 const QMultiMap<QString, EnumDecl> &enumerations() const & { return m_enumerations; }
1003 const QList<QmlObject> &objects() const & { return m_objects; }
1004 bool isSingleton() const { return m_isSingleton; }
1005 bool isCreatable() const { return m_isCreatable; }
1006 bool isComposite() const { return m_isComposite; }
1007 QString attachedTypeName() const { return m_attachedTypeName; }
1008 Path attachedTypePath(const DomItem &) const { return m_attachedTypePath; }
1009
1010 void setName(const QString &name) { m_name = name; }
1011 void setEnumerations(const QMultiMap<QString, EnumDecl> &enumerations)
1012 {
1013 m_enumerations = enumerations;
1014 }
1015 Path addEnumeration(const EnumDecl &enumeration, AddOption option = AddOption::Overwrite,
1016 EnumDecl **ePtr = nullptr)
1017 {
1018 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::enumerations),
1019 m_enumerations, enumeration.name(), enumeration,
1020 option, ePtr);
1021 }
1022 void setObjects(const QList<QmlObject> &objects) { m_objects = objects; }
1023 Path addObject(const QmlObject &object, QmlObject **oPtr = nullptr);
1024 void setIsSingleton(bool isSingleton) { m_isSingleton = isSingleton; }
1025 void setIsCreatable(bool isCreatable) { m_isCreatable = isCreatable; }
1026 void setIsComposite(bool isComposite) { m_isComposite = isComposite; }
1027 void setAttachedTypeName(const QString &name) { m_attachedTypeName = name; }
1028 void setAttachedTypePath(const Path &p) { m_attachedTypePath = p; }
1029
1030private:
1032 QString m_name;
1033 QMultiMap<QString, EnumDecl> m_enumerations;
1034 QList<QmlObject> m_objects;
1035 bool m_isSingleton = false;
1036 bool m_isCreatable = true;
1037 bool m_isComposite = true;
1038 QString m_attachedTypeName;
1039 Path m_attachedTypePath;
1040};
1041
1042class QMLDOM_EXPORT JsResource final : public Component
1043{
1044public:
1046 DomType kind() const override { return kindValue; }
1047
1048 JsResource(const Path &pathFromOwner = Path()) : Component(pathFromOwner) { }
1049 bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override
1050 { // to do: complete
1051 return true;
1052 }
1053 // globalSymbols defined/exported, required/used
1054};
1055
1056class QMLDOM_EXPORT QmltypesComponent final : public Component
1057{
1058public:
1060 DomType kind() const override { return kindValue; }
1061
1062 QmltypesComponent(const Path &pathFromOwner = Path()) : Component(pathFromOwner) { }
1063 bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override;
1064 const QList<Export> &exports() const & { return m_exports; }
1065 QString fileName() const { return m_fileName; }
1066 void setExports(const QList<Export> &exports) { m_exports = exports; }
1067 void addExport(const Export &exportedEntry) { m_exports.append(exportedEntry); }
1068 void setFileName(const QString &fileName) { m_fileName = fileName; }
1069 const QList<int> &metaRevisions() const & { return m_metaRevisions; }
1070 void setMetaRevisions(const QList<int> &metaRevisions) { m_metaRevisions = metaRevisions; }
1071 void setInterfaceNames(const QStringList& interfaces) { m_interfaceNames = interfaces; }
1072 const QStringList &interfaceNames() const & { return m_interfaceNames; }
1073 QString extensionTypeName() const { return m_extensionTypeName; }
1074 void setExtensionTypeName(const QString &name) { m_extensionTypeName = name; }
1075 QString elementTypeName() const { return m_elementTypeName; }
1076 void setElementTypeName(const QString &name) { m_elementTypeName = name; }
1077 bool hasCustomParser() const { return m_hasCustomParser; }
1078 void setHasCustomParser(bool v) { m_hasCustomParser = v; }
1079 bool extensionIsJavaScript() const { return m_extensionIsJavaScript; }
1080 void setExtensionIsJavaScript(bool v) { m_extensionIsJavaScript = v; }
1081 bool extensionIsNamespace() const { return m_extensionIsNamespace; }
1082 void setExtensionIsNamespace(bool v) { m_extensionIsNamespace = v; }
1083 QQmlJSScope::AccessSemantics accessSemantics() const { return m_accessSemantics; }
1084 void setAccessSemantics(QQmlJSScope::AccessSemantics v) { m_accessSemantics = v; }
1085
1086 void setSemanticScope(const QQmlJSScope::ConstPtr &scope) { m_semanticScope = scope; }
1087 QQmlJSScope::ConstPtr semanticScope() const { return m_semanticScope; }
1088
1089private:
1090 QList<Export> m_exports;
1091 QList<int> m_metaRevisions;
1092 QString m_fileName; // remove?
1093 QStringList m_interfaceNames;
1094 bool m_hasCustomParser = false;
1095 bool m_extensionIsJavaScript = false;
1096 bool m_extensionIsNamespace = false;
1097 QString m_elementTypeName;
1098 QString m_extensionTypeName;
1099 QQmlJSScope::AccessSemantics m_accessSemantics = QQmlJSScope::AccessSemantics::None;
1100 QQmlJSScope::ConstPtr m_semanticScope;
1101};
1102
1103class QMLDOM_EXPORT QmlComponent final : public Component
1104{
1105public:
1107 DomType kind() const override { return kindValue; }
1108
1109 QmlComponent(const QString &name = QString()) : Component(name)
1110 {
1111 setIsComposite(true);
1112 setIsCreatable(true);
1113 }
1114
1115 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
1116
1117 const QMultiMap<QString, Id> &ids() const & { return m_ids; }
1118 Path nextComponentPath() const { return m_nextComponentPath; }
1119 void setIds(const QMultiMap<QString, Id> &ids) { m_ids = ids; }
1120 void setNextComponentPath(const Path &p) { m_nextComponentPath = p; }
1121 void updatePathFromOwner(const Path &newPath) override;
1122 Path addId(const Id &id, AddOption option = AddOption::Overwrite, Id **idPtr = nullptr)
1123 {
1124 // warning does nor remove old idStr when overwriting...
1125 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::ids), m_ids, id.name,
1126 id, option, idPtr);
1127 }
1128 void writeOut(const DomItem &self, OutWriter &) const override;
1129 QList<QString> subComponentsNames(const DomItem &self) const;
1130 QList<DomItem> subComponents(const DomItem &self) const;
1131
1132 void setSemanticScope(const QQmlJSScope::ConstPtr &scope) { m_semanticScope = scope; }
1133 QQmlJSScope::ConstPtr semanticScope() const { return m_semanticScope; }
1134 ScriptElementVariant nameIdentifiers() const { return m_nameIdentifiers; }
1135 void setNameIdentifiers(const ScriptElementVariant &name) { m_nameIdentifiers = name; }
1136
1137private:
1139 Path m_nextComponentPath;
1140 QMultiMap<QString, Id> m_ids;
1141 QQmlJSScope::ConstPtr m_semanticScope;
1142 // m_nameIdentifiers contains the name of the component as FieldMemberExpression, and therefore
1143 // only exists in inline components!
1144 ScriptElementVariant m_nameIdentifiers;
1145};
1146
1147class QMLDOM_EXPORT GlobalComponent final : public Component
1148{
1149public:
1151 DomType kind() const override { return kindValue; }
1152
1153 GlobalComponent(const Path &pathFromOwner = Path()) : Component(pathFromOwner) { }
1154};
1155
1157
1159{
1161public:
1163
1164 ImportScope() = default;
1165
1166 const QList<Path> &importSourcePaths() const & { return m_importSourcePaths; }
1167
1168 const QMap<QString, ImportScope> &subImports() const & { return m_subImports; }
1169
1170 QList<Path> allSources(const DomItem &self) const;
1171
1172 QSet<QString> importedNames(const DomItem &self) const
1173 {
1174 QSet<QString> res;
1175 const auto sources = allSources(self);
1176 for (const Path &p : sources) {
1177 QSet<QString> ks = self.path(p.withField(Fields::exports), self.errorHandler()).keys();
1178 res += ks;
1179 }
1180 return res;
1181 }
1182
1183 QList<DomItem> importedItemsWithName(const DomItem &self, const QString &name) const
1184 {
1185 QList<DomItem> res;
1186 const auto sources = allSources(self);
1187 for (const Path &p : sources) {
1188 DomItem source = self.path(p.withField(Fields::exports), self.errorHandler());
1189 DomItem els = source.key(name);
1190 int nEls = els.indexes();
1191 for (int i = 0; i < nEls; ++i)
1192 res.append(els.index(i));
1193 if (nEls == 0 && els) {
1194 self.addError(importErrors.warning(
1195 tr("Looking up '%1' expected a list of exports, not %2")
1196 .arg(name, els.toString())));
1197 }
1198 }
1199 return res;
1200 }
1201
1202 QList<Export> importedExportsWithName(const DomItem &self, const QString &name) const
1203 {
1204 QList<Export> res;
1205 for (const DomItem &i : importedItemsWithName(self, name))
1206 if (const Export *e = i.as<Export>())
1207 res.append(*e);
1208 else
1209 self.addError(importErrors.warning(
1210 tr("Expected Export looking up '%1', not %2").arg(name, i.toString())));
1211 return res;
1212 }
1213
1214 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
1215
1216 void addImport(const QStringList &p, const Path &targetExports)
1217 {
1218 if (!p.isEmpty())
1219 m_subImports[p.first()].addImport(p.mid(1), targetExports);
1220 else if (!m_importSourcePaths.contains(targetExports))
1221 m_importSourcePaths.append(targetExports);
1222 }
1223
1224private:
1225 QList<Path> m_importSourcePaths;
1226 QMap<QString, ImportScope> m_subImports;
1227};
1228
1230{
1231public:
1232 BindingValue();
1233 BindingValue(const QmlObject &o);
1234 BindingValue(const std::shared_ptr<ScriptExpression> &o);
1235 BindingValue(const QList<QmlObject> &l);
1236 ~BindingValue();
1237 BindingValue(const BindingValue &o);
1239
1240 DomItem value(const DomItem &binding) const;
1241 void updatePathFromOwner(const Path &newPath);
1242
1243private:
1244 friend class Binding;
1245 void clearValue();
1246
1247 BindingValueKind kind;
1248 union {
1253 };
1254};
1255
1256} // end namespace Dom
1257} // end namespace QQmlJS
1258QT_END_NAMESPACE
1259#endif // QQMLDOMELEMENTS_P_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 &
Path pathFromOwner() const override
DomElement(const Path &pathFromOwner=Path())
A value type that references any element of the Dom.
static ErrorGroup domErrorGroup
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
Represents a set of tags grouping a set of related error messages.
static Export fromString(const Path &source, QStringView exp, const Path &typePath, const ErrorHandler &h)
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
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
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
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
MutableDomItem(const DomItem &owner, const Path &pathFromOwner)
A DomItem that owns other DomItems and is managed through a shared pointer.
OwningItem(int derivedFrom=0)
PathEls::Kind Kind
static Path fromRoot(PathRoot r)
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 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)
void writeOutSortedEnumerations(const DomItem &component, OutWriter &ow) const
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
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
Keeps the comments associated with a DomItem.
Use this to contain any script element.
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
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.
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)
bool operator==(Version v1, Version v2)
std::disjunction< std::is_same< U, V >... > IsInList
bool operator<(Version v1, Version v2)
bool operator<=(Version v1, Version v2)
bool operator!=(Version v1, Version v2)
bool operator>=(Version v1, Version v2)
bool visitWithCustomListIteration(T *t, AST::Visitor *visitor)
std::function< void(const ErrorMessage &)> ErrorHandler
static ErrorGroups importErrors
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
#define QMLDOM_EXPORT
#define Q_SCRIPTELEMENT_EXIT_IF(check)
#define Q_SCRIPTELEMENT_DISABLE()
#define NewErrorGroup(name)