import org.cojen.classfile.TypeDesc;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
+import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.internal.codegen.continuations.Branch;
import org.simantics.scl.compiler.internal.codegen.continuations.BranchRef;
import org.simantics.scl.compiler.internal.codegen.continuations.ICont;
this.moduleWriter = moduleWriter;
this.block = block;
}
+
+ private int lineNumber(long location) {
+ if(location == Locations.NO_LOCATION)
+ return -1;
+ else {
+ int position = Locations.beginOf(location);
+ int line = moduleWriter.lineLocator.lineNumberFromPosition(position);
+ //System.out.println("location=" + location + ", position=" + position + ", line=" + line);
+ return line + 1;
+ }
+ }
- public IVal apply(long lineNumber, IVal function, IVal ... parameters) {
+ public IVal apply(long location, IVal function, IVal ... parameters) {
try {
MultiFunction mfun = Types.matchFunction(function.getType(), parameters.length);
- return applyWithEffect(lineNumber,
+ return applyWithEffect(location,
mfun.effect,
mfun.returnType,
function, parameters);
}
}
- public IVal applyWithEffectChecked(long lineNumber, Type effect, Type returnType, IVal function, IVal ... parameters) {
+ public IVal applyWithEffectChecked(long location, Type effect, Type returnType, IVal function, IVal ... parameters) {
try {
MultiFunction mfun = Types.matchFunction(function.getType(), parameters.length);
if(!Types.equals(effect, mfun.effect))
} catch (MatchException e) {
throw new InternalCompilerError(e);
}
- return applyWithEffect(lineNumber, effect, returnType, function, parameters);
+ return applyWithEffect(location, effect, returnType, function, parameters);
}
public IVal applyWithEffect(long location, Type effect, Type returnType, IVal function, IVal ... parameters) {
effect,
function.createOccurrence(),
ValRef.createOccurrences(parameters));
- apply.location = location;
+ apply.lineNumber = lineNumber(location);
block.addStatement(apply);
return var;
}
return block;
}
- public void jump(ICont cont, IVal ... parameters) {
- block.setExit(new Jump(cont.createOccurrence(),
+ public void jump(long location, ICont cont, IVal ... parameters) {
+ block.setExit(new Jump(
+ lineNumber(location),
+ cont.createOccurrence(),
ValRef.createOccurrences(parameters)));
block = null;
}
- public void if_(IVal condition, ICont thenTarget, ICont elseTarget) {
- block.setExit(new If(condition.createOccurrence(),
+ public void if_(long location, IVal condition, ICont thenTarget, ICont elseTarget) {
+ block.setExit(new If(
+ lineNumber(location),
+ condition.createOccurrence(),
thenTarget.createOccurrence(),
elseTarget.createOccurrence()));
block = null;
}
- public void branchAwayIf(IVal condition, ICont target) {
+ public void branchAwayIf(long location, IVal condition, ICont target) {
SSABlock newBlock = new SSABlock(Type.EMPTY_ARRAY);
block.getParent().addBlock(newBlock);
- block.setExit(new If(condition.createOccurrence(),
+ block.setExit(new If(
+ lineNumber(location),
+ condition.createOccurrence(),
target.createOccurrence(),
newBlock.createOccurrence()));
this.block = newBlock;
}
- public void branchAwayUnless(IVal condition, ICont target) {
+ public void branchAwayUnless(long location, IVal condition, ICont target) {
SSABlock newBlock = new SSABlock(Type.EMPTY_ARRAY);
block.getParent().addBlock(newBlock);
- block.setExit(new If(condition.createOccurrence(),
+ block.setExit(new If(
+ lineNumber(location),
+ condition.createOccurrence(),
newBlock.createOccurrence(),
target.createOccurrence()));
this.block = newBlock;
}
- public void return_(IVal val) {
- jump(block.getParent().getReturnCont(), val);
+ public void return_(long location, IVal val) {
+ jump(lineNumber(location), block.getParent().getReturnCont(), val);
}
- public void switch_(IVal val, Branch[] branches) {
- block.setExit(new Switch(val.createOccurrence(), BranchRef.toBranchRefs(branches)));
+ public void switch_(long location, IVal val, Branch[] branches) {
+ block.setExit(new Switch(lineNumber(location), val.createOccurrence(), BranchRef.toBranchRefs(branches)));
block = null;
}
public void throw_(long location, TypeDesc exceptionClass, String description) {
- Throw exit = new Throw(exceptionClass, description);
- exit.location = location;
+ Throw exit = new Throw(lineNumber(location), exceptionClass, description);
block.setExit(exit);
block = null;
}