 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
90.0% |
9 / 10 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
100.0% |
10 / 10 |
| |
|
Line Coverage: |
96.0% |
24 / 25 |
| |
 |
|
 |
1 : //===- CIndexInclusionStack.cpp - Clang-C Source Indexing Library ---------===//
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 file defines a callback mechanism for clients to get the inclusion
11 : // stack from a translation unit.
12 : //
13 : //===----------------------------------------------------------------------===//
14 :
15 : #include "CIndexer.h"
16 : #include "CXSourceLocation.h"
17 : #include "clang/AST/DeclVisitor.h"
18 : #include "llvm/ADT/SmallString.h"
19 : #include "llvm/Support/raw_ostream.h"
20 :
21 : extern "C" {
22 : void clang_getInclusions(CXTranslationUnit TU, CXInclusionVisitor CB,
23 1: CXClientData clientData) {
24 :
25 1: ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
26 1: SourceManager &SM = CXXUnit->getSourceManager();
27 1: ASTContext &Ctx = CXXUnit->getASTContext();
28 :
29 1: llvm::SmallVector<CXSourceLocation, 10> InclusionStack;
30 1: unsigned i = SM.sloc_loaded_entry_size();
31 1: unsigned n = SM.sloc_entry_size();
32 :
33 : // In the case where all the SLocEntries are in an external source, traverse
34 : // those SLocEntries as well. This is the case where we are looking
35 : // at the inclusion stack of an AST/PCH file.
0: branch 0 not taken
1: branch 1 taken
36 1: if (i >= n)
37 0: i = 0;
38 :
5: branch 0 taken
1: branch 1 taken
39 6: for ( ; i < n ; ++i) {
40 :
41 5: const SrcMgr::SLocEntry &SL = SM.getSLocEntry(i);
42 :
1: branch 1 taken
4: branch 2 taken
43 5: if (!SL.isFile())
44 1: continue;
45 :
46 4: const SrcMgr::FileInfo &FI = SL.getFile();
1: branch 1 taken
3: branch 2 taken
47 4: if (!FI.getContentCache()->Entry)
48 1: continue;
49 :
50 : // Build the inclusion stack.
51 3: SourceLocation L = FI.getIncludeLoc();
52 3: InclusionStack.clear();
3: branch 1 taken
3: branch 2 taken
53 9: while (L.isValid()) {
54 3: PresumedLoc PLoc = SM.getPresumedLoc(L);
55 3: InclusionStack.push_back(cxloc::translateSourceLocation(Ctx, L));
56 3: L = PLoc.getIncludeLoc();
57 : }
58 :
59 : // Callback to the client.
60 : // FIXME: We should have a function to construct CXFiles.
61 : CB((CXFile) FI.getContentCache()->Entry,
62 3: InclusionStack.data(), InclusionStack.size(), clientData);
63 1: }
64 1: }
65 : } // end extern C
Generated: 2010-02-10 01:31 by zcov