aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/frontends
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-07-15 23:30:01 +0100
committerMichael Williamson <mike@zwobble.org>2016-07-15 23:30:01 +0100
commita48b9d12118e650c1edac765ba1fb0f9d1ea10c8 (patch)
tree21647c1e7f500e50135dea35cf61949e94852bbb /src/main/java/org/zwobble/couscous/frontends
parente1ff9d7faaa048b41ecfdf14d58850e06ab7cea2 (diff)
Use different temp prefix for switch desugarring
Diffstat (limited to 'src/main/java/org/zwobble/couscous/frontends')
-rw-r--r--src/main/java/org/zwobble/couscous/frontends/java/Scope.java19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/main/java/org/zwobble/couscous/frontends/java/Scope.java b/src/main/java/org/zwobble/couscous/frontends/java/Scope.java
index ee8be5f..d4af1f5 100644
--- a/src/main/java/org/zwobble/couscous/frontends/java/Scope.java
+++ b/src/main/java/org/zwobble/couscous/frontends/java/Scope.java
@@ -10,23 +10,32 @@ import java.util.*;
public class Scope {
public static Scope create() {
- return new Scope(new HashMap<>(), new HashSet<>(), Identifier.TOP, NaturalNumbers.INSTANCE.iterator());
+ return new Scope(
+ new HashMap<>(),
+ new HashSet<>(),
+ Identifier.TOP,
+ "_couscous_tmp_",
+ NaturalNumbers.INSTANCE.iterator()
+ );
}
private final Map<String, VariableDeclaration> variablesByKey;
private final Set<Identifier> identifiers;
private final Identifier identifier;
+ private final String temporaryPrefix;
private final Iterator<Integer> temporaryCounter;
private Scope(
Map<String, VariableDeclaration> variablesByKey,
Set<Identifier> identifiers,
Identifier identifier,
+ String temporaryPrefix,
Iterator<Integer> temporaryCounter)
{
this.variablesByKey = variablesByKey;
this.identifiers = identifiers;
this.identifier = identifier;
+ this.temporaryPrefix = temporaryPrefix;
this.temporaryCounter = temporaryCounter;
}
@@ -34,6 +43,10 @@ public class Scope {
return identifier;
}
+ public Scope temporaryPrefix(String temporaryPrefix) {
+ return new Scope(variablesByKey, identifiers, identifier, temporaryPrefix, temporaryCounter);
+ }
+
public Scope enterClass(ScalarType className) {
return enter(identifier.type(className.getQualifiedName()));
}
@@ -48,7 +61,7 @@ public class Scope {
}
private Scope enter(Identifier newIdentifier) {
- return new Scope(variablesByKey, identifiers, newIdentifier, temporaryCounter);
+ return new Scope(variablesByKey, identifiers, newIdentifier, temporaryPrefix, temporaryCounter);
}
public FormalArgumentNode formalArgument(String name, Type type) {
@@ -85,7 +98,7 @@ public class Scope {
}
public LocalVariableDeclarationNode temporaryVariable(Type type, ExpressionNode initialValue) {
- return localVariable("_couscous_tmp_" + temporaryCounter.next(), type, initialValue);
+ return localVariable(temporaryPrefix + temporaryCounter.next(), type, initialValue);
}
public ExpressionNode reference(String key) {