001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.quercus.expr;
031:
032: import com.caucho.quercus.Location;
033: import com.caucho.quercus.env.*;
034: import com.caucho.quercus.program.AbstractFunction;
035: import com.caucho.util.L10N;
036:
037: import java.util.ArrayList;
038:
039: /**
040: * Represents a PHP function expression.
041: */
042: public class VarMethodCallExpr extends Expr {
043: private static final L10N L = new L10N(VarMethodCallExpr.class);
044:
045: protected final Expr _objExpr;
046:
047: protected final Expr _name;
048: protected final Expr[] _args;
049:
050: protected Expr[] _fullArgs;
051:
052: private AbstractFunction _fun;
053:
054: public VarMethodCallExpr(Location location, Expr objExpr,
055: Expr name, ArrayList<Expr> args) {
056: super (location);
057: _objExpr = objExpr;
058:
059: _name = name;
060:
061: _args = new Expr[args.size()];
062: args.toArray(_args);
063: }
064:
065: public VarMethodCallExpr(Location location, Expr objExpr,
066: Expr name, Expr[] args) {
067: super (location);
068: _objExpr = objExpr;
069:
070: _name = name;
071:
072: _args = args;
073: }
074:
075: public VarMethodCallExpr(Expr objExpr, Expr name,
076: ArrayList<Expr> args) {
077: this (Location.UNKNOWN, objExpr, name, args);
078: }
079:
080: public VarMethodCallExpr(Expr objExpr, Expr name, Expr[] args) {
081: this (Location.UNKNOWN, objExpr, name, args);
082: }
083:
084: /**
085: * Evaluates the expression.
086: *
087: * @param env the calling environment.
088: *
089: * @return the expression value.
090: */
091: public Value eval(Env env) {
092: Value[] values = new Value[_args.length];
093:
094: for (int i = 0; i < values.length; i++) {
095: values[i] = _args[i].evalArg(env);
096: }
097:
098: StringValue methodName = _name.eval(env).toStringValue();
099:
100: Value obj = _objExpr.eval(env);
101:
102: env.pushCall(this , obj);
103:
104: try {
105: env.checkTimeout();
106:
107: return obj.callMethod(env, methodName, values);
108: } finally {
109: env.popCall();
110: }
111: }
112:
113: public String toString() {
114: return _objExpr + "->" + _name + "()";
115: }
116: }
|