Browse Source

* Check added to catch if the same variable is set twice in the same update

* New class of semantic checks created that are only done after constant definitions


git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@3231 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 15 years ago
parent
commit
2654125531
  1. 17
      prism/src/parser/ast/ASTElement.java
  2. 1
      prism/src/parser/ast/ModulesFile.java
  3. 1
      prism/src/parser/ast/PropertiesFile.java
  4. 1
      prism/src/parser/visitor/SemanticCheck.java
  5. 89
      prism/src/parser/visitor/SemanticCheckAfterConstants.java

17
prism/src/parser/ast/ASTElement.java

@ -373,9 +373,9 @@ public abstract class ASTElement
}
/**
* Perform any required semantic checks. Optionally pass in parent
* ModulesFile and PropertiesFile for some additional checks (or leave
* null);
* Perform any required semantic checks. Optionally pass in parent ModulesFile
* and PropertiesFile for some additional checks (or leave null);
* These checks are done *before* any undefined constants have been defined.
*/
public void semanticCheck(ModulesFile modulesFile, PropertiesFile propertiesFile) throws PrismLangException
{
@ -383,6 +383,17 @@ public abstract class ASTElement
accept(visitor);
}
/**
* Perform further semantic checks that can only be done once values
* for any undefined constants have been defined. Optionally pass in parent
* ModulesFile and PropertiesFile for some additional checks (or leave null);
*/
public void semanticCheckAfterConstants(ModulesFile modulesFile, PropertiesFile propertiesFile) throws PrismLangException
{
SemanticCheckAfterConstants visitor = new SemanticCheckAfterConstants(modulesFile, propertiesFile);
accept(visitor);
}
/**
* Evaluate partially: replace some constants and variables with actual values.
*/

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

@ -763,6 +763,7 @@ public class ModulesFile extends ASTElement
public void setUndefinedConstants(Values someValues) throws PrismLangException
{
constantValues = constantList.evaluateConstants(someValues, null);
semanticCheckAfterConstants(this, null);
}
/**

1
prism/src/parser/ast/PropertiesFile.java

@ -371,6 +371,7 @@ public class PropertiesFile extends ASTElement
{
// might need values for ModulesFile constants too
constantValues = constantList.evaluateConstants(someValues, modulesFile.getConstantValues());
semanticCheckAfterConstants(modulesFile, this);
}
/**

1
prism/src/parser/visitor/SemanticCheck.java

@ -36,6 +36,7 @@ import prism.PrismLangException;
/**
* Perform any required semantic checks. Optionally pass in parent ModulesFile
* and PropertiesFile for some additional checks (or leave null);
* These checks are done *before* any undefined constants have been defined.
*/
public class SemanticCheck extends ASTTraverse
{

89
prism/src/parser/visitor/SemanticCheckAfterConstants.java

@ -0,0 +1,89 @@
//==============================================================================
//
// Copyright (c) 2002-
// Authors:
// * Dave Parker <david.parker@comlab.ox.ac.uk> (University of Oxford)
//
//------------------------------------------------------------------------------
//
// This file is part of PRISM.
//
// PRISM is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PRISM is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with PRISM; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//==============================================================================
package parser.visitor;
import java.util.Vector;
import parser.ast.*;
import prism.PrismLangException;
/**
* Perform further semantic checks that can only be done once values
* for any undefined constants have been defined. Optionally pass in parent
* ModulesFile and PropertiesFile for some additional checks (or leave null);
*/
public class SemanticCheckAfterConstants extends ASTTraverse
{
private ModulesFile modulesFile;
private PropertiesFile propertiesFile;
public SemanticCheckAfterConstants()
{
this(null, null);
}
public SemanticCheckAfterConstants(ModulesFile modulesFile)
{
this(modulesFile, null);
}
public SemanticCheckAfterConstants(ModulesFile modulesFile, PropertiesFile propertiesFile)
{
setModulesFile(modulesFile);
setPropertiesFile(propertiesFile);
}
public void setModulesFile(ModulesFile modulesFile)
{
this.modulesFile = modulesFile;
}
public void setPropertiesFile(PropertiesFile propertiesFile)
{
this.propertiesFile = propertiesFile;
}
public void visitPost(Update e) throws PrismLangException
{
int i, n;
String var;
Vector<String> varsUsed = new Vector<String>();
// Check that no variables are set twice in the same update
// Currently, could do this *before* constants are defined,
// but one day we might need to worry about e.g. array indices...
n = e.getNumElements();
for (i = 0; i < n; i++) {
var = e.getVar(i);
if (varsUsed.contains(var)) {
throw new PrismLangException("Variable \"" + var + "\" is set twice in the same update", e.getVarIdent(i));
}
varsUsed.add(var);
}
varsUsed.clear();
}
}
Loading…
Cancel
Save