Browse Source
Property references can appear in properties (still a few TODOs though).
Property references can appear in properties (still a few TODOs though).
git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@3186 bbc10eb1-c90d-0410-af57-cb519fbb1720master
9 changed files with 241 additions and 0 deletions
-
9prism/src/parser/ast/ASTElement.java
-
111prism/src/parser/ast/ExpressionProp.java
-
13prism/src/parser/ast/ModulesFile.java
-
3prism/src/parser/ast/PropertiesFile.java
-
9prism/src/parser/visitor/ASTTraverse.java
-
9prism/src/parser/visitor/ASTTraverseModify.java
-
1prism/src/parser/visitor/ASTVisitor.java
-
68prism/src/parser/visitor/FindAllProps.java
-
18prism/src/prism/StateModelChecker.java
@ -0,0 +1,111 @@ |
|||
//============================================================================== |
|||
// |
|||
// 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.ast; |
|||
|
|||
import parser.*; |
|||
import parser.type.Type; |
|||
import parser.visitor.*; |
|||
import prism.PrismLangException; |
|||
|
|||
/** |
|||
* An expression "prop", representing a reference to another property. |
|||
*/ |
|||
public class ExpressionProp extends Expression |
|||
{ |
|||
private String name; |
|||
|
|||
// Constructor |
|||
|
|||
public ExpressionProp(String s, Type t) |
|||
{ |
|||
name = s; |
|||
setType(t); |
|||
} |
|||
|
|||
// Get Method |
|||
|
|||
public String getName() |
|||
{ |
|||
return name; |
|||
} |
|||
|
|||
// Methods required for Expression: |
|||
|
|||
/** |
|||
* Is this expression constant? |
|||
*/ |
|||
public boolean isConstant() |
|||
{ |
|||
// Don't know - err on the side of caution |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* Evaluate this expression, return result. |
|||
* Note: assumes that type checking has been done already. |
|||
*/ |
|||
public Object evaluate(EvaluateContext ec) throws PrismLangException |
|||
{ |
|||
throw new PrismLangException("Cannot evaluate property references", this); |
|||
} |
|||
|
|||
@Override |
|||
public boolean returnsSingleValue() |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
// Methods required for ASTElement: |
|||
|
|||
/** |
|||
* Visitor method. |
|||
*/ |
|||
public Object accept(ASTVisitor v) throws PrismLangException |
|||
{ |
|||
return v.visit(this); |
|||
} |
|||
|
|||
/** |
|||
* Convert to string. |
|||
*/ |
|||
public String toString() |
|||
{ |
|||
return "\"" + name + "\""; |
|||
} |
|||
|
|||
/** |
|||
* Perform a deep copy. |
|||
*/ |
|||
public Expression deepCopy() |
|||
{ |
|||
ExpressionProp expr = new ExpressionProp(name, type); |
|||
expr.setPosition(this); |
|||
return expr; |
|||
} |
|||
} |
|||
|
|||
//------------------------------------------------------------------------------ |
|||
@ -0,0 +1,68 @@ |
|||
//============================================================================== |
|||
// |
|||
// 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 parser.ast.*; |
|||
import prism.PrismLangException; |
|||
|
|||
/** |
|||
* Find all references to properties (by name), replace the ExpressionLabels with ExpressionProps. |
|||
*/ |
|||
public class FindAllProps extends ASTTraverseModify |
|||
{ |
|||
private ModulesFile mf; |
|||
private PropertiesFile pf; |
|||
|
|||
public FindAllProps(ModulesFile mf, PropertiesFile pf) |
|||
{ |
|||
this.mf = mf; |
|||
this.pf = pf; |
|||
} |
|||
|
|||
public Object visit(ExpressionLabel e) throws PrismLangException |
|||
{ |
|||
String name; |
|||
Property prop = null; |
|||
// See if identifier corresponds to a property |
|||
name = e.getName(); |
|||
if (mf != null) { |
|||
prop = mf.getPropertyByName(name); |
|||
} |
|||
if (prop == null && pf != null) { |
|||
prop = pf.getPropertyObjectByName(name); |
|||
} |
|||
if (prop != null) { |
|||
// If so, replace it with an ExpressionProp object |
|||
ExpressionProp expr = new ExpressionProp(e.getName(), prop.getType()); |
|||
expr.setPosition(e); |
|||
return expr; |
|||
} |
|||
// Otherwise, leave it unchanged |
|||
return e; |
|||
} |
|||
} |
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue