diff options
| author | Ted Kremenek <kremenek@apple.com> | 2010-08-14 01:14:06 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2010-08-14 01:14:06 +0000 |
| commit | f4ade0ae3f268c6a1c9b59e2c0803aabe705a53f (patch) | |
| tree | e446dfddf3b3c47579915bc0e5cf874f39990942 /clang/tools | |
| parent | aa445c075119075e59dad9d431ee37e33430a938 (diff) | |
| download | bcm5719-llvm-f4ade0ae3f268c6a1c9b59e2c0803aabe705a53f.tar.gz bcm5719-llvm-f4ade0ae3f268c6a1c9b59e2c0803aabe705a53f.zip | |
As a heuristic, annotate tokens (via clang_annotateTokens) that are the arguments of a macro instantiation using the closest cursor with the same spelling location. Because macro arguments can get token pasted in any arbitrary order, we use the annotation map to paper over the token -> cursor annotations during our post-processing stage. This fixes most of <rdar://problem/8044584>, but still doesn't work for assert().
llvm-svn: 111062
Diffstat (limited to 'clang/tools')
| -rw-r--r-- | clang/tools/libclang/CIndex.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index f7dce99c723..4de675370ee 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -2655,6 +2655,23 @@ AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) { } } + // If the location of the cursor occurs within a macro instantiation, record + // the spelling location of the cursor in our annotation map. We can then + // paper over the token labelings during a post-processing step to try and + // get cursor mappings for tokens that are the *arguments* of a macro + // instantiation. + if (L.isMacroID()) { + unsigned rawEncoding = SrcMgr.getSpellingLoc(L).getRawEncoding(); + // Only invalidate the old annotation if it isn't part of a preprocessing + // directive. Here we assume that the default construction of CXCursor + // results in CXCursor.kind being an initialized value (i.e., 0). If + // this isn't the case, we can fix by doing lookup + insertion. + + CXCursor &oldC = Annotated[rawEncoding]; + if (!clang_isPreprocessing(oldC.kind)) + oldC = cursor; + } + const enum CXCursorKind K = clang_getCursorKind(parent); const CXCursor updateC = (clang_isInvalid(K) || K == CXCursor_TranslationUnit || |

