KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > program > FunctionInfo


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.program;
31
32 import com.caucho.quercus.Quercus;
33 import com.caucho.quercus.expr.VarInfo;
34
35 import java.util.ArrayList JavaDoc;
36 import java.util.Collection JavaDoc;
37 import java.util.HashMap JavaDoc;
38
39 /**
40  * Information about a function.
41  */

42 public class FunctionInfo {
43   private final Quercus _quercus;
44
45   private final String JavaDoc _name;
46   
47   private final HashMap JavaDoc<String JavaDoc,VarInfo> _varMap
48     = new HashMap JavaDoc<String JavaDoc,VarInfo>();
49
50   private final ArrayList JavaDoc<String JavaDoc> _tempVarList
51     = new ArrayList JavaDoc<String JavaDoc>();
52
53   private ClassDef _classDef;
54   private Function _fun;
55
56   private boolean _isGlobal;
57   
58   private boolean _isPageMain;
59   private boolean _isPageStatic;
60   
61   private boolean _isReturnsReference;
62   private boolean _isVariableVar;
63   private boolean _isOutUsed;
64
65   private boolean _isVariableArgs;
66   private boolean _isUsesSymbolTable;
67
68   private boolean _isReadOnly = true;
69
70   public FunctionInfo(Quercus quercus, String JavaDoc name)
71   {
72     _quercus = quercus;
73     _name = name;
74   }
75
76   /**
77    * Returns the owning quercus.
78    */

79   public Quercus getPhp()
80   {
81     return _quercus;
82   }
83
84   public String JavaDoc getName()
85   {
86     return _name;
87   }
88
89   /**
90    * Sets the actual function.
91    */

92   public void setFunction(Function fun)
93   {
94     _fun = fun;
95   }
96
97   /**
98    * True for a global function (top-level script).
99    */

100   public boolean isGlobal()
101   {
102     return _isGlobal;
103   }
104
105   /**
106    * True for a global function.
107    */

108   public void setGlobal(boolean isGlobal)
109   {
110     _isGlobal = isGlobal;
111   }
112
113   /**
114    * True for a main function (top-level script).
115    */

116   public boolean isPageMain()
117   {
118     return _isPageMain;
119   }
120
121   /**
122    * True for a main function (top-level script).
123    */

124   public void setPageMain(boolean isPageMain)
125   {
126     _isPageMain = isPageMain;
127   }
128
129   /**
130    * True for a static function (top-level script).
131    */

132   public boolean isPageStatic()
133   {
134     return _isPageStatic;
135   }
136
137   /**
138    * True for a static function (top-level script).
139    */

140   public void setPageStatic(boolean isPageStatic)
141   {
142     _isPageStatic = isPageStatic;
143   }
144
145   /**
146    * Sets the owning class.
147    */

148   public void setDeclaringClass(ClassDef classDef)
149   {
150     _classDef = classDef;
151   }
152
153   /**
154    * Gets the owning class.
155    */

156   public ClassDef getDeclaringClass()
157   {
158     return _classDef;
159   }
160
161   /**
162    * True for a method.
163    */

164   public boolean isMethod()
165   {
166     return _classDef != null && ! _fun.isStatic();
167   }
168
169   /**
170    * True if the function returns a reference.
171    */

172   public boolean isReturnsReference()
173   {
174     return _isReturnsReference;
175   }
176
177   /**
178    * True if the function returns a reference.
179    */

180   public void setReturnsReference(boolean isReturnsReference)
181   {
182     _isReturnsReference = isReturnsReference;
183   }
184
185   /**
186    * True if the function has variable vars.
187    */

188   public boolean isVariableVar()
189   {
190     return _isVariableVar;
191   }
192
193   /**
194    * True if the function has variable vars
195    */

196   public void setVariableVar(boolean isVariableVar)
197   {
198     _isVariableVar = isVariableVar;
199   }
200
201   /**
202    * True if the function has variable numbers of arguments
203    */

204   public boolean isVariableArgs()
205   {
206     return _isVariableArgs;
207   }
208
209   /**
210    * True if the function has variable numbers of arguments
211    */

212   public void setVariableArgs(boolean isVariableArgs)
213   {
214     _isVariableArgs = isVariableArgs;
215   }
216
217   /**
218    * True if the function uses the symbol table
219    */

220   public boolean isUsesSymbolTable()
221   {
222     return _isUsesSymbolTable;
223   }
224
225   /**
226    * True if the function uses the symbol table
227    */

228   public void setUsesSymbolTable(boolean isUsesSymbolTable)
229   {
230     _isUsesSymbolTable = isUsesSymbolTable;
231   }
232
233   /**
234    * Returns true if the out is used.
235    */

236   public boolean isOutUsed()
237   {
238     return _isOutUsed;
239   }
240
241   /**
242    * Set true if the out is used.
243    */

244   public void setOutUsed()
245   {
246     _isOutUsed = true;
247   }
248
249   /**
250    * Returns true for a read-only function, i.e. no values are changed.
251    */

252   public boolean isReadOnly()
253   {
254     return _isReadOnly;
255   }
256
257   /**
258    * True for a non-read-only function
259    */

260   public void setModified()
261   {
262     _isReadOnly = false;
263   }
264
265   /**
266    * Returns the variable.
267    */

268   public VarInfo createVar(String JavaDoc name)
269   {
270     VarInfo var = _varMap.get(name);
271
272     if (var == null) {
273       var = new VarInfo(name, this);
274
275       if (_isGlobal)
276     var.setGlobal();
277
278       if (Quercus.isSuperGlobal(name))
279     var.setGlobal();
280       
281       _varMap.put(name, var);
282     }
283
284     return var;
285   }
286
287   /**
288    * Returns the variables.
289    */

290   public Collection JavaDoc<VarInfo> getVariables()
291   {
292     return _varMap.values();
293   }
294
295   /**
296    * Adds a temp variable.
297    */

298   public void addTempVar(String JavaDoc name)
299   {
300     if (! _tempVarList.contains(name))
301       _tempVarList.add(name);
302   }
303
304   /**
305    * Returns the temp variables.
306    */

307   public Collection JavaDoc<String JavaDoc> getTempVariables()
308   {
309     return _tempVarList;
310   }
311
312   public int getTempIndex()
313   {
314     return _tempVarList.size();
315   }
316
317   public String JavaDoc toString()
318   {
319     return "FunctionInfo[" + _name + "]";
320   }
321 }
322
323
Popular Tags