1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_BASIC_SOURCE_INC_SYMTBL_HXX
21 #define INCLUDED_BASIC_SOURCE_INC_SYMTBL_HXX
24 #include <boost/ptr_container/ptr_vector.hpp>
30 class SbiSymDef
; // base class
32 enum SbiSymScope
{ SbLOCAL
, SbPARAM
, SbPUBLIC
, SbGLOBAL
, SbRTL
};
34 // The string-pool collects string entries and
35 // makes sure that they don't exist twice.
38 const OUString aEmpty
;
39 std::vector
<OUString
> aData
;
42 SbiStringPool( SbiParser
* );
44 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 SbiParser
* GetParser() { return pParser
; }
54 typedef boost::ptr_vector
<SbiSymDef
> SbiSymbols
;
57 friend class SbiSymDef
;
58 friend class SbiProcDef
;
60 SbiStringPool
& rStrings
;
65 sal_uInt16 nProcId
; // for STATIC-variable
66 sal_uInt16 nCur
; // iterator
68 SbiSymPool( SbiStringPool
&, SbiSymScope
);
71 void SetParent( SbiSymPool
* p
) { pParent
= p
; }
72 void SetProcId( short n
) { nProcId
= n
; }
73 sal_uInt16
GetSize() const { return aData
.size(); }
74 SbiSymScope
GetScope() const { return eScope
; }
75 void SetScope( SbiSymScope s
) { eScope
= s
; }
76 SbiParser
* GetParser() { return pParser
; }
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
85 sal_uInt32
Define( const OUString
& );
86 sal_uInt32
Reference( const OUString
& );
91 class SbiSymDef
{ // general symbol entry
92 friend class SbiSymPool
;
96 SbiSymPool
* pIn
; // parent pool
97 SbiSymPool
* pPool
; // pool for sub-elements
98 short nLen
; // string length for STRING*n
101 sal_uInt16 nTypeId
; // Dim X AS data type
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
118 SbiSymDef( const OUString
& );
119 virtual ~SbiSymDef();
120 virtual SbiProcDef
* GetProcDef();
121 virtual SbiConstDef
* GetConstDef();
123 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 sal_uInt32
GetAddr() const { return nChain
; }
129 sal_uInt16
GetId() const { return nId
; }
130 sal_uInt16
GetTypeId() const{ return nTypeId
; }
131 void SetTypeId( sal_uInt16 n
) { nTypeId
= n
; eType
= SbxOBJECT
; }
132 sal_uInt16
GetPos() const { return nPos
; }
133 void SetLen( short n
){ nLen
= n
; }
134 short GetLen() const { return nLen
; }
135 void SetDims( short n
) { nDims
= n
; }
136 short GetDims() const { return nDims
; }
137 bool IsDefined() const{ return bChained
; }
138 void SetOptional() { bOpt
= true; }
139 void SetParamArray() { bParamArray
= true; }
140 void SetWithEvents() { bWithEvents
= true; }
141 void SetWithBrackets(){ bWithBrackets
= true; }
142 void SetByVal( bool bByVal_
= true ) { bByVal
= bByVal_
; }
143 void SetStatic( bool bAsStatic
= true ) { bStatic
= bAsStatic
; }
144 void SetNew() { bNew
= true; }
145 void SetDefinedAs() { bAs
= true; }
146 void SetGlobal(bool b
){ bGlobal
= b
; }
147 void SetDefaultId( sal_uInt16 n
) { nDefaultId
= n
; }
148 sal_uInt16
GetDefaultId() { return nDefaultId
; }
149 bool IsOptional() const{ return bOpt
; }
150 bool IsParamArray() const{ return bParamArray
; }
151 bool IsWithEvents() const{ return bWithEvents
; }
152 bool IsWithBrackets() const{ return bWithBrackets
; }
153 bool IsByVal() const { return bByVal
; }
154 bool IsStatic() const { return bStatic
; }
155 bool IsNew() const { return bNew
; }
156 bool IsDefinedAs() const { return bAs
; }
157 bool IsGlobal() const { return bGlobal
; }
158 short GetFixedStringLength() const { return nFixedStringLength
; }
159 void SetFixedStringLength( short n
) { nFixedStringLength
= n
; }
161 SbiSymPool
& GetPool();
162 sal_uInt32
Define(); // define symbol in code
163 sal_uInt32
Reference(); // reference symbol in code
166 SbiSymDef( const SbiSymDef
& ) SAL_DELETED_FUNCTION
;
170 class SbiProcDef
: public SbiSymDef
{ // procedure definition (from basic):
172 SbiSymPool aLabels
; // local jump targets
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
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 SbiSymPool
& GetParams() { return aParams
; }
187 SbiSymPool
& GetLabels() { return aLabels
; }
188 SbiSymPool
& GetLocals() { return GetPool();}
189 OUString
& GetLib() { return aLibName
; }
190 OUString
& GetAlias() { return aAlias
; }
191 void SetPublic( bool b
) { bPublic
= b
; }
192 bool IsPublic() const { return bPublic
; }
193 void SetCdecl( bool b
= true) { bCdecl
= b
; }
194 bool IsCdecl() const { return bCdecl
; }
195 bool IsUsedForProcDecl() const { return mbProcDecl
; }
196 void SetLine1( sal_uInt16 n
) { nLine1
= n
; }
197 sal_uInt16
GetLine1() const { return nLine1
; }
198 void SetLine2( sal_uInt16 n
) { nLine2
= n
; }
199 sal_uInt16
GetLine2() const { return nLine2
; }
200 PropertyMode
getPropertyMode() { return mePropMode
; }
201 void setPropertyMode( PropertyMode ePropMode
);
202 const OUString
& GetPropName() { return maPropName
; }
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
);
209 SbiProcDef( const SbiProcDef
& ) SAL_DELETED_FUNCTION
;
213 class SbiConstDef
: public SbiSymDef
218 SbiConstDef( const OUString
& );
219 virtual ~SbiConstDef();
220 virtual SbiConstDef
* GetConstDef() SAL_OVERRIDE
;
221 void Set( double, SbxDataType
);
222 void Set( const OUString
& );
223 double GetValue() { return nVal
; }
224 const OUString
& GetString() { return aVal
; }
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */