]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/ReplaceContext.java
(refs #7371) Support expression cloning for ECHRSelect
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / contexts / ReplaceContext.java
index 1bb40c5faa2acb72e3fa0e8f1856767d811c226e..b526cb3f0950d647cc8002661766abe982be87a7 100644 (file)
@@ -3,8 +3,10 @@ package org.simantics.scl.compiler.elaboration.contexts;
 import org.simantics.scl.compiler.elaboration.expressions.EVariable;
 import org.simantics.scl.compiler.elaboration.expressions.Expression;
 import org.simantics.scl.compiler.elaboration.expressions.Variable;
+import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
 import org.simantics.scl.compiler.types.TVar;
 import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
 
 import gnu.trove.map.hash.THashMap;
 
@@ -37,4 +39,28 @@ public class ReplaceContext {
     public ReplaceContext(TypingContext typingContext) {
         this(new THashMap<TVar, Type>(), new THashMap<Variable, Expression>(), typingContext);
     }
+    
+    public Expression[] replace(Expression[] expressions) {
+        if(expressions == null)
+            return null;
+        Expression[] result = new Expression[expressions.length];
+        for(int i=0;i<expressions.length;++i)
+            result[i] = expressions[i].replace(this);
+        return result;
+    }
+
+    public Type[] replace(Type[] types) {
+        if(types == null)
+            return null;
+        return Types.replace(types, tvarMap);
+    }
+
+    public FieldAssignment[] replace(FieldAssignment[] fields) {
+        if(fields == null)
+            return null;
+        FieldAssignment[] result = new FieldAssignment[fields.length];
+        for(int i=0;i<fields.length;++i)
+            result[i] = fields[i].replace(this);
+        return result;
+    }
 }