00001 package edu.ksu.cis.bandera.jjjc.node;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 import ca.mcgill.sable.util.*;
00037 import edu.ksu.cis.bandera.jjjc.analysis.*;
00038
00039 public final class AOldNameCastExp extends PCastExp
00040 {
00041 private TLPar _lPar_;
00042 private PName _name_;
00043 private final LinkedList _dim_ = new TypedLinkedList(new Dim_Cast());
00044 private TRPar _rPar_;
00045 private PUnaryExpNotPlusMinus _unaryExpNotPlusMinus_;
00046
00047 private class Dim_Cast implements Cast
00048 {
00049 public Object cast(Object o)
00050 {
00051 PDim node = (PDim) o;
00052
00053 if((node.parent() != null) &&
00054 (node.parent() != AOldNameCastExp.this))
00055 {
00056 node.parent().removeChild(node);
00057 }
00058
00059 if((node.parent() == null) ||
00060 (node.parent() != AOldNameCastExp.this))
00061 {
00062 node.parent(AOldNameCastExp.this);
00063 }
00064
00065 return node;
00066 }
00067 }
00068 public AOldNameCastExp()
00069 {
00070 }
00071 public AOldNameCastExp(
00072 TLPar _lPar_,
00073 PName _name_,
00074 List _dim_,
00075 TRPar _rPar_,
00076 PUnaryExpNotPlusMinus _unaryExpNotPlusMinus_)
00077 {
00078 setLPar(_lPar_);
00079
00080 setName(_name_);
00081
00082 {
00083 Object temp[] = _dim_.toArray();
00084 for(int i = 0; i < temp.length; i++)
00085 {
00086 this._dim_.add(temp[i]);
00087 }
00088 }
00089
00090 setRPar(_rPar_);
00091
00092 setUnaryExpNotPlusMinus(_unaryExpNotPlusMinus_);
00093
00094 }
00095 public AOldNameCastExp(
00096 TLPar _lPar_,
00097 PName _name_,
00098 XPDim _dim_,
00099 TRPar _rPar_,
00100 PUnaryExpNotPlusMinus _unaryExpNotPlusMinus_)
00101 {
00102 setLPar(_lPar_);
00103
00104 setName(_name_);
00105
00106 if(_dim_ != null)
00107 {
00108 while(_dim_ instanceof X1PDim)
00109 {
00110 this._dim_.addFirst(((X1PDim) _dim_).getPDim());
00111 _dim_ = ((X1PDim) _dim_).getXPDim();
00112 }
00113 this._dim_.addFirst(((X2PDim) _dim_).getPDim());
00114 }
00115
00116 setRPar(_rPar_);
00117
00118 setUnaryExpNotPlusMinus(_unaryExpNotPlusMinus_);
00119
00120 }
00121 public void apply(Switch sw)
00122 {
00123 ((Analysis) sw).caseAOldNameCastExp(this);
00124 }
00125 public Object clone()
00126 {
00127 return new AOldNameCastExp(
00128 (TLPar) cloneNode(_lPar_),
00129 (PName) cloneNode(_name_),
00130 cloneList(_dim_),
00131 (TRPar) cloneNode(_rPar_),
00132 (PUnaryExpNotPlusMinus) cloneNode(_unaryExpNotPlusMinus_));
00133 }
00134 public LinkedList getDim()
00135 {
00136 return _dim_;
00137 }
00138 public TLPar getLPar()
00139 {
00140 return _lPar_;
00141 }
00142 public PName getName()
00143 {
00144 return _name_;
00145 }
00146 public TRPar getRPar()
00147 {
00148 return _rPar_;
00149 }
00150 public PUnaryExpNotPlusMinus getUnaryExpNotPlusMinus()
00151 {
00152 return _unaryExpNotPlusMinus_;
00153 }
00154 void removeChild(Node child)
00155 {
00156 if(_lPar_ == child)
00157 {
00158 _lPar_ = null;
00159 return;
00160 }
00161
00162 if(_name_ == child)
00163 {
00164 _name_ = null;
00165 return;
00166 }
00167
00168 if(_dim_.remove(child))
00169 {
00170 return;
00171 }
00172
00173 if(_rPar_ == child)
00174 {
00175 _rPar_ = null;
00176 return;
00177 }
00178
00179 if(_unaryExpNotPlusMinus_ == child)
00180 {
00181 _unaryExpNotPlusMinus_ = null;
00182 return;
00183 }
00184
00185 }
00186 void replaceChild(Node oldChild, Node newChild)
00187 {
00188 if(_lPar_ == oldChild)
00189 {
00190 setLPar((TLPar) newChild);
00191 return;
00192 }
00193
00194 if(_name_ == oldChild)
00195 {
00196 setName((PName) newChild);
00197 return;
00198 }
00199
00200 for(ListIterator i = _dim_.listIterator(); i.hasNext();)
00201 {
00202 if(i.next() == oldChild)
00203 {
00204 if(newChild != null)
00205 {
00206 i.set(newChild);
00207 oldChild.parent(null);
00208 return;
00209 }
00210
00211 i.remove();
00212 oldChild.parent(null);
00213 return;
00214 }
00215 }
00216
00217 if(_rPar_ == oldChild)
00218 {
00219 setRPar((TRPar) newChild);
00220 return;
00221 }
00222
00223 if(_unaryExpNotPlusMinus_ == oldChild)
00224 {
00225 setUnaryExpNotPlusMinus((PUnaryExpNotPlusMinus) newChild);
00226 return;
00227 }
00228
00229 }
00230 public void setDim(List list)
00231 {
00232 Object temp[] = list.toArray();
00233 for(int i = 0; i < temp.length; i++)
00234 {
00235 _dim_.add(temp[i]);
00236 }
00237 }
00238 public void setLPar(TLPar node)
00239 {
00240 if(_lPar_ != null)
00241 {
00242 _lPar_.parent(null);
00243 }
00244
00245 if(node != null)
00246 {
00247 if(node.parent() != null)
00248 {
00249 node.parent().removeChild(node);
00250 }
00251
00252 node.parent(this);
00253 }
00254
00255 _lPar_ = node;
00256 }
00257 public void setName(PName node)
00258 {
00259 if(_name_ != null)
00260 {
00261 _name_.parent(null);
00262 }
00263
00264 if(node != null)
00265 {
00266 if(node.parent() != null)
00267 {
00268 node.parent().removeChild(node);
00269 }
00270
00271 node.parent(this);
00272 }
00273
00274 _name_ = node;
00275 }
00276 public void setRPar(TRPar node)
00277 {
00278 if(_rPar_ != null)
00279 {
00280 _rPar_.parent(null);
00281 }
00282
00283 if(node != null)
00284 {
00285 if(node.parent() != null)
00286 {
00287 node.parent().removeChild(node);
00288 }
00289
00290 node.parent(this);
00291 }
00292
00293 _rPar_ = node;
00294 }
00295 public void setUnaryExpNotPlusMinus(PUnaryExpNotPlusMinus node)
00296 {
00297 if(_unaryExpNotPlusMinus_ != null)
00298 {
00299 _unaryExpNotPlusMinus_.parent(null);
00300 }
00301
00302 if(node != null)
00303 {
00304 if(node.parent() != null)
00305 {
00306 node.parent().removeChild(node);
00307 }
00308
00309 node.parent(this);
00310 }
00311
00312 _unaryExpNotPlusMinus_ = node;
00313 }
00314 public String toString()
00315 {
00316 return ""
00317 + toString(_lPar_)
00318 + toString(_name_)
00319 + toString(_dim_)
00320 + toString(_rPar_)
00321 + toString(_unaryExpNotPlusMinus_);
00322 }
00323 }