1 29 30 package com.caucho.quercus.expr; 31 32 import com.caucho.quercus.Location; 33 import com.caucho.quercus.env.Env; 34 import com.caucho.quercus.env.NullValue; 35 import com.caucho.quercus.env.QuercusClass; 36 import com.caucho.quercus.env.Value; 37 import com.caucho.util.L10N; 38 39 import java.util.ArrayList ; 40 41 44 public class NewExpr extends Expr { 45 private static final L10N L = new L10N(NewExpr.class); 46 protected final String _name; 47 protected final Expr []_args; 48 49 public NewExpr(Location location, String name, ArrayList <Expr> args) 50 { 51 super(location); 52 _name = name.intern(); 53 54 _args = new Expr[args.size()]; 55 args.toArray(_args); 56 } 57 58 public NewExpr(Location location, String name, Expr []args) 59 { 60 super(location); 61 _name = name.intern(); 62 _args = args; 63 } 64 65 public NewExpr(String name, ArrayList <Expr> args) 66 { 67 this(Location.UNKNOWN, name, args); 68 } 69 70 public NewExpr(String name, Expr []args) 71 { 72 this(Location.UNKNOWN, name, args); 73 } 74 75 82 public Value eval(Env env) 83 { 84 QuercusClass cl = env.findAbstractClass(_name); 85 86 if (cl == null) { 87 throw env.errorException(L.l("no matching class {0}", _name)); 88 } 89 90 91 Value []args = new Value[_args.length]; 92 93 for (int i = 0; i < args.length; i++) 94 args[i] = _args[i].eval(env); 95 96 env.pushCall(this, NullValue.NULL); 97 try { 98 env.checkTimeout(); 99 100 return cl.callNew(env, args); 101 } finally { 102 env.popCall(); 103 } 104 } 105 106 public String toString() 107 { 108 return _name + "()"; 109 } 110 } 111 112 | Popular Tags |