1*234bd5c5SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*234bd5c5SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*234bd5c5SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*234bd5c5SAndrew Rist * distributed with this work for additional information 6*234bd5c5SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*234bd5c5SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*234bd5c5SAndrew Rist * "License"); you may not use this file except in compliance 9*234bd5c5SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*234bd5c5SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*234bd5c5SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*234bd5c5SAndrew Rist * software distributed under the License is distributed on an 15*234bd5c5SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*234bd5c5SAndrew Rist * KIND, either express or implied. See the License for the 17*234bd5c5SAndrew Rist * specific language governing permissions and limitations 18*234bd5c5SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*234bd5c5SAndrew Rist *************************************************************/ 21*234bd5c5SAndrew Rist 22*234bd5c5SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _SYMTBL_HXX 25cdf0e10cSrcweir #define _SYMTBL_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <svl/svarray.hxx> 28cdf0e10cSrcweir #include <tools/string.hxx> 29cdf0e10cSrcweir #include <basic/sbxdef.hxx> 30cdf0e10cSrcweir #include <basic/sbdef.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir class SbiSymDef; // Basisklasse 33cdf0e10cSrcweir class SbiProcDef; // Prozedur 34cdf0e10cSrcweir class SbiConstDef; // Konstante 35cdf0e10cSrcweir class SbiSymPool; // Symbol-Pool 36cdf0e10cSrcweir class SbiStringPool; // gepoolte Strings 37cdf0e10cSrcweir 38cdf0e10cSrcweir class SvStream; 39cdf0e10cSrcweir class SbiParser; 40cdf0e10cSrcweir 41cdf0e10cSrcweir enum SbiSymScope { SbLOCAL, SbPARAM, SbPUBLIC, SbGLOBAL, SbRTL }; 42cdf0e10cSrcweir 43cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 44cdf0e10cSrcweir 45cdf0e10cSrcweir // Der String-Pool nimmt String-Eintraege auf und sorgt dafuer, 46cdf0e10cSrcweir // dass sie nicht doppelt vorkommen. 47cdf0e10cSrcweir 48cdf0e10cSrcweir SV_DECL_PTRARR_DEL(SbiStrings,String*,5,5) 49cdf0e10cSrcweir 50cdf0e10cSrcweir class SbiStringPool { // String-Pool 51cdf0e10cSrcweir SbiStrings aData; // Daten 52cdf0e10cSrcweir String aEmpty; // for convenience 53cdf0e10cSrcweir SbiParser* pParser; // der Parser 54cdf0e10cSrcweir public: 55cdf0e10cSrcweir SbiStringPool( SbiParser* ); 56cdf0e10cSrcweir ~SbiStringPool(); GetSize() const57cdf0e10cSrcweir sal_uInt16 GetSize() const { return aData.Count(); } 58cdf0e10cSrcweir // AB 8.4.1999, Default wegen #64236 auf sal_True geaendert 59cdf0e10cSrcweir // Wenn der Bug sauber behoben ist, wieder auf sal_False aendern. 60cdf0e10cSrcweir short Add( const String&, sal_Bool=sal_True ); 61cdf0e10cSrcweir short Add( double, SbxDataType ); 62cdf0e10cSrcweir const String& Find( sal_uInt16 ) const; GetParser()63cdf0e10cSrcweir SbiParser* GetParser() { return pParser; } 64cdf0e10cSrcweir }; 65cdf0e10cSrcweir 66cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 67cdf0e10cSrcweir 68cdf0e10cSrcweir SV_DECL_PTRARR_DEL(SbiSymbols,SbiSymDef*,5,5) 69cdf0e10cSrcweir 70cdf0e10cSrcweir class SbiSymPool { // Symbol-Pool 71cdf0e10cSrcweir friend class SbiSymDef; 72cdf0e10cSrcweir friend class SbiProcDef; 73cdf0e10cSrcweir protected: 74cdf0e10cSrcweir SbiStringPool& rStrings; // verwendeter Stringpool 75cdf0e10cSrcweir SbiSymbols aData; // Daten 76cdf0e10cSrcweir SbiSymPool* pParent; // uebergeordneter Symbol-Pool 77cdf0e10cSrcweir SbiParser* pParser; // der Parser 78cdf0e10cSrcweir SbiSymScope eScope; // Scope des Pools 79cdf0e10cSrcweir sal_uInt16 nProcId; // aktuelles ProcId fuer STATIC-Variable 80cdf0e10cSrcweir sal_uInt16 nCur; // Iterator 81cdf0e10cSrcweir public: 82cdf0e10cSrcweir SbiSymPool( SbiStringPool&, SbiSymScope ); 83cdf0e10cSrcweir ~SbiSymPool(); 84cdf0e10cSrcweir 85cdf0e10cSrcweir void Clear(); 86cdf0e10cSrcweir SetParent(SbiSymPool * p)87cdf0e10cSrcweir void SetParent( SbiSymPool* p ) { pParent = p; } SetProcId(short n)88cdf0e10cSrcweir void SetProcId( short n ) { nProcId = n; } GetSize() const89cdf0e10cSrcweir sal_uInt16 GetSize() const { return aData.Count(); } GetScope() const90cdf0e10cSrcweir SbiSymScope GetScope() const { return eScope; } SetScope(SbiSymScope s)91cdf0e10cSrcweir void SetScope( SbiSymScope s ) { eScope = s; } GetParser()92cdf0e10cSrcweir SbiParser* GetParser() { return pParser; } 93cdf0e10cSrcweir 94cdf0e10cSrcweir SbiSymDef* AddSym( const String& ); // Symbol hinzufuegen 95cdf0e10cSrcweir SbiProcDef* AddProc( const String& );// Prozedur hinzufuegen 96cdf0e10cSrcweir void Add( SbiSymDef* ); // Symbol uebernehmen 97cdf0e10cSrcweir SbiSymDef* Find( const String& ) const;// Variablenname 98cdf0e10cSrcweir SbiSymDef* FindId( sal_uInt16 ) const; // Variable per ID suchen 99cdf0e10cSrcweir SbiSymDef* Get( sal_uInt16 ) const; // Variable per Position suchen 100cdf0e10cSrcweir SbiSymDef* First(), *Next(); // Iteratoren 101cdf0e10cSrcweir 102cdf0e10cSrcweir sal_uInt32 Define( const String& ); // Label definieren 103cdf0e10cSrcweir sal_uInt32 Reference( const String& ); // Label referenzieren 104cdf0e10cSrcweir void CheckRefs(); // offene Referenzen suchen 105cdf0e10cSrcweir }; 106cdf0e10cSrcweir 107cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 108cdf0e10cSrcweir 109cdf0e10cSrcweir class SbiSymDef { // Allgemeiner Symboleintrag 110cdf0e10cSrcweir friend class SbiSymPool; 111cdf0e10cSrcweir protected: 112cdf0e10cSrcweir String aName; // Name des Eintrags 113cdf0e10cSrcweir SbxDataType eType; // Typ des Eintrags 114cdf0e10cSrcweir SbiSymPool* pIn; // Parent-Pool 115cdf0e10cSrcweir SbiSymPool* pPool; // Pool fuer Unterelemente 116cdf0e10cSrcweir short nLen; // Stringlaenge bei STRING*n 117cdf0e10cSrcweir short nDims; // Array-Dimensionen 118cdf0e10cSrcweir sal_uInt16 nId; // Symbol-Nummer 119cdf0e10cSrcweir sal_uInt16 nTypeId; // String-ID des Datentyps (Dim X AS Dytentyp) 120cdf0e10cSrcweir sal_uInt16 nProcId; // aktuelles ProcId fuer STATIC-Variable 121cdf0e10cSrcweir sal_uInt16 nPos; // Positions-Nummer 122cdf0e10cSrcweir sal_uInt32 nChain; // Backchain-Kette 123cdf0e10cSrcweir sal_Bool bNew : 1; // sal_True: Dim As New... 124cdf0e10cSrcweir sal_Bool bChained : 1; // sal_True: Symbol ist in Code definiert 125cdf0e10cSrcweir sal_Bool bByVal : 1; // sal_True: ByVal-Parameter 126cdf0e10cSrcweir sal_Bool bOpt : 1; // sal_True: optionaler Parameter 127cdf0e10cSrcweir sal_Bool bStatic : 1; // sal_True: STATIC-Variable 128cdf0e10cSrcweir sal_Bool bAs : 1; // sal_True: Datentyp per AS XXX definiert 129cdf0e10cSrcweir sal_Bool bGlobal : 1; // sal_True: Global-Variable 130cdf0e10cSrcweir sal_Bool bParamArray : 1; // sal_True: ParamArray parameter 131cdf0e10cSrcweir sal_Bool bWithEvents : 1; // sal_True: Declared WithEvents 132cdf0e10cSrcweir sal_Bool bWithBrackets : 1; // sal_True: Followed by () 133cdf0e10cSrcweir sal_uInt16 nDefaultId; // Symbol number of default value 134cdf0e10cSrcweir short nFixedStringLength; // String length in: Dim foo As String*Length 135cdf0e10cSrcweir public: 136cdf0e10cSrcweir SbiSymDef( const String& ); 137cdf0e10cSrcweir virtual ~SbiSymDef(); 138cdf0e10cSrcweir virtual SbiProcDef* GetProcDef(); 139cdf0e10cSrcweir virtual SbiConstDef* GetConstDef(); 140cdf0e10cSrcweir GetType() const141cdf0e10cSrcweir SbxDataType GetType() const { return eType; } 142cdf0e10cSrcweir virtual void SetType( SbxDataType ); 143cdf0e10cSrcweir const String& GetName(); 144cdf0e10cSrcweir SbiSymScope GetScope() const; GetProcId() const145cdf0e10cSrcweir sal_uInt16 GetProcId() const{ return nProcId; } GetAddr() const146cdf0e10cSrcweir sal_uInt32 GetAddr() const { return nChain; } GetId() const147cdf0e10cSrcweir sal_uInt16 GetId() const { return nId; } GetTypeId() const148cdf0e10cSrcweir sal_uInt16 GetTypeId() const{ return nTypeId; } SetTypeId(sal_uInt16 n)149cdf0e10cSrcweir void SetTypeId( sal_uInt16 n ) { nTypeId = n; eType = SbxOBJECT; } GetPos() const150cdf0e10cSrcweir sal_uInt16 GetPos() const { return nPos; } SetLen(short n)151cdf0e10cSrcweir void SetLen( short n ){ nLen = n; } GetLen() const152cdf0e10cSrcweir short GetLen() const { return nLen; } SetDims(short n)153cdf0e10cSrcweir void SetDims( short n ) { nDims = n; } GetDims() const154cdf0e10cSrcweir short GetDims() const { return nDims; } IsDefined() const155cdf0e10cSrcweir sal_Bool IsDefined() const{ return bChained; } SetOptional()156cdf0e10cSrcweir void SetOptional() { bOpt = sal_True; } SetParamArray()157cdf0e10cSrcweir void SetParamArray() { bParamArray = sal_True; } SetWithEvents()158cdf0e10cSrcweir void SetWithEvents() { bWithEvents = sal_True; } SetWithBrackets()159cdf0e10cSrcweir void SetWithBrackets(){ bWithBrackets = sal_True; } SetByVal(sal_Bool bByVal_=sal_True)160cdf0e10cSrcweir void SetByVal( sal_Bool bByVal_ = sal_True ) 161cdf0e10cSrcweir { bByVal = bByVal_; } SetStatic(sal_Bool bAsStatic=sal_True)162cdf0e10cSrcweir void SetStatic( sal_Bool bAsStatic = sal_True ) { bStatic = bAsStatic; } SetNew()163cdf0e10cSrcweir void SetNew() { bNew = sal_True; } SetDefinedAs()164cdf0e10cSrcweir void SetDefinedAs() { bAs = sal_True; } SetGlobal(sal_Bool b)165cdf0e10cSrcweir void SetGlobal(sal_Bool b){ bGlobal = b; } SetDefaultId(sal_uInt16 n)166cdf0e10cSrcweir void SetDefaultId( sal_uInt16 n ) { nDefaultId = n; } GetDefaultId(void)167cdf0e10cSrcweir sal_uInt16 GetDefaultId( void ) { return nDefaultId; } IsOptional() const168cdf0e10cSrcweir sal_Bool IsOptional() const{ return bOpt; } IsParamArray() const169cdf0e10cSrcweir sal_Bool IsParamArray() const{ return bParamArray; } IsWithEvents() const170cdf0e10cSrcweir sal_Bool IsWithEvents() const{ return bWithEvents; } IsWithBrackets() const171cdf0e10cSrcweir sal_Bool IsWithBrackets() const{ return bWithBrackets; } IsByVal() const172cdf0e10cSrcweir sal_Bool IsByVal() const { return bByVal; } IsStatic() const173cdf0e10cSrcweir sal_Bool IsStatic() const { return bStatic; } IsNew() const174cdf0e10cSrcweir sal_Bool IsNew() const { return bNew; } IsDefinedAs() const175cdf0e10cSrcweir sal_Bool IsDefinedAs() const { return bAs; } IsGlobal() const176cdf0e10cSrcweir sal_Bool IsGlobal() const { return bGlobal; } GetFixedStringLength(void) const177cdf0e10cSrcweir short GetFixedStringLength( void ) const { return nFixedStringLength; } SetFixedStringLength(short n)178cdf0e10cSrcweir void SetFixedStringLength( short n ) { nFixedStringLength = n; } 179cdf0e10cSrcweir 180cdf0e10cSrcweir SbiSymPool& GetPool(); 181cdf0e10cSrcweir sal_uInt32 Define(); // Symbol in Code definieren 182cdf0e10cSrcweir sal_uInt32 Reference(); // Symbol in Code referenzieren 183cdf0e10cSrcweir 184cdf0e10cSrcweir private: 185cdf0e10cSrcweir SbiSymDef( const SbiSymDef& ); 186cdf0e10cSrcweir 187cdf0e10cSrcweir }; 188cdf0e10cSrcweir 189cdf0e10cSrcweir class SbiProcDef : public SbiSymDef { // Prozedur-Definition (aus Basic): 190cdf0e10cSrcweir SbiSymPool aParams; // Parameter 191cdf0e10cSrcweir SbiSymPool aLabels; // lokale Sprungziele 192cdf0e10cSrcweir String aLibName; // LIB "name" 193cdf0e10cSrcweir String aAlias; // ALIAS "name" 194cdf0e10cSrcweir sal_uInt16 nLine1, nLine2; // Zeilenbereich 195cdf0e10cSrcweir PropertyMode mePropMode; // Marks if this is a property procedure and which 196cdf0e10cSrcweir String maPropName; // Property name if property procedure (!= proc name) 197cdf0e10cSrcweir sal_Bool bCdecl : 1; // sal_True: CDECL angegeben 198cdf0e10cSrcweir sal_Bool bPublic : 1; // sal_True: proc ist PUBLIC 199cdf0e10cSrcweir sal_Bool mbProcDecl : 1; // sal_True: instanciated by SbiParser::ProcDecl 200cdf0e10cSrcweir public: 201cdf0e10cSrcweir SbiProcDef( SbiParser*, const String&, sal_Bool bProcDecl=false ); 202cdf0e10cSrcweir virtual ~SbiProcDef(); 203cdf0e10cSrcweir virtual SbiProcDef* GetProcDef(); 204cdf0e10cSrcweir virtual void SetType( SbxDataType ); GetParams()205cdf0e10cSrcweir SbiSymPool& GetParams() { return aParams; } GetLabels()206cdf0e10cSrcweir SbiSymPool& GetLabels() { return aLabels; } GetLocals()207cdf0e10cSrcweir SbiSymPool& GetLocals() { return GetPool();} GetLib()208cdf0e10cSrcweir String& GetLib() { return aLibName; } GetAlias()209cdf0e10cSrcweir String& GetAlias() { return aAlias; } SetPublic(sal_Bool b)210cdf0e10cSrcweir void SetPublic( sal_Bool b ) { bPublic = b; } IsPublic() const211cdf0e10cSrcweir sal_Bool IsPublic() const { return bPublic; } SetCdecl(sal_Bool b=sal_True)212cdf0e10cSrcweir void SetCdecl( sal_Bool b = sal_True) { bCdecl = b; } IsCdecl() const213cdf0e10cSrcweir sal_Bool IsCdecl() const { return bCdecl; } IsUsedForProcDecl() const214cdf0e10cSrcweir sal_Bool IsUsedForProcDecl() const { return mbProcDecl; } SetLine1(sal_uInt16 n)215cdf0e10cSrcweir void SetLine1( sal_uInt16 n ) { nLine1 = n; } GetLine1() const216cdf0e10cSrcweir sal_uInt16 GetLine1() const { return nLine1; } SetLine2(sal_uInt16 n)217cdf0e10cSrcweir void SetLine2( sal_uInt16 n ) { nLine2 = n; } GetLine2() const218cdf0e10cSrcweir sal_uInt16 GetLine2() const { return nLine2; } getPropertyMode()219cdf0e10cSrcweir PropertyMode getPropertyMode() { return mePropMode; } 220cdf0e10cSrcweir void setPropertyMode( PropertyMode ePropMode ); GetPropName()221cdf0e10cSrcweir const String& GetPropName() { return maPropName; } 222cdf0e10cSrcweir 223cdf0e10cSrcweir // Match mit einer Forward-Deklaration. Die Parameternamen 224cdf0e10cSrcweir // werden abgeglichen und die Forward-Deklaration wird 225cdf0e10cSrcweir // durch this ersetzt 226cdf0e10cSrcweir void Match( SbiProcDef* pForward ); 227cdf0e10cSrcweir 228cdf0e10cSrcweir private: 229cdf0e10cSrcweir SbiProcDef( const SbiProcDef& ); 230cdf0e10cSrcweir 231cdf0e10cSrcweir }; 232cdf0e10cSrcweir 233cdf0e10cSrcweir class SbiConstDef : public SbiSymDef 234cdf0e10cSrcweir { 235cdf0e10cSrcweir double nVal; 236cdf0e10cSrcweir String aVal; 237cdf0e10cSrcweir public: 238cdf0e10cSrcweir SbiConstDef( const String& ); 239cdf0e10cSrcweir virtual ~SbiConstDef(); 240cdf0e10cSrcweir virtual SbiConstDef* GetConstDef(); 241cdf0e10cSrcweir void Set( double, SbxDataType ); 242cdf0e10cSrcweir void Set( const String& ); GetValue()243cdf0e10cSrcweir double GetValue() { return nVal; } GetString()244cdf0e10cSrcweir const String& GetString() { return aVal; } 245cdf0e10cSrcweir }; 246cdf0e10cSrcweir 247cdf0e10cSrcweir 248cdf0e10cSrcweir #endif 249cdf0e10cSrcweir 250