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
QQmlJS::Dom::Path Class Reference

Represents an immutable JsonPath like path in the Qml code model (from a DomItem to another DomItem). More...

#include <qqmldompath_p.h>

Collaboration diagram for QQmlJS::Dom::Path:

Public Types

using Kind = PathEls::Kind
using Component = PathEls::PathComponent

Public Member Functions

 Path ()=default
int length () const
Path operator[] (int i) const
 operator bool () const
PathIterator begin () const
PathSentinel end () const
std::optional< PathRoot > headRoot () const
std::optional< PathCurrent > headCurrent () const
Kind headKind () const
QString headName () const
std::optional< FieldName > headField () const
std::optional< index_type > headIndex () const
Path head () const
Path last () const
Source split () const
 Splits the path at the last field or current component, or right after a root anchor.
void dump (const Sink &sinksink) const
QString toString () const
Path dropFront (int nn=1) const
Path dropTail (int nn=1) const
Path mid (int offsetoffset, int lengthlength) const
Path mid (int offsetoffset) const
Path withComponent (PathEls::PathComponent cc) const
Path withEmpty () const
Path withField (FieldName namename) const
Path withKey (const QString &namename) const
Path withKey (QStringView namename) const
Path withIndex (index_type i) const
Path withCurrent (PathCurrent ss) const
Path withPath (const Path &toAdd) const
 Returns a copy of this with toAdd appended to it.

Static Public Member Functions

static Path fromRoot (PathRoot rr)
static Path fromIndex (index_type i)
static Path fromField (FieldName namename)
static Path fromKey (QStringView ss)
static Path fromKey (const QString &ss)
static Path fromCurrent (PathCurrent cc)
static Path fromComponent (Component cc)
static int cmp (const Path &p1, const Path &p2)
 Compares p1 and p2 lexicographically.

Friends

class QQmlJS::Dom::PathEls::TestPaths
class FieldFilter
class PathIterator
QMLDOM_EXPORT size_t qHash (const Path &pathpath, size_t seed=0)

Detailed Description

Represents an immutable JsonPath like path in the Qml code model (from a DomItem to another DomItem).

A Path is a pointer to the node holding its last component, plus the path length. Each node (PathEls::PathNode) holds one PathComponent and a pointer to the node of the component before it:

\badcode

                  __[.e] a.e (node e, length 2)
                 /

[$root] <- [.a] <- [.b] <- [.c] $root.a.b.c: (node c, length 4) ^ ___ [.d] $root.a.d: (node d, length 3)

Nodes are immutable and reference counted.

The path consists of the m_length nodes ending in m_lastNode. Ancestors beyond that are not part of the path, which makes dropFront() O(1). dropTail(n) and mid() walk up from the tail, which is O(n) in the number of dropped components. That's often cheap, as they mostly drop the last one or two components.

As the links point backwards, accessing the front of a path is O(length). Operations that traverse the components in order therefore first collect the nodes into an array.

Each PathComponent owns the data it stores, there are no references to outside data strutures.

It can be created with the path static functions or by modifying an existing path. To parse a Path from its textual form, use parsePath() from qqmldompathparser_p.h.

.withField(Fields::qmlFilesByPath)
.withKey(QStringLiteral("/path/to/file"))
.withField(Fields::imports);
Path currentComponentImports = Path::fromCurrent(PathCurrent::Component)
.withField(Fields::imports);
static Path fromRoot(PathRoot r)
Path withField(FieldName name) const
Path withKey(const QString &name) const
static Path fromCurrent(PathCurrent c)
#define QStringLiteral(str)
Definition qstring.h:1859

This is a way to refer to elements in the Dom models that is not dependent from the source location, and thus can also be used in visual tools. A Path is quite stable toward reallocations or changes in the Dom model, and accessing it is safe even when "dangling", thus it is a good long term reference to an element in the Dom model.

Path objects are a value type that have a shared pointer to extra data if needed, thus one should use them as value objects. The implementation has still optimization potential, but the behavior for the user should be already the final one.

Path is both a range, and a single element (a bit like strings and characters in python).

The root contexts are: \list

  • \l{$modules} All the known modules (even not imported), this is a global, rename independent reference
  • \l{$cpp} The Cpp names (namespaces, and Cpp types) visible in the current component
  • \l{$libs} The plugins/libraries and their contents
  • \l{$top} A top level entry in the DOM model, either $env or $universe (stepping in the universe one looses the reference to its environment)
  • \l{$env} The environment containing the currently available modules, i.e. the top level entry in the DOM model
  • \l{$universe} The dom unverse used by ths environment, and potentially shared with others that contains all the known parse entries, and also the latest, potentially invalid entries \endlist

The current contexts are: \list

  • \l{@obj} The current object (if in a map or list goes up until it is in the current object) .
  • \l{@component} The root object of the current component.
  • \l{@module} The current module instantiation.
  • \l{@ids} The ids in the current component.
  • \l{@types} All the types in the current component (reachable through imports, respecting renames)
  • \l{@lookupStrict} The strict lookup inside the current object: localJS, ids, properties, proto properties, component, its properties, global context, oterwise error
  • \l{@lookupDynamic} The default lookup inside the current object: localJS, ids, properties, proto properties, component, its properties, global context, ..
  • \l{@lookup} Either lookupStrict or lookupDynamic depending on the current component and context. \endlist

Member Typedef Documentation

◆ Component

◆ Kind

Definition at line 575 of file qqmldompath_p.h.

Constructor & Destructor Documentation

◆ Path()

Member Function Documentation

◆ begin()

PathIterator QQmlJS::Dom::Path::begin ( ) const

Definition at line 251 of file qqmldompath.cpp.

References QQmlJS::Dom::PathIterator::PathIterator().

Referenced by QQmlJS::Dom::DomItem::resolve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cmp()

int QQmlJS::Dom::Path::cmp ( const Path & p1,
const Path & p2 )
static

Compares p1 and p2 lexicographically.

Definition at line 389 of file qqmldompath.cpp.

References QQmlJS::Dom::PathEls::PathComponent::cmp().

Referenced by QQmlJS::Dom::ErrorMessage::compare, QQmlJS::Dom::operator!=(), QQmlJS::Dom::operator<(), QQmlJS::Dom::operator<=(), QQmlJS::Dom::operator==(), QQmlJS::Dom::operator>(), and QQmlJS::Dom::operator>=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dropFront()

Path QQmlJS::Dom::Path::dropFront ( int n = 1) const

Definition at line 438 of file qqmldompath.cpp.

References Path().

Here is the call graph for this function:

◆ dropTail()

Path QQmlJS::Dom::Path::dropTail ( int n = 1) const

Definition at line 445 of file qqmldompath.cpp.

References Path().

Referenced by QQmlJS::Dom::DomItem::goUp(), QQmlJS::Dom::DomItem::isCanonicalChild(), mid(), QQmlJS::Dom::DomItem::visitScopeChain(), and QQmlJS::Dom::DomItem::visitUp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dump()

void QQmlJS::Dom::Path::dump ( const Sink & sink) const

Definition at line 414 of file qqmldompath.cpp.

◆ end()

PathSentinel QQmlJS::Dom::Path::end ( ) const

Definition at line 256 of file qqmldompath.cpp.

◆ fromComponent()

Path QQmlJS::Dom::Path::fromComponent ( Component c)
static

Definition at line 343 of file qqmldompath.cpp.

References Path(), and withComponent().

Referenced by fromCurrent(), fromField(), fromIndex(), fromKey(), and fromRoot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromCurrent()

Path QQmlJS::Dom::Path::fromCurrent ( PathCurrent c)
static

Definition at line 353 of file qqmldompath.cpp.

References fromComponent().

Referenced by QQmlJS::Dom::Paths::lookupCppTypePath(), QQmlJS::Dom::Paths::lookupPropertyPath(), QQmlJS::Dom::Paths::lookupSymbolPath(), and QQmlJS::Dom::Paths::lookupTypePath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromField()

Path QQmlJS::Dom::Path::fromField ( FieldName name)
static

Definition at line 350 of file qqmldompath.cpp.

References fromComponent().

Referenced by QQmlJS::Dom::QmlObject::addPrototypePath(), QQmlJS::Dom::EnumDecl::addValue(), and QQmlJS::Dom::QmlObject::writeOut().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromIndex()

Path QQmlJS::Dom::Path::fromIndex ( index_type i)
static

Definition at line 349 of file qqmldompath.cpp.

References fromComponent().

Here is the call graph for this function:

◆ fromKey() [1/2]

Path QQmlJS::Dom::Path::fromKey ( const QString & s)
static

Definition at line 351 of file qqmldompath.cpp.

References fromComponent().

Here is the call graph for this function:

◆ fromKey() [2/2]

Path QQmlJS::Dom::Path::fromKey ( QStringView s)
static

Definition at line 352 of file qqmldompath.cpp.

◆ fromRoot()

Path QQmlJS::Dom::Path::fromRoot ( PathRoot r)
static

Definition at line 348 of file qqmldompath.cpp.

References fromComponent().

Referenced by QQmlJS::Dom::DomEnvironment::canonicalPath(), QQmlJS::Dom::DomUniverse::canonicalPath(), QQmlJS::Dom::LoadInfo::canonicalPath(), QQmlJS::Dom::Paths::jsFileInfoPath(), QQmlJS::Dom::Paths::loadInfoPath(), QQmlJS::Dom::Paths::moduleIndexPath(), QQmlJS::Dom::Paths::moduleScopePath(), and QQmlJS::Dom::Paths::qmlFileInfoPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ head()

Path QQmlJS::Dom::Path::head ( ) const

Definition at line 305 of file qqmldompath.cpp.

References mid().

Here is the call graph for this function:

◆ headCurrent()

std::optional< PathCurrent > QQmlJS::Dom::Path::headCurrent ( ) const

Definition at line 269 of file qqmldompath.cpp.

References QQmlJS::Dom::PathEls::PathComponent::asCurrent(), and QQmlJS::Dom::PathEls::Current::contextKind.

Referenced by QQmlJS::Dom::DomItem::resolve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ headField()

std::optional< FieldName > QQmlJS::Dom::Path::headField ( ) const

Definition at line 277 of file qqmldompath.cpp.

References QQmlJS::Dom::PathEls::PathComponent::asField(), and QQmlJS::Dom::PathEls::Field::fieldName.

Referenced by QQmlJS::Dom::DomItem::resolve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ headIndex()

std::optional< index_type > QQmlJS::Dom::Path::headIndex ( ) const

Definition at line 297 of file qqmldompath.cpp.

References QQmlJS::Dom::PathEls::PathComponent::asIndex().

Here is the call graph for this function:

◆ headKind()

Path::Kind QQmlJS::Dom::Path::headKind ( ) const

Definition at line 285 of file qqmldompath.cpp.

References QQmlJS::Dom::PathEls::Empty, and QQmlJS::Dom::PathEls::PathComponent::kind().

Referenced by QQmlJS::Dom::DomItem::canonicalPath(), and QQmlJS::Dom::DomItem::resolve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ headName()

QString QQmlJS::Dom::Path::headName ( ) const

Definition at line 292 of file qqmldompath.cpp.

◆ headRoot()

std::optional< PathRoot > QQmlJS::Dom::Path::headRoot ( ) const

Definition at line 261 of file qqmldompath.cpp.

References QQmlJS::Dom::PathEls::PathComponent::asRoot(), and QQmlJS::Dom::PathEls::Root::contextKind.

Referenced by QQmlJS::Dom::DomItem::resolve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ last()

Path QQmlJS::Dom::Path::last ( ) const

Definition at line 310 of file qqmldompath.cpp.

Referenced by QQmlJS::Dom::QmlObject::addBinding(), QQmlJS::Dom::QmlObject::addMethod(), QQmlJS::Dom::QmlObject::addPropertyDef(), QQmlJS::Dom::QmlObject::orderOfAttributes(), QQmlJS::Dom::FileLocations::treeOf(), and QQmlJS::Dom::EnumItem::writeOut().

Here is the caller graph for this function:

◆ length()

int QQmlJS::Dom::Path::length ( ) const
inline

◆ mid() [1/2]

Path QQmlJS::Dom::Path::mid ( int offset) const

Definition at line 464 of file qqmldompath.cpp.

Referenced by split().

Here is the caller graph for this function:

◆ mid() [2/2]

Path QQmlJS::Dom::Path::mid ( int offset,
int length ) const

Definition at line 456 of file qqmldompath.cpp.

References Path(), and dropTail().

Referenced by head(), QQmlJS::Dom::ExternalItemInfoBase::lastRevision(), QQmlJS::Dom::ExternalItemInfoBase::lastValidRevision(), operator[](), and split().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator bool()

QQmlJS::Dom::Path::operator bool ( ) const
explicit

Definition at line 246 of file qqmldompath.cpp.

References length().

Here is the call graph for this function:

◆ operator[]()

Path QQmlJS::Dom::Path::operator[] ( int i) const

Definition at line 241 of file qqmldompath.cpp.

References mid().

Referenced by QQmlJS::Dom::QmlComponent::subComponentsNames().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ split()

Source QQmlJS::Dom::Path::split ( ) const

Splits the path at the last field or current component, or right after a root anchor.

Field and Current introduce a new logical "starting point" inside the path, so split puts everything before them into pathToSource and the component itself (plus any tail) into pathFromSource. A Root, in contrast, is an anchor: pathToSource includes the Root and pathFromSource is what follows it. If neither is present, the entire path is pathFromSource.

Definition at line 326 of file qqmldompath.cpp.

References Path(), QQmlJS::Dom::PathEls::Current, QQmlJS::Dom::PathEls::Field, QQmlJS::Dom::PathEls::PathComponent::kind(), length(), mid(), mid(), and QQmlJS::Dom::PathEls::Root.

Referenced by QQmlJS::Dom::DomItem::container(), QQmlJS::Dom::DomBase::containingObject(), and QQmlJS::Dom::OwningItem::containingObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

QString QQmlJS::Dom::Path::toString ( ) const

Definition at line 429 of file qqmldompath.cpp.

◆ withComponent()

Path QQmlJS::Dom::Path::withComponent ( PathEls::PathComponent c) const

Definition at line 355 of file qqmldompath.cpp.

Referenced by fromComponent(), QQmlJS::Dom::keyMultiMapHelper(), withCurrent(), withEmpty(), withField(), withIndex(), and withKey().

Here is the caller graph for this function:

◆ withCurrent()

Path QQmlJS::Dom::Path::withCurrent ( PathCurrent s) const

Definition at line 366 of file qqmldompath.cpp.

References withComponent().

Here is the call graph for this function:

◆ withEmpty()

Path QQmlJS::Dom::Path::withEmpty ( ) const

Definition at line 361 of file qqmldompath.cpp.

References QQmlJS::Dom::PathEls::PathComponent::PathComponent(), and withComponent().

Here is the call graph for this function:

◆ withField()

◆ withIndex()

Path QQmlJS::Dom::Path::withIndex ( index_type i) const

Definition at line 365 of file qqmldompath.cpp.

References withComponent().

Here is the call graph for this function:

◆ withKey() [1/2]

Path QQmlJS::Dom::Path::withKey ( const QString & name) const

Definition at line 363 of file qqmldompath.cpp.

References withComponent().

Here is the call graph for this function:

◆ withKey() [2/2]

Path QQmlJS::Dom::Path::withKey ( QStringView name) const

Definition at line 364 of file qqmldompath.cpp.

◆ withPath()

Path QQmlJS::Dom::Path::withPath ( const Path & toAdd) const

Returns a copy of this with toAdd appended to it.

This allocates one node per component of toAdd. If this path is empty, toAdd is returned as is.

Definition at line 375 of file qqmldompath.cpp.

Referenced by QQmlJS::Dom::AstRangesVisitor::addItemRanges(), QQmlJS::Dom::DomElement::canonicalPath(), QQmlJS::Dom::FileLocations::treeOf(), and QQmlJS::Dom::FileLocations::visitTree().

Here is the caller graph for this function:

◆ FieldFilter

friend class FieldFilter
friend

Definition at line 637 of file qqmldompath_p.h.

◆ PathIterator

friend class PathIterator
friend

Definition at line 638 of file qqmldompath_p.h.

◆ qHash

QMLDOM_EXPORT size_t qHash ( const Path & path,
size_t seed = 0 )
friend

Definition at line 469 of file qqmldompath.cpp.

References length().

◆ QQmlJS::Dom::PathEls::TestPaths

friend class QQmlJS::Dom::PathEls::TestPaths
friend

Definition at line 636 of file qqmldompath_p.h.


The documentation for this class was generated from the following files: