diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-01-22 19:49:59 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-01-22 19:49:59 +0000 |
commit | 33e9abd21083a0191a7676a04b497006d2da184d (patch) | |
tree | fc940943935ee6e5460a2f0c580183a48fd21989 /lib | |
parent | 372ade25bd4c56355172210dfc2a308cfa75b55a (diff) | |
download | clang-33e9abd21083a0191a7676a04b497006d2da184d.tar.gz |
Teach CIndex's cursor visitor to restrict its traversal to a specific
region of interest (if provided). Implement clang_getCursor() in terms
of this traversal rather than using the Index library; the unified
cursor visitor is more complete, and will be The Way Forward.
Minor other tweaks needed to make this work:
- Extend Preprocessor::getLocForEndOfToken() to accept an offset
from the end, making it easy to move to the last character in the
token (rather than just past the end of the token).
- In Lexer::MeasureTokenLength(), the length of whitespace is zero.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94200 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/Decl.cpp | 8 | ||||
-rw-r--r-- | lib/Lex/Lexer.cpp | 4 | ||||
-rw-r--r-- | lib/Lex/Preprocessor.cpp | 18 |
3 files changed, 17 insertions, 13 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index e77661a9fb..794b14a1f4 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -629,9 +629,13 @@ VarDecl::~VarDecl() { } SourceRange VarDecl::getSourceRange() const { + SourceLocation Start = getTypeSpecStartLoc(); + if (Start.isInvalid()) + Start = getLocation(); + if (getInit()) - return SourceRange(getLocation(), getInit()->getLocEnd()); - return SourceRange(getLocation(), getLocation()); + return SourceRange(Start, getInit()->getLocEnd()); + return SourceRange(Start, getLocation()); } bool VarDecl::isOutOfLine() const { diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index 9556bc39ec..afd1ba8851 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -210,6 +210,7 @@ void Lexer::Stringify(llvm::SmallVectorImpl<char> &Str) { } } +static bool isWhitespace(unsigned char c); /// MeasureTokenLength - Relex the token at the specified location and return /// its length in bytes in the input file. If the token needs cleaning (e.g. @@ -231,6 +232,9 @@ unsigned Lexer::MeasureTokenLength(SourceLocation Loc, std::pair<const char *,const char *> Buffer = SM.getBufferData(LocInfo.first); const char *StrData = Buffer.first+LocInfo.second; + if (isWhitespace(StrData[0])) + return 0; + // Create a lexer starting at the beginning of this token. Lexer TheLexer(Loc, LangOpts, Buffer.first, StrData, Buffer.second); TheLexer.SetCommentRetentionState(true); diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 586202bccf..5689baaac6 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -429,21 +429,17 @@ SourceLocation Preprocessor::AdvanceToTokenCharacter(SourceLocation TokStart, return TokStart.getFileLocWithOffset(PhysOffset); } -/// \brief Computes the source location just past the end of the -/// token at this source location. -/// -/// This routine can be used to produce a source location that -/// points just past the end of the token referenced by \p Loc, and -/// is generally used when a diagnostic needs to point just after a -/// token where it expected something different that it received. If -/// the returned source location would not be meaningful (e.g., if -/// it points into a macro), this routine returns an invalid -/// source location. -SourceLocation Preprocessor::getLocForEndOfToken(SourceLocation Loc) { +SourceLocation Preprocessor::getLocForEndOfToken(SourceLocation Loc, + unsigned Offset) { if (Loc.isInvalid() || !Loc.isFileID()) return SourceLocation(); unsigned Len = Lexer::MeasureTokenLength(Loc, getSourceManager(), Features); + if (Len > Offset) + Len = Len - Offset; + else + return Loc; + return AdvanceToTokenCharacter(Loc, Len); } |