01: package net.sf.saxon.instruct;
02:
03: import java.io.Serializable;
04: import java.util.List;
05: import java.util.ArrayList;
06:
07: /**
08: * A SlotManager supports functions, templates, etc: specifically, any executable code that
09: * requires a stack frame containing local variables. In XSLT a SlotManager underpins any
10: * top-level element that can contain local variable declarations,
11: * specifically, a top-level xsl:template, xsl:variable, xsl:param, or xsl:function element
12: * or an xsl:attribute-set element or xsl:key element. In XQuery it underpins functions and
13: * global variables. The purpose of the SlotManager is to allocate slot numbers to variables
14: * in the stack, and to record how many slots are needed. A Debugger may define a subclass
15: * with additional functionality.
16: */
17:
18: public class SlotManager implements Serializable {
19:
20: private ArrayList variableMap = new ArrayList(10);
21: private int numberOfVariables = 0;
22:
23: /**
24: * The constructor should not be called directly. A new SlotManager should be obtained using
25: * the factory method in the Configuration object.
26: */
27:
28: public SlotManager() {
29: }
30:
31: /**
32: * Get number of variables (size of stack frame)
33: */
34:
35: public int getNumberOfVariables() {
36: return numberOfVariables;
37: }
38:
39: /**
40: * Set the number of variables
41: * @param numberOfVariables
42: */
43:
44: public void setNumberOfVariables(int numberOfVariables) {
45: this .numberOfVariables = numberOfVariables;
46: variableMap.trimToSize();
47: }
48:
49: /**
50: * Allocate a slot number for a variable
51: */
52:
53: public int allocateSlotNumber(int fingerprint) {
54: final Integer key = new Integer(fingerprint);
55: variableMap.add(key);
56: return numberOfVariables++;
57: }
58:
59: /**
60: * Get the variable map (simply a list of fingerprints of the variable names). Note that it
61: * is possible for several variables to have the same name.
62: */
63:
64: public List getVariableMap() {
65: return variableMap;
66: }
67:
68: }
69:
70: //
71: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
72: // you may not use this file except in compliance with the License. You may obtain a copy of the
73: // License at http://www.mozilla.org/MPL/
74: //
75: // Software distributed under the License is distributed on an "AS IS" basis,
76: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
77: // See the License for the specific language governing rights and limitations under the License.
78: //
79: // The Original Code is: all this file.
80: //
81: // The Initial Developer of the Original Code is Michael H. Kay.
82: //
83: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
84: //
85: // Contributor(s): none.
86: //
|