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.env;
031:
032: import java.io.Serializable;
033:
034: import com.caucho.quercus.Location;
035:
036: /**
037: * Represents an array-get argument which might be a call to a reference.
038: *
039: * foo($a[0]), where is not known if foo is defined as foo($a) or foo(&$a)
040: */
041: public class ArgGetValue extends Value implements Serializable {
042: private final Value _obj;
043: private final Value _index;
044:
045: public ArgGetValue(Value obj, Value index) {
046: _obj = obj;
047: _index = index;
048: }
049:
050: /**
051: * Returns the arg object for a field reference, e.g.
052: * foo($a[0][1])
053: */
054: public Value getArg(Value index) {
055: return new ArgGetValue(this , index); // php/3d1p
056: }
057:
058: /**
059: * Returns the arg object for a field reference, e.g.
060: * foo($a[0]->x)
061: */
062: public Value getFieldArg(Env env, StringValue index) {
063: return new ArgGetFieldValue(env, this , index); // php/3d2p
064: }
065:
066: /**
067: * Converts to a reference variable.
068: */
069: @Override
070: public Var toRefVar() {
071: // php/3d55, php/3d49, php/3921
072:
073: return _obj.getRef(_index).toRefVar();
074: }
075:
076: /**
077: * Converts to a reference variable.
078: */
079: @Override
080: public Value toRefValue() {
081: // php/3a57
082: return _obj.getRef(_index);
083: }
084:
085: /**
086: * Converts to a value.
087: */
088: @Override
089: public Value toValue() {
090: return _obj.get(_index);
091: }
092:
093: /**
094: * Converts to a read-only value.
095: */
096: @Override
097: public Value toArgValueReadOnly() {
098: return _obj.get(_index);
099: }
100:
101: /**
102: * Converts to a value.
103: */
104: @Override
105: public Value toArgValue() {
106: return toValue();
107: }
108:
109: /**
110: * Converts to a variable.
111: */
112: public Var toVar() {
113: // quercus/3d56
114: return new Var();
115: }
116:
117: /**
118: * Converts to a reference.
119: */
120: public Value getRef(Value index) {
121: // php/3d1p
122: return _obj.getArray(_index).getRef(index);
123: }
124:
125: /**
126: * Converts to a reference variable.
127: */
128: public Value getFieldObject(Env env, StringValue index) {
129: return _obj.getObject(env, _index).getFieldObject(env, index);
130: }
131:
132: /**
133: * Converts to a reference variable.
134: */
135: public Value getFieldRef(Env env, StringValue index) {
136: // php/3d2p
137: return _obj.getObject(env, _index).getFieldRef(env, index);
138: }
139:
140: //
141: // Java Serialization
142: //
143:
144: public Object writeReplace() {
145: return toValue();
146: }
147: }
|