LCOV - code coverage report
Current view: top level - basic/source/inc - symtbl.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 53 59 89.8 %
Date: 2014-11-03 Functions: 53 59 89.8 %
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 INCLUDED_BASIC_SOURCE_INC_SYMTBL_HXX
      21             : #define INCLUDED_BASIC_SOURCE_INC_SYMTBL_HXX
      22             : 
      23             : #include <vector>
      24             : #include <boost/ptr_container/ptr_vector.hpp>
      25             : 
      26             : class SbiConstDef;
      27             : class SbiParser;
      28             : class SbiProcDef;
      29             : class SbiStringPool;
      30             : class SbiSymDef;                    // base class
      31             : 
      32             : enum SbiSymScope { SbLOCAL, SbPARAM, SbPUBLIC, SbGLOBAL, SbRTL };
      33             : 
      34             : // The string-pool collects string entries and
      35             : // makes sure that they don't exist twice.
      36             : 
      37             : class SbiStringPool {
      38             :     const OUString aEmpty;
      39             :     std::vector<OUString> aData;
      40             :     SbiParser* pParser;
      41             : public:
      42             :     SbiStringPool( SbiParser* );
      43             :    ~SbiStringPool();
      44         348 :     sal_uInt32 GetSize() const { return aData.size(); }
      45             :     // From 8.4.1999: default changed to true because of #64236 -
      46             :     // change it back to false when the bug is cleanly removed.
      47             :     short Add( const OUString&, bool=true );
      48             :     short Add( double, SbxDataType );
      49             :     const OUString& Find( sal_uInt32 ) const;
      50        8646 :     SbiParser* GetParser() { return pParser; }
      51             : };
      52             : 
      53             : 
      54             : typedef boost::ptr_vector<SbiSymDef> SbiSymbols;
      55             : 
      56             : class SbiSymPool {
      57             :     friend class SbiSymDef;
      58             :     friend class SbiProcDef;
      59             : protected:
      60             :     SbiStringPool& rStrings;
      61             :     SbiSymbols  aData;
      62             :     SbiSymPool* pParent;
      63             :     SbiParser*  pParser;
      64             :     SbiSymScope eScope;
      65             :     sal_uInt16     nProcId;             // for STATIC-variable
      66             :     sal_uInt16     nCur;                // iterator
      67             : public:
      68             :     SbiSymPool( SbiStringPool&, SbiSymScope );
      69             :    ~SbiSymPool();
      70             : 
      71        6872 :     void   SetParent( SbiSymPool* p )   { pParent = p;      }
      72        1620 :     void   SetProcId( short n )         { nProcId = n;      }
      73        2176 :     sal_uInt16 GetSize() const              { return aData.size(); }
      74       45084 :     SbiSymScope GetScope() const        { return eScope;    }
      75        5490 :     void   SetScope( SbiSymScope s )    { eScope = s;       }
      76         552 :     SbiParser* GetParser()              { return pParser;   }
      77             : 
      78             :     SbiSymDef* AddSym( const OUString& );
      79             :     SbiProcDef* AddProc( const OUString& );
      80             :     void Add( SbiSymDef* );
      81             :     SbiSymDef* Find( const OUString& ); // variable name
      82             :     SbiSymDef* Get( sal_uInt16 );     // find variable per position
      83             :     SbiSymDef* First(), *Next();            // iterators
      84             : 
      85             :     sal_uInt32 Define( const OUString& );
      86             :     sal_uInt32 Reference( const OUString& );
      87             :     void   CheckRefs();
      88             : };
      89             : 
      90             : 
      91             : class SbiSymDef {                   // general symbol entry
      92             :     friend class SbiSymPool;
      93             : protected:
      94             :     OUString     aName;
      95             :     SbxDataType eType;
      96             :     SbiSymPool* pIn;                // parent pool
      97             :     SbiSymPool* pPool;              // pool for sub-elements
      98             :     short      nLen;                // string length for STRING*n
      99             :     short      nDims;
     100             :     sal_uInt16     nId;
     101             :     sal_uInt16     nTypeId;             // Dim X AS data type
     102             :     sal_uInt16     nProcId;
     103             :     sal_uInt16     nPos;
     104             :     sal_uInt32     nChain;
     105             :     bool       bNew     : 1;        // true: Dim As New...
     106             :     bool       bChained : 1;        // true: symbol is defined in code
     107             :     bool       bByVal   : 1;        // true: ByVal-parameter
     108             :     bool       bOpt     : 1;        // true: optional parameter
     109             :     bool       bStatic  : 1;        // true: STATIC variable
     110             :     bool       bAs      : 1;        // true: data type defined per AS XXX
     111             :     bool       bGlobal  : 1;        // true: global variable
     112             :     bool       bParamArray : 1;     // true: ParamArray parameter
     113             :     bool       bWithEvents : 1;     // true: Declared WithEvents
     114             :     bool       bWithBrackets : 1;   // true: Followed by ()
     115             :     sal_uInt16     nDefaultId;          // Symbol number of default value
     116             :     short      nFixedStringLength;  // String length in: Dim foo As String*Length
     117             : public:
     118             :     SbiSymDef( const OUString& );
     119             :     virtual ~SbiSymDef();
     120             :     virtual SbiProcDef* GetProcDef();
     121             :     virtual SbiConstDef* GetConstDef();
     122             : 
     123       59070 :     SbxDataType GetType() const { return eType;     }
     124             :     virtual void SetType( SbxDataType );
     125             :     const OUString& GetName();
     126             :     SbiSymScope GetScope() const;
     127             :     sal_uInt16 GetProcId() const{ return nProcId;   }
     128         818 :     sal_uInt32 GetAddr() const  { return nChain;    }
     129       26122 :     sal_uInt16 GetId() const    { return nId;       }
     130        1382 :     sal_uInt16 GetTypeId() const{ return nTypeId;   }
     131         278 :     void       SetTypeId( sal_uInt16 n ) { nTypeId = n; eType = SbxOBJECT; }
     132        2776 :     sal_uInt16 GetPos() const   { return nPos;      }
     133        2046 :     void       SetLen( short n ){ nLen = n;         }
     134           0 :     short      GetLen() const   { return nLen;      }
     135          90 :     void       SetDims( short n ) { nDims = n;      }
     136       17838 :     short      GetDims() const  { return nDims;     }
     137        1162 :     bool       IsDefined() const{ return bChained;  }
     138          92 :     void       SetOptional()    { bOpt = true;      }
     139           0 :     void       SetParamArray()  { bParamArray = true;       }
     140           0 :     void       SetWithEvents()  { bWithEvents = true;       }
     141          38 :     void       SetWithBrackets(){ bWithBrackets = true;     }
     142           8 :     void       SetByVal( bool bByVal_ = true ) { bByVal = bByVal_; }
     143         810 :     void       SetStatic( bool bAsStatic = true )      { bStatic = bAsStatic;  }
     144          56 :     void       SetNew()         { bNew = true;      }
     145        2046 :     void       SetDefinedAs()   { bAs = true;       }
     146          86 :     void       SetGlobal(bool b){ bGlobal = b;  }
     147           0 :     void       SetDefaultId( sal_uInt16 n ) { nDefaultId = n; }
     148         440 :     sal_uInt16 GetDefaultId( void ) { return nDefaultId; }
     149         486 :     bool       IsOptional() const{ return bOpt;     }
     150         440 :     bool       IsParamArray() const{ return bParamArray; }
     151        1698 :     bool       IsWithEvents() const{ return bWithEvents; }
     152         440 :     bool       IsWithBrackets() const{ return bWithBrackets; }
     153         448 :     bool       IsByVal() const  { return bByVal;    }
     154       26718 :     bool       IsStatic() const { return bStatic;   }
     155        3506 :     bool       IsNew() const    { return bNew;      }
     156       17180 :     bool       IsDefinedAs() const { return bAs;    }
     157       15628 :     bool       IsGlobal() const { return bGlobal;   }
     158        1698 :     short      GetFixedStringLength( void ) const { return nFixedStringLength; }
     159           0 :     void       SetFixedStringLength( short n ) { nFixedStringLength = n; }
     160             : 
     161             :     SbiSymPool& GetPool();
     162             :     sal_uInt32     Define();        // define symbol in code
     163             :     sal_uInt32     Reference();     // reference symbol in code
     164             : 
     165             : private:
     166             :     SbiSymDef( const SbiSymDef& );
     167             : 
     168             : };
     169             : 
     170             : class SbiProcDef : public SbiSymDef {   // procedure definition (from basic):
     171             :     SbiSymPool aParams;
     172             :     SbiSymPool aLabels;             // local jump targets
     173             :     OUString aLibName;
     174             :     OUString aAlias;
     175             :     sal_uInt16 nLine1, nLine2;      // line area
     176             :     PropertyMode mePropMode;        // Marks if this is a property procedure and which
     177             :     OUString maPropName;              // Property name if property procedure (!= proc name)
     178             :     bool   bCdecl  : 1;             // true: CDECL given
     179             :     bool   bPublic : 1;             // true: proc is PUBLIC
     180             :     bool   mbProcDecl : 1;          // true: instantiated by SbiParser::ProcDecl
     181             : public:
     182             :     SbiProcDef( SbiParser*, const OUString&, bool bProcDecl=false );
     183             :     virtual ~SbiProcDef();
     184             :     virtual SbiProcDef* GetProcDef() SAL_OVERRIDE;
     185             :     virtual void SetType( SbxDataType ) SAL_OVERRIDE;
     186        3866 :     SbiSymPool& GetParams()         { return aParams;  }
     187        1030 :     SbiSymPool& GetLabels()         { return aLabels;  }
     188        1620 :     SbiSymPool& GetLocals()         { return GetPool();}
     189        2478 :     OUString& GetLib()              { return aLibName; }
     190        1628 :     OUString& GetAlias()            { return aAlias;   }
     191         818 :     void SetPublic( bool b )        { bPublic = b;     }
     192         818 :     bool IsPublic() const           { return bPublic;  }
     193         810 :     void SetCdecl( bool b = true)   { bCdecl = b;      }
     194         818 :     bool IsCdecl() const            { return bCdecl;   }
     195         428 :     bool IsUsedForProcDecl() const  { return mbProcDecl; }
     196         818 :     void SetLine1( sal_uInt16 n )   { nLine1 = n;      }
     197         818 :     sal_uInt16 GetLine1() const     { return nLine1;   }
     198         818 :     void SetLine2( sal_uInt16 n )   { nLine2 = n;      }
     199         818 :     sal_uInt16 GetLine2() const     { return nLine2;   }
     200         818 :     PropertyMode getPropertyMode()  { return mePropMode; }
     201             :     void setPropertyMode( PropertyMode ePropMode );
     202           0 :     const OUString& GetPropName()     { return maPropName; }
     203             : 
     204             :     // Match with a forward-declaration. The parameter names are
     205             :     // compared and the forward declaration is replaced by this
     206             :     void Match( SbiProcDef* pForward );
     207             : 
     208             : private:
     209             :     SbiProcDef( const SbiProcDef& );
     210             : 
     211             : };
     212             : 
     213             : class SbiConstDef : public SbiSymDef
     214             : {
     215             :     double nVal;
     216             :     OUString aVal;
     217             : public:
     218             :     SbiConstDef( const OUString& );
     219             :     virtual ~SbiConstDef();
     220             :     virtual SbiConstDef* GetConstDef() SAL_OVERRIDE;
     221             :     void Set( double, SbxDataType );
     222             :     void Set( const OUString& );
     223         220 :     double GetValue()           { return nVal; }
     224         302 :     const OUString& GetString() { return aVal; }
     225             : };
     226             : 
     227             : 
     228             : #endif
     229             : 
     230             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10