From b870e550e71e1d58e192642b9dbac77cbc4e1a98 Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Fri, 27 Jan 2012 23:11:00 +0000 Subject: [PATCH] Fixes/renames in property reference search code. git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@4503 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/parser/ast/ASTElement.java | 11 +++ .../visitor/GetAllPropRefsRecursively.java | 73 +++++++++++++++++++ .../visitor/GetAllReferencedProperties.java | 51 ------------- .../userinterface/properties/GUIProperty.java | 6 +- 4 files changed, 86 insertions(+), 55 deletions(-) create mode 100644 prism/src/parser/visitor/GetAllPropRefsRecursively.java delete mode 100644 prism/src/parser/visitor/GetAllReferencedProperties.java diff --git a/prism/src/parser/ast/ASTElement.java b/prism/src/parser/ast/ASTElement.java index 1f57d819..18fdf107 100644 --- a/prism/src/parser/ast/ASTElement.java +++ b/prism/src/parser/ast/ASTElement.java @@ -368,6 +368,17 @@ public abstract class ASTElement return v; } + /** + * Get all references to properties (by name) (i.e. ExpressionProp objects) recursively, store names in set. + */ + public Vector getAllPropRefsRecursively(PropertiesFile propertiesFile) throws PrismLangException + { + Vector v = new Vector(); + GetAllPropRefsRecursively visitor = new GetAllPropRefsRecursively(v, propertiesFile); + accept(visitor); + return v; + } + /** * Find all references to action labels, check they exist and, if required, * store their index locally (as defined by the containing ModuleFile). diff --git a/prism/src/parser/visitor/GetAllPropRefsRecursively.java b/prism/src/parser/visitor/GetAllPropRefsRecursively.java new file mode 100644 index 00000000..7b9d86b5 --- /dev/null +++ b/prism/src/parser/visitor/GetAllPropRefsRecursively.java @@ -0,0 +1,73 @@ +//============================================================================== +// +// Copyright (c) 2002- +// Authors: +// * Vojtech Forejt (University of Oxford) +// * Dave Parker (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.ExpressionLabel; +import parser.ast.ExpressionProp; +import parser.ast.PropertiesFile; +import parser.ast.Property; +import prism.PrismLangException; + +/** + * Get all references to properties (by name) (i.e. ExpressionProp objects) recursively, store names in set. + */ +public class GetAllPropRefsRecursively extends ASTTraverse +{ + private Vector v; + private PropertiesFile pf; + + public GetAllPropRefsRecursively(Vector v, PropertiesFile pf) + { + this.v = v; + this.pf = pf; + } + + public void visitPost(ExpressionProp e) throws PrismLangException + { + if (!v.contains(e.getName())) { + v.addElement(e.getName()); + } + } + + public void visitPost(ExpressionLabel e) throws PrismLangException + { + String name; + Property prop = null; + // See if identifier corresponds to a property + name = e.getName(); + if (prop == null && pf != null) { + prop = pf.lookUpPropertyObjectByName(name); + } + if (prop != null) { + // If so, add the name + v.addElement(e.getName()); + } + } +} diff --git a/prism/src/parser/visitor/GetAllReferencedProperties.java b/prism/src/parser/visitor/GetAllReferencedProperties.java deleted file mode 100644 index c39caa91..00000000 --- a/prism/src/parser/visitor/GetAllReferencedProperties.java +++ /dev/null @@ -1,51 +0,0 @@ -package parser.visitor; - -import java.util.Vector; - -import parser.ast.ExpressionFormula; -import parser.ast.ExpressionLabel; -import parser.ast.ExpressionProp; -import parser.ast.ModulesFile; -import parser.ast.PropertiesFile; -import parser.ast.Property; -import prism.PrismLangException; - -public class GetAllReferencedProperties extends ASTTraverse -{ - private Vector v; - private ModulesFile mf; - private PropertiesFile pf; - - - public GetAllReferencedProperties(Vector v, ModulesFile mf, PropertiesFile pf) - { - this.v = v; - this.mf = mf; - this.pf = pf; - } - - public void visitPost(ExpressionProp e) throws PrismLangException - { - if (!v.contains(e.getName())) { - v.addElement(e.getName()); - } - } - - public void visitPost(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, add the name - v.addElement(e.getName()); - } - } -} diff --git a/prism/src/userinterface/properties/GUIProperty.java b/prism/src/userinterface/properties/GUIProperty.java index c9daed94..3939c855 100644 --- a/prism/src/userinterface/properties/GUIProperty.java +++ b/prism/src/userinterface/properties/GUIProperty.java @@ -35,7 +35,6 @@ import javax.swing.*; import userinterface.GUIPrism; import parser.*; import parser.ast.*; -import parser.visitor.GetAllReferencedProperties; import prism.*; /** @@ -411,9 +410,8 @@ public class GUIProperty if (getStatus() == STATUS_PARSE_ERROR) setStatus(STATUS_NOT_DONE); - //get the referenced names - this.referencedNames = new Vector(); - (new GetAllReferencedProperties(this.referencedNames, m, ff)).visit(ff.getPropertyObject(namedCount)); + // get the referenced names + this.referencedNames = ff.getPropertyObject(namedCount).getAllPropRefsRecursively(ff); } catch (PrismException ex) { this.expr = null;