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