From a73b36685b8362e40889ad6621985c8fa25fb6fa Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Wed, 7 Aug 2013 16:54:05 +0000 Subject: [PATCH] Add getAllLabels method to ASTElement (not used currently). git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@7243 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/parser/ast/ASTElement.java | 12 +++++ prism/src/parser/visitor/GetAllLabels.java | 53 ++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 prism/src/parser/visitor/GetAllLabels.java diff --git a/prism/src/parser/ast/ASTElement.java b/prism/src/parser/ast/ASTElement.java index f1e0c390..d45c9638 100644 --- a/prism/src/parser/ast/ASTElement.java +++ b/prism/src/parser/ast/ASTElement.java @@ -337,6 +337,18 @@ public abstract class ASTElement return evaluatePartially(new EvaluateContextValues(null, varValues)); } + /** + * Get all labels (i.e. ExpressionLabel objects), store names in set. + * Special labels "deadlock", "init" *are* included in the list. + */ + public Vector getAllLabels() throws PrismLangException + { + Vector v = new Vector(); + GetAllLabels visitor = new GetAllLabels(v); + accept(visitor); + return v; + } + /** * Expand labels, return result. * Special labels "deadlock", "init" and any not in list are left. diff --git a/prism/src/parser/visitor/GetAllLabels.java b/prism/src/parser/visitor/GetAllLabels.java new file mode 100644 index 00000000..4d5bf98d --- /dev/null +++ b/prism/src/parser/visitor/GetAllLabels.java @@ -0,0 +1,53 @@ +//============================================================================== +// +// Copyright (c) 2002- +// Authors: +// * Dave Parker (University of Birmingham/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; + +/** + * Get all variables (i.e. ExpressionVar objects), store names in set. + */ +public class GetAllLabels extends ASTTraverse +{ + private Vector v; + + public GetAllLabels(Vector v) + { + this.v = v; + } + + public void visitPost(ExpressionLabel e) throws PrismLangException + { + if (!v.contains(e.getName())) { + v.addElement(e.getName()); + } + } +} +