LCOV - code coverage report
Current view: top level - libreoffice/sc/inc - compiler.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 46 78.3 %
Date: 2012-12-27 Functions: 22 27 81.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10