Skip to content

Commit e0091ae

Browse files
authored
Handle constant typedef global declaration (#878)
1 parent fa70329 commit e0091ae

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

Cesium.CodeGen.Tests/CodeGenDeclarationsTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ public Task StaticDeclarationsFuncionAndGlobalContext() => DoTest(
3737
3838
static int i = 2;
3939
");
40+
41+
[Fact]
42+
public Task ConstTypeDef() => DoTest(
43+
@"
44+
typedef int myint;
45+
static const myint i = 0;");
4046
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
System.Void <Module>::.cctor()
2+
IL_0000: ldc.i4.0
3+
IL_0001: stsfld System.Int32 testInput<Statics>::i
4+
IL_0006: ret

Cesium.CodeGen/Extensions/TranslationUnitEx.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ private static IEnumerable<IBlockItem> GetTopLevelDeclarations(SymbolDeclaration
7070
throw new CompilationException($"CLI initializer should be a function for identifier {identifier}.");
7171
}
7272

73-
if (type is PrimitiveType or PointerType or InPlaceArrayType
74-
|| (type is StructType varStructType && varStructType.Identifier != identifier)
75-
|| type is NamedType)
73+
var nonConstType = type.EraseConstType();
74+
if (nonConstType is PrimitiveType or PointerType or InPlaceArrayType
75+
|| (nonConstType is StructType varStructType && varStructType.Identifier != identifier)
76+
|| nonConstType is NamedType)
7677
{
7778
var variable = new DeclarationBlockItem(new(storageClass, new(type, identifier, null), initializer));
7879
yield return variable;

0 commit comments

Comments
 (0)