diff options
Diffstat (limited to 'src/libs/cplusplus/ASTPath.cpp')
-rw-r--r-- | src/libs/cplusplus/ASTPath.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/libs/cplusplus/ASTPath.cpp b/src/libs/cplusplus/ASTPath.cpp index a38c5eadc1..9a4ef293a7 100644 --- a/src/libs/cplusplus/ASTPath.cpp +++ b/src/libs/cplusplus/ASTPath.cpp @@ -65,8 +65,8 @@ void ASTPath::dump(const QList<AST *> nodes) bool ASTPath::preVisit(AST *ast) { - unsigned firstToken = ast->firstToken(); - unsigned lastToken = ast->lastToken(); + const unsigned firstToken = firstNonGeneratedToken(ast); + const unsigned lastToken = lastNonGeneratedToken(ast); if (firstToken > 0) { if (lastToken <= firstToken) @@ -89,3 +89,24 @@ bool ASTPath::preVisit(AST *ast) return false; } + +unsigned ASTPath::firstNonGeneratedToken(AST *ast) const +{ + const unsigned lastTokenIndex = ast->lastToken(); + unsigned tokenIndex = ast->firstToken(); + while (tokenIndex <= lastTokenIndex && tokenAt(tokenIndex).generated()) + ++tokenIndex; + return tokenIndex; +} + +unsigned ASTPath::lastNonGeneratedToken(AST *ast) const +{ + const unsigned firstTokenIndex = ast->firstToken(); + const unsigned lastTokenIndex = ast->lastToken(); + unsigned tokenIndex = lastTokenIndex; + while (firstTokenIndex <= tokenIndex && tokenAt(tokenIndex).generated()) + --tokenIndex; + return tokenIndex != lastTokenIndex + ? tokenIndex + 1 + : tokenIndex; +} |