From aa3ec454a8d52b5213bae31629b4641892a0b2a6 Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Fri, 22 Jul 2016 10:29:05 +0000 Subject: [PATCH] ConstantList: add constructor from Values object git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@11547 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/parser/ast/ConstantList.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/prism/src/parser/ast/ConstantList.java b/prism/src/parser/ast/ConstantList.java index 4f892269..05ff0012 100644 --- a/prism/src/parser/ast/ConstantList.java +++ b/prism/src/parser/ast/ConstantList.java @@ -49,12 +49,28 @@ public class ConstantList extends ASTElement // This is to just to provide positional info. private Vector nameIdents = new Vector(); - // Constructor - + /** Constructor */ public ConstantList() { } + /** Constructor from a Values object, i.e., a list of name=value tuples */ + public ConstantList(Values constValues) throws PrismLangException + { + for (int i = 0; i < constValues.getNumValues(); i++) { + Type type = constValues.getType(i); + if (type.equals(TypeBool.getInstance()) || + type.equals(TypeInt.getInstance()) || + type.equals(TypeDouble.getInstance())) { + addConstant(new ExpressionIdent(constValues.getName(i)), + new ExpressionLiteral(type, constValues.getValue(i)), + type); + } else { + throw new PrismLangException("Unsupported type for constant " + constValues.getName(i)); + } + } + } + // Set methods public void addConstant(ExpressionIdent n, Expression c, Type t)