Skip to content

Commit 180511b

Browse files
committed
Fix code generator for IsConst modifier
Doesn't change the generated code
1 parent 0bbf8ec commit 180511b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Generator/Types/TypeHelpers.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,16 @@ public static string GetInputTypeName(Generator gen, ITypeRequestSource source,
238238
}
239239
}
240240

241-
public static string UnwrapInputParameter(string name, TypeReference t)
241+
public static string UnwrapInputParameter(string name, TypeReference t, bool hasConstModifier = false)
242242
{
243243
if (t.IsGenericParameter)
244244
{
245245
return $"{ t.Name }::unwrap({ name })";
246246
}
247247
if (t.IsByReference)
248248
{
249-
throw new NotSupportedException();
249+
// value types passed by reference
250+
return $"{ name } as *const _ as *mut _";
250251
}
251252
else if (t.IsArray)
252253
{
@@ -288,6 +289,23 @@ public static string UnwrapInputParameter(string name, TypeReference t)
288289
{
289290
return name;
290291
}
292+
else if (t.IsOptionalModifier)
293+
{
294+
var ty = (OptionalModifierType)t;
295+
if (ty.ModifierType.FullName == "System.Runtime.CompilerServices.IsConst")
296+
{
297+
return UnwrapInputParameter(name, ty.ElementType, true);
298+
}
299+
else
300+
{
301+
// according to ECMA Partition II documentation, we can usually just ignore optional modifiers
302+
return UnwrapInputParameter(name, ty.ElementType, hasConstModifier);
303+
}
304+
}
305+
else if (t.IsRequiredModifier)
306+
{
307+
throw new NotImplementedException($"Unexpected reqmod { ((RequiredModifierType)t).ModifierType.FullName } is not implemented");
308+
}
291309
else // reference type
292310
{
293311
return $"{ name } as *const _ as *mut _";

0 commit comments

Comments
 (0)