From f24249554b3dc5d2cac5e34d61586aaec773eeec Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Mon, 6 Jul 2009 21:35:02 +0000 Subject: [PATCH] Move the 'ResolveLocationInAST' function from the Frontend library to the Index library. Also, cut down its comments; more comments will be added to ASTLocation. llvm-svn: 74860 --- clang/include/clang/Frontend/Utils.h | 32 ----------------- clang/include/clang/Index/Utils.h | 35 +++++++++++++++++++ .../{Frontend => Index}/ResolveLocation.cpp | 6 ++-- clang/tools/index-test/index-test.cpp | 2 +- 4 files changed, 39 insertions(+), 36 deletions(-) create mode 100644 clang/include/clang/Index/Utils.h rename clang/lib/{Frontend => Index}/ResolveLocation.cpp (98%) diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 7845e8f7cf58..2ad44da999c1 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -34,12 +34,6 @@ class PreprocessorFactory; class LangOptions; class Decl; class Stmt; -class ASTContext; -class SourceLocation; - -namespace idx { -class ASTLocation; -} /// ProcessWarningOptions - Initialize the diagnostic client and process the /// warning options specified on the command line. @@ -82,32 +76,6 @@ void AttachDependencyFileGen(Preprocessor *PP, llvm::raw_ostream *OS, /// a seekable stream. void CacheTokens(Preprocessor& PP, llvm::raw_fd_ostream* OS); -/// \brief Returns the AST node that a source location points to. -/// -/// Returns a pair of Decl* and Stmt*. If no AST node is found for the source -/// location, the pair will contain null pointers. -/// -/// If the source location points to just a declaration, the statement part of -/// the pair will be null, e.g., -/// @code -/// int foo; -/// @endcode -/// If the source location points at 'foo', the pair will contain the VarDecl -/// of foo and a null Stmt. -/// -/// If the source location points to a statement node, the returned declaration -/// will be the immediate 'parent' declaration of the statement node, e.g., -/// @code -/// void f() { -/// int foo = 100; -/// ++foo; -/// } -/// @endcode -/// Pointing at '100' will return a pair. -/// Pointing at '++foo' will return a pair. -/// -idx::ASTLocation ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc); - } // end namespace clang #endif diff --git a/clang/include/clang/Index/Utils.h b/clang/include/clang/Index/Utils.h new file mode 100644 index 000000000000..e78ef8a15563 --- /dev/null +++ b/clang/include/clang/Index/Utils.h @@ -0,0 +1,35 @@ +//===--- Utils.h - Misc utilities for indexing-----------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This header contains miscellaneous utilities for indexing related +// functionality. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_INDEX_UTILS_H +#define LLVM_CLANG_INDEX_UTILS_H + +namespace clang { + class ASTContext; + class SourceLocation; + +namespace idx { + class ASTLocation; + +/// \brief Returns the ASTLocation that a source location points to. +/// +/// \returns the resolved ASTLocation or an invalid ASTLocation if the source +/// location could not be resolved. +ASTLocation ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc); + +} // end namespace idx + +} // end namespace clang + +#endif diff --git a/clang/lib/Frontend/ResolveLocation.cpp b/clang/lib/Index/ResolveLocation.cpp similarity index 98% rename from clang/lib/Frontend/ResolveLocation.cpp rename to clang/lib/Index/ResolveLocation.cpp index 9fbae30a4857..b9df7029048e 100644 --- a/clang/lib/Frontend/ResolveLocation.cpp +++ b/clang/lib/Index/ResolveLocation.cpp @@ -8,11 +8,11 @@ //===----------------------------------------------------------------------===// // // This defines the ResolveLocationInAST function, which resolves a -// source location into a pair. +// source location into a ASTLocation. // //===----------------------------------------------------------------------===// -#include "clang/Frontend/Utils.h" +#include "clang/Index/Utils.h" #include "clang/Index/ASTLocation.h" #include "clang/AST/DeclVisitor.h" #include "clang/AST/StmtVisitor.h" @@ -322,7 +322,7 @@ void LocResolverBase::print(Stmt *Node) { /// \brief Returns the AST node that a source location points to. /// -ASTLocation clang::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc) { +ASTLocation idx::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc) { if (Loc.isInvalid()) return ASTLocation(); diff --git a/clang/tools/index-test/index-test.cpp b/clang/tools/index-test/index-test.cpp index dd1ced45cefe..37ecbd928f32 100644 --- a/clang/tools/index-test/index-test.cpp +++ b/clang/tools/index-test/index-test.cpp @@ -38,8 +38,8 @@ #include "clang/Index/TranslationUnit.h" #include "clang/Index/ASTLocation.h" #include "clang/Index/DeclReferenceMap.h" +#include "clang/Index/Utils.h" #include "clang/Frontend/ASTUnit.h" -#include "clang/Frontend/Utils.h" #include "clang/Frontend/CommandLineSourceLoc.h" #include "clang/AST/Decl.h" #include "clang/AST/Expr.h"