@@ -193,6 +193,55 @@ public static Vector getReturnValues(Statement st)
193193 return res ;
194194 } // Other cases, for all other forms of statement.
195195
196+ public static boolean endsWithReturn (Statement st )
197+ { if (st == null )
198+ { return false ; }
199+
200+ if (st instanceof SequenceStatement )
201+ { SequenceStatement sq = (SequenceStatement ) st ;
202+ Vector stats = sq .getStatements ();
203+ Statement stat = (Statement ) stats .get (stats .size ()-1 );
204+ return Statement .endsWithReturn (stat );
205+ }
206+
207+ if (st instanceof ReturnStatement )
208+ { return true ; }
209+
210+ if (st instanceof ConditionalStatement )
211+ { ConditionalStatement cs = (ConditionalStatement ) st ;
212+ if (Statement .endsWithReturn (cs .ifPart ()))
213+ { return Statement .endsWithReturn (cs .elsePart ()); }
214+ return false ;
215+ }
216+
217+ if (st instanceof WhileStatement )
218+ { return false ; }
219+
220+ if (st instanceof TryStatement )
221+ { TryStatement ts = (TryStatement ) st ;
222+
223+ if (Statement .endsWithReturn (ts .getBody ()))
224+ { Vector stats = ts .getClauses ();
225+ for (int i = 0 ; i < stats .size (); i ++)
226+ { if (stats .get (i ) instanceof Statement )
227+ { Statement stat = (Statement ) stats .get (i );
228+ if (Statement .endsWithReturn (stat )) { }
229+ else
230+ { return false ; }
231+ }
232+ else
233+ { return false ; }
234+ }
235+ }
236+ else
237+ { return false ; }
238+ if (ts .getEndStatement () == null ) { return false ; }
239+ return Statement .endsWithReturn (ts .getEndStatement ());
240+ }
241+
242+ return false ;
243+ } // Other cases, for all other forms of statement.
244+
196245 public static Statement replaceReturnBySkip (Statement st )
197246 { if (st == null )
198247 { return st ; }
@@ -269,8 +318,101 @@ public static Statement replaceReturnBySkip(Statement st)
269318 return st ;
270319 } // Other cases, for all other forms of statement.
271320
321+ public static Statement replaceElseBySequence (Statement st )
322+ { if (st == null )
323+ { return st ; }
324+
325+ if (st instanceof SequenceStatement )
326+ { SequenceStatement sq = (SequenceStatement ) st ;
327+ Vector newstats = new Vector ();
328+ Vector stats = sq .getStatements ();
329+ for (int i = 0 ; i < stats .size (); i ++)
330+ { if (stats .get (i ) instanceof Statement )
331+ { Statement stat = (Statement ) stats .get (i );
332+ Statement newstat =
333+ Statement .replaceElseBySequence (stat );
334+ newstats .add (newstat );
335+ }
336+ }
337+
338+ SequenceStatement newsq =
339+ new SequenceStatement (newstats );
340+ newsq .setBrackets (sq .hasBrackets ());
341+ return newsq ;
342+ }
343+
344+ if (st instanceof ReturnStatement )
345+ { return st ; }
346+
347+ if (st instanceof ConditionalStatement )
348+ { ConditionalStatement cs = (ConditionalStatement ) st ;
349+ Statement newif =
350+ Statement .replaceElseBySequence (cs .ifPart ());
351+ Statement newelse =
352+ Statement .replaceElseBySequence (cs .elsePart ());
353+ if (Statement .endsWithReturn (newif ))
354+ { ConditionalStatement res =
355+ new ConditionalStatement (cs .getTest (),
356+ newif ,
357+ new InvocationStatement ("skip" ));
358+ SequenceStatement ss = new SequenceStatement ();
359+ ss .addStatement (res );
360+ ss .addStatement (newelse );
361+ return ss ;
362+ }
363+ else
364+ { ConditionalStatement res =
365+ new ConditionalStatement (cs .getTest (),
366+ newif ,
367+ newelse );
368+
369+ return res ;
370+ }
371+ }
372+
373+ if (st instanceof WhileStatement )
374+ { WhileStatement ws = (WhileStatement ) st ;
375+ Statement newbody =
376+ Statement .replaceElseBySequence (ws .getLoopBody ());
377+ WhileStatement wsnew =
378+ new WhileStatement (ws .getTest (), newbody );
379+ wsnew .loopKind = ws .loopKind ;
380+ wsnew .loopVar = ws .loopVar ;
381+ wsnew .loopRange = ws .loopRange ;
382+
383+ return wsnew ;
384+ }
385+
386+ if (st instanceof TryStatement )
387+ { TryStatement ts = (TryStatement ) st ;
388+ Statement newbody =
389+ Statement .replaceElseBySequence (ts .getBody ());
390+ Vector newclauses = new Vector ();
391+ Vector stats = ts .getClauses ();
392+ for (int i = 0 ; i < stats .size (); i ++)
393+ { if (stats .get (i ) instanceof Statement )
394+ { Statement stat = (Statement ) stats .get (i );
395+ Statement newstat =
396+ Statement .replaceElseBySequence (stat );
397+ newclauses .add (newstat );
398+ }
399+ }
400+
401+ Statement newend =
402+ Statement .replaceElseBySequence (
403+ ts .getEndStatement ());
404+ TryStatement newtry =
405+ new TryStatement (newbody , newclauses , newend );
406+ return newtry ;
407+ }
408+
409+ return st ;
410+ } // Other cases, for all other forms of statement.
411+
272412 public static Vector getLocalDeclarations (Statement st )
273- { Vector res = new Vector ();
413+ { // Local declarations that are not within a loop
414+
415+ Vector res = new Vector ();
274416 if (st == null )
275417 { return res ; }
276418
@@ -300,7 +442,7 @@ public static Vector getLocalDeclarations(Statement st)
300442
301443 if (st instanceof WhileStatement )
302444 { WhileStatement ws = (WhileStatement ) st ;
303- res .addAll (getLocalDeclarations (ws .getLoopBody ()));
445+ // res.addAll(getLocalDeclarations(ws.getLoopBody()));
304446 return res ;
305447 }
306448
@@ -869,7 +1011,7 @@ public static Statement replaceLocalDeclarations(Statement st, Vector vars)
8691011 return res ;
8701012 }
8711013
872- if (st instanceof WhileStatement )
1014+ /* if (st instanceof WhileStatement)
8731015 { WhileStatement ws = (WhileStatement) st;
8741016 Statement newbody =
8751017 Statement.replaceLocalDeclarations(
@@ -880,7 +1022,7 @@ public static Statement replaceLocalDeclarations(Statement st, Vector vars)
8801022 return res;
8811023 }
8821024
883- /* if (st instanceof TryStatement)
1025+ if (st instanceof TryStatement)
8841026 { TryStatement ts = (TryStatement) st;
8851027 res.addAll(getLocalDeclarations(ts.getBody()));
8861028 Vector stats = ts.getClauses();
@@ -5393,6 +5535,19 @@ class CreationStatement extends Statement
53935535 boolean isFrozen = false ; // true when a constant is declared.
53945536 Attribute variable = null ; // for the LHS
53955537
5538+ public Object clone ()
5539+ { CreationStatement cs =
5540+ new CreationStatement (createsInstanceOf ,assignsTo );
5541+ cs .instanceType = instanceType ;
5542+ cs .elementType = elementType ;
5543+ cs .declarationOnly = declarationOnly ;
5544+ cs .initialValue = initialValue ;
5545+ cs .initialExpression = (Expression ) initialExpression .clone ();
5546+ cs .isFrozen = isFrozen ;
5547+ cs .variable = variable ;
5548+ return cs ;
5549+ }
5550+
53965551 public Type getType ()
53975552 { return instanceType ; }
53985553
@@ -5449,6 +5604,15 @@ public CreationStatement(Expression vbl, Type typ)
54495604 assignsTo = vbl + "" ;
54505605 }
54515606
5607+ public CreationStatement defaultVersion ()
5608+ { CreationStatement res = (CreationStatement ) clone ();
5609+ Expression defaultInit =
5610+ Type .defaultInitialValueExpression (instanceType );
5611+ res .initialExpression = defaultInit ;
5612+ res .initialValue = defaultInit + "" ;
5613+ return res ;
5614+ }
5615+
54525616
54535617 /* public CreationStatement(Attribute vbl, Type typ)
54545618 { createsInstanceOf = typ.getName();
@@ -5577,9 +5741,6 @@ public void setElementType(Type t)
55775741 { instanceType .setElementType (t ); }
55785742 }
55795743
5580- public Object clone ()
5581- { return this ; }
5582-
55835744 public Statement dereference (BasicExpression var )
55845745 { return this ; }
55855746
0 commit comments