-
Notifications
You must be signed in to change notification settings - Fork 524
/
Copy pathCommon.Gen.cs
92 lines (76 loc) · 2.63 KB
/
Common.Gen.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System.Linq;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Generators.CSharp;
using CppSharp.Types;
using CppSharp.Utils;
namespace CppSharp.Tests
{
[TypeMap("TypeMappedIndex")]
public class TypeMappedIndex : TypeMap
{
public override Type CLISignatureType(TypePrinterContext ctx)
{
return new BuiltinType(PrimitiveType.UShort);
}
public override void CLIMarshalToManaged(MarshalContext ctx)
{
ctx.Return.Write(ctx.ReturnVarName);
}
public override void CLIMarshalToNative(MarshalContext ctx)
{
ctx.Return.Write("::TypeMappedIndex()");
}
public override Type CSharpSignatureType(TypePrinterContext ctx)
{
return new BuiltinType(PrimitiveType.UShort);
}
public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)
{
ctx.Return.Write(ctx.ReturnVarName);
}
public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
{
ctx.Return.Write("IntPtr.Zero");
}
}
public class CommonTestsGenerator : GeneratorTest
{
public CommonTestsGenerator(GeneratorKind kind)
: base("Common", kind)
{
}
public override void Setup(Driver driver)
{
base.Setup(driver);
driver.Options.GenerateName = file =>
file.FileNameWithoutExtension + "_GenerateName";
driver.Options.Modules[1].OutputNamespace = "CommonTest";
driver.ParserOptions.UnityBuild = true;
}
public override void SetupPasses(Driver driver)
{
driver.Options.MarshalCharAsManagedChar = false; // c++ char is mapped to sbyte. c++ wchar_t is mapped to char
driver.Options.GenerateDefaultValuesForArguments = true;
}
public override void Preprocess(Driver driver, ASTContext ctx)
{
ctx.SetClassAsValueType("Bar");
ctx.SetClassAsValueType("Bar2");
ctx.IgnoreClassWithName("IgnoredType");
if (ctx.FindCompleteClass("Foo") != null)
{
ctx.FindCompleteClass("Foo").Enums.First(
e => string.IsNullOrEmpty(e.Name)).Name = "RenamedEmptyEnum";
}
}
public override void Postprocess(Driver driver, ASTContext ctx)
{
}
public static void Main(string[] args)
{
ConsoleDriver.Run(new CommonTestsGenerator(GeneratorKind.CLI));
ConsoleDriver.Run(new CommonTestsGenerator(GeneratorKind.CSharp));
}
}
}