Source Code Cross Referenced for ExprFactory.java in  » EJB-Server-resin-3.1.5 » quercus » com » caucho » quercus » expr » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server resin 3.1.5 » quercus » com.caucho.quercus.expr 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
0003:         *
0004:         * This file is part of Resin(R) Open Source
0005:         *
0006:         * Each copy or derived work must preserve the copyright notice and this
0007:         * notice unmodified.
0008:         *
0009:         * Resin Open Source is free software; you can redistribute it and/or modify
0010:         * it under the terms of the GNU General Public License as published by
0011:         * the Free Software Foundation; either version 2 of the License, or
0012:         * (at your option) any later version.
0013:         *
0014:         * Resin Open Source is distributed in the hope that it will be useful,
0015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
0017:         * of NON-INFRINGEMENT.  See the GNU General Public License for more
0018:         * details.
0019:         *
0020:         * You should have received a copy of the GNU General Public License
0021:         * along with Resin Open Source; if not, write to the
0022:         *
0023:         *   Free Software Foundation, Inc.
0024:         *   59 Temple Place, Suite 330
0025:         *   Boston, MA 02111-1307  USA
0026:         *
0027:         * @author Scott Ferguson
0028:         */
0029:
0030:        package com.caucho.quercus.expr;
0031:
0032:        import com.caucho.quercus.Location;
0033:        import com.caucho.quercus.env.*;
0034:        import com.caucho.quercus.parser.QuercusParser;
0035:        import com.caucho.quercus.program.*;
0036:        import com.caucho.util.L10N;
0037:        import com.caucho.vfs.Path;
0038:
0039:        import java.util.ArrayList;
0040:        import java.util.logging.Level;
0041:        import java.util.logging.Logger;
0042:
0043:        /**
0044:         * Factory for creating PHP expressions and statements
0045:         */
0046:        public class ExprFactory {
0047:            private static final L10N L = new L10N(ExprFactory.class);
0048:            private static final Logger log = Logger
0049:                    .getLogger(ExprFactory.class.getName());
0050:
0051:            public ExprFactory() {
0052:            }
0053:
0054:            public static ExprFactory create() {
0055:                try {
0056:                    Class cl = Class
0057:                            .forName("com.caucho.quercus.expr.ProExprFactory");
0058:
0059:                    return (ExprFactory) cl.newInstance();
0060:                } catch (Exception e) {
0061:                    log.log(Level.FINEST, e.toString(), e);
0062:
0063:                    return new ExprFactory();
0064:                }
0065:            }
0066:
0067:            /**
0068:             * Creates a null literal expression.
0069:             */
0070:            public Expr createNull() {
0071:                return NullLiteralExpr.NULL;
0072:            }
0073:
0074:            /**
0075:             * Creates a string (php5) literal expression.
0076:             */
0077:            public Expr createString(String lexeme) {
0078:                return new StringLiteralExpr(lexeme);
0079:            }
0080:
0081:            /**
0082:             * Creates a string literal expression.
0083:             */
0084:            public Expr createUnicode(String lexeme) {
0085:                return new UnicodeLiteralExpr(lexeme);
0086:            }
0087:
0088:            /**
0089:             * Creates a binary literal expression.
0090:             */
0091:            public Expr createBinary(byte[] bytes) {
0092:                return new BinaryLiteralExpr(bytes);
0093:            }
0094:
0095:            /**
0096:             * Creates a binary literal expression.
0097:             */
0098:            public Expr createBinary(String bytes, String encoding) {
0099:                return new BinaryLiteralExpr(bytes, encoding);
0100:            }
0101:
0102:            /**
0103:             * Creates a long literal expression.
0104:             */
0105:            public Expr createLong(long value) {
0106:                return new LongLiteralExpr(value);
0107:            }
0108:
0109:            /**
0110:             * Creates a string literal expression.
0111:             */
0112:            public Expr createLiteral(Value literal) {
0113:                return new LiteralExpr(literal);
0114:            }
0115:
0116:            /**
0117:             * Creates a var expression.
0118:             */
0119:            public VarExpr createVar(VarInfo var) {
0120:                return new VarExpr(var);
0121:            }
0122:
0123:            /**
0124:             * Creates a var expression.
0125:             */
0126:            public VarVarExpr createVarVar(Expr var) {
0127:                return new VarVarExpr(var);
0128:            }
0129:
0130:            /**
0131:             * Creates a const expression.
0132:             */
0133:            public ConstExpr createConst(String name) {
0134:                return new ConstExpr(name);
0135:            }
0136:
0137:            /**
0138:             * Creates a class const expression.
0139:             */
0140:            public ClassConstExpr createClassConst(String className, String name) {
0141:                return new ClassConstExpr(className, name);
0142:            }
0143:
0144:            /**
0145:             * Creates a this expression.
0146:             */
0147:            public ThisExpr createThis(Location location, InterpretedClassDef cl) {
0148:                return new ThisExpr(location, cl);
0149:            }
0150:
0151:            /**
0152:             * Creates an array get 'a[0]' expression.
0153:             * @param location
0154:             */
0155:            public ArrayGetExpr createArrayGet(Location location, Expr base,
0156:                    Expr index) {
0157:                return new ArrayGetExpr(location, base, index);
0158:            }
0159:
0160:            /**
0161:             * Creates an array tail 'a[]' expression.
0162:             * @param location TODO
0163:             */
0164:            public ArrayTailExpr createArrayTail(Location location, Expr base) {
0165:                return new ArrayTailExpr(location, base);
0166:            }
0167:
0168:            /**
0169:             * Creates an object get '$a->b' expression.
0170:             */
0171:            public Expr createFieldGet(Location location, Expr base,
0172:                    StringValue name) {
0173:                return new FieldGetExpr(location, base, name);
0174:            }
0175:
0176:            /**
0177:             * Creates an object get '$a->$b' expression.
0178:             */
0179:            public Expr createFieldVarGet(Location location, Expr base,
0180:                    Expr name) {
0181:                return new FieldVarGetExpr(location, base, name);
0182:            }
0183:
0184:            /**
0185:             * Creates an object get 'a::b' expression.
0186:             */
0187:            public Expr createStaticFieldGet(Location location,
0188:                    String className, String name) {
0189:                return new StaticFieldGetExpr(location, className, name);
0190:            }
0191:
0192:            /**
0193:             * Creates an unset '$a' expression.
0194:             */
0195:            public Expr createUnsetVar(AbstractVarExpr var) {
0196:                return new UnsetVarExpr(var);
0197:            }
0198:
0199:            /**
0200:             * Creates a char at 'a{0}' expression.
0201:             */
0202:            public CharAtExpr createCharAt(Expr base, Expr index) {
0203:                return new CharAtExpr(base, index);
0204:            }
0205:
0206:            /**
0207:             * Creates a post increment 'a++' expression.
0208:             */
0209:            public PostIncrementExpr createPostIncrement(Expr expr, int incr) {
0210:                return new PostIncrementExpr(expr, incr);
0211:            }
0212:
0213:            /**
0214:             * Creates a pre increment '++a' expression.
0215:             */
0216:            public PreIncrementExpr createPreIncrement(Expr expr, int incr) {
0217:                return new PreIncrementExpr(expr, incr);
0218:            }
0219:
0220:            /**
0221:             * Creates a unary minus '-a' expression.
0222:             */
0223:            public Expr createMinus(Expr expr) {
0224:                return new MinusExpr(expr);
0225:            }
0226:
0227:            /**
0228:             * Creates a unary plus '+a' expression.
0229:             */
0230:            public Expr createPlus(Expr expr) {
0231:                return new PlusExpr(expr);
0232:            }
0233:
0234:            /**
0235:             * Creates a unary not '!a' expression.
0236:             */
0237:            public Expr createNot(Expr expr) {
0238:                return new NotExpr(expr);
0239:            }
0240:
0241:            /**
0242:             * Creates a unary inversion '~a' expression.
0243:             */
0244:            public Expr createBitNot(Expr expr) {
0245:                return new BitNotExpr(expr);
0246:            }
0247:
0248:            /**
0249:             * Creates a clone 'clone a' expression.
0250:             */
0251:            public Expr createClone(Expr expr) {
0252:                return new CloneExpr(expr);
0253:            }
0254:
0255:            /**
0256:             * Creates a clone 'clone a' expression.
0257:             */
0258:            public Expr createCopy(Expr expr) {
0259:                return new CopyExpr(expr);
0260:            }
0261:
0262:            /**
0263:             * Creates an error suppression '@a' expression.
0264:             */
0265:            public Expr createSuppress(Expr expr) {
0266:                return new SuppressErrorExpr(expr);
0267:            }
0268:
0269:            /**
0270:             * Creates a boolean cast
0271:             */
0272:            public Expr createToBoolean(Expr expr) {
0273:                return new ToBooleanExpr(expr);
0274:            }
0275:
0276:            /**
0277:             * Creates a long cast
0278:             */
0279:            public Expr createToLong(Expr expr) {
0280:                return new ToLongExpr(expr);
0281:            }
0282:
0283:            /**
0284:             * Creates a double cast
0285:             */
0286:            public Expr createToDouble(Expr expr) {
0287:                return new ToDoubleExpr(expr);
0288:            }
0289:
0290:            /**
0291:             * Creates a string cast
0292:             */
0293:            public Expr createToString(Expr expr) {
0294:                return new ToStringExpr(expr);
0295:            }
0296:
0297:            /**
0298:             * Creates a unicode cast
0299:             */
0300:            public Expr createToUnicode(Expr expr) {
0301:                return new ToUnicodeExpr(expr);
0302:            }
0303:
0304:            /**
0305:             * Creates a binary string cast
0306:             */
0307:            public Expr createToBinary(Expr expr) {
0308:                return new ToBinaryExpr(expr);
0309:            }
0310:
0311:            /**
0312:             * Creates an object cast
0313:             */
0314:            public Expr createToObject(Expr expr) {
0315:                return new ToObjectExpr(expr);
0316:            }
0317:
0318:            /**
0319:             * Creates an array cast
0320:             */
0321:            public Expr createToArray(Expr expr) {
0322:                return new ToArrayExpr(expr);
0323:            }
0324:
0325:            /**
0326:             * Creates a die 'die("msg")' expression.
0327:             */
0328:            public Expr createDie(Expr expr) {
0329:                return new DieExpr(expr);
0330:            }
0331:
0332:            /**
0333:             * Creates an exit 'exit("msg")' expression.
0334:             */
0335:            public Expr createExit(Expr expr) {
0336:                return new ExitExpr(expr);
0337:            }
0338:
0339:            /**
0340:             * Creates a required
0341:             */
0342:            public Expr createRequired() {
0343:                return new RequiredExpr();
0344:            }
0345:
0346:            /**
0347:             * Creates a default
0348:             */
0349:            public Expr createDefault() {
0350:                return new DefaultExpr();
0351:            }
0352:
0353:            /**
0354:             * Creates an addition expression.
0355:             */
0356:            public Expr createAdd(Expr left, Expr right) {
0357:                return new AddExpr(left, right);
0358:            }
0359:
0360:            /**
0361:             * Creates a subtraction expression.
0362:             */
0363:            public Expr createSub(Expr left, Expr right) {
0364:                return new SubExpr(left, right);
0365:            }
0366:
0367:            /**
0368:             * Creates a multiplication expression.
0369:             */
0370:            public Expr createMul(Expr left, Expr right) {
0371:                return new MulExpr(left, right);
0372:            }
0373:
0374:            /**
0375:             * Creates a division expression.
0376:             */
0377:            public Expr createDiv(Expr left, Expr right) {
0378:                return new DivExpr(left, right);
0379:            }
0380:
0381:            /**
0382:             * Creates a modulo expression.
0383:             */
0384:            public Expr createMod(Expr left, Expr right) {
0385:                return new ModExpr(left, right);
0386:            }
0387:
0388:            /**
0389:             * Creates a left-shift expression.
0390:             */
0391:            public Expr createLeftShift(Expr left, Expr right) {
0392:                return new LeftShiftExpr(left, right);
0393:            }
0394:
0395:            /**
0396:             * Creates a right-shift expression.
0397:             */
0398:            public Expr createRightShift(Expr left, Expr right) {
0399:                return new RightShiftExpr(left, right);
0400:            }
0401:
0402:            /**
0403:             * Creates a bit-and expression.
0404:             */
0405:            public Expr createBitAnd(Expr left, Expr right) {
0406:                return new BitAndExpr(left, right);
0407:            }
0408:
0409:            /**
0410:             * Creates a bit-or expression.
0411:             */
0412:            public Expr createBitOr(Expr left, Expr right) {
0413:                return new BitOrExpr(left, right);
0414:            }
0415:
0416:            /**
0417:             * Creates a bit-xor expression.
0418:             */
0419:            public Expr createBitXor(Expr left, Expr right) {
0420:                return new BitXorExpr(left, right);
0421:            }
0422:
0423:            /**
0424:             * Creates an append expression
0425:             */
0426:            public final Expr createAppend(Expr left, Expr right) {
0427:                AppendExpr leftAppend;
0428:
0429:                // XXX: i18n binary vs unicode issues
0430:                /*
0431:                if (left instanceof ToStringExpr)
0432:                  left = ((ToStringExpr) left).getExpr();
0433:
0434:                if (left instanceof StringLiteralExpr) {
0435:                  StringLiteralExpr string = (StringLiteralExpr) left;
0436:
0437:                  if (string.evalConstant().length() == 0)
0438:                return ToStringExpr.create(right);
0439:                }
0440:                 */
0441:
0442:                if (left instanceof  AppendExpr)
0443:                    leftAppend = (AppendExpr) left;
0444:                else
0445:                    leftAppend = createAppendImpl(left, null);
0446:
0447:                AppendExpr next;
0448:
0449:                /*
0450:                if (right instanceof ToStringExpr)
0451:                  right = ((ToStringExpr) right).getExpr();
0452:
0453:                if (right instanceof StringLiteralExpr) {
0454:                  StringLiteralExpr string = (StringLiteralExpr) right;
0455:
0456:                  if (string.evalConstant().length() == 0)
0457:                return ToStringExpr.create(left);
0458:                }
0459:                 */
0460:
0461:                if (right instanceof  AppendExpr)
0462:                    next = (AppendExpr) right;
0463:                else
0464:                    next = createAppendImpl(right, null);
0465:
0466:                AppendExpr result = append(leftAppend, next);
0467:
0468:                if (result.getNext() != null)
0469:                    return result;
0470:                else
0471:                    return result.getValue();
0472:            }
0473:
0474:            /**
0475:             * Appends the tail to the current expression, combining
0476:             * constant literals.
0477:             */
0478:            private AppendExpr append(AppendExpr left, AppendExpr tail) {
0479:                if (left == null)
0480:                    return tail;
0481:
0482:                tail = append(left.getNext(), tail);
0483:
0484:                if (left.getValue() instanceof  BinaryLiteralExpr
0485:                        && tail.getValue() instanceof  BinaryLiteralExpr) {
0486:                    BinaryLiteralExpr leftString = (BinaryLiteralExpr) left
0487:                            .getValue();
0488:                    BinaryLiteralExpr rightString = (BinaryLiteralExpr) tail
0489:                            .getValue();
0490:
0491:                    try {
0492:                        byte[] bytes = (leftString.evalConstant().toString() + rightString
0493:                                .evalConstant().toString())
0494:                                .getBytes("ISO-8859-1");
0495:
0496:                        Expr value = createBinary(bytes);
0497:
0498:                        return createAppendImpl(value, tail.getNext());
0499:                    } catch (java.io.UnsupportedEncodingException e) {
0500:                        throw new RuntimeException(e);
0501:                    }
0502:                } else if (left.getValue() instanceof  BinaryLiteralExpr
0503:                        || tail.getValue() instanceof  BinaryLiteralExpr) {
0504:                    left.setNext(tail);
0505:
0506:                    return left;
0507:                } else if (left.getValue() instanceof  StringLiteralExpr
0508:                        && tail.getValue() instanceof  StringLiteralExpr) {
0509:                    StringLiteralExpr leftString = (StringLiteralExpr) left
0510:                            .getValue();
0511:                    StringLiteralExpr rightString = (StringLiteralExpr) tail
0512:                            .getValue();
0513:
0514:                    Expr value = createString(leftString.evalConstant()
0515:                            .toString()
0516:                            + rightString.evalConstant().toString());
0517:
0518:                    return createAppendImpl(value, tail.getNext());
0519:                } else if (left.getValue() instanceof  UnicodeLiteralExpr
0520:                        && tail.getValue() instanceof  UnicodeLiteralExpr) {
0521:                    UnicodeLiteralExpr leftString = (UnicodeLiteralExpr) left
0522:                            .getValue();
0523:                    UnicodeLiteralExpr rightString = (UnicodeLiteralExpr) tail
0524:                            .getValue();
0525:
0526:                    Expr value = createUnicode(leftString.evalConstant()
0527:                            .toString()
0528:                            + rightString.evalConstant().toString());
0529:
0530:                    return createAppendImpl(value, tail.getNext());
0531:                } else {
0532:                    left.setNext(tail);
0533:
0534:                    return left;
0535:                }
0536:            }
0537:
0538:            protected AppendExpr createAppendImpl(Expr left, AppendExpr right) {
0539:                return new AppendExpr(left, right);
0540:            }
0541:
0542:            /**
0543:             * Creates a lt expression.
0544:             */
0545:            public Expr createLt(Expr left, Expr right) {
0546:                return new LtExpr(left, right);
0547:            }
0548:
0549:            /**
0550:             * Creates a leq expression.
0551:             */
0552:            public Expr createLeq(Expr left, Expr right) {
0553:                return new LeqExpr(left, right);
0554:            }
0555:
0556:            /**
0557:             * Creates a gt expression.
0558:             */
0559:            public Expr createGt(Expr left, Expr right) {
0560:                return new GtExpr(left, right);
0561:            }
0562:
0563:            /**
0564:             * Creates a geq expression.
0565:             */
0566:            public Expr createGeq(Expr left, Expr right) {
0567:                return new GeqExpr(left, right);
0568:            }
0569:
0570:            /**
0571:             * Creates an eq expression.
0572:             */
0573:            public Expr createEq(Expr left, Expr right) {
0574:                return new EqExpr(left, right);
0575:            }
0576:
0577:            /**
0578:             * Creates a neq expression.
0579:             */
0580:            public Expr createNeq(Expr left, Expr right) {
0581:                return new NeqExpr(left, right);
0582:            }
0583:
0584:            /**
0585:             * Creates an equals expression.
0586:             */
0587:            public Expr createEquals(Expr left, Expr right) {
0588:                return new EqualsExpr(left, right);
0589:            }
0590:
0591:            /**
0592:             * Creates an assignment expression.
0593:             */
0594:            public Expr createAssign(AbstractVarExpr left, Expr right) {
0595:                return new AssignExpr(left, right);
0596:            }
0597:
0598:            /**
0599:             * Creates an assignment expression.
0600:             */
0601:            public Expr createAssignRef(AbstractVarExpr left, Expr right) {
0602:                return new AssignRefExpr(left, right);
0603:            }
0604:
0605:            /**
0606:             * Creates a ref '&$a' expression.
0607:             */
0608:            public RefExpr createRef(Expr base) {
0609:                return new RefExpr(base);
0610:            }
0611:
0612:            /**
0613:             * Creates an and expression.
0614:             */
0615:            public Expr createAnd(Expr left, Expr right) {
0616:                return new AndExpr(left, right);
0617:            }
0618:
0619:            /**
0620:             * Creates an or expression.
0621:             */
0622:            public Expr createOr(Expr left, Expr right) {
0623:                return new OrExpr(left, right);
0624:            }
0625:
0626:            /**
0627:             * Creates an xor expression.
0628:             */
0629:            public Expr createXor(Expr left, Expr right) {
0630:                return new XorExpr(left, right);
0631:            }
0632:
0633:            /**
0634:             * Creates a comma expression.
0635:             */
0636:            public Expr createComma(Expr left, Expr right) {
0637:                return new CommaExpr(left, right);
0638:            }
0639:
0640:            /**
0641:             * Creates an instanceof expression.
0642:             */
0643:            public Expr createInstanceOf(Expr expr, String name) {
0644:                return new InstanceOfExpr(expr, name);
0645:            }
0646:
0647:            /**
0648:             * Creates an instanceof expression.
0649:             */
0650:            public Expr createInstanceOfVar(Expr expr, Expr name) {
0651:                return new InstanceOfVarExpr(expr, name);
0652:            }
0653:
0654:            /**
0655:             * Creates an each expression.
0656:             */
0657:            public Expr createEach(Expr expr) {
0658:                return new EachExpr(expr);
0659:            }
0660:
0661:            /**
0662:             * Creates a list expression.
0663:             */
0664:            public final Expr createList(QuercusParser parser,
0665:                    ListHeadExpr head, Expr value) {
0666:                boolean isSuppress = value instanceof  SuppressErrorExpr;
0667:
0668:                if (isSuppress) {
0669:                    SuppressErrorExpr suppressExpr = (SuppressErrorExpr) value;
0670:
0671:                    value = suppressExpr.getExpr();
0672:                }
0673:
0674:                Expr expr;
0675:
0676:                if (value instanceof  EachExpr) {
0677:                    expr = createListEach(head.getVarList(), (EachExpr) value);
0678:                } else
0679:                    expr = createList(head, value);
0680:
0681:                if (isSuppress)
0682:                    return createSuppress(expr);
0683:                else
0684:                    return expr;
0685:            }
0686:
0687:            /**
0688:             * Creates a list expression.
0689:             */
0690:            public ListHeadExpr createListHead(ArrayList<Expr> keys) {
0691:                return new ListHeadExpr(keys);
0692:            }
0693:
0694:            /**
0695:             * Creates a list expression.
0696:             */
0697:            public Expr createList(ListHeadExpr head, Expr value) {
0698:                return new ListExpr(head, value);
0699:            }
0700:
0701:            /**
0702:             * Creates a list expression.
0703:             */
0704:            public Expr createListEach(Expr[] varList, EachExpr value) {
0705:                return new ListEachExpr(varList, value);
0706:            }
0707:
0708:            /**
0709:             * Creates an conditional expression.
0710:             */
0711:            public Expr createConditional(Expr test, Expr left, Expr right) {
0712:                return new ConditionalExpr(test, left, right);
0713:            }
0714:
0715:            /**
0716:             * Creates a array() expression.
0717:             */
0718:            public Expr createArrayFun(ArrayList<Expr> keys,
0719:                    ArrayList<Expr> values) {
0720:                return new ArrayFunExpr(keys, values);
0721:            }
0722:
0723:            /**
0724:             * Creates a new function call.
0725:             */
0726:            public Expr createFunction(Location loc, String name,
0727:                    ArrayList<Expr> args) {
0728:                return new FunctionExpr(loc, name, args);
0729:            }
0730:
0731:            /**
0732:             * Creates a new var function call.
0733:             */
0734:            public VarFunctionExpr createVarFunction(Location loc, Expr name,
0735:                    ArrayList<Expr> args) {
0736:                return new VarFunctionExpr(loc, name, args);
0737:            }
0738:
0739:            /**
0740:             * Creates a new function call.
0741:             */
0742:            public Expr createClassMethod(Location loc, String className,
0743:                    String name, ArrayList<Expr> args) {
0744:                return new ClassMethodExpr(loc, className, name, args);
0745:            }
0746:
0747:            /**
0748:             * Creates a new function call.
0749:             */
0750:            public Expr createStaticMethod(Location loc, String className,
0751:                    String name, ArrayList<Expr> args) {
0752:                return new StaticMethodExpr(loc, className, name, args);
0753:            }
0754:
0755:            /**
0756:             * Creates a new method A::$f()
0757:             */
0758:            public Expr createStaticVarMethod(Location loc, String className,
0759:                    Expr var, ArrayList<Expr> args) {
0760:                return new StaticVarMethodExpr(loc, className, var, args);
0761:            }
0762:
0763:            /**
0764:             * Creates a new method call.
0765:             */
0766:            public Expr createMethodCall(Location loc, Expr objExpr,
0767:                    String name, ArrayList<Expr> args) {
0768:                return new MethodCallExpr(loc, objExpr, name, args);
0769:            }
0770:
0771:            /**
0772:             * Creates a new method call.
0773:             */
0774:            public Expr createVarMethodCall(Location loc, Expr objExpr,
0775:                    Expr name, ArrayList<Expr> args) {
0776:                return new VarMethodCallExpr(loc, objExpr, name, args);
0777:            }
0778:
0779:            /**
0780:             * Creates a new function call.
0781:             */
0782:            public NewExpr createNew(Location loc, String name,
0783:                    ArrayList<Expr> args) {
0784:                return new NewExpr(loc, name, args);
0785:            }
0786:
0787:            /**
0788:             * Creates a new function call.
0789:             */
0790:            public VarNewExpr createVarNew(Location loc, Expr name,
0791:                    ArrayList<Expr> args) {
0792:                return new VarNewExpr(loc, name, args);
0793:            }
0794:
0795:            /**
0796:             * Creates an include expr
0797:             */
0798:            public Expr createInclude(Location loc, Path source, Expr expr) {
0799:                return new IncludeExpr(loc, source, expr, false);
0800:            }
0801:
0802:            /**
0803:             * Creates an include expr
0804:             */
0805:            public Expr createRequire(Location loc, Path source, Expr expr) {
0806:                return new IncludeExpr(loc, source, expr, true);
0807:            }
0808:
0809:            /**
0810:             * Creates an include expr
0811:             */
0812:            public Expr createIncludeOnce(Location loc, Path source, Expr expr) {
0813:                return new IncludeOnceExpr(loc, source, expr, false);
0814:            }
0815:
0816:            /**
0817:             * Creates an include expr
0818:             */
0819:            public Expr createRequireOnce(Location loc, Path source, Expr expr) {
0820:                return new IncludeOnceExpr(loc, source, expr, true);
0821:            }
0822:
0823:            /**
0824:             * Creates a Quercus class import.
0825:             */
0826:            public Expr createImport(Location loc, String name,
0827:                    boolean isWildcard) {
0828:                return new ImportExpr(loc, name, isWildcard);
0829:            }
0830:
0831:            /**
0832:             * Creates a null literal expression.
0833:             */
0834:            public Statement createNullStatement() {
0835:                return NullStatement.NULL;
0836:            }
0837:
0838:            /**
0839:             * Creates an echo statement
0840:             */
0841:            public Statement createEcho(Location loc, Expr expr) {
0842:                return new EchoStatement(loc, expr);
0843:            }
0844:
0845:            /**
0846:             * Creates an expr statement
0847:             */
0848:            public Statement createExpr(Location loc, Expr expr) {
0849:                return new ExprStatement(loc, expr);
0850:            }
0851:
0852:            public final Statement createBlock(Location loc,
0853:                    ArrayList<Statement> statementList) {
0854:                if (statementList.size() == 1)
0855:                    return statementList.get(0);
0856:
0857:                Statement[] statements = new Statement[statementList.size()];
0858:
0859:                statementList.toArray(statements);
0860:
0861:                return createBlockImpl(loc, statements);
0862:            }
0863:
0864:            public final Statement createBlock(Location loc,
0865:                    Statement[] statementList) {
0866:                if (statementList.length == 1)
0867:                    return statementList[0];
0868:
0869:                Statement[] statements = new Statement[statementList.length];
0870:
0871:                System.arraycopy(statementList, 0, statements, 0,
0872:                        statementList.length);
0873:
0874:                return createBlockImpl(loc, statements);
0875:            }
0876:
0877:            /**
0878:             * Creates an expr statement
0879:             */
0880:            public final BlockStatement createBlockImpl(Location loc,
0881:                    ArrayList<Statement> statementList) {
0882:                Statement[] statements = new Statement[statementList.size()];
0883:
0884:                statementList.toArray(statements);
0885:
0886:                return createBlockImpl(loc, statements);
0887:            }
0888:
0889:            /**
0890:             * Creates an expr statement
0891:             */
0892:            public BlockStatement createBlockImpl(Location loc,
0893:                    Statement[] statements) {
0894:                return new BlockStatement(loc, statements);
0895:            }
0896:
0897:            /**
0898:             * Creates a text statement
0899:             */
0900:            public Statement createText(Location loc, String text) {
0901:                return new TextStatement(loc, text);
0902:            }
0903:
0904:            /**
0905:             * Creates an if statement
0906:             */
0907:            public Statement createIf(Location loc, Expr test,
0908:                    Statement trueBlock, Statement falseBlock) {
0909:                return new IfStatement(loc, test, trueBlock, falseBlock);
0910:            }
0911:
0912:            /**
0913:             * Creates a switch statement
0914:             */
0915:            public Statement createSwitch(Location loc, Expr value,
0916:                    ArrayList<Expr[]> caseList,
0917:                    ArrayList<BlockStatement> blockList, Statement defaultBlock) {
0918:                return new SwitchStatement(loc, value, caseList, blockList,
0919:                        defaultBlock);
0920:            }
0921:
0922:            /**
0923:             * Creates a for statement
0924:             */
0925:            public Statement createFor(Location loc, Expr init, Expr test,
0926:                    Expr incr, Statement block) {
0927:                return new ForStatement(loc, init, test, incr, block);
0928:            }
0929:
0930:            /**
0931:             * Creates a foreach statement
0932:             */
0933:            public Statement createForeach(Location loc, Expr objExpr,
0934:                    AbstractVarExpr key, AbstractVarExpr value, boolean isRef,
0935:                    Statement block) {
0936:                return new ForeachStatement(loc, objExpr, key, value, isRef,
0937:                        block);
0938:            }
0939:
0940:            /**
0941:             * Creates a while statement
0942:             */
0943:            public Statement createWhile(Location loc, Expr test,
0944:                    Statement block) {
0945:                return new WhileStatement(loc, test, block);
0946:            }
0947:
0948:            /**
0949:             * Creates a do-while statement
0950:             */
0951:            public Statement createDo(Location loc, Expr test, Statement block) {
0952:                return new DoStatement(loc, test, block);
0953:            }
0954:
0955:            /**
0956:             * Creates a break statement
0957:             */
0958:            public BreakStatement createBreak() {
0959:                return BreakStatement.BREAK;
0960:            }
0961:
0962:            /**
0963:             * Creates a continue statement
0964:             */
0965:            public ContinueStatement createContinue() {
0966:                return ContinueStatement.CONTINUE;
0967:            }
0968:
0969:            /**
0970:             * Creates a global statement
0971:             */
0972:            public Statement createGlobal(Location loc, VarExpr var) {
0973:                return new GlobalStatement(loc, var);
0974:            }
0975:
0976:            /**
0977:             * Creates a global var statement
0978:             */
0979:            public Statement createVarGlobal(Location loc, VarVarExpr var) {
0980:                return new VarGlobalStatement(loc, var);
0981:            }
0982:
0983:            /**
0984:             * Creates a static statement
0985:             */
0986:            public Statement createStatic(Location loc, VarExpr var, Expr value) {
0987:                return new StaticStatement(loc, var, value);
0988:            }
0989:
0990:            /**
0991:             * Creates a throw statement
0992:             */
0993:            public Statement createThrow(Location loc, Expr value) {
0994:                return new ThrowStatement(loc, value);
0995:            }
0996:
0997:            /**
0998:             * Creates a try statement
0999:             */
1000:            public TryStatement createTry(Location loc, Statement block) {
1001:                return new TryStatement(loc, block);
1002:            }
1003:
1004:            /**
1005:             * Creates a return statement
1006:             */
1007:            public Statement createReturn(Location loc, Expr value) {
1008:                return new ReturnStatement(loc, value);
1009:            }
1010:
1011:            /**
1012:             * Creates a return ref statement
1013:             */
1014:            public Statement createReturnRef(Location loc, Expr value) {
1015:                return new ReturnRefStatement(loc, value);
1016:            }
1017:
1018:            /**
1019:             * Creates a new function definition def.
1020:             */
1021:            public Statement createFunctionDef(Location loc, Function fun) {
1022:                return new FunctionDefStatement(loc, fun);
1023:            }
1024:
1025:            /**
1026:             * Creates a new function def statement
1027:             */
1028:            public Statement createClassDef(Location loc, InterpretedClassDef cl) {
1029:                return new ClassDefStatement(loc, cl);
1030:            }
1031:
1032:            /**
1033:             * Creates a new function definition.
1034:             */
1035:            public Function createFunction(Location loc, String name,
1036:                    FunctionInfo info, ArrayList<Arg> argList,
1037:                    ArrayList<Statement> statementList) {
1038:                return new Function(this , loc, name, info, argList,
1039:                        statementList);
1040:            }
1041:
1042:            /**
1043:             * Creates a new object method definition.
1044:             */
1045:            public Function createObjectMethod(Location loc,
1046:                    InterpretedClassDef cl, String name, FunctionInfo info,
1047:                    ArrayList<Arg> argList, ArrayList<Statement> statementList) {
1048:                return new ObjectMethod(this , loc, cl, name, info, argList,
1049:                        statementList);
1050:            }
1051:
1052:            /**
1053:             * Creates a new object method definition.
1054:             */
1055:            public Function createMethodDeclaration(Location loc,
1056:                    InterpretedClassDef cl, String name, FunctionInfo info,
1057:                    ArrayList<Arg> argList) {
1058:                return new MethodDeclaration(this , loc, cl, name, info, argList);
1059:            }
1060:
1061:            public InterpretedClassDef createClassDef(Location location,
1062:                    String name, String parentName, String[] ifaceList) {
1063:                return new InterpretedClassDef(location, name, parentName,
1064:                        ifaceList);
1065:            }
1066:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.