forked from qt-creator/qt-creator
Update qmljs parser to Qt 5.15 parser
* parser side support for annotations, inline components, new UiVersion and all the things included in QT 5.15 parser * SourceLocation moved from QmlJS:AST to QmlJS * Visitors now need to handle throwRecursionDepthError * BaseVisitor for visitors that want to override all visit Task-number: QTCREATORBUG-23591 Change-Id: I682a30d0b08b6c929739fd0e339ef6fbde3eb630 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
@@ -51,6 +51,7 @@
|
||||
#include <QMessageBox>
|
||||
|
||||
using namespace QmlJS::AST;
|
||||
using QmlJS::SourceLocation;
|
||||
using namespace QmlJSTools;
|
||||
|
||||
namespace QmlJSEditor {
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
#include <QTextCodec>
|
||||
#include <QTimer>
|
||||
#include <QTreeView>
|
||||
#include <QDebug>
|
||||
|
||||
enum {
|
||||
UPDATE_USES_DEFAULT_INTERVAL = 150,
|
||||
@@ -230,7 +231,7 @@ bool QmlJSEditorWidget::isOutlineCursorChangesBlocked()
|
||||
void QmlJSEditorWidget::jumpToOutlineElement(int /*index*/)
|
||||
{
|
||||
QModelIndex index = m_outlineCombo->view()->currentIndex();
|
||||
AST::SourceLocation location = m_qmlJsEditorDocument->outlineModel()->sourceLocation(index);
|
||||
SourceLocation location = m_qmlJsEditorDocument->outlineModel()->sourceLocation(index);
|
||||
|
||||
if (!location.isValid())
|
||||
return;
|
||||
@@ -332,7 +333,7 @@ void QmlJSEditorWidget::updateUses()
|
||||
return;
|
||||
|
||||
QList<QTextEdit::ExtraSelection> selections;
|
||||
foreach (const AST::SourceLocation &loc,
|
||||
foreach (const SourceLocation &loc,
|
||||
m_qmlJsEditorDocument->semanticInfo().idLocations.value(wordUnderCursor())) {
|
||||
if (! loc.isValid())
|
||||
continue;
|
||||
@@ -432,6 +433,11 @@ protected:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void throwRecursionDepthError() override
|
||||
{
|
||||
qWarning("Warning: Hit maximum recursion depth visiting AST in SelectedElement");
|
||||
}
|
||||
};
|
||||
|
||||
void QmlJSEditorWidget::setSelectedElements()
|
||||
@@ -941,7 +947,7 @@ QModelIndex QmlJSEditorWidget::indexForPosition(unsigned cursorPosition, const Q
|
||||
const int rowCount = model->rowCount(rootIndex);
|
||||
for (int i = 0; i < rowCount; ++i) {
|
||||
QModelIndex childIndex = model->index(i, 0, rootIndex);
|
||||
AST::SourceLocation location = model->sourceLocation(childIndex);
|
||||
SourceLocation location = model->sourceLocation(childIndex);
|
||||
|
||||
if ((cursorPosition >= location.offset)
|
||||
&& (cursorPosition <= location.offset + location.length)) {
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
#include <qmljstools/qmljsmodelmanager.h>
|
||||
#include <qmljstools/qmljsqtstylecodeformatter.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
const char QML_UI_FILE_WARNING[] = "QmlJSEditor.QmlUiFileWarning";
|
||||
|
||||
using namespace QmlJSEditor;
|
||||
@@ -69,7 +71,7 @@ struct Declaration
|
||||
class FindIdDeclarations: protected Visitor
|
||||
{
|
||||
public:
|
||||
using Result = QHash<QString, QList<AST::SourceLocation> >;
|
||||
using Result = QHash<QString, QList<SourceLocation> >;
|
||||
|
||||
Result operator()(Document::Ptr doc)
|
||||
{
|
||||
@@ -110,7 +112,7 @@ protected:
|
||||
if (auto idExpr = AST::cast<const AST::IdentifierExpression *>(stmt->expression)) {
|
||||
if (!idExpr->name.isEmpty()) {
|
||||
const QString &id = idExpr->name.toString();
|
||||
QList<AST::SourceLocation> *locs = &_ids[id];
|
||||
QList<SourceLocation> *locs = &_ids[id];
|
||||
locs->append(idExpr->firstSourceLocation());
|
||||
locs->append(_maybeIds.value(id));
|
||||
_maybeIds.remove(id);
|
||||
@@ -138,6 +140,11 @@ protected:
|
||||
return false;
|
||||
}
|
||||
|
||||
void throwRecursionDepthError() override
|
||||
{
|
||||
qWarning("Warning: Hit maximum recursion depth while visiting AST in FindIdDeclarations");
|
||||
}
|
||||
|
||||
private:
|
||||
Result _ids;
|
||||
Result _maybeIds;
|
||||
@@ -414,6 +421,11 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
void throwRecursionDepthError() override
|
||||
{
|
||||
qWarning("Warning: Hit maximum recursion depth while visiting AST in CreateRanges");
|
||||
}
|
||||
|
||||
Range createRange(AST::UiObjectMember *member, AST::UiObjectInitializer *ast)
|
||||
{
|
||||
return createRange(member, member->firstSourceLocation(), ast->rbraceToken);
|
||||
@@ -429,7 +441,7 @@ protected:
|
||||
return createRange(ast, block->lbraceToken, block->rbraceToken);
|
||||
}
|
||||
|
||||
Range createRange(AST::Node *ast, AST::SourceLocation start, AST::SourceLocation end)
|
||||
Range createRange(AST::Node *ast, SourceLocation start, SourceLocation end)
|
||||
{
|
||||
Range range;
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
#include <QTimer>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QtConcurrentMap>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
@@ -70,7 +71,7 @@ namespace {
|
||||
class FindUsages: protected Visitor
|
||||
{
|
||||
public:
|
||||
using Result = QList<AST::SourceLocation>;
|
||||
using Result = QList<SourceLocation>;
|
||||
|
||||
FindUsages(Document::Ptr doc, const ContextPtr &context)
|
||||
: _doc(doc)
|
||||
@@ -236,6 +237,11 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
void throwRecursionDepthError() override
|
||||
{
|
||||
qWarning("Warning: Hit maximum recursion depth while visitin AST in FindUsages");
|
||||
}
|
||||
|
||||
private:
|
||||
bool contains(const QmlComponentChain *chain)
|
||||
{
|
||||
@@ -294,7 +300,7 @@ private:
|
||||
class FindTypeUsages: protected Visitor
|
||||
{
|
||||
public:
|
||||
using Result = QList<AST::SourceLocation>;
|
||||
using Result = QList<SourceLocation>;
|
||||
|
||||
FindTypeUsages(Document::Ptr doc, const ContextPtr &context)
|
||||
: _doc(doc)
|
||||
@@ -427,6 +433,10 @@ protected:
|
||||
return false;
|
||||
}
|
||||
|
||||
void throwRecursionDepthError() override
|
||||
{
|
||||
qWarning("Warning: Hit maximum recursion depth while visitin AST in FindTypeUsages");
|
||||
}
|
||||
|
||||
private:
|
||||
bool checkTypeName(UiQualifiedId *id)
|
||||
@@ -624,6 +634,11 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
void throwRecursionDepthError() override
|
||||
{
|
||||
qWarning("Warning: Hit maximum recursion depth visiting AST in FindUsages");
|
||||
}
|
||||
|
||||
private:
|
||||
bool containsOffset(SourceLocation start, SourceLocation end)
|
||||
{
|
||||
@@ -720,7 +735,7 @@ public:
|
||||
// find all idenfifier expressions, try to resolve them and check if the result is in scope
|
||||
FindUsages findUsages(doc, context);
|
||||
FindUsages::Result results = findUsages(name, scope);
|
||||
foreach (const AST::SourceLocation &loc, results)
|
||||
foreach (const SourceLocation &loc, results)
|
||||
usages.append(Usage(fileName, matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length));
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
@@ -762,7 +777,7 @@ public:
|
||||
// find all idenfifier expressions, try to resolve them and check if the result is in scope
|
||||
FindTypeUsages findUsages(doc, context);
|
||||
FindTypeUsages::Result results = findUsages(name, scope);
|
||||
foreach (const AST::SourceLocation &loc, results)
|
||||
foreach (const SourceLocation &loc, results)
|
||||
usages.append(Usage(fileName, matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length));
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
@@ -944,7 +959,7 @@ QList<FindReferences::Usage> FindReferences::findUsageOfType(const QString &file
|
||||
foreach (const QmlJS::Document::Ptr &doc, snapshot) {
|
||||
FindTypeUsages findUsages(doc, context);
|
||||
FindTypeUsages::Result results = findUsages(typeName, targetValue);
|
||||
foreach (const AST::SourceLocation &loc, results) {
|
||||
foreach (const SourceLocation &loc, results) {
|
||||
usages.append(Usage(doc->fileName(), matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ namespace QmlJSEditor {
|
||||
namespace {
|
||||
|
||||
QString textAt(const Document::Ptr doc,
|
||||
const AST::SourceLocation &from,
|
||||
const AST::SourceLocation &to)
|
||||
const SourceLocation &from,
|
||||
const SourceLocation &to)
|
||||
{
|
||||
return doc->source().mid(from.offset, to.end() - from.begin());
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ void QmlJSOutlineWidget::updateTextCursor(const QModelIndex &index)
|
||||
if (!m_editor->isOutlineCursorChangesBlocked()) {
|
||||
QModelIndex sourceIndex = m_filterModel->mapToSource(index);
|
||||
|
||||
AST::SourceLocation location
|
||||
SourceLocation location
|
||||
= m_editor->qmlJsEditorDocument()->outlineModel()->sourceLocation(sourceIndex);
|
||||
|
||||
if (!location.isValid())
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QTextDocument>
|
||||
#include <QThreadPool>
|
||||
|
||||
@@ -163,6 +164,11 @@ protected:
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void throwRecursionDepthError() override
|
||||
{
|
||||
qWarning("Warning: Hit maximum recursion depth while visitin AST in CollectStateNames");
|
||||
}
|
||||
};
|
||||
|
||||
class CollectionTask : protected Visitor
|
||||
@@ -453,6 +459,11 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
void throwRecursionDepthError() override
|
||||
{
|
||||
qWarning("Warning: Hit Maximum recursion depth when visiting AST in CollectionTask");
|
||||
}
|
||||
|
||||
private:
|
||||
void addUse(const SourceLocation &location, SemanticHighlighter::UseType type)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <QVector>
|
||||
|
||||
namespace QmlJS {
|
||||
namespace AST { class SourceLocation; }
|
||||
class SourceLocation;
|
||||
}
|
||||
|
||||
namespace TextEditor { class FontSettings; }
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <qmljs/qmljsbind.h>
|
||||
#include <qmljstools/qmljsrefactoringchanges.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QCoreApplication>
|
||||
@@ -71,6 +72,11 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
void throwRecursionDepthError() override
|
||||
{
|
||||
qWarning("Warning: Hit maximum recursion depth while visitin AST in FindIds");
|
||||
}
|
||||
|
||||
Result result;
|
||||
};
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ QmlOutlineItem::QmlOutlineItem(QmlOutlineModel *model) :
|
||||
QVariant QmlOutlineItem::data(int role) const
|
||||
{
|
||||
if (role == Qt::ToolTipRole) {
|
||||
AST::SourceLocation location = m_outlineModel->sourceLocation(index());
|
||||
SourceLocation location = m_outlineModel->sourceLocation(index());
|
||||
AST::UiQualifiedId *uiQualifiedId = m_outlineModel->idNode(index());
|
||||
if (!uiQualifiedId || !location.isValid() || !m_outlineModel->m_semanticInfo.isValid())
|
||||
return QVariant();
|
||||
@@ -146,6 +146,11 @@ private:
|
||||
parent.insert(objMember, stack.last());
|
||||
}
|
||||
}
|
||||
|
||||
void throwRecursionDepthError() override
|
||||
{
|
||||
qWarning("Warning: Hit maximum recursion depth while visiting AST in ObjectMemberParentVisitor");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -304,6 +309,11 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void throwRecursionDepthError() override
|
||||
{
|
||||
qWarning("Warning: Hit maximum recursion limit visiting AST in QmlOutlineModelSync");
|
||||
}
|
||||
|
||||
QmlOutlineModel *m_model;
|
||||
|
||||
QHash<AST::Node*, QModelIndex> m_nodeToIndex;
|
||||
@@ -341,7 +351,7 @@ QMimeData *QmlOutlineModel::mimeData(const QModelIndexList &indexes) const
|
||||
stream << indexes.size();
|
||||
|
||||
for (const auto &index : indexes) {
|
||||
AST::SourceLocation location = sourceLocation(index);
|
||||
SourceLocation location = sourceLocation(index);
|
||||
data->addFile(m_editorDocument->filePath().toString(), location.startLine,
|
||||
location.startColumn - 1 /*editors have 0-based column*/);
|
||||
|
||||
@@ -719,9 +729,9 @@ AST::Node *QmlOutlineModel::nodeForIndex(const QModelIndex &index) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AST::SourceLocation QmlOutlineModel::sourceLocation(const QModelIndex &index) const
|
||||
SourceLocation QmlOutlineModel::sourceLocation(const QModelIndex &index) const
|
||||
{
|
||||
AST::SourceLocation location;
|
||||
SourceLocation location;
|
||||
QTC_ASSERT(index.isValid() && (index.model() == this), return location);
|
||||
AST::Node *node = nodeForIndex(index);
|
||||
if (node) {
|
||||
@@ -981,8 +991,8 @@ QString QmlOutlineModel::asString(AST::UiQualifiedId *id)
|
||||
return text;
|
||||
}
|
||||
|
||||
AST::SourceLocation QmlOutlineModel::getLocation(AST::UiObjectMember *objMember) {
|
||||
AST::SourceLocation location;
|
||||
SourceLocation QmlOutlineModel::getLocation(AST::UiObjectMember *objMember) {
|
||||
SourceLocation location;
|
||||
location = objMember->firstSourceLocation();
|
||||
location.length = objMember->lastSourceLocation().offset
|
||||
- objMember->firstSourceLocation().offset
|
||||
@@ -990,8 +1000,8 @@ AST::SourceLocation QmlOutlineModel::getLocation(AST::UiObjectMember *objMember)
|
||||
return location;
|
||||
}
|
||||
|
||||
AST::SourceLocation QmlOutlineModel::getLocation(AST::ExpressionNode *exprNode) {
|
||||
AST::SourceLocation location;
|
||||
SourceLocation QmlOutlineModel::getLocation(AST::ExpressionNode *exprNode) {
|
||||
SourceLocation location;
|
||||
location = exprNode->firstSourceLocation();
|
||||
location.length = exprNode->lastSourceLocation().offset
|
||||
- exprNode->firstSourceLocation().offset
|
||||
@@ -999,14 +1009,14 @@ AST::SourceLocation QmlOutlineModel::getLocation(AST::ExpressionNode *exprNode)
|
||||
return location;
|
||||
}
|
||||
|
||||
AST::SourceLocation QmlOutlineModel::getLocation(AST::PatternPropertyList *propertyNode) {
|
||||
SourceLocation QmlOutlineModel::getLocation(AST::PatternPropertyList *propertyNode) {
|
||||
if (auto assignment = AST::cast<AST::PatternProperty *>(propertyNode->property))
|
||||
return getLocation(assignment);
|
||||
return propertyNode->firstSourceLocation(); // should never happen
|
||||
}
|
||||
|
||||
AST::SourceLocation QmlOutlineModel::getLocation(AST::PatternProperty *propertyNode) {
|
||||
AST::SourceLocation location;
|
||||
SourceLocation QmlOutlineModel::getLocation(AST::PatternProperty *propertyNode) {
|
||||
SourceLocation location;
|
||||
location = propertyNode->name->propertyNameToken;
|
||||
location.length = propertyNode->initializer->lastSourceLocation().end() - location.offset;
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
void update(const QmlJSTools::SemanticInfo &semanticInfo);
|
||||
|
||||
QmlJS::AST::Node *nodeForIndex(const QModelIndex &index) const;
|
||||
QmlJS::AST::SourceLocation sourceLocation(const QModelIndex &index) const;
|
||||
QmlJS::SourceLocation sourceLocation(const QModelIndex &index) const;
|
||||
QmlJS::AST::UiQualifiedId *idNode(const QModelIndex &index) const;
|
||||
QIcon icon(const QModelIndex &index) const;
|
||||
|
||||
@@ -138,10 +138,10 @@ private:
|
||||
QStandardItem *parentItem();
|
||||
|
||||
static QString asString(QmlJS::AST::UiQualifiedId *id);
|
||||
static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::UiObjectMember *objMember);
|
||||
static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::ExpressionNode *exprNode);
|
||||
static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::PatternProperty *propertyNode);
|
||||
static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::PatternPropertyList *propertyNode);
|
||||
static QmlJS::SourceLocation getLocation(QmlJS::AST::UiObjectMember *objMember);
|
||||
static QmlJS::SourceLocation getLocation(QmlJS::AST::ExpressionNode *exprNode);
|
||||
static QmlJS::SourceLocation getLocation(QmlJS::AST::PatternProperty *propertyNode);
|
||||
static QmlJS::SourceLocation getLocation(QmlJS::AST::PatternPropertyList *propertyNode);
|
||||
QIcon getIcon(QmlJS::AST::UiQualifiedId *objDef);
|
||||
|
||||
QString getAnnotation(QmlJS::AST::UiObjectInitializer *objInitializer);
|
||||
|
||||
Reference in New Issue
Block a user