Skip to content

Commit ae1300c

Browse files
committed
Fixes #188
* Updating comments to indicate string.Empty is a valid struct name for anonymous structs. * Corrected DebugStructType.Name to never produce a null name (uses string.Empty instead) * Corrected Context.CreateStructType to allow empty string
1 parent 0104b98 commit ae1300c

File tree

5 files changed

+42
-17
lines changed

5 files changed

+42
-17
lines changed

src/Design.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Ubiquity.NET.Llvm is designed to provide an OO model that faithfully reflects th
1111
underlying LLVM model while fitting naturally into .NET programming patterns.
1212
1) While the underlying extended "C" LLVM API is available in the Ubiquity.NET.Llvm.Interop package
1313
direct use of those APIs is generally discouraged as there are a lot of subtleties for correct
14-
usage that are automatically mnaged by the Ubiquity.NET.Llvm class library.
14+
usage that are automatically managed by the Ubiquity.NET.Llvm class library.
1515
1) FxCop Clean
1616
4) Leverage existing LLVM-C APIs underneath whenever possible
1717
1) Extend only when needed with custom wrappers
1818

1919
# Details
20-
## Interning (Uniquing in LLVM)
20+
## Interning (Uniqueing in LLVM)
2121
Many of the underlying object instances in LLVM are interned/Uniqued. That is,
2222
there will only be one instance of a type with a given value within some scope.
2323

src/Ubiquity.NET.Llvm.Tests/DebugInfo/DebugStructTypeTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,31 @@ public void DebugStructType_constructing_empty_struct_succeeds()
4040
Assert.AreEqual( sourceName, structType.SourceName );
4141
}
4242

43+
[TestMethod]
44+
public void DebugStructType_constructing_empty_anonymous_struct_succeeds( )
45+
{
46+
using var context = new Context( );
47+
using var testModule = context.CreateBitcodeModule( "test" );
48+
49+
string sourceName = string.Empty;
50+
string linkageName = string.Empty;
51+
52+
var structType = new DebugStructType( module: testModule
53+
, nativeName: linkageName
54+
, scope: null
55+
, sourceName: sourceName
56+
, file: null
57+
, line: 0
58+
, debugFlags: default
59+
, members: Enumerable.Empty<DebugMemberInfo>()
60+
); // rest of args use defaults...
61+
Assert.IsTrue( structType.IsSized );
62+
Assert.IsFalse( structType.IsPacked );
63+
Assert.IsTrue( structType.IsStruct );
64+
Assert.AreEqual( linkageName, structType.Name );
65+
Assert.AreEqual( sourceName, structType.SourceName );
66+
}
67+
4368
#if NOT_YET_READY_GENERATED
4469
[TestMethod]
4570
public void SetBody_StateUnderTest_ExpectedBehavior( )

src/Ubiquity.NET.Llvm/Context.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ public IStructType CreateStructType( string name, bool packed, params ITypeRef[
440440
=> CreateStructType( name, packed, ( IEnumerable<ITypeRef> )elements );
441441

442442
/// <summary>Creates a new structure type in this <see cref="Context"/></summary>
443-
/// <param name="name">Name of the structure</param>
443+
/// <param name="name">Name of the structure (use <see cref="string.Empty"/> for anonymous types)</param>
444444
/// <param name="packed">Flag indicating if the structure is packed</param>
445445
/// <param name="elements">Types for the structures elements in layout order</param>
446446
/// <returns>
@@ -451,7 +451,7 @@ public IStructType CreateStructType( string name, bool packed, params ITypeRef[
451451
/// </remarks>
452452
public IStructType CreateStructType( string name, bool packed, IEnumerable<ITypeRef> elements )
453453
{
454-
name.ValidateNotNullOrWhiteSpace( nameof( name ) );
454+
name.ValidateNotNull( nameof( name ) );
455455
elements.ValidateNotNull( nameof( elements ) );
456456

457457
var retVal = TypeRef.FromHandle<IStructType>( LLVMStructCreateNamed( ContextHandle, name ).ThrowIfInvalid( ) )!;

src/Ubiquity.NET.Llvm/DebugInfo/DebugInfoBuilder.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ public DISubroutineType CreateSubroutineType( DebugInfoFlags debugFlags, DIType?
601601

602602
/// <summary>Creates debug description of a structure type</summary>
603603
/// <param name="scope">Scope containing the structure</param>
604-
/// <param name="name">Name of the type</param>
604+
/// <param name="name">Name of the type (use <see cref="string.Empty"/> for anonymous types)</param>
605605
/// <param name="file">File containing the type</param>
606606
/// <param name="line">Line of the start of the type</param>
607607
/// <param name="bitSize">Size of the type in bits</param>
@@ -626,7 +626,7 @@ public DICompositeType CreateStructType( DIScope? scope
626626

627627
/// <summary>Creates debug description of a structure type</summary>
628628
/// <param name="scope">Scope containing the structure</param>
629-
/// <param name="name">Name of the type</param>
629+
/// <param name="name">Name of the type (use <see cref="string.Empty"/> for anonymous types)</param>
630630
/// <param name="file">File containing the type</param>
631631
/// <param name="line">Line of the start of the type</param>
632632
/// <param name="bitSize">Size of the type in bits</param>
@@ -679,7 +679,7 @@ public DICompositeType CreateStructType( DIScope? scope
679679

680680
/// <summary>Creates debug description of a union type</summary>
681681
/// <param name="scope">Scope containing the union</param>
682-
/// <param name="name">Name of the type</param>
682+
/// <param name="name">Name of the type (use <see cref="string.Empty"/> for anonymous types)</param>
683683
/// <param name="file">File containing the union</param>
684684
/// <param name="line">Line of the start of the union</param>
685685
/// <param name="bitSize">Size of the union in bits</param>
@@ -703,7 +703,7 @@ public DICompositeType CreateUnionType( DIScope? scope
703703

704704
/// <summary>Creates debug description of a union type</summary>
705705
/// <param name="scope">Scope containing the union</param>
706-
/// <param name="name">Name of the type</param>
706+
/// <param name="name">Name of the type (use <see cref="string.Empty"/> for anonymous types)</param>
707707
/// <param name="file">File containing the union</param>
708708
/// <param name="line">Line of the start of the union</param>
709709
/// <param name="bitSize">Size of the union in bits</param>
@@ -726,7 +726,7 @@ public DICompositeType CreateUnionType( DIScope? scope
726726

727727
/// <summary>Creates debug description of a union type</summary>
728728
/// <param name="scope">Scope containing the union</param>
729-
/// <param name="name">Name of the type</param>
729+
/// <param name="name">Name of the type (use <see cref="string.Empty"/> for anonymous types)</param>
730730
/// <param name="file">File containing the union</param>
731731
/// <param name="line">Line of the start of the union</param>
732732
/// <param name="bitSize">Size of the union in bits</param>
@@ -978,7 +978,7 @@ public DIEnumerator CreateEnumeratorValue( string name, long value, bool isUnsig
978978

979979
/// <summary>Creates an enumeration type</summary>
980980
/// <param name="scope">Containing scope for the type</param>
981-
/// <param name="name">source language name of the type</param>
981+
/// <param name="name">source language name of the type (use <see cref="string.Empty"/> for anonymous types)</param>
982982
/// <param name="file">Source file containing the type</param>
983983
/// <param name="lineNumber">Source file line number for the type</param>
984984
/// <param name="sizeInBits">Size, in bits, for the type</param>
@@ -1407,7 +1407,7 @@ public DIExpression CreateConstantValueExpression( Int64 value )
14071407

14081408
/// <summary>Creates a replaceable composite type</summary>
14091409
/// <param name="tag">Debug information <see cref="Tag"/> for the composite type (only values for a composite type are allowed)</param>
1410-
/// <param name="name">Name of the type</param>
1410+
/// <param name="name">Name of the type (use <see cref="string.Empty"/> for anonymous types)</param>
14111411
/// <param name="scope">Scope of the type</param>
14121412
/// <param name="file">Source file for the type</param>
14131413
/// <param name="line">Source line for the type</param>

src/Ubiquity.NET.Llvm/DebugInfo/DebugStructType.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public class DebugStructType
2323
{
2424
/// <summary>Initializes a new instance of the <see cref="DebugStructType"/> class.</summary>
2525
/// <param name="module">Module to contain the debug meta data</param>
26-
/// <param name="nativeName">Name of the type in LLVM IR</param>
26+
/// <param name="nativeName">Name of the type in LLVM IR (use <see cref="string.Empty"/> for anonymous types)</param>
2727
/// <param name="scope">Debug scope for the structure</param>
28-
/// <param name="sourceName">Source/debug name of the struct</param>
28+
/// <param name="sourceName">Source/debug name of the struct (use <see cref="string.Empty"/> for anonymous types)</param>
2929
/// <param name="file">File containing the definition of this type</param>
3030
/// <param name="line">line number this type is defined at</param>
3131
/// <param name="debugFlags">debug flags for this type</param>
@@ -81,7 +81,7 @@ public DebugStructType( BitcodeModule module
8181
/// <param name="llvmType">LLVM native type to build debug information for</param>
8282
/// <param name="module">Module to contain the debug meta data</param>
8383
/// <param name="scope">Debug scope for the structure</param>
84-
/// <param name="name">Source/debug name of the struct</param>
84+
/// <param name="name">Source/debug name of the struct (use <see cref="string.Empty"/> for anonymous types)</param>
8585
/// <param name="file">File containing the definition of this type</param>
8686
/// <param name="line">line number this type is defined at</param>
8787
/// <param name="debugFlags">debug flags for this type</param>
@@ -119,7 +119,7 @@ public DebugStructType( IStructType llvmType
119119
/// <param name="llvmType">LLVM native type to build debug information for</param>
120120
/// <param name="module">Module to contain the debug meta data</param>
121121
/// <param name="scope">Debug scope for the structure</param>
122-
/// <param name="name">Source/debug name of the struct</param>
122+
/// <param name="name">Source/debug name of the struct (use <see cref="string.Empty"/> for anonymous types)</param>
123123
/// <param name="file">File containing the definition of this type</param>
124124
/// <param name="line">line number this type is defined at</param>
125125
/// <remarks>
@@ -150,7 +150,7 @@ public DebugStructType( IStructType llvmType
150150
/// <param name="module">Module to contain the debug meta data</param>
151151
/// <param name="nativeName">Name of the type in LLVM IR</param>
152152
/// <param name="scope">Debug scope for the structure</param>
153-
/// <param name="name">Source/debug name of the struct</param>
153+
/// <param name="name">Source/debug name of the struct (use <see cref="string.Empty"/> for anonymous types)</param>
154154
/// <param name="file">File containing the definition of this type</param>
155155
/// <param name="line">line number this type is defined at</param>
156156
/// <remarks>
@@ -184,7 +184,7 @@ public DebugStructType( BitcodeModule module
184184
public IReadOnlyList<ITypeRef> Members => NativeType.Members;
185185

186186
/// <summary>Gets the name of the type</summary>
187-
public string Name => NativeType.Name;
187+
public string Name => NativeType.Name ?? string.Empty;
188188

189189
/// <summary>Gets the Source/Debug name</summary>
190190
public string SourceName => DIType?.Name ?? string.Empty;

0 commit comments

Comments
 (0)