KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > es > parser > DeleteExpr


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.es.parser;
30
31 import com.caucho.es.ESException;
32 import com.caucho.es.ESId;
33
34 import java.io.IOException JavaDoc;
35
36 /**
37  * Expr is an intermediate form representing an expression.
38  */

39 class DeleteExpr extends Expr {
40   private Expr lhs;
41   private IdExpr var;
42   private ESId id;
43   private Expr field;
44   private boolean isTop;
45
46   DeleteExpr(Block block, IdExpr var)
47   {
48     super(block);
49     
50     this.var = var;
51     var.setUsed();
52   }
53
54   DeleteExpr(Block block, Expr lhs, ESId id)
55   {
56     super(block);
57     
58     this.lhs = lhs;
59     this.id = id;
60
61     if (lhs != null)
62       lhs.setUsed();
63   }
64
65   DeleteExpr(Block block, Expr lhs, Expr field)
66   {
67     super(block);
68     
69     this.lhs = lhs;
70     this.field = field;
71     
72     if (lhs != null)
73       lhs.setUsed();
74     if (field != null)
75       field.setUsed();
76   }
77
78   void exprStatement(Function fun) throws ESException
79   {
80     isTop = true;
81
82     fun.addExpr(this);
83   }
84
85   /**
86    * The assignment operator
87    */

88   void print()
89     throws IOException JavaDoc
90   {
91     if (var != null && var.isLocal()) {
92       if (! isTop)
93         cl.print("ESBoolean.FALSE");
94     }
95     else if (var != null) {
96       if (function.isGlobalScope())
97         cl.print("_env.global.delete(");
98       else
99         cl.print("_env.deleteScopeProperty(");
100       printLiteral(var.getId());
101       cl.print(")");
102       if (isTop)
103         cl.println(";");
104     }
105     else if (id != null) {
106       lhs.print();
107       cl.print(".delete(");
108       printLiteral(id);
109       cl.print(")");
110       if (isTop)
111         cl.println(";");
112     } else {
113       lhs.print();
114       cl.print(".delete(");
115       field.printStr();
116       cl.print(")");
117       if (isTop)
118         cl.println(";");
119     }
120   }
121 }
122
Popular Tags