|
|
@ -29,9 +29,12 @@ import apmc.*; |
|
|
|
|
|
|
|
|
public class Update |
|
|
public class Update |
|
|
{ |
|
|
{ |
|
|
|
|
|
// list of variable/expression pairs (and types) |
|
|
Vector vars; |
|
|
Vector vars; |
|
|
Vector exprs; |
|
|
Vector exprs; |
|
|
Vector types; |
|
|
Vector types; |
|
|
|
|
|
// parent Updates object |
|
|
|
|
|
Updates parent; |
|
|
|
|
|
|
|
|
// constructor |
|
|
// constructor |
|
|
|
|
|
|
|
|
@ -50,6 +53,13 @@ public class Update |
|
|
exprs.addElement(e); |
|
|
exprs.addElement(e); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// set parent |
|
|
|
|
|
|
|
|
|
|
|
public void setParent(Updates u) |
|
|
|
|
|
{ |
|
|
|
|
|
parent = u; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// get methods |
|
|
// get methods |
|
|
|
|
|
|
|
|
public int getNumElements() |
|
|
public int getNumElements() |
|
|
@ -72,6 +82,11 @@ public class Update |
|
|
return ((Integer)types.elementAt(i)).intValue(); |
|
|
return ((Integer)types.elementAt(i)).intValue(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Updates getParent() |
|
|
|
|
|
{ |
|
|
|
|
|
return parent; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// find all formulas (i.e. locate idents which are formulas) |
|
|
// find all formulas (i.e. locate idents which are formulas) |
|
|
|
|
|
|
|
|
public void findAllFormulas(FormulaList formulaList) throws PrismException |
|
|
public void findAllFormulas(FormulaList formulaList) throws PrismException |
|
|
@ -160,16 +175,40 @@ public class Update |
|
|
public void check() throws PrismException |
|
|
public void check() throws PrismException |
|
|
{ |
|
|
{ |
|
|
int i, n; |
|
|
int i, n; |
|
|
|
|
|
String s; |
|
|
Expression e; |
|
|
Expression e; |
|
|
|
|
|
Command c; |
|
|
|
|
|
Module m; |
|
|
|
|
|
ModulesFile mf; |
|
|
|
|
|
boolean isLocal, isGlobal; |
|
|
|
|
|
String var; |
|
|
|
|
|
|
|
|
|
|
|
c = getParent().getParent(); |
|
|
|
|
|
m = c.getParent(); |
|
|
|
|
|
mf = m.getParent(); |
|
|
|
|
|
|
|
|
n = getNumElements(); |
|
|
n = getNumElements(); |
|
|
for (i = 0; i < n; i++) { |
|
|
for (i = 0; i < n; i++) { |
|
|
e = getExpression(i); |
|
|
|
|
|
|
|
|
// check that the update is allowed to modify this variable |
|
|
|
|
|
var = getVar(i); |
|
|
|
|
|
isLocal = m.isLocalVariable(var); |
|
|
|
|
|
isGlobal = isLocal ? false : mf.isGlobalVariable(var); |
|
|
|
|
|
if (!isLocal && !isGlobal) { |
|
|
|
|
|
s = "Module " + m.getName() + " is not allowed to modify variable " + var; |
|
|
|
|
|
s += " which belongs to another module"; |
|
|
|
|
|
throw new PrismException(s); |
|
|
|
|
|
} |
|
|
|
|
|
if (isGlobal && !c.getSynch().equals("")) { |
|
|
|
|
|
s = "Synchronous command (" + c.getSynch() + ") in module " + m.getName(); |
|
|
|
|
|
s += " is not allowed to modify global variable " + var; |
|
|
|
|
|
throw new PrismException(s); |
|
|
|
|
|
} |
|
|
// check expression |
|
|
// check expression |
|
|
|
|
|
e = getExpression(i); |
|
|
e.check(); |
|
|
e.check(); |
|
|
// check evaluates to correct type |
|
|
// check evaluates to correct type |
|
|
if (!Expression.canAssignTypes(getType(i), e.getType())) { |
|
|
if (!Expression.canAssignTypes(getType(i), e.getType())) { |
|
|
throw new PrismException("Type error in update \"(" + getVar(i) + "'=" + getExpression(i) + ")\""); |
|
|
|
|
|
|
|
|
throw new PrismException("Type error in update \"(" + var + "'=" + getExpression(i) + ")\""); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|