forked from MobileNativeFoundation/index-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
absolute-unit.cpp
81 lines (68 loc) · 2.84 KB
/
absolute-unit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "clang/Index/IndexUnitReader.h"
#include "llvm/Support/CommandLine.h"
using namespace llvm;
using namespace clang::index;
static cl::list<std::string> UnitPaths(cl::Positional, cl::OneOrMore,
cl::desc("<index-units>"));
static const char *_dependencyKindName(IndexUnitReader::DependencyKind kind) {
switch (kind) {
case IndexUnitReader::DependencyKind::Unit:
return "Unit";
case IndexUnitReader::DependencyKind::Record:
return "Record";
case IndexUnitReader::DependencyKind::File:
return "File";
}
}
#define INDENT " "
int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv);
for (const auto &unitPath : UnitPaths) {
std::string readerError;
auto reader = IndexUnitReader::createWithFilePath(unitPath, readerError);
if (not reader) {
errs() << "error: failed to read unit file " << unitPath << " -- "
<< readerError << "\n";
return EXIT_FAILURE;
}
// Output using a yaml format.
outs() << "---\n";
outs() << "# " << unitPath << "\n";
outs() << "WorkingDirectory: " << reader->getWorkingDirectory() << "\n"
<< "MainFilePath: " << reader->getMainFilePath() << "\n"
<< "OutputFile: " << reader->getOutputFile() << "\n"
<< "ModuleName: " << reader->getModuleName() << "\n"
<< "IsSystemUnit: " << reader->isSystemUnit() << "\n"
<< "IsModuleUnit: " << reader->isModuleUnit() << "\n"
<< "IsDebugCompilation: " << reader->isDebugCompilation() << "\n"
<< "CompilationTarget: " << reader->getTarget() << "\n"
<< "SysrootPath: " << reader->getSysrootPath() << "\n"
<< "ProviderIdentifier: " << reader->getProviderIdentifier() << "\n"
<< "ProviderVersion: " << reader->getProviderVersion() << "\n";
bool needsHeader = true;
reader->foreachDependency([&](const IndexUnitReader::DependencyInfo &info) {
if (needsHeader) {
outs() << "Dependencies:\n";
needsHeader = false;
}
outs() << INDENT "- DependencyKind: " << _dependencyKindName(info.Kind) << "\n"
<< INDENT " IsSystem: " << info.IsSystem << "\n"
<< INDENT " UnitOrRecordName: " << info.UnitOrRecordName << "\n"
<< INDENT " FilePath: " << info.FilePath << "\n"
<< INDENT " ModuleName: " << info.ModuleName << "\n";
return true;
});
needsHeader = true;
reader->foreachInclude([&](const IndexUnitReader::IncludeInfo &info) {
if (needsHeader) {
outs() << "Includes:\n";
needsHeader = false;
}
outs() << INDENT "- SourcePath: " << info.SourcePath << "\n"
<< INDENT " SourceLine: " << info.SourceLine << "\n"
<< INDENT " TargetPath: " << info.TargetPath << "\n";
return true;
});
}
return EXIT_SUCCESS;
}