summaryrefslogtreecommitdiff
path: root/src/plugins/qmljseditor
diff options
context:
space:
mode:
authorMarco Benelli <marco.benelli@qt.io>2018-10-16 15:32:58 +0200
committerMarco Benelli <marco.benelli@qt.io>2018-11-22 11:21:32 +0000
commit4646acad0db369302d08a1b83e1971be31c1df4f (patch)
treecc6b02cc0942309f9887e3a8e0f19a34e60123d5 /src/plugins/qmljseditor
parentfe8a3727735f1e6cf9414999ff5103520b1a56f9 (diff)
downloadqt-creator-4646acad0db369302d08a1b83e1971be31c1df4f.tar.gz
qmljs: update parser
Update the qtcreator qmljs parser to the one of Qt 5.12. It supports EcmaScript 7. Task-number: QTCREATORBUG-20341 Change-Id: I0d1cff71402ba17e22cde6b46c65614e162280de Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/plugins/qmljseditor')
-rw-r--r--src/plugins/qmljseditor/qmljseditordocument.cpp14
-rw-r--r--src/plugins/qmljseditor/qmljsfindreferences.cpp21
-rw-r--r--src/plugins/qmljseditor/qmljssemantichighlighter.cpp9
-rw-r--r--src/plugins/qmljseditor/qmloutlinemodel.cpp50
-rw-r--r--src/plugins/qmljseditor/qmloutlinemodel.h9
5 files changed, 47 insertions, 56 deletions
diff --git a/src/plugins/qmljseditor/qmljseditordocument.cpp b/src/plugins/qmljseditor/qmljseditordocument.cpp
index ccae08f6dd..bbd53bcf41 100644
--- a/src/plugins/qmljseditor/qmljseditordocument.cpp
+++ b/src/plugins/qmljseditor/qmljseditordocument.cpp
@@ -295,8 +295,8 @@ protected:
decl.text += QLatin1Char('(');
for (FormalParameterList *it = ast->formals; it; it = it->next) {
- if (!it->name.isEmpty())
- decl.text += it->name;
+ if (!it->element->bindingIdentifier.isEmpty())
+ decl.text += it->element->bindingIdentifier;
if (it->next)
decl.text += QLatin1String(", ");
@@ -309,14 +309,14 @@ protected:
return false;
}
- bool visit(AST::VariableDeclaration *ast) override
+ bool visit(AST::PatternElement *ast) override
{
- if (ast->name.isEmpty())
+ if (!ast->isVariableDeclaration() || ast->bindingIdentifier.isEmpty())
return false;
Declaration decl;
decl.text.fill(QLatin1Char(' '), _depth);
- decl.text += ast->name;
+ decl.text += ast->bindingIdentifier;
const SourceLocation first = ast->identifierToken;
decl.startLine = first.startLine;
@@ -343,8 +343,8 @@ protected:
decl.text += QLatin1Char('(');
for (FormalParameterList *it = funcExpr->formals; it; it = it->next) {
- if (!it->name.isEmpty())
- decl.text += it->name;
+ if (!it->element->bindingIdentifier.isEmpty())
+ decl.text += it->element->bindingIdentifier;
if (it->next)
decl.text += QLatin1String(", ");
diff --git a/src/plugins/qmljseditor/qmljsfindreferences.cpp b/src/plugins/qmljseditor/qmljsfindreferences.cpp
index 6c8d2f4f98..c44158fb14 100644
--- a/src/plugins/qmljseditor/qmljsfindreferences.cpp
+++ b/src/plugins/qmljseditor/qmljsfindreferences.cpp
@@ -227,9 +227,9 @@ protected:
return false;
}
- bool visit(AST::VariableDeclaration *node) override
+ bool visit(AST::PatternElement *node) override
{
- if (node->name == _name) {
+ if (node->isVariableDeclaration() && node->bindingIdentifier == _name) {
if (checkLookup())
_usages.append(node->identifierToken);
}
@@ -322,7 +322,7 @@ protected:
bool visit(AST::UiPublicMember *node) override
{
- if (node->memberTypeName() == _name){
+ if (node->memberType->name == _name){
const ObjectValue * tVal = _context->lookupType(_doc.data(), QStringList(_name));
if (tVal == _typeValue)
_usages.append(node->typeToken);
@@ -406,9 +406,10 @@ protected:
return false;
}
- bool visit(AST::VariableDeclaration *node) override
+ bool visit(AST::PatternElement *node) override
{
- Node::accept(node->expression, this);
+ if (node->isVariableDeclaration())
+ Node::accept(node->initializer, this);
return false;
}
@@ -583,8 +584,8 @@ protected:
bool visit(UiPublicMember *node) override
{
if (containsOffset(node->typeToken)){
- if (node->isValid()) {
- _name = node->memberTypeName().toString();
+ if (node->defaultToken.isValid()) {
+ _name = node->memberType->name.toString();
_targetValue = _scopeChain->context()->lookupType(_doc.data(), QStringList(_name));
_scope = 0;
_typeKind = TypeKind;
@@ -612,10 +613,10 @@ protected:
return true;
}
- bool visit(VariableDeclaration *node) override
+ bool visit(PatternElement *node) override
{
- if (containsOffset(node->identifierToken)) {
- _name = node->name.toString();
+ if (node->isVariableDeclaration() && containsOffset(node->identifierToken)) {
+ _name = node->bindingIdentifier.toString();
return false;
}
return true;
diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp
index 4cd696a046..c464b38092 100644
--- a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp
+++ b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp
@@ -323,8 +323,8 @@ protected:
bool visit(UiPublicMember *ast)
{
- if (ast->typeToken.isValid() && ast->isValid()) {
- if (m_scopeChain.context()->lookupType(m_scopeChain.document().data(), QStringList(ast->memberTypeName().toString())))
+ if (ast->typeToken.isValid()) { // TODO: ast->isValid() ?
+ if (m_scopeChain.context()->lookupType(m_scopeChain.document().data(), QStringList(ast->memberType->name.toString())))
addUse(ast->typeToken, SemanticHighlighter::QmlTypeType);
}
if (ast->identifierToken.isValid())
@@ -350,9 +350,10 @@ protected:
return visit(static_cast<FunctionExpression *>(ast));
}
- bool visit(VariableDeclaration *ast)
+ bool visit(PatternElement *ast)
{
- processName(ast->name, ast->identifierToken);
+ if (ast->isVariableDeclaration())
+ processName(ast->bindingIdentifier, ast->identifierToken);
return true;
}
diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp
index b10d7902d0..647a733a77 100644
--- a/src/plugins/qmljseditor/qmloutlinemodel.cpp
+++ b/src/plugins/qmljseditor/qmloutlinemodel.cpp
@@ -263,14 +263,14 @@ private:
bool visit(AST::BinaryExpression *binExp)
{
AST::IdentifierExpression *lhsIdent = AST::cast<AST::IdentifierExpression *>(binExp->left);
- AST::ObjectLiteral *rhsObjLit = AST::cast<AST::ObjectLiteral *>(binExp->right);
+ AST::ObjectPattern *rhsObjLit = AST::cast<AST::ObjectPattern *>(binExp->right);
if (lhsIdent && rhsObjLit && (lhsIdent->name == QLatin1String("testcase"))
&& (binExp->op == QSOperator::Assign)) {
QModelIndex index = m_model->enterTestCase(rhsObjLit);
m_nodeToIndex.insert(rhsObjLit, index);
- if (AST::PropertyAssignmentList *properties = rhsObjLit->properties)
+ if (AST::PatternPropertyList *properties = rhsObjLit->properties)
visitProperties(properties);
m_model->leaveTestCase();
@@ -290,13 +290,13 @@ private:
return true;
}
- void visitProperties(AST::PropertyAssignmentList *properties)
+ void visitProperties(AST::PatternPropertyList *properties)
{
while (properties) {
QModelIndex index = m_model->enterTestCaseProperties(properties);
m_nodeToIndex.insert(properties, index);
- if (AST::PropertyNameAndValue *assignment = AST::cast<AST::PropertyNameAndValue *>(properties->assignment))
- if (AST::ObjectLiteral *objLiteral = AST::cast<AST::ObjectLiteral *>(assignment->value))
+ if (AST::PatternProperty *assignment = AST::cast<AST::PatternProperty *>(properties->property))
+ if (AST::ObjectPattern *objLiteral = AST::cast<AST::ObjectPattern *>(assignment->initializer))
visitProperties(objLiteral->properties);
m_model->leaveTestCaseProperties();
@@ -592,7 +592,7 @@ static QString functionDisplayName(QStringRef name, AST::FormalParameterList *fo
if (!name.isEmpty())
display += name.toString() + QLatin1Char('(');
for (AST::FormalParameterList *param = formals; param; param = param->next) {
- display += param->name.toString();
+ display += param->element->bindingIdentifier.toString();
if (param->next)
display += QLatin1String(", ");
}
@@ -650,7 +650,7 @@ void QmlOutlineModel::leaveFieldMemberExpression()
leaveNode();
}
-QModelIndex QmlOutlineModel::enterTestCase(AST::ObjectLiteral *objectLiteral)
+QModelIndex QmlOutlineModel::enterTestCase(AST::ObjectPattern *objectLiteral)
{
QMap<int, QVariant> objectData;
@@ -667,18 +667,18 @@ void QmlOutlineModel::leaveTestCase()
leaveNode();
}
-QModelIndex QmlOutlineModel::enterTestCaseProperties(AST::PropertyAssignmentList *propertyAssignmentList)
+QModelIndex QmlOutlineModel::enterTestCaseProperties(AST::PatternPropertyList *propertyAssignmentList)
{
QMap<int, QVariant> objectData;
- if (AST::PropertyNameAndValue *assignment = AST::cast<AST::PropertyNameAndValue *>(
- propertyAssignmentList->assignment)) {
+ if (AST::PatternProperty *assignment = AST::cast<AST::PatternProperty *>(
+ propertyAssignmentList->property)) {
if (AST::IdentifierPropertyName *propertyName = AST::cast<AST::IdentifierPropertyName *>(assignment->name)) {
objectData.insert(Qt::DisplayRole, propertyName->id.toString());
objectData.insert(ItemTypeRole, ElementBindingType);
QmlOutlineItem *item;
- if (assignment->value->kind == AST::Node::Kind_FunctionExpression)
+ if (assignment->initializer->kind == AST::Node::Kind_FunctionExpression)
item = enterNode(objectData, assignment, 0, Icons::functionDeclarationIcon());
- else if (assignment->value->kind == AST::Node::Kind_ObjectLiteral)
+ else if (assignment->initializer->kind == AST::Node::Kind_ObjectPattern)
item = enterNode(objectData, assignment, 0, Icons::objectDefinitionIcon());
else
item = enterNode(objectData, assignment, 0, Icons::scriptBindingIcon());
@@ -686,8 +686,8 @@ QModelIndex QmlOutlineModel::enterTestCaseProperties(AST::PropertyAssignmentList
return item->index();
}
}
- if (AST::PropertyGetterSetter *getterSetter = AST::cast<AST::PropertyGetterSetter *>(
- propertyAssignmentList->assignment)) {
+ if (AST::PatternProperty *getterSetter = AST::cast<AST::PatternProperty *>(
+ propertyAssignmentList->property)) {
if (AST::IdentifierPropertyName *propertyName = AST::cast<AST::IdentifierPropertyName *>(getterSetter->name)) {
objectData.insert(Qt::DisplayRole, propertyName->id.toString());
objectData.insert(ItemTypeRole, ElementBindingType);
@@ -728,7 +728,7 @@ AST::SourceLocation QmlOutlineModel::sourceLocation(const QModelIndex &index) co
location = getLocation(member);
else if (AST::ExpressionNode *expression = node->expressionCast())
location = getLocation(expression);
- else if (AST::PropertyAssignmentList *propertyAssignmentList = AST::cast<AST::PropertyAssignmentList *>(node))
+ else if (AST::PatternPropertyList *propertyAssignmentList = AST::cast<AST::PatternPropertyList *>(node))
location = getLocation(propertyAssignmentList);
}
return location;
@@ -999,26 +999,16 @@ AST::SourceLocation QmlOutlineModel::getLocation(AST::ExpressionNode *exprNode)
return location;
}
-AST::SourceLocation QmlOutlineModel::getLocation(AST::PropertyAssignmentList *propertyNode) {
- if (AST::PropertyNameAndValue *assignment = AST::cast<AST::PropertyNameAndValue *>(propertyNode->assignment))
+AST::SourceLocation QmlOutlineModel::getLocation(AST::PatternPropertyList *propertyNode) {
+ if (AST::PatternProperty *assignment = AST::cast<AST::PatternProperty *>(propertyNode->property))
return getLocation(assignment);
- if (AST::PropertyGetterSetter *getterSetter = AST::cast<AST::PropertyGetterSetter *>(propertyNode->assignment))
- return getLocation(getterSetter);
- return propertyNode->commaToken; // should never happen
+ return propertyNode->firstSourceLocation(); // should never happen
}
-AST::SourceLocation QmlOutlineModel::getLocation(AST::PropertyNameAndValue *propertyNode) {
+AST::SourceLocation QmlOutlineModel::getLocation(AST::PatternProperty *propertyNode) {
AST::SourceLocation location;
location = propertyNode->name->propertyNameToken;
- location.length = propertyNode->value->lastSourceLocation().end() - location.offset;
-
- return location;
-}
-
-AST::SourceLocation QmlOutlineModel::getLocation(AST::PropertyGetterSetter *propertyNode) {
- AST::SourceLocation location;
- location = propertyNode->name->propertyNameToken;
- location.length = propertyNode->rbraceToken.end() - location.offset;
+ location.length = propertyNode->initializer->lastSourceLocation().end() - location.offset;
return location;
}
diff --git a/src/plugins/qmljseditor/qmloutlinemodel.h b/src/plugins/qmljseditor/qmloutlinemodel.h
index 2f1ff2a26e..fddbd2f7c6 100644
--- a/src/plugins/qmljseditor/qmloutlinemodel.h
+++ b/src/plugins/qmljseditor/qmloutlinemodel.h
@@ -120,10 +120,10 @@ private:
QmlJS::AST::FunctionExpression *functionExpression);
void leaveFieldMemberExpression();
- QModelIndex enterTestCase(QmlJS::AST::ObjectLiteral *objectLiteral);
+ QModelIndex enterTestCase(QmlJS::AST::ObjectPattern *objectLiteral);
void leaveTestCase();
- QModelIndex enterTestCaseProperties(QmlJS::AST::PropertyAssignmentList *propertyAssignmentList);
+ QModelIndex enterTestCaseProperties(QmlJS::AST::PatternPropertyList *propertyAssignmentList);
void leaveTestCaseProperties();
private:
@@ -140,9 +140,8 @@ private:
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::PropertyAssignmentList *propertyNode);
- static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::PropertyNameAndValue *propertyNode);
- static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::PropertyGetterSetter *propertyNode);
+ static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::PatternProperty *propertyNode);
+ static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::PatternPropertyList *propertyNode);
QIcon getIcon(QmlJS::AST::UiQualifiedId *objDef);
QString getAnnotation(QmlJS::AST::UiObjectInitializer *objInitializer);