From 17d8c3a77c635c2646002d506fa1027a16564ec5 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 22 Dec 2024 10:06:48 +0000 Subject: Extract methodToShidLocalName() --- .../java/org/shedlang/compiler/shid/ShidCodeGen.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java b/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java index 8c9d5f96..59a5bc87 100644 --- a/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java +++ b/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java @@ -10,6 +10,7 @@ import org.shedlang.compiler.types.*; import org.shedlang.compiler.util.Iterables; import org.shedlang.compiler.util.P; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; @@ -578,9 +579,7 @@ public class ShidCodeGen { var structType = node.typeOrConstructor().toType(); for (var methodNode : node.methods()) { - var shidFunctionName = context.generateLocalNameForVariable( - "$methods__" + String.join("_", structType.namespaceName().parts()) + "__" + structType.name() + "__" + methodNode.name() - ); + var shidFunctionName = methodToShidLocalName(structType, methodNode.name()); context = compileFunction( shidFunctionName, methodNode.signature().params(), @@ -610,6 +609,18 @@ public class ShidCodeGen { return context; } + private static String methodToShidLocalName( + SimpleStructType structType, + String methodName + ) { + return MessageFormat.format( + "$methods__{0}__{1}__{2}", + String.join("_", structType.namespaceName().parts()), + structType.name(), + methodName + ); + } + private static Context compileSumTypeDefinition( TypedSumTypeDefinitionNode node, Context context -- cgit v1.2.3