KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > expr > ExprFactory


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.quercus.expr;
31
32 import com.caucho.quercus.Location;
33 import com.caucho.quercus.env.Value;
34 import com.caucho.quercus.parser.QuercusParser;
35 import com.caucho.quercus.program.*;
36 import com.caucho.util.L10N;
37 import com.caucho.vfs.Path;
38
39 import java.util.ArrayList JavaDoc;
40 import java.util.logging.Level JavaDoc;
41 import java.util.logging.Logger JavaDoc;
42
43 /**
44  * Factory for creating PHP expressions and statements
45  */

46 public class ExprFactory {
47   private static final L10N L = new L10N(ExprFactory.class);
48   private static final Logger JavaDoc log
49     = Logger.getLogger(ExprFactory.class.getName());
50
51   public ExprFactory()
52   {
53   }
54
55   public static ExprFactory create()
56   {
57     try {
58       Class JavaDoc cl = Class.forName("com.caucho.quercus.expr.ProExprFactory");
59
60       return (ExprFactory) cl.newInstance();
61     } catch (Exception JavaDoc e) {
62       log.log(Level.FINEST, e.toString(), e);
63
64       return new ExprFactory();
65     }
66   }
67
68   /**
69    * Creates a null literal expression.
70    */

71   public Expr createNull()
72   {
73     return NullLiteralExpr.NULL;
74   }
75
76   /**
77    * Creates a string literal expression.
78    */

79   public Expr createString(String JavaDoc lexeme)
80   {
81     return new StringLiteralExpr(lexeme);
82   }
83
84   /**
85    * Creates a binary literal expression.
86    */

87   public Expr createBinary(byte []bytes)
88   {
89     return new BinaryLiteralExpr(bytes);
90   }
91
92   /**
93    * Creates a long literal expression.
94    */

95   public Expr createLong(long value)
96   {
97     return new LongLiteralExpr(value);
98   }
99
100   /**
101    * Creates a string literal expression.
102    */

103   public Expr createLiteral(Value literal)
104   {
105     return new LiteralExpr(literal);
106   }
107
108   /**
109    * Creates a var expression.
110    */

111   public VarExpr createVar(VarInfo var)
112   {
113     return new VarExpr(var);
114   }
115
116   /**
117    * Creates a var expression.
118    */

119   public VarVarExpr createVarVar(Expr var)
120   {
121     return new VarVarExpr(var);
122   }
123
124   /**
125    * Creates a const expression.
126    */

127   public ConstExpr createConst(String JavaDoc name)
128   {
129     return new ConstExpr(name);
130   }
131
132   /**
133    * Creates a class const expression.
134    */

135   public ClassConstExpr createClassConst(String JavaDoc className, String JavaDoc name)
136   {
137     return new ClassConstExpr(className, name);
138   }
139
140   /**
141    * Creates a this expression.
142    */

143   public ThisExpr createThis(InterpretedClassDef cl)
144   {
145     return new ThisExpr(cl);
146   }
147
148   /**
149    * Creates an array get 'a[0]' expression.
150    */

151   public ArrayGetExpr createArrayGet(Expr base, Expr index)
152   {
153     return new ArrayGetExpr(base, index);
154   }
155
156   /**
157    * Creates an array tail 'a[]' expression.
158    */

159   public ArrayTailExpr createArrayTail(Expr base)
160   {
161     return new ArrayTailExpr(base);
162   }
163
164   /**
165    * Creates an object get '$a->b' expression.
166    */

167   public Expr createFieldGet(Expr base, String JavaDoc name)
168   {
169     return new FieldGetExpr(base, name);
170   }
171
172   /**
173    * Creates an object get '$a->$b' expression.
174    */

175   public Expr createFieldVarGet(Expr base, Expr name)
176   {
177     return new FieldVarGetExpr(base, name);
178   }
179
180   /**
181    * Creates an object get 'a::b' expression.
182    */

183   public Expr createStaticFieldGet(String JavaDoc className, String JavaDoc name)
184   {
185     return new StaticFieldGetExpr(className, name);
186   }
187
188   /**
189    * Creates an unset '$a' expression.
190    */

191   public Expr createUnsetVar(AbstractVarExpr var)
192   {
193     return new UnsetVarExpr(var);
194   }
195
196   /**
197    * Creates a char at 'a{0}' expression.
198    */

199   public CharAtExpr createCharAt(Expr base, Expr index)
200   {
201     return new CharAtExpr(base, index);
202   }
203
204   /**
205    * Creates a post increment 'a++' expression.
206    */

207   public PostIncrementExpr createPostIncrement(Expr expr, int incr)
208   {
209     return new PostIncrementExpr(expr, incr);
210   }
211
212   /**
213    * Creates a pre increment '++a' expression.
214    */

215   public PreIncrementExpr createPreIncrement(Expr expr, int incr)
216   {
217     return new PreIncrementExpr(expr, incr);
218   }
219
220   /**
221    * Creates a unary minus '-a' expression.
222    */

223   public Expr createMinus(Expr expr)
224   {
225     return new MinusExpr(expr);
226   }
227
228   /**
229    * Creates a unary plus '+a' expression.
230    */

231   public Expr createPlus(Expr expr)
232   {
233     return new PlusExpr(expr);
234   }
235
236   /**
237    * Creates a unary not '!a' expression.
238    */

239   public Expr createNot(Expr expr)
240   {
241     return new NotExpr(expr);
242   }
243
244   /**
245    * Creates a unary inversion '~a' expression.
246    */

247   public Expr createBitNot(Expr expr)
248   {
249     return new BitNotExpr(expr);
250   }
251
252   /**
253    * Creates a clone 'clone a' expression.
254    */

255   public Expr createClone(Expr expr)
256   {
257     return new CloneExpr(expr);
258   }
259
260   /**
261    * Creates a clone 'clone a' expression.
262    */

263   public Expr createCopy(Expr expr)
264   {
265     return new CopyExpr(expr);
266   }
267
268   /**
269    * Creates an error suppression '@a' expression.
270    */

271   public Expr createSuppress(Expr expr)
272   {
273     return new SuppressErrorExpr(expr);
274   }
275
276   /**
277    * Creates a boolean cast
278    */

279   public Expr createToBoolean(Expr expr)
280   {
281     return new ToBooleanExpr(expr);
282   }
283
284   /**
285    * Creates a long cast
286    */

287   public Expr createToLong(Expr expr)
288   {
289     return new ToLongExpr(expr);
290   }
291
292   /**
293    * Creates a double cast
294    */

295   public Expr createToDouble(Expr expr)
296   {
297     return new ToDoubleExpr(expr);
298   }
299
300   /**
301    * Creates a string cast
302    */

303   public Expr createToString(Expr expr)
304   {
305     return new ToStringExpr(expr);
306   }
307
308   /**
309    * Creates a unicode cast
310    */

311   public Expr createToUnicode(Expr expr)
312   {
313     return new ToUnicodeExpr(expr);
314   }
315
316   /**
317    * Creates a binary string cast
318    */

319   public Expr createToBinary(Expr expr)
320   {
321     return new ToBinaryExpr(expr);
322   }
323
324   /**
325    * Creates an object cast
326    */

327   public Expr createToObject(Expr expr)
328   {
329     return new ToObjectExpr(expr);
330   }
331
332   /**
333    * Creates an array cast
334    */

335   public Expr createToArray(Expr expr)
336   {
337     return new ToArrayExpr(expr);
338   }
339
340   /**
341    * Creates a die 'die("msg")' expression.
342    */

343   public Expr createDie(Expr expr)
344   {
345     return new DieExpr(expr);
346   }
347
348   /**
349    * Creates an exit 'exit("msg")' expression.
350    */

351   public Expr createExit(Expr expr)
352   {
353     return new ExitExpr(expr);
354   }
355
356   /**
357    * Creates a required
358    */

359   public Expr createRequired()
360   {
361     return new RequiredExpr();
362   }
363
364   /**
365    * Creates a default
366    */

367   public Expr createDefault()
368   {
369     return new DefaultExpr();
370   }
371
372   /**
373    * Creates an addition expression.
374    */

375   public Expr createAdd(Expr left, Expr right)
376   {
377     return new AddExpr(left, right);
378   }
379
380   /**
381    * Creates a subtraction expression.
382    */

383   public Expr createSub(Expr left, Expr right)
384   {
385     return new SubExpr(left, right);
386   }
387
388   /**
389    * Creates a multiplication expression.
390    */

391   public Expr createMul(Expr left, Expr right)
392   {
393     return new MulExpr(left, right);
394   }
395
396   /**
397    * Creates a division expression.
398    */

399   public Expr createDiv(Expr left, Expr right)
400   {
401     return new DivExpr(left, right);
402   }
403
404   /**
405    * Creates a modulo expression.
406    */

407   public Expr createMod(Expr left, Expr right)
408   {
409     return new ModExpr(left, right);
410   }
411
412   /**
413    * Creates a left-shift expression.
414    */

415   public Expr createLeftShift(Expr left, Expr right)
416   {
417     return new LeftShiftExpr(left, right);
418   }
419
420   /**
421    * Creates a right-shift expression.
422    */

423   public Expr createRightShift(Expr left, Expr right)
424   {
425     return new RightShiftExpr(left, right);
426   }
427
428   /**
429    * Creates a bit-and expression.
430    */

431   public Expr createBitAnd(Expr left, Expr right)
432   {
433     return new BitAndExpr(left, right);
434   }
435
436   /**
437    * Creates a bit-or expression.
438    */

439   public Expr createBitOr(Expr left, Expr right)
440   {
441     return new BitOrExpr(left, right);
442   }
443
444   /**
445    * Creates a bit-xor expression.
446    */

447   public Expr createBitXor(Expr left, Expr right)
448   {
449     return new BitXorExpr(left, right);
450   }
451
452   /**
453    * Creates an append expression
454    */

455   public final Expr createAppend(Expr left, Expr right)
456   {
457     AppendExpr leftAppend;
458
459     // XXX: i18n binary vs unicode issues
460
/*
461     if (left instanceof ToStringExpr)
462       left = ((ToStringExpr) left).getExpr();
463
464     if (left instanceof StringLiteralExpr) {
465       StringLiteralExpr string = (StringLiteralExpr) left;
466
467       if (string.evalConstant().length() == 0)
468     return ToStringExpr.create(right);
469     }
470     */

471
472     if (left instanceof AppendExpr)
473       leftAppend = (AppendExpr) left;
474     else
475       leftAppend = createAppendImpl(left, null);
476     
477     AppendExpr next;
478
479     /*
480     if (right instanceof ToStringExpr)
481       right = ((ToStringExpr) right).getExpr();
482
483     if (right instanceof StringLiteralExpr) {
484       StringLiteralExpr string = (StringLiteralExpr) right;
485
486       if (string.evalConstant().length() == 0)
487     return ToStringExpr.create(left);
488     }
489     */

490
491     if (right instanceof AppendExpr)
492       next = (AppendExpr) right;
493     else
494       next = createAppendImpl(right, null);
495
496     AppendExpr result = append(leftAppend, next);
497
498     if (result.getNext() != null)
499       return result;
500     else
501       return result.getValue();
502   }
503
504   /**
505    * Appends the tail to the current expression, combining
506    * constant literals.
507    */

508   private AppendExpr append(AppendExpr left, AppendExpr tail)
509   {
510     if (left == null)
511       return tail;
512
513     tail = append(left.getNext(), tail);
514
515     if (true
516     && left.getValue() instanceof StringLiteralExpr
517     && tail.getValue() instanceof StringLiteralExpr) {
518       StringLiteralExpr leftString = (StringLiteralExpr) left.getValue();
519       StringLiteralExpr rightString = (StringLiteralExpr) tail.getValue();
520
521       Expr value = createString(leftString.evalConstant().toString()
522                 + rightString.evalConstant().toString());
523
524       return createAppendImpl(value, tail.getNext());
525     }
526     else {
527       left.setNext(tail);
528
529       return left;
530     }
531   }
532   
533   protected AppendExpr createAppendImpl(Expr left, AppendExpr right)
534   {
535     return new AppendExpr(left, right);
536   }
537
538   /**
539    * Creates a lt expression.
540    */

541   public Expr createLt(Expr left, Expr right)
542   {
543     return new LtExpr(left, right);
544   }
545
546   /**
547    * Creates a leq expression.
548    */

549   public Expr createLeq(Expr left, Expr right)
550   {
551     return new LeqExpr(left, right);
552   }
553
554   /**
555    * Creates a gt expression.
556    */

557   public Expr createGt(Expr left, Expr right)
558   {
559     return new GtExpr(left, right);
560   }
561
562   /**
563    * Creates a geq expression.
564    */

565   public Expr createGeq(Expr left, Expr right)
566   {
567     return new GeqExpr(left, right);
568   }
569
570   /**
571    * Creates an eq expression.
572    */

573   public Expr createEq(Expr left, Expr right)
574   {
575     return new EqExpr(left, right);
576   }
577
578   /**
579    * Creates a neq expression.
580    */

581   public Expr createNeq(Expr left, Expr right)
582   {
583     return new NeqExpr(left, right);
584   }
585
586   /**
587    * Creates an equals expression.
588    */

589   public Expr createEquals(Expr left, Expr right)
590   {
591     return new EqualsExpr(left, right);
592   }
593
594   /**
595    * Creates an assignment expression.
596    */

597   public Expr createAssign(AbstractVarExpr left, Expr right)
598   {
599     return new AssignExpr(left, right);
600   }
601
602   /**
603    * Creates an assignment expression.
604    */

605   public Expr createAssignRef(AbstractVarExpr left, Expr right)
606   {
607     return new AssignRefExpr(left, right);
608   }
609
610   /**
611    * Creates a ref '&$a' expression.
612    */

613   public RefExpr createRef(Expr base)
614   {
615     return new RefExpr(base);
616   }
617
618   /**
619    * Creates an and expression.
620    */

621   public Expr createAnd(Expr left, Expr right)
622   {
623     return new AndExpr(left, right);
624   }
625
626   /**
627    * Creates an or expression.
628    */

629   public Expr createOr(Expr left, Expr right)
630   {
631     return new OrExpr(left, right);
632   }
633
634   /**
635    * Creates an xor expression.
636    */

637   public Expr createXor(Expr left, Expr right)
638   {
639     return new XorExpr(left, right);
640   }
641
642   /**
643    * Creates a comma expression.
644    */

645   public Expr createComma(Expr left, Expr right)
646   {
647     return new CommaExpr(left, right);
648   }
649
650   /**
651    * Creates an instanceof expression.
652    */

653   public Expr createInstanceOf(Expr expr, String JavaDoc name)
654   {
655     return new InstanceOfExpr(expr, name);
656   }
657
658   /**
659    * Creates an instanceof expression.
660    */

661   public Expr createInstanceOfVar(Expr expr, Expr name)
662   {
663     return new InstanceOfVarExpr(expr, name);
664   }
665
666   /**
667    * Creates an each expression.
668    */

669   public Expr createEach(Expr expr)
670   {
671     return new EachExpr(expr);
672   }
673
674   /**
675    * Creates a list expression.
676    */

677   public final Expr createList(QuercusParser parser,
678                    ListHeadExpr head, Expr value)
679   {
680     boolean isSuppress = value instanceof SuppressErrorExpr;
681
682     if (isSuppress) {
683       SuppressErrorExpr suppressExpr = (SuppressErrorExpr) value;
684
685       value = suppressExpr.getExpr();
686     }
687
688     Expr expr;
689
690     if (value instanceof EachExpr) {
691       expr = createListEach(head.getVarList(), (EachExpr) value);
692     }
693     else
694       expr = createList(head, value);
695
696     if (isSuppress)
697       return createSuppress(expr);
698     else
699       return expr;
700   }
701
702   /**
703    * Creates a list expression.
704    */

705   public ListHeadExpr createListHead(ArrayList JavaDoc<Expr> keys)
706   {
707     return new ListHeadExpr(keys);
708   }
709
710   /**
711    * Creates a list expression.
712    */

713   public Expr createList(ListHeadExpr head, Expr value)
714   {
715     return new ListExpr(head, value);
716   }
717
718   /**
719    * Creates a list expression.
720    */

721   public Expr createListEach(Expr []varList, EachExpr value)
722   {
723     return new ListEachExpr(varList, value);
724   }
725
726   /**
727    * Creates an conditional expression.
728    */

729   public Expr createConditional(Expr test, Expr left, Expr right)
730   {
731     return new ConditionalExpr(test, left, right);
732   }
733
734   /**
735    * Creates a array() expression.
736    */

737   public Expr createArrayFun(ArrayList JavaDoc<Expr> keys, ArrayList JavaDoc<Expr> values)
738   {
739     return new ArrayFunExpr(keys, values);
740   }
741
742   /**
743    * Creates a new function call.
744    */

745   public FunctionExpr createFunction(Location loc,
746                      String JavaDoc name,
747                      ArrayList JavaDoc<Expr> args)
748   {
749     return new FunctionExpr(loc, name, args);
750   }
751
752   /**
753    * Creates a new var function call.
754    */

755   public VarFunctionExpr createVarFunction(Location loc,
756                        Expr name,
757                        ArrayList JavaDoc<Expr> args)
758   {
759     return new VarFunctionExpr(loc, name, args);
760   }
761
762   /**
763    * Creates a new function call.
764    */

765   public Expr createClassMethod(Location loc,
766                 String JavaDoc className,
767                 String JavaDoc name,
768                 ArrayList JavaDoc<Expr> args)
769   {
770     return new ClassMethodExpr(loc, className, name, args);
771   }
772
773   /**
774    * Creates a new function call.
775    */

776   public Expr createStaticMethod(Location loc,
777                  String JavaDoc className,
778                  String JavaDoc name,
779                  ArrayList JavaDoc<Expr> args)
780   {
781     return new StaticMethodExpr(loc, className, name, args);
782   }
783
784   /**
785    * Creates a new method call.
786    */

787   public Expr createMethodCall(Location loc,
788                        Expr objExpr,
789                        String JavaDoc name,
790                        ArrayList JavaDoc<Expr> args)
791   {
792     return new MethodCallExpr(loc, objExpr, name, args);
793   }
794
795   /**
796    * Creates a new method call.
797    */

798   public Expr createVarMethodCall(Location loc,
799                   Expr objExpr,
800                   Expr name,
801                   ArrayList JavaDoc<Expr> args)
802   {
803     return new VarMethodCallExpr(loc, objExpr, name, args);
804   }
805
806   /**
807    * Creates a new function call.
808    */

809   public NewExpr createNew(Location loc,
810                String JavaDoc name,
811                ArrayList JavaDoc<Expr> args)
812   {
813     return new NewExpr(loc, name, args);
814   }
815
816   /**
817    * Creates a new function call.
818    */

819   public VarNewExpr createVarNew(Location loc,
820                  Expr name,
821                  ArrayList JavaDoc<Expr> args)
822   {
823     return new VarNewExpr(loc, name, args);
824   }
825
826   /**
827    * Creates an include expr
828    */

829   public Expr createInclude(Location loc,
830                 Path source,
831                 Expr expr)
832   {
833     return new IncludeExpr(loc, source, expr, false);
834   }
835
836   /**
837    * Creates an include expr
838    */

839   public Expr createRequire(Location loc,
840                 Path source,
841                 Expr expr)
842   {
843     return new IncludeExpr(loc, source, expr, true);
844   }
845
846   /**
847    * Creates an include expr
848    */

849   public Expr createIncludeOnce(Location loc,
850                 Path source,
851                 Expr expr)
852   {
853     return new IncludeOnceExpr(loc, source, expr, false);
854   }
855
856   /**
857    * Creates an include expr
858    */

859   public Expr createRequireOnce(Location loc,
860                 Path source,
861                 Expr expr)
862   {
863     return new IncludeOnceExpr(loc, source, expr, true);
864   }
865
866   /**
867    * Creates a null literal expression.
868    */

869   public Statement createNullStatement()
870   {
871     return NullStatement.NULL;
872   }
873
874   /**
875    * Creates an echo statement
876    */

877   public Statement createEcho(Location loc, Expr expr)
878   {
879     return new EchoStatement(loc, expr);
880   }
881
882   /**
883    * Creates an expr statement
884    */

885   public Statement createExpr(Location loc, Expr expr)
886   {
887     return new ExprStatement(loc, expr);
888   }
889
890   public final Statement createBlock(Location loc,
891                      ArrayList JavaDoc<Statement> statementList)
892   {
893     if (statementList.size() == 1)
894       return statementList.get(0);
895
896     Statement []statements = new Statement[statementList.size()];
897
898     statementList.toArray(statements);
899
900     return createBlockImpl(loc, statements);
901   }
902
903   public final Statement createBlock(Location loc, Statement []statementList)
904   {
905     if (statementList.length == 1)
906       return statementList[0];
907
908     Statement []statements = new Statement[statementList.length];
909
910     System.arraycopy(statementList, 0, statements, 0, statementList.length);
911
912     return createBlockImpl(loc, statements);
913   }
914
915   /**
916    * Creates an expr statement
917    */

918   public final BlockStatement createBlockImpl(Location loc,
919                           ArrayList JavaDoc<Statement> statementList)
920   {
921     Statement []statements = new Statement[statementList.size()];
922
923     statementList.toArray(statements);
924     
925     return createBlockImpl(loc, statements);
926   }
927
928   /**
929    * Creates an expr statement
930    */

931   public BlockStatement createBlockImpl(Location loc, Statement []statements)
932   {
933     return new BlockStatement(loc, statements);
934   }
935
936   /**
937    * Creates a text statement
938    */

939   public Statement createText(Location loc, String JavaDoc text)
940   {
941     return new TextStatement(loc, text);
942   }
943
944   /**
945    * Creates an if statement
946    */

947   public Statement createIf(Location loc,
948                 Expr test,
949                 Statement trueBlock,
950                 Statement falseBlock)
951   {
952     return new IfStatement(loc, test, trueBlock, falseBlock);
953   }
954
955   /**
956    * Creates a switch statement
957    */

958   public Statement createSwitch(Location loc,
959                 Expr value,
960                 ArrayList JavaDoc<Expr[]> caseList,
961                 ArrayList JavaDoc<BlockStatement> blockList,
962                 Statement defaultBlock)
963   {
964     return new SwitchStatement(loc, value, caseList, blockList, defaultBlock);
965   }
966
967   /**
968    * Creates a for statement
969    */

970   public Statement createFor(Location loc,
971                  Expr init,
972                  Expr test,
973                  Expr incr,
974                  Statement block)
975   {
976     return new ForStatement(loc, init, test, incr, block);
977   }
978
979   /**
980    * Creates a foreach statement
981    */

982   public Statement createForeach(Location loc,
983                  Expr objExpr,
984                  AbstractVarExpr key,
985                  AbstractVarExpr value,
986                  boolean isRef,
987                  Statement block)
988   {
989     return new ForeachStatement(loc, objExpr, key, value, isRef, block);
990   }
991
992   /**
993    * Creates a while statement
994    */

995   public Statement createWhile(Location loc,
996                    Expr test,
997                    Statement block)
998   {
999     return new WhileStatement(loc, test, block);
1000  }
1001
1002  /**
1003   * Creates a do-while statement
1004   */

1005  public Statement createDo(Location loc,
1006                Expr test,
1007                Statement block)
1008  {
1009    return new DoStatement(loc, test, block);
1010  }
1011
1012  /**
1013   * Creates a break statement
1014   */

1015  public BreakStatement createBreak()
1016  {
1017    return BreakStatement.BREAK;
1018  }
1019
1020  /**
1021   * Creates a continue statement
1022   */

1023  public ContinueStatement createContinue()
1024  {
1025    return ContinueStatement.CONTINUE;
1026  }
1027
1028  /**
1029   * Creates a global statement
1030   */

1031  public Statement createGlobal(Location loc,
1032                VarExpr var)
1033  {
1034    return new GlobalStatement(loc, var);
1035  }
1036
1037  /**
1038   * Creates a static statement
1039   */

1040  public Statement createStatic(Location loc,
1041                VarExpr var,
1042                Expr value)
1043  {
1044    return new StaticStatement(loc, var, value);
1045  }
1046
1047  /**
1048   * Creates a throw statement
1049   */

1050  public Statement createThrow(Location loc,
1051                Expr value)
1052  {
1053    return new ThrowStatement(loc, value);
1054  }
1055
1056  /**
1057   * Creates a try statement
1058   */

1059  public TryStatement createTry(Location loc,
1060                Statement block)
1061  {
1062    return new TryStatement(loc, block);
1063  }
1064
1065  /**
1066   * Creates a return statement
1067   */

1068  public Statement createReturn(Location loc,
1069                Expr value)
1070  {
1071    return new ReturnStatement(loc, value);
1072  }
1073
1074  /**
1075   * Creates a return ref statement
1076   */

1077  public Statement createReturnRef(Location loc,
1078                   Expr value)
1079  {
1080    return new ReturnRefStatement(loc, value);
1081  }
1082
1083  /**
1084   * Creates a new function definition def.
1085   */

1086  public Statement createFunctionDef(Location loc,
1087                     Function fun)
1088  {
1089    return new FunctionDefStatement(loc, fun);
1090  }
1091
1092  /**
1093   * Creates a new function def statement
1094   */

1095  public Statement createClassDef(Location loc,
1096                  InterpretedClassDef cl)
1097  {
1098    return new ClassDefStatement(loc, cl);
1099  }
1100
1101  /**
1102   * Creates a new function definition.
1103   */

1104  public Function createFunction(Location loc,
1105                 String JavaDoc name,
1106                 FunctionInfo info,
1107                 ArrayList JavaDoc<Arg> argList,
1108                 ArrayList JavaDoc<Statement> statementList)
1109  {
1110    return new Function(this, loc, name, info, argList, statementList);
1111  }
1112
1113  /**
1114   * Creates a new object method definition.
1115   */

1116  public Function createObjectMethod(Location loc,
1117                     InterpretedClassDef cl,
1118                     String JavaDoc name,
1119                     FunctionInfo info,
1120                     ArrayList JavaDoc<Arg> argList,
1121                     ArrayList JavaDoc<Statement> statementList)
1122  {
1123    return new ObjectMethod(this, loc, cl, name, info, argList, statementList);
1124  }
1125
1126  /**
1127   * Creates a new object method definition.
1128   */

1129  public Function createMethodDeclaration(Location loc,
1130                     InterpretedClassDef cl,
1131                     String JavaDoc name,
1132                     FunctionInfo info,
1133                     ArrayList JavaDoc<Arg> argList)
1134  {
1135    return new MethodDeclaration(this, loc, cl, name, info, argList);
1136  }
1137
1138  public InterpretedClassDef createClassDef(String JavaDoc name,
1139                        String JavaDoc parentName,
1140                        String JavaDoc []ifaceList)
1141  {
1142    return new InterpretedClassDef(name, parentName, ifaceList);
1143  }
1144}
1145
1146
Popular Tags