KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > expr > VarInfo


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  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.quercus.expr;
31
32 import com.caucho.quercus.program.FunctionInfo;
33
34 /**
35  * Information about a variable's use in a function.
36  */

37 public class VarInfo {
38   private final FunctionInfo _function;
39
40   private final String JavaDoc _name;
41   
42   private boolean _isGlobal;
43   private boolean _isArgument;
44   private boolean _isRefArgument;
45   private boolean _isAssigned;
46   
47   // true if the variable is a reference
48
private boolean _isReference;
49
50   // XXX: move to arg?
51
private int _argumentIndex;
52
53   public VarInfo(String JavaDoc name, FunctionInfo function)
54   {
55     _name = name.intern();
56     _function = function;
57
58     if (function != null && function.isPageMain()) {
59       _isReference = true;
60     }
61   }
62
63   /**
64    * Returns the variable name.
65    */

66   public String JavaDoc getName()
67   {
68     return _name;
69   }
70
71   /**
72    * Returns the owning function.
73    */

74   public FunctionInfo getFunction()
75   {
76     return _function;
77   }
78
79   /**
80    * True if the variable is global.
81    */

82   public boolean isGlobal()
83   {
84     return _isGlobal;
85   }
86
87   /**
88    * True if the variable is global.
89    */

90   public void setGlobal()
91   {
92     _isGlobal = true;
93   }
94
95   /**
96    * True if the variable is variable
97    */

98   public boolean isVariable()
99   {
100     // php/3251
101
return _function != null && (_function.isUsesSymbolTable() ||
102                  _function.isVariableVar());
103   }
104
105   /**
106    * True if the variable is a function argument
107    */

108   public boolean isArgument()
109   {
110     return _isArgument;
111   }
112
113   /**
114    * True if the variable is a function argument
115    */

116   public void setArgument(boolean isArgument)
117   {
118     _isArgument = isArgument;
119   }
120
121   /**
122    * Sets the argument index
123    */

124   public void setArgumentIndex(int index)
125   {
126     _argumentIndex = index;
127   }
128
129   /**
130    * Returns the argument indext
131    */

132   public int getArgumentIndex()
133   {
134     return _argumentIndex;
135   }
136
137   /**
138    * True if the variable is a reference function argument
139    */

140   public boolean isRefArgument()
141   {
142     return _isRefArgument;
143   }
144
145   /**
146    * True if the variable is a reference function argument
147    */

148   public void setRefArgument()
149   {
150     _isRefArgument = true;
151     
152     setReference();
153   }
154
155   /**
156    * True if the variable is assigned in the function.
157    */

158   public boolean isAssigned()
159   {
160     return _isAssigned;
161   }
162
163   /**
164    * True if the variable is assigned in the function.
165    */

166   public void setAssigned()
167   {
168     _isAssigned = true;
169
170     if (isReference()) {
171       // php/3a7c
172
setModified();
173     }
174   }
175
176   /**
177    * True if the Java variable only contains PHP values.
178    */

179   public boolean isValue()
180   {
181     // php/3a71
182
// php/3435
183
return ! (_isArgument || _isReference || isGlobal() || isVariable());
184   }
185   
186   /**
187    * True if the variable is used as a reference in the function.
188    */

189   public boolean isReference()
190   {
191     // php/3a70 vs php/3995
192
return (_isReference || isGlobal() || isArgument() || isVariable());
193   }
194
195   /**
196    * True if the variable is assigned in the function.
197    */

198   public void setReference()
199   {
200     _isReference = true;
201
202     if (_isAssigned)
203       setModified();
204   }
205
206   /**
207    * Returns true for a read-only variable, i.e. one that doesn't
208    * need to be copied as an argument.
209    */

210   public boolean isReadOnly()
211   {
212     return _function.isReadOnly();
213   }
214
215   /**
216    * Sets as modified.
217    */

218   public void setModified()
219   {
220     _function.setModified();
221   }
222
223   public String JavaDoc toString()
224   {
225     return "VarInfo[" + _name + "]";
226   }
227 }
228
229
Popular Tags