Eliminate index-test; all of its tested functionality is now in c-index-test.
llvm-svn: 94211
This commit is contained in:
parent
877524918a
commit
9ae8d349e6
|
@ -1,34 +0,0 @@
|
|||
// Run lines are sensitive to line numbers and come below the code.
|
||||
|
||||
//! It all starts here.
|
||||
/*! It's a little odd to continue line this,
|
||||
*
|
||||
* but we need more multi-line comments. */
|
||||
/// This comment comes before my other comments
|
||||
/** This is a block comment that is associated with the function f. It
|
||||
* runs for three lines.
|
||||
*/
|
||||
void f(int, int);
|
||||
|
||||
// NOT IN THE COMMENT
|
||||
/// This is a BCPL comment that is associated with the function g.
|
||||
/// It has only two lines.
|
||||
/** But there are other blocks that are part of the comment, too. */
|
||||
void g(int);
|
||||
|
||||
void h(int); ///< This is a member comment.
|
||||
|
||||
|
||||
// RUN: %clang_cc1 -emit-pch -o %t.ast %s
|
||||
|
||||
// RUN: index-test %t.ast -point-at %s:11:6 > %t
|
||||
// RUN: grep "starts here" %t
|
||||
// RUN: grep "block comment" %t
|
||||
|
||||
// RUN: index-test %t.ast -point-at %s:17:6 > %t
|
||||
// RUN: grep "BCPL" %t
|
||||
// RUN: grep "But" %t
|
||||
|
||||
// RUN: index-test %t.ast -point-at %s:19:6 > %t
|
||||
// RUN: grep "NOT" %t | count 0
|
||||
// RUN: grep "member" %t
|
|
@ -1,47 +0,0 @@
|
|||
// RUN: %clang_cc1 -fblocks -emit-pch %S/Inputs/t1.c -o %t1.ast
|
||||
// RUN: %clang_cc1 -fblocks -emit-pch %S/Inputs/t2.c -o %t2.ast
|
||||
|
||||
// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/foo.h:1:14 -print-refs > %t
|
||||
// RUN: cat %t | count 4
|
||||
// RUN: grep 't1.c:4:19,' %t
|
||||
// RUN: grep 't1.c:28:40,' %t
|
||||
// RUN: grep 't2.c:6:3,' %t
|
||||
// RUN: grep 't2.c:7:12,' %t
|
||||
|
||||
// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/foo.h:3:9 -print-refs > %t
|
||||
// RUN: cat %t | count 1
|
||||
// RUN: grep 't2.c:7:3,' %t
|
||||
|
||||
// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/foo.h:4:9 -print-refs > %t
|
||||
// RUN: cat %t | count 1
|
||||
// RUN: grep 't1.c:8:3,' %t
|
||||
|
||||
// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/t1.c:3:22 -print-refs > %t
|
||||
// RUN: cat %t | count 1
|
||||
// RUN: grep 't1.c:6:17,' %t
|
||||
|
||||
// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/t1.c:4:11 -print-refs > %t
|
||||
// RUN: cat %t | count 1
|
||||
// RUN: grep 't1.c:6:5,' %t
|
||||
|
||||
// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/t1.c:5:30 -print-refs > %t
|
||||
// RUN: cat %t | count 3
|
||||
// RUN: grep 't1.c:5:27,' %t
|
||||
// RUN: grep 't1.c:5:44,' %t
|
||||
// RUN: grep 't1.c:6:26,' %t
|
||||
|
||||
// field test
|
||||
|
||||
// FIXME: References point at the start of MemberExpr, make them point at the field instead.
|
||||
// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/t1.c:12:7 -print-refs > %t
|
||||
// RUN: cat %t | count 1
|
||||
// RUN: grep 't1.c:21:3,' %t
|
||||
|
||||
// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/t1.c:16:7 -print-refs > %t
|
||||
// RUN: cat %t | count 1
|
||||
// RUN: grep 't1.c:22:3,' %t
|
||||
|
||||
// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/foo.h:7:11 -print-refs > %t
|
||||
// RUN: cat %t | count 2
|
||||
// RUN: grep 't1.c:25:3,' %t
|
||||
// RUN: grep 't2.c:10:3,' %t
|
|
@ -1,12 +0,0 @@
|
|||
// RUN: %clang_cc1 -emit-pch %s -o %t.ast
|
||||
// RUN: index-test %t.ast -point-at %s:8:4 -print-decls | count 2
|
||||
// RUN: index-test %t.ast -point-at %s:8:4 -print-defs | count 1
|
||||
|
||||
static void foo(int x);
|
||||
|
||||
static void bar(void) {
|
||||
foo(10);
|
||||
}
|
||||
|
||||
void foo(int x) {
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
// RUN: %clang_cc1 -emit-pch %S/Inputs/t1.m -o %t1.m.ast
|
||||
// RUN: %clang_cc1 -emit-pch %S/Inputs/t2.m -o %t2.m.ast
|
||||
|
||||
// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/Inputs/t1.m:12:12 -print-decls > %t
|
||||
// RUN: cat %t | count 2
|
||||
// RUN: grep 'objc.h:2:9,' %t | count 2
|
||||
|
||||
// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/Inputs/objc.h:5:13 -print-decls > %t
|
||||
// RUN: cat %t | count 3
|
||||
// RUN: grep 'objc.h:5:1,' %t | count 2
|
||||
// RUN: grep 't1.m:15:1,' %t | count 1
|
||||
|
||||
// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/Inputs/objc.h:10:13 -print-decls > %t
|
||||
// RUN: cat %t | count 3
|
||||
// RUN: grep 'objc.h:10:1,' %t | count 2
|
||||
// RUN: grep 't2.m:11:1,' %t | count 1
|
|
@ -1,38 +0,0 @@
|
|||
// RUN: %clang_cc1 -emit-pch %S/Inputs/t1.m -o %t1.m.ast
|
||||
// RUN: %clang_cc1 -emit-pch %S/Inputs/t2.m -o %t2.m.ast
|
||||
|
||||
// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/Inputs/objc.h:5:13 -print-refs > %t
|
||||
// RUN: cat %t | count 1
|
||||
// RUN: grep 't1.m:6:3,' %t
|
||||
|
||||
// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/Inputs/objc.h:6:13 -print-refs > %t
|
||||
// RUN: cat %t | count 2
|
||||
// RUN: grep 't1.m:7:3,' %t
|
||||
// RUN: grep 't2.m:7:3,' %t
|
||||
|
||||
// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/Inputs/objc.h:10:13 -print-refs > %t
|
||||
// RUN: cat %t | count 2
|
||||
// RUN: grep 't1.m:6:3,' %t
|
||||
// RUN: grep 't2.m:6:3,' %t
|
||||
|
||||
// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/Inputs/t1.m:6:15 -print-decls > %t
|
||||
// RUN: cat %t | count 6
|
||||
// RUN: grep 'objc.h:5:1,' %t | count 2
|
||||
// RUN: grep 'objc.h:10:1,' %t | count 2
|
||||
// RUN: grep 't1.m:15:1,' %t
|
||||
// RUN: grep 't2.m:11:1,' %t
|
||||
|
||||
// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/Inputs/t1.m:7:15 -print-decls > %t
|
||||
// RUN: cat %t | count 3
|
||||
// RUN: grep 'objc.h:6:1,' %t | count 2
|
||||
// RUN: grep 't1.m:18:1,' %t
|
||||
|
||||
// RUN: index-test %t2.m.ast %t1.m.ast -point-at %S/Inputs/t2.m:6:15 -print-decls > %t
|
||||
// RUN: cat %t | count 3
|
||||
// RUN: grep 'objc.h:10:1,' %t | count 2
|
||||
// RUN: grep 't2.m:11:1,' %t
|
||||
|
||||
// RUN: index-test %t2.m.ast %t1.m.ast -point-at %S/Inputs/t2.m:7:15 -print-decls > %t
|
||||
// RUN: cat %t | count 3
|
||||
// RUN: grep 'objc.h:6:1,' %t | count 2
|
||||
// RUN: grep 't1.m:18:1,' %t
|
|
@ -1,39 +0,0 @@
|
|||
// Run lines are sensitive to line numbers and come below the code.
|
||||
|
||||
int top_var;
|
||||
|
||||
void top_func_decl(int param1);
|
||||
|
||||
void top_func_def(int param2) {
|
||||
int local_var1;
|
||||
for (int for_var = 100; for_var < 500; ++for_var) {
|
||||
int local_var2 = for_var + 1;
|
||||
}
|
||||
}
|
||||
|
||||
struct S {
|
||||
int field_var;
|
||||
};
|
||||
|
||||
// RUN: %clang_cc1 -emit-pch %s -o %t.ast
|
||||
// RUN: c-index-test \
|
||||
// RUN: -cursor-at=%s:3:8 -cursor-at=%s:5:15 -cursor-at=%s:5:25 \
|
||||
// RUN: -cursor-at=%s:7:17 -cursor-at=%s:7:23 -cursor-at=%s:8:10 \
|
||||
// RUN: -cursor-at=%s:9:15 -cursor-at=%s:10:9 -cursor-at=%s:15:10 \
|
||||
// RUN: %s | FileCheck %s
|
||||
// CHECK: VarDecl=top_var
|
||||
// CHECK: FunctionDecl=top_func_decl
|
||||
// CHECK: ParmDecl=param1
|
||||
// CHECK: FunctionDecl=top_func_def:7:6 (Definition)
|
||||
// CHECK: ParmDecl=param2
|
||||
// CHECK: VarDecl=local_var1
|
||||
// CHECK: VarDecl=for_var
|
||||
// CHECK: VarDecl=local_var2
|
||||
// CHECK: FieldDecl=field_var
|
||||
|
||||
// FIXME: Eliminate these once clang_getCursor supports them.
|
||||
// RUN: index-test %t.ast -point-at %s:9:43 > %t
|
||||
// RUN: grep '++for_var' %t
|
||||
|
||||
// RUN: index-test %t.ast -point-at %s:10:30 > %t
|
||||
// RUN: grep 'for_var + 1' %t
|
|
@ -1,4 +1,3 @@
|
|||
add_subdirectory(CIndex)
|
||||
add_subdirectory(c-index-test)
|
||||
add_subdirectory(driver)
|
||||
add_subdirectory(index-test)
|
||||
|
|
|
@ -8,6 +8,6 @@
|
|||
##===----------------------------------------------------------------------===##
|
||||
|
||||
LEVEL := ../../..
|
||||
DIRS := driver index-test CIndex c-index-test
|
||||
DIRS := driver CIndex c-index-test
|
||||
|
||||
include $(LEVEL)/Makefile.common
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
set(LLVM_NO_RTTI 1)
|
||||
|
||||
set( LLVM_USED_LIBS
|
||||
clangIndex
|
||||
clangFrontend
|
||||
clangDriver
|
||||
clangSema
|
||||
clangAnalysis
|
||||
clangAST
|
||||
clangParse
|
||||
clangLex
|
||||
clangBasic
|
||||
)
|
||||
|
||||
set( LLVM_LINK_COMPONENTS
|
||||
bitreader
|
||||
mc
|
||||
core
|
||||
)
|
||||
|
||||
add_clang_executable(index-test
|
||||
index-test.cpp
|
||||
)
|
|
@ -1,25 +0,0 @@
|
|||
##===- tools/index-test/Makefile ---------------------------*- Makefile -*-===##
|
||||
#
|
||||
# The LLVM Compiler Infrastructure
|
||||
#
|
||||
# This file is distributed under the University of Illinois Open Source
|
||||
# License. See LICENSE.TXT for details.
|
||||
#
|
||||
##===----------------------------------------------------------------------===##
|
||||
LEVEL = ../../../..
|
||||
|
||||
TOOLNAME = index-test
|
||||
CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
|
||||
CXXFLAGS = -fno-rtti
|
||||
NO_INSTALL = 1
|
||||
|
||||
# No plugins, optimize startup time.
|
||||
TOOL_NO_EXPORTS = 1
|
||||
|
||||
include $(LEVEL)/Makefile.config
|
||||
|
||||
LINK_COMPONENTS := bitreader mc core
|
||||
USEDLIBS = clangIndex.a clangFrontend.a clangDriver.a clangSema.a \
|
||||
clangAnalysis.a clangAST.a clangParse.a clangLex.a clangBasic.a
|
||||
|
||||
include $(LLVM_SRC_ROOT)/Makefile.rules
|
|
@ -1,334 +0,0 @@
|
|||
//===--- index-test.cpp - Indexing test bed -------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This utility may be invoked in the following manner:
|
||||
// index-test --help - Output help info.
|
||||
// index-test [options] - Read from stdin.
|
||||
// index-test [options] file - Read from "file".
|
||||
// index-test [options] file1 file2 - Read these files.
|
||||
//
|
||||
// Files must be AST files.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// -point-at [file:line:column]
|
||||
// Point at a declaration/statement/expression. If no other operation is
|
||||
// specified, prints some info about it.
|
||||
//
|
||||
// -print-refs
|
||||
// Print ASTLocations that reference the -point-at node
|
||||
//
|
||||
// -print-defs
|
||||
// Print ASTLocations that define the -point-at node
|
||||
//
|
||||
// -print-decls
|
||||
// Print ASTLocations that declare the -point-at node
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "clang/Index/Program.h"
|
||||
#include "clang/Index/Indexer.h"
|
||||
#include "clang/Index/Entity.h"
|
||||
#include "clang/Index/TranslationUnit.h"
|
||||
#include "clang/Index/ASTLocation.h"
|
||||
#include "clang/Index/DeclReferenceMap.h"
|
||||
#include "clang/Index/SelectorMap.h"
|
||||
#include "clang/Index/Handlers.h"
|
||||
#include "clang/Index/Analyzer.h"
|
||||
#include "clang/Index/Utils.h"
|
||||
#include "clang/Frontend/ASTUnit.h"
|
||||
#include "clang/Frontend/CompilerInstance.h"
|
||||
#include "clang/Frontend/CompilerInvocation.h"
|
||||
#include "clang/Frontend/DiagnosticOptions.h"
|
||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
||||
#include "clang/Frontend/CommandLineSourceLoc.h"
|
||||
#include "clang/AST/DeclObjC.h"
|
||||
#include "clang/AST/ExprObjC.h"
|
||||
#include "clang/Basic/FileManager.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
#include "llvm/Support/PrettyStackTrace.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/System/Signals.h"
|
||||
using namespace clang;
|
||||
using namespace idx;
|
||||
|
||||
class TUnit : public TranslationUnit {
|
||||
public:
|
||||
TUnit(ASTUnit *ast, const std::string &filename)
|
||||
: AST(ast), Filename(filename),
|
||||
DeclRefMap(ast->getASTContext()),
|
||||
SelMap(ast->getASTContext()) { }
|
||||
|
||||
virtual ASTContext &getASTContext() { return AST->getASTContext(); }
|
||||
virtual DeclReferenceMap &getDeclReferenceMap() { return DeclRefMap; }
|
||||
virtual SelectorMap &getSelectorMap() { return SelMap; }
|
||||
|
||||
llvm::OwningPtr<ASTUnit> AST;
|
||||
std::string Filename;
|
||||
DeclReferenceMap DeclRefMap;
|
||||
SelectorMap SelMap;
|
||||
};
|
||||
|
||||
static llvm::cl::list<ParsedSourceLocation>
|
||||
PointAtLocation("point-at", llvm::cl::Optional,
|
||||
llvm::cl::value_desc("source-location"),
|
||||
llvm::cl::desc("Point at the given source location of the first AST file"));
|
||||
|
||||
enum ProgActions {
|
||||
PrintPoint, // Just print the point-at node
|
||||
PrintRefs, // Print references of the point-at node
|
||||
PrintDefs, // Print definitions of the point-at node
|
||||
PrintDecls // Print declarations of the point-at node
|
||||
};
|
||||
|
||||
static llvm::cl::opt<ProgActions>
|
||||
ProgAction(
|
||||
llvm::cl::desc("Choose action to perform on the pointed-at AST node:"),
|
||||
llvm::cl::ZeroOrMore,
|
||||
llvm::cl::init(PrintPoint),
|
||||
llvm::cl::values(
|
||||
clEnumValN(PrintRefs, "print-refs",
|
||||
"Print references"),
|
||||
clEnumValN(PrintDefs, "print-defs",
|
||||
"Print definitions"),
|
||||
clEnumValN(PrintDecls, "print-decls",
|
||||
"Print declarations"),
|
||||
clEnumValEnd));
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
DisableFree("disable-free",
|
||||
llvm::cl::desc("Disable freeing of memory on exit"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static bool HadErrors = false;
|
||||
|
||||
static void ProcessObjCMessage(ObjCMessageExpr *Msg, Indexer &Idxer) {
|
||||
llvm::raw_ostream &OS = llvm::outs();
|
||||
typedef Storing<TULocationHandler> ResultsTy;
|
||||
ResultsTy Results;
|
||||
|
||||
Analyzer Analyz(Idxer.getProgram(), Idxer);
|
||||
|
||||
switch (ProgAction) {
|
||||
default: assert(0);
|
||||
case PrintRefs:
|
||||
llvm::errs() << "Error: Cannot -print-refs on a ObjC message expression\n";
|
||||
HadErrors = true;
|
||||
return;
|
||||
|
||||
case PrintDecls: {
|
||||
Analyz.FindObjCMethods(Msg, Results);
|
||||
for (ResultsTy::iterator
|
||||
I = Results.begin(), E = Results.end(); I != E; ++I)
|
||||
I->print(OS);
|
||||
break;
|
||||
}
|
||||
|
||||
case PrintDefs: {
|
||||
Analyz.FindObjCMethods(Msg, Results);
|
||||
for (ResultsTy::iterator
|
||||
I = Results.begin(), E = Results.end(); I != E; ++I) {
|
||||
const ObjCMethodDecl *D = cast<ObjCMethodDecl>(I->AsDecl());
|
||||
if (D->isThisDeclarationADefinition())
|
||||
I->print(OS);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcessASTLocation(ASTLocation ASTLoc, Indexer &Idxer) {
|
||||
assert(ASTLoc.isValid());
|
||||
|
||||
if (ObjCMessageExpr *Msg =
|
||||
dyn_cast_or_null<ObjCMessageExpr>(ASTLoc.dyn_AsStmt()))
|
||||
return ProcessObjCMessage(Msg, Idxer);
|
||||
|
||||
Decl *D = ASTLoc.getReferencedDecl();
|
||||
if (D == 0) {
|
||||
llvm::errs() << "Error: Couldn't get referenced Decl for the ASTLocation\n";
|
||||
HadErrors = true;
|
||||
return;
|
||||
}
|
||||
|
||||
llvm::raw_ostream &OS = llvm::outs();
|
||||
typedef Storing<TULocationHandler> ResultsTy;
|
||||
ResultsTy Results;
|
||||
|
||||
Analyzer Analyz(Idxer.getProgram(), Idxer);
|
||||
|
||||
switch (ProgAction) {
|
||||
default: assert(0);
|
||||
case PrintRefs: {
|
||||
Analyz.FindReferences(D, Results);
|
||||
for (ResultsTy::iterator
|
||||
I = Results.begin(), E = Results.end(); I != E; ++I)
|
||||
I->print(OS);
|
||||
break;
|
||||
}
|
||||
|
||||
case PrintDecls: {
|
||||
Analyz.FindDeclarations(D, Results);
|
||||
for (ResultsTy::iterator
|
||||
I = Results.begin(), E = Results.end(); I != E; ++I)
|
||||
I->print(OS);
|
||||
break;
|
||||
}
|
||||
|
||||
case PrintDefs: {
|
||||
Analyz.FindDeclarations(D, Results);
|
||||
for (ResultsTy::iterator
|
||||
I = Results.begin(), E = Results.end(); I != E; ++I) {
|
||||
const Decl *D = I->AsDecl();
|
||||
bool isDef = false;
|
||||
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
|
||||
isDef = FD->isThisDeclarationADefinition();
|
||||
else if (const VarDecl *VD = dyn_cast<VarDecl>(D))
|
||||
isDef = VD->getInit() != 0;
|
||||
else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
|
||||
isDef = MD->isThisDeclarationADefinition();
|
||||
|
||||
if (isDef)
|
||||
I->print(OS);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
ASTFromSource("ast-from-source",
|
||||
llvm::cl::desc("Treat the inputs as source files to parse"));
|
||||
|
||||
static llvm::cl::list<std::string>
|
||||
CompilerArgs("arg", llvm::cl::desc("Extra arguments to use during parsing"));
|
||||
|
||||
static llvm::cl::list<std::string>
|
||||
InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input AST files>"));
|
||||
|
||||
ASTUnit *CreateFromSource(const std::string &Filename, Diagnostic &Diags,
|
||||
const char *Argv0) {
|
||||
llvm::SmallVector<const char *, 16> Args;
|
||||
Args.push_back(Filename.c_str());
|
||||
for (unsigned i = 0, e = CompilerArgs.size(); i != e; ++i)
|
||||
Args.push_back(CompilerArgs[i].c_str());
|
||||
|
||||
void *MainAddr = (void*) (intptr_t) CreateFromSource;
|
||||
std::string ResourceDir =
|
||||
CompilerInvocation::GetResourcesPath(Argv0, MainAddr);
|
||||
return ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(),
|
||||
Diags, ResourceDir);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
llvm::sys::PrintStackTraceOnErrorSignal();
|
||||
llvm::PrettyStackTraceProgram X(argc, argv);
|
||||
llvm::cl::ParseCommandLineOptions(argc, argv,
|
||||
"LLVM 'Clang' Indexing Test Bed: http://clang.llvm.org\n");
|
||||
|
||||
Program Prog;
|
||||
Indexer Idxer(Prog);
|
||||
llvm::SmallVector<TUnit*, 4> TUnits;
|
||||
|
||||
DiagnosticOptions DiagOpts;
|
||||
llvm::OwningPtr<Diagnostic> Diags(
|
||||
CompilerInstance::createDiagnostics(DiagOpts, argc, argv));
|
||||
|
||||
// If no input was specified, read from stdin.
|
||||
if (InputFilenames.empty())
|
||||
InputFilenames.push_back("-");
|
||||
|
||||
for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
|
||||
const std::string &InFile = InputFilenames[i];
|
||||
llvm::OwningPtr<ASTUnit> AST;
|
||||
if (ASTFromSource)
|
||||
AST.reset(CreateFromSource(InFile, *Diags, argv[0]));
|
||||
else
|
||||
AST.reset(ASTUnit::LoadFromPCHFile(InFile, *Diags));
|
||||
if (!AST)
|
||||
return 1;
|
||||
|
||||
TUnit *TU = new TUnit(AST.take(), InFile);
|
||||
TUnits.push_back(TU);
|
||||
|
||||
Idxer.IndexAST(TU);
|
||||
}
|
||||
|
||||
ASTLocation ASTLoc;
|
||||
const std::string &FirstFile = TUnits[0]->Filename;
|
||||
ASTUnit *FirstAST = TUnits[0]->AST.get();
|
||||
|
||||
if (!PointAtLocation.empty()) {
|
||||
const std::string &Filename = PointAtLocation[0].FileName;
|
||||
const FileEntry *File = FirstAST->getFileManager().getFile(Filename);
|
||||
if (File == 0) {
|
||||
llvm::errs() << "File '" << Filename << "' does not exist\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Safety check. Using an out-of-date AST file will only lead to crashes
|
||||
// or incorrect results.
|
||||
// FIXME: Check all the source files that make up the AST file.
|
||||
const FileEntry *ASTFile = FirstAST->getFileManager().getFile(FirstFile);
|
||||
if (File->getModificationTime() > ASTFile->getModificationTime()) {
|
||||
llvm::errs() << "[" << FirstFile << "] Error: " <<
|
||||
"Pointing at a source file which was modified after creating "
|
||||
"the AST file\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned Line = PointAtLocation[0].Line;
|
||||
unsigned Col = PointAtLocation[0].Column;
|
||||
|
||||
SourceLocation Loc =
|
||||
FirstAST->getSourceManager().getLocation(File, Line, Col);
|
||||
if (Loc.isInvalid()) {
|
||||
llvm::errs() << "[" << FirstFile << "] Error: " <<
|
||||
"Couldn't resolve source location (invalid location)\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASTLoc = ResolveLocationInAST(FirstAST->getASTContext(), Loc);
|
||||
if (ASTLoc.isInvalid()) {
|
||||
llvm::errs() << "[" << FirstFile << "] Error: " <<
|
||||
"Couldn't resolve source location (no declaration found)\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (ASTLoc.isValid()) {
|
||||
if (ProgAction == PrintPoint) {
|
||||
llvm::raw_ostream &OS = llvm::outs();
|
||||
ASTLoc.print(OS);
|
||||
if (const char *Comment =
|
||||
FirstAST->getASTContext().getCommentForDecl(ASTLoc.dyn_AsDecl()))
|
||||
OS << "Comment associated with this declaration:\n" << Comment << "\n";
|
||||
} else {
|
||||
ProcessASTLocation(ASTLoc, Idxer);
|
||||
}
|
||||
}
|
||||
|
||||
if (HadErrors)
|
||||
return 1;
|
||||
|
||||
if (!DisableFree) {
|
||||
for (int i=0, e=TUnits.size(); i != e; ++i)
|
||||
delete TUnits[i];
|
||||
}
|
||||
|
||||
// Managed static deconstruction. Useful for making things like
|
||||
// -time-passes usable.
|
||||
llvm::llvm_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue