added Info.plist
[TestXSLT.git] / libsablot / src / engine / vars.h
1 /* 
2  * The contents of this file are subject to the Mozilla Public
3  * License Version 1.1 (the "License"); you may not use this file
4  * except in compliance with the License. You may obtain a copy of
5  * the License at http://www.mozilla.org/MPL/
6  * 
7  * Software distributed under the License is distributed on an "AS
8  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9  * implied. See the License for the specific language governing
10  * rights and limitations under the License.
11  * 
12  * The Original Code is the Sablotron XSLT Processor.
13  * 
14  * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15  * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16  * Ginger Alliance Ltd. All Rights Reserved.
17  * 
18  * Contributor(s):
19  * 
20  * Alternatively, the contents of this file may be used under the
21  * terms of the GNU General Public License Version 2 or later (the
22  * "GPL"), in which case the provisions of the GPL are applicable 
23  * instead of those above.  If you wish to allow use of your 
24  * version of this file only under the terms of the GPL and not to
25  * allow others to use your version of this file under the MPL,
26  * indicate your decision by deleting the provisions above and
27  * replace them with the notice and other provisions required by
28  * the GPL.  If you do not delete the provisions above, a recipient
29  * may use your version of this file under either the MPL or the
30  * GPL.
31  */
32
33 #ifndef VarsHIncl
34 #define VarsHIncl
35
36 // GP: clean
37
38 #include "base.h"
39 #include "datastr.h"
40 #include "expr.h"
41
42 class VarBindingItem /* : public SabObj */
43 {
44 public:
45     VarBindingItem()
46         : expr(NULL), callLevel(-1), nestLevel(-1), prebinding(FALSE)
47         {};
48     ~VarBindingItem();
49     Expression *expr;
50     int callLevel, nestLevel;
51     Bool prebinding;
52 };
53
54 class VarBindings /* : public SabObj */
55 {
56 public:
57     VarBindings(QName& varname_)
58         : varname(varname_), isOpenGlobal(FALSE)
59     {
60     }
61     ~VarBindings();
62     QName varname;
63     // TRUE if this is a global variable currently processed for forward references
64     PList <VarBindingItem*> bindings;
65     Bool isOpenGlobal;
66 };
67
68 class Tree;
69
70 class VarsList : public SList<VarBindings *>
71 {
72 public:
73     VarsList(Tree&);
74     ~VarsList();
75     VarBindings* find(QName&);
76     virtual int compare(int first, int second, void *data);
77     eFlag addBinding(Sit S, QName&, Expression *, Bool force);
78     eFlag addPrebinding(Sit S, QName&, Expression *);
79     void rmBinding(QName&);
80     Expression* getBinding(QName &);
81     Expression* getBinding(VarBindings*);
82     void startCall();
83     void endCall();
84     void pushCallLevel(int level);
85     void popCallLevel();
86     void startNested();
87     void endNested();
88     void startApplyOne();
89     void endApplyOne();
90     void rmPrebindings();
91     int currCallLevel, currNestLevel;
92     // open the global variable (mark as being processed for forward refs)
93     // if it doesn't exist, create it; return the pointer to VarBindings* in 'record'
94     // if non-NULL record is passed, use it instead of name for performance
95     eFlag openGlobal(Sit S, QName& name, VarBindings *&record);
96     // close the global variable after having succesfully resolved the forward refs
97     eFlag closeGlobal(Sit S, VarBindings *record);
98     // see if the var with given 'record' is an open global
99     Bool isOpenGlobal(VarBindings *record)
100         { return record -> isOpenGlobal; }
101     Tree& sheet;
102 private:
103     List<int> callLevels;
104     VarBindings* getOrAdd(QName &);
105     void _endCall(Bool rmLastLevelPrebs);
106     void report(Sit S, MsgType type, MsgCode code, const Str& arg1, const Str& arg2);
107 };
108
109 #endif  // ifndef VarsHIncl