1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: symtbl.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #include <svtools/svarray.hxx>
35 #include <tools/string.hxx>
36 #include <basic/sbxdef.hxx>
37 #include <basic/sbdef.hxx>
39 class SbiSymDef
; // Basisklasse
40 class SbiProcDef
; // Prozedur
41 class SbiConstDef
; // Konstante
42 class SbiSymPool
; // Symbol-Pool
43 class SbiStringPool
; // gepoolte Strings
48 enum SbiSymScope
{ SbLOCAL
, SbPARAM
, SbPUBLIC
, SbGLOBAL
, SbRTL
};
50 ///////////////////////////////////////////////////////////////////////////
52 // Der String-Pool nimmt String-Eintraege auf und sorgt dafuer,
53 // dass sie nicht doppelt vorkommen.
55 SV_DECL_PTRARR_DEL(SbiStrings
,String
*,5,5)
57 class SbiStringPool
{ // String-Pool
58 SbiStrings aData
; // Daten
59 String aEmpty
; // for convenience
60 SbiParser
* pParser
; // der Parser
62 SbiStringPool( SbiParser
* );
64 USHORT
GetSize() const { return aData
.Count(); }
65 // AB 8.4.1999, Default wegen #64236 auf TRUE geaendert
66 // Wenn der Bug sauber behoben ist, wieder auf FALSE aendern.
67 short Add( const String
&, BOOL
=TRUE
);
68 short Add( double, SbxDataType
);
69 const String
& Find( USHORT
) const;
70 SbiParser
* GetParser() { return pParser
; }
73 ///////////////////////////////////////////////////////////////////////////
75 SV_DECL_PTRARR_DEL(SbiSymbols
,SbiSymDef
*,5,5)
77 class SbiSymPool
{ // Symbol-Pool
78 friend class SbiSymDef
;
79 friend class SbiProcDef
;
81 SbiStringPool
& rStrings
; // verwendeter Stringpool
82 SbiSymbols aData
; // Daten
83 SbiSymPool
* pParent
; // uebergeordneter Symbol-Pool
84 SbiParser
* pParser
; // der Parser
85 SbiSymScope eScope
; // Scope des Pools
86 USHORT nProcId
; // aktuelles ProcId fuer STATIC-Variable
87 USHORT nCur
; // Iterator
89 SbiSymPool( SbiStringPool
&, SbiSymScope
);
94 void SetParent( SbiSymPool
* p
) { pParent
= p
; }
95 void SetProcId( short n
) { nProcId
= n
; }
96 USHORT
GetSize() const { return aData
.Count(); }
97 SbiSymScope
GetScope() const { return eScope
; }
98 void SetScope( SbiSymScope s
) { eScope
= s
; }
99 SbiParser
* GetParser() { return pParser
; }
101 SbiSymDef
* AddSym( const String
& ); // Symbol hinzufuegen
102 SbiProcDef
* AddProc( const String
& );// Prozedur hinzufuegen
103 void Add( SbiSymDef
* ); // Symbol uebernehmen
104 SbiSymDef
* Find( const String
& ) const;// Variablenname
105 SbiSymDef
* FindId( USHORT
) const; // Variable per ID suchen
106 SbiSymDef
* Get( USHORT
) const; // Variable per Position suchen
107 SbiSymDef
* First(), *Next(); // Iteratoren
109 UINT32
Define( const String
& ); // Label definieren
110 UINT32
Reference( const String
& ); // Label referenzieren
111 void CheckRefs(); // offene Referenzen suchen
114 ///////////////////////////////////////////////////////////////////////////
116 class SbiSymDef
{ // Allgemeiner Symboleintrag
117 friend class SbiSymPool
;
119 String aName
; // Name des Eintrags
120 SbxDataType eType
; // Typ des Eintrags
121 SbiSymPool
* pIn
; // Parent-Pool
122 SbiSymPool
* pPool
; // Pool fuer Unterelemente
123 short nLen
; // Stringlaenge bei STRING*n
124 short nDims
; // Array-Dimensionen
125 USHORT nId
; // Symbol-Nummer
126 USHORT nTypeId
; // String-ID des Datentyps (Dim X AS Dytentyp)
127 USHORT nProcId
; // aktuelles ProcId fuer STATIC-Variable
128 USHORT nPos
; // Positions-Nummer
129 UINT32 nChain
; // Backchain-Kette
130 BOOL bNew
: 1; // TRUE: Dim As New...
131 BOOL bChained
: 1; // TRUE: Symbol ist in Code definiert
132 BOOL bByVal
: 1; // TRUE: ByVal-Parameter
133 BOOL bOpt
: 1; // TRUE: optionaler Parameter
134 BOOL bStatic
: 1; // TRUE: STATIC-Variable
135 BOOL bAs
: 1; // TRUE: Datentyp per AS XXX definiert
136 BOOL bGlobal
: 1; // TRUE: Global-Variable
137 BOOL bParamArray
: 1; // TRUE: ParamArray parameter
138 USHORT nDefaultId
; // Symbol number of default value
140 SbiSymDef( const String
& );
141 virtual ~SbiSymDef();
142 virtual SbiProcDef
* GetProcDef();
143 virtual SbiConstDef
* GetConstDef();
145 SbxDataType
GetType() const { return eType
; }
146 virtual void SetType( SbxDataType
);
147 const String
& GetName();
148 SbiSymScope
GetScope() const;
149 USHORT
GetProcId() const{ return nProcId
; }
150 UINT32
GetAddr() const { return nChain
; }
151 USHORT
GetId() const { return nId
; }
152 USHORT
GetTypeId() const{ return nTypeId
; }
153 void SetTypeId( USHORT n
) { nTypeId
= n
; eType
= SbxOBJECT
; }
154 USHORT
GetPos() const { return nPos
; }
155 void SetLen( short n
){ nLen
= n
; }
156 short GetLen() const { return nLen
; }
157 void SetDims( short n
) { nDims
= n
; }
158 short GetDims() const { return nDims
; }
159 BOOL
IsDefined() const{ return bChained
; }
160 void SetOptional() { bOpt
= TRUE
; }
161 void SetParamArray() { bParamArray
= TRUE
; }
162 void SetByVal() { bByVal
= TRUE
; }
163 void SetStatic( BOOL bAsStatic
= TRUE
) { bStatic
= bAsStatic
; }
164 void SetNew() { bNew
= TRUE
; }
165 void SetDefinedAs() { bAs
= TRUE
; }
166 void SetGlobal(BOOL b
){ bGlobal
= b
; }
167 void SetDefaultId( USHORT n
) { nDefaultId
= n
; }
168 USHORT
GetDefaultId( void ) { return nDefaultId
; }
169 BOOL
IsOptional() const{ return bOpt
; }
170 BOOL
IsParamArray() const{ return bParamArray
; }
171 BOOL
IsByVal() const { return bByVal
; }
172 BOOL
IsStatic() const { return bStatic
; }
173 BOOL
IsNew() const { return bNew
; }
174 BOOL
IsDefinedAs() const { return bAs
; }
175 BOOL
IsGlobal() const { return bGlobal
; }
177 SbiSymPool
& GetPool();
178 UINT32
Define(); // Symbol in Code definieren
179 UINT32
Reference(); // Symbol in Code referenzieren
182 SbiSymDef( const SbiSymDef
& );
186 class SbiProcDef
: public SbiSymDef
{ // Prozedur-Definition (aus Basic):
187 SbiSymPool aParams
; // Parameter
188 SbiSymPool aLabels
; // lokale Sprungziele
189 String aLibName
; // LIB "name"
190 String aAlias
; // ALIAS "name"
191 USHORT nLine1
, nLine2
; // Zeilenbereich
192 PropertyMode mePropMode
; // Marks if this is a property procedure and which
193 String maPropName
; // Property name if property procedure (!= proc name)
194 BOOL bCdecl
: 1; // TRUE: CDECL angegeben
195 BOOL bPublic
: 1; // TRUE: proc ist PUBLIC
196 BOOL mbProcDecl
: 1; // TRUE: instanciated by SbiParser::ProcDecl
198 SbiProcDef( SbiParser
*, const String
&, BOOL bProcDecl
=false );
199 virtual ~SbiProcDef();
200 virtual SbiProcDef
* GetProcDef();
201 virtual void SetType( SbxDataType
);
202 SbiSymPool
& GetParams() { return aParams
; }
203 SbiSymPool
& GetLabels() { return aLabels
; }
204 SbiSymPool
& GetLocals() { return GetPool();}
205 String
& GetLib() { return aLibName
; }
206 String
& GetAlias() { return aAlias
; }
207 void SetPublic( BOOL b
) { bPublic
= b
; }
208 BOOL
IsPublic() const { return bPublic
; }
209 void SetCdecl( BOOL b
= TRUE
) { bCdecl
= b
; }
210 BOOL
IsCdecl() const { return bCdecl
; }
211 BOOL
IsUsedForProcDecl() const { return mbProcDecl
; }
212 void SetLine1( USHORT n
) { nLine1
= n
; }
213 USHORT
GetLine1() const { return nLine1
; }
214 void SetLine2( USHORT n
) { nLine2
= n
; }
215 USHORT
GetLine2() const { return nLine2
; }
216 PropertyMode
getPropertyMode() { return mePropMode
; }
217 void setPropertyMode( PropertyMode ePropMode
);
218 const String
& GetPropName() { return maPropName
; }
220 // Match mit einer Forward-Deklaration. Die Parameternamen
221 // werden abgeglichen und die Forward-Deklaration wird
222 // durch this ersetzt
223 void Match( SbiProcDef
* pForward
);
226 SbiProcDef( const SbiProcDef
& );
230 class SbiConstDef
: public SbiSymDef
235 SbiConstDef( const String
& );
236 virtual ~SbiConstDef();
237 virtual SbiConstDef
* GetConstDef();
238 void Set( double, SbxDataType
);
239 void Set( const String
& );
240 double GetValue() { return nVal
; }
241 const String
& GetString() { return aVal
; }