001: /*
002: * Copyright (c) 1998-2006 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: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.es.parser;
030:
031: import com.caucho.es.ESException;
032:
033: import java.io.IOException;
034:
035: /**
036: * FieldExpr is an intermediate form representing a field reference.
037: *
038: * <p>In JavaScript, foo.bar and foo["bar"] are equivalent.
039: */
040: class FieldExpr extends Expr {
041: Expr lhs;
042: Expr field;
043:
044: FieldExpr(Block block, Expr lhs, Expr field) {
045: super (block);
046:
047: this .lhs = lhs;
048: this .field = field;
049:
050: if (lhs != null)
051: lhs.setUsed();
052: if (field != null)
053: field.setUsed();
054: }
055:
056: /**
057: * Returns the base expression of the field. For foo.bar it returns foo.
058: */
059: Expr getExpr() {
060: return lhs;
061: }
062:
063: /**
064: * Returns the field reference.
065: */
066: Expr getField() {
067: return field;
068: }
069:
070: /**
071: * Type is always ES.
072: */
073: int getType() {
074: return TYPE_ES;
075: }
076:
077: Expr assign(Expr value) throws ESException {
078: return new AssignExpr(block, lhs, field, value);
079: }
080:
081: Expr delete() {
082: return new DeleteExpr(block, lhs, field);
083: }
084:
085: Expr prefix(int op) {
086: if (op == '+')
087: return new PostfixExpr(block, PostfixExpr.PREINC, this );
088: else
089: return new PostfixExpr(block, PostfixExpr.PREDEC, this );
090: }
091:
092: Expr postfix(int op) {
093: if (op == '+')
094: return new PostfixExpr(block, PostfixExpr.POSTINC, this );
095: else
096: return new PostfixExpr(block, PostfixExpr.POSTDEC, this );
097: }
098:
099: CallExpr startCall() throws ESException {
100: return new CallExpr(block, lhs, field, false);
101: }
102:
103: CallExpr startNew() throws ESException {
104: return new CallExpr(block, lhs, field, true);
105: }
106:
107: void printImpl() throws IOException {
108: lhs.print();
109: cl.print(".getProperty(");
110: field.printStr();
111: cl.print(")");
112: }
113: }
|