KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
32
33 /**
34  * Expr is an intermediate form representing an expression.
35  */

36 class SpecialExpr extends Expr {
37   final static int THIS = 't';
38   final static int HAS_NEXT = 'm';
39   final static int NEXT = 'n';
40   final static int EXCEPTION = 'e';
41   final static int ARRAY = 'a';
42   
43   private int code;
44   private String JavaDoc str;
45   private Expr expr;
46
47   SpecialExpr(Block block, int code)
48   {
49     super(block);
50
51     if (code == THIS)
52       block.function.setThis();
53     this.code = code;
54   }
55
56   SpecialExpr(Block block, int code, String JavaDoc str)
57   {
58     super(block);
59     
60     this.code = code;
61     this.str = str;
62   }
63
64   SpecialExpr(Block block, int code, Expr expr)
65   {
66     super(block);
67     
68     this.code = code;
69     this.expr = expr;
70   }
71
72   int getType()
73   {
74     switch (code) {
75     case HAS_NEXT:
76       return TYPE_BOOLEAN;
77       
78     case THIS:
79     case NEXT:
80     case EXCEPTION:
81     case ARRAY:
82       return TYPE_ES;
83       
84     default:
85       throw new RuntimeException JavaDoc();
86     }
87   }
88
89   void printBooleanImpl() throws IOException JavaDoc
90   {
91     switch (code) {
92     case HAS_NEXT:
93       cl.print(str + ".hasNext()");
94       break;
95       
96     default:
97       throw new RuntimeException JavaDoc();
98     }
99   }
100
101   void printImpl() throws IOException JavaDoc
102   {
103     switch (code) {
104     case THIS:
105       cl.print("_this");
106       break;
107       
108     case NEXT:
109       cl.print("((ESBase) " + str + ".next())");
110       break;
111       
112     case EXCEPTION:
113       cl.print("_env.wrap(new ESWrapperException(" + str + "))");
114       break;
115       
116     case ARRAY:
117       cl.print("_env.array(");
118       expr.print();
119       cl.print(")");
120       break;
121       
122     default:
123       throw new RuntimeException JavaDoc();
124     }
125   }
126 }
127
128
Popular Tags