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.invokeVisitorOnField(visitor, Fields::import, import);
327 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::inheritVersion),
329 return cont;
330 }
331
332 friend bool operator==(const ModuleAutoExport &i1, const ModuleAutoExport &i2)
333 {
334 return i1.import == i2.import && i1.inheritVersion == i2.inheritVersion;
335 }
336 friend bool operator!=(const ModuleAutoExport &i1, const ModuleAutoExport &i2)
337 {
338 return !(i1 == i2);
339 }
340
342 bool inheritVersion = false;
343};
344
346{
347public:
349
350 Pragma(const QString &pragmaName = QString(), const QStringList &pragmaValues = {})
352 {
353 }
354
355 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
356 {
357 bool cont = self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::name), name);
358 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::values), values);
359 cont = cont && self.invokeVisitorOnField(visitor, Fields::comments, comments);
360 return cont;
361 }
362
363 void writeOut(const DomItem &self, OutWriter &ow) const;
364
368};
369
371{
372public:
373 constexpr static DomType kindValue = DomType::Id;
374
375 Id(const QString &idName = QString(), const Path &referredObject = Path());
376
377 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const;
378 void updatePathFromOwner(const Path &pathFromOwner);
379 Path addAnnotation(const Path &selfPathFromOwner, const QmlObject &ann, QmlObject **aPtr = nullptr);
380
386};
387
388// TODO: rename? it may contain statements and stuff, not only expressions
389// TODO QTBUG-121933
391{
392 Q_GADGET
393 Q_DECLARE_TR_FUNCTIONS(ScriptExpression)
394public:
395 enum class ExpressionType {
401 JSCode, // Used for storing the content of the whole .js file as "one" Expression
402 ESMCode, // Used for storing the content of the whole ECMAScript module (.mjs) as "one"
403 // Expression
404 };
407 DomType kind() const override { return kindValue; }
408
409 explicit ScriptExpression(QStringView code, const std::shared_ptr<QQmlJS::Engine> &engine,
410 AST::Node *ast, const std::shared_ptr<AstComments> &comments,
411 ExpressionType expressionType,
412 const SourceLocation &localOffset = SourceLocation());
413
420
421 explicit ScriptExpression(const QString &code, ExpressionType expressionType)
423 {
424 setCode(code);
425 }
426
428
429 std::shared_ptr<ScriptExpression> makeCopy(const DomItem &self) const
430 {
431 return std::static_pointer_cast<ScriptExpression>(doCopy(self));
432 }
433
434 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override;
435
436 Path canonicalPath(const DomItem &self) const override { return self.m_ownerPath; }
437 // parsed and created if not available
438 AST::Node *ast() const { return m_ast; }
439 // dump of the ast (without locations)
440 void astDumper(const Sink &s, AstDumperOptions options) const;
442
443 // definedSymbols name, value, from
444 // usedSymbols name, locations
446 {
447 QMutexLocker l(mutex());
448 return m_code;
449 }
450
452 {
453 QMutexLocker l(mutex());
454 return m_expressionType;
455 }
456
457 bool isNull() const
458 {
459 QMutexLocker l(mutex());
460 return m_code.isNull();
461 }
463 {
464 QMutexLocker l(mutex());
465 return m_engine;
466 }
467 QStringView loc2Str(const SourceLocation &) const;
468 std::shared_ptr<AstComments> astComments() const { return m_astComments; }
469 void writeOut(const DomItem &self, OutWriter &lw) const override;
470 SourceLocation globalLocation(const DomItem &self) const;
471 SourceLocation localOffset() const { return m_localOffset; }
473 ScriptElementVariant scriptElement() { return m_element; }
474
475protected:
476 std::shared_ptr<OwningItem> doCopy(const DomItem &) const override
477 {
478 return std::make_shared<ScriptExpression>(*this);
479 }
480
481 SourceLocation locationToLocal(const SourceLocation &x) const
482 {
483 return SourceLocation(
484 x.offset - m_localOffset.offset, x.length, x.startLine - m_localOffset.startLine,
485 ((x.startLine == m_localOffset.startLine)
486 ? x.startColumn - m_localOffset.startColumn
487 : x.startColumn)); // are line and column 1 based? then we should + 1
488 }
489
490private:
491 void setCode(const QString &code);
492 [[nodiscard]] AST::Node *parse();
493
494 ExpressionType m_expressionType;
495 QString m_codeStr;
496 QStringView m_code;
497 mutable std::shared_ptr<QQmlJS::Engine> m_engine;
498 mutable AST::Node *m_ast;
499 std::shared_ptr<AstComments> m_astComments;
500 SourceLocation m_localOffset;
501 ScriptElementVariant m_element;
502};
503
504class BindingValue;
505
507{
508public:
510
511 Binding(const QString &m_name = QString());
512 Binding(const QString &m_name, std::unique_ptr<BindingValue> &&value,
513 BindingType bindingType = BindingType::Normal);
514 Binding(const QString &m_name, const std::shared_ptr<ScriptExpression> &value,
515 BindingType bindingType = BindingType::Normal);
516 Binding(const QString &m_name, const QString &scriptCode,
517 BindingType bindingType = BindingType::Normal);
518 Binding(const QString &m_name, const QmlObject &value,
519 BindingType bindingType = BindingType::Normal);
520 Binding(const QString &m_name, const QList<QmlObject> &value,
521 BindingType bindingType = BindingType::Normal);
522 Binding(const Binding &o);
523 Binding(Binding &&o) = default;
524 ~Binding();
525 Binding &operator=(const Binding &);
526 Binding &operator=(Binding &&) = default;
527
528 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const;
529 DomItem valueItem(const DomItem &self) const; // ### REVISIT: consider replacing return value with variant
531 QString name() const { return m_name; }
532 BindingType bindingType() const { return m_bindingType; }
533 QmlObject const *objectValue() const;
534 QList<QmlObject> const *arrayValue() const;
535 std::shared_ptr<ScriptExpression> scriptExpressionValue() const;
539 QList<QmlObject> annotations() const { return m_annotations; }
540 void setAnnotations(const QList<QmlObject> &annotations) { m_annotations = annotations; }
541 void setValue(std::unique_ptr<BindingValue> &&value);
542 Path addAnnotation(const Path &selfPathFromOwner, const QmlObject &a, QmlObject **aPtr = nullptr);
543 const RegionComments &comments() const { return m_comments; }
544 RegionComments &comments() { return m_comments; }
545 void updatePathFromOwner(const Path &newPath);
546 void writeOut(const DomItem &self, OutWriter &lw) const;
547 void writeOutValue(const DomItem &self, OutWriter &lw) const;
548 bool isSignalHandler() const
549 {
550 QString baseName = m_name.split(QLatin1Char('.')).last();
551 return QQmlSignalNames::isHandlerName(baseName);
552 }
553 static QString preCodeForName(QStringView n)
554 {
555 return QStringLiteral(u"QtObject{\n %1: ").arg(n.split(u'.').last());
556 }
557 static QString postCodeForName(QStringView) { return QStringLiteral(u"\n}\n"); }
558 QString preCode() const { return preCodeForName(m_name); }
559 QString postCode() const { return postCodeForName(m_name); }
560
561 ScriptElementVariant bindingIdentifiers() const { return m_bindingIdentifiers; }
562 void setBindingIdentifiers(const ScriptElementVariant &bindingIdentifiers) { m_bindingIdentifiers = bindingIdentifiers; }
563
564private:
566 BindingType m_bindingType;
567 QString m_name;
568 std::unique_ptr<BindingValue> m_value;
569 QList<QmlObject> m_annotations;
570 RegionComments m_comments;
571 ScriptElementVariant m_bindingIdentifiers;
572};
573
575{
576public:
578
579 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
580
581 Path addAnnotation(const Path &selfPathFromOwner, const QmlObject &annotation,
582 QmlObject **aPtr = nullptr);
583 void updatePathFromOwner(const Path &newPath);
584
585 QQmlJSScope::ConstPtr semanticScope() const { return m_semanticScope; }
586 void setSemanticScope(const QQmlJSScope::ConstPtr &scope) { m_semanticScope = scope; }
587
591 bool isReadonly = false;
592 bool isList = false;
596};
597
618
620{
621public:
623
624 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
625 {
626 bool cont = AttributeInfo::iterateDirectSubpaths(self, visitor);
627 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::isPointer), isPointer);
628 // virtual and override don't need to be accessed through DomItem API for now
629 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::isFinal), isFinal);
630 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::isAlias), isAlias());
631 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::isDefaultMember),
633 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::isRequired),
634 isRequired);
635 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::read), read);
636 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::write), write);
637 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::bindable), bindable);
638 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::notify), notify);
639 cont = cont && self.invokeVisitorOnReference(visitor, Fields::type, typePath());
640 if (m_nameIdentifiers) {
641 cont = cont && visitor(PathEls::Field(Fields::nameIdentifiers), [this, &self]() {
642 return self.subScriptElementWrapperItem(m_nameIdentifiers);
643 });
644 }
645 return cont;
646 }
647
648 Path typePath() const { return Paths::lookupTypePath(typeName); }
649
650 bool isAlias() const { return typeName == u"alias"; }
651 bool isParametricType() const;
652 void writeOut(const DomItem &self, OutWriter &lw) const;
653 ScriptElementVariant nameIdentifiers() const { return m_nameIdentifiers; }
654 void setNameIdentifiers(const ScriptElementVariant &name) { m_nameIdentifiers = name; }
655
660 bool isVirtual = false;
661 bool isOverride = false;
662 bool isFinal = false;
663 bool isPointer = false;
664 bool isDefaultMember = false;
665 bool isRequired = false;
667};
668
670{
671public:
672 constexpr static DomType kindValue = DomType::PropertyInfo; // used to get the correct kind in ObjectWrapper
673
674 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
675
678};
679
681{
682public:
685 Prefix, // a(int x)
686 Suffix, // a(x : int)
687 };
688 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
689
690 void writeOut(const DomItem &self, OutWriter &ow) const;
691 void writeOutSignal(const DomItem &self, OutWriter &ow) const;
692
695 bool isPointer = false;
696 bool isReadonly = false;
697 bool isList = false;
698 bool isRestElement = false;
700 /*!
701 \internal
702 Contains the scriptElement representing this argument, inclusive default value,
703 deconstruction, etc.
704 */
709};
710
711// TODO (QTBUG-128423)
712// Refactor to differentiate between Signals and Methods easily,
713// considering their distinct handling and formatting needs.
714// Explore separating Signal functionality or unifying shared methods.
716{
718public:
720 Q_ENUM(MethodType)
721
722 constexpr static DomType kindValue = DomType::MethodInfo;
723
724 Path typePath(const DomItem &) const
725 {
726 return (typeName.isEmpty() ? Path() : Paths::lookupTypePath(typeName));
727 }
728
729 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
730 void writePre(const DomItem &self, OutWriter &ow) const;
731 void writeOut(const DomItem &self, OutWriter &ow) const;
732 QString signature(const DomItem &self) const;
733
734 MethodInfo() = default;
735
736 // TODO: make private + add getters/setters
741 bool isConstructor = false;
742
743private:
744 void writeOutArguments(const DomItem &self, OutWriter &ow) const;
745 void writeOutReturnType(const DomItem &self, OutWriter &ow) const;
746 void writeOutBody(const DomItem &self, OutWriter &ow) const;
747};
748
750{
751public:
757 EnumItem(const QString &name = QString(), int value = 0, ValueKind valueKind = ValueKind::ImplicitValue)
758 : m_name(name), m_value(value), m_valueKind(valueKind)
759 {
760 }
761
762 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
763
764 QString name() const { return m_name; }
765 double value() const { return m_value; }
766 RegionComments &comments() { return m_comments; }
767 const RegionComments &comments() const { return m_comments; }
768 void writeOut(const DomItem &self, OutWriter &lw) const;
769
770private:
771 QString m_name;
772 double m_value;
773 ValueKind m_valueKind;
774 RegionComments m_comments;
775};
776
777class QMLDOM_EXPORT EnumDecl final : public CommentableDomElement
778{
779public:
781 DomType kind() const override { return kindValue; }
782
783 EnumDecl(const QString &name = QString(), const QList<EnumItem> &values = QList<EnumItem>(),
784 const Path &pathFromOwner = Path())
786 {
787 }
788
789 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override;
790
791 QString name() const { return m_name; }
792 void setName(const QString &name) { m_name = name; }
793 const QList<EnumItem> &values() const & { return m_values; }
794 bool isFlag() const { return m_isFlag; }
795 void setIsFlag(bool flag) { m_isFlag = flag; }
796 QString alias() const { return m_alias; }
797 void setAlias(const QString &aliasName) { m_alias = aliasName; }
798 void setValues(const QList<EnumItem> &values) { m_values = values; }
799 Path addValue(const EnumItem &value)
800 {
801 m_values.append(value);
802 return Path::fromField(Fields::values).withIndex(index_type(m_values.size() - 1));
803 }
804 void updatePathFromOwner(const Path &newP) override;
805
806 const QList<QmlObject> &annotations() const & { return m_annotations; }
807 void setAnnotations(const QList<QmlObject> &annotations);
808 Path addAnnotation(const QmlObject &child, QmlObject **cPtr = nullptr);
809 void writeOut(const DomItem &self, OutWriter &lw) const override;
810
811private:
812 QString m_name;
813 bool m_isFlag = false;
814 QString m_alias;
815 QList<EnumItem> m_values;
816 QList<QmlObject> m_annotations;
817};
818
820{
822public:
823 constexpr static DomType kindValue = DomType::QmlObject;
824 DomType kind() const override { return kindValue; }
825
826 QmlObject(const Path &pathFromOwner = Path());
827 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
828 bool iterateBaseDirectSubpaths(const DomItem &self, DirectVisitor) const;
829 QList<QString> fields() const;
830 QList<QString> fields(const DomItem &) const override { return fields(); }
831 DomItem field(const DomItem &self, QStringView name) const override;
832 void updatePathFromOwner(const Path &newPath) override;
834 QString defaultPropertyName(const DomItem &self) const;
835 bool iterateSubOwners(const DomItem &self,
836 function_ref<bool(const DomItem &owner)> visitor) const;
837
838 QString idStr() const { return m_idStr; }
839 QString name() const { return m_name; }
840 const QList<Path> &prototypePaths() const & { return m_prototypePaths; }
841 Path nextScopePath() const { return m_nextScopePath; }
842 const QMultiMap<QString, PropertyDefinition> &propertyDefs() const & { return m_propertyDefs; }
843 const QMultiMap<QString, Binding> &bindings() const & { return m_bindings; }
844 const QMultiMap<QString, MethodInfo> &methods() const & { return m_methods; }
845 QList<QmlObject> children() const { return m_children; }
846 QList<QmlObject> annotations() const { return m_annotations; }
847
848 void setIdStr(const QString &id) { m_idStr = id; }
849 void setName(const QString &name) { m_name = name; }
850 void setDefaultPropertyName(const QString &name) { m_defaultPropertyName = name; }
851 void setPrototypePaths(const QList<Path> &prototypePaths) { m_prototypePaths = prototypePaths; }
852 Path addPrototypePath(const Path &prototypePath)
853 {
854 index_type idx = index_type(m_prototypePaths.indexOf(prototypePath));
855 if (idx == -1) {
856 idx = index_type(m_prototypePaths.size());
857 m_prototypePaths.append(prototypePath);
858 }
859 return Path::fromField(Fields::prototypes).withIndex(idx);
860 }
861 void setNextScopePath(const Path &nextScopePath) { m_nextScopePath = nextScopePath; }
862 void setPropertyDefs(const QMultiMap<QString, PropertyDefinition> &propertyDefs)
863 {
864 m_propertyDefs = propertyDefs;
865 }
866 void setBindings(const QMultiMap<QString, Binding> &bindings) { m_bindings = bindings; }
867 void setMethods(const QMultiMap<QString, MethodInfo> &functionDefs)
868 {
869 m_methods = functionDefs;
870 }
871 void setChildren(const QList<QmlObject> &children)
872 {
873 m_children = children;
874 if (pathFromOwner())
876 }
877 void setAnnotations(const QList<QmlObject> &annotations)
878 {
879 m_annotations = annotations;
880 if (pathFromOwner())
882 }
884 PropertyDefinition **pDef = nullptr)
885 {
886 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::propertyDefs),
887 m_propertyDefs, propertyDef.name, propertyDef,
888 option, pDef);
889 }
891 AddOption option);
892
893 Path addBinding(const Binding &binding, AddOption option, Binding **bPtr = nullptr)
894 {
895 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::bindings), m_bindings,
896 binding.name(), binding, option, bPtr);
897 }
898 MutableDomItem addBinding(MutableDomItem &self, const Binding &binding, AddOption option);
899 Path addMethod(const MethodInfo &functionDef, AddOption option, MethodInfo **mPtr = nullptr)
900 {
901 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::methods), m_methods,
902 functionDef.name, functionDef, option, mPtr);
903 }
904 MutableDomItem addMethod(MutableDomItem &self, const MethodInfo &functionDef, AddOption option);
905 Path addChild(const QmlObject &child, QmlObject **cPtr = nullptr)
906 {
907 return appendUpdatableElementInQList(pathFromOwner().withField(Fields::children), m_children,
908 child, cPtr);
909 }
911 {
912 Path p = addChild(child);
914 }
915 Path addAnnotation(const QmlObject &annotation, QmlObject **aPtr = nullptr)
916 {
917 return appendUpdatableElementInQList(pathFromOwner().withField(Fields::annotations),
918 m_annotations, annotation, aPtr);
919 }
920
922 const DomItem &component) const;
923 void writeOutAttributes(const DomItem &self, OutWriter &ow, const DomItem &component,
924 const QString &code) const;
925
926 void writeOutSortedEnumerations(const QList<DomItem> &descs, OutWriter &ow) const;
927 void writeOutSortedAttributes(const DomItem &self, OutWriter &ow,
928 const DomItem &component) const;
929 void writeOutSortedPropertyDefinition(const DomItem &self, OutWriter &ow,
930 QSet<QString> &mergedDefBinding,
931 const QStringList &keys) const;
932
933 void writeOutId(const DomItem &self, OutWriter &ow) const;
934 void writeOut(const DomItem &self, OutWriter &ow, const QString &onTarget) const;
935 void writeOut(const DomItem &self, OutWriter &lw) const override { writeOut(self, lw, QString()); }
936
938 std::shared_ptr<ScriptExpression> accessSequence) const;
939 LocallyResolvedAlias resolveAlias(const DomItem &self, const QStringList &accessSequence) const;
940
941 QQmlJSScope::ConstPtr semanticScope() const { return m_scope; }
942 void setSemanticScope(const QQmlJSScope::ConstPtr &scope) { m_scope = scope; }
943
944 ScriptElementVariant nameIdentifiers() const { return m_nameIdentifiers; }
945 void setNameIdentifiers(const ScriptElementVariant &name) { m_nameIdentifiers = name; }
946
947private:
949 QString m_idStr;
950 QString m_name;
951 QList<Path> m_prototypePaths;
952 Path m_nextScopePath;
953 QString m_defaultPropertyName;
954 QMultiMap<QString, PropertyDefinition> m_propertyDefs;
955 QMultiMap<QString, Binding> m_bindings;
956 QMultiMap<QString, MethodInfo> m_methods;
957 QList<QmlObject> m_children;
958 QList<QmlObject> m_annotations;
959 QQmlJSScope::ConstPtr m_scope;
960 ScriptElementVariant m_nameIdentifiers;
961
962 static constexpr quint32 posOfNewElements = std::numeric_limits<quint32>::max();
963};
964
966{
968public:
969 constexpr static DomType kindValue = DomType::Export;
970 static Export fromString(
971 const Path &source, QStringView exp, const Path &typePath, const ErrorHandler &h);
972 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
973 {
974 bool cont = true;
975 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::uri), uri);
976 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::typeName), typeName);
977 cont = cont && self.invokeVisitorOnField(visitor, Fields::version, version);
978 if (typePath)
979 cont = cont && self.invokeVisitorOnReference(visitor, Fields::type, typePath);
980 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::isInternal),
981 isInternal);
982 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::isSingleton),
984 if (exportSourcePath)
985 cont = cont && self.invokeVisitorOnReference(visitor, Fields::exportSource,
986 exportSourcePath);
987 return cont;
988 }
989
995 bool isInternal = false;
996 bool isSingleton = false;
997};
998
1000{
1001public:
1002 Component(const QString &name);
1003 Component(const Path &pathFromOwner = Path());
1004 Component(const Component &o) = default;
1005 Component &operator=(const Component &) = default;
1006
1007 bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override;
1008 void updatePathFromOwner(const Path &newPath) override;
1009 DomItem field(const DomItem &self, QStringView name) const override;
1010
1011 QString name() const { return m_name; }
1012 const QMultiMap<QString, EnumDecl> &enumerations() const & { return m_enumerations; }
1013 const QList<QmlObject> &objects() const & { return m_objects; }
1014 bool isSingleton() const { return m_isSingleton; }
1015 bool isCreatable() const { return m_isCreatable; }
1016 bool isComposite() const { return m_isComposite; }
1017 QString attachedTypeName() const { return m_attachedTypeName; }
1018 Path attachedTypePath(const DomItem &) const { return m_attachedTypePath; }
1019
1020 void setName(const QString &name) { m_name = name; }
1021 void setEnumerations(const QMultiMap<QString, EnumDecl> &enumerations)
1022 {
1023 m_enumerations = enumerations;
1024 }
1025 Path addEnumeration(const EnumDecl &enumeration, AddOption option = AddOption::Overwrite,
1026 EnumDecl **ePtr = nullptr)
1027 {
1028 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::enumerations),
1029 m_enumerations, enumeration.name(), enumeration,
1030 option, ePtr);
1031 }
1032 void setObjects(const QList<QmlObject> &objects) { m_objects = objects; }
1033 Path addObject(const QmlObject &object, QmlObject **oPtr = nullptr);
1034 void setIsSingleton(bool isSingleton) { m_isSingleton = isSingleton; }
1035 void setIsCreatable(bool isCreatable) { m_isCreatable = isCreatable; }
1036 void setIsComposite(bool isComposite) { m_isComposite = isComposite; }
1037 void setAttachedTypeName(const QString &name) { m_attachedTypeName = name; }
1038 void setAttachedTypePath(const Path &p) { m_attachedTypePath = p; }
1039
1040private:
1042 QString m_name;
1043 QMultiMap<QString, EnumDecl> m_enumerations;
1044 QList<QmlObject> m_objects;
1045 bool m_isSingleton = false;
1046 bool m_isCreatable = true;
1047 bool m_isComposite = true;
1048 QString m_attachedTypeName;
1049 Path m_attachedTypePath;
1050};
1051
1052class QMLDOM_EXPORT JsResource final : public Component
1053{
1054public:
1056 DomType kind() const override { return kindValue; }
1057
1058 JsResource(const Path &pathFromOwner = Path()) : Component(pathFromOwner) { }
1059 bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override
1060 { // to do: complete
1061 return true;
1062 }
1063 // globalSymbols defined/exported, required/used
1064};
1065
1066class QMLDOM_EXPORT QmltypesComponent final : public Component
1067{
1068public:
1070 DomType kind() const override { return kindValue; }
1071
1072 QmltypesComponent(const Path &pathFromOwner = Path()) : Component(pathFromOwner) { }
1073 bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override;
1074 const QList<Export> &exports() const & { return m_exports; }
1075 QString fileName() const { return m_fileName; }
1076 void setExports(const QList<Export> &exports) { m_exports = exports; }
1077 void addExport(const Export &exportedEntry) { m_exports.append(exportedEntry); }
1078 void setFileName(const QString &fileName) { m_fileName = fileName; }
1079 const QList<int> &metaRevisions() const & { return m_metaRevisions; }
1080 void setMetaRevisions(const QList<int> &metaRevisions) { m_metaRevisions = metaRevisions; }
1081 void setInterfaceNames(const QStringList& interfaces) { m_interfaceNames = interfaces; }
1082 const QStringList &interfaceNames() const & { return m_interfaceNames; }
1083 QString extensionTypeName() const { return m_extensionTypeName; }
1084 void setExtensionTypeName(const QString &name) { m_extensionTypeName = name; }
1085 QString elementTypeName() const { return m_elementTypeName; }
1086 void setElementTypeName(const QString &name) { m_elementTypeName = name; }
1087 bool hasCustomParser() const { return m_hasCustomParser; }
1088 void setHasCustomParser(bool v) { m_hasCustomParser = v; }
1089 bool extensionIsJavaScript() const { return m_extensionIsJavaScript; }
1090 void setExtensionIsJavaScript(bool v) { m_extensionIsJavaScript = v; }
1091 bool extensionIsNamespace() const { return m_extensionIsNamespace; }
1092 void setExtensionIsNamespace(bool v) { m_extensionIsNamespace = v; }
1093 QQmlJSScope::AccessSemantics accessSemantics() const { return m_accessSemantics; }
1094 void setAccessSemantics(QQmlJSScope::AccessSemantics v) { m_accessSemantics = v; }
1095
1096 void setSemanticScope(const QQmlJSScope::ConstPtr &scope) { m_semanticScope = scope; }
1097 QQmlJSScope::ConstPtr semanticScope() const { return m_semanticScope; }
1098
1099private:
1100 QList<Export> m_exports;
1101 QList<int> m_metaRevisions;
1102 QString m_fileName; // remove?
1103 QStringList m_interfaceNames;
1104 bool m_hasCustomParser = false;
1105 bool m_extensionIsJavaScript = false;
1106 bool m_extensionIsNamespace = false;
1107 QString m_elementTypeName;
1108 QString m_extensionTypeName;
1109 QQmlJSScope::AccessSemantics m_accessSemantics = QQmlJSScope::AccessSemantics::None;
1110 QQmlJSScope::ConstPtr m_semanticScope;
1111};
1112
1113class QMLDOM_EXPORT QmlComponent final : public Component
1114{
1115public:
1117 DomType kind() const override { return kindValue; }
1118
1119 QmlComponent(const QString &name = QString()) : Component(name)
1120 {
1121 setIsComposite(true);
1122 setIsCreatable(true);
1123 }
1124
1125 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
1126
1127 const QMultiMap<QString, Id> &ids() const & { return m_ids; }
1128 Path nextComponentPath() const { return m_nextComponentPath; }
1129 void setIds(const QMultiMap<QString, Id> &ids) { m_ids = ids; }
1130 void setNextComponentPath(const Path &p) { m_nextComponentPath = p; }
1131 void updatePathFromOwner(const Path &newPath) override;
1132 Path addId(const Id &id, AddOption option = AddOption::Overwrite, Id **idPtr = nullptr)
1133 {
1134 // warning does nor remove old idStr when overwriting...
1135 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::ids), m_ids, id.name,
1136 id, option, idPtr);
1137 }
1138 void writeOut(const DomItem &self, OutWriter &) const override;
1139 QList<QString> subComponentsNames(const DomItem &self) const;
1140 QList<DomItem> subComponents(const DomItem &self) const;
1141
1142 void setSemanticScope(const QQmlJSScope::ConstPtr &scope) { m_semanticScope = scope; }
1143 QQmlJSScope::ConstPtr semanticScope() const { return m_semanticScope; }
1144 ScriptElementVariant nameIdentifiers() const { return m_nameIdentifiers; }
1145 void setNameIdentifiers(const ScriptElementVariant &name) { m_nameIdentifiers = name; }
1146
1147private:
1149 Path m_nextComponentPath;
1150 QMultiMap<QString, Id> m_ids;
1151 QQmlJSScope::ConstPtr m_semanticScope;
1152 // m_nameIdentifiers contains the name of the component as FieldMemberExpression, and therefore
1153 // only exists in inline components!
1154 ScriptElementVariant m_nameIdentifiers;
1155};
1156
1157class QMLDOM_EXPORT GlobalComponent final : public Component
1158{
1159public:
1161 DomType kind() const override { return kindValue; }
1162
1163 GlobalComponent(const Path &pathFromOwner = Path()) : Component(pathFromOwner) { }
1164};
1165
1167
1169{
1171public:
1173
1174 ImportScope() = default;
1175
1176 const QList<Path> &importSourcePaths() const & { return m_importSourcePaths; }
1177
1178 const QMap<QString, ImportScope> &subImports() const & { return m_subImports; }
1179
1180 QList<Path> allSources(const DomItem &self) const;
1181
1182 QSet<QString> importedNames(const DomItem &self) const
1183 {
1184 QSet<QString> res;
1185 const auto sources = allSources(self);
1186 for (const Path &p : sources) {
1187 QSet<QString> ks = self.path(p.withField(Fields::exports), self.errorHandler()).keys();
1188 res += ks;
1189 }
1190 return res;
1191 }
1192
1193 QList<DomItem> importedItemsWithName(const DomItem &self, const QString &name) const
1194 {
1195 QList<DomItem> res;
1196 const auto sources = allSources(self);
1197 for (const Path &p : sources) {
1198 DomItem source = self.path(p.withField(Fields::exports), self.errorHandler());
1199 DomItem els = source.key(name);
1200 int nEls = els.indexes();
1201 for (int i = 0; i < nEls; ++i)
1202 res.append(els.index(i));
1203 if (nEls == 0 && els) {
1204 self.addError(importErrors.warning(
1205 tr("Looking up '%1' expected a list of exports, not %2")
1206 .arg(name, els.toString())));
1207 }
1208 }
1209 return res;
1210 }
1211
1212 QList<Export> importedExportsWithName(const DomItem &self, const QString &name) const
1213 {
1214 QList<Export> res;
1215 for (const DomItem &i : importedItemsWithName(self, name))
1216 if (const Export *e = i.as<Export>())
1217 res.append(*e);
1218 else
1219 self.addError(importErrors.warning(
1220 tr("Expected Export looking up '%1', not %2").arg(name, i.toString())));
1221 return res;
1222 }
1223
1224 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
1225
1226 void addImport(const QStringList &p, const Path &targetExports)
1227 {
1228 if (!p.isEmpty())
1229 m_subImports[p.first()].addImport(p.mid(1), targetExports);
1230 else if (!m_importSourcePaths.contains(targetExports))
1231 m_importSourcePaths.append(targetExports);
1232 }
1233
1234private:
1235 QList<Path> m_importSourcePaths;
1236 QMap<QString, ImportScope> m_subImports;
1237};
1238
1240{
1241public:
1242 BindingValue();
1243 BindingValue(const QmlObject &o);
1244 BindingValue(const std::shared_ptr<ScriptExpression> &o);
1245 BindingValue(const QList<QmlObject> &l);
1246 ~BindingValue();
1247 BindingValue(const BindingValue &o);
1249
1250 DomItem value(const DomItem &binding) const;
1251 void updatePathFromOwner(const Path &newPath);
1252
1253private:
1254 friend class Binding;
1255 void clearValue();
1256
1257 BindingValueKind kind;
1258 union {
1263 };
1264};
1265
1266} // end namespace Dom
1267} // end namespace QQmlJS
1268QT_END_NAMESPACE
1269#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 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
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.
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)
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
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)