1 29 30 package com.caucho.quercus.expr; 31 32 import com.caucho.quercus.Location; 33 import com.caucho.quercus.QuercusException; 34 import com.caucho.quercus.env.Env; 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 VarNewExpr extends Expr { 45 private static final L10N L = new L10N(NewExpr.class); 46 47 protected final Expr _name; 48 protected final Expr []_args; 49 50 protected Expr []_fullArgs; 51 52 public VarNewExpr(Location location, Expr name, ArrayList <Expr> args) 53 { 54 super(location); 55 _name = name; 56 57 _args = new Expr[args.size()]; 58 args.toArray(_args); 59 } 60 61 public VarNewExpr(Location location, Expr name, Expr []args) 62 { 63 super(location); 64 _name = name; 65 _args = args; 66 } 67 68 public VarNewExpr(Expr name, ArrayList <Expr> args) 69 { 70 this(Location.UNKNOWN, name, args); 71 } 72 73 public VarNewExpr(Expr name, Expr []args) 74 { 75 this(Location.UNKNOWN, name, args); 76 } 77 78 85 public Value eval(Env env) 86 { 87 String name = _name.evalString(env).intern(); 88 89 QuercusClass cl = env.findClass(name); 90 91 if (cl == null) { 92 throw new QuercusException(L.l("no matching class {0}", name)); 93 } 94 95 _fullArgs = _args; 96 97 return cl.callNew(env, _args); 98 } 99 100 public String toString() 101 { 102 return _name + "()"; 103 } 104 } 105 106 | Popular Tags |