This repository was archived by the owner on Jul 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFunctionVisitor.cs
53 lines (41 loc) · 1.63 KB
/
FunctionVisitor.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
namespace ClangSharpPInvokeGenerator
{
using System;
using System.Collections.Generic;
using System.IO;
using ClangSharp;
internal sealed class FunctionVisitor : ICXCursorVisitor
{
private readonly TextWriter tw;
private readonly HashSet<string> visitedFunctions = new HashSet<string>();
private readonly string prefixStrip;
public FunctionVisitor(TextWriter tw, string libraryPath, string prefixStrip)
{
this.prefixStrip = prefixStrip;
this.tw = tw;
this.tw.WriteLine(" private const string libraryPath = \"" + libraryPath + "\";");
this.tw.WriteLine();
}
public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data)
{
if (cursor.IsInSystemHeader())
{
return CXChildVisitResult.CXChildVisit_Continue;
}
CXCursorKind curKind = clang.getCursorKind(cursor);
// look only at function decls
if (curKind == CXCursorKind.CXCursor_FunctionDecl)
{
var functionName = clang.getCursorSpelling(cursor).ToString();
if (this.visitedFunctions.Contains(functionName))
{
return CXChildVisitResult.CXChildVisit_Continue;
}
this.visitedFunctions.Add(functionName);
Extensions.WriteFunctionInfoHelper(cursor, this.tw, this.prefixStrip);
return CXChildVisitResult.CXChildVisit_Continue;
}
return CXChildVisitResult.CXChildVisit_Recurse;
}
}
}