diff options
author | Fawzi Mohamed <fawzi.mohamed@qt.io> | 2021-03-22 07:13:04 +0100 |
---|---|---|
committer | Fawzi Mohamed <fawzi.mohamed@qt.io> | 2021-03-26 17:48:46 +0100 |
commit | ac5332091f057cae80fa8fab73819acb551aa9da (patch) | |
tree | 022ca2a7679cfe8efb315d19cfc8b307e2316878 /src/qml/parser/qqmljs.g | |
parent | 365dc57879ca6ed605b42ab7fae7842374dc49c6 (diff) |
Ensure that empty tokens in the AST are empty
Arrow functions introduce a virtual functions and return statements to
simplify code generation (arrow function look like normal function
definitions), but to have correct firstSourceLocation /
lastSourcelocation other tokens were reused.
Use an empty SourceLocation at the correct position instead, so code
that expects the correct location (for error messages,...) works and
code that expects the correct token content (rewriter in QtCreator for
example) also works.
Introduce helper SourceLocation::startZeroLengthLocation/
endZeroLengthLocation to simplify such code.
Change-Id: I1c5df16e1704df2df9b7cbd1a039ce56be3727d3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/parser/qqmljs.g')
-rw-r--r-- | src/qml/parser/qqmljs.g | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index f10bde5ff1..3243dea2fe 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -4043,14 +4043,14 @@ ArrowFunction_In: ArrowParameters T_ARROW ConciseBodyLookahead AssignmentExpress /. case $rule_number: { AST::ReturnStatement *ret = new (pool) AST::ReturnStatement(sym(4).Expression); - ret->returnToken = sym(4).Node->firstSourceLocation(); - ret->semicolonToken = sym(4).Node->lastSourceLocation(); + ret->returnToken = sym(4).Node->firstSourceLocation().startZeroLengthLocation(); + ret->semicolonToken = sym(4).Node->lastSourceLocation().endZeroLengthLocation(driver->code()); AST::StatementList *statements = (new (pool) AST::StatementList(ret))->finish(); 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(); - f->rbraceToken = sym(4).Node->lastSourceLocation(); + f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation().startZeroLengthLocation() : loc(1).startZeroLengthLocation(); + f->lbraceToken = sym(4).Node->firstSourceLocation().startZeroLengthLocation(); + f->rbraceToken = sym(4).Node->lastSourceLocation().endZeroLengthLocation(driver->code()); sym(1).Node = f; } break; ./ @@ -4062,7 +4062,7 @@ ArrowFunction_In: ArrowParameters T_ARROW ConciseBodyLookahead T_FORCE_BLOCK Fun case $rule_number: { 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->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation().startZeroLengthLocation() : loc(1).startZeroLengthLocation(); f->lbraceToken = loc(6); f->rbraceToken = loc(7); sym(1).Node = f; |