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