]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added a unit test for bug 6989 and some methods to print expressions 82/282/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 20 Jan 2017 11:47:00 +0000 (13:47 +0200)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 20 Jan 2017 11:47:00 +0000 (13:47 +0200)
refs #6989

Change-Id: Ia79a14ebf9acd9c5d1fb62dbb921db684746f316

14 files changed:
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ASTExpression.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBinary.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBlock.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPreLet.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERange.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERecord.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EStringLiteral.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVar.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ExpressionVisitor.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionVisitor.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/printing/ExpressionToStringVisitor.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ActiveTests.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/InitialRepository.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Bug6989.scl [new file with mode: 0644]

index ac37f4a14ca7f034c21cdccb16f9797f09f17c10..fbc0a79014dcb107c3b17842ef5bbb06fddaac8b 100644 (file)
@@ -54,7 +54,7 @@ public abstract class ASTExpression extends SimplifiableExpression {
     }
     
     @Override
-    final public void accept(ExpressionVisitor visitor) {
+    public void accept(ExpressionVisitor visitor) {
         throw new InternalCompilerError(getClass().getSimpleName() + " does not support accept.");
     }
     
index 274624aee0e08e97c22ad7c2f7c1ac1183c5d049..465c5c8ffac7f1981ccc50a42c7a09bfb94cf749 100644 (file)
@@ -234,5 +234,9 @@ public class EBinary extends ASTExpression {
     public Expression accept(ExpressionTransformer transformer) {
         return transformer.transform(this);
     }
-
+    
+    @Override
+    public void accept(ExpressionVisitor visitor) {
+        visitor.visit(this);
+    }
 }
index ebe88b499aab482e79bef9baac25a544898abaa1..c5f30417eed13983d839b211a1a8cf1f88aacc25 100644 (file)
@@ -128,4 +128,9 @@ public class EBlock extends ASTExpression {
             return 0;
         return ((GuardStatement)lastStatement).value.getSyntacticFunctionArity();
     }
+    
+    @Override
+    public void accept(ExpressionVisitor visitor) {
+        visitor.visit(this);
+    }
 }
index c78b9f4572bda462183776f8e7cc140694eaa2ec..035a2cadca6a02413575095ccd83112662961117 100644 (file)
@@ -98,5 +98,9 @@ public class EPreLet extends ASTExpression {
     public int getSyntacticFunctionArity() {
         return in.getSyntacticFunctionArity();
     }
-
+    
+    @Override
+    public void accept(ExpressionVisitor visitor) {
+        visitor.visit(this);
+    }
 }
index 3ea3d5e6c5945c02b13fb0a06cf9f2e90ec3227f..6fbcdafecfbaa90248e858a619061c24c813db89 100644 (file)
@@ -6,8 +6,8 @@ import org.simantics.scl.compiler.elaboration.modules.SCLValue;
 import org.simantics.scl.compiler.errors.Locations;
 
 public class ERange extends ASTExpression {
-    Expression from;
-    Expression to;
+    public Expression from;
+    public Expression to;
     
     public ERange(Expression from, Expression to) {
         this.from = from;
@@ -35,5 +35,9 @@ public class ERange extends ASTExpression {
     public Expression accept(ExpressionTransformer transformer) {
         return transformer.transform(this);
     }
-
+    
+    @Override
+    public void accept(ExpressionVisitor visitor) {
+        visitor.visit(this);
+    }
 }
index 32999dcb48877a689c980d7e7c1bc73973b46345..6ef9e9e72b4f69ef878e244484edc97880219cf1 100644 (file)
@@ -121,5 +121,9 @@ public class ERecord extends ASTExpression {
     public Expression accept(ExpressionTransformer transformer) {
         return transformer.transform(this);
     }
-
+    
+    @Override
+    public void accept(ExpressionVisitor visitor) {
+        visitor.visit(this);
+    }
 }
index fa85d8bfe888a0cb32e1dd4f3a8139fc0ab5606f..58ec41fd2f74b85dbbaf4ee420601b9638ada5e8 100644 (file)
@@ -8,8 +8,8 @@ import org.simantics.scl.compiler.errors.Locations;
 
 public class EStringLiteral extends ASTExpression {
     
-    String[] strings;
-    Expression[] expressions;
+    public String[] strings;
+    public Expression[] expressions;
    
     public EStringLiteral(String[] strings, Expression[] expressions) {
         this.strings = strings;
@@ -50,5 +50,8 @@ public class EStringLiteral extends ASTExpression {
         return new EApply(new ELiteral(new StringInterpolation(strings)), expressions);
     }
 
-
+    @Override
+    public void accept(ExpressionVisitor visitor) {
+        visitor.visit(this);
+    }
 }
index f1c3e31e0a3c0678abe2bb60a778b852c1150ac2..a47d3e0dd0a9691261d79e5b380467a98d47b4fb 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.scl.compiler.elaboration.expressions;
 
 import java.util.ArrayList;
 
+import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
 import org.simantics.scl.compiler.elaboration.errors.NotPatternException;
 import org.simantics.scl.compiler.elaboration.expressions.lhstype.FunctionDefinitionLhs;
@@ -79,4 +80,9 @@ public class EVar extends ASTExpression {
     public Expression accept(ExpressionTransformer transformer) {
         return transformer.transform(this);
     }
+    
+    @Override
+    public void accept(ExpressionVisitor visitor) {
+        visitor.visit(this);
+    }
 }
index 00e5f118789c2ab87729d7268c3b7cc69b19a41b..62e21f204b182b66a9446e3ed28aeea285eeb502 100644 (file)
@@ -5,7 +5,9 @@ public interface ExpressionVisitor {
     void visit(EApply expression);
     void visit(EApplyType expression);
     void visit(EAsPattern expression);
+    void visit(EBinary expression);
     void visit(EBind expression);
+    void visit(EBlock expression);
     void visit(ECHRRuleset echrRuleset);
     void visit(EConstant expression);
     void visit(ECoveringBranchPoint expression);
@@ -25,13 +27,18 @@ public interface ExpressionVisitor {
     void visit(ELiteral expression);
     void visit(EMatch expression);
     void visit(EPlaceholder expression);
+    void visit(EPreLet expression);
+    void visit(ERange expression);
     void visit(ERealLiteral expression);
+    void visit(ERecord expression);
     void visit(ERuleset expression);
     void visit(ESelect expression);
     void visit(ESimpleLambda expression);
     void visit(ESimpleLet expression);
+    void visit(EStringLiteral expression);
     void visit(ETransformation expression);
     void visit(ETypeAnnotation expression);
+    void visit(EVar expression);
     void visit(EVariable expression);
     void visit(EViewPattern expression);
     void visit(EWhen expression);
index 6bdd7abde4bcf90df1926bad6901f5ce79a48b97..401150db5f6bc39f7e50d6940175eb68a57c6735 100644 (file)
@@ -12,12 +12,19 @@ import org.simantics.scl.compiler.elaboration.expressions.accessor.FieldAccessor
 import org.simantics.scl.compiler.elaboration.expressions.accessor.FieldAccessorVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.accessor.IdAccessor;
 import org.simantics.scl.compiler.elaboration.expressions.accessor.StringAccessor;
+import org.simantics.scl.compiler.elaboration.expressions.block.BindStatement;
+import org.simantics.scl.compiler.elaboration.expressions.block.GuardStatement;
+import org.simantics.scl.compiler.elaboration.expressions.block.LetStatement;
+import org.simantics.scl.compiler.elaboration.expressions.block.RuleStatement;
+import org.simantics.scl.compiler.elaboration.expressions.block.Statement;
+import org.simantics.scl.compiler.elaboration.expressions.block.StatementVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.list.ListAssignment;
 import org.simantics.scl.compiler.elaboration.expressions.list.ListGenerator;
 import org.simantics.scl.compiler.elaboration.expressions.list.ListGuard;
 import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifierVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.list.ListSeq;
 import org.simantics.scl.compiler.elaboration.expressions.list.ListThen;
+import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
 import org.simantics.scl.compiler.elaboration.query.QAlternative;
 import org.simantics.scl.compiler.elaboration.query.QAtom;
 import org.simantics.scl.compiler.elaboration.query.QConjunction;
@@ -32,7 +39,7 @@ import org.simantics.scl.compiler.elaboration.query.QueryVisitor;
 
 public class StandardExpressionVisitor implements 
 ExpressionVisitor, QueryVisitor, FieldAccessorVisitor, ListQualifierVisitor,
-EquationVisitor {
+EquationVisitor, StatementVisitor {
 
     @Override
     public void visit(EApply expression) {
@@ -211,6 +218,10 @@ EquationVisitor {
         expression.value.accept(this);
     }
 
+    @Override
+    public void visit(EVar expression) {
+    }
+
     @Override
     public void visit(EVariable expression) {
     }
@@ -356,4 +367,67 @@ EquationVisitor {
         ruleset.in.accept(this);
     }
 
+    @Override
+    public void visit(EBinary expression) {
+        expression.left.accept(this);
+        for(EBinaryRightSide right : expression.rights)
+            right.right.accept(this);
+    }
+
+    @Override
+    public void visit(EBlock expression) {
+        for(Statement stat : expression.statements)
+            stat.accept(this);
+    }
+
+    @Override
+    public void visit(EPreLet expression) {
+        for(LetStatement stat : expression.assignments) {
+            stat.pattern.accept(this);
+            stat.value.accept(this);
+        }
+        expression.in.accept(this);
+    }
+
+    @Override
+    public void visit(ERange expression) {
+        expression.from.accept(this);
+        expression.to.accept(this);
+    }
+
+    @Override
+    public void visit(ERecord expression) {
+        for(FieldAssignment assignment : expression.fields)
+            assignment.value.accept(this);
+        
+    }
+
+    @Override
+    public void visit(EStringLiteral expression) {
+        for(Expression exp : expression.expressions)
+            exp.accept(this);
+    }
+
+    @Override
+    public void visit(BindStatement statement) {
+        statement.pattern.accept(this);
+        statement.value.accept(this);
+    }
+
+    @Override
+    public void visit(GuardStatement statement) {
+        statement.value.accept(this);
+    }
+
+    @Override
+    public void visit(LetStatement statement) {
+        statement.value.accept(this);
+    }
+
+    @Override
+    public void visit(RuleStatement statement) {
+        statement.head.accept(this);
+        statement.body.accept(this);
+    }
+
 }
index ac347385ae68b5d860ad927cb52a4f67ff9a0282..59e7d8909f24967e71400ba86067053550e6f5e9 100644 (file)
@@ -11,7 +11,9 @@ import org.simantics.scl.compiler.elaboration.expressions.Case;
 import org.simantics.scl.compiler.elaboration.expressions.EApply;
 import org.simantics.scl.compiler.elaboration.expressions.EApplyType;
 import org.simantics.scl.compiler.elaboration.expressions.EAsPattern;
+import org.simantics.scl.compiler.elaboration.expressions.EBinary;
 import org.simantics.scl.compiler.elaboration.expressions.EBind;
+import org.simantics.scl.compiler.elaboration.expressions.EBlock;
 import org.simantics.scl.compiler.elaboration.expressions.ECHRRuleset;
 import org.simantics.scl.compiler.elaboration.expressions.EConstant;
 import org.simantics.scl.compiler.elaboration.expressions.ECoveringBranchPoint;
@@ -31,13 +33,18 @@ import org.simantics.scl.compiler.elaboration.expressions.EListLiteral;
 import org.simantics.scl.compiler.elaboration.expressions.ELiteral;
 import org.simantics.scl.compiler.elaboration.expressions.EMatch;
 import org.simantics.scl.compiler.elaboration.expressions.EPlaceholder;
+import org.simantics.scl.compiler.elaboration.expressions.EPreLet;
+import org.simantics.scl.compiler.elaboration.expressions.ERange;
 import org.simantics.scl.compiler.elaboration.expressions.ERealLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ERecord;
 import org.simantics.scl.compiler.elaboration.expressions.ERuleset;
 import org.simantics.scl.compiler.elaboration.expressions.ESelect;
 import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda;
 import org.simantics.scl.compiler.elaboration.expressions.ESimpleLet;
+import org.simantics.scl.compiler.elaboration.expressions.EStringLiteral;
 import org.simantics.scl.compiler.elaboration.expressions.ETransformation;
 import org.simantics.scl.compiler.elaboration.expressions.ETypeAnnotation;
+import org.simantics.scl.compiler.elaboration.expressions.EVar;
 import org.simantics.scl.compiler.elaboration.expressions.EVariable;
 import org.simantics.scl.compiler.elaboration.expressions.EViewPattern;
 import org.simantics.scl.compiler.elaboration.expressions.EWhen;
@@ -384,6 +391,11 @@ public class ExpressionToStringVisitor implements ExpressionVisitor, QueryVisito
         expression.getValue().accept(this);
     }
 
+    @Override
+    public void visit(EVar expression) {
+        b.append(expression.name);
+    }
+
     @Override
     public void visit(EVariable expression) {
         show(expression.getVariable());
@@ -545,4 +557,47 @@ public class ExpressionToStringVisitor implements ExpressionVisitor, QueryVisito
             showPar(parameter);
         }
     }
+
+    @Override
+    public void visit(EBinary expression) {
+        b.append("<EBinary>");
+    }
+
+    @Override
+    public void visit(EBlock expression) {
+        b.append("<EBlock>");
+    }
+
+    @Override
+    public void visit(EPreLet expression) {
+        b.append("<EPreLet>");
+    }
+
+    @Override
+    public void visit(ERange expression) {
+        b.append('[');
+        expression.from.accept(this);
+        b.append("..");
+        expression.to.accept(this);
+        b.append(']');
+    }
+
+    @Override
+    public void visit(ERecord expression) {
+        b.append("<ERecord>");
+    }
+
+    @Override
+    public void visit(EStringLiteral expression) {
+        b.append('"');
+        for(int i=0;i<expression.strings.length;++i) {
+            b.append(expression.strings[i]);
+            if(i < expression.expressions.length) {
+                b.append("\\(");
+                expression.expressions[i].accept(this);
+                b.append(')');
+            }
+        }
+        b.append('"');
+    }
 }
index 7a4f8cda2ac62e860b7e5f056bfc0b890c9f4c27..4670b048d62f7b19cdfd9cd1abb2e780de486015 100644 (file)
@@ -19,4 +19,6 @@ public class ActiveTests extends TestBase {
   */  
     
     //@Test public void CityoptSetup() { test(); }
+    
+    @Test public void Bug6989() { test(); }
 }
index 917696bf4aee757875d8d8044d0900f61d54e3a4..5608689f512079c8a01c76fa50e63476d767e888 100644 (file)
@@ -6,6 +6,8 @@ import org.simantics.scl.compiler.source.repository.SourceRepositories;
 import org.simantics.scl.osgi.SCLOsgi;
 
 public class InitialRepository {
+    public static final boolean NO_PRELUDE = false;
+    
     private static ModuleRepository MODULE_REPOSITORY1 = new ModuleRepository(
             new CompositeModuleSourceRepository(
                     SourceRepositories.BUILTIN_SOURCE_REPOSITORY,
@@ -13,7 +15,9 @@ public class InitialRepository {
                     ));
     
     public static ModuleRepository getInitialRepository() {
-        if(MODULE_REPOSITORY1.getModule("Prelude").didSucceed())
+        if(NO_PRELUDE)
+            return new ModuleRepository(SourceRepositories.BUILTIN_SOURCE_REPOSITORY);
+        else if(MODULE_REPOSITORY1.getModule("Prelude").didSucceed())
             return MODULE_REPOSITORY1;
         else
             return SCLOsgi.MODULE_REPOSITORY;
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Bug6989.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Bug6989.scl
new file mode 100644 (file)
index 0000000..665f939
--- /dev/null
@@ -0,0 +1,5 @@
+main = ()
+  where
+    test = "foo","bar" 
+--
+()
\ No newline at end of file