Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 1 | //===--- index-test.cpp - Indexing test bed -------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This utility may be invoked in the following manner: |
| 11 | // index-test --help - Output help info. |
| 12 | // index-test [options] - Read from stdin. |
| 13 | // index-test [options] file - Read from "file". |
| 14 | // index-test [options] file1 file2 - Read these files. |
| 15 | // |
| 16 | // Files must be AST files. |
| 17 | // |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | // |
Zhongxing Xu | 96bac6b | 2009-07-07 07:14:55 +0000 | [diff] [blame] | 20 | // -point-at [file:line:column] |
Argyrios Kyrtzidis | 6e4a86d | 2009-06-25 21:54:50 +0000 | [diff] [blame] | 21 | // Point at a declaration/statement/expression. If no other operation is |
| 22 | // specified, prints some info about it. |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 23 | // |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 24 | // -print-refs |
Argyrios Kyrtzidis | 874012b | 2009-07-06 21:34:20 +0000 | [diff] [blame] | 25 | // Print ASTLocations that reference the -point-at node |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 26 | // |
| 27 | // -print-defs |
Argyrios Kyrtzidis | 874012b | 2009-07-06 21:34:20 +0000 | [diff] [blame] | 28 | // Print ASTLocations that define the -point-at node |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 29 | // |
| 30 | // -print-decls |
Argyrios Kyrtzidis | 874012b | 2009-07-06 21:34:20 +0000 | [diff] [blame] | 31 | // Print ASTLocations that declare the -point-at node |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 32 | // |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 33 | //===----------------------------------------------------------------------===// |
| 34 | |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 35 | #include "clang/Index/Program.h" |
Argyrios Kyrtzidis | b17dc46 | 2009-07-29 23:38:21 +0000 | [diff] [blame] | 36 | #include "clang/Index/Indexer.h" |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 37 | #include "clang/Index/Entity.h" |
| 38 | #include "clang/Index/TranslationUnit.h" |
Argyrios Kyrtzidis | ccbcb70 | 2009-07-06 21:34:47 +0000 | [diff] [blame] | 39 | #include "clang/Index/ASTLocation.h" |
| 40 | #include "clang/Index/DeclReferenceMap.h" |
Argyrios Kyrtzidis | 0f39848 | 2009-07-29 23:41:08 +0000 | [diff] [blame] | 41 | #include "clang/Index/SelectorMap.h" |
Argyrios Kyrtzidis | 94431b5 | 2009-07-29 23:39:03 +0000 | [diff] [blame] | 42 | #include "clang/Index/Handlers.h" |
Argyrios Kyrtzidis | 7f4656e | 2009-07-29 23:40:14 +0000 | [diff] [blame] | 43 | #include "clang/Index/Analyzer.h" |
Argyrios Kyrtzidis | 818e15b | 2009-07-06 21:35:02 +0000 | [diff] [blame] | 44 | #include "clang/Index/Utils.h" |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 45 | #include "clang/Frontend/ASTUnit.h" |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 46 | #include "clang/Frontend/CommandLineSourceLoc.h" |
Argyrios Kyrtzidis | 19b732a | 2009-07-30 00:03:55 +0000 | [diff] [blame] | 47 | #include "clang/AST/DeclObjC.h" |
| 48 | #include "clang/AST/ExprObjC.h" |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 49 | #include "clang/Basic/FileManager.h" |
| 50 | #include "clang/Basic/SourceManager.h" |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 51 | #include "llvm/Support/CommandLine.h" |
| 52 | #include "llvm/Support/ManagedStatic.h" |
| 53 | #include "llvm/Support/PrettyStackTrace.h" |
| 54 | #include "llvm/Support/raw_ostream.h" |
| 55 | #include "llvm/System/Signals.h" |
| 56 | using namespace clang; |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 57 | using namespace idx; |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 58 | |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 59 | class TUnit : public TranslationUnit { |
| 60 | public: |
| 61 | TUnit(ASTUnit *ast, const std::string &filename) |
Argyrios Kyrtzidis | 0f39848 | 2009-07-29 23:41:08 +0000 | [diff] [blame] | 62 | : AST(ast), Filename(filename), |
| 63 | DeclRefMap(ast->getASTContext()), |
| 64 | SelMap(ast->getASTContext()) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 65 | |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 66 | virtual ASTContext &getASTContext() { return AST->getASTContext(); } |
Argyrios Kyrtzidis | 768a6c9 | 2009-07-29 23:39:18 +0000 | [diff] [blame] | 67 | virtual DeclReferenceMap &getDeclReferenceMap() { return DeclRefMap; } |
Argyrios Kyrtzidis | 0f39848 | 2009-07-29 23:41:08 +0000 | [diff] [blame] | 68 | virtual SelectorMap &getSelectorMap() { return SelMap; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 69 | |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 70 | llvm::OwningPtr<ASTUnit> AST; |
| 71 | std::string Filename; |
Argyrios Kyrtzidis | 768a6c9 | 2009-07-29 23:39:18 +0000 | [diff] [blame] | 72 | DeclReferenceMap DeclRefMap; |
Argyrios Kyrtzidis | 0f39848 | 2009-07-29 23:41:08 +0000 | [diff] [blame] | 73 | SelectorMap SelMap; |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 74 | }; |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 75 | |
| 76 | static llvm::cl::list<ParsedSourceLocation> |
| 77 | PointAtLocation("point-at", llvm::cl::Optional, |
| 78 | llvm::cl::value_desc("source-location"), |
| 79 | llvm::cl::desc("Point at the given source location of the first AST file")); |
| 80 | |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 81 | enum ProgActions { |
| 82 | PrintPoint, // Just print the point-at node |
| 83 | PrintRefs, // Print references of the point-at node |
| 84 | PrintDefs, // Print definitions of the point-at node |
| 85 | PrintDecls // Print declarations of the point-at node |
| 86 | }; |
| 87 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 88 | static llvm::cl::opt<ProgActions> |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 89 | ProgAction( |
| 90 | llvm::cl::desc("Choose action to perform on the pointed-at AST node:"), |
| 91 | llvm::cl::ZeroOrMore, |
| 92 | llvm::cl::init(PrintPoint), |
| 93 | llvm::cl::values( |
| 94 | clEnumValN(PrintRefs, "print-refs", |
| 95 | "Print references"), |
| 96 | clEnumValN(PrintDefs, "print-defs", |
| 97 | "Print definitions"), |
| 98 | clEnumValN(PrintDecls, "print-decls", |
| 99 | "Print declarations"), |
| 100 | clEnumValEnd)); |
| 101 | |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 102 | static llvm::cl::opt<bool> |
| 103 | DisableFree("disable-free", |
| 104 | llvm::cl::desc("Disable freeing of memory on exit"), |
| 105 | llvm::cl::init(false)); |
| 106 | |
Argyrios Kyrtzidis | 1258554 | 2009-07-14 03:18:40 +0000 | [diff] [blame] | 107 | static bool HadErrors = false; |
| 108 | |
Argyrios Kyrtzidis | 19b732a | 2009-07-30 00:03:55 +0000 | [diff] [blame] | 109 | static void ProcessObjCMessage(ObjCMessageExpr *Msg, Indexer &Idxer) { |
| 110 | llvm::raw_ostream &OS = llvm::outs(); |
| 111 | typedef Storing<TULocationHandler> ResultsTy; |
| 112 | ResultsTy Results; |
| 113 | |
| 114 | Analyzer Analyz(Idxer.getProgram(), Idxer); |
| 115 | |
| 116 | switch (ProgAction) { |
| 117 | default: assert(0); |
| 118 | case PrintRefs: |
| 119 | llvm::errs() << "Error: Cannot -print-refs on a ObjC message expression\n"; |
| 120 | HadErrors = true; |
| 121 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 122 | |
Argyrios Kyrtzidis | 19b732a | 2009-07-30 00:03:55 +0000 | [diff] [blame] | 123 | case PrintDecls: { |
| 124 | Analyz.FindObjCMethods(Msg, Results); |
| 125 | for (ResultsTy::iterator |
| 126 | I = Results.begin(), E = Results.end(); I != E; ++I) |
| 127 | I->print(OS); |
| 128 | break; |
| 129 | } |
| 130 | |
| 131 | case PrintDefs: { |
| 132 | Analyz.FindObjCMethods(Msg, Results); |
| 133 | for (ResultsTy::iterator |
| 134 | I = Results.begin(), E = Results.end(); I != E; ++I) { |
Argyrios Kyrtzidis | f4526e3 | 2009-09-29 19:44:27 +0000 | [diff] [blame] | 135 | const ObjCMethodDecl *D = cast<ObjCMethodDecl>(I->AsDecl()); |
Argyrios Kyrtzidis | 19b732a | 2009-07-30 00:03:55 +0000 | [diff] [blame] | 136 | if (D->isThisDeclarationADefinition()) |
| 137 | I->print(OS); |
| 138 | } |
| 139 | break; |
| 140 | } |
| 141 | |
| 142 | } |
| 143 | } |
| 144 | |
Argyrios Kyrtzidis | b17dc46 | 2009-07-29 23:38:21 +0000 | [diff] [blame] | 145 | static void ProcessASTLocation(ASTLocation ASTLoc, Indexer &Idxer) { |
Argyrios Kyrtzidis | 4499405 | 2009-07-06 21:35:26 +0000 | [diff] [blame] | 146 | assert(ASTLoc.isValid()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 147 | |
Argyrios Kyrtzidis | 19b732a | 2009-07-30 00:03:55 +0000 | [diff] [blame] | 148 | if (ObjCMessageExpr *Msg = |
Argyrios Kyrtzidis | f4526e3 | 2009-09-29 19:44:27 +0000 | [diff] [blame] | 149 | dyn_cast_or_null<ObjCMessageExpr>(ASTLoc.dyn_AsStmt())) |
Argyrios Kyrtzidis | 19b732a | 2009-07-30 00:03:55 +0000 | [diff] [blame] | 150 | return ProcessObjCMessage(Msg, Idxer); |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 151 | |
Argyrios Kyrtzidis | dc50c64 | 2009-07-18 21:17:58 +0000 | [diff] [blame] | 152 | Decl *D = ASTLoc.getReferencedDecl(); |
Argyrios Kyrtzidis | 1258554 | 2009-07-14 03:18:40 +0000 | [diff] [blame] | 153 | if (D == 0) { |
Argyrios Kyrtzidis | ec930d3 | 2009-07-21 00:05:10 +0000 | [diff] [blame] | 154 | llvm::errs() << "Error: Couldn't get referenced Decl for the ASTLocation\n"; |
Argyrios Kyrtzidis | 1258554 | 2009-07-14 03:18:40 +0000 | [diff] [blame] | 155 | HadErrors = true; |
| 156 | return; |
| 157 | } |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 158 | |
Argyrios Kyrtzidis | 7f4656e | 2009-07-29 23:40:14 +0000 | [diff] [blame] | 159 | llvm::raw_ostream &OS = llvm::outs(); |
| 160 | typedef Storing<TULocationHandler> ResultsTy; |
| 161 | ResultsTy Results; |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 162 | |
Argyrios Kyrtzidis | 7f4656e | 2009-07-29 23:40:14 +0000 | [diff] [blame] | 163 | Analyzer Analyz(Idxer.getProgram(), Idxer); |
Argyrios Kyrtzidis | 94431b5 | 2009-07-29 23:39:03 +0000 | [diff] [blame] | 164 | |
Argyrios Kyrtzidis | 7f4656e | 2009-07-29 23:40:14 +0000 | [diff] [blame] | 165 | switch (ProgAction) { |
| 166 | default: assert(0); |
| 167 | case PrintRefs: { |
| 168 | Analyz.FindReferences(D, Results); |
| 169 | for (ResultsTy::iterator |
| 170 | I = Results.begin(), E = Results.end(); I != E; ++I) |
| 171 | I->print(OS); |
| 172 | break; |
| 173 | } |
| 174 | |
| 175 | case PrintDecls: { |
| 176 | Analyz.FindDeclarations(D, Results); |
| 177 | for (ResultsTy::iterator |
| 178 | I = Results.begin(), E = Results.end(); I != E; ++I) |
| 179 | I->print(OS); |
| 180 | break; |
| 181 | } |
| 182 | |
Argyrios Kyrtzidis | 19b732a | 2009-07-30 00:03:55 +0000 | [diff] [blame] | 183 | case PrintDefs: { |
Argyrios Kyrtzidis | 7f4656e | 2009-07-29 23:40:14 +0000 | [diff] [blame] | 184 | Analyz.FindDeclarations(D, Results); |
| 185 | for (ResultsTy::iterator |
| 186 | I = Results.begin(), E = Results.end(); I != E; ++I) { |
Argyrios Kyrtzidis | f4526e3 | 2009-09-29 19:44:27 +0000 | [diff] [blame] | 187 | const Decl *D = I->AsDecl(); |
Argyrios Kyrtzidis | 7f4656e | 2009-07-29 23:40:14 +0000 | [diff] [blame] | 188 | bool isDef = false; |
| 189 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 190 | isDef = FD->isThisDeclarationADefinition(); |
| 191 | else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) |
| 192 | isDef = VD->getInit() != 0; |
Argyrios Kyrtzidis | 87bcb50 | 2009-07-29 23:41:46 +0000 | [diff] [blame] | 193 | else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) |
| 194 | isDef = MD->isThisDeclarationADefinition(); |
Argyrios Kyrtzidis | 7f4656e | 2009-07-29 23:40:14 +0000 | [diff] [blame] | 195 | |
| 196 | if (isDef) |
| 197 | I->print(OS); |
| 198 | } |
| 199 | break; |
| 200 | } |
| 201 | |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 205 | static llvm::cl::list<std::string> |
| 206 | InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input AST files>")); |
| 207 | |
| 208 | int main(int argc, char **argv) { |
| 209 | llvm::sys::PrintStackTraceOnErrorSignal(); |
| 210 | llvm::PrettyStackTraceProgram X(argc, argv); |
| 211 | llvm::cl::ParseCommandLineOptions(argc, argv, |
| 212 | "LLVM 'Clang' Indexing Test Bed: http://clang.llvm.org\n"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 213 | |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 214 | Program Prog; |
Daniel Dunbar | a390759 | 2009-09-21 03:03:22 +0000 | [diff] [blame] | 215 | Indexer Idxer(Prog); |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 216 | llvm::SmallVector<TUnit*, 4> TUnits; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 217 | |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 218 | // If no input was specified, read from stdin. |
| 219 | if (InputFilenames.empty()) |
| 220 | InputFilenames.push_back("-"); |
| 221 | |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 222 | for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) { |
| 223 | const std::string &InFile = InputFilenames[i]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 225 | std::string ErrMsg; |
| 226 | llvm::OwningPtr<ASTUnit> AST; |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 227 | |
Steve Naroff | 36c4464 | 2009-10-19 14:34:22 +0000 | [diff] [blame] | 228 | AST.reset(ASTUnit::LoadFromPCHFile(InFile, &ErrMsg)); |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 229 | if (!AST) { |
| 230 | llvm::errs() << "[" << InFile << "] Error: " << ErrMsg << '\n'; |
| 231 | return 1; |
| 232 | } |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 233 | |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 234 | TUnit *TU = new TUnit(AST.take(), InFile); |
| 235 | TUnits.push_back(TU); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 236 | |
Argyrios Kyrtzidis | b17dc46 | 2009-07-29 23:38:21 +0000 | [diff] [blame] | 237 | Idxer.IndexAST(TU); |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Argyrios Kyrtzidis | 4499405 | 2009-07-06 21:35:26 +0000 | [diff] [blame] | 240 | ASTLocation ASTLoc; |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 241 | const std::string &FirstFile = TUnits[0]->Filename; |
| 242 | ASTUnit *FirstAST = TUnits[0]->AST.get(); |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 243 | |
| 244 | if (!PointAtLocation.empty()) { |
| 245 | const std::string &Filename = PointAtLocation[0].FileName; |
Steve Naroff | 36c4464 | 2009-10-19 14:34:22 +0000 | [diff] [blame] | 246 | const FileEntry *File = FirstAST->getFileManager().getFile(Filename); |
Argyrios Kyrtzidis | 19b732a | 2009-07-30 00:03:55 +0000 | [diff] [blame] | 247 | if (File == 0) { |
| 248 | llvm::errs() << "File '" << Filename << "' does not exist\n"; |
| 249 | return 1; |
| 250 | } |
Argyrios Kyrtzidis | 119b7fe | 2009-06-25 22:15:12 +0000 | [diff] [blame] | 251 | |
| 252 | // Safety check. Using an out-of-date AST file will only lead to crashes |
| 253 | // or incorrect results. |
| 254 | // FIXME: Check all the source files that make up the AST file. |
Steve Naroff | 36c4464 | 2009-10-19 14:34:22 +0000 | [diff] [blame] | 255 | const FileEntry *ASTFile = FirstAST->getFileManager().getFile(FirstFile); |
Argyrios Kyrtzidis | 119b7fe | 2009-06-25 22:15:12 +0000 | [diff] [blame] | 256 | if (File->getModificationTime() > ASTFile->getModificationTime()) { |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 257 | llvm::errs() << "[" << FirstFile << "] Error: " << |
Argyrios Kyrtzidis | 119b7fe | 2009-06-25 22:15:12 +0000 | [diff] [blame] | 258 | "Pointing at a source file which was modified after creating " |
| 259 | "the AST file\n"; |
| 260 | return 1; |
| 261 | } |
| 262 | |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 263 | unsigned Line = PointAtLocation[0].Line; |
| 264 | unsigned Col = PointAtLocation[0].Column; |
| 265 | |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 266 | SourceLocation Loc = |
| 267 | FirstAST->getSourceManager().getLocation(File, Line, Col); |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 268 | if (Loc.isInvalid()) { |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 269 | llvm::errs() << "[" << FirstFile << "] Error: " << |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 270 | "Couldn't resolve source location (invalid location)\n"; |
| 271 | return 1; |
| 272 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 273 | |
Argyrios Kyrtzidis | 4499405 | 2009-07-06 21:35:26 +0000 | [diff] [blame] | 274 | ASTLoc = ResolveLocationInAST(FirstAST->getASTContext(), Loc); |
| 275 | if (ASTLoc.isInvalid()) { |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 276 | llvm::errs() << "[" << FirstFile << "] Error: " << |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 277 | "Couldn't resolve source location (no declaration found)\n"; |
| 278 | return 1; |
| 279 | } |
| 280 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | |
Argyrios Kyrtzidis | 4499405 | 2009-07-06 21:35:26 +0000 | [diff] [blame] | 282 | if (ASTLoc.isValid()) { |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 283 | if (ProgAction == PrintPoint) { |
| 284 | llvm::raw_ostream &OS = llvm::outs(); |
Argyrios Kyrtzidis | 4499405 | 2009-07-06 21:35:26 +0000 | [diff] [blame] | 285 | ASTLoc.print(OS); |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 286 | if (const char *Comment = |
Argyrios Kyrtzidis | f4526e3 | 2009-09-29 19:44:27 +0000 | [diff] [blame] | 287 | FirstAST->getASTContext().getCommentForDecl(ASTLoc.dyn_AsDecl())) |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 288 | OS << "Comment associated with this declaration:\n" << Comment << "\n"; |
| 289 | } else { |
Argyrios Kyrtzidis | b17dc46 | 2009-07-29 23:38:21 +0000 | [diff] [blame] | 290 | ProcessASTLocation(ASTLoc, Idxer); |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 291 | } |
| 292 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | |
Argyrios Kyrtzidis | 1258554 | 2009-07-14 03:18:40 +0000 | [diff] [blame] | 294 | if (HadErrors) |
| 295 | return 1; |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 296 | |
Argyrios Kyrtzidis | 7b332d9 | 2009-07-05 22:22:35 +0000 | [diff] [blame] | 297 | if (!DisableFree) { |
| 298 | for (int i=0, e=TUnits.size(); i != e; ++i) |
| 299 | delete TUnits[i]; |
| 300 | } |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 301 | |
| 302 | // Managed static deconstruction. Useful for making things like |
| 303 | // -time-passes usable. |
| 304 | llvm::llvm_shutdown(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 305 | |
Argyrios Kyrtzidis | 30b983b | 2009-06-25 18:22:52 +0000 | [diff] [blame] | 306 | return 0; |
| 307 | } |