Skip to content

Commit 6553084

Browse files
committed
Simplified the generation of default zeroes.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 1743f7e commit 6553084

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

src/Generator/Passes/HandleDefaultParamValuesPass.cs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ public override bool VisitFunctionDecl(Function function)
6666
{
6767
var desugared = type.Desugar();
6868

69+
if (!desugared.IsPrimitiveTypeConvertibleToRef() &&
70+
expression.String == "0")
71+
{
72+
result = $"default({desugared})";
73+
return true;
74+
}
75+
6976
// constants are obtained through dynamic calls at present so they are not compile-time values in target languages
7077
if (expression.Declaration is Variable ||
7178
(!Options.MarshalCharAsManagedChar &&
@@ -263,25 +270,6 @@ private bool CheckForEnumValue(Type desugared, Statement statement,
263270
private string TranslateEnumExpression(Function function,
264271
Type desugared, string @params)
265272
{
266-
TypeMap typeMap;
267-
if ((function.Parameters.Count == 0 ||
268-
HasSingleZeroArgExpression(function)) &&
269-
TypeMaps.FindTypeMap(desugared, out typeMap))
270-
{
271-
var typePrinterContext = new TypePrinterContext
272-
{
273-
MarshalKind = MarshalKind.DefaultExpression,
274-
Type = desugared
275-
};
276-
277-
var typeInSignature = typeMap.CSharpSignatureType(typePrinterContext)
278-
.SkipPointerRefs().Desugar();
279-
280-
Enumeration @enum;
281-
if (typeInSignature.TryGetEnum(out @enum))
282-
return "0";
283-
}
284-
285273
if (@params.Contains("::"))
286274
return regexDoubleColon.Replace(@params, desugared + ".");
287275

0 commit comments

Comments
 (0)