Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void EndUnchecked()

public void BeginValue(in ValueDesc desc)
{
if (_generator.Config.GenerateDocIncludes && (desc.Kind == ValueKind.Enumerator))
if (_generator.Config.GenerateDocIncludes && !string.IsNullOrWhiteSpace(desc.ParentName))
{
WriteIndented("/// <include file='");
Write(desc.ParentName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ private void VisitVarDecl(VarDecl varDecl)

var desc = new ValueDesc {
AccessSpecifier = accessSpecifier,
ParentName = IsPrevContextDecl<RecordDecl>(out var recordDecl, out _) ? GetRemappedCursorName(recordDecl) : className,
TypeName = typeName,
EscapedName = escapedName,
NativeTypeName = nativeTypeName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ClangSharp.Test
{
public static partial class Constants
{
/// <include file='Constants.xml' path='doc/member[@name="Constants.MyMacro"]/*' />
[NativeTypeName("#define MY_MACRO 42")]
public const int MyMacro = 42;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<bindings>
<namespace name="ClangSharp.Test">
<class name="Constants" access="public" static="true">
<constant name="MyMacro" access="public">
<type primitive="True">int</type>
<value>
<code>42</code>
</value>
</constant>
</class>
</namespace>
</bindings>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace ClangSharp.Test
{
/// <include file='MyStruct.xml' path='doc/member[@name="MyStruct"]/*' />
public partial struct MyStruct
{
/// <include file='MyStruct.xml' path='doc/member[@name="MyStruct.value"]/*' />
public int value;
}

public static partial class Methods
{
/// <include file='Methods.xml' path='doc/member[@name="Methods.MyConstant"]/*' />
[NativeTypeName("const MyStruct")]
public static readonly MyStruct MyConstant = new MyStruct
{
value = 0,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<bindings>
<namespace name="ClangSharp.Test">
<struct name="MyStruct" access="public">
<field name="value" access="public">
<type>int</type>
</field>
</struct>
<class name="Methods" access="public" static="true">
<constant name="MyConstant" access="public">
<type primitive="False">MyStruct</type>
<value>
<code>new MyStruct
{
value = 0,
}</code>
</value>
</constant>
</class>
</namespace>
</bindings>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ClangSharp.Test
{
/// <include file='MyStruct.xml' path='doc/member[@name="MyStruct"]/*' />
public partial struct MyStruct
{
/// <include file='MyStruct.xml' path='doc/member[@name="MyStruct.MyConstant"]/*' />
[NativeTypeName("const int")]
public const int MyConstant = 42;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<bindings>
<namespace name="ClangSharp.Test">
<struct name="MyStruct" access="public">
<constant name="MyConstant" access="public">
<type primitive="True">int</type>
<value>
<code>42</code>
</value>
</constant>
</struct>
</namespace>
</bindings>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ public VarDeclarationTest(BaselineVariant variant) : base(variant)

protected override string Area => "VarDeclaration";

[Test]
public Task DocIncludesMacroTest()
{
var remappedNames = new Dictionary<string, string> { ["MY_MACRO"] = "MyMacro" };
var withClasses = new Dictionary<string, string> { ["MyMacro"] = "Constants" };
return ValidateAsync(nameof(DocIncludesMacroTest), "#define MY_MACRO 42", additionalConfigOptions: PInvokeGeneratorConfigurationOptions.GenerateDocIncludes, remappedNames: remappedNames, withClasses: withClasses);
}

[Test]
public Task DocIncludesStaticConstTest()
=> ValidateAsync(nameof(DocIncludesStaticConstTest), @"struct MyStruct
{
int value;
};

static const MyStruct MyConstant = { 0 };", additionalConfigOptions: PInvokeGeneratorConfigurationOptions.GenerateDocIncludes);

[Test]
public Task DocIncludesStaticMemberTest()
{
var remappedNames = new Dictionary<string, string> { ["NativeStruct"] = "MyStruct", ["NativeConstant"] = "MyConstant" };
return ValidateAsync(nameof(DocIncludesStaticMemberTest), @"struct NativeStruct
{
static const int NativeConstant = 42;
};", additionalConfigOptions: PInvokeGeneratorConfigurationOptions.GenerateDocIncludes, remappedNames: remappedNames);
}

[TestCase("double")]
[TestCase("short")]
[TestCase("int")]
Expand Down
Loading