Browse Source

Allow the actual type of a PRISM model to differ from the one specified in the file.

For now, this provides a cleaner implementation of the default (unspecified)
model type being set to an MDP. Later, this will allow the actual model type
to be omitted or partially specified and derived from langage features.
accumulation-v4.7
Dave Parker 6 years ago
parent
commit
2700f52271
  1. 8
      prism/src/parser/PrismParser.java
  2. 8
      prism/src/parser/PrismParser.jj
  3. 52
      prism/src/parser/ast/ModulesFile.java
  4. 2
      prism/src/pta/DigitalClocks.java

8
prism/src/parser/PrismParser.java

@ -151,7 +151,7 @@ public class PrismParser implements PrismParserConstants {
} }
// Override type of model if requested // Override type of model if requested
if (typeOverride != null) { if (typeOverride != null) {
mf.setModelType(typeOverride);
mf.setModelTypeInFile(typeOverride);
} }
return mf; return mf;
@ -371,7 +371,7 @@ public class PrismParser implements PrismParserConstants {
// Modules file // Modules file
static final public static final public
ModulesFile ModulesFile() throws ParseException, PrismLangException {ModelType type = ModelType.MDP;
ModulesFile ModulesFile() throws ParseException, PrismLangException {ModelType type = null;
int typeCount = 0; int typeCount = 0;
Token typeDupe = null; Token typeDupe = null;
Declaration global; Declaration global;
@ -491,8 +491,8 @@ mf.setInitialStates(init); initCount++; if (initCount == 2) initDupe = init;
{if (true) throw new PrismLangException("There were multiple init...endinit constructs", initDupe);} {if (true) throw new PrismLangException("There were multiple init...endinit constructs", initDupe);}
} }
// Set model type (note default is MDP)
mf.setModelType(type);
// Set model type (might be null, i.e., unspecified)
mf.setModelTypeInFile(type);
// Return completed ModulesFile object // Return completed ModulesFile object
mf.setPosition(begin != null? begin: getToken(0), getToken(0)); mf.setPosition(begin != null? begin: getToken(0), getToken(0));

8
prism/src/parser/PrismParser.jj

@ -183,7 +183,7 @@ public class PrismParser
} }
// Override type of model if requested // Override type of model if requested
if (typeOverride != null) { if (typeOverride != null) {
mf.setModelType(typeOverride);
mf.setModelTypeInFile(typeOverride);
} }
return mf; return mf;
@ -531,7 +531,7 @@ TOKEN :
ModulesFile ModulesFile() throws PrismLangException : ModulesFile ModulesFile() throws PrismLangException :
{ {
ModelType type = ModelType.MDP;
ModelType type = null;
int typeCount = 0; int typeCount = 0;
Token typeDupe = null; Token typeDupe = null;
Declaration global; Declaration global;
@ -574,8 +574,8 @@ ModulesFile ModulesFile() throws PrismLangException :
throw new PrismLangException("There were multiple init...endinit constructs", initDupe); throw new PrismLangException("There were multiple init...endinit constructs", initDupe);
} }
// Set model type (note default is MDP)
mf.setModelType(type);
// Set model type (might be null, i.e., unspecified)
mf.setModelTypeInFile(type);
// Return completed ModulesFile object // Return completed ModulesFile object
mf.setPosition(begin != null? begin: getToken(0), getToken(0)); mf.setPosition(begin != null? begin: getToken(0), getToken(0));

52
prism/src/parser/ast/ModulesFile.java

@ -44,7 +44,9 @@ import parser.type.*;
public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerator public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerator
{ {
// Model type (enum)
// Model type, as specified in the model file
private ModelType modelTypeInFile;
// Model type (actual, may differ)
private ModelType modelType; private ModelType modelType;
// Model components // Model components
@ -84,7 +86,7 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
formulaList = new FormulaList(); formulaList = new FormulaList();
labelList = new LabelList(); labelList = new LabelList();
constantList = new ConstantList(); constantList = new ConstantList();
modelType = ModelType.MDP; // default type
modelTypeInFile = modelType = null; // Unspecified
globals = new Vector<Declaration>(); globals = new Vector<Declaration>();
modules = new Vector<Object>(); modules = new Vector<Object>();
systemDefns = new ArrayList<SystemDefn>(); systemDefns = new ArrayList<SystemDefn>();
@ -119,6 +121,22 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
constantList = cl; constantList = cl;
} }
/**
* Set the model type that is specified in the model file.
* Can be null, denoting that it is unspecified.
*/
public void setModelTypeInFile(ModelType t)
{
modelTypeInFile = t;
// As a default, set the actual type to be the same
modelType = modelTypeInFile;
}
/**
* Set the actual model type,
* which may differ from the type specified in the model file.
* Note: if {@link #tidyUp()} is called, this may be overwritten.
*/
public void setModelType(ModelType t) public void setModelType(ModelType t)
{ {
modelType = t; modelType = t;
@ -273,6 +291,11 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
return constantList; return constantList;
} }
public ModelType getModelTypeInFile()
{
return modelTypeInFile;
}
@Override @Override
public ModelType getModelType() public ModelType getModelType()
{ {
@ -705,6 +728,11 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
// Then identify/check any references to action names // Then identify/check any references to action names
findAllActions(synchs); findAllActions(synchs);
// Determine actual model type
// (checks/processing below this point can assume that modelType
// is non-null; methods before this point cannot)
finaliseModelType();
// Various semantic checks // Various semantic checks
doSemanticChecks(); doSemanticChecks();
// Type checking // Type checking
@ -1244,6 +1272,21 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
return new VarList(this); return new VarList(this);
} }
/**
* Determine the actual model type
*/
private void finaliseModelType()
{
// Default (if unspecified) is MDP
if (modelTypeInFile == null) {
modelType = ModelType.MDP;
}
// Otherwise, it's just whatever was specified
else {
modelType = modelTypeInFile;
}
}
// Methods required for ASTElement: // Methods required for ASTElement:
/** /**
@ -1262,7 +1305,9 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
String s = "", tmp; String s = "", tmp;
int i, n; int i, n;
s += modelType.toString().toLowerCase() + "\n\n";
if (modelTypeInFile != null) {
s += modelTypeInFile.toString().toLowerCase() + "\n\n";
}
tmp = "" + formulaList; tmp = "" + formulaList;
if (tmp.length() > 0) if (tmp.length() > 0)
@ -1323,6 +1368,7 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
// Copy ASTElement stuff // Copy ASTElement stuff
ret.setPosition(this); ret.setPosition(this);
// Copy type // Copy type
ret.setModelTypeInFile(modelTypeInFile);
ret.setModelType(modelType); ret.setModelType(modelType);
// Deep copy main components // Deep copy main components
ret.setFormulaList((FormulaList) formulaList.deepCopy()); ret.setFormulaList((FormulaList) formulaList.deepCopy());

2
prism/src/pta/DigitalClocks.java

@ -172,7 +172,7 @@ public class DigitalClocks
prop = (Expression) propertyToCheck.deepCopy(); prop = (Expression) propertyToCheck.deepCopy();
// Change the model type // Change the model type
mf.setModelType(ModelType.MDP);
mf.setModelTypeInFile(ModelType.MDP);
// Change all clock variable declarations to bounded integers // Change all clock variable declarations to bounded integers
mf = (ModulesFile) mf.accept(new ASTTraverseModify() mf = (ModulesFile) mf.accept(new ASTTraverseModify()

Loading…
Cancel
Save