138d50f7bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 338d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 438d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file 538d50f7bSAndrew Rist * distributed with this work for additional information 638d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 738d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the 838d50f7bSAndrew Rist * "License"); you may not use this file except in compliance 938d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at 1038d50f7bSAndrew Rist * 1138d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1238d50f7bSAndrew Rist * 1338d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing, 1438d50f7bSAndrew Rist * software distributed under the License is distributed on an 1538d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1638d50f7bSAndrew Rist * KIND, either express or implied. See the License for the 1738d50f7bSAndrew Rist * specific language governing permissions and limitations 1838d50f7bSAndrew Rist * under the License. 1938d50f7bSAndrew Rist * 2038d50f7bSAndrew Rist *************************************************************/ 2138d50f7bSAndrew Rist 2238d50f7bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SC_COMPILER_HXX 25cdf0e10cSrcweir #define SC_COMPILER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef INCLUDED_STRING_H 28cdf0e10cSrcweir #include <string.h> 29cdf0e10cSrcweir #define INCLUDED_STRING_H 30cdf0e10cSrcweir #endif 31cdf0e10cSrcweir #include <tools/mempool.hxx> 32cdf0e10cSrcweir #include "scdllapi.h" 33cdf0e10cSrcweir #include "global.hxx" 34cdf0e10cSrcweir #include "refdata.hxx" 35cdf0e10cSrcweir #include "formula/token.hxx" 36cdf0e10cSrcweir #include "formula/intruref.hxx" 37cdf0e10cSrcweir #include "formula/grammar.hxx" 38cdf0e10cSrcweir #include <unotools/charclass.hxx> 39cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 40cdf0e10cSrcweir #include <com/sun/star/sheet/ExternalLinkInfo.hpp> 41cdf0e10cSrcweir #include <vector> 42cdf0e10cSrcweir 43cdf0e10cSrcweir #include <formula/FormulaCompiler.hxx> 44cdf0e10cSrcweir 45cdf0e10cSrcweir 46cdf0e10cSrcweir #ifndef BOOST_SHARED_PTR_HPP_INCLUDED 47cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 48cdf0e10cSrcweir #endif 49cdf0e10cSrcweir 50cdf0e10cSrcweir #ifndef INCLUDED_HASH_MAP 51cdf0e10cSrcweir #include <hash_map> 52cdf0e10cSrcweir #define INCLUDED_HASH_MAP 53cdf0e10cSrcweir #endif 54cdf0e10cSrcweir 55cdf0e10cSrcweir //----------------------------------------------- 56cdf0e10cSrcweir 57cdf0e10cSrcweir // constants and data types also for external modules (ScInterpreter et al) 58cdf0e10cSrcweir 59cdf0e10cSrcweir #define MAXCODE 512 /* maximum number of tokens in formula */ 60cdf0e10cSrcweir #define MAXSTRLEN 1024 /* maximum length of input string of one symbol */ 61cdf0e10cSrcweir #define MAXJUMPCOUNT 32 /* maximum number of jumps (ocChose) */ 62cdf0e10cSrcweir 63cdf0e10cSrcweir // flag values of CharTable 64cdf0e10cSrcweir #define SC_COMPILER_C_ILLEGAL 0x00000000 65cdf0e10cSrcweir #define SC_COMPILER_C_CHAR 0x00000001 66cdf0e10cSrcweir #define SC_COMPILER_C_CHAR_BOOL 0x00000002 67cdf0e10cSrcweir #define SC_COMPILER_C_CHAR_WORD 0x00000004 68cdf0e10cSrcweir #define SC_COMPILER_C_CHAR_VALUE 0x00000008 69cdf0e10cSrcweir #define SC_COMPILER_C_CHAR_STRING 0x00000010 70cdf0e10cSrcweir #define SC_COMPILER_C_CHAR_DONTCARE 0x00000020 71cdf0e10cSrcweir #define SC_COMPILER_C_BOOL 0x00000040 72cdf0e10cSrcweir #define SC_COMPILER_C_WORD 0x00000080 73cdf0e10cSrcweir #define SC_COMPILER_C_WORD_SEP 0x00000100 74cdf0e10cSrcweir #define SC_COMPILER_C_VALUE 0x00000200 75cdf0e10cSrcweir #define SC_COMPILER_C_VALUE_SEP 0x00000400 76cdf0e10cSrcweir #define SC_COMPILER_C_VALUE_EXP 0x00000800 77cdf0e10cSrcweir #define SC_COMPILER_C_VALUE_SIGN 0x00001000 78cdf0e10cSrcweir #define SC_COMPILER_C_VALUE_VALUE 0x00002000 79cdf0e10cSrcweir #define SC_COMPILER_C_STRING_SEP 0x00004000 80cdf0e10cSrcweir #define SC_COMPILER_C_NAME_SEP 0x00008000 // there can be only one! '\'' 81cdf0e10cSrcweir #define SC_COMPILER_C_CHAR_IDENT 0x00010000 // identifier (built-in function) or reference start 82cdf0e10cSrcweir #define SC_COMPILER_C_IDENT 0x00020000 // identifier or reference continuation 83cdf0e10cSrcweir #define SC_COMPILER_C_ODF_LBRACKET 0x00040000 // ODF '[' reference bracket 84cdf0e10cSrcweir #define SC_COMPILER_C_ODF_RBRACKET 0x00080000 // ODF ']' reference bracket 85cdf0e10cSrcweir #define SC_COMPILER_C_ODF_LABEL_OP 0x00100000 // ODF '!!' automatic intersection of labels 86cdf0e10cSrcweir #define SC_COMPILER_C_ODF_NAME_MARKER 0x00200000 // ODF '$$' marker that starts a defined (range) name 87cdf0e10cSrcweir #define SC_COMPILER_C_CHAR_NAME 0x00400000 // start character of a defined name 88cdf0e10cSrcweir #define SC_COMPILER_C_NAME 0x00800000 // continuation character of a defined name 89cdf0e10cSrcweir 90cdf0e10cSrcweir #define SC_COMPILER_FILE_TAB_SEP '#' // 'Doc'#Tab 91cdf0e10cSrcweir 92cdf0e10cSrcweir 93cdf0e10cSrcweir class ScDocument; 94cdf0e10cSrcweir class ScMatrix; 95cdf0e10cSrcweir class ScRangeData; 96cdf0e10cSrcweir class ScExternalRefManager; 97cdf0e10cSrcweir class ScTokenArray; 98cdf0e10cSrcweir 99cdf0e10cSrcweir // constants and data types internal to compiler 100cdf0e10cSrcweir 101cdf0e10cSrcweir #if 0 102cdf0e10cSrcweir /* 103cdf0e10cSrcweir OpCode eOp; // OpCode 104cdf0e10cSrcweir formula::StackVar eType; // type of data 105cdf0e10cSrcweir sal_uInt16 nRefCnt; // reference count 106cdf0e10cSrcweir sal_Bool bRaw; // not cloned yet and trimmed to real size 107cdf0e10cSrcweir */ 108cdf0e10cSrcweir #endif 109cdf0e10cSrcweir 110cdf0e10cSrcweir #define SC_TOKEN_FIX_MEMBERS \ 111cdf0e10cSrcweir OpCode eOp; \ 112cdf0e10cSrcweir formula::StackVar eType; \ 113cdf0e10cSrcweir sal_uInt16 nRefCnt; \ 114cdf0e10cSrcweir sal_Bool bRaw; 115cdf0e10cSrcweir 116cdf0e10cSrcweir struct ScDoubleRawToken 117cdf0e10cSrcweir { 118cdf0e10cSrcweir private: 1193d28333aStruckman // SC_TOKEN_FIX_MEMBERS 120*898153d9Struckman OpCode SAL_UNUSED_MEMBER eOp; 121*898153d9Struckman formula::StackVar SAL_UNUSED_MEMBER eType; 122*898153d9Struckman sal_uInt16 SAL_UNUSED_MEMBER nRefCnt; 123*898153d9Struckman sal_Bool SAL_UNUSED_MEMBER bRaw; 124cdf0e10cSrcweir public: 125cdf0e10cSrcweir union 126cdf0e10cSrcweir { // union only to assure alignment identical to ScRawToken 127cdf0e10cSrcweir double nValue; 128cdf0e10cSrcweir struct { 129cdf0e10cSrcweir sal_uInt8 cByte; 130cdf0e10cSrcweir bool bHasForceArray; 131cdf0e10cSrcweir } sbyte; 132cdf0e10cSrcweir }; 133cdf0e10cSrcweir DECL_FIXEDMEMPOOL_NEWDEL( ScDoubleRawToken ); 134cdf0e10cSrcweir }; 135cdf0e10cSrcweir 136cdf0e10cSrcweir struct ScRawToken 137cdf0e10cSrcweir { 138cdf0e10cSrcweir friend class ScCompiler; 139cdf0e10cSrcweir // Friends that use a temporary ScRawToken on the stack (and therefor need 140cdf0e10cSrcweir // the private dtor) and know what they're doing.. 141cdf0e10cSrcweir friend class ScTokenArray; 142cdf0e10cSrcweir friend sal_uInt16 lcl_ScRawTokenOffset(); 143cdf0e10cSrcweir private: 144cdf0e10cSrcweir SC_TOKEN_FIX_MEMBERS 145cdf0e10cSrcweir public: 146cdf0e10cSrcweir union { 147cdf0e10cSrcweir double nValue; 148cdf0e10cSrcweir struct { 149cdf0e10cSrcweir sal_uInt8 cByte; 150cdf0e10cSrcweir bool bHasForceArray; 151cdf0e10cSrcweir } sbyte; 152cdf0e10cSrcweir ScComplexRefData aRef; 153cdf0e10cSrcweir struct { 154cdf0e10cSrcweir sal_uInt16 nFileId; 155cdf0e10cSrcweir sal_Unicode cTabName[MAXSTRLEN+1]; 156cdf0e10cSrcweir ScComplexRefData aRef; 157cdf0e10cSrcweir } extref; 158cdf0e10cSrcweir struct { 159cdf0e10cSrcweir sal_uInt16 nFileId; 160cdf0e10cSrcweir sal_Unicode cName[MAXSTRLEN+1]; 161cdf0e10cSrcweir } extname; 162cdf0e10cSrcweir ScMatrix* pMat; 163cdf0e10cSrcweir sal_uInt16 nIndex; // index into name collection 164cdf0e10cSrcweir sal_Unicode cStr[ MAXSTRLEN+1 ]; // string (up to 255 characters + 0) 165cdf0e10cSrcweir short nJump[MAXJUMPCOUNT+1]; // If/Chose token 166cdf0e10cSrcweir }; 167cdf0e10cSrcweir 168cdf0e10cSrcweir //! other members not initialized ScRawTokenScRawToken169cdf0e10cSrcweir ScRawToken() : bRaw( sal_True ) {} 170cdf0e10cSrcweir private: ~ScRawTokenScRawToken171cdf0e10cSrcweir ~ScRawToken() {} //! only delete via Delete() 172cdf0e10cSrcweir public: 173cdf0e10cSrcweir DECL_FIXEDMEMPOOL_NEWDEL( ScRawToken ); GetTypeScRawToken174cdf0e10cSrcweir formula::StackVar GetType() const { return (formula::StackVar) eType; } GetOpCodeScRawToken175cdf0e10cSrcweir OpCode GetOpCode() const { return (OpCode) eOp; } NewOpCodeScRawToken176cdf0e10cSrcweir void NewOpCode( OpCode e ) { eOp = e; } IncRefScRawToken177cdf0e10cSrcweir void IncRef() { nRefCnt++; } DecRefScRawToken178cdf0e10cSrcweir void DecRef() { if( !--nRefCnt ) Delete(); } GetRefScRawToken179cdf0e10cSrcweir sal_uInt16 GetRef() const { return nRefCnt; } 180cdf0e10cSrcweir SC_DLLPUBLIC void Delete(); 181cdf0e10cSrcweir 182cdf0e10cSrcweir // Use these methods only on tokens that are not part of a token array, 183cdf0e10cSrcweir // since the reference count is cleared! 184cdf0e10cSrcweir void SetOpCode( OpCode eCode ); 185cdf0e10cSrcweir void SetString( const sal_Unicode* pStr ); 186cdf0e10cSrcweir void SetSingleReference( const ScSingleRefData& rRef ); 187cdf0e10cSrcweir void SetDoubleReference( const ScComplexRefData& rRef ); 188cdf0e10cSrcweir void SetDouble( double fVal ); 189cdf0e10cSrcweir //UNUSED2008-05 void SetInt( int nVal ); 190cdf0e10cSrcweir //UNUSED2008-05 void SetMatrix( ScMatrix* p ); 191cdf0e10cSrcweir 192cdf0e10cSrcweir // These methods are ok to use, reference count not cleared. 193cdf0e10cSrcweir //UNUSED2008-05 ScComplexRefData& GetReference(); 194cdf0e10cSrcweir //UNUSED2008-05 void SetReference( ScComplexRefData& rRef ); 195cdf0e10cSrcweir void SetName( sal_uInt16 n ); 196cdf0e10cSrcweir void SetExternalSingleRef( sal_uInt16 nFileId, const String& rTabName, const ScSingleRefData& rRef ); 197cdf0e10cSrcweir void SetExternalDoubleRef( sal_uInt16 nFileId, const String& rTabName, const ScComplexRefData& rRef ); 198cdf0e10cSrcweir void SetExternalName( sal_uInt16 nFileId, const String& rName ); 199cdf0e10cSrcweir void SetMatrix( ScMatrix* p ); 200cdf0e10cSrcweir void SetExternal(const sal_Unicode* pStr); 201cdf0e10cSrcweir 202cdf0e10cSrcweir ScRawToken* Clone() const; // real copy! 203cdf0e10cSrcweir formula::FormulaToken* CreateToken() const; // create typified token 204cdf0e10cSrcweir void Load( SvStream&, sal_uInt16 nVer ); 205cdf0e10cSrcweir 206cdf0e10cSrcweir static xub_StrLen GetStrLen( const sal_Unicode* pStr ); // as long as a "string" is an array GetStrLenBytesScRawToken207cdf0e10cSrcweir static size_t GetStrLenBytes( xub_StrLen nLen ) 208cdf0e10cSrcweir { return nLen * sizeof(sal_Unicode); } GetStrLenBytesScRawToken209cdf0e10cSrcweir static size_t GetStrLenBytes( const sal_Unicode* pStr ) 210cdf0e10cSrcweir { return GetStrLenBytes( GetStrLen( pStr ) ); } 211cdf0e10cSrcweir }; 212cdf0e10cSrcweir 213cdf0e10cSrcweir 214cdf0e10cSrcweir typedef formula::SimpleIntrusiveReference< struct ScRawToken > ScRawTokenRef; 215cdf0e10cSrcweir 216cdf0e10cSrcweir class SC_DLLPUBLIC ScCompiler : public formula::FormulaCompiler 217cdf0e10cSrcweir { 218cdf0e10cSrcweir public: 219cdf0e10cSrcweir 220cdf0e10cSrcweir enum EncodeUrlMode 221cdf0e10cSrcweir { 222cdf0e10cSrcweir ENCODE_BY_GRAMMAR, 223cdf0e10cSrcweir ENCODE_ALWAYS, 224cdf0e10cSrcweir ENCODE_NEVER, 225cdf0e10cSrcweir }; 226cdf0e10cSrcweir 227cdf0e10cSrcweir struct Convention 228cdf0e10cSrcweir { 229cdf0e10cSrcweir const formula::FormulaGrammar::AddressConvention meConv; 230cdf0e10cSrcweir const sal_uLong* mpCharTable; 231cdf0e10cSrcweir 232cdf0e10cSrcweir 233cdf0e10cSrcweir Convention( formula::FormulaGrammar::AddressConvention eConvP ); 234cdf0e10cSrcweir virtual ~Convention(); 235cdf0e10cSrcweir 236cdf0e10cSrcweir virtual void MakeRefStr( rtl::OUStringBuffer& rBuffer, 237cdf0e10cSrcweir const ScCompiler& rCompiler, 238cdf0e10cSrcweir const ScComplexRefData& rRef, 239cdf0e10cSrcweir sal_Bool bSingleRef ) const = 0; 240cdf0e10cSrcweir virtual ::com::sun::star::i18n::ParseResult 241cdf0e10cSrcweir parseAnyToken( const String& rFormula, 242cdf0e10cSrcweir xub_StrLen nSrcPos, 243cdf0e10cSrcweir const CharClass* pCharClass) const = 0; 244cdf0e10cSrcweir 245cdf0e10cSrcweir /** 246cdf0e10cSrcweir * Parse the symbol string and pick up the file name and the external 247cdf0e10cSrcweir * range name. 248cdf0e10cSrcweir * 249cdf0e10cSrcweir * @return true on successful parse, or false otherwise. 250cdf0e10cSrcweir */ 251cdf0e10cSrcweir virtual bool parseExternalName( const String& rSymbol, String& rFile, String& rName, 252cdf0e10cSrcweir const ScDocument* pDoc, 253cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< 254cdf0e10cSrcweir const ::com::sun::star::sheet::ExternalLinkInfo > * pExternalLinks ) const = 0; 255cdf0e10cSrcweir 256cdf0e10cSrcweir virtual String makeExternalNameStr( const String& rFile, const String& rName ) const = 0; 257cdf0e10cSrcweir 258cdf0e10cSrcweir virtual void makeExternalRefStr( ::rtl::OUStringBuffer& rBuffer, const ScCompiler& rCompiler, 259cdf0e10cSrcweir sal_uInt16 nFileId, const String& rTabName, const ScSingleRefData& rRef, 260cdf0e10cSrcweir ScExternalRefManager* pRefMgr ) const = 0; 261cdf0e10cSrcweir 262cdf0e10cSrcweir virtual void makeExternalRefStr( ::rtl::OUStringBuffer& rBuffer, const ScCompiler& rCompiler, 263cdf0e10cSrcweir sal_uInt16 nFileId, const String& rTabName, const ScComplexRefData& rRef, 264cdf0e10cSrcweir ScExternalRefManager* pRefMgr ) const = 0; 265cdf0e10cSrcweir 266cdf0e10cSrcweir enum SpecialSymbolType 267cdf0e10cSrcweir { 268cdf0e10cSrcweir /** 269cdf0e10cSrcweir * Character between sheet name and address. In OOO A1 this is 270cdf0e10cSrcweir * '.', while XL A1 and XL R1C1 this is '!'. 271cdf0e10cSrcweir */ 272cdf0e10cSrcweir SHEET_SEPARATOR, 273cdf0e10cSrcweir 274cdf0e10cSrcweir /** 275cdf0e10cSrcweir * In OOO A1, a sheet name may be prefixed with '$' to indicate an 276cdf0e10cSrcweir * absolute sheet position. 277cdf0e10cSrcweir */ 278cdf0e10cSrcweir ABS_SHEET_PREFIX 279cdf0e10cSrcweir }; 280cdf0e10cSrcweir virtual sal_Unicode getSpecialSymbol( SpecialSymbolType eSymType ) const = 0; 281cdf0e10cSrcweir }; 282cdf0e10cSrcweir friend struct Convention; 283cdf0e10cSrcweir 284cdf0e10cSrcweir private: 285cdf0e10cSrcweir 286cdf0e10cSrcweir 287cdf0e10cSrcweir static CharClass *pCharClassEnglish; // character classification for en_US locale 288cdf0e10cSrcweir static const Convention *pConventions[ formula::FormulaGrammar::CONV_LAST ]; 289cdf0e10cSrcweir 290cdf0e10cSrcweir static const Convention * const pConvOOO_A1; 291cdf0e10cSrcweir static const Convention * const pConvOOO_A1_ODF; 292cdf0e10cSrcweir static const Convention * const pConvXL_A1; 293cdf0e10cSrcweir static const Convention * const pConvXL_R1C1; 294cdf0e10cSrcweir static const Convention * const pConvXL_OOX; 295cdf0e10cSrcweir 296cdf0e10cSrcweir static struct AddInMap 297cdf0e10cSrcweir { 298cdf0e10cSrcweir const char* pODFF; 299cdf0e10cSrcweir const char* pEnglish; 300cdf0e10cSrcweir bool bMapDupToInternal; // when writing ODFF 301cdf0e10cSrcweir const char* pOriginal; // programmatical name 302cdf0e10cSrcweir const char* pUpper; // upper case programmatical name 303cdf0e10cSrcweir } maAddInMap[]; 304cdf0e10cSrcweir static const AddInMap* GetAddInMap(); 305cdf0e10cSrcweir static size_t GetAddInMapCount(); 306cdf0e10cSrcweir 307cdf0e10cSrcweir ScDocument* pDoc; 308cdf0e10cSrcweir ScAddress aPos; 309cdf0e10cSrcweir 310cdf0e10cSrcweir // For CONV_XL_OOX, may be set via API by MOOXML filter. 311cdf0e10cSrcweir ::com::sun::star::uno::Sequence< const ::com::sun::star::sheet::ExternalLinkInfo > maExternalLinks; 312cdf0e10cSrcweir 313cdf0e10cSrcweir sal_Unicode cSymbol[MAXSTRLEN]; // current Symbol 314cdf0e10cSrcweir String aFormula; // formula source code 315cdf0e10cSrcweir xub_StrLen nSrcPos; // tokenizer position (source code) 316cdf0e10cSrcweir ScRawTokenRef pRawToken; 317cdf0e10cSrcweir 318cdf0e10cSrcweir const CharClass* pCharClass; // which character classification is used for parseAnyToken 319cdf0e10cSrcweir sal_uInt16 mnPredetectedReference; // reference when reading ODF, 0 (none), 1 (single) or 2 (double) 320cdf0e10cSrcweir SCsTAB nMaxTab; // last sheet in document 321cdf0e10cSrcweir sal_Int32 mnRangeOpPosInSymbol; // if and where a range operator is in symbol 322cdf0e10cSrcweir const Convention *pConv; 323cdf0e10cSrcweir EncodeUrlMode meEncodeUrlMode; 324cdf0e10cSrcweir bool mbCloseBrackets; // whether to close open brackets automatically, default TRUE 325cdf0e10cSrcweir bool mbExtendedErrorDetection; 326cdf0e10cSrcweir bool mbRewind; // whether symbol is to be rewound to some step during lexical analysis 327cdf0e10cSrcweir 328cdf0e10cSrcweir sal_Bool NextNewToken(bool bInArray = false); 329cdf0e10cSrcweir 330cdf0e10cSrcweir virtual void SetError(sal_uInt16 nError); 331cdf0e10cSrcweir xub_StrLen NextSymbol(bool bInArray); 332cdf0e10cSrcweir sal_Bool IsValue( const String& ); 333cdf0e10cSrcweir sal_Bool IsOpCode( const String&, bool bInArray ); 334cdf0e10cSrcweir sal_Bool IsOpCode2( const String& ); 335cdf0e10cSrcweir sal_Bool IsString(); 336cdf0e10cSrcweir sal_Bool IsReference( const String& ); 337cdf0e10cSrcweir sal_Bool IsSingleReference( const String& ); 338cdf0e10cSrcweir sal_Bool IsPredetectedReference( const String& ); 339cdf0e10cSrcweir sal_Bool IsDoubleReference( const String& ); 340cdf0e10cSrcweir sal_Bool IsMacro( const String& ); 341cdf0e10cSrcweir sal_Bool IsNamedRange( const String& ); 342cdf0e10cSrcweir bool IsExternalNamedRange( const String& rSymbol ); 343cdf0e10cSrcweir sal_Bool IsDBRange( const String& ); 344cdf0e10cSrcweir sal_Bool IsColRowName( const String& ); 345cdf0e10cSrcweir sal_Bool IsBoolean( const String& ); 346cdf0e10cSrcweir void AutoCorrectParsedSymbol(); 347cdf0e10cSrcweir 348cdf0e10cSrcweir void SetRelNameReference(); 349cdf0e10cSrcweir 350cdf0e10cSrcweir static void InitCharClassEnglish(); 351cdf0e10cSrcweir 352cdf0e10cSrcweir public: 353cdf0e10cSrcweir ScCompiler( ScDocument* pDocument, const ScAddress&); 354cdf0e10cSrcweir 355cdf0e10cSrcweir ScCompiler( ScDocument* pDocument, const ScAddress&,ScTokenArray& rArr); 356cdf0e10cSrcweir 357cdf0e10cSrcweir public: 358cdf0e10cSrcweir static void DeInit(); /// all 359cdf0e10cSrcweir 360cdf0e10cSrcweir // for ScAddress::Format() 361cdf0e10cSrcweir static void CheckTabQuotes( String& aTabName, 362cdf0e10cSrcweir const formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_OOO ); 363cdf0e10cSrcweir 364cdf0e10cSrcweir /** Analyzes a string for a 'Doc'#Tab construct, or 'Do''c'#Tab etc.. 365cdf0e10cSrcweir 366cdf0e10cSrcweir @returns the position of the unquoted # hash mark in 'Doc'#Tab, or 367cdf0e10cSrcweir STRING_NOTFOUND if none. */ 368cdf0e10cSrcweir static xub_StrLen GetDocTabPos( const String& rString ); 369cdf0e10cSrcweir 370cdf0e10cSrcweir static sal_Bool EnQuote( String& rStr ); 371cdf0e10cSrcweir sal_Unicode GetNativeAddressSymbol( Convention::SpecialSymbolType eType ) const; 372cdf0e10cSrcweir 373cdf0e10cSrcweir 374cdf0e10cSrcweir // Check if it is a valid english function name 375cdf0e10cSrcweir bool IsEnglishSymbol( const String& rName ); 376cdf0e10cSrcweir 377cdf0e10cSrcweir //! _either_ CompileForFAP _or_ AutoCorrection, _not_ both 378cdf0e10cSrcweir // #i101512# SetCompileForFAP is in formula::FormulaCompiler SetAutoCorrection(sal_Bool bVal)379cdf0e10cSrcweir void SetAutoCorrection( sal_Bool bVal ) 380cdf0e10cSrcweir { bAutoCorrect = bVal; bIgnoreErrors = bVal; } SetCloseBrackets(bool bVal)381cdf0e10cSrcweir void SetCloseBrackets( bool bVal ) { mbCloseBrackets = bVal; } 382cdf0e10cSrcweir void SetRefConvention( const Convention *pConvP ); 383cdf0e10cSrcweir void SetRefConvention( const formula::FormulaGrammar::AddressConvention eConv ); 384cdf0e10cSrcweir 385cdf0e10cSrcweir /// Set symbol map if not empty. 386cdf0e10cSrcweir void SetFormulaLanguage( const OpCodeMapPtr & xMap ); 387cdf0e10cSrcweir 388cdf0e10cSrcweir void SetGrammar( const formula::FormulaGrammar::Grammar eGrammar ); 389cdf0e10cSrcweir 390cdf0e10cSrcweir void SetEncodeUrlMode( EncodeUrlMode eMode ); 391cdf0e10cSrcweir EncodeUrlMode GetEncodeUrlMode() const; 392cdf0e10cSrcweir private: 393cdf0e10cSrcweir /** Set grammar and reference convention from within SetFormulaLanguage() 394cdf0e10cSrcweir or SetGrammar(). 395cdf0e10cSrcweir 396cdf0e10cSrcweir @param eNewGrammar 397cdf0e10cSrcweir The new grammar to be set and the associated reference convention. 398cdf0e10cSrcweir 399cdf0e10cSrcweir @param eOldGrammar 400cdf0e10cSrcweir The previous grammar that was active before SetFormulaLanguage(). 401cdf0e10cSrcweir */ 402cdf0e10cSrcweir void SetGrammarAndRefConvention( 403cdf0e10cSrcweir const formula::FormulaGrammar::Grammar eNewGrammar, 404cdf0e10cSrcweir const formula::FormulaGrammar::Grammar eOldGrammar ); 405cdf0e10cSrcweir public: 406cdf0e10cSrcweir 407cdf0e10cSrcweir /// Set external link info for ScAddress::CONV_XL_OOX. SetExternalLinks(const::com::sun::star::uno::Sequence<const::com::sun::star::sheet::ExternalLinkInfo> & rLinks)408cdf0e10cSrcweir inline void SetExternalLinks( 409cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< 410cdf0e10cSrcweir const ::com::sun::star::sheet::ExternalLinkInfo > & rLinks ) 411cdf0e10cSrcweir { 412cdf0e10cSrcweir maExternalLinks = rLinks; 413cdf0e10cSrcweir } 414cdf0e10cSrcweir 415cdf0e10cSrcweir void CreateStringFromXMLTokenArray( String& rFormula, String& rFormulaNmsp ); 416cdf0e10cSrcweir SetExtendedErrorDetection(bool bVal)417cdf0e10cSrcweir void SetExtendedErrorDetection( bool bVal ) { mbExtendedErrorDetection = bVal; } 418cdf0e10cSrcweir IsCorrected()419cdf0e10cSrcweir sal_Bool IsCorrected() { return bCorrected; } GetCorrectedFormula()420cdf0e10cSrcweir const String& GetCorrectedFormula() { return aCorrectedFormula; } 421cdf0e10cSrcweir 422cdf0e10cSrcweir // Use convention from this->aPos by default 423cdf0e10cSrcweir ScTokenArray* CompileString( const String& rFormula ); 424cdf0e10cSrcweir ScTokenArray* CompileString( const String& rFormula, const String& rFormulaNmsp ); GetDoc() const425cdf0e10cSrcweir const ScDocument* GetDoc() const { return pDoc; } GetPos() const426cdf0e10cSrcweir const ScAddress& GetPos() const { return aPos; } 427cdf0e10cSrcweir 428cdf0e10cSrcweir void MoveRelWrap( SCCOL nMaxCol, SCROW nMaxRow ); 429cdf0e10cSrcweir static void MoveRelWrap( ScTokenArray& rArr, ScDocument* pDoc, const ScAddress& rPos, 430cdf0e10cSrcweir SCCOL nMaxCol, SCROW nMaxRow ); 431cdf0e10cSrcweir 432cdf0e10cSrcweir sal_Bool UpdateNameReference( UpdateRefMode eUpdateRefMode, 433cdf0e10cSrcweir const ScRange&, 434cdf0e10cSrcweir SCsCOL nDx, SCsROW nDy, SCsTAB nDz, 435cdf0e10cSrcweir sal_Bool& rChanged, sal_Bool bSharedFormula = sal_False); 436cdf0e10cSrcweir 437cdf0e10cSrcweir ScRangeData* UpdateReference( UpdateRefMode eUpdateRefMode, 438cdf0e10cSrcweir const ScAddress& rOldPos, const ScRange&, 439cdf0e10cSrcweir SCsCOL nDx, SCsROW nDy, SCsTAB nDz, 440cdf0e10cSrcweir sal_Bool& rChanged, sal_Bool& rRefSizeChanged ); 441cdf0e10cSrcweir 442cdf0e10cSrcweir /// Only once for converted shared formulas, 443cdf0e10cSrcweir /// token array has to be compiled afterwards. 444cdf0e10cSrcweir void UpdateSharedFormulaReference( UpdateRefMode eUpdateRefMode, 445cdf0e10cSrcweir const ScAddress& rOldPos, const ScRange&, 446cdf0e10cSrcweir SCsCOL nDx, SCsROW nDy, SCsTAB nDz ); 447cdf0e10cSrcweir 448cdf0e10cSrcweir ScRangeData* UpdateInsertTab(SCTAB nTable, sal_Bool bIsName ); 449cdf0e10cSrcweir ScRangeData* UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove, sal_Bool bIsName, sal_Bool& bCompile); 450dffa72deSWang Lei // the last parameter is true only when copying a sheet, to update the range name's address 451dffa72deSWang Lei ScRangeData* UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, bool bIsName, bool bOnlyUpdateOwnTab = false ); 452cdf0e10cSrcweir 453cdf0e10cSrcweir sal_Bool HasModifiedRange(); 454cdf0e10cSrcweir 455cdf0e10cSrcweir /** If the character is allowed as first character in sheet names or 456cdf0e10cSrcweir references, includes '$' and '?'. */ IsCharWordChar(String const & rStr,xub_StrLen nPos,const formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO)457cdf0e10cSrcweir static inline sal_Bool IsCharWordChar( String const & rStr, 458cdf0e10cSrcweir xub_StrLen nPos, 459cdf0e10cSrcweir const formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_OOO ) 460cdf0e10cSrcweir { 461cdf0e10cSrcweir sal_Unicode c = rStr.GetChar( nPos ); 462cdf0e10cSrcweir if (c < 128) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir return pConventions[eConv] ? static_cast<sal_Bool>( 465cdf0e10cSrcweir (pConventions[eConv]->mpCharTable[ sal_uInt8(c) ] & SC_COMPILER_C_CHAR_WORD) == SC_COMPILER_C_CHAR_WORD) : 466cdf0e10cSrcweir sal_False; // no convention => assume invalid 467cdf0e10cSrcweir } 468cdf0e10cSrcweir else 469cdf0e10cSrcweir return ScGlobal::pCharClass->isLetterNumeric( rStr, nPos ); 470cdf0e10cSrcweir } 471cdf0e10cSrcweir 472cdf0e10cSrcweir /** If the character is allowed in sheet names, thus may be part of a 473cdf0e10cSrcweir reference, includes '$' and '?' and such. */ IsWordChar(String const & rStr,xub_StrLen nPos,const formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO)474cdf0e10cSrcweir static inline sal_Bool IsWordChar( String const & rStr, 475cdf0e10cSrcweir xub_StrLen nPos, 476cdf0e10cSrcweir const formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_OOO ) 477cdf0e10cSrcweir { 478cdf0e10cSrcweir sal_Unicode c = rStr.GetChar( nPos ); 479cdf0e10cSrcweir if (c < 128) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir return pConventions[eConv] ? static_cast<sal_Bool>( 482cdf0e10cSrcweir (pConventions[eConv]->mpCharTable[ sal_uInt8(c) ] & SC_COMPILER_C_WORD) == SC_COMPILER_C_WORD) : 483cdf0e10cSrcweir sal_False; // convention not known => assume invalid 484cdf0e10cSrcweir } 485cdf0e10cSrcweir else 486cdf0e10cSrcweir return ScGlobal::pCharClass->isLetterNumeric( rStr, nPos ); 487cdf0e10cSrcweir } 488cdf0e10cSrcweir 489cdf0e10cSrcweir /** If the character is allowed as tested by nFlags (SC_COMPILER_C_... 490cdf0e10cSrcweir bits) for all known address conventions. If more than one bit is given 491cdf0e10cSrcweir in nFlags, all bits must match. If bTestLetterNumeric is sal_False and 492cdf0e10cSrcweir char>=128, no LetterNumeric test is done and sal_False is returned. */ IsCharFlagAllConventions(String const & rStr,xub_StrLen nPos,sal_uLong nFlags,bool bTestLetterNumeric=true)493cdf0e10cSrcweir static inline bool IsCharFlagAllConventions( String const & rStr, 494cdf0e10cSrcweir xub_StrLen nPos, 495cdf0e10cSrcweir sal_uLong nFlags, 496cdf0e10cSrcweir bool bTestLetterNumeric = true ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir sal_Unicode c = rStr.GetChar( nPos ); 499cdf0e10cSrcweir if (c < 128) 500cdf0e10cSrcweir { 501cdf0e10cSrcweir for ( int nConv = formula::FormulaGrammar::CONV_UNSPECIFIED; 502cdf0e10cSrcweir ++nConv < formula::FormulaGrammar::CONV_LAST; ) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir if (pConventions[nConv] && 505cdf0e10cSrcweir ((pConventions[nConv]->mpCharTable[ sal_uInt8(c) ] & nFlags) != nFlags)) 506cdf0e10cSrcweir return false; 507cdf0e10cSrcweir // convention not known => assume valid 508cdf0e10cSrcweir } 509cdf0e10cSrcweir return true; 510cdf0e10cSrcweir } 511cdf0e10cSrcweir else if (bTestLetterNumeric) 512cdf0e10cSrcweir return ScGlobal::pCharClass->isLetterNumeric( rStr, nPos ); 513cdf0e10cSrcweir else 514cdf0e10cSrcweir return false; 515cdf0e10cSrcweir } 516cdf0e10cSrcweir 517cdf0e10cSrcweir private: 518cdf0e10cSrcweir // FormulaCompiler 519cdf0e10cSrcweir virtual String FindAddInFunction( const String& rUpperName, sal_Bool bLocalFirst ) const; 520cdf0e10cSrcweir virtual void fillFromAddInCollectionUpperName( NonConstOpCodeMapPtr xMap ) const; 521cdf0e10cSrcweir virtual void fillFromAddInCollectionEnglishName( NonConstOpCodeMapPtr xMap ) const; 522cdf0e10cSrcweir virtual void fillFromAddInMap( NonConstOpCodeMapPtr xMap, formula::FormulaGrammar::Grammar _eGrammar ) const; 523cdf0e10cSrcweir virtual void fillAddInToken(::std::vector< ::com::sun::star::sheet::FormulaOpCodeMapEntry >& _rVec,bool _bIsEnglish) const; 524cdf0e10cSrcweir 525cdf0e10cSrcweir virtual sal_Bool HandleExternalReference(const formula::FormulaToken& _aToken); 526cdf0e10cSrcweir virtual sal_Bool HandleRange(); 527cdf0e10cSrcweir virtual sal_Bool HandleSingleRef(); 528cdf0e10cSrcweir virtual sal_Bool HandleDbData(); 529cdf0e10cSrcweir 530cdf0e10cSrcweir virtual formula::FormulaTokenRef ExtendRangeReference( formula::FormulaToken & rTok1, formula::FormulaToken & rTok2, bool bReuseDoubleRef ); 531cdf0e10cSrcweir virtual void CreateStringFromExternal(rtl::OUStringBuffer& rBuffer, formula::FormulaToken* pTokenP); 532cdf0e10cSrcweir virtual void CreateStringFromSingleRef(rtl::OUStringBuffer& rBuffer,formula::FormulaToken* _pTokenP); 533cdf0e10cSrcweir virtual void CreateStringFromDoubleRef(rtl::OUStringBuffer& rBuffer,formula::FormulaToken* _pTokenP); 534cdf0e10cSrcweir virtual void CreateStringFromMatrix( rtl::OUStringBuffer& rBuffer, formula::FormulaToken* _pTokenP); 535cdf0e10cSrcweir virtual void CreateStringFromIndex(rtl::OUStringBuffer& rBuffer,formula::FormulaToken* _pTokenP); 536cdf0e10cSrcweir virtual void LocalizeString( String& rName ); // modify rName - input: exact name 537cdf0e10cSrcweir virtual sal_Bool IsImportingXML() const; 538cdf0e10cSrcweir 539cdf0e10cSrcweir /// Access the CharTable flags GetCharTableFlags(sal_Unicode c)540cdf0e10cSrcweir inline sal_uLong GetCharTableFlags( sal_Unicode c ) 541cdf0e10cSrcweir { return c < 128 ? pConv->mpCharTable[ sal_uInt8(c) ] : 0; } 542cdf0e10cSrcweir }; 543cdf0e10cSrcweir 544cdf0e10cSrcweir SC_DLLPUBLIC String GetScCompilerNativeSymbol( OpCode eOp ); //CHINA001 545cdf0e10cSrcweir 546cdf0e10cSrcweir #endif 547