]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java
CHR query translation and support for assignment in CHR bodies
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / chr / CHRLiteral.java
index 7b4a5bc26b1c7afb59addb97fa91d93985d7cc39..918dd9fb309ef25d4d9dfd3f156e60b7d4b097e5 100644 (file)
@@ -47,6 +47,15 @@ public class CHRLiteral extends Symbol {
     }
 
     public void resolve(TranslationContext context) {
+        if(relation == SpecialCHRRelation.ASSIGN) {
+            parameters[1] = parameters[1].resolve(context);
+            parameters[0] = parameters[0].resolveAsPattern(context);
+            return;
+        }
+        if(parameters != null) {
+            for(int i=0;i<parameters.length;++i)
+                parameters[i] = parameters[i].resolve(context);
+        }
         if(relation instanceof UnresolvedCHRRelation) {
             UnresolvedCHRRelation unresolved = (UnresolvedCHRRelation)relation;
             CHRConstraint constraint = context.resolveCHRConstraint(unresolved.name);
@@ -59,6 +68,10 @@ public class CHRLiteral extends Symbol {
                 if(sclRelation != null)
                     relation = new ExternalCHRRelation(sclRelation);
                 else {
+                    if(unresolved.name.contains(".")) {
+                        context.getErrorLog().log(unresolved.location, "Couldn't resolve relation " + unresolved.name + ".");
+                        return;
+                    }   
                     if(parameters == null) {
                         context.getErrorLog().log(location, "Relation must be declared if record syntax is used.");
                         return;
@@ -98,10 +111,6 @@ public class CHRLiteral extends Symbol {
             }
             fields = null;
         }
-        else {
-            for(int i=0;i<parameters.length;++i)
-                parameters[i] = parameters[i].resolve(context);
-        }
     }
 
     public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
@@ -119,6 +128,11 @@ public class CHRLiteral extends Symbol {
             parameters[0] = parameters[0].checkIgnoredType(context);
             typeConstraintEvidenceParameters = Expression.EMPTY_ARRAY;
         }
+        else if(relation == SpecialCHRRelation.ASSIGN) {
+            parameters[1] = parameters[1].inferType(context);
+            parameters[0] = parameters[0].checkTypeAsPattern(context, parameters[1].getType());
+            typeConstraintEvidenceParameters = Expression.EMPTY_ARRAY;
+        }
         else {
             TVar[] typeVariables = relation.getTypeVariables();
             typeParameters = typeVariables.length == 0 ? Type.EMPTY_ARRAY : new Type[typeVariables.length];
@@ -152,11 +166,16 @@ public class CHRLiteral extends Symbol {
     }
 
     public void collectFreeVariables(THashSet<Variable> vars) {
-        for(Expression parameter : parameters)
-            parameter.collectFreeVariables(vars);
-        if(typeConstraintEvidenceParameters != null)
-            for(Expression parameter : typeConstraintEvidenceParameters)
+        if(relation == SpecialCHRRelation.ASSIGN) {
+            parameters[1].collectFreeVariables(vars);
+        }
+        else {
+            for(Expression parameter : parameters)
                 parameter.collectFreeVariables(vars);
+            if(typeConstraintEvidenceParameters != null)
+                for(Expression parameter : typeConstraintEvidenceParameters)
+                    parameter.collectFreeVariables(vars);
+        }
     }
 
     public void setLocationDeep(long loc) {
@@ -183,8 +202,10 @@ public class CHRLiteral extends Symbol {
     }
 
     public void collectQueryEffects(THashSet<Type> effects) {
+        // TODO
     }
 
     public void collectEnforceEffects(THashSet<Type> effects) {
+        // TODO
     }
 }