Make QmlJS(Tools) build with Qt5 & Qt6

Port from QStringRef to QStringView

Change-Id: I472d16f20e40ca52b8e5d481850a6bd8a1a38f3b
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2020-09-16 15:08:57 +02:00
parent 5ad724c61b
commit cf2a651c3b
37 changed files with 442 additions and 321 deletions

View File

@@ -269,7 +269,7 @@ bool JsonCheck::visit(StringLiteral *ast)
analysis()->boostRanking();
const QStringRef literal = ast->value;
const QStringView literal = ast->value;
const QString &pattern = m_schema->pattern();
if (!pattern.isEmpty()) {

View File

@@ -29,7 +29,7 @@
QT_QML_BEGIN_NAMESPACE
static int parseInt(const QStringRef &str, bool *ok)
static int parseInt(const QStringView &str, bool *ok)
{
int pos = 0;
int number = 0;
@@ -51,9 +51,10 @@ static bool parseVersion(const QString &str, int *major, int *minor)
const int dotIndex = str.indexOf(QLatin1Char('.'));
if (dotIndex != -1 && str.indexOf(QLatin1Char('.'), dotIndex + 1) == -1) {
bool ok = false;
*major = parseInt(QStringRef(&str, 0, dotIndex), &ok);
*major = parseInt(QStringView(str.constData(), dotIndex), &ok);
if (ok)
*minor = parseInt(QStringRef(&str, dotIndex + 1, str.length() - dotIndex - 1), &ok);
*minor = parseInt(QStringView(str.constData() + dotIndex + 1, str.length() - dotIndex - 1),
&ok);
return ok;
}
return false;

View File

@@ -403,10 +403,10 @@ protected:
inline Value &sym(int index)
{ return sym_stack [tos + index - 1]; }
inline QStringRef &stringRef(int index)
inline QStringView &stringRef(int index)
{ return string_stack [tos + index - 1]; }
inline QStringRef &rawStringRef(int index)
inline QStringView &rawStringRef(int index)
{ return rawString_stack [tos + index - 1]; }
inline SourceLocation &loc(int index)
@@ -444,8 +444,8 @@ protected:
Value *sym_stack = nullptr;
int *state_stack = nullptr;
SourceLocation *location_stack = nullptr;
QVector<QStringRef> string_stack;
QVector<QStringRef> rawString_stack;
QVector<QStringView> string_stack;
QVector<QStringView> rawString_stack;
AST::Node *program = nullptr;
@@ -456,14 +456,14 @@ protected:
int token;
double dval;
SourceLocation loc;
QStringRef spell;
QStringRef raw;
QStringView spell;
QStringView raw;
};
int yytoken = -1;
double yylval = 0.;
QStringRef yytokenspell;
QStringRef yytokenraw;
QStringView yytokenspell;
QStringView yytokenraw;
SourceLocation yylloc;
SourceLocation yyprevlloc;
@@ -555,7 +555,7 @@ static inline SourceLocation location(Lexer *lexer)
AST::UiQualifiedId *Parser::reparseAsQualifiedId(AST::ExpressionNode *expr)
{
QVarLengthArray<QStringRef, 4> nameIds;
QVarLengthArray<QStringView, 4> nameIds;
QVarLengthArray<SourceLocation, 4> locations;
AST::ExpressionNode *it = expr;
@@ -3624,7 +3624,7 @@ ContinueStatement: T_CONTINUE IdentifierReference Semicolon;
BreakStatement: T_BREAK Semicolon;
/.
case $rule_number: {
AST::BreakStatement *node = new (pool) AST::BreakStatement(QStringRef());
AST::BreakStatement *node = new (pool) AST::BreakStatement(QStringView());
node->breakToken = loc(1);
node->semicolonToken = loc(2);
sym(1).Node = node;
@@ -3898,7 +3898,7 @@ FunctionDeclaration_Default: Function T_LPAREN FormalParameters T_RPAREN TypeAnn
case $rule_number: {
if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList))
return false;
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringRef(), sym(3).FormalParameterList, sym(7).StatementList,
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringView(), sym(3).FormalParameterList, sym(7).StatementList,
/*type annotation*/nullptr);
node->functionToken = loc(1);
node->lparenToken = loc(2);
@@ -3932,7 +3932,7 @@ FunctionExpression: T_FUNCTION T_LPAREN FormalParameters T_RPAREN TypeAnnotation
case $rule_number: {
if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList))
return false;
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringRef(), sym(3).FormalParameterList, sym(7).StatementList,
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringView(), sym(3).FormalParameterList, sym(7).StatementList,
/*type annotation*/nullptr);
node->functionToken = loc(1);
node->lparenToken = loc(2);
@@ -4022,7 +4022,7 @@ ArrowFunction_In: ArrowParameters T_ARROW ConciseBodyLookahead AssignmentExpress
ret->returnToken = sym(4).Node->firstSourceLocation();
ret->semicolonToken = sym(4).Node->lastSourceLocation();
AST::StatementList *statements = (new (pool) AST::StatementList(ret))->finish();
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringRef(), sym(1).FormalParameterList, statements);
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, statements);
f->isArrowFunction = true;
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation() : loc(1);
f->lbraceToken = sym(4).Node->firstSourceLocation();
@@ -4036,7 +4036,7 @@ ArrowFunction: ArrowParameters T_ARROW ConciseBodyLookahead T_FORCE_BLOCK Functi
ArrowFunction_In: ArrowParameters T_ARROW ConciseBodyLookahead T_FORCE_BLOCK FunctionLBrace FunctionBody FunctionRBrace;
/.
case $rule_number: {
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringRef(), sym(1).FormalParameterList, sym(6).StatementList);
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, sym(6).StatementList);
f->isArrowFunction = true;
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation() : loc(1);
f->lbraceToken = loc(6);
@@ -4197,7 +4197,7 @@ GeneratorDeclaration_Default: GeneratorDeclaration;
GeneratorDeclaration_Default: FunctionStar GeneratorLParen FormalParameters T_RPAREN FunctionLBrace GeneratorBody GeneratorRBrace;
/.
case $rule_number: {
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringRef(), sym(3).FormalParameterList, sym(6).StatementList);
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringView(), sym(3).FormalParameterList, sym(6).StatementList);
node->functionToken = loc(1);
node->lparenToken = loc(2);
node->rparenToken = loc(4);
@@ -4227,7 +4227,7 @@ GeneratorExpression: T_FUNCTION_STAR BindingIdentifier GeneratorLParen FormalPar
GeneratorExpression: T_FUNCTION_STAR GeneratorLParen FormalParameters T_RPAREN FunctionLBrace GeneratorBody GeneratorRBrace;
/.
case $rule_number: {
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringRef(), sym(3).FormalParameterList, sym(6).StatementList);
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringView(), sym(3).FormalParameterList, sym(6).StatementList);
node->functionToken = loc(1);
node->lparenToken = loc(2);
node->rparenToken = loc(4);
@@ -4302,7 +4302,7 @@ ClassExpression: T_CLASS BindingIdentifier ClassHeritageOpt ClassLBrace ClassBod
ClassDeclaration_Default: T_CLASS ClassHeritageOpt ClassLBrace ClassBodyOpt ClassRBrace;
/.
case $rule_number: {
AST::ClassDeclaration *node = new (pool) AST::ClassDeclaration(QStringRef(), sym(2).Expression, sym(4).ClassElementList);
AST::ClassDeclaration *node = new (pool) AST::ClassDeclaration(QStringView(), sym(2).Expression, sym(4).ClassElementList);
node->classToken = loc(1);
node->lbraceToken = loc(3);
node->rbraceToken = loc(5);
@@ -4313,7 +4313,7 @@ ClassDeclaration_Default: T_CLASS ClassHeritageOpt ClassLBrace ClassBodyOpt Clas
ClassExpression: T_CLASS ClassHeritageOpt ClassLBrace ClassBodyOpt ClassRBrace;
/.
case $rule_number: {
AST::ClassExpression *node = new (pool) AST::ClassExpression(QStringRef(), sym(2).Expression, sym(4).ClassElementList);
AST::ClassExpression *node = new (pool) AST::ClassExpression(QStringView(), sym(2).Expression, sym(4).ClassElementList);
node->classToken = loc(1);
node->lbraceToken = loc(3);
node->rbraceToken = loc(5);

View File

@@ -27,6 +27,8 @@
#include "qmljsastvisitor_p.h"
#include <QLocale>
QT_QML_BEGIN_NAMESPACE
namespace QmlJS { namespace AST {
@@ -1529,7 +1531,7 @@ QString Type::toString() const
void Type::toString(QString *out) const
{
for (QmlJS::AST::UiQualifiedId *it = typeId; it; it = it->next) {
out->append(it->name);
out->append(it->name.toString());
if (it->next)
out->append(QLatin1Char('.'));

View File

@@ -318,11 +318,12 @@ class QML_PARSER_EXPORT UiQualifiedId: public Node
public:
QMLJS_DECLARE_AST_NODE(UiQualifiedId)
UiQualifiedId(const QStringRef &name)
: next(this), name(name)
UiQualifiedId(const QStringView &name)
: next(this)
, name(name)
{ kind = K; }
UiQualifiedId(UiQualifiedId *previous, const QStringRef &name)
UiQualifiedId(UiQualifiedId *previous, const QStringView &name)
: name(name)
{
kind = K;
@@ -347,7 +348,7 @@ public:
// attributes
UiQualifiedId *next;
QStringRef name;
QStringView name;
SourceLocation identifierToken;
};
@@ -512,8 +513,11 @@ class QML_PARSER_EXPORT IdentifierExpression: public LeftHandSideExpression
public:
QMLJS_DECLARE_AST_NODE(IdentifierExpression)
IdentifierExpression(const QStringRef &n):
name (n) { kind = K; }
IdentifierExpression(const QStringView &n)
: name(n)
{
kind = K;
}
void accept0(BaseVisitor *visitor) override;
@@ -524,7 +528,7 @@ public:
{ return identifierToken; }
// attributes
QStringRef name;
QStringView name;
SourceLocation identifierToken;
};
@@ -654,8 +658,11 @@ class QML_PARSER_EXPORT StringLiteral : public LeftHandSideExpression
public:
QMLJS_DECLARE_AST_NODE(StringLiteral)
StringLiteral(const QStringRef &v):
value (v) { kind = K; }
StringLiteral(const QStringView &v)
: value(v)
{
kind = K;
}
void accept0(BaseVisitor *visitor) override;
@@ -666,7 +673,7 @@ public:
{ return literalToken; }
// attributes:
QStringRef value;
QStringView value;
SourceLocation literalToken;
};
@@ -675,8 +682,11 @@ class QML_PARSER_EXPORT TemplateLiteral : public LeftHandSideExpression
public:
QMLJS_DECLARE_AST_NODE(TemplateLiteral)
TemplateLiteral(const QStringRef &str, const QStringRef &raw, ExpressionNode *e)
: value(str), rawValue(raw), expression(e), next(nullptr)
TemplateLiteral(const QStringView &str, const QStringView &raw, ExpressionNode *e)
: value(str)
, rawValue(raw)
, expression(e)
, next(nullptr)
{ kind = K; }
SourceLocation firstSourceLocation() const override
@@ -690,8 +700,8 @@ public:
void accept0(BaseVisitor *visitor) override;
QStringRef value;
QStringRef rawValue;
QStringView value;
QStringView rawValue;
ExpressionNode *expression;
TemplateLiteral *next;
SourceLocation literalToken;
@@ -702,8 +712,12 @@ class QML_PARSER_EXPORT RegExpLiteral: public LeftHandSideExpression
public:
QMLJS_DECLARE_AST_NODE(RegExpLiteral)
RegExpLiteral(const QStringRef &p, int f):
pattern (p), flags (f) { kind = K; }
RegExpLiteral(const QStringView &p, int f)
: pattern(p)
, flags(f)
{
kind = K;
}
void accept0(BaseVisitor *visitor) override;
@@ -714,7 +728,7 @@ public:
{ return literalToken; }
// attributes:
QStringRef pattern;
QStringView pattern;
int flags;
SourceLocation literalToken;
};
@@ -893,8 +907,13 @@ public:
: initializer(i), type(t)
{ kind = K; }
PatternElement(const QStringRef &n, TypeAnnotation *typeAnnotation = nullptr, ExpressionNode *i = nullptr, Type t = Binding)
: bindingIdentifier(n), initializer(i), type(t)
PatternElement(const QStringView &n,
TypeAnnotation *typeAnnotation = nullptr,
ExpressionNode *i = nullptr,
Type t = Binding)
: bindingIdentifier(n)
, initializer(i)
, type(t)
, typeAnnotation(typeAnnotation)
{
Q_ASSERT(t >= RestElement);
@@ -929,7 +948,7 @@ public:
// attributes
SourceLocation identifierToken;
QStringRef bindingIdentifier;
QStringView bindingIdentifier;
ExpressionNode *bindingTarget = nullptr;
ExpressionNode *initializer = nullptr;
Type type = Literal;
@@ -988,8 +1007,9 @@ public:
: PatternElement(i, t), name(name)
{ kind = K; }
PatternProperty(PropertyName *name, const QStringRef &n, ExpressionNode *i = nullptr)
: PatternElement(n, /*type annotation*/nullptr, i), name(name)
PatternProperty(PropertyName *name, const QStringView &n, ExpressionNode *i = nullptr)
: PatternElement(n, /*type annotation*/ nullptr, i)
, name(name)
{ kind = K; }
PatternProperty(PropertyName *name, Pattern *pattern, ExpressionNode *i = nullptr)
@@ -1058,15 +1078,18 @@ class QML_PARSER_EXPORT IdentifierPropertyName: public PropertyName
public:
QMLJS_DECLARE_AST_NODE(IdentifierPropertyName)
IdentifierPropertyName(const QStringRef &n):
id (n) { kind = K; }
IdentifierPropertyName(const QStringView &n)
: id(n)
{
kind = K;
}
void accept0(BaseVisitor *visitor) override;
QString asString() const override { return id.toString(); }
// attributes
QStringRef id;
QStringView id;
};
class QML_PARSER_EXPORT StringLiteralPropertyName: public PropertyName
@@ -1074,15 +1097,18 @@ class QML_PARSER_EXPORT StringLiteralPropertyName: public PropertyName
public:
QMLJS_DECLARE_AST_NODE(StringLiteralPropertyName)
StringLiteralPropertyName(const QStringRef &n):
id (n) { kind = K; }
StringLiteralPropertyName(const QStringView &n)
: id(n)
{
kind = K;
}
void accept0(BaseVisitor *visitor) override;
QString asString() const override { return id.toString(); }
// attributes
QStringRef id;
QStringView id;
};
class QML_PARSER_EXPORT NumericLiteralPropertyName: public PropertyName
@@ -1154,9 +1180,11 @@ class QML_PARSER_EXPORT FieldMemberExpression: public LeftHandSideExpression
public:
QMLJS_DECLARE_AST_NODE(FieldMemberExpression)
FieldMemberExpression(ExpressionNode *b, const QStringRef &n):
base (b), name (n)
{ kind = K; }
FieldMemberExpression(ExpressionNode *b, const QStringView &n)
: base(b)
, name(n)
{
kind = K; }
void accept0(BaseVisitor *visitor) override;
@@ -1168,7 +1196,7 @@ public:
// attributes
ExpressionNode *base;
QStringRef name;
QStringView name;
SourceLocation dotToken;
SourceLocation identifierToken;
};
@@ -1944,8 +1972,11 @@ class QML_PARSER_EXPORT ContinueStatement: public Statement
public:
QMLJS_DECLARE_AST_NODE(ContinueStatement)
ContinueStatement(const QStringRef &l = QStringRef()):
label (l) { kind = K; }
ContinueStatement(const QStringView &l = QStringView())
: label(l)
{
kind = K;
}
void accept0(BaseVisitor *visitor) override;
@@ -1956,7 +1987,7 @@ public:
{ return semicolonToken; }
// attributes
QStringRef label;
QStringView label;
SourceLocation continueToken;
SourceLocation identifierToken;
SourceLocation semicolonToken;
@@ -1967,8 +1998,11 @@ class QML_PARSER_EXPORT BreakStatement: public Statement
public:
QMLJS_DECLARE_AST_NODE(BreakStatement)
BreakStatement(const QStringRef &l):
label (l) { kind = K; }
BreakStatement(const QStringView &l)
: label(l)
{
kind = K;
}
void accept0(BaseVisitor *visitor) override;
@@ -1979,7 +2013,7 @@ public:
{ return semicolonToken; }
// attributes
QStringRef label;
QStringView label;
SourceLocation breakToken;
SourceLocation identifierToken;
SourceLocation semicolonToken;
@@ -2195,9 +2229,11 @@ class QML_PARSER_EXPORT LabelledStatement: public Statement
public:
QMLJS_DECLARE_AST_NODE(LabelledStatement)
LabelledStatement(const QStringRef &l, Statement *stmt):
label (l), statement (stmt)
{ kind = K; }
LabelledStatement(const QStringView &l, Statement *stmt)
: label(l)
, statement(stmt)
{
kind = K; }
void accept0(BaseVisitor *visitor) override;
@@ -2208,7 +2244,7 @@ public:
{ return statement->lastSourceLocation(); }
// attributes
QStringRef label;
QStringView label;
Statement *statement;
SourceLocation identifierToken;
SourceLocation colonToken;
@@ -2328,10 +2364,16 @@ class QML_PARSER_EXPORT FunctionExpression: public ExpressionNode
public:
QMLJS_DECLARE_AST_NODE(FunctionExpression)
FunctionExpression(const QStringRef &n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr):
name (n), formals (f), body (b),
typeAnnotation(typeAnnotation)
{ kind = K; }
FunctionExpression(const QStringView &n,
FormalParameterList *f,
StatementList *b,
TypeAnnotation *typeAnnotation = nullptr)
: name(n)
, formals(f)
, body(b)
, typeAnnotation(typeAnnotation)
{
kind = K; }
void accept0(BaseVisitor *visitor) override;
@@ -2344,7 +2386,7 @@ public:
FunctionExpression *asFunctionDefinition() override;
// attributes
QStringRef name;
QStringView name;
bool isArrowFunction = false;
bool isGenerator = false;
FormalParameterList *formals;
@@ -2363,9 +2405,13 @@ class QML_PARSER_EXPORT FunctionDeclaration: public FunctionExpression
public:
QMLJS_DECLARE_AST_NODE(FunctionDeclaration)
FunctionDeclaration(const QStringRef &n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr):
FunctionExpression(n, f, b, typeAnnotation)
{ kind = K; }
FunctionDeclaration(const QStringView &n,
FormalParameterList *f,
StatementList *b,
TypeAnnotation *typeAnnotation = nullptr)
: FunctionExpression(n, f, b, typeAnnotation)
{
kind = K; }
void accept0(BaseVisitor *visitor) override;
};
@@ -2460,9 +2506,12 @@ class QML_PARSER_EXPORT ClassExpression : public ExpressionNode
public:
QMLJS_DECLARE_AST_NODE(ClassExpression)
ClassExpression(const QStringRef &n, ExpressionNode *heritage, ClassElementList *elements)
: name(n), heritage(heritage), elements(elements)
{ kind = K; }
ClassExpression(const QStringView &n, ExpressionNode *heritage, ClassElementList *elements)
: name(n)
, heritage(heritage)
, elements(elements)
{
kind = K; }
void accept0(BaseVisitor *visitor) override;
@@ -2475,7 +2524,7 @@ public:
ClassExpression *asClassDefinition() override;
// attributes
QStringRef name;
QStringView name;
ExpressionNode *heritage;
ClassElementList *elements;
SourceLocation classToken;
@@ -2489,9 +2538,10 @@ class QML_PARSER_EXPORT ClassDeclaration: public ClassExpression
public:
QMLJS_DECLARE_AST_NODE(ClassDeclaration)
ClassDeclaration(const QStringRef &n, ExpressionNode *heritage, ClassElementList *elements)
ClassDeclaration(const QStringView &n, ExpressionNode *heritage, ClassElementList *elements)
: ClassExpression(n, heritage, elements)
{ kind = K; }
{
kind = K; }
void accept0(BaseVisitor *visitor) override;
};
@@ -2560,14 +2610,15 @@ class QML_PARSER_EXPORT ImportSpecifier: public Node
public:
QMLJS_DECLARE_AST_NODE(ImportSpecifier)
ImportSpecifier(const QStringRef &importedBinding)
ImportSpecifier(const QStringView &importedBinding)
: importedBinding(importedBinding)
{
kind = K;
}
ImportSpecifier(const QStringRef &identifier, const QStringRef &importedBinding)
: identifier(identifier), importedBinding(importedBinding)
ImportSpecifier(const QStringView &identifier, const QStringView &importedBinding)
: identifier(identifier)
, importedBinding(importedBinding)
{
kind = K;
}
@@ -2582,8 +2633,8 @@ public:
// attributes
SourceLocation identifierToken;
SourceLocation importedBindingToken;
QStringRef identifier;
QStringRef importedBinding;
QStringView identifier;
QStringView importedBinding;
};
class QML_PARSER_EXPORT ImportsList: public Node
@@ -2667,7 +2718,7 @@ class QML_PARSER_EXPORT NameSpaceImport: public Node
public:
QMLJS_DECLARE_AST_NODE(NameSpaceImport)
NameSpaceImport(const QStringRef &importedBinding)
NameSpaceImport(const QStringView &importedBinding)
: importedBinding(importedBinding)
{
kind = K;
@@ -2683,7 +2734,7 @@ public:
// attributes
SourceLocation starToken;
SourceLocation importedBindingToken;
QStringRef importedBinding;
QStringView importedBinding;
};
class QML_PARSER_EXPORT ImportClause: public Node
@@ -2691,7 +2742,7 @@ class QML_PARSER_EXPORT ImportClause: public Node
public:
QMLJS_DECLARE_AST_NODE(ImportClause)
ImportClause(const QStringRef &importedDefaultBinding)
ImportClause(const QStringView &importedDefaultBinding)
: importedDefaultBinding(importedDefaultBinding)
{
kind = K;
@@ -2709,14 +2760,14 @@ public:
kind = K;
}
ImportClause(const QStringRef &importedDefaultBinding, NameSpaceImport *nameSpaceImport)
ImportClause(const QStringView &importedDefaultBinding, NameSpaceImport *nameSpaceImport)
: importedDefaultBinding(importedDefaultBinding)
, nameSpaceImport(nameSpaceImport)
{
kind = K;
}
ImportClause(const QStringRef &importedDefaultBinding, NamedImports *namedImports)
ImportClause(const QStringView &importedDefaultBinding, NamedImports *namedImports)
: importedDefaultBinding(importedDefaultBinding)
, namedImports(namedImports)
{
@@ -2732,7 +2783,7 @@ public:
// attributes
SourceLocation importedDefaultBindingToken;
QStringRef importedDefaultBinding;
QStringView importedDefaultBinding;
NameSpaceImport *nameSpaceImport = nullptr;
NamedImports *namedImports = nullptr;
};
@@ -2742,7 +2793,7 @@ class QML_PARSER_EXPORT FromClause: public Node
public:
QMLJS_DECLARE_AST_NODE(FromClause)
FromClause(const QStringRef &moduleSpecifier)
FromClause(const QStringView &moduleSpecifier)
: moduleSpecifier(moduleSpecifier)
{
kind = K;
@@ -2759,7 +2810,7 @@ public:
// attributes
SourceLocation fromToken;
SourceLocation moduleSpecifierToken;
QStringRef moduleSpecifier;
QStringView moduleSpecifier;
};
class QML_PARSER_EXPORT ImportDeclaration: public Statement
@@ -2773,7 +2824,7 @@ public:
kind = K;
}
ImportDeclaration(const QStringRef &moduleSpecifier)
ImportDeclaration(const QStringView &moduleSpecifier)
: moduleSpecifier(moduleSpecifier)
{
kind = K;
@@ -2790,7 +2841,7 @@ public:
// attributes
SourceLocation importToken;
SourceLocation moduleSpecifierToken;
QStringRef moduleSpecifier;
QStringView moduleSpecifier;
ImportClause *importClause = nullptr;
FromClause *fromClause = nullptr;
};
@@ -2800,14 +2851,16 @@ class QML_PARSER_EXPORT ExportSpecifier: public Node
public:
QMLJS_DECLARE_AST_NODE(ExportSpecifier)
ExportSpecifier(const QStringRef &identifier)
: identifier(identifier), exportedIdentifier(identifier)
ExportSpecifier(const QStringView &identifier)
: identifier(identifier)
, exportedIdentifier(identifier)
{
kind = K;
}
ExportSpecifier(const QStringRef &identifier, const QStringRef &exportedIdentifier)
: identifier(identifier), exportedIdentifier(exportedIdentifier)
ExportSpecifier(const QStringView &identifier, const QStringView &exportedIdentifier)
: identifier(identifier)
, exportedIdentifier(exportedIdentifier)
{
kind = K;
}
@@ -2822,8 +2875,8 @@ public:
// attributes
SourceLocation identifierToken;
SourceLocation exportedIdentifierToken;
QStringRef identifier;
QStringRef exportedIdentifier;
QStringView identifier;
QStringView exportedIdentifier;
};
class QML_PARSER_EXPORT ExportsList: public Node
@@ -2994,8 +3047,9 @@ class QML_PARSER_EXPORT UiImport: public Node
public:
QMLJS_DECLARE_AST_NODE(UiImport)
UiImport(const QStringRef &fileName)
: fileName(fileName), importUri(nullptr)
UiImport(const QStringView &fileName)
: fileName(fileName)
, importUri(nullptr)
{ kind = K; }
UiImport(UiQualifiedId *uri)
@@ -3011,9 +3065,9 @@ public:
{ return semicolonToken; }
// attributes
QStringRef fileName;
QStringView fileName;
UiQualifiedId *importUri;
QStringRef importId;
QStringView importId;
SourceLocation importToken;
SourceLocation fileNameToken;
SourceLocation asToken;
@@ -3076,7 +3130,7 @@ class QML_PARSER_EXPORT UiPragma: public Node
public:
QMLJS_DECLARE_AST_NODE(UiPragma)
UiPragma(QStringRef name)
UiPragma(QStringView name)
: name(name)
{ kind = K; }
@@ -3089,7 +3143,7 @@ public:
{ return semicolonToken; }
// attributes
QStringRef name;
QStringView name;
SourceLocation pragmaToken;
SourceLocation semicolonToken;
};
@@ -3099,8 +3153,8 @@ class QML_PARSER_EXPORT UiRequired: public Node
public:
QMLJS_DECLARE_AST_NODE(UiRequired)
UiRequired(QStringRef name)
:name(name)
UiRequired(QStringView name)
: name(name)
{ kind = K; }
void accept0(BaseVisitor *visitor) override;
@@ -3111,7 +3165,7 @@ public:
SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
QStringRef name;
QStringView name;
SourceLocation requiredToken;
SourceLocation semicolonToken;
};
@@ -3265,12 +3319,16 @@ class QML_PARSER_EXPORT UiParameterList: public Node
public:
QMLJS_DECLARE_AST_NODE(UiParameterList)
UiParameterList(UiQualifiedId *t, const QStringRef &n):
type (t), name (n), next (this)
{ kind = K; }
UiParameterList(UiQualifiedId *t, const QStringView &n)
: type(t)
, name(n)
, next(this)
{
kind = K; }
UiParameterList(UiParameterList *previous, UiQualifiedId *t, const QStringRef &n):
type (t), name (n)
UiParameterList(UiParameterList *previous, UiQualifiedId *t, const QStringView &n)
: type(t)
, name(n)
{
kind = K;
next = previous->next;
@@ -3297,7 +3355,7 @@ public:
// attributes
UiQualifiedId *type;
QStringRef name;
QStringView name;
UiParameterList *next;
SourceLocation commaToken;
SourceLocation propertyTypeToken;
@@ -3310,15 +3368,26 @@ class QML_PARSER_EXPORT UiPublicMember: public UiObjectMember
public:
QMLJS_DECLARE_AST_NODE(UiPublicMember)
UiPublicMember(UiQualifiedId *memberType,
const QStringRef &name)
: type(Property), memberType(memberType), name(name), statement(nullptr), binding(nullptr), isDefaultMember(false), isReadonlyMember(false), parameters(nullptr)
UiPublicMember(UiQualifiedId *memberType, const QStringView &name)
: type(Property)
, memberType(memberType)
, name(name)
, statement(nullptr)
, binding(nullptr)
, isDefaultMember(false)
, isReadonlyMember(false)
, parameters(nullptr)
{ kind = K; }
UiPublicMember(UiQualifiedId *memberType,
const QStringRef &name,
Statement *statement)
: type(Property), memberType(memberType), name(name), statement(statement), binding(nullptr), isDefaultMember(false), isReadonlyMember(false), parameters(nullptr)
UiPublicMember(UiQualifiedId *memberType, const QStringView &name, Statement *statement)
: type(Property)
, memberType(memberType)
, name(name)
, statement(statement)
, binding(nullptr)
, isDefaultMember(false)
, isReadonlyMember(false)
, parameters(nullptr)
{ kind = K; }
void accept0(BaseVisitor *visitor) override;
@@ -3347,9 +3416,9 @@ public:
// attributes
enum { Signal, Property } type;
QStringRef typeModifier;
QStringView typeModifier;
UiQualifiedId *memberType;
QStringRef name;
QStringView name;
Statement *statement; // initialized with a JS expression
UiObjectMember *binding; // initialized with a QML object or array.
bool isDefaultMember;
@@ -3396,8 +3465,9 @@ class QML_PARSER_EXPORT UiInlineComponent: public UiObjectMember
public:
QMLJS_DECLARE_AST_NODE(UiInlineComponent)
UiInlineComponent(const QStringRef& inlineComponentName, UiObjectDefinition* inlineComponent)
: name(inlineComponentName), component(inlineComponent)
UiInlineComponent(const QStringView &inlineComponentName, UiObjectDefinition *inlineComponent)
: name(inlineComponentName)
, component(inlineComponent)
{ kind = K; }
SourceLocation lastSourceLocation() const override
@@ -3409,7 +3479,7 @@ public:
void accept0(BaseVisitor *visitor) override;
// attributes
QStringRef name;
QStringView name;
UiObjectDefinition* component;
SourceLocation componentToken;
};
@@ -3542,11 +3612,13 @@ class QML_PARSER_EXPORT UiEnumMemberList: public Node
{
QMLJS_DECLARE_AST_NODE(UiEnumMemberList)
public:
UiEnumMemberList(const QStringRef &member, double v = 0.0)
: next(this), member(member), value(v)
UiEnumMemberList(const QStringView &member, double v = 0.0)
: next(this)
, member(member)
, value(v)
{ kind = K; }
UiEnumMemberList(UiEnumMemberList *previous, const QStringRef &member)
UiEnumMemberList(UiEnumMemberList *previous, const QStringView &member)
: member(member)
{
kind = K;
@@ -3555,8 +3627,9 @@ public:
value = previous->value + 1;
}
UiEnumMemberList(UiEnumMemberList *previous, const QStringRef &member, double v)
: member(member), value(v)
UiEnumMemberList(UiEnumMemberList *previous, const QStringView &member, double v)
: member(member)
, value(v)
{
kind = K;
next = previous->next;
@@ -3583,7 +3656,7 @@ public:
// attributes
UiEnumMemberList *next;
QStringRef member;
QStringView member;
double value;
SourceLocation memberToken;
SourceLocation valueToken;
@@ -3594,8 +3667,7 @@ class QML_PARSER_EXPORT UiEnumDeclaration: public UiObjectMember
public:
QMLJS_DECLARE_AST_NODE(UiEnumDeclaration)
UiEnumDeclaration(const QStringRef &name,
UiEnumMemberList *members)
UiEnumDeclaration(const QStringView &name, UiEnumMemberList *members)
: name(name)
, members(members)
{ kind = K; }
@@ -3611,7 +3683,7 @@ public:
// attributes
SourceLocation enumToken;
SourceLocation rbraceToken;
QStringRef name;
QStringView name;
UiEnumMemberList *members;
};

View File

@@ -26,9 +26,11 @@
#include "qmljsengine_p.h"
#include "qmljsglobal_p.h"
#include <QtCore/qnumeric.h>
#include <QtCore/qhash.h>
#include <utils/porting.h>
#include <QtCore/qdebug.h>
#include <QtCore/qhash.h>
#include <QtCore/qnumeric.h>
QT_QML_BEGIN_NAMESPACE
@@ -129,14 +131,14 @@ void Engine::setDirectives(Directives *directives)
MemoryPool *Engine::pool()
{ return &_pool; }
QStringRef Engine::newStringRef(const QString &text)
QStringView Engine::newStringRef(const QString &text)
{
const int pos = _extraCode.length();
_extraCode += text;
return _extraCode.midRef(pos, text.length());
return Utils::midView(_extraCode, pos, text.length());
}
QStringRef Engine::newStringRef(const QChar *chars, int size)
QStringView Engine::newStringRef(const QChar *chars, int size)
{ return newStringRef(QString(chars, size)); }
} // end of namespace QmlJS

View File

@@ -105,10 +105,15 @@ public:
MemoryPool *pool();
inline QStringRef midRef(int position, int size) { return _code.midRef(position, size); }
inline QStringView midRef(int position, int size)
{
if (position + size > _code.size())
return QStringView(_code).mid(position);
return QStringView(_code).mid(position, size);
}
QStringRef newStringRef(const QString &s);
QStringRef newStringRef(const QChar *chars, int size);
QStringView newStringRef(const QString &s);
QStringView newStringRef(const QChar *chars, int size);
};
double integerFromString(const char *buf, int size, int radix);

View File

@@ -3,8 +3,9 @@
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the

View File

@@ -124,8 +124,8 @@ void Lexer::setCode(const QString &code, int lineno, bool qmlMode)
_tokenText.clear();
_tokenText.reserve(1024);
_errorMessage.clear();
_tokenSpell = QStringRef();
_rawString = QStringRef();
_tokenSpell = QStringView();
_rawString = QStringView();
_codePtr = code.unicode();
_endPtr = _codePtr + code.length();
@@ -248,70 +248,70 @@ int Lexer::lex()
const int previousTokenKind = _tokenKind;
again:
_tokenSpell = QStringRef();
_rawString = QStringRef();
_tokenKind = scanToken();
_tokenLength = _codePtr - _tokenStartPtr - 1;
_tokenSpell = QStringView();
_rawString = QStringView();
_tokenKind = scanToken();
_tokenLength = _codePtr - _tokenStartPtr - 1;
_delimited = false;
_restrictedKeyword = false;
_followsClosingBrace = (previousTokenKind == T_RBRACE);
_delimited = false;
_restrictedKeyword = false;
_followsClosingBrace = (previousTokenKind == T_RBRACE);
// update the flags
switch (_tokenKind) {
case T_LBRACE:
if (_bracesCount > 0)
++_bracesCount;
Q_FALLTHROUGH();
case T_SEMICOLON:
_importState = ImportState::NoQmlImport;
Q_FALLTHROUGH();
case T_QUESTION:
case T_COLON:
case T_TILDE:
_delimited = true;
break;
case T_AUTOMATIC_SEMICOLON:
case T_AS:
_importState = ImportState::NoQmlImport;
Q_FALLTHROUGH();
default:
if (isBinop(_tokenKind))
_delimited = true;
break;
// update the flags
switch (_tokenKind) {
case T_LBRACE:
if (_bracesCount > 0)
++_bracesCount;
Q_FALLTHROUGH();
case T_SEMICOLON:
_importState = ImportState::NoQmlImport;
Q_FALLTHROUGH();
case T_QUESTION:
case T_COLON:
case T_TILDE:
_delimited = true;
break;
case T_AUTOMATIC_SEMICOLON:
case T_AS:
_importState = ImportState::NoQmlImport;
Q_FALLTHROUGH();
default:
if (isBinop(_tokenKind))
_delimited = true;
break;
case T_IMPORT:
if (qmlMode() || (_handlingDirectives && previousTokenKind == T_DOT))
_importState = ImportState::SawImport;
if (isBinop(_tokenKind))
_delimited = true;
break;
case T_IMPORT:
if (qmlMode() || (_handlingDirectives && previousTokenKind == T_DOT))
_importState = ImportState::SawImport;
if (isBinop(_tokenKind))
_delimited = true;
break;
case T_IF:
case T_FOR:
case T_WHILE:
case T_WITH:
_parenthesesState = CountParentheses;
_parenthesesCount = 0;
break;
case T_IF:
case T_FOR:
case T_WHILE:
case T_WITH:
_parenthesesState = CountParentheses;
_parenthesesCount = 0;
break;
case T_ELSE:
case T_DO:
_parenthesesState = BalancedParentheses;
break;
case T_ELSE:
case T_DO:
_parenthesesState = BalancedParentheses;
break;
case T_CONTINUE:
case T_BREAK:
case T_RETURN:
case T_YIELD:
case T_THROW:
_restrictedKeyword = true;
break;
case T_RBRACE:
if (_bracesCount > 0)
--_bracesCount;
if (_bracesCount == 0)
goto again;
case T_CONTINUE:
case T_BREAK:
case T_RETURN:
case T_YIELD:
case T_THROW:
_restrictedKeyword = true;
break;
case T_RBRACE:
if (_bracesCount > 0)
--_bracesCount;
if (_bracesCount == 0)
goto again;
} // switch
// update the parentheses state

View File

@@ -150,8 +150,8 @@ public:
int tokenStartLine() const { return _tokenLine; }
int tokenStartColumn() const { return _tokenColumn; }
inline QStringRef tokenSpell() const { return _tokenSpell; }
inline QStringRef rawString() const { return _rawString; }
inline QStringView tokenSpell() const { return _tokenSpell; }
inline QStringView rawString() const { return _rawString; }
double tokenValue() const { return _tokenValue; }
QString tokenText() const;
@@ -204,8 +204,8 @@ private:
QString _code;
QString _tokenText;
QString _errorMessage;
QStringRef _tokenSpell;
QStringRef _rawString;
QStringView _tokenSpell;
QStringView _rawString;
const QChar *_codePtr;
const QChar *_endPtr;

View File

@@ -90,9 +90,10 @@ public:
template <typename Tp, typename... Ta> Tp *New(Ta... args)
{ return new (this->allocate(sizeof(Tp))) Tp(args...); }
QStringRef newString(const QString &string) {
QStringView newString(const QString &string)
{
strings.append(new QString(string));
return QStringRef(strings.last());
return QStringView(*strings.last());
}
private:

View File

@@ -102,7 +102,7 @@ static inline SourceLocation location(Lexer *lexer)
AST::UiQualifiedId *Parser::reparseAsQualifiedId(AST::ExpressionNode *expr)
{
QVarLengthArray<QStringRef, 4> nameIds;
QVarLengthArray<QStringView, 4> nameIds;
QVarLengthArray<SourceLocation, 4> locations;
AST::ExpressionNode *it = expr;
@@ -2655,7 +2655,7 @@ case 241: {
#line 3625 "qmljs.g"
case 483: {
AST::BreakStatement *node = new (pool) AST::BreakStatement(QStringRef());
AST::BreakStatement *node = new (pool) AST::BreakStatement(QStringView());
node->breakToken = loc(1);
node->semicolonToken = loc(2);
sym(1).Node = node;
@@ -2893,8 +2893,11 @@ case 241: {
case 512: {
if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList))
return false;
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringRef(), sym(3).FormalParameterList, sym(7).StatementList,
/*type annotation*/nullptr);
AST::FunctionDeclaration *node = new (pool)
AST::FunctionDeclaration(QStringView(),
sym(3).FormalParameterList,
sym(7).StatementList,
/*type annotation*/ nullptr);
node->functionToken = loc(1);
node->lparenToken = loc(2);
node->rparenToken = loc(4);
@@ -2925,8 +2928,11 @@ case 241: {
case 514: {
if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList))
return false;
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringRef(), sym(3).FormalParameterList, sym(7).StatementList,
/*type annotation*/nullptr);
AST::FunctionExpression *node = new (pool)
AST::FunctionExpression(QStringView(),
sym(3).FormalParameterList,
sym(7).StatementList,
/*type annotation*/ nullptr);
node->functionToken = loc(1);
node->lparenToken = loc(2);
node->rparenToken = loc(4);
@@ -2998,7 +3004,8 @@ case 241: {
ret->returnToken = sym(4).Node->firstSourceLocation();
ret->semicolonToken = sym(4).Node->lastSourceLocation();
AST::StatementList *statements = (new (pool) AST::StatementList(ret))->finish();
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringRef(), sym(1).FormalParameterList, statements);
AST::FunctionExpression *f = new (pool)
AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, statements);
f->isArrowFunction = true;
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation() : loc(1);
f->lbraceToken = sym(4).Node->firstSourceLocation();
@@ -3011,7 +3018,8 @@ case 241: {
#line 4037 "qmljs.g"
case 530: {
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringRef(), sym(1).FormalParameterList, sym(6).StatementList);
AST::FunctionExpression *f = new (pool)
AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, sym(6).StatementList);
f->isArrowFunction = true;
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation() : loc(1);
f->lbraceToken = loc(6);
@@ -3150,7 +3158,8 @@ case 241: {
#line 4198 "qmljs.g"
case 544: {
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringRef(), sym(3).FormalParameterList, sym(6).StatementList);
AST::FunctionDeclaration *node = new (pool)
AST::FunctionDeclaration(QStringView(), sym(3).FormalParameterList, sym(6).StatementList);
node->functionToken = loc(1);
node->lparenToken = loc(2);
node->rparenToken = loc(4);
@@ -3178,7 +3187,8 @@ case 241: {
#line 4228 "qmljs.g"
case 546: {
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringRef(), sym(3).FormalParameterList, sym(6).StatementList);
AST::FunctionExpression *node = new (pool)
AST::FunctionExpression(QStringView(), sym(3).FormalParameterList, sym(6).StatementList);
node->functionToken = loc(1);
node->lparenToken = loc(2);
node->rparenToken = loc(4);
@@ -3244,7 +3254,8 @@ case 241: {
#line 4303 "qmljs.g"
case 556: {
AST::ClassDeclaration *node = new (pool) AST::ClassDeclaration(QStringRef(), sym(2).Expression, sym(4).ClassElementList);
AST::ClassDeclaration *node = new (pool)
AST::ClassDeclaration(QStringView(), sym(2).Expression, sym(4).ClassElementList);
node->classToken = loc(1);
node->lbraceToken = loc(3);
node->rbraceToken = loc(5);
@@ -3254,7 +3265,8 @@ case 241: {
#line 4314 "qmljs.g"
case 557: {
AST::ClassExpression *node = new (pool) AST::ClassExpression(QStringRef(), sym(2).Expression, sym(4).ClassElementList);
AST::ClassExpression *node = new (pool)
AST::ClassExpression(QStringView(), sym(2).Expression, sym(4).ClassElementList);
node->classToken = loc(1);
node->lbraceToken = loc(3);
node->rbraceToken = loc(5);

View File

@@ -207,10 +207,10 @@ protected:
inline Value &sym(int index)
{ return sym_stack [tos + index - 1]; }
inline QStringRef &stringRef(int index)
inline QStringView &stringRef(int index)
{ return string_stack [tos + index - 1]; }
inline QStringRef &rawStringRef(int index)
inline QStringView &rawStringRef(int index)
{ return rawString_stack [tos + index - 1]; }
inline SourceLocation &loc(int index)
@@ -248,8 +248,8 @@ protected:
Value *sym_stack = nullptr;
int *state_stack = nullptr;
SourceLocation *location_stack = nullptr;
QVector<QStringRef> string_stack;
QVector<QStringRef> rawString_stack;
QVector<QStringView> string_stack;
QVector<QStringView> rawString_stack;
AST::Node *program = nullptr;
@@ -260,14 +260,14 @@ protected:
int token;
double dval;
SourceLocation loc;
QStringRef spell;
QStringRef raw;
QStringView spell;
QStringView raw;
};
int yytoken = -1;
double yylval = 0.;
QStringRef yytokenspell;
QStringRef yytokenraw;
QStringView yytokenspell;
QStringView yytokenraw;
SourceLocation yylloc;
SourceLocation yyprevlloc;

View File

@@ -152,15 +152,13 @@ void QmlBundle::printEscaped(QTextStream &s, const QString &str)
iEnd = str.constEnd();
while (i != iEnd) {
if ((*i) != QLatin1Char('"')) {
s << QStringRef(&str, static_cast<int>(iLast - str.constBegin())
, static_cast<int>(i - iLast) ).toString()
s << str.mid(static_cast<int>(iLast - str.constBegin()), static_cast<int>(i - iLast))
<< QLatin1Char('\\');
iLast = i;
}
++i;
}
s << QStringRef(&str, static_cast<int>(iLast - str.constBegin())
, static_cast<int>(i - iLast) ).toString();
s << str.mid(static_cast<int>(iLast - str.constBegin()), static_cast<int>(i - iLast));
}
void QmlBundle::writeTrie(QTextStream &stream, const Trie &t, const QString &indent) {

View File

@@ -831,10 +831,10 @@ void Check::endVisit(UiObjectInitializer *)
m_propertyStack.pop();
m_typeStack.pop();
UiObjectDefinition *objectDefinition = cast<UiObjectDefinition *>(parent());
if (objectDefinition && objectDefinition->qualifiedTypeNameId->name == "Component")
if (objectDefinition && objectDefinition->qualifiedTypeNameId->name == QLatin1String("Component"))
m_idStack.pop();
UiObjectBinding *objectBinding = cast<UiObjectBinding *>(parent());
if (objectBinding && objectBinding->qualifiedTypeNameId->name == "Component")
if (objectBinding && objectBinding->qualifiedTypeNameId->name == QLatin1String("Component"))
m_idStack.pop();
}
@@ -1028,7 +1028,7 @@ void Check::visitQmlObject(Node *ast, UiQualifiedId *typeId,
bool Check::visit(UiScriptBinding *ast)
{
// special case for id property
if (ast->qualifiedId->name == "id" && !ast->qualifiedId->next) {
if (ast->qualifiedId->name == QLatin1String("id") && !ast->qualifiedId->next) {
if (! ast->statement)
return false;
@@ -1125,20 +1125,20 @@ bool Check::visit(UiPublicMember *ast)
{
if (ast->type == UiPublicMember::Property) {
if (ast->defaultToken.isValid() || ast->readonlyToken.isValid()) {
const QStringRef typeName = ast->memberType->name;
const QStringView typeName = ast->memberType->name;
if (!typeName.isEmpty() && typeName.at(0).isLower()) {
const QString typeNameS = typeName.toString();
if (!isValidBuiltinPropertyType(typeNameS))
addMessage(ErrInvalidPropertyType, ast->typeToken, typeNameS);
}
const QStringRef name = ast->name;
const QStringView name = ast->name;
if (name == "data")
if (name == QLatin1String("data"))
addMessage(ErrInvalidPropertyName, ast->identifierToken, name.toString());
// warn about dubious use of var/variant
if (typeName == "variant" || typeName == "var") {
if (typeName == QLatin1String("variant") || typeName == QLatin1String("var")) {
Evaluate evaluator(&_scopeChain);
const Value *init = evaluator(ast->statement);
QString preferredType;
@@ -1666,16 +1666,16 @@ bool Check::visit(NewMemberExpression *ast)
// check for Number, Boolean, etc constructor usage
if (IdentifierExpression *idExp = cast<IdentifierExpression *>(ast->base)) {
const QStringRef name = idExp->name;
if (name == "Number") {
const QStringView name = idExp->name;
if (name == QLatin1String("Number")) {
addMessage(WarnNumberConstructor, idExp->identifierToken);
} else if (name == "Boolean") {
} else if (name == QLatin1String("Boolean")) {
addMessage(WarnBooleanConstructor, idExp->identifierToken);
} else if (name == "String") {
} else if (name == QLatin1String("String")) {
addMessage(WarnStringConstructor, idExp->identifierToken);
} else if (name == "Object") {
} else if (name == QLatin1String("Object")) {
addMessage(WarnObjectConstructor, idExp->identifierToken);
} else if (name == "Array") {
} else if (name == QLatin1String("Array")) {
bool ok = false;
if (ast->arguments && ast->arguments->expression && !ast->arguments->next) {
Evaluate evaluate(&_scopeChain);
@@ -1685,7 +1685,7 @@ bool Check::visit(NewMemberExpression *ast)
}
if (!ok)
addMessage(WarnArrayConstructor, idExp->identifierToken);
} else if (name == "Function") {
} else if (name == QLatin1String("Function")) {
addMessage(WarnFunctionConstructor, idExp->identifierToken);
}
}

View File

@@ -25,6 +25,8 @@
#include "qmljscodeformatter.h"
#include <utils/porting.h>
#include <QLoggingCategory>
#include <QMetaEnum>
#include <QTextBlock>
@@ -205,11 +207,14 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
turnInto(property_maybe_initializer);
break;
case property_list_open:
if (m_currentLine.midRef(m_currentToken.begin(), m_currentToken.length) == QLatin1String(">"))
case property_list_open: {
const QStringView tok = Utils::midView(m_currentLine,
m_currentToken.begin(),
m_currentToken.length);
if (tok == QLatin1String(">"))
turnInto(property_name);
break;
}
case property_maybe_initializer:
switch (kind) {
case Colon: turnInto(binding_assignment); break;
@@ -846,9 +851,9 @@ int CodeFormatter::column(int index) const
return col;
}
QStringRef CodeFormatter::currentTokenText() const
QStringView CodeFormatter::currentTokenText() const
{
return m_currentLine.midRef(m_currentToken.begin(), m_currentToken.length);
return Utils::midView(m_currentLine, m_currentToken.begin(), m_currentToken.length);
}
void CodeFormatter::turnInto(int newState)
@@ -922,7 +927,7 @@ int CodeFormatter::tokenizeBlock(const QTextBlock &block)
CodeFormatter::TokenKind CodeFormatter::extendedTokenKind(const QmlJS::Token &token) const
{
const int kind = token.kind;
QStringRef text = m_currentLine.midRef(token.begin(), token.length);
const QStringView text = Utils::midView(m_currentLine, token.begin(), token.length);
if (kind == Identifier) {
if (text == QLatin1String("as"))

View File

@@ -284,7 +284,7 @@ private:
void saveCurrentState(const QTextBlock &block);
void restoreCurrentState(const QTextBlock &block);
QStringRef currentTokenText() const;
QStringView currentTokenText() const;
int tokenizeBlock(const QTextBlock &block);

View File

@@ -26,6 +26,8 @@
#include "qmljscompletioncontextfinder.h"
#include "qmljsscanner.h"
#include <utils/porting.h>
#include <QTextDocument>
#include <QStringList>
@@ -161,7 +163,7 @@ void CompletionContextFinder::checkBinding()
break;
case Token::Identifier: {
QStringRef tokenString = yyLine->midRef(token.begin(), token.length);
const QStringView tokenString = Utils::midView(*yyLine, token.begin(), token.length);
dotExpected = false;
if (identifierExpected) {
m_bindingPropertyName.prepend(tokenString.toString());
@@ -231,7 +233,7 @@ void CompletionContextFinder::checkImport()
switch (token.kind) {
case Token::Identifier: {
const QStringRef tokenString = yyLine->midRef(token.begin(), token.length);
const QStringView tokenString = Utils::midView(*yyLine, token.begin(), token.length);
if (tokenString == QLatin1String("as")) {
isInLibVersionImport = 0;
if (state == Unknown) {
@@ -270,7 +272,7 @@ void CompletionContextFinder::checkImport()
case Token::Number:
if (state == Unknown || (state & ExpectVersion)) {
state = ExpectAnyTarget;
libVersionImport.prepend(yyLine->midRef(token.begin(), token.length).toString());
libVersionImport.prepend(yyLine->mid(token.begin(), token.length));
libVersionImport.prepend(QLatin1String(" "));
if (isInLibVersionImport == -1)
isInLibVersionImport = 1;

View File

@@ -313,7 +313,7 @@ ImportMatchStrength ImportKey::matchImport(const ImportKey &o, const ViewerConte
}
if (!p1.startsWith(QLatin1Char('+')))
return QList<int>();
QStringRef selectorAtt(&p1, 1, p1.size()-1);
const QStringView selectorAtt(p1.constData() + 1, p1.size() - 1);
while (iSelector < nSelectors) {
if (selectorAtt == vContext.selectors.at(iSelector))
break;

View File

@@ -246,8 +246,8 @@ CppComponentValue::CppComponentValue(FakeMetaObject::ConstPtr metaObject, const
CppComponentValue::~CppComponentValue()
{
delete m_metaSignatures.load();
delete m_signalScopes.load();
delete m_metaSignatures.loadRelaxed();
delete m_signalScopes.loadRelaxed();
}
static QString generatedSlotName(const QString &base)
@@ -261,7 +261,7 @@ static QString generatedSlotName(const QString &base)
if (c != QLatin1Char('_'))
break;
}
slotName += base.midRef(firstChar);
slotName += base.mid(firstChar);
return slotName;
}
@@ -285,7 +285,7 @@ void CppComponentValue::processMembers(MemberProcessor *processor) const
QSet<QString> explicitSignals;
// make MetaFunction instances lazily when first needed
QList<const Value *> *signatures = m_metaSignatures.load();
QList<const Value *> *signatures = m_metaSignatures.loadRelaxed();
if (!signatures) {
signatures = new QList<const Value *>;
signatures->reserve(m_metaObject->methodCount());
@@ -293,7 +293,7 @@ void CppComponentValue::processMembers(MemberProcessor *processor) const
signatures->append(new MetaFunction(m_metaObject->method(index), valueOwner()));
if (!m_metaSignatures.testAndSetOrdered(nullptr, signatures)) {
delete signatures;
signatures = m_metaSignatures.load();
signatures = m_metaSignatures.loadRelaxed();
}
}
@@ -523,7 +523,7 @@ const QmlEnumValue *CppComponentValue::getEnumValue(const QString &typeName, con
const ObjectValue *CppComponentValue::signalScope(const QString &signalName) const
{
QHash<QString, const ObjectValue *> *scopes = m_signalScopes.load();
QHash<QString, const ObjectValue *> *scopes = m_signalScopes.loadRelaxed();
if (!scopes) {
scopes = new QHash<QString, const ObjectValue *>;
// usually not all methods are signals
@@ -549,7 +549,7 @@ const ObjectValue *CppComponentValue::signalScope(const QString &signalName) con
}
if (!m_signalScopes.testAndSetOrdered(nullptr, scopes)) {
delete scopes;
scopes = m_signalScopes.load();
scopes = m_signalScopes.loadRelaxed();
}
}
@@ -1055,7 +1055,7 @@ void ObjectValue::setMember(const QString &name, const Value *value)
m_members[name].value = value;
}
void ObjectValue::setMember(const QStringRef &name, const Value *value)
void ObjectValue::setMember(const QStringView &name, const Value *value)
{
m_members[name.toString()].value = value;
}

View File

@@ -508,7 +508,7 @@ public:
virtual void processMembers(MemberProcessor *processor) const;
virtual void setMember(const QString &name, const Value *value);
virtual void setMember(const QStringRef &name, const Value *value);
virtual void setMember(const QStringView &name, const Value *value);
virtual void setPropertyInfo(const QString &name, const PropertyInfo &propertyInfo);
virtual void removeMember(const QString &name);

View File

@@ -64,6 +64,8 @@
#include <qmljs/qmljslineinfo.h>
#include <qmljs/qmljsscanner.h>
#include <utils/porting.h>
using namespace QmlJS;
/*
@@ -128,7 +130,7 @@ QString LineInfo::trimmedCodeLine(const QString &t)
QString trimmed;
int previousTokenEnd = 0;
foreach (const Token &token, yyLinizerState.tokens) {
trimmed.append(t.midRef(previousTokenEnd, token.begin() - previousTokenEnd));
trimmed.append(t.mid(previousTokenEnd, token.begin() - previousTokenEnd));
if (token.is(Token::String)) {
for (int i = 0; i < token.length; ++i)
@@ -139,7 +141,7 @@ QString LineInfo::trimmedCodeLine(const QString &t)
trimmed.append(QLatin1Char(' '));
} else {
trimmed.append(tokenText(token));
trimmed.append(tokenText(token).toString());
}
previousTokenEnd = token.end();
@@ -191,7 +193,7 @@ QString LineInfo::trimmedCodeLine(const QString &t)
// "a = Somevar\n{" in a JS context
// What's done here does not cover all cases, but goes as far as possible
// with the limited information that's available.
const QStringRef text = tokenText(last);
const QStringView text = tokenText(last);
if (yyLinizerState.leftBraceFollows && !text.isEmpty() && text.at(0).isUpper()) {
int i = index;
@@ -277,9 +279,9 @@ Token LineInfo::lastToken() const
return Token();
}
QStringRef LineInfo::tokenText(const Token &token) const
QStringView LineInfo::tokenText(const Token &token) const
{
return yyLinizerState.line.midRef(token.offset, token.length);
return Utils::midView(yyLinizerState.line, token.offset, token.length);
}
/*
@@ -457,7 +459,7 @@ bool LineInfo::matchBracelessControlStatement()
const Token &tk = yyLinizerState.tokens.at(tokenIndex - 1);
if (tk.is(Token::Keyword)) {
const QStringRef text = tokenText(tk);
const QStringView text = tokenText(tk);
/*
We have

View File

@@ -69,7 +69,7 @@ protected:
bool matchBracelessControlStatement();
Token lastToken() const;
QStringRef tokenText(const Token &token) const;
QStringView tokenText(const Token &token) const;
protected:
struct LinizerState

View File

@@ -201,7 +201,7 @@ QLinearGradient PropertyReader::parseGradient(const QString &propertyName, bool
if (UiObjectBinding* objectBinding = cast<UiObjectBinding *>(member)) {
UiObjectInitializer *initializer = objectBinding->initializer;
const QString objectPropertyName = objectBinding->qualifiedId->name.toString();
const QStringRef typeName = objectBinding->qualifiedTypeNameId->name;
const QStringView typeName = objectBinding->qualifiedTypeNameId->name;
if (objectPropertyName == propertyName && typeName.contains(QLatin1String("Gradient"))) {
QLinearGradient gradient;
QVector<QGradientStop> stops;

View File

@@ -33,6 +33,7 @@
#include <QFile>
#include <QLoggingCategory>
#include <QVariant>
static Q_LOGGING_CATEGORY(simpleReaderLog, "qtc.qmljs.simpleReader", QtWarningMsg)

View File

@@ -83,7 +83,7 @@ QColor QmlJS::toQColor(const QString &qmlColorString)
QColor color;
if (qmlColorString.size() == 9 && qmlColorString.at(0) == QLatin1Char('#')) {
bool ok;
const int alpha = qmlColorString.midRef(1, 2).toInt(&ok, 16);
const int alpha = qmlColorString.mid(1, 2).toInt(&ok, 16);
if (ok) {
const QString name = qmlColorString.at(0) + qmlColorString.right(6);
if (QColor::isValidColor(name)) {
@@ -106,7 +106,7 @@ QString QmlJS::toString(UiQualifiedId *qualifiedId, QChar delimiter)
if (iter != qualifiedId)
result += delimiter;
result += iter->name;
result += iter->name.toString();
}
return result;

View File

@@ -51,6 +51,7 @@ using StringView = QStringRef;
#else
using StringView = QStringView;
#endif
inline StringView make_stringview(const QString &s)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@@ -60,4 +61,18 @@ inline StringView make_stringview(const QString &s)
#endif
}
// QStringView::mid in Qt5 does not do bounds checking, in Qt6 it does
inline QStringView midView(const QString &s, int offset, int length)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (offset > s.size())
return {};
if (offset + length > s.size())
return QStringView(s).mid(offset);
return QStringView(s).mid(offset, length);
#else
return QStringView(s).mid(offset, length);
#endif
}
} // namespace Utils

View File

@@ -74,7 +74,7 @@ static bool isDerivedFromTestCase(QmlJS::AST::UiQualifiedId *id, const QmlJS::Do
if (auto prototype = val->prototype()) {
if (auto qmlPrototypeRef = prototype->asQmlPrototypeReference()) {
if (auto qmlTypeName = qmlPrototypeRef->qmlTypeName()) {
if (qmlTypeName->name == "TestCase") {
if (qmlTypeName->name == QLatin1String("TestCase")) {
if (auto astObjVal = val->asAstObjectValue())
return documentImportsQtTest(astObjVal->document());
}
@@ -87,9 +87,9 @@ static bool isDerivedFromTestCase(QmlJS::AST::UiQualifiedId *id, const QmlJS::Do
bool TestQmlVisitor::visit(QmlJS::AST::UiObjectDefinition *ast)
{
const QStringRef name = ast->qualifiedTypeNameId->name;
const QStringView name = ast->qualifiedTypeNameId->name;
m_objectIsTestStack.push(false);
if (name != "TestCase") {
if (name != QLatin1String("TestCase")) {
if (!isDerivedFromTestCase(ast->qualifiedTypeNameId, m_currentDoc, m_snapshot))
return true;
} else if (!documentImportsQtTest(m_currentDoc.data())) {
@@ -122,7 +122,7 @@ bool TestQmlVisitor::visit(QmlJS::AST::ExpressionStatement *ast)
bool TestQmlVisitor::visit(QmlJS::AST::UiScriptBinding *ast)
{
if (m_objectIsTestStack.top())
m_expectTestCaseName = ast->qualifiedId->name == "name";
m_expectTestCaseName = ast->qualifiedId->name == QLatin1String("name");
return m_expectTestCaseName;
}
@@ -137,24 +137,22 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
if (m_caseParseStack.isEmpty())
return false;
const QStringRef name = ast->name;
if (name.startsWith("test_")
|| name.startsWith("benchmark_")
|| name.endsWith("_data")
|| specialFunctions.contains(name.toString())) {
const QString name = ast->name.toString();
if (name.startsWith("test_") || name.startsWith("benchmark_") || name.endsWith("_data")
|| specialFunctions.contains(name)) {
const auto sourceLocation = ast->firstSourceLocation();
TestCodeLocationAndType locationAndType;
locationAndType.m_name = m_currentDoc->fileName();
locationAndType.m_line = sourceLocation.startLine;
locationAndType.m_column = sourceLocation.startColumn - 1;
if (specialFunctions.contains(name.toString()))
if (specialFunctions.contains(name))
locationAndType.m_type = TestTreeItem::TestSpecialFunction;
else if (name.endsWith("_data"))
locationAndType.m_type = TestTreeItem::TestDataFunction;
else
locationAndType.m_type = TestTreeItem::TestFunction;
const QString nameStr = name.toString();
const QString nameStr = name;
// identical test functions inside the same file are not working - will fail at runtime
if (!Utils::anyOf(m_caseParseStack.top().m_functions,
[nameStr, locationAndType](const QuickTestFunctionSpec func) {

View File

@@ -1203,7 +1203,7 @@ void TextToModelMerger::syncNode(ModelNode &modelNode,
if (property->type == AST::UiPublicMember::Signal)
continue; // QML designer doesn't support this yet.
const QStringRef astName = property->name;
const QStringView astName = property->name;
QString astValue;
if (property->statement)
astValue = textAt(context->doc(),

View File

@@ -27,6 +27,8 @@
#include <qmljs/qmljsscanner.h>
#include <utils/porting.h>
#include <QChar>
#include <QLatin1Char>
#include <QTextDocument>
@@ -119,7 +121,7 @@ static bool shouldInsertNewline(const QTextCursor &tc)
return false;
}
static bool isCompleteStringLiteral(const QStringRef &text)
static bool isCompleteStringLiteral(const QStringView &text)
{
if (text.length() < 2)
return false;
@@ -173,7 +175,7 @@ bool AutoCompleter::contextAllowsAutoBrackets(const QTextCursor &cursor,
case Token::String: {
const QString blockText = cursor.block().text();
const QStringRef tokenText = blockText.midRef(token.offset, token.length);
const QStringView tokenText = Utils::midView(blockText, token.offset, token.length);
QChar quote = tokenText.at(0);
// if a string literal doesn't start with a quote, it must be multiline
if (quote != QLatin1Char('"') && quote != QLatin1Char('\'')) {
@@ -217,7 +219,7 @@ bool AutoCompleter::contextAllowsAutoQuotes(const QTextCursor &cursor,
case Token::String: {
const QString blockText = cursor.block().text();
const QStringRef tokenText = blockText.midRef(token.offset, token.length);
const QStringView tokenText = Utils::midView(blockText, token.offset, token.length);
QChar quote = tokenText.at(0);
// if a string literal doesn't start with a quote, it must be multiline
if (quote != QLatin1Char('"') && quote != QLatin1Char('\'')) {

View File

@@ -411,7 +411,7 @@ protected:
{
UiQualifiedId *id = qualifiedTypeNameId(member);
if (id) {
const QStringRef &name = id->name;
const QStringView &name = id->name;
if (!name.isEmpty() && name.at(0).isUpper())
return true;
}
@@ -429,7 +429,7 @@ protected:
else if (script->qualifiedId->next)
return false;
const QStringRef &propertyName = script->qualifiedId->name;
const QStringView &propertyName = script->qualifiedId->name;
if (propertyName == QLatin1String("id"))
return true;

View File

@@ -89,7 +89,7 @@ protected:
QString text;
for (; id; id = id->next) {
if (!id->name.isEmpty())
text += id->name;
text += id->name.toString();
else
text += QLatin1Char('?');
@@ -174,7 +174,7 @@ protected:
QString text;
for (; id; id = id->next) {
if (!id->name.isEmpty())
text += id->name;
text += id->name.toString();
else
text += QLatin1Char('?');
@@ -294,12 +294,12 @@ protected:
init(&decl, ast);
decl.text.fill(QLatin1Char(' '), _depth);
decl.text += ast->name;
decl.text += ast->name.toString();
decl.text += QLatin1Char('(');
for (FormalParameterList *it = ast->formals; it; it = it->next) {
if (!it->element->bindingIdentifier.isEmpty())
decl.text += it->element->bindingIdentifier;
decl.text += it->element->bindingIdentifier.toString();
if (it->next)
decl.text += QLatin1String(", ");
@@ -319,7 +319,7 @@ protected:
Declaration decl;
decl.text.fill(QLatin1Char(' '), _depth);
decl.text += ast->bindingIdentifier;
decl.text += ast->bindingIdentifier.toString();
const SourceLocation first = ast->identifierToken;
decl.startLine = first.startLine;
@@ -342,12 +342,12 @@ protected:
init(&decl, ast);
decl.text.fill(QLatin1Char(' '), _depth);
decl.text += field->name;
decl.text += field->name.toString();
decl.text += QLatin1Char('(');
for (FormalParameterList *it = funcExpr->formals; it; it = it->next) {
if (!it->element->bindingIdentifier.isEmpty())
decl.text += it->element->bindingIdentifier;
decl.text += it->element->bindingIdentifier.toString();
if (it->next)
decl.text += QLatin1String(", ");

View File

@@ -27,6 +27,7 @@
#include <QSet>
#include <utils/porting.h>
#include <utils/qtcassert.h>
using namespace QmlJS;
@@ -75,7 +76,8 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
break;
case Token::Comment:
if (m_inMultilineComment && text.midRef(token.end() - 2, 2) == QLatin1String("*/")) {
if (m_inMultilineComment
&& Utils::midView(text, token.end() - 2, 2) == QLatin1String("*/")) {
onClosingParenthesis(QLatin1Char('-'), token.end() - 1, index == tokens.size()-1);
m_inMultilineComment = false;
} else if (!m_inMultilineComment
@@ -119,7 +121,7 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
if (!m_qmlEnabled)
break;
const QStringRef spell = text.midRef(token.offset, token.length);
const QStringView spell = Utils::midView(text, token.offset, token.length);
if (maybeQmlKeyword(spell)) {
// check the previous token
@@ -129,25 +131,25 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
break;
}
}
if (text.midRef(token.offset, token.length) == QLatin1String("enum")) {
if (Utils::midView(text, token.offset, token.length) == QLatin1String("enum")) {
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
break;
}
} else if (index > 0 && maybeQmlBuiltinType(spell)) {
const Token &previousToken = tokens.at(index - 1);
if (previousToken.is(Token::Identifier)
&& text.at(previousToken.offset) == QLatin1Char('p')
&& text.midRef(previousToken.offset, previousToken.length)
== QLatin1String("property")) {
&& text.at(previousToken.offset) == QLatin1Char('p')
&& Utils::midView(text, previousToken.offset, previousToken.length)
== QLatin1String("property")) {
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
break;
}
} else if (index == 1) {
const Token &previousToken = tokens.at(0);
if (previousToken.is(Token::Identifier)
&& text.at(previousToken.offset) == QLatin1Char('e')
&& text.midRef(previousToken.offset, previousToken.length)
== QLatin1String("enum")) {
&& text.at(previousToken.offset) == QLatin1Char('e')
&& Utils::midView(text, previousToken.offset, previousToken.length)
== QLatin1String("enum")) {
setFormat(token.offset, token.length, formatForCategory(C_ENUMERATION));
break;
}
@@ -200,7 +202,7 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
onBlockEnd(m_scanner.state());
}
bool QmlJSHighlighter::maybeQmlKeyword(const QStringRef &text) const
bool QmlJSHighlighter::maybeQmlKeyword(const QStringView &text) const
{
if (text.isEmpty())
return false;
@@ -226,7 +228,7 @@ bool QmlJSHighlighter::maybeQmlKeyword(const QStringRef &text) const
return false;
}
bool QmlJSHighlighter::maybeQmlBuiltinType(const QStringRef &text) const
bool QmlJSHighlighter::maybeQmlBuiltinType(const QStringView &text) const
{
if (text.isEmpty())
return false;

View File

@@ -56,8 +56,8 @@ protected:
void onOpeningParenthesis(QChar parenthesis, int pos, bool atStart);
void onClosingParenthesis(QChar parenthesis, int pos, bool atEnd);
bool maybeQmlKeyword(const QStringRef &text) const;
bool maybeQmlBuiltinType(const QStringRef &text) const;
bool maybeQmlKeyword(const QStringView &text) const;
bool maybeQmlBuiltinType(const QStringView &text) const;
private:
bool m_qmlEnabled;

View File

@@ -235,7 +235,7 @@ protected:
m_scopeBuilder.pop();
}
void processName(const QStringRef &name, SourceLocation location)
void processName(const QStringView &name, SourceLocation location)
{
if (name.isEmpty())
return;

View File

@@ -599,7 +599,7 @@ void QmlOutlineModel::leavePublicMember()
leaveNode();
}
static QString functionDisplayName(QStringRef name, AST::FormalParameterList *formals)
static QString functionDisplayName(QStringView name, AST::FormalParameterList *formals)
{
QString display;
@@ -1002,7 +1002,7 @@ QString QmlOutlineModel::asString(AST::UiQualifiedId *id)
QString text;
for (; id; id = id->next) {
if (!id->name.isEmpty())
text += id->name;
text += id->name.toString();
else
text += QLatin1Char('?');

View File

@@ -159,7 +159,7 @@ Node *SemanticInfo::declaringMemberNoProperties(int cursorPosition) const
AST::Node *node = rangeAt(cursorPosition);
if (auto objectDefinition = cast<const UiObjectDefinition*>(node)) {
const QStringRef name = objectDefinition->qualifiedTypeNameId->name;
const QStringView name = objectDefinition->qualifiedTypeNameId->name;
if (!name.isEmpty() && name.at(0).isLower()) {
QList<AST::Node *> path = rangePath(cursorPosition);
if (path.size() > 1)
@@ -170,7 +170,7 @@ Node *SemanticInfo::declaringMemberNoProperties(int cursorPosition) const
return path.at(path.size() - 3);
}
} else if (auto objectBinding = cast<const UiObjectBinding*>(node)) {
const QStringRef name = objectBinding->qualifiedTypeNameId->name;
const QStringView name = objectBinding->qualifiedTypeNameId->name;
if (name.contains(QLatin1String("Gradient"))) {
QList<AST::Node *> path = rangePath(cursorPosition);
if (path.size() > 1)