diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-09-13 15:05:12 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-09-15 09:01:59 +0200 |
commit | 1f5b7d843d5d091b98c068f2bff2fc63957b8134 (patch) | |
tree | 5424cc4e243c017100010d297c8f20cf2e0e1842 /src/qmldom/qqmldomcomments_p.h | |
parent | 5dadee1186429e61b7bb8d27120b0399f0d16655 (diff) |
QmlDom: Add const-correctness
We almost never want non-const DomItems anywhere. There is exactly one
exception: From a MutableDomItem we need to poke into the internals of
the respective DomItem and const_cast them. However, MutableDomItem is
to be handled with care anyway.
Change-Id: I826f0669c049462beec9ad71dccb39c5191a1d3f
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'src/qmldom/qqmldomcomments_p.h')
-rw-r--r-- | src/qmldom/qqmldomcomments_p.h | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/qmldom/qqmldomcomments_p.h b/src/qmldom/qqmldomcomments_p.h index e4f85fa3e3..e987644343 100644 --- a/src/qmldom/qqmldomcomments_p.h +++ b/src/qmldom/qqmldomcomments_p.h @@ -82,7 +82,7 @@ public: { } - bool iterateDirectSubpaths(DomItem &self, DirectVisitor visitor); + bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const; int newlinesBefore() const { return m_newlinesBefore; } void setNewlinesBefore(int n) { m_newlinesBefore = n; } QStringView rawComment() const { return m_comment; } @@ -107,7 +107,7 @@ public: constexpr static DomType kindValue = DomType::CommentedElement; DomType kind() const { return kindValue; } - bool iterateDirectSubpaths(DomItem &self, DirectVisitor visitor); + bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const; void writePre(OutWriter &lw, QList<SourceLocation> *locations = nullptr) const; void writePost(OutWriter &lw, QList<SourceLocation> *locations = nullptr) const; QMultiMap<quint32, const QList<Comment> *> commentGroups(SourceLocation elLocation) const; @@ -131,7 +131,7 @@ public: constexpr static DomType kindValue = DomType::RegionComments; DomType kind() const { return kindValue; } - bool iterateDirectSubpaths(DomItem &self, DirectVisitor visitor); + bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const; friend bool operator==(const RegionComments &c1, const RegionComments &c2) { @@ -170,7 +170,7 @@ public: class QMLDOM_EXPORT AstComments final : public OwningItem { protected: - std::shared_ptr<OwningItem> doCopy(DomItem &) const override + std::shared_ptr<OwningItem> doCopy(const DomItem &) const override { return std::make_shared<AstComments>(*this); } @@ -178,13 +178,13 @@ protected: public: constexpr static DomType kindValue = DomType::AstComments; DomType kind() const override { return kindValue; } - bool iterateDirectSubpaths(DomItem &self, DirectVisitor) override; - std::shared_ptr<AstComments> makeCopy(DomItem &self) const + bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override; + std::shared_ptr<AstComments> makeCopy(const DomItem &self) const { return std::static_pointer_cast<AstComments>(doCopy(self)); } - Path canonicalPath(DomItem &self) const override { return self.m_ownerPath; } + Path canonicalPath(const DomItem &self) const override { return self.m_ownerPath; } static void collectComments(MutableDomItem &item); static void collectComments(std::shared_ptr<Engine> engine, AST::Node *n, std::shared_ptr<AstComments> collectComments, |