From 49dd5851c463963a8a78f5222ea72cfaa6db1029 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sun, 5 Jul 2009 22:21:40 +0000 Subject: [PATCH] Make use of ASTNode for return value of clang::ResolveLocationInAST() and in the index-test tool. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74798 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/Utils.h | 4 ++-- lib/Frontend/ResolveLocation.cpp | 8 ++++---- tools/index-test/index-test.cpp | 32 ++++++++++++++------------------ 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h index 77df60cd72..7e7efbce57 100644 --- a/include/clang/Frontend/Utils.h +++ b/include/clang/Frontend/Utils.h @@ -36,6 +36,7 @@ class Decl; class Stmt; class ASTContext; class SourceLocation; +class ASTNode; /// ProcessWarningOptions - Initialize the diagnostic client and process the /// warning options specified on the command line. @@ -102,8 +103,7 @@ void CacheTokens(Preprocessor& PP, llvm::raw_fd_ostream* OS); /// Pointing at '100' will return a pair. /// Pointing at '++foo' will return a pair. /// -std::pair ResolveLocationInAST(ASTContext &Ctx, - SourceLocation Loc); +ASTNode ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc); } // end namespace clang diff --git a/lib/Frontend/ResolveLocation.cpp b/lib/Frontend/ResolveLocation.cpp index fd5cacf127..3dcd2143cb 100644 --- a/lib/Frontend/ResolveLocation.cpp +++ b/lib/Frontend/ResolveLocation.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "clang/Frontend/Utils.h" +#include "clang/AST/ASTNode.h" #include "clang/AST/DeclVisitor.h" #include "clang/AST/StmtVisitor.h" #include "clang/Lex/Lexer.h" @@ -313,12 +314,11 @@ void LocResolverBase::print(Stmt *Node) { /// \brief Returns the AST node that a source location points to. /// -std::pair -clang::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc) { +ASTNode clang::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc) { if (Loc.isInvalid()) - return std::make_pair((Decl*)0, (Stmt*)0); + return ASTNode(); DeclLocResolver DLR(Ctx, Loc); DLR.Visit(Ctx.getTranslationUnitDecl()); - return DLR.getResult(); + return ASTNode(DLR.getDecl(), DLR.getStmt()); } diff --git a/tools/index-test/index-test.cpp b/tools/index-test/index-test.cpp index 552b7b0149..0fa0d5a466 100644 --- a/tools/index-test/index-test.cpp +++ b/tools/index-test/index-test.cpp @@ -28,6 +28,7 @@ #include "clang/Frontend/CommandLineSourceLoc.h" #include "clang/AST/Decl.h" #include "clang/AST/Stmt.h" +#include "clang/AST/ASTNode.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/STLExtras.h" @@ -77,13 +78,7 @@ int main(int argc, char **argv) { return 1; } - struct ASTPoint { - Decl *D; - Stmt *Node; - ASTPoint() : D(0), Node(0) {} - }; - - ASTPoint Point; + ASTNode Node; if (!PointAtLocation.empty()) { const std::string &Filename = PointAtLocation[0].FileName; @@ -114,30 +109,31 @@ int main(int argc, char **argv) { return 1; } - llvm::tie(Point.D, Point.Node) = - ResolveLocationInAST(AST->getASTContext(), Loc); - if (Point.D == 0) { + Node = ResolveLocationInAST(AST->getASTContext(), Loc); + if (Node.isInvalid()) { llvm::errs() << "[" << InFile << "] Error: " << "Couldn't resolve source location (no declaration found)\n"; return 1; } } - if (Point.D) { + if (Node.isValid()) { llvm::raw_ostream &OS = llvm::outs(); - OS << "Declaration node at point: " << Point.D->getDeclKindName() << " "; - if (NamedDecl *ND = dyn_cast(Point.D)) + OS << "Declaration node at point: " << Node.getDecl()->getDeclKindName() + << " "; + if (NamedDecl *ND = dyn_cast(Node.getDecl())) OS << ND->getNameAsString(); OS << "\n"; - if (const char *Comment = AST->getASTContext().getCommentForDecl(Point.D)) + if (const char *Comment = + AST->getASTContext().getCommentForDecl(Node.getDecl())) OS << "Comment associated with this declaration:\n" << Comment << "\n"; - if (Point.Node) { - OS << "Statement node at point: " << Point.Node->getStmtClassName() + if (Node.getStmt()) { + OS << "Statement node at point: " << Node.getStmt()->getStmtClassName() << " "; - Point.Node->printPretty(OS, AST->getASTContext(), 0, - PrintingPolicy(AST->getASTContext().getLangOptions())); + Node.getStmt()->printPretty(OS, AST->getASTContext(), 0, + PrintingPolicy(AST->getASTContext().getLangOptions())); OS << "\n"; } } -- 2.40.0