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: import com.caucho.es.ESId;
033:
034: import java.io.IOException;
035:
036: /**
037: * Expr is an intermediate form representing an expression.
038: */
039: class DeleteExpr extends Expr {
040: private Expr lhs;
041: private IdExpr var;
042: private ESId id;
043: private Expr field;
044: private boolean isTop;
045:
046: DeleteExpr(Block block, IdExpr var) {
047: super (block);
048:
049: this .var = var;
050: var.setUsed();
051: }
052:
053: DeleteExpr(Block block, Expr lhs, ESId id) {
054: super (block);
055:
056: this .lhs = lhs;
057: this .id = id;
058:
059: if (lhs != null)
060: lhs.setUsed();
061: }
062:
063: DeleteExpr(Block block, Expr lhs, Expr field) {
064: super (block);
065:
066: this .lhs = lhs;
067: this .field = field;
068:
069: if (lhs != null)
070: lhs.setUsed();
071: if (field != null)
072: field.setUsed();
073: }
074:
075: void exprStatement(Function fun) throws ESException {
076: isTop = true;
077:
078: fun.addExpr(this );
079: }
080:
081: /**
082: * The assignment operator
083: */
084: void print() throws IOException {
085: if (var != null && var.isLocal()) {
086: if (!isTop)
087: cl.print("ESBoolean.FALSE");
088: } else if (var != null) {
089: if (function.isGlobalScope())
090: cl.print("_env.global.delete(");
091: else
092: cl.print("_env.deleteScopeProperty(");
093: printLiteral(var.getId());
094: cl.print(")");
095: if (isTop)
096: cl.println(";");
097: } else if (id != null) {
098: lhs.print();
099: cl.print(".delete(");
100: printLiteral(id);
101: cl.print(")");
102: if (isTop)
103: cl.println(";");
104: } else {
105: lhs.print();
106: cl.print(".delete(");
107: field.printStr();
108: cl.print(")");
109: if (isTop)
110: cl.println(";");
111: }
112: }
113: }
|