diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-06-16 10:23:19 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-06-16 22:46:16 +0200 |
commit | 1b10ce6a08edbc2ac7e8fd7e97e3fc691f2081df (patch) | |
tree | 34ab485d1dd9435369709b5e77c11af6dec78c22 /src/qml/parser | |
parent | b65eee039092fa664e781cdd98a4bb5e66815218 (diff) |
Port QtDeclarative from QStringRef to QStringView
Task-number: QTBUG-84319
Change-Id: I2dcfb8a2db98282c7a1acdad1e6f4f949f26df15
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/qml/parser')
-rw-r--r-- | src/qml/parser/qqmljs.g | 36 | ||||
-rw-r--r-- | src/qml/parser/qqmljsast_p.h | 146 | ||||
-rw-r--r-- | src/qml/parser/qqmljsengine_p.cpp | 9 | ||||
-rw-r--r-- | src/qml/parser/qqmljsengine_p.h | 8 | ||||
-rw-r--r-- | src/qml/parser/qqmljslexer.cpp | 8 | ||||
-rw-r--r-- | src/qml/parser/qqmljslexer_p.h | 8 |
6 files changed, 107 insertions, 108 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index 8d79e48287..783ac273c8 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -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; + QList<QStringView> string_stack; + QList<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; @@ -3613,7 +3613,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; @@ -3887,7 +3887,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); @@ -3921,7 +3921,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); @@ -4011,7 +4011,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(); @@ -4025,7 +4025,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); @@ -4186,7 +4186,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); @@ -4216,7 +4216,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); @@ -4291,7 +4291,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); @@ -4302,7 +4302,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); diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h index 700643e1df..f846a5a3dc 100644 --- a/src/qml/parser/qqmljsast_p.h +++ b/src/qml/parser/qqmljsast_p.h @@ -335,11 +335,11 @@ class QML_PARSER_EXPORT UiQualifiedId: public Node public: QQMLJS_DECLARE_AST_NODE(UiQualifiedId) - UiQualifiedId(const QStringRef &name) + UiQualifiedId(QStringView name) : next(this), name(name) { kind = K; } - UiQualifiedId(UiQualifiedId *previous, const QStringRef &name) + UiQualifiedId(UiQualifiedId *previous, QStringView name) : name(name) { kind = K; @@ -364,7 +364,7 @@ public: // attributes UiQualifiedId *next; - QStringRef name; + QStringView name; SourceLocation identifierToken; }; @@ -549,7 +549,7 @@ class QML_PARSER_EXPORT IdentifierExpression: public LeftHandSideExpression public: QQMLJS_DECLARE_AST_NODE(IdentifierExpression) - IdentifierExpression(const QStringRef &n): + IdentifierExpression(QStringView n): name (n) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -561,7 +561,7 @@ public: { return identifierToken; } // attributes - QStringRef name; + QStringView name; SourceLocation identifierToken; }; @@ -698,7 +698,7 @@ class QML_PARSER_EXPORT StringLiteral : public LeftHandSideExpression public: QQMLJS_DECLARE_AST_NODE(StringLiteral) - StringLiteral(const QStringRef &v): + StringLiteral(QStringView v): value (v) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -710,7 +710,7 @@ public: { return literalToken; } // attributes: - QStringRef value; + QStringView value; SourceLocation literalToken; }; @@ -719,7 +719,7 @@ class QML_PARSER_EXPORT TemplateLiteral : public LeftHandSideExpression public: QQMLJS_DECLARE_AST_NODE(TemplateLiteral) - TemplateLiteral(const QStringRef &str, const QStringRef &raw, ExpressionNode *e) + TemplateLiteral(QStringView str, QStringView raw, ExpressionNode *e) : value(str), rawValue(raw), expression(e), next(nullptr) { kind = K; } @@ -734,8 +734,8 @@ public: void accept0(BaseVisitor *visitor) override; - QStringRef value; - QStringRef rawValue; + QStringView value; + QStringView rawValue; ExpressionNode *expression; TemplateLiteral *next; SourceLocation literalToken; @@ -746,7 +746,7 @@ class QML_PARSER_EXPORT RegExpLiteral: public LeftHandSideExpression public: QQMLJS_DECLARE_AST_NODE(RegExpLiteral) - RegExpLiteral(const QStringRef &p, int f): + RegExpLiteral(QStringView p, int f): pattern (p), flags (f) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -758,7 +758,7 @@ public: { return literalToken; } // attributes: - QStringRef pattern; + QStringView pattern; int flags; SourceLocation literalToken; }; @@ -937,7 +937,7 @@ public: : initializer(i), type(t) { kind = K; } - PatternElement(const QStringRef &n, TypeAnnotation *typeAnnotation = nullptr, ExpressionNode *i = nullptr, Type t = Binding) + PatternElement(QStringView n, TypeAnnotation *typeAnnotation = nullptr, ExpressionNode *i = nullptr, Type t = Binding) : bindingIdentifier(n), initializer(i), type(t) , typeAnnotation(typeAnnotation) { @@ -973,7 +973,7 @@ public: // attributes SourceLocation identifierToken; - QStringRef bindingIdentifier; + QStringView bindingIdentifier; ExpressionNode *bindingTarget = nullptr; ExpressionNode *initializer = nullptr; Type type = Literal; @@ -1032,7 +1032,7 @@ public: : PatternElement(i, t), name(name) { kind = K; } - PatternProperty(PropertyName *name, const QStringRef &n, ExpressionNode *i = nullptr) + PatternProperty(PropertyName *name, QStringView n, ExpressionNode *i = nullptr) : PatternElement(n, /*type annotation*/nullptr, i), name(name) { kind = K; } @@ -1102,7 +1102,7 @@ class QML_PARSER_EXPORT IdentifierPropertyName: public PropertyName public: QQMLJS_DECLARE_AST_NODE(IdentifierPropertyName) - IdentifierPropertyName(const QStringRef &n): + IdentifierPropertyName(QStringView n): id (n) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -1110,7 +1110,7 @@ public: QString asString() const override { return id.toString(); } // attributes - QStringRef id; + QStringView id; }; class QML_PARSER_EXPORT StringLiteralPropertyName: public PropertyName @@ -1118,7 +1118,7 @@ class QML_PARSER_EXPORT StringLiteralPropertyName: public PropertyName public: QQMLJS_DECLARE_AST_NODE(StringLiteralPropertyName) - StringLiteralPropertyName(const QStringRef &n): + StringLiteralPropertyName(QStringView n): id (n) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -1126,7 +1126,7 @@ public: QString asString() const override { return id.toString(); } // attributes - QStringRef id; + QStringView id; }; class QML_PARSER_EXPORT NumericLiteralPropertyName: public PropertyName @@ -1198,7 +1198,7 @@ class QML_PARSER_EXPORT FieldMemberExpression: public LeftHandSideExpression public: QQMLJS_DECLARE_AST_NODE(FieldMemberExpression) - FieldMemberExpression(ExpressionNode *b, const QStringRef &n): + FieldMemberExpression(ExpressionNode *b, QStringView n): base (b), name (n) { kind = K; } @@ -1212,7 +1212,7 @@ public: // attributes ExpressionNode *base; - QStringRef name; + QStringView name; SourceLocation dotToken; SourceLocation identifierToken; }; @@ -1988,7 +1988,7 @@ class QML_PARSER_EXPORT ContinueStatement: public Statement public: QQMLJS_DECLARE_AST_NODE(ContinueStatement) - ContinueStatement(const QStringRef &l = QStringRef()): + ContinueStatement(QStringView l = QStringView()): label (l) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -2000,7 +2000,7 @@ public: { return semicolonToken; } // attributes - QStringRef label; + QStringView label; SourceLocation continueToken; SourceLocation identifierToken; SourceLocation semicolonToken; @@ -2011,7 +2011,7 @@ class QML_PARSER_EXPORT BreakStatement: public Statement public: QQMLJS_DECLARE_AST_NODE(BreakStatement) - BreakStatement(const QStringRef &l): + BreakStatement(QStringView l): label (l) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -2023,7 +2023,7 @@ public: { return semicolonToken; } // attributes - QStringRef label; + QStringView label; SourceLocation breakToken; SourceLocation identifierToken; SourceLocation semicolonToken; @@ -2239,7 +2239,7 @@ class QML_PARSER_EXPORT LabelledStatement: public Statement public: QQMLJS_DECLARE_AST_NODE(LabelledStatement) - LabelledStatement(const QStringRef &l, Statement *stmt): + LabelledStatement(QStringView l, Statement *stmt): label (l), statement (stmt) { kind = K; } @@ -2252,7 +2252,7 @@ public: { return statement->lastSourceLocation(); } // attributes - QStringRef label; + QStringView label; Statement *statement; SourceLocation identifierToken; SourceLocation colonToken; @@ -2372,7 +2372,7 @@ class QML_PARSER_EXPORT FunctionExpression: public ExpressionNode public: QQMLJS_DECLARE_AST_NODE(FunctionExpression) - FunctionExpression(const QStringRef &n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr): + FunctionExpression(QStringView n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr): name (n), formals (f), body (b), typeAnnotation(typeAnnotation) { kind = K; } @@ -2388,7 +2388,7 @@ public: FunctionExpression *asFunctionDefinition() override; // attributes - QStringRef name; + QStringView name; bool isArrowFunction = false; bool isGenerator = false; FormalParameterList *formals; @@ -2407,7 +2407,7 @@ class QML_PARSER_EXPORT FunctionDeclaration: public FunctionExpression public: QQMLJS_DECLARE_AST_NODE(FunctionDeclaration) - FunctionDeclaration(const QStringRef &n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr): + FunctionDeclaration(QStringView n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr): FunctionExpression(n, f, b, typeAnnotation) { kind = K; } @@ -2504,7 +2504,7 @@ class QML_PARSER_EXPORT ClassExpression : public ExpressionNode public: QQMLJS_DECLARE_AST_NODE(ClassExpression) - ClassExpression(const QStringRef &n, ExpressionNode *heritage, ClassElementList *elements) + ClassExpression(QStringView n, ExpressionNode *heritage, ClassElementList *elements) : name(n), heritage(heritage), elements(elements) { kind = K; } @@ -2519,7 +2519,7 @@ public: ClassExpression *asClassDefinition() override; // attributes - QStringRef name; + QStringView name; ExpressionNode *heritage; ClassElementList *elements; SourceLocation classToken; @@ -2533,7 +2533,7 @@ class QML_PARSER_EXPORT ClassDeclaration: public ClassExpression public: QQMLJS_DECLARE_AST_NODE(ClassDeclaration) - ClassDeclaration(const QStringRef &n, ExpressionNode *heritage, ClassElementList *elements) + ClassDeclaration(QStringView n, ExpressionNode *heritage, ClassElementList *elements) : ClassExpression(n, heritage, elements) { kind = K; } @@ -2604,13 +2604,13 @@ class QML_PARSER_EXPORT ImportSpecifier: public Node public: QQMLJS_DECLARE_AST_NODE(ImportSpecifier) - ImportSpecifier(const QStringRef &importedBinding) + ImportSpecifier(QStringView importedBinding) : importedBinding(importedBinding) { kind = K; } - ImportSpecifier(const QStringRef &identifier, const QStringRef &importedBinding) + ImportSpecifier(QStringView identifier, QStringView importedBinding) : identifier(identifier), importedBinding(importedBinding) { kind = K; @@ -2626,8 +2626,8 @@ public: // attributes SourceLocation identifierToken; SourceLocation importedBindingToken; - QStringRef identifier; - QStringRef importedBinding; + QStringView identifier; + QStringView importedBinding; }; class QML_PARSER_EXPORT ImportsList: public Node @@ -2711,7 +2711,7 @@ class QML_PARSER_EXPORT NameSpaceImport: public Node public: QQMLJS_DECLARE_AST_NODE(NameSpaceImport) - NameSpaceImport(const QStringRef &importedBinding) + NameSpaceImport(QStringView importedBinding) : importedBinding(importedBinding) { kind = K; @@ -2727,7 +2727,7 @@ public: // attributes SourceLocation starToken; SourceLocation importedBindingToken; - QStringRef importedBinding; + QStringView importedBinding; }; class QML_PARSER_EXPORT ImportClause: public Node @@ -2735,7 +2735,7 @@ class QML_PARSER_EXPORT ImportClause: public Node public: QQMLJS_DECLARE_AST_NODE(ImportClause) - ImportClause(const QStringRef &importedDefaultBinding) + ImportClause(QStringView importedDefaultBinding) : importedDefaultBinding(importedDefaultBinding) { kind = K; @@ -2753,14 +2753,14 @@ public: kind = K; } - ImportClause(const QStringRef &importedDefaultBinding, NameSpaceImport *nameSpaceImport) + ImportClause(QStringView importedDefaultBinding, NameSpaceImport *nameSpaceImport) : importedDefaultBinding(importedDefaultBinding) , nameSpaceImport(nameSpaceImport) { kind = K; } - ImportClause(const QStringRef &importedDefaultBinding, NamedImports *namedImports) + ImportClause(QStringView importedDefaultBinding, NamedImports *namedImports) : importedDefaultBinding(importedDefaultBinding) , namedImports(namedImports) { @@ -2776,7 +2776,7 @@ public: // attributes SourceLocation importedDefaultBindingToken; - QStringRef importedDefaultBinding; + QStringView importedDefaultBinding; NameSpaceImport *nameSpaceImport = nullptr; NamedImports *namedImports = nullptr; }; @@ -2786,7 +2786,7 @@ class QML_PARSER_EXPORT FromClause: public Node public: QQMLJS_DECLARE_AST_NODE(FromClause) - FromClause(const QStringRef &moduleSpecifier) + FromClause(QStringView moduleSpecifier) : moduleSpecifier(moduleSpecifier) { kind = K; @@ -2803,7 +2803,7 @@ public: // attributes SourceLocation fromToken; SourceLocation moduleSpecifierToken; - QStringRef moduleSpecifier; + QStringView moduleSpecifier; }; class QML_PARSER_EXPORT ImportDeclaration: public Statement @@ -2817,7 +2817,7 @@ public: kind = K; } - ImportDeclaration(const QStringRef &moduleSpecifier) + ImportDeclaration(QStringView moduleSpecifier) : moduleSpecifier(moduleSpecifier) { kind = K; @@ -2834,7 +2834,7 @@ public: // attributes SourceLocation importToken; SourceLocation moduleSpecifierToken; - QStringRef moduleSpecifier; + QStringView moduleSpecifier; ImportClause *importClause = nullptr; FromClause *fromClause = nullptr; }; @@ -2844,13 +2844,13 @@ class QML_PARSER_EXPORT ExportSpecifier: public Node public: QQMLJS_DECLARE_AST_NODE(ExportSpecifier) - ExportSpecifier(const QStringRef &identifier) + ExportSpecifier(QStringView identifier) : identifier(identifier), exportedIdentifier(identifier) { kind = K; } - ExportSpecifier(const QStringRef &identifier, const QStringRef &exportedIdentifier) + ExportSpecifier(QStringView identifier, QStringView exportedIdentifier) : identifier(identifier), exportedIdentifier(exportedIdentifier) { kind = K; @@ -2866,8 +2866,8 @@ public: // attributes SourceLocation identifierToken; SourceLocation exportedIdentifierToken; - QStringRef identifier; - QStringRef exportedIdentifier; + QStringView identifier; + QStringView exportedIdentifier; }; class QML_PARSER_EXPORT ExportsList: public Node @@ -3038,7 +3038,7 @@ class QML_PARSER_EXPORT UiImport: public Node public: QQMLJS_DECLARE_AST_NODE(UiImport) - UiImport(const QStringRef &fileName) + UiImport(QStringView fileName) : fileName(fileName), importUri(nullptr) { kind = K; } @@ -3055,9 +3055,9 @@ public: { return semicolonToken; } // attributes - QStringRef fileName; + QStringView fileName; UiQualifiedId *importUri; - QStringRef importId; + QStringView importId; SourceLocation importToken; SourceLocation fileNameToken; SourceLocation asToken; @@ -3120,7 +3120,7 @@ class QML_PARSER_EXPORT UiPragma: public Node public: QQMLJS_DECLARE_AST_NODE(UiPragma) - UiPragma(QStringRef name) + UiPragma(QStringView name) : name(name) { kind = K; } @@ -3133,7 +3133,7 @@ public: { return semicolonToken; } // attributes - QStringRef name; + QStringView name; SourceLocation pragmaToken; SourceLocation semicolonToken; }; @@ -3143,7 +3143,7 @@ class QML_PARSER_EXPORT UiRequired: public Node public: QQMLJS_DECLARE_AST_NODE(UiRequired) - UiRequired(QStringRef name) + UiRequired(QStringView name) :name(name) { kind = K; } @@ -3155,7 +3155,7 @@ public: SourceLocation lastSourceLocation() const override { return semicolonToken; } - QStringRef name; + QStringView name; SourceLocation requiredToken; SourceLocation semicolonToken; }; @@ -3309,11 +3309,11 @@ class QML_PARSER_EXPORT UiParameterList: public Node public: QQMLJS_DECLARE_AST_NODE(UiParameterList) - UiParameterList(UiQualifiedId *t, const QStringRef &n): + UiParameterList(UiQualifiedId *t, QStringView n): type (t), name (n), next (this) { kind = K; } - UiParameterList(UiParameterList *previous, UiQualifiedId *t, const QStringRef &n): + UiParameterList(UiParameterList *previous, UiQualifiedId *t, QStringView n): type (t), name (n) { kind = K; @@ -3341,7 +3341,7 @@ public: // attributes UiQualifiedId *type; - QStringRef name; + QStringView name; UiParameterList *next; SourceLocation commaToken; SourceLocation propertyTypeToken; @@ -3355,12 +3355,12 @@ public: QQMLJS_DECLARE_AST_NODE(UiPublicMember) UiPublicMember(UiQualifiedId *memberType, - const QStringRef &name) + 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, + QStringView name, Statement *statement) : type(Property), memberType(memberType), name(name), statement(statement), binding(nullptr), isDefaultMember(false), isReadonlyMember(false), parameters(nullptr) { kind = K; } @@ -3391,9 +3391,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; @@ -3440,7 +3440,7 @@ class QML_PARSER_EXPORT UiInlineComponent: public UiObjectMember public: QQMLJS_DECLARE_AST_NODE(UiInlineComponent) - UiInlineComponent(const QStringRef& inlineComponentName, UiObjectDefinition* inlineComponent) + UiInlineComponent(QStringView inlineComponentName, UiObjectDefinition* inlineComponent) : name(inlineComponentName), component(inlineComponent) { kind = K; } @@ -3453,7 +3453,7 @@ public: void accept0(BaseVisitor *visitor) override; // attributes - QStringRef name; + QStringView name; UiObjectDefinition* component; SourceLocation componentToken; }; @@ -3586,11 +3586,11 @@ class QML_PARSER_EXPORT UiEnumMemberList: public Node { QQMLJS_DECLARE_AST_NODE(UiEnumMemberList) public: - UiEnumMemberList(const QStringRef &member, double v = 0.0) + UiEnumMemberList(QStringView member, double v = 0.0) : next(this), member(member), value(v) { kind = K; } - UiEnumMemberList(UiEnumMemberList *previous, const QStringRef &member) + UiEnumMemberList(UiEnumMemberList *previous, QStringView member) : member(member) { kind = K; @@ -3599,7 +3599,7 @@ public: value = previous->value + 1; } - UiEnumMemberList(UiEnumMemberList *previous, const QStringRef &member, double v) + UiEnumMemberList(UiEnumMemberList *previous, QStringView member, double v) : member(member), value(v) { kind = K; @@ -3627,7 +3627,7 @@ public: // attributes UiEnumMemberList *next; - QStringRef member; + QStringView member; double value; SourceLocation memberToken; SourceLocation valueToken; @@ -3638,7 +3638,7 @@ class QML_PARSER_EXPORT UiEnumDeclaration: public UiObjectMember public: QQMLJS_DECLARE_AST_NODE(UiEnumDeclaration) - UiEnumDeclaration(const QStringRef &name, + UiEnumDeclaration(QStringView name, UiEnumMemberList *members) : name(name) , members(members) @@ -3655,7 +3655,7 @@ public: // attributes SourceLocation enumToken; SourceLocation rbraceToken; - QStringRef name; + QStringView name; UiEnumMemberList *members; }; diff --git a/src/qml/parser/qqmljsengine_p.cpp b/src/qml/parser/qqmljsengine_p.cpp index cb6b0375e6..53ad8820dd 100644 --- a/src/qml/parser/qqmljsengine_p.cpp +++ b/src/qml/parser/qqmljsengine_p.cpp @@ -143,14 +143,13 @@ 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()); + _extraCode.append(text); + return QStringView{_extraCode.last()}; } -QStringRef Engine::newStringRef(const QChar *chars, int size) +QStringView Engine::newStringRef(const QChar *chars, int size) { return newStringRef(QString(chars, size)); } } // end of namespace QQmlJS diff --git a/src/qml/parser/qqmljsengine_p.h b/src/qml/parser/qqmljsengine_p.h index a34922fa1e..b57515982b 100644 --- a/src/qml/parser/qqmljsengine_p.h +++ b/src/qml/parser/qqmljsengine_p.h @@ -98,7 +98,7 @@ class QML_PARSER_EXPORT Engine Directives *_directives; MemoryPool _pool; QList<SourceLocation> _comments; - QString _extraCode; + QStringList _extraCode; QString _code; public: @@ -119,10 +119,10 @@ public: MemoryPool *pool(); - inline QStringRef midRef(int position, int size) { return _code.midRef(position, size); } + inline QStringView midRef(int position, int size) { 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); diff --git a/src/qml/parser/qqmljslexer.cpp b/src/qml/parser/qqmljslexer.cpp index cdab17ff63..601596a9e3 100644 --- a/src/qml/parser/qqmljslexer.cpp +++ b/src/qml/parser/qqmljslexer.cpp @@ -132,8 +132,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(); @@ -256,8 +256,8 @@ int Lexer::lex() const int previousTokenKind = _tokenKind; again: - _tokenSpell = QStringRef(); - _rawString = QStringRef(); + _tokenSpell = QStringView(); + _rawString = QStringView(); _tokenKind = scanToken(); _tokenLength = _codePtr - _tokenStartPtr - 1; diff --git a/src/qml/parser/qqmljslexer_p.h b/src/qml/parser/qqmljslexer_p.h index e2ee4ae351..7b4c219506 100644 --- a/src/qml/parser/qqmljslexer_p.h +++ b/src/qml/parser/qqmljslexer_p.h @@ -165,8 +165,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; @@ -219,8 +219,8 @@ private: QString _code; QString _tokenText; QString _errorMessage; - QStringRef _tokenSpell; - QStringRef _rawString; + QStringView _tokenSpell; + QStringView _rawString; const QChar *_codePtr; const QChar *_endPtr; |