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
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 std::vector
<OUString
> aData
;
42 sal_uInt32
GetSize() const { return aData
.size(); }
43 short Add( const OUString
& );
44 short Add( double, SbxDataType
);
45 OUString
Find( sal_uInt32
) const;
50 friend class SbiSymDef
;
51 friend class SbiProcDef
;
53 SbiStringPool
& rStrings
;
54 std::vector
<std::unique_ptr
<SbiSymDef
>> m_Data
;
58 sal_uInt16 nProcId
; // for STATIC-variable
59 sal_uInt16 nCur
; // iterator
61 SbiSymPool( SbiStringPool
&, SbiSymScope
, SbiParser
* pParser_
);
64 void SetParent( SbiSymPool
* p
) { pParent
= p
; }
65 void SetProcId( short n
) { nProcId
= n
; }
66 sal_uInt16
GetSize() const { return m_Data
.size(); }
67 SbiSymScope
GetScope() const { return eScope
; }
68 void SetScope( SbiSymScope s
) { eScope
= s
; }
69 SbiParser
* GetParser() { return pParser
; }
71 SbiSymDef
* AddSym( const OUString
& );
72 SbiProcDef
* AddProc( const OUString
& );
73 void Add( SbiSymDef
* );
74 SbiSymDef
* Find( const OUString
& ); // variable name
75 SbiSymDef
* Get( sal_uInt16
); // find variable per position
76 SbiSymDef
* First(), *Next(); // iterators
78 sal_uInt32
Define( const OUString
& );
79 sal_uInt32
Reference( const OUString
& );
84 class SbiSymDef
{ // general symbol entry
85 friend class SbiSymPool
;
89 SbiSymPool
* pIn
; // parent pool
90 std::unique_ptr
<SbiSymPool
> pPool
; // pool for sub-elements
91 short nLen
; // string length for STRING*n
94 sal_uInt16 nTypeId
; // Dim X AS data type
98 bool bNew
: 1; // true: Dim As New...
99 bool bChained
: 1; // true: symbol is defined in code
100 bool bByVal
: 1; // true: ByVal-parameter
101 bool bOpt
: 1; // true: optional parameter
102 bool bStatic
: 1; // true: STATIC variable
103 bool bAs
: 1; // true: data type defined per AS XXX
104 bool bGlobal
: 1; // true: global variable
105 bool bParamArray
: 1; // true: ParamArray parameter
106 bool bWithEvents
: 1; // true: Declared WithEvents
107 bool bWithBrackets
: 1; // true: Followed by ()
108 sal_uInt16 nDefaultId
; // Symbol number of default value
109 short nFixedStringLength
; // String length in: Dim foo As String*Length
111 SbiSymDef( const OUString
& );
112 virtual ~SbiSymDef();
113 virtual SbiProcDef
* GetProcDef();
114 virtual SbiConstDef
* GetConstDef();
116 SbxDataType
GetType() const { return eType
; }
117 virtual void SetType( SbxDataType
);
118 const OUString
& GetName();
119 SbiSymScope
GetScope() const;
120 sal_uInt32
GetAddr() const { return nChain
; }
121 sal_uInt16
GetId() const { return nId
; }
122 sal_uInt16
GetTypeId() const{ return nTypeId
; }
123 void SetTypeId( sal_uInt16 n
) { nTypeId
= n
; eType
= SbxOBJECT
; }
124 sal_uInt16
GetPos() const { return nPos
; }
125 void SetLen( short n
){ nLen
= n
; }
126 short GetLen() const { return nLen
; }
127 void SetDims( short n
) { nDims
= n
; }
128 short GetDims() const { return nDims
; }
129 bool IsDefined() const{ return bChained
; }
130 void SetOptional() { bOpt
= true; }
131 void SetParamArray() { bParamArray
= true; }
132 void SetWithEvents() { bWithEvents
= true; }
133 void SetWithBrackets(){ bWithBrackets
= true; }
134 void SetByVal( bool bByVal_
) { bByVal
= bByVal_
; }
135 void SetStatic( bool bAsStatic
= true ) { bStatic
= bAsStatic
; }
136 void SetNew() { bNew
= true; }
137 void SetDefinedAs() { bAs
= true; }
138 void SetGlobal(bool b
){ bGlobal
= b
; }
139 void SetDefaultId( sal_uInt16 n
) { nDefaultId
= n
; }
140 sal_uInt16
GetDefaultId() { return nDefaultId
; }
141 bool IsOptional() const{ return bOpt
; }
142 bool IsParamArray() const{ return bParamArray
; }
143 bool IsWithEvents() const{ return bWithEvents
; }
144 bool IsWithBrackets() const{ return bWithBrackets
; }
145 bool IsByVal() const { return bByVal
; }
146 bool IsStatic() const { return bStatic
; }
147 bool IsNew() const { return bNew
; }
148 bool IsDefinedAs() const { return bAs
; }
149 bool IsGlobal() const { return bGlobal
; }
150 short GetFixedStringLength() const { return nFixedStringLength
; }
151 void SetFixedStringLength( short n
) { nFixedStringLength
= n
; }
153 SbiSymPool
& GetPool();
154 sal_uInt32
Define(); // define symbol in code
155 sal_uInt32
Reference(); // reference symbol in code
158 SbiSymDef( const SbiSymDef
& ) = delete;
162 class SbiProcDef
: public SbiSymDef
{ // procedure definition (from basic):
164 SbiSymPool aLabels
; // local jump targets
167 sal_uInt16 nLine1
, nLine2
; // line area
168 PropertyMode mePropMode
; // Marks if this is a property procedure and which
169 OUString maPropName
; // Property name if property procedure (!= proc name)
170 bool bCdecl
: 1; // true: CDECL given
171 bool bPublic
: 1; // true: proc is PUBLIC
172 bool mbProcDecl
: 1; // true: instantiated by SbiParser::ProcDecl
174 SbiProcDef( SbiParser
*, const OUString
&, bool bProcDecl
=false );
175 virtual ~SbiProcDef() override
;
176 virtual SbiProcDef
* GetProcDef() override
;
177 virtual void SetType( SbxDataType
) override
;
178 SbiSymPool
& GetParams() { return aParams
; }
179 SbiSymPool
& GetLabels() { return aLabels
; }
180 SbiSymPool
& GetLocals() { return GetPool();}
181 OUString
& GetLib() { return aLibName
; }
182 OUString
& GetAlias() { return aAlias
; }
183 void SetPublic( bool b
) { bPublic
= b
; }
184 bool IsPublic() const { return bPublic
; }
185 void SetCdecl( bool b
) { bCdecl
= b
; }
186 bool IsCdecl() const { return bCdecl
; }
187 bool IsUsedForProcDecl() const { return mbProcDecl
; }
188 void SetLine1( sal_uInt16 n
) { nLine1
= n
; }
189 sal_uInt16
GetLine1() const { return nLine1
; }
190 void SetLine2( sal_uInt16 n
) { nLine2
= n
; }
191 sal_uInt16
GetLine2() const { return nLine2
; }
192 PropertyMode
getPropertyMode() { return mePropMode
; }
193 void setPropertyMode( PropertyMode ePropMode
);
194 const OUString
& GetPropName() { return maPropName
; }
196 // Match with a forward-declaration. The parameter names are
197 // compared and the forward declaration is replaced by this
198 void Match( SbiProcDef
* pForward
);
201 SbiProcDef( const SbiProcDef
& ) = delete;
205 class SbiConstDef
: public SbiSymDef
210 SbiConstDef( const OUString
& );
211 virtual ~SbiConstDef() override
;
212 virtual SbiConstDef
* GetConstDef() override
;
213 void Set( double, SbxDataType
);
214 void Set( const OUString
& );
215 double GetValue() { return nVal
; }
216 const OUString
& GetString() { return aVal
; }
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */