diff options
| author | Ted Kremenek <kremenek@apple.com> | 2010-11-01 23:26:51 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2010-11-01 23:26:51 +0000 |
| commit | 818e5c1839eead75e3e409ab60a2bb1f0be9a54f (patch) | |
| tree | bdd78d3a139a95ac4fa5f766efc806c99030c347 /clang/tools/libclang/CIndex.cpp | |
| parent | 53078294ed3e82452cb5883d2ef3c2453e3ee41d (diff) | |
| download | bcm5719-llvm-818e5c1839eead75e3e409ab60a2bb1f0be9a54f.tar.gz bcm5719-llvm-818e5c1839eead75e3e409ab60a2bb1f0be9a54f.zip | |
Encapsulate within CXCursor the notion of whether a VarDecl* is the first Decl in a DeclGroup. We use this
to recover some context that is currently not modeled directly in the AST. Currently VarDecl's cannot
properly determine their source range because they have no context on whether or not they appear in a DeclGroup.
For the meantime, this bandaid suffices in libclang since that is where the correct SourceRange is directly needed.
Fixes <rdar://problem/8595749>.
llvm-svn: 117973
Diffstat (limited to 'clang/tools/libclang/CIndex.cpp')
| -rw-r--r-- | clang/tools/libclang/CIndex.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 44493497bdb..4413766b028 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -1357,10 +1357,12 @@ bool CursorVisitor::VisitCaseStmt(CaseStmt *S) { } bool CursorVisitor::VisitDeclStmt(DeclStmt *S) { + bool isFirst = true; for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); D != DEnd; ++D) { - if (*D && Visit(MakeCXCursor(*D, TU))) + if (*D && Visit(MakeCXCursor(*D, TU, isFirst))) return true; + isFirst = false; } return false; @@ -2926,6 +2928,16 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) { SourceLocation Loc = D->getLocation(); if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(D)) Loc = Class->getClassLoc(); + // FIXME: Multiple variables declared in a single declaration + // currently lack the information needed to correctly determine their + // ranges when accounting for the type-specifier. We use context + // stored in the CXCursor to determine if the VarDecl is in a DeclGroup, + // and if so, whether it is the first decl. + if (VarDecl *VD = dyn_cast<VarDecl>(D)) { + if (!cxcursor::isFirstInDeclGroup(C)) + Loc = VD->getLocation(); + } + return cxloc::translateSourceLocation(getCursorContext(C), Loc); } @@ -2988,9 +3000,20 @@ static SourceRange getRawCursorExtent(CXCursor C) { if (C.kind == CXCursor_InclusionDirective) return cxcursor::getCursorInclusionDirective(C)->getSourceRange(); - if (C.kind >= CXCursor_FirstDecl && C.kind <= CXCursor_LastDecl) - return getCursorDecl(C)->getSourceRange(); - + if (C.kind >= CXCursor_FirstDecl && C.kind <= CXCursor_LastDecl) { + Decl *D = cxcursor::getCursorDecl(C); + SourceRange R = D->getSourceRange(); + // FIXME: Multiple variables declared in a single declaration + // currently lack the information needed to correctly determine their + // ranges when accounting for the type-specifier. We use context + // stored in the CXCursor to determine if the VarDecl is in a DeclGroup, + // and if so, whether it is the first decl. + if (VarDecl *VD = dyn_cast<VarDecl>(D)) { + if (!cxcursor::isFirstInDeclGroup(C)) + R.setBegin(VD->getLocation()); + } + return R; + } return SourceRange();} extern "C" { |

