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 APrimitiveTypeArrayCreationExp extends PArrayCreationExp
00040 {
00041 private TNew _new_;
00042 private PPrimitiveType _primitiveType_;
00043 private final LinkedList _dimExp_ = new TypedLinkedList(new DimExp_Cast());
00044 private final LinkedList _dim_ = new TypedLinkedList(new Dim_Cast());
00045
00046 private class DimExp_Cast implements Cast
00047 {
00048 public Object cast(Object o)
00049 {
00050 PDimExp node = (PDimExp) o;
00051
00052 if((node.parent() != null) &&
00053 (node.parent() != APrimitiveTypeArrayCreationExp.this))
00054 {
00055 node.parent().removeChild(node);
00056 }
00057
00058 if((node.parent() == null) ||
00059 (node.parent() != APrimitiveTypeArrayCreationExp.this))
00060 {
00061 node.parent(APrimitiveTypeArrayCreationExp.this);
00062 }
00063
00064 return node;
00065 }
00066 }
00067
00068 private class Dim_Cast implements Cast
00069 {
00070 public Object cast(Object o)
00071 {
00072 PDim node = (PDim) o;
00073
00074 if((node.parent() != null) &&
00075 (node.parent() != APrimitiveTypeArrayCreationExp.this))
00076 {
00077 node.parent().removeChild(node);
00078 }
00079
00080 if((node.parent() == null) ||
00081 (node.parent() != APrimitiveTypeArrayCreationExp.this))
00082 {
00083 node.parent(APrimitiveTypeArrayCreationExp.this);
00084 }
00085
00086 return node;
00087 }
00088 }
00089 public APrimitiveTypeArrayCreationExp()
00090 {
00091 }
00092 public APrimitiveTypeArrayCreationExp(
00093 TNew _new_,
00094 PPrimitiveType _primitiveType_,
00095 List _dimExp_,
00096 List _dim_)
00097 {
00098 setNew(_new_);
00099
00100 setPrimitiveType(_primitiveType_);
00101
00102 {
00103 Object temp[] = _dimExp_.toArray();
00104 for(int i = 0; i < temp.length; i++)
00105 {
00106 this._dimExp_.add(temp[i]);
00107 }
00108 }
00109
00110 {
00111 Object temp[] = _dim_.toArray();
00112 for(int i = 0; i < temp.length; i++)
00113 {
00114 this._dim_.add(temp[i]);
00115 }
00116 }
00117
00118 }
00119 public APrimitiveTypeArrayCreationExp(
00120 TNew _new_,
00121 PPrimitiveType _primitiveType_,
00122 XPDimExp _dimExp_,
00123 XPDim _dim_)
00124 {
00125 setNew(_new_);
00126
00127 setPrimitiveType(_primitiveType_);
00128
00129 if(_dimExp_ != null)
00130 {
00131 while(_dimExp_ instanceof X1PDimExp)
00132 {
00133 this._dimExp_.addFirst(((X1PDimExp) _dimExp_).getPDimExp());
00134 _dimExp_ = ((X1PDimExp) _dimExp_).getXPDimExp();
00135 }
00136 this._dimExp_.addFirst(((X2PDimExp) _dimExp_).getPDimExp());
00137 }
00138
00139 if(_dim_ != null)
00140 {
00141 while(_dim_ instanceof X1PDim)
00142 {
00143 this._dim_.addFirst(((X1PDim) _dim_).getPDim());
00144 _dim_ = ((X1PDim) _dim_).getXPDim();
00145 }
00146 this._dim_.addFirst(((X2PDim) _dim_).getPDim());
00147 }
00148
00149 }
00150 public void apply(Switch sw)
00151 {
00152 ((Analysis) sw).caseAPrimitiveTypeArrayCreationExp(this);
00153 }
00154 public Object clone()
00155 {
00156 return new APrimitiveTypeArrayCreationExp(
00157 (TNew) cloneNode(_new_),
00158 (PPrimitiveType) cloneNode(_primitiveType_),
00159 cloneList(_dimExp_),
00160 cloneList(_dim_));
00161 }
00162 public LinkedList getDim()
00163 {
00164 return _dim_;
00165 }
00166 public LinkedList getDimExp()
00167 {
00168 return _dimExp_;
00169 }
00170 public TNew getNew()
00171 {
00172 return _new_;
00173 }
00174 public PPrimitiveType getPrimitiveType()
00175 {
00176 return _primitiveType_;
00177 }
00178 void removeChild(Node child)
00179 {
00180 if(_new_ == child)
00181 {
00182 _new_ = null;
00183 return;
00184 }
00185
00186 if(_primitiveType_ == child)
00187 {
00188 _primitiveType_ = null;
00189 return;
00190 }
00191
00192 if(_dimExp_.remove(child))
00193 {
00194 return;
00195 }
00196
00197 if(_dim_.remove(child))
00198 {
00199 return;
00200 }
00201
00202 }
00203 void replaceChild(Node oldChild, Node newChild)
00204 {
00205 if(_new_ == oldChild)
00206 {
00207 setNew((TNew) newChild);
00208 return;
00209 }
00210
00211 if(_primitiveType_ == oldChild)
00212 {
00213 setPrimitiveType((PPrimitiveType) newChild);
00214 return;
00215 }
00216
00217 for(ListIterator i = _dimExp_.listIterator(); i.hasNext();)
00218 {
00219 if(i.next() == oldChild)
00220 {
00221 if(newChild != null)
00222 {
00223 i.set(newChild);
00224 oldChild.parent(null);
00225 return;
00226 }
00227
00228 i.remove();
00229 oldChild.parent(null);
00230 return;
00231 }
00232 }
00233
00234 for(ListIterator i = _dim_.listIterator(); i.hasNext();)
00235 {
00236 if(i.next() == oldChild)
00237 {
00238 if(newChild != null)
00239 {
00240 i.set(newChild);
00241 oldChild.parent(null);
00242 return;
00243 }
00244
00245 i.remove();
00246 oldChild.parent(null);
00247 return;
00248 }
00249 }
00250
00251 }
00252 public void setDim(List list)
00253 {
00254 Object temp[] = list.toArray();
00255 for(int i = 0; i < temp.length; i++)
00256 {
00257 _dim_.add(temp[i]);
00258 }
00259 }
00260 public void setDimExp(List list)
00261 {
00262 Object temp[] = list.toArray();
00263 for(int i = 0; i < temp.length; i++)
00264 {
00265 _dimExp_.add(temp[i]);
00266 }
00267 }
00268 public void setNew(TNew node)
00269 {
00270 if(_new_ != null)
00271 {
00272 _new_.parent(null);
00273 }
00274
00275 if(node != null)
00276 {
00277 if(node.parent() != null)
00278 {
00279 node.parent().removeChild(node);
00280 }
00281
00282 node.parent(this);
00283 }
00284
00285 _new_ = node;
00286 }
00287 public void setPrimitiveType(PPrimitiveType node)
00288 {
00289 if(_primitiveType_ != null)
00290 {
00291 _primitiveType_.parent(null);
00292 }
00293
00294 if(node != null)
00295 {
00296 if(node.parent() != null)
00297 {
00298 node.parent().removeChild(node);
00299 }
00300
00301 node.parent(this);
00302 }
00303
00304 _primitiveType_ = node;
00305 }
00306 public String toString()
00307 {
00308 return ""
00309 + toString(_new_)
00310 + toString(_primitiveType_)
00311 + toString(_dimExp_)
00312 + toString(_dim_);
00313 }
00314 }