diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-09-02 15:47:43 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-09-03 10:46:49 +0200 |
commit | fcf0dfed9d9dbfa0fc1c91f334caf16926b8552c (patch) | |
tree | fe3fac0d252a9233db482c314e33363df7566b37 /src/qml/parser | |
parent | d045cd4330afee92a3c5c86e51aefc2299ab3ad9 (diff) |
Visit lists iteratively when determining source locations in QML
Change-Id: I35d44de09f9d4133eb82490a1edb57eb374ff2f1
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/parser')
-rw-r--r-- | src/qml/parser/qqmljsast_p.h | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h index 39194068bf..6c28903066 100644 --- a/src/qml/parser/qqmljsast_p.h +++ b/src/qml/parser/qqmljsast_p.h @@ -307,6 +307,14 @@ public: int kind = Kind_Undefined; }; +template<typename T> +T lastListElement(T head) +{ + auto current = head; + while (current->next) + current = current->next; + return current; +} class QML_PARSER_EXPORT UiQualifiedId: public Node { @@ -338,7 +346,7 @@ public: { return identifierToken; } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : identifierToken; } + { return lastListElement(this)->identifierToken; } // attributes UiQualifiedId *next; @@ -397,7 +405,7 @@ public: { return typeId->firstSourceLocation(); } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : typeId->lastSourceLocation(); } + { return lastListElement(this)->typeId->lastSourceLocation(); } inline TypeArgumentList *finish() { @@ -678,7 +686,10 @@ public: { return literalToken; } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : (expression ? expression->lastSourceLocation() : literalToken); } + { + auto last = lastListElement(this); + return (last->expression ? last->expression->lastSourceLocation() : last->literalToken); + } void accept0(Visitor *visitor) override; @@ -800,7 +811,7 @@ public: { return commaToken; } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : commaToken; } + { return lastListElement(this)->commaToken; } inline Elision *finish () { @@ -961,7 +972,10 @@ public: { return elision ? elision->firstSourceLocation() : element->firstSourceLocation(); } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : (element ? element->lastSourceLocation() : elision->lastSourceLocation()); } + { + auto last = lastListElement(this); + return last->element ? last->element->lastSourceLocation() : last->elision->lastSourceLocation(); + } Elision *elision = nullptr; PatternElement *element = nullptr; @@ -1036,7 +1050,7 @@ public: { return property->firstSourceLocation(); } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : property->lastSourceLocation(); } + { return lastListElement(this)->property->lastSourceLocation(); } PatternProperty *property; PatternPropertyList *next; @@ -1645,7 +1659,9 @@ public: { return statement->firstSourceLocation(); } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : statement->lastSourceLocation(); } + { + return lastListElement(this)->statement->lastSourceLocation(); + } inline StatementList *finish () { @@ -2138,7 +2154,9 @@ public: { return clause->firstSourceLocation(); } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : clause->lastSourceLocation(); } + { + return lastListElement(this)->clause->lastSourceLocation(); + } inline CaseClauses *finish () { @@ -2429,7 +2447,9 @@ public: { return element->firstSourceLocation(); } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : element->lastSourceLocation(); } + { + return lastListElement(this)->element->lastSourceLocation(); + } FormalParameterList *finish(MemoryPool *pool); @@ -2606,7 +2626,9 @@ public: { return importSpecifierToken; } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : importSpecifierToken; } + { + return lastListElement(this)->importSpecifierToken; + } // attributes SourceLocation importSpecifierToken; @@ -2843,7 +2865,7 @@ public: SourceLocation firstSourceLocation() const override { return exportSpecifier->firstSourceLocation(); } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : exportSpecifier->lastSourceLocation(); } + { return lastListElement(this)->exportSpecifier->lastSourceLocation(); } // attributes ExportSpecifier *exportSpecifier; @@ -3036,7 +3058,7 @@ public: { return member->firstSourceLocation(); } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : member->lastSourceLocation(); } + { return lastListElement(this)->member->lastSourceLocation(); } UiObjectMemberList *finish() { @@ -3115,7 +3137,7 @@ public: { return headerItem->firstSourceLocation(); } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : headerItem->lastSourceLocation(); } + { return lastListElement(this)->headerItem->lastSourceLocation(); } // attributes Node *headerItem; @@ -3179,7 +3201,7 @@ public: { return member->firstSourceLocation(); } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : member->lastSourceLocation(); } + { return lastListElement(this)->member->lastSourceLocation(); } UiArrayMemberList *finish() { @@ -3240,7 +3262,10 @@ public: { return colonToken.isValid() ? identifierToken : propertyTypeToken; } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : (colonToken.isValid() ? propertyTypeToken : identifierToken); } + { + auto last = lastListElement(this); + return (last->colonToken.isValid() ? last->propertyTypeToken : last->identifierToken); + } inline UiParameterList *finish () { @@ -3493,8 +3518,10 @@ public: { return memberToken; } SourceLocation lastSourceLocation() const override - { return next ? next->lastSourceLocation() : - valueToken.isValid() ? valueToken : memberToken; } + { + auto last = lastListElement(this); + return last->valueToken.isValid() ? last->valueToken : last->memberToken; + } void accept0(Visitor *visitor) override; |