]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java
SCL compiler generates line numbers to bytecode
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / Expression.java
index 5b60dad423c942ddbb2a0ff4d03906a5e327b0cb..dcb38165e7665ae66bf6af53c458e277dc192700 100644 (file)
@@ -18,6 +18,7 @@ import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToS
 import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectEffectsVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectFreeVariablesVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectRefsVisitor;
+import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectVarsVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.visitors.ForVariablesUsesVisitor;
 import org.simantics.scl.compiler.elaboration.expressions.visitors.StandardExpressionVisitor;
 import org.simantics.scl.compiler.elaboration.query.QAtom;
@@ -60,10 +61,10 @@ public abstract class Expression extends Symbol implements Typed {
             try {
                 updateType();
             } catch (MatchException e) {
-                throw new InternalCompilerError(e);
+                throw new InternalCompilerError(location, e);
             }
             if(type == null)
-                throw new InternalCompilerError(getClass().getSimpleName() + 
+                throw new InternalCompilerError(location, getClass().getSimpleName() + 
                         ".updateType couldn't compute its type.");
         }
         return type;
@@ -163,7 +164,9 @@ public abstract class Expression extends Symbol implements Typed {
         accept(new CollectRefsVisitor(allRefs, refs));
     }
 
-    public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
+    public final void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
+        accept(new CollectVarsVisitor(allVars, vars));
+    }
 
     public final void forVariableUses(VariableProcedure procedure) {
         accept(new ForVariablesUsesVisitor(procedure));
@@ -239,7 +242,7 @@ public abstract class Expression extends Symbol implements Typed {
 
     public void getParameters(TranslationContext translationContext,
             ArrayList<Expression> parameters) {
-        throw new InternalCompilerError("Class " + getClass().getSimpleName() + " does not support getParameters.");        
+        throw new InternalCompilerError(location, "Class " + getClass().getSimpleName() + " does not support getParameters.");        
     }
 
     public Expression resolveAsPattern(TranslationContext context) {
@@ -249,7 +252,7 @@ public abstract class Expression extends Symbol implements Typed {
     
     public Expression checkTypeAsPattern(TypingContext context, Type requiredType) {
         if(context.isInPattern())
-            throw new InternalCompilerError("Already in a pattern.");
+            throw new InternalCompilerError(location, "Already in a pattern.");
         context.setInPattern(true);
         Expression expression = checkType(context, requiredType);
         context.setInPattern(false);
@@ -279,7 +282,7 @@ public abstract class Expression extends Symbol implements Typed {
     }
 
     public Expression replace(ReplaceContext context) {
-        throw new InternalCompilerError(getClass().getSimpleName() + " does not support replace.");
+        throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support replace.");
     }
     
     public static Expression[] replace(ReplaceContext context, Expression[] expressions) {
@@ -317,7 +320,7 @@ public abstract class Expression extends Symbol implements Typed {
         IVal functionVal = newW.getFunction().getTarget();
         for(int i=0;i<parameters.length;++i)
             decomposed.parameters[i].setVal(parameters[i]);
-        newW.return_(decomposed.body.toVal(context, newW));
+        newW.return_(decomposed.body.location, decomposed.body.toVal(context, newW));
         return functionVal;
     }