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(); analysis()->boostRanking();
const QStringRef literal = ast->value; const QStringView literal = ast->value;
const QString &pattern = m_schema->pattern(); const QString &pattern = m_schema->pattern();
if (!pattern.isEmpty()) { if (!pattern.isEmpty()) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -105,10 +105,15 @@ public:
MemoryPool *pool(); 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); QStringView newStringRef(const QString &s);
QStringRef newStringRef(const QChar *chars, int size); QStringView newStringRef(const QChar *chars, int size);
}; };
double integerFromString(const char *buf, int size, int radix); double integerFromString(const char *buf, int size, int radix);

View File

@@ -3,8 +3,9 @@
** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** 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 ** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in ** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the ** 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.clear();
_tokenText.reserve(1024); _tokenText.reserve(1024);
_errorMessage.clear(); _errorMessage.clear();
_tokenSpell = QStringRef(); _tokenSpell = QStringView();
_rawString = QStringRef(); _rawString = QStringView();
_codePtr = code.unicode(); _codePtr = code.unicode();
_endPtr = _codePtr + code.length(); _endPtr = _codePtr + code.length();
@@ -248,8 +248,8 @@ int Lexer::lex()
const int previousTokenKind = _tokenKind; const int previousTokenKind = _tokenKind;
again: again:
_tokenSpell = QStringRef(); _tokenSpell = QStringView();
_rawString = QStringRef(); _rawString = QStringView();
_tokenKind = scanToken(); _tokenKind = scanToken();
_tokenLength = _codePtr - _tokenStartPtr - 1; _tokenLength = _codePtr - _tokenStartPtr - 1;

View File

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

View File

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

View File

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

View File

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

View File

@@ -152,15 +152,13 @@ void QmlBundle::printEscaped(QTextStream &s, const QString &str)
iEnd = str.constEnd(); iEnd = str.constEnd();
while (i != iEnd) { while (i != iEnd) {
if ((*i) != QLatin1Char('"')) { if ((*i) != QLatin1Char('"')) {
s << QStringRef(&str, static_cast<int>(iLast - str.constBegin()) s << str.mid(static_cast<int>(iLast - str.constBegin()), static_cast<int>(i - iLast))
, static_cast<int>(i - iLast) ).toString()
<< QLatin1Char('\\'); << QLatin1Char('\\');
iLast = i; iLast = i;
} }
++i; ++i;
} }
s << QStringRef(&str, static_cast<int>(iLast - str.constBegin()) s << str.mid(static_cast<int>(iLast - str.constBegin()), static_cast<int>(i - iLast));
, static_cast<int>(i - iLast) ).toString();
} }
void QmlBundle::writeTrie(QTextStream &stream, const Trie &t, const QString &indent) { 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_propertyStack.pop();
m_typeStack.pop(); m_typeStack.pop();
UiObjectDefinition *objectDefinition = cast<UiObjectDefinition *>(parent()); UiObjectDefinition *objectDefinition = cast<UiObjectDefinition *>(parent());
if (objectDefinition && objectDefinition->qualifiedTypeNameId->name == "Component") if (objectDefinition && objectDefinition->qualifiedTypeNameId->name == QLatin1String("Component"))
m_idStack.pop(); m_idStack.pop();
UiObjectBinding *objectBinding = cast<UiObjectBinding *>(parent()); UiObjectBinding *objectBinding = cast<UiObjectBinding *>(parent());
if (objectBinding && objectBinding->qualifiedTypeNameId->name == "Component") if (objectBinding && objectBinding->qualifiedTypeNameId->name == QLatin1String("Component"))
m_idStack.pop(); m_idStack.pop();
} }
@@ -1028,7 +1028,7 @@ void Check::visitQmlObject(Node *ast, UiQualifiedId *typeId,
bool Check::visit(UiScriptBinding *ast) bool Check::visit(UiScriptBinding *ast)
{ {
// special case for id property // 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) if (! ast->statement)
return false; return false;
@@ -1125,20 +1125,20 @@ bool Check::visit(UiPublicMember *ast)
{ {
if (ast->type == UiPublicMember::Property) { if (ast->type == UiPublicMember::Property) {
if (ast->defaultToken.isValid() || ast->readonlyToken.isValid()) { 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()) { if (!typeName.isEmpty() && typeName.at(0).isLower()) {
const QString typeNameS = typeName.toString(); const QString typeNameS = typeName.toString();
if (!isValidBuiltinPropertyType(typeNameS)) if (!isValidBuiltinPropertyType(typeNameS))
addMessage(ErrInvalidPropertyType, ast->typeToken, 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()); addMessage(ErrInvalidPropertyName, ast->identifierToken, name.toString());
// warn about dubious use of var/variant // warn about dubious use of var/variant
if (typeName == "variant" || typeName == "var") { if (typeName == QLatin1String("variant") || typeName == QLatin1String("var")) {
Evaluate evaluator(&_scopeChain); Evaluate evaluator(&_scopeChain);
const Value *init = evaluator(ast->statement); const Value *init = evaluator(ast->statement);
QString preferredType; QString preferredType;
@@ -1666,16 +1666,16 @@ bool Check::visit(NewMemberExpression *ast)
// check for Number, Boolean, etc constructor usage // check for Number, Boolean, etc constructor usage
if (IdentifierExpression *idExp = cast<IdentifierExpression *>(ast->base)) { if (IdentifierExpression *idExp = cast<IdentifierExpression *>(ast->base)) {
const QStringRef name = idExp->name; const QStringView name = idExp->name;
if (name == "Number") { if (name == QLatin1String("Number")) {
addMessage(WarnNumberConstructor, idExp->identifierToken); addMessage(WarnNumberConstructor, idExp->identifierToken);
} else if (name == "Boolean") { } else if (name == QLatin1String("Boolean")) {
addMessage(WarnBooleanConstructor, idExp->identifierToken); addMessage(WarnBooleanConstructor, idExp->identifierToken);
} else if (name == "String") { } else if (name == QLatin1String("String")) {
addMessage(WarnStringConstructor, idExp->identifierToken); addMessage(WarnStringConstructor, idExp->identifierToken);
} else if (name == "Object") { } else if (name == QLatin1String("Object")) {
addMessage(WarnObjectConstructor, idExp->identifierToken); addMessage(WarnObjectConstructor, idExp->identifierToken);
} else if (name == "Array") { } else if (name == QLatin1String("Array")) {
bool ok = false; bool ok = false;
if (ast->arguments && ast->arguments->expression && !ast->arguments->next) { if (ast->arguments && ast->arguments->expression && !ast->arguments->next) {
Evaluate evaluate(&_scopeChain); Evaluate evaluate(&_scopeChain);
@@ -1685,7 +1685,7 @@ bool Check::visit(NewMemberExpression *ast)
} }
if (!ok) if (!ok)
addMessage(WarnArrayConstructor, idExp->identifierToken); addMessage(WarnArrayConstructor, idExp->identifierToken);
} else if (name == "Function") { } else if (name == QLatin1String("Function")) {
addMessage(WarnFunctionConstructor, idExp->identifierToken); addMessage(WarnFunctionConstructor, idExp->identifierToken);
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -508,7 +508,7 @@ public:
virtual void processMembers(MemberProcessor *processor) const; virtual void processMembers(MemberProcessor *processor) const;
virtual void setMember(const QString &name, const Value *value); 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 setPropertyInfo(const QString &name, const PropertyInfo &propertyInfo);
virtual void removeMember(const QString &name); virtual void removeMember(const QString &name);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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