aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmljseditor
diff options
context:
space:
mode:
authorFawzi Mohamed <fawzi.mohamed@qt.io>2020-02-28 17:51:32 +0100
committerFawzi Mohamed <fawzi.mohamed@qt.io>2020-03-03 15:31:10 +0000
commitb09a48599e7e5db5447189136353b79aca3898cf (patch)
tree5f6f3b1d4da3ed746caa612992d94ed21978dd75 /src/plugins/qmljseditor
parenta24dead5f63d7eb0b209539daebf5b2ce558b1c0 (diff)
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>
Diffstat (limited to 'src/plugins/qmljseditor')
-rw-r--r--src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp1
-rw-r--r--src/plugins/qmljseditor/qmljseditor.cpp12
-rw-r--r--src/plugins/qmljseditor/qmljseditordocument.cpp18
-rw-r--r--src/plugins/qmljseditor/qmljsfindreferences.cpp25
-rw-r--r--src/plugins/qmljseditor/qmljshoverhandler.cpp4
-rw-r--r--src/plugins/qmljseditor/qmljsoutline.cpp2
-rw-r--r--src/plugins/qmljseditor/qmljssemantichighlighter.cpp11
-rw-r--r--src/plugins/qmljseditor/qmljssemantichighlighter.h2
-rw-r--r--src/plugins/qmljseditor/qmljswrapinloader.cpp6
-rw-r--r--src/plugins/qmljseditor/qmloutlinemodel.cpp32
-rw-r--r--src/plugins/qmljseditor/qmloutlinemodel.h10
11 files changed, 92 insertions, 31 deletions
diff --git a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
index 3afca0b036..9ed886246b 100644
--- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
+++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
@@ -51,6 +51,7 @@
#include <QMessageBox>
using namespace QmlJS::AST;
+using QmlJS::SourceLocation;
using namespace QmlJSTools;
namespace QmlJSEditor {
diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp
index 13eab82ce4..c260c2f708 100644
--- a/src/plugins/qmljseditor/qmljseditor.cpp
+++ b/src/plugins/qmljseditor/qmljseditor.cpp
@@ -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)) {
diff --git a/src/plugins/qmljseditor/qmljseditordocument.cpp b/src/plugins/qmljseditor/qmljseditordocument.cpp
index bb487202c0..b600af61c0 100644
--- a/src/plugins/qmljseditor/qmljseditordocument.cpp
+++ b/src/plugins/qmljseditor/qmljseditordocument.cpp
@@ -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;
diff --git a/src/plugins/qmljseditor/qmljsfindreferences.cpp b/src/plugins/qmljseditor/qmljsfindreferences.cpp
index 670fc69282..d6f85ef26c 100644
--- a/src/plugins/qmljseditor/qmljsfindreferences.cpp
+++ b/src/plugins/qmljseditor/qmljsfindreferences.cpp
@@ -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));
}
}
diff --git a/src/plugins/qmljseditor/qmljshoverhandler.cpp b/src/plugins/qmljseditor/qmljshoverhandler.cpp
index cf73d63d7c..1009a7f543 100644
--- a/src/plugins/qmljseditor/qmljshoverhandler.cpp
+++ b/src/plugins/qmljseditor/qmljshoverhandler.cpp
@@ -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());
}
diff --git a/src/plugins/qmljseditor/qmljsoutline.cpp b/src/plugins/qmljseditor/qmljsoutline.cpp
index abd333f468..0fcac6e60a 100644
--- a/src/plugins/qmljseditor/qmljsoutline.cpp
+++ b/src/plugins/qmljseditor/qmljsoutline.cpp
@@ -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())
diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp
index e3b169f46d..65e9b0ca2e 100644
--- a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp
+++ b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp
@@ -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)
{
diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.h b/src/plugins/qmljseditor/qmljssemantichighlighter.h
index 7fa25b588f..77ea2a7c12 100644
--- a/src/plugins/qmljseditor/qmljssemantichighlighter.h
+++ b/src/plugins/qmljseditor/qmljssemantichighlighter.h
@@ -32,7 +32,7 @@
#include <QVector>
namespace QmlJS {
-namespace AST { class SourceLocation; }
+class SourceLocation;
}
namespace TextEditor { class FontSettings; }
diff --git a/src/plugins/qmljseditor/qmljswrapinloader.cpp b/src/plugins/qmljseditor/qmljswrapinloader.cpp
index d83d34e23e..5f0ef4bb05 100644
--- a/src/plugins/qmljseditor/qmljswrapinloader.cpp
+++ b/src/plugins/qmljseditor/qmljswrapinloader.cpp
@@ -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;
};
diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp
index 50162fb1fc..0cda207b51 100644
--- a/src/plugins/qmljseditor/qmloutlinemodel.cpp
+++ b/src/plugins/qmljseditor/qmloutlinemodel.cpp
@@ -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;
diff --git a/src/plugins/qmljseditor/qmloutlinemodel.h b/src/plugins/qmljseditor/qmloutlinemodel.h
index 17dd08abd8..626b5f3be4 100644
--- a/src/plugins/qmljseditor/qmloutlinemodel.h
+++ b/src/plugins/qmljseditor/qmloutlinemodel.h
@@ -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);