forked from SimonRichards/clang-sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.cs
76 lines (66 loc) · 2.63 KB
/
Index.cs
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
using System;
using System.Linq;
namespace ClangSharp {
public class Index : IDisposable {
internal readonly IntPtr Native;
public Index()
: this(true, false) {
}
public Index(bool excludeDeclarationsFromPch, bool displayDiagnostics) {
Native = Interop.clang_createIndex(excludeDeclarationsFromPch ? 1 : 0, displayDiagnostics ? 1 : 0);
}
public void Dispose() {
Interop.clang_disposeIndex(Native);
GC.SuppressFinalize(this);
}
~Index() {
Interop.clang_disposeIndex(Native);
}
public bool ExternalAstGeneration {
set {
Interop.clang_setUseExternalASTGeneration(Native, value ? 1 : 0);
}
}
public TranslationUnit CreateTranslationUnitFromAst(string astFilename) {
return new TranslationUnit(astFilename, Interop.clang_createTranslationUnit(Native, astFilename));
}
public TranslationUnit CreateTranslationUnit(string filename, Options[] clangArgs, UnsavedFile[] unsavedFiles = null, TranslationUnitFlags options = TranslationUnitFlags.None) {
var args = clangArgs.Select(arg => "-" + arg.ToString().Replace("_", "-")).ToArray();
return CreateTranslationUnit(
filename,
args,
unsavedFiles,
options);
}
public TranslationUnit CreateTranslationUnit(string filename, string[] clangArgs = null, UnsavedFile[] unsavedFiles = null, TranslationUnitFlags options = TranslationUnitFlags.None) {
if (!System.IO.File.Exists(filename)) {
throw new System.IO.FileNotFoundException("Couldn't find input file.", filename);
}
clangArgs = clangArgs ?? new string[0];
unsavedFiles = unsavedFiles ?? new UnsavedFile[0];
return new TranslationUnit(
filename,
Interop.clang_parseTranslationUnit(
Native,
filename,
clangArgs,
clangArgs.Length,
unsavedFiles.Select(f => f.Native).ToArray(),
(uint)unsavedFiles.Length,
options));
}
}
[Flags]
public enum TranslationUnitFlags
{
None = 0x00,
DetailedPreprocessingRecord = 0x01,
Incomplete = 0x02,
PrecompiledPreamble = 0x04,
CacheCompletionResults = 0x08,
ForSerialization = 0x10,
CXXChainedPCH = 0x20,
SkipFunctionBodies = 0x40,
IncludeBriefCommentsInCodeCompletion = 0x80
}
}