Skip to content

Commit b574687

Browse files
author
Steffen Märcker
committed
[DAG-copy] Make ASTElements cloneable
1 parent 076cc0a commit b574687

51 files changed

Lines changed: 452 additions & 19 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

prism/src/parser/ast/ASTElement.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
// Abstract class for PRISM language AST elements
3737

38-
public abstract class ASTElement
38+
public abstract class ASTElement implements Cloneable
3939
{
4040
// Type - default to null (unknown)
4141
protected Type type = null;
@@ -188,6 +188,20 @@ public String getEndString()
188188
*/
189189
public abstract ASTElement deepCopy();
190190

191+
/**
192+
* Perform a shallow copy of the receiver and
193+
* clone all internal container, e.g., lists and vectors, too.
194+
*/
195+
@Override
196+
public ASTElement clone()
197+
{
198+
try {
199+
return (ASTElement) super.clone();
200+
} catch (CloneNotSupportedException e) {
201+
throw new InternalError("Object#clone is expected to work for Cloneable objects.", e);
202+
}
203+
}
204+
191205
// Various methods based on AST traversals (implemented using the visitor
192206
// pattern):
193207

prism/src/parser/ast/Command.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ public ASTElement deepCopy()
151151
ret.setPosition(this);
152152
return ret;
153153
}
154+
155+
@Override
156+
public Command clone()
157+
{
158+
return (Command) super.clone();
159+
}
154160
}
155161

156162
//------------------------------------------------------------------------------

prism/src/parser/ast/ConstantList.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void addConstant(ExpressionIdent n, Expression c, Type t)
8080
types.addElement(t);
8181
nameIdents.addElement(n);
8282
}
83-
83+
8484
public void setConstant(int i, Expression c)
8585
{
8686
constants.setElementAt(c, i);
@@ -445,6 +445,20 @@ public ASTElement deepCopy()
445445
ret.setPosition(this);
446446
return ret;
447447
}
448+
449+
@SuppressWarnings("unchecked")
450+
@Override
451+
public ConstantList clone()
452+
{
453+
ConstantList clone = (ConstantList) super.clone();
454+
455+
clone.constants = (Vector<Expression>) constants.clone();
456+
clone.nameIdents = (Vector<ExpressionIdent>) nameIdents.clone();
457+
clone.names = (Vector<String>) names.clone();
458+
clone.types = (Vector<Type>) types.clone();
459+
460+
return clone;
461+
}
448462
}
449463

450464
//------------------------------------------------------------------------------

prism/src/parser/ast/Declaration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ public ASTElement deepCopy()
150150
ret.setPosition(this);
151151
return ret;
152152
}
153+
154+
@Override
155+
public Declaration clone()
156+
{
157+
return (Declaration) super.clone();
158+
}
153159
}
154160

155161
// ------------------------------------------------------------------------------

prism/src/parser/ast/DeclarationArray.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,10 @@ public ASTElement deepCopy()
134134
ret.setPosition(this);
135135
return ret;
136136
}
137+
138+
@Override
139+
public DeclarationArray clone()
140+
{
141+
return (DeclarationArray) super.clone();
142+
}
137143
}

prism/src/parser/ast/DeclarationBool.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,10 @@ public ASTElement deepCopy()
8484
ret.setPosition(this);
8585
return ret;
8686
}
87+
88+
@Override
89+
public DeclarationBool clone()
90+
{
91+
return (DeclarationBool) super.clone();
92+
}
8793
}

prism/src/parser/ast/DeclarationClock.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,10 @@ public ASTElement deepCopy()
8888
ret.setPosition(this);
8989
return ret;
9090
}
91+
92+
@Override
93+
public DeclarationClock clone()
94+
{
95+
return (DeclarationClock) super.clone();
96+
}
9197
}

prism/src/parser/ast/DeclarationInt.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,10 @@ public ASTElement deepCopy()
118118
ret.setPosition(this);
119119
return ret;
120120
}
121+
122+
@Override
123+
public DeclarationInt clone()
124+
{
125+
return (DeclarationInt) super.clone();
126+
}
121127
}

prism/src/parser/ast/DeclarationIntUnbounded.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,10 @@ public ASTElement deepCopy()
8888
ret.setPosition(this);
8989
return ret;
9090
}
91+
92+
@Override
93+
public DeclarationIntUnbounded clone()
94+
{
95+
return (DeclarationIntUnbounded) super.clone();
96+
}
9197
}

prism/src/parser/ast/Expression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public String getResultName()
7676
*/
7777
public abstract boolean returnsSingleValue();
7878

79-
// Overrided version of deepCopy() from superclass ASTElement (to reduce casting).
79+
// Override version of deepCopy() from superclass ASTElement (to reduce casting).
8080

8181
/**
8282
* Perform a deep copy.

0 commit comments

Comments
 (0)