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 bool isGenerator = false;
743
744private:
745 void writeOutArguments(const DomItem &self, OutWriter &ow) const;
746 void writeOutReturnType(const DomItem &self, OutWriter &ow) const;
747 void writeOutBody(const DomItem &self, OutWriter &ow) const;
748};
749
751{
752public:
758 EnumItem(const QString &name = QString(), int value = 0, ValueKind valueKind = ValueKind::ImplicitValue)
759 : m_name(name), m_value(value), m_valueKind(valueKind)
760 {
761 }
762
763 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
764
765 QString name() const { return m_name; }
766 double value() const { return m_value; }
767 RegionComments &comments() { return m_comments; }
768 const RegionComments &comments() const { return m_comments; }
769 void writeOut(const DomItem &self, OutWriter &lw) const;
770
771private:
772 QString m_name;
773 double m_value;
774 ValueKind m_valueKind;
775 RegionComments m_comments;
776};
777
778class QMLDOM_EXPORT EnumDecl final : public CommentableDomElement
779{
780public:
782 DomType kind() const override { return kindValue; }
783
784 EnumDecl(const QString &name = QString(), const QList<EnumItem> &values = QList<EnumItem>(),
785 const Path &pathFromOwner = Path())
787 {
788 }
789
790 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override;
791
792 QString name() const { return m_name; }
793 void setName(const QString &name) { m_name = name; }
794 const QList<EnumItem> &values() const & { return m_values; }
795 bool isFlag() const { return m_isFlag; }
796 void setIsFlag(bool flag) { m_isFlag = flag; }
797 QString alias() const { return m_alias; }
798 void setAlias(const QString &aliasName) { m_alias = aliasName; }
799 void setValues(const QList<EnumItem> &values) { m_values = values; }
800 Path addValue(const EnumItem &value)
801 {
802 m_values.append(value);
803 return Path::fromField(Fields::values).withIndex(index_type(m_values.size() - 1));
804 }
805 void updatePathFromOwner(const Path &newP) override;
806
807 const QList<QmlObject> &annotations() const & { return m_annotations; }
808 void setAnnotations(const QList<QmlObject> &annotations);
809 Path addAnnotation(const QmlObject &child, QmlObject **cPtr = nullptr);
810 void writeOut(const DomItem &self, OutWriter &lw) const override;
811
812private:
813 QString m_name;
814 bool m_isFlag = false;
815 QString m_alias;
816 QList<EnumItem> m_values;
817 QList<QmlObject> m_annotations;
818};
819
821{
823public:
824 constexpr static DomType kindValue = DomType::QmlObject;
825 DomType kind() const override { return kindValue; }
826
827 QmlObject(const Path &pathFromOwner = Path());
828 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
829 bool iterateBaseDirectSubpaths(const DomItem &self, DirectVisitor) const;
830 QList<QString> fields() const;
831 QList<QString> fields(const DomItem &) const override { return fields(); }
832 DomItem field(const DomItem &self, QStringView name) const override;
833 void updatePathFromOwner(const Path &newPath) override;
835 QString defaultPropertyName(const DomItem &self) const;
836 bool iterateSubOwners(const DomItem &self,
837 function_ref<bool(const DomItem &owner)> visitor) const;
838
839 QString idStr() const { return m_idStr; }
840 QString name() const { return m_name; }
841 const QList<Path> &prototypePaths() const & { return m_prototypePaths; }
842 Path nextScopePath() const { return m_nextScopePath; }
843 const QMultiMap<QString, PropertyDefinition> &propertyDefs() const & { return m_propertyDefs; }
844 const QMultiMap<QString, Binding> &bindings() const & { return m_bindings; }
845 const QMultiMap<QString, MethodInfo> &methods() const & { return m_methods; }
846 QList<QmlObject> children() const { return m_children; }
847 QList<QmlObject> annotations() const { return m_annotations; }
848
849 void setIdStr(const QString &id) { m_idStr = id; }
850 void setName(const QString &name) { m_name = name; }
851 void setDefaultPropertyName(const QString &name) { m_defaultPropertyName = name; }
852 void setPrototypePaths(const QList<Path> &prototypePaths) { m_prototypePaths = prototypePaths; }
853 Path addPrototypePath(const Path &prototypePath)
854 {
855 index_type idx = index_type(m_prototypePaths.indexOf(prototypePath));
856 if (idx == -1) {
857 idx = index_type(m_prototypePaths.size());
858 m_prototypePaths.append(prototypePath);
859 }
860 return Path::fromField(Fields::prototypes).withIndex(idx);
861 }
862 void setNextScopePath(const Path &nextScopePath) { m_nextScopePath = nextScopePath; }
863 void setPropertyDefs(const QMultiMap<QString, PropertyDefinition> &propertyDefs)
864 {
865 m_propertyDefs = propertyDefs;
866 }
867 void setBindings(const QMultiMap<QString, Binding> &bindings) { m_bindings = bindings; }
868 void setMethods(const QMultiMap<QString, MethodInfo> &functionDefs)
869 {
870 m_methods = functionDefs;
871 }
872 void setChildren(const QList<QmlObject> &children)
873 {
874 m_children = children;
875 if (pathFromOwner())
877 }
878 void setAnnotations(const QList<QmlObject> &annotations)
879 {
880 m_annotations = annotations;
881 if (pathFromOwner())
883 }
885 PropertyDefinition **pDef = nullptr)
886 {
887 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::propertyDefs),
888 m_propertyDefs, propertyDef.name, propertyDef,
889 option, pDef);
890 }
892 AddOption option);
893
894 Path addBinding(const Binding &binding, AddOption option, Binding **bPtr = nullptr)
895 {
896 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::bindings), m_bindings,
897 binding.name(), binding, option, bPtr);
898 }
899 MutableDomItem addBinding(MutableDomItem &self, const Binding &binding, AddOption option);
900 Path addMethod(const MethodInfo &functionDef, AddOption option, MethodInfo **mPtr = nullptr)
901 {
902 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::methods), m_methods,
903 functionDef.name, functionDef, option, mPtr);
904 }
905 MutableDomItem addMethod(MutableDomItem &self, const MethodInfo &functionDef, AddOption option);
906 Path addChild(const QmlObject &child, QmlObject **cPtr = nullptr)
907 {
908 return appendUpdatableElementInQList(pathFromOwner().withField(Fields::children), m_children,
909 child, cPtr);
910 }
912 {
913 Path p = addChild(child);
915 }
916 Path addAnnotation(const QmlObject &annotation, QmlObject **aPtr = nullptr)
917 {
918 return appendUpdatableElementInQList(pathFromOwner().withField(Fields::annotations),
919 m_annotations, annotation, aPtr);
920 }
921
923 const DomItem &component) const;
925 void writeOutAttributes(OutWriter &ow, const Attributes &attribs, const QString &code) const;
926
927 void writeOutSortedEnumerations(const QList<DomItem> &descs, OutWriter &ow) const;
928 void writeOutSortedAttributes(const DomItem &self, OutWriter &ow, const DomItem &component,
929 const Attributes &attribs) const;
930 void writeOutSortedPropertyDefinition(const DomItem &self, OutWriter &ow,
931 QSet<QString> &mergedDefBinding,
932 const QStringList &keys) const;
933
934 void writeOutId(const DomItem &self, OutWriter &ow) const;
935 void writeOut(const DomItem &self, OutWriter &ow, const QString &onTarget) const;
936 void writeOut(const DomItem &self, OutWriter &lw) const override { writeOut(self, lw, QString()); }
937
939 std::shared_ptr<ScriptExpression> accessSequence) const;
940 LocallyResolvedAlias resolveAlias(const DomItem &self, const QStringList &accessSequence) const;
941
942 QQmlJSScope::ConstPtr semanticScope() const { return m_scope; }
943 void setSemanticScope(const QQmlJSScope::ConstPtr &scope) { m_scope = scope; }
944
945 ScriptElementVariant nameIdentifiers() const { return m_nameIdentifiers; }
946 void setNameIdentifiers(const ScriptElementVariant &name) { m_nameIdentifiers = name; }
947
948private:
950 QString m_idStr;
951 QString m_name;
952 QList<Path> m_prototypePaths;
953 Path m_nextScopePath;
954 QString m_defaultPropertyName;
955 QMultiMap<QString, PropertyDefinition> m_propertyDefs;
956 QMultiMap<QString, Binding> m_bindings;
957 QMultiMap<QString, MethodInfo> m_methods;
958 QList<QmlObject> m_children;
959 QList<QmlObject> m_annotations;
960 QQmlJSScope::ConstPtr m_scope;
961 ScriptElementVariant m_nameIdentifiers;
962
963 static constexpr quint32 posOfNewElements = std::numeric_limits<quint32>::max();
964};
965
967{
969public:
970 constexpr static DomType kindValue = DomType::Export;
971 static Export fromString(
972 const Path &source, QStringView exp, const Path &typePath, const ErrorHandler &h);
973 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const
974 {
975 bool cont = true;
976 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::uri), uri);
977 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::typeName), typeName);
978 cont = cont && self.invokeVisitorOnField(visitor, Fields::version, version);
979 if (typePath)
980 cont = cont && self.invokeVisitorOnReference(visitor, Fields::type, typePath);
981 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::isInternal),
982 isInternal);
983 cont = cont && self.invokeVisitorOnValue(visitor, PathEls::Field(Fields::isSingleton),
985 if (exportSourcePath)
986 cont = cont && self.invokeVisitorOnReference(visitor, Fields::exportSource,
987 exportSourcePath);
988 return cont;
989 }
990
996 bool isInternal = false;
997 bool isSingleton = false;
998};
999
1001{
1002public:
1003 Component(const QString &name);
1004 Component(const Path &pathFromOwner = Path());
1005 Component(const Component &o) = default;
1006 Component &operator=(const Component &) = default;
1007
1008 bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override;
1009 void updatePathFromOwner(const Path &newPath) override;
1010 DomItem field(const DomItem &self, QStringView name) const override;
1011
1012 QString name() const { return m_name; }
1013 const QMultiMap<QString, EnumDecl> &enumerations() const & { return m_enumerations; }
1014 const QList<QmlObject> &objects() const & { return m_objects; }
1015 bool isSingleton() const { return m_isSingleton; }
1016 bool isCreatable() const { return m_isCreatable; }
1017 bool isComposite() const { return m_isComposite; }
1018 QString attachedTypeName() const { return m_attachedTypeName; }
1019 Path attachedTypePath(const DomItem &) const { return m_attachedTypePath; }
1020
1021 void setName(const QString &name) { m_name = name; }
1022 void setEnumerations(const QMultiMap<QString, EnumDecl> &enumerations)
1023 {
1024 m_enumerations = enumerations;
1025 }
1026 Path addEnumeration(const EnumDecl &enumeration, AddOption option = AddOption::Overwrite,
1027 EnumDecl **ePtr = nullptr)
1028 {
1029 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::enumerations),
1030 m_enumerations, enumeration.name(), enumeration,
1031 option, ePtr);
1032 }
1033 void setObjects(const QList<QmlObject> &objects) { m_objects = objects; }
1034 Path addObject(const QmlObject &object, QmlObject **oPtr = nullptr);
1035 void setIsSingleton(bool isSingleton) { m_isSingleton = isSingleton; }
1036 void setIsCreatable(bool isCreatable) { m_isCreatable = isCreatable; }
1037 void setIsComposite(bool isComposite) { m_isComposite = isComposite; }
1038 void setAttachedTypeName(const QString &name) { m_attachedTypeName = name; }
1039 void setAttachedTypePath(const Path &p) { m_attachedTypePath = p; }
1040
1041private:
1043 QString m_name;
1044 QMultiMap<QString, EnumDecl> m_enumerations;
1045 QList<QmlObject> m_objects;
1046 bool m_isSingleton = false;
1047 bool m_isCreatable = true;
1048 bool m_isComposite = true;
1049 QString m_attachedTypeName;
1050 Path m_attachedTypePath;
1051};
1052
1053class QMLDOM_EXPORT JsResource final : public Component
1054{
1055public:
1057 DomType kind() const override { return kindValue; }
1058
1059 JsResource(const Path &pathFromOwner = Path()) : Component(pathFromOwner) { }
1060 bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override
1061 { // to do: complete
1062 return true;
1063 }
1064 // globalSymbols defined/exported, required/used
1065};
1066
1067class QMLDOM_EXPORT QmltypesComponent final : public Component
1068{
1069public:
1071 DomType kind() const override { return kindValue; }
1072
1073 QmltypesComponent(const Path &pathFromOwner = Path()) : Component(pathFromOwner) { }
1074 bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override;
1075 const QList<Export> &exports() const & { return m_exports; }
1076 QString fileName() const { return m_fileName; }
1077 void setExports(const QList<Export> &exports) { m_exports = exports; }
1078 void addExport(const Export &exportedEntry) { m_exports.append(exportedEntry); }
1079 void setFileName(const QString &fileName) { m_fileName = fileName; }
1080 const QList<int> &metaRevisions() const & { return m_metaRevisions; }
1081 void setMetaRevisions(const QList<int> &metaRevisions) { m_metaRevisions = metaRevisions; }
1082 void setInterfaceNames(const QStringList& interfaces) { m_interfaceNames = interfaces; }
1083 const QStringList &interfaceNames() const & { return m_interfaceNames; }
1084 QString extensionTypeName() const { return m_extensionTypeName; }
1085 void setExtensionTypeName(const QString &name) { m_extensionTypeName = name; }
1086 QString elementTypeName() const { return m_elementTypeName; }
1087 void setElementTypeName(const QString &name) { m_elementTypeName = name; }
1088 bool hasCustomParser() const { return m_hasCustomParser; }
1089 void setHasCustomParser(bool v) { m_hasCustomParser = v; }
1090 bool extensionIsJavaScript() const { return m_extensionIsJavaScript; }
1091 void setExtensionIsJavaScript(bool v) { m_extensionIsJavaScript = v; }
1092 bool extensionIsNamespace() const { return m_extensionIsNamespace; }
1093 void setExtensionIsNamespace(bool v) { m_extensionIsNamespace = v; }
1094 QQmlJSScope::AccessSemantics accessSemantics() const { return m_accessSemantics; }
1095 void setAccessSemantics(QQmlJSScope::AccessSemantics v) { m_accessSemantics = v; }
1096
1097 void setSemanticScope(const QQmlJSScope::ConstPtr &scope) { m_semanticScope = scope; }
1098 QQmlJSScope::ConstPtr semanticScope() const { return m_semanticScope; }
1099
1100private:
1101 QList<Export> m_exports;
1102 QList<int> m_metaRevisions;
1103 QString m_fileName; // remove?
1104 QStringList m_interfaceNames;
1105 bool m_hasCustomParser = false;
1106 bool m_extensionIsJavaScript = false;
1107 bool m_extensionIsNamespace = false;
1108 QString m_elementTypeName;
1109 QString m_extensionTypeName;
1110 QQmlJSScope::AccessSemantics m_accessSemantics = QQmlJSScope::AccessSemantics::None;
1111 QQmlJSScope::ConstPtr m_semanticScope;
1112};
1113
1114class QMLDOM_EXPORT QmlComponent final : public Component
1115{
1116public:
1118 DomType kind() const override { return kindValue; }
1119
1120 QmlComponent(const QString &name = QString()) : Component(name)
1121 {
1122 setIsComposite(true);
1123 setIsCreatable(true);
1124 }
1125
1126 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override;
1127
1128 const QMultiMap<QString, Id> &ids() const & { return m_ids; }
1129 Path nextComponentPath() const { return m_nextComponentPath; }
1130 void setIds(const QMultiMap<QString, Id> &ids) { m_ids = ids; }
1131 void setNextComponentPath(const Path &p) { m_nextComponentPath = p; }
1132 void updatePathFromOwner(const Path &newPath) override;
1133 Path addId(const Id &id, AddOption option = AddOption::Overwrite, Id **idPtr = nullptr)
1134 {
1135 // warning does nor remove old idStr when overwriting...
1136 return insertUpdatableElementInMultiMap(pathFromOwner().withField(Fields::ids), m_ids, id.name,
1137 id, option, idPtr);
1138 }
1139 void writeOut(const DomItem &self, OutWriter &) const override;
1140 QList<QString> subComponentsNames(const DomItem &self) const;
1141 QList<DomItem> subComponents(const DomItem &self) const;
1142
1143 void setSemanticScope(const QQmlJSScope::ConstPtr &scope) { m_semanticScope = scope; }
1144 QQmlJSScope::ConstPtr semanticScope() const { return m_semanticScope; }
1145 ScriptElementVariant nameIdentifiers() const { return m_nameIdentifiers; }
1146 void setNameIdentifiers(const ScriptElementVariant &name) { m_nameIdentifiers = name; }
1147
1148private:
1150 Path m_nextComponentPath;
1151 QMultiMap<QString, Id> m_ids;
1152 QQmlJSScope::ConstPtr m_semanticScope;
1153 // m_nameIdentifiers contains the name of the component as FieldMemberExpression, and therefore
1154 // only exists in inline components!
1155 ScriptElementVariant m_nameIdentifiers;
1156};
1157
1158class QMLDOM_EXPORT GlobalComponent final : public Component
1159{
1160public:
1162 DomType kind() const override { return kindValue; }
1163
1164 GlobalComponent(const Path &pathFromOwner = Path()) : Component(pathFromOwner) { }
1165};
1166
1168
1170{
1172public:
1174
1175 ImportScope() = default;
1176
1177 const QList<Path> &importSourcePaths() const & { return m_importSourcePaths; }
1178
1179 const QMap<QString, ImportScope> &subImports() const & { return m_subImports; }
1180
1181 QList<Path> allSources(const DomItem &self) const;
1182
1183 QSet<QString> importedNames(const DomItem &self) const
1184 {
1185 QSet<QString> res;
1186 const auto sources = allSources(self);
1187 for (const Path &p : sources) {
1188 QSet<QString> ks = self.path(p.withField(Fields::exports), self.errorHandler()).keys();
1189 res += ks;
1190 }
1191 return res;
1192 }
1193
1194 QList<DomItem> importedItemsWithName(const DomItem &self, const QString &name) const
1195 {
1196 QList<DomItem> res;
1197 const auto sources = allSources(self);
1198 for (const Path &p : sources) {
1199 DomItem source = self.path(p.withField(Fields::exports), self.errorHandler());
1200 DomItem els = source.key(name);
1201 int nEls = els.indexes();
1202 for (int i = 0; i < nEls; ++i)
1203 res.append(els.index(i));
1204 if (nEls == 0 && els) {
1205 self.addError(importErrors.warning(
1206 tr("Looking up '%1' expected a list of exports, not %2")
1207 .arg(name, els.toString())));
1208 }
1209 }
1210 return res;
1211 }
1212
1213 QList<Export> importedExportsWithName(const DomItem &self, const QString &name) const
1214 {
1215 QList<Export> res;
1216 for (const DomItem &i : importedItemsWithName(self, name))
1217 if (const Export *e = i.as<Export>())
1218 res.append(*e);
1219 else
1220 self.addError(importErrors.warning(
1221 tr("Expected Export looking up '%1', not %2").arg(name, i.toString())));
1222 return res;
1223 }
1224
1225 bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
1226
1227 void addImport(const QStringList &p, const Path &targetExports)
1228 {
1229 if (!p.isEmpty())
1230 m_subImports[p.first()].addImport(p.mid(1), targetExports);
1231 else if (!m_importSourcePaths.contains(targetExports))
1232 m_importSourcePaths.append(targetExports);
1233 }
1234
1235private:
1236 QList<Path> m_importSourcePaths;
1237 QMap<QString, ImportScope> m_subImports;
1238};
1239
1241{
1242public:
1243 BindingValue();
1244 BindingValue(const QmlObject &o);
1245 BindingValue(const std::shared_ptr<ScriptExpression> &o);
1246 BindingValue(const QList<QmlObject> &l);
1247 ~BindingValue();
1248 BindingValue(const BindingValue &o);
1250
1251 DomItem value(const DomItem &binding) const;
1252 void updatePathFromOwner(const Path &newPath);
1253
1254private:
1255 friend class Binding;
1256 void clearValue();
1257
1258 BindingValueKind kind;
1259 union {
1264 };
1265};
1266
1267} // end namespace Dom
1268} // end namespace QQmlJS
1269QT_END_NAMESPACE
1270#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)
Path addAnnotation(const QmlObject &annotation, QmlObject **aPtr=nullptr)
LocallyResolvedAlias resolveAlias(const DomItem &self, std::shared_ptr< ScriptExpression > accessSequence) const
void writeOutId(const DomItem &self, OutWriter &ow) const
QList< QmlObject > children() const
LocallyResolvedAlias resolveAlias(const DomItem &self, const QStringList &accessSequence) const
const QList< Path > & prototypePaths() const &
void writeOutSortedPropertyDefinition(const DomItem &self, OutWriter &ow, QSet< QString > &mergedDefBinding, const QStringList &keys) const
Path addPropertyDef(const PropertyDefinition &propertyDef, AddOption option, PropertyDefinition **pDef=nullptr)
void writeOutSortedAttributes(const DomItem &self, OutWriter &ow, const DomItem &component, const Attributes &attribs) const
const QMultiMap< QString, MethodInfo > & methods() const &
MutableDomItem addPropertyDef(MutableDomItem &self, const PropertyDefinition &propertyDef, AddOption option)
DomItem field(const DomItem &self, QStringView name) const override
void setBindings(const QMultiMap< QString, Binding > &bindings)
QString localDefaultPropertyName() const
QString defaultPropertyName(const DomItem &self) const
void setPropertyDefs(const QMultiMap< QString, PropertyDefinition > &propertyDefs)
QmlObject(const Path &pathFromOwner=Path())
void writeOutAttributes(OutWriter &ow, const Attributes &attribs, const QString &code) const
MutableDomItem addMethod(MutableDomItem &self, const MethodInfo &functionDef, AddOption option)
void setIdStr(const QString &id)
QQmlJSScope::ConstPtr semanticScope() const
const QMultiMap< QString, PropertyDefinition > & propertyDefs() const &
void writeOut(const DomItem &self, OutWriter &lw) const override
Path addPrototypePath(const Path &prototypePath)
void setSemanticScope(const QQmlJSScope::ConstPtr &scope)
void setDefaultPropertyName(const QString &name)
void setPrototypePaths(const QList< Path > &prototypePaths)
QList< QmlObject > annotations() const
QList< QString > fields() const
QList< std::pair< SourceLocation, DomItem > > Attributes
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
Path addMethod(const MethodInfo &functionDef, AddOption option, MethodInfo **mPtr=nullptr)
bool iterateBaseDirectSubpaths(const DomItem &self, DirectVisitor) const
static QmlUri fromString(const QString &importStr)
QString absoluteLocalPath(const QString &basePath=QString()) const
QString directoryString() const
static QmlUri fromUriString(const QString &importStr)
QString localPath() const
QString moduleUri() const
friend bool operator==(const QmlUri &i1, const QmlUri &i2)
static QmlUri fromDirectoryString(const QString &importStr)
friend bool operator!=(const QmlUri &i1, const QmlUri &i2)
void setInterfaceNames(const QStringList &interfaces)
void setMetaRevisions(const QList< int > &metaRevisions)
QQmlJSScope::AccessSemantics accessSemantics() const
void setFileName(const QString &fileName)
static constexpr DomType kindValue
QQmlJSScope::ConstPtr semanticScope() const
void setAccessSemantics(QQmlJSScope::AccessSemantics v)
void setSemanticScope(const QQmlJSScope::ConstPtr &scope)
bool iterateDirectSubpaths(const DomItem &, DirectVisitor) const override
void setExtensionTypeName(const QString &name)
void setElementTypeName(const QString &name)
const QList< int > & metaRevisions() const &
const QList< Export > & exports() const &
void setExports(const QList< Export > &exports)
void addExport(const Export &exportedEntry)
const QStringList & interfaceNames() const &
QmltypesComponent(const Path &pathFromOwner=Path())
DomType kind() const override
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)