aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/backends/csharp/CsharpPrimitiveMethods.java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-01-24 16:13:33 +0000
committerMichael Williamson <mike@zwobble.org>2016-01-24 16:13:33 +0000
commit5fe2fa7934197d73bc1f6a3e361149923279b35a (patch)
tree3850ffc02c864875084c174e26466a052ccc6368 /src/main/java/org/zwobble/couscous/backends/csharp/CsharpPrimitiveMethods.java
parentf2ed6b591da6149319c149d1c78694bfa9641a73 (diff)
Implement negation in C# backend
Diffstat (limited to 'src/main/java/org/zwobble/couscous/backends/csharp/CsharpPrimitiveMethods.java')
-rw-r--r--src/main/java/org/zwobble/couscous/backends/csharp/CsharpPrimitiveMethods.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/couscous/backends/csharp/CsharpPrimitiveMethods.java b/src/main/java/org/zwobble/couscous/backends/csharp/CsharpPrimitiveMethods.java
index 9424b2d..e094258 100644
--- a/src/main/java/org/zwobble/couscous/backends/csharp/CsharpPrimitiveMethods.java
+++ b/src/main/java/org/zwobble/couscous/backends/csharp/CsharpPrimitiveMethods.java
@@ -3,6 +3,8 @@ package org.zwobble.couscous.backends.csharp;
import com.google.common.collect.ImmutableMap;
import org.zwobble.couscous.ast.ExpressionNode;
import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.backends.python.ast.PythonExpressionNode;
+import org.zwobble.couscous.values.BooleanValue;
import org.zwobble.couscous.values.ObjectValues;
import java.util.List;
@@ -13,6 +15,18 @@ import static org.zwobble.couscous.ast.MethodCallNode.staticMethodCall;
import static org.zwobble.couscous.util.ExtraLists.list;
public class CsharpPrimitiveMethods {
+ private static final Map<String, PrimitiveMethodGenerator> BOOLEAN_METHODS;
+
+ static {
+ ImmutableMap.Builder<String, PrimitiveMethodGenerator> methods = ImmutableMap.builder();
+ BOOLEAN_METHODS = methods.build();
+ }
+
+ private static final Map<TypeName, Map<String, PrimitiveMethodGenerator>> METHODS =
+ ImmutableMap.<TypeName, Map<String, PrimitiveMethodGenerator>>builder()
+ .put(BooleanValue.REF, BOOLEAN_METHODS)
+ .build();
+
private static final Map<String, PrimitiveStaticMethodGenerator> STATIC_INT_METHODS =
ImmutableMap.<String, PrimitiveStaticMethodGenerator>builder()
@@ -29,6 +43,16 @@ public class CsharpPrimitiveMethods {
.put(ObjectValues.BOXED_INT, STATIC_INT_METHODS)
.build();
+ public static Optional<PrimitiveMethodGenerator> getPrimitiveMethod(TypeName type, String methodName) {
+ return Optional.ofNullable(METHODS.get(type))
+ .flatMap(methodsForType -> Optional.ofNullable(methodsForType.get(methodName)));
+ }
+
+ @FunctionalInterface
+ public interface PrimitiveMethodGenerator {
+ ExpressionNode generate(ExpressionNode receiver, List<ExpressionNode> arguments);
+ }
+
public static Optional<PrimitiveStaticMethodGenerator> getPrimitiveStaticMethod(TypeName type, String methodName) {
return Optional.ofNullable(STATIC_METHODS.get(type))
.flatMap(methodsForType -> Optional.ofNullable(methodsForType.get(methodName)));