Commit 5bc54f32 authored by Alfons Laarman's avatar Alfons Laarman

Remove perpetual exception creation

parent 4685e5d9
......@@ -143,7 +143,7 @@ public class AritmicExpression extends NAryExpression {
}
} catch (ParseException pe ) {
if (null == ex2 || PromelaConstants.RARROW == getToken().kind) {
throw new ParseException();
throw pex;
}
int rhs = ex2.getConstantValue();
switch (getToken().kind) {
......
......@@ -101,7 +101,7 @@ public class BooleanExpression extends NAryExpression {
case PromelaConstants.LAND:
return (ex1.getConstantValue() != 0) && (ex2.getConstantValue() != 0) ? 1 : 0;
}
throw new MyParseException("Unimplemented aritmic type: " + getToken().image, getToken());
throw pex;
}
@Override
......
......@@ -100,7 +100,7 @@ public class CompareExpression extends NAryExpression {
case PromelaConstants.NEQ:
return ex1.getConstantValue() != ex2.getConstantValue() ? 1 : 0;
}
throw new MyParseException("Unimplemented compare type: " + getToken().image, getToken());
throw pex;
}
@Override
......
......@@ -16,8 +16,8 @@ package spins.promela.compiler.expression;
import java.util.Set;
import spins.promela.compiler.parser.MyParseException;
import spins.promela.compiler.parser.ParseException;
import spins.promela.compiler.parser.StaticException;
import spins.promela.compiler.parser.Token;
import spins.promela.compiler.variable.VariableAccess;
import spins.promela.compiler.variable.VariableType;
......@@ -31,6 +31,8 @@ import spins.promela.compiler.variable.VariableType;
public abstract class Expression {
private final Token token;
public static StaticException pex = new StaticException();
/**
* Creates a new Expression using the specified token.
*
......@@ -67,9 +69,7 @@ public abstract class Expression {
* When it can not determine what the constant value is.
*/
public int getConstantValue() throws ParseException {
if (token == null)
throw new ParseException("Constant value not be determened on compile-time."+ this);
throw new MyParseException("Constant value not be determened on compile-time.", getToken());
throw pex;
}
/**
......
......@@ -19,6 +19,10 @@ import static spins.promela.compiler.parser.Promela.C_STATE_PROC_COUNTER;
import java.util.HashSet;
import java.util.Set;
import spins.promela.compiler.ltsmin.LTSminPrinter;
import spins.promela.compiler.ltsmin.LTSminPrinter.ExprPrinter;
import spins.promela.compiler.ltsmin.model.LTSminModel;
import spins.promela.compiler.ltsmin.state.LTSminPointer;
import spins.promela.compiler.parser.ParseException;
import spins.promela.compiler.parser.Token;
import spins.promela.compiler.variable.Variable;
......@@ -249,4 +253,16 @@ public class Identifier extends Expression {
public void setArrayIndex(Expression e) {
arrayExpr = e;
}
public String ref = null;
public String getRef(LTSminModel model) {
if (null!= ref)
return ref;
LTSminPointer svp = new LTSminPointer(model.sv, "");
ExprPrinter p = new ExprPrinter(svp);
ref = p.print(this);
assert (!ref.equals(LTSminPrinter.SCRATCH_VARIABLE)); // write-only
return ref;
}
}
......@@ -17,7 +17,6 @@ package spins.promela.compiler.expression;
import java.util.HashSet;
import java.util.Set;
import spins.promela.compiler.parser.ParseException;
import spins.promela.compiler.parser.Token;
import spins.promela.compiler.variable.VariableAccess;
import spins.promela.compiler.variable.VariableType;
......@@ -35,11 +34,6 @@ public class TimeoutExpression extends Expression {
return "_timeout";
}
@Override
public int getConstantValue() throws ParseException {
throw new ParseException();
}
@Override
public String getIntExpression() {
return "(_timeout ? 1 : 0)";
......
......@@ -18,6 +18,9 @@ public class MyParseException extends ParseException {
private static final long serialVersionUID = 2026932200848510897L;
public MyParseException(String message, Token token) {
super(String.format("(@%d:%d) %s", token.beginLine, token.beginColumn, message));
super(String.format("(@%d:%d) %s",
token==null ? -1 : token.beginLine,
token==null ? -1 : token.beginColumn,
message));
}
}
// Copyright 2010, University of Twente, Formal Methods and Tools group
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package spins.promela.compiler.parser;
public class StaticException extends ParseException {
private static final long serialVersionUID = 2026932200848510897L;
Token t;
public StaticException() {}
public StaticException update(Token t) {
this.t = t;
return this;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment