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