From 307b0717f728afdd151dc608b5c8b955969472c9 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 14 Jul 2009 03:18:17 +0000 Subject: [PATCH] In ResolveLocationInAST, handle locations that are inside TagDecl definitions. llvm-svn: 75594 --- clang/lib/Index/ResolveLocation.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/clang/lib/Index/ResolveLocation.cpp b/clang/lib/Index/ResolveLocation.cpp index e93d689c04bc..edb46c23f4f3 100644 --- a/clang/lib/Index/ResolveLocation.cpp +++ b/clang/lib/Index/ResolveLocation.cpp @@ -89,7 +89,9 @@ public: DeclLocResolver(ASTContext &ctx, SourceLocation loc) : LocResolverBase(ctx, loc) {} + ASTLocation VisitDeclContext(DeclContext *DC); ASTLocation VisitTranslationUnitDecl(TranslationUnitDecl *TU); + ASTLocation VisitRecordDecl(RecordDecl *D); ASTLocation VisitVarDecl(VarDecl *D); ASTLocation VisitFunctionDecl(FunctionDecl *D); ASTLocation VisitDecl(Decl *D); @@ -131,9 +133,7 @@ ASTLocation StmtLocResolver::VisitStmt(Stmt *Node) { return ASTLocation(Parent, Node); } -ASTLocation DeclLocResolver::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { - DeclContext *DC = TU; - +ASTLocation DeclLocResolver::VisitDeclContext(DeclContext *DC) { for (DeclContext::decl_iterator I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) { RangePos RP = CheckRange(*I); @@ -143,7 +143,20 @@ ASTLocation DeclLocResolver::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { return Visit(*I); } - return ASTLocation(); + return ASTLocation(cast(DC)); +} + +ASTLocation DeclLocResolver::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { + ASTLocation ASTLoc = VisitDeclContext(TU); + if (ASTLoc.getDecl() == TU) + return ASTLocation(); + return ASTLoc; +} + +ASTLocation DeclLocResolver::VisitRecordDecl(RecordDecl *D) { + assert(ContainsLocation(D) && + "Should visit only after verifying that loc is in range"); + return VisitDeclContext(D); } ASTLocation DeclLocResolver::VisitFunctionDecl(FunctionDecl *D) {