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
qqmltctyperesolver.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant
4
6
7#include <private/qqmljsimporter_p.h>
8#include <private/qqmljsliteralbindingcheck_p.h>
9#include <private/qv4value_p.h>
10
11#include <QtCore/qqueue.h>
12#include <QtCore/qloggingcategory.h>
13#include <QtCore/qfileinfo.h>
14#include <QtCore/qdiriterator.h>
15
16Q_STATIC_LOGGING_CATEGORY(lcTypeResolver2, "qml.qmltc.typeresolver", QtInfoMsg);
17
18QT_BEGIN_NAMESPACE
19
20namespace QQmltc {
21
22void TypeResolver::init(Visitor *visitor, QQmlJS::AST::Node *program)
23{
24 QQmlJSTypeResolver::init(visitor, program);
25
26 m_root = visitor->result();
27
28 QQueue<QQmlJSScope::Ptr> objects;
29 objects.enqueue(m_root);
30 while (!objects.isEmpty()) {
31 const QQmlJSScope::Ptr object = objects.dequeue();
32 const QQmlJS::SourceLocation location = object->sourceLocation();
33 qCDebug(lcTypeResolver2()).nospace() << "inserting " << object.data() << " at "
34 << location.startLine << ':' << location.startColumn;
35 m_objectsByLocationNonConst.insert({ location.startLine, location.startColumn }, object);
36
37 const auto childScopes = object->childScopes();
38 for (const auto &childScope : childScopes)
39 objects.enqueue(childScope);
40 }
41}
42
44TypeResolver::scopeForLocation(const QV4::CompiledData::Location &location) const
45{
46 qCDebug(lcTypeResolver2()).nospace()
47 << "looking for object at " << location.line() << ':' << location.column();
48 return m_objectsByLocationNonConst.value(location);
49}
50
52TypeResolver::importedType(const QQmlJSScope::ConstPtr &type) const
53{
54 const auto files = m_importer->importedFiles();
55 auto it = std::find_if(files.cbegin(), files.cend(), [&](const QQmlJSScope::Ptr &importedType) {
56 return importedType.data() == type.data();
57 });
58 if (it == files.cend())
59 return {};
60 return { it.key(), it.value() };
61}
62
63} // namespace QQmltc
64
65QT_END_NAMESPACE
std::pair< QString, QQmlJSScope::Ptr > importedType(const QQmlJSScope::ConstPtr &type) const
QQmlJSScope::Ptr scopeForLocation(const QV4::CompiledData::Location &location) const
void init(Visitor *visitor, QQmlJS::AST::Node *program)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)