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