|
39 | 39 | /** |
40 | 40 | * Class to store list of (defined and undefined) constants |
41 | 41 | */ |
42 | | -public class ConstantList extends ASTElement |
| 42 | +public class ConstantList extends ASTElement implements Cloneable |
43 | 43 | { |
44 | 44 | // Name/expression/type triples to define constants |
45 | 45 | private Vector<String> names = new Vector<String>(); |
@@ -80,7 +80,15 @@ public void addConstant(ExpressionIdent n, Expression c, Type t) |
80 | 80 | types.addElement(t); |
81 | 81 | nameIdents.addElement(n); |
82 | 82 | } |
83 | | - |
| 83 | + |
| 84 | + public void setConstant(int i, ExpressionIdent n, Expression c, Type t) |
| 85 | + { |
| 86 | + names.set(i, n.getName()); |
| 87 | + constants.set(i, c); |
| 88 | + types.set(i, t); |
| 89 | + nameIdents.set(i, n); |
| 90 | + } |
| 91 | + |
84 | 92 | public void setConstant(int i, Expression c) |
85 | 93 | { |
86 | 94 | constants.setElementAt(c, i); |
@@ -151,6 +159,7 @@ public void removeConstant(int i) |
151 | 159 | nameIdents.remove(i); |
152 | 160 | } |
153 | 161 |
|
| 162 | + |
154 | 163 | /** |
155 | 164 | * Find cyclic dependencies. |
156 | 165 | */ |
@@ -429,21 +438,29 @@ public String toString() |
429 | 438 |
|
430 | 439 | return s; |
431 | 440 | } |
432 | | - |
433 | | - /** |
434 | | - * Perform a deep copy. |
435 | | - */ |
436 | | - public ASTElement deepCopy() |
| 441 | + |
| 442 | + @Override |
| 443 | + public ConstantList deepCopy(DeepCopy copier) throws PrismLangException |
437 | 444 | { |
438 | | - int i, n; |
439 | | - ConstantList ret = new ConstantList(); |
440 | | - n = size(); |
441 | | - for (i = 0; i < n; i++) { |
442 | | - Expression constantNew = (getConstant(i) == null) ? null : getConstant(i).deepCopy(); |
443 | | - ret.addConstant((ExpressionIdent)getConstantNameIdent(i).deepCopy(), constantNew, getConstantType(i)); |
444 | | - } |
445 | | - ret.setPosition(this); |
446 | | - return ret; |
| 445 | + copier.copyAll(constants); |
| 446 | + copier.copyAll(nameIdents); |
| 447 | + |
| 448 | + return this; |
| 449 | + } |
| 450 | + |
| 451 | + |
| 452 | + @SuppressWarnings("unchecked") |
| 453 | + @Override |
| 454 | + public ConstantList clone() |
| 455 | + { |
| 456 | + ConstantList clone = (ConstantList) super.clone(); |
| 457 | + |
| 458 | + clone.constants = (Vector<Expression>) constants.clone(); |
| 459 | + clone.nameIdents = (Vector<ExpressionIdent>) nameIdents.clone(); |
| 460 | + clone.names = (Vector<String>) names.clone(); |
| 461 | + clone.types = (Vector<Type>) types.clone(); |
| 462 | + |
| 463 | + return clone; |
447 | 464 | } |
448 | 465 | } |
449 | 466 |
|
|
0 commit comments