LibreOffice Module basic (master) 1
symtbl.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <memory>
23#include <vector>
24#include <basic/sbdef.hxx>
25
26class SbiConstDef;
27class SbiParser;
28class SbiProcDef;
29class SbiStringPool;
30class SbiSymDef; // base class
31
33
34// The string-pool collects string entries and
35// makes sure that they don't exist twice.
36
38 std::vector<OUString> aData;
39public:
42 sal_uInt32 GetSize() const { return aData.size(); }
43 short Add( const OUString& );
44 short Add( double, SbxDataType );
45 OUString Find( sal_uInt32 ) const;
46};
47
48
49class SbiSymPool final {
50 friend class SbiSymDef;
51 friend class SbiProcDef;
53 std::vector<std::unique_ptr<SbiSymDef>> m_Data;
57 sal_uInt16 nProcId; // for STATIC-variable
58 sal_uInt16 nCur; // iterator
59public:
62
63 void SetParent( SbiSymPool* p ) { pParent = p; }
64 void SetProcId( short n ) { nProcId = n; }
65 sal_uInt16 GetSize() const { return m_Data.size(); }
66 SbiSymScope GetScope() const { return eScope; }
67 void SetScope( SbiSymScope s ) { eScope = s; }
69
70 SbiSymDef* AddSym( const OUString& );
71 SbiProcDef* AddProc( const OUString& );
72 void Add( SbiSymDef* );
73 SbiSymDef* Find( const OUString&, bool bSearchInParents = true ); // variable name
74 SbiSymDef* Get( sal_uInt16 ); // find variable per position
75 SbiSymDef* First(), *Next(); // iterators
76
77 sal_uInt32 Define( const OUString& );
78 sal_uInt32 Reference( const OUString& );
79 void CheckRefs();
80};
81
82
83class SbiSymDef { // general symbol entry
84 friend class SbiSymPool;
85protected:
86 OUString aName;
88 SbiSymPool* pIn; // parent pool
89 std::unique_ptr<SbiSymPool> pPool; // pool for sub-elements
90 short nLen; // string length for STRING*n
91 short nDims;
92 sal_uInt16 nId;
93 sal_uInt16 nTypeId; // Dim X AS data type
94 sal_uInt16 nProcId;
95 sal_uInt16 nPos;
96 sal_uInt32 nChain;
97 bool bNew : 1; // true: Dim As New...
98 bool bChained : 1; // true: symbol is defined in code
99 bool bByVal : 1; // true: ByVal-parameter
100 bool bOpt : 1; // true: optional parameter
101 bool bStatic : 1; // true: STATIC variable
102 bool bAs : 1; // true: data type defined per AS XXX
103 bool bGlobal : 1; // true: global variable
104 bool bParamArray : 1; // true: ParamArray parameter
105 bool bWithEvents : 1; // true: Declared WithEvents
106 bool bWithBrackets : 1; // true: Followed by ()
107 sal_uInt16 nDefaultId; // Symbol number of default value
108 short nFixedStringLength; // String length in: Dim foo As String*Length
109public:
110 SbiSymDef( OUString );
111 virtual ~SbiSymDef();
112 virtual SbiProcDef* GetProcDef();
113 virtual SbiConstDef* GetConstDef();
114
115 SbxDataType GetType() const { return eType; }
116 virtual void SetType( SbxDataType );
117 const OUString& GetName();
118 SbiSymScope GetScope() const;
119 sal_uInt32 GetAddr() const { return nChain; }
120 sal_uInt16 GetId() const { return nId; }
121 sal_uInt16 GetTypeId() const{ return nTypeId; }
122 void SetTypeId( sal_uInt16 n ) { nTypeId = n; eType = SbxOBJECT; }
123 sal_uInt16 GetPos() const { return nPos; }
124 void SetLen( short n ){ nLen = n; }
125 short GetLen() const { return nLen; }
126 void SetDims( short n ) { nDims = n; }
127 short GetDims() const { return nDims; }
128 bool IsDefined() const{ return bChained; }
129 void SetOptional() { bOpt = true; }
130 void SetParamArray() { bParamArray = true; }
131 void SetWithEvents() { bWithEvents = true; }
133 void SetByVal( bool bByVal_ ) { bByVal = bByVal_; }
134 void SetStatic( bool bAsStatic = true ) { bStatic = bAsStatic; }
135 void SetNew() { bNew = true; }
136 void SetDefinedAs() { bAs = true; }
137 void SetGlobal(bool b){ bGlobal = b; }
138 void SetDefaultId( sal_uInt16 n ) { nDefaultId = n; }
139 sal_uInt16 GetDefaultId() const { return nDefaultId; }
140 bool IsOptional() const{ return bOpt; }
141 bool IsParamArray() const{ return bParamArray; }
142 bool IsWithEvents() const{ return bWithEvents; }
143 bool IsWithBrackets() const{ return bWithBrackets; }
144 bool IsByVal() const { return bByVal; }
145 bool IsStatic() const { return bStatic; }
146 bool IsNew() const { return bNew; }
147 bool IsDefinedAs() const { return bAs; }
148 bool IsGlobal() const { return bGlobal; }
149 short GetFixedStringLength() const { return nFixedStringLength; }
151
153 sal_uInt32 Define(); // define symbol in code
154 sal_uInt32 Reference(); // reference symbol in code
155
156private:
157 SbiSymDef( const SbiSymDef& ) = delete;
158
159};
160
161class SbiProcDef final : public SbiSymDef { // procedure definition (from basic):
163 SbiSymPool aLabels; // local jump targets
164 OUString aLibName;
165 OUString aAlias;
166 sal_uInt16 nLine1, nLine2; // line area
167 PropertyMode mePropMode; // Marks if this is a property procedure and which
168 OUString maPropName; // Property name if property procedure (!= proc name)
169 bool bCdecl : 1; // true: CDECL given
170 bool bPublic : 1; // true: proc is PUBLIC
171 bool mbProcDecl : 1; // true: instantiated by SbiParser::ProcDecl
172public:
173 SbiProcDef( SbiParser*, const OUString&, bool bProcDecl=false );
174 virtual ~SbiProcDef() override;
175 virtual SbiProcDef* GetProcDef() override;
176 virtual void SetType( SbxDataType ) override;
180 OUString& GetLib() { return aLibName; }
181 OUString& GetAlias() { return aAlias; }
182 void SetPublic( bool b ) { bPublic = b; }
183 bool IsPublic() const { return bPublic; }
184 void SetCdecl( bool b ) { bCdecl = b; }
185 bool IsCdecl() const { return bCdecl; }
186 bool IsUsedForProcDecl() const { return mbProcDecl; }
187 void SetLine1( sal_uInt16 n ) { nLine1 = n; }
188 sal_uInt16 GetLine1() const { return nLine1; }
189 void SetLine2( sal_uInt16 n ) { nLine2 = n; }
190 sal_uInt16 GetLine2() const { return nLine2; }
192 void setPropertyMode( PropertyMode ePropMode );
193 const OUString& GetPropName() const { return maPropName; }
194
195 // Match with a forward-declaration. The parameter names are
196 // compared and the forward declaration is replaced by this
197 void Match( SbiProcDef* pForward );
198
199private:
200 SbiProcDef( const SbiProcDef& ) = delete;
201
202};
203
204class SbiConstDef final : public SbiSymDef
205{
206 double nVal;
207 OUString aVal;
208public:
209 SbiConstDef( const OUString& );
210 virtual ~SbiConstDef() override;
211 virtual SbiConstDef* GetConstDef() override;
212 void Set( double, SbxDataType );
213 void Set( const OUString& );
214 double GetValue() const { return nVal; }
215 const OUString& GetString() const { return aVal; }
216};
217
218
219/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString aVal
Definition: symtbl.hxx:207
virtual SbiConstDef * GetConstDef() override
Definition: symtbl.cxx:529
void Set(double, SbxDataType)
Definition: symtbl.cxx:516
double GetValue() const
Definition: symtbl.hxx:214
const OUString & GetString() const
Definition: symtbl.hxx:215
double nVal
Definition: symtbl.hxx:206
SbiConstDef(const OUString &)
Definition: symtbl.cxx:510
virtual ~SbiConstDef() override
Definition: symtbl.cxx:526
void SetLine1(sal_uInt16 n)
Definition: symtbl.hxx:187
PropertyMode mePropMode
Definition: symtbl.hxx:167
OUString & GetLib()
Definition: symtbl.hxx:180
OUString maPropName
Definition: symtbl.hxx:168
sal_uInt16 nLine2
Definition: symtbl.hxx:166
sal_uInt16 GetLine1() const
Definition: symtbl.hxx:188
OUString aLibName
Definition: symtbl.hxx:164
bool IsUsedForProcDecl() const
Definition: symtbl.hxx:186
void setPropertyMode(PropertyMode ePropMode)
Definition: symtbl.cxx:486
void Match(SbiProcDef *pForward)
Definition: symtbl.cxx:446
SbiProcDef(SbiParser *, const OUString &, bool bProcDecl=false)
Definition: symtbl.cxx:407
OUString & GetAlias()
Definition: symtbl.hxx:181
const OUString & GetPropName() const
Definition: symtbl.hxx:193
bool bCdecl
Definition: symtbl.hxx:169
SbiSymPool & GetParams()
Definition: symtbl.hxx:177
SbiProcDef(const SbiProcDef &)=delete
virtual SbiProcDef * GetProcDef() override
Definition: symtbl.cxx:431
bool IsCdecl() const
Definition: symtbl.hxx:185
sal_uInt16 nLine1
Definition: symtbl.hxx:166
SbiSymPool & GetLabels()
Definition: symtbl.hxx:178
PropertyMode getPropertyMode() const
Definition: symtbl.hxx:191
void SetLine2(sal_uInt16 n)
Definition: symtbl.hxx:189
SbiSymPool & GetLocals()
Definition: symtbl.hxx:179
OUString aAlias
Definition: symtbl.hxx:165
virtual void SetType(SbxDataType) override
Definition: symtbl.cxx:436
sal_uInt16 GetLine2() const
Definition: symtbl.hxx:190
void SetCdecl(bool b)
Definition: symtbl.hxx:184
SbiSymPool aParams
Definition: symtbl.hxx:162
bool IsPublic() const
Definition: symtbl.hxx:183
virtual ~SbiProcDef() override
Definition: symtbl.cxx:428
SbiSymPool aLabels
Definition: symtbl.hxx:163
bool bPublic
Definition: symtbl.hxx:170
bool mbProcDecl
Definition: symtbl.hxx:171
void SetPublic(bool b)
Definition: symtbl.hxx:182
OUString Find(sal_uInt32) const
Definition: symtbl.cxx:43
short Add(const OUString &)
Definition: symtbl.cxx:51
sal_uInt32 GetSize() const
Definition: symtbl.hxx:42
std::vector< OUString > aData
Definition: symtbl.hxx:38
~SbiStringPool()
Definition: symtbl.cxx:40
void SetOptional()
Definition: symtbl.hxx:129
OUString aName
Definition: symtbl.hxx:86
short nLen
Definition: symtbl.hxx:90
SbiSymScope GetScope() const
Definition: symtbl.cxx:394
sal_uInt16 GetPos() const
Definition: symtbl.hxx:123
virtual SbiProcDef * GetProcDef()
Definition: symtbl.cxx:310
bool IsGlobal() const
Definition: symtbl.hxx:148
void SetLen(short n)
Definition: symtbl.hxx:124
sal_uInt16 nPos
Definition: symtbl.hxx:95
bool IsWithBrackets() const
Definition: symtbl.hxx:143
sal_uInt16 GetId() const
Definition: symtbl.hxx:120
virtual SbiConstDef * GetConstDef()
Definition: symtbl.cxx:315
bool bAs
Definition: symtbl.hxx:102
sal_uInt32 GetAddr() const
Definition: symtbl.hxx:119
sal_uInt16 nId
Definition: symtbl.hxx:92
SbiSymDef(OUString)
Definition: symtbl.cxx:280
SbxDataType eType
Definition: symtbl.hxx:87
void SetNew()
Definition: symtbl.hxx:135
short GetDims() const
Definition: symtbl.hxx:127
bool IsParamArray() const
Definition: symtbl.hxx:141
sal_uInt32 Define()
Definition: symtbl.cxx:369
sal_uInt16 nTypeId
Definition: symtbl.hxx:93
bool bStatic
Definition: symtbl.hxx:101
sal_uInt16 GetTypeId() const
Definition: symtbl.hxx:121
short nFixedStringLength
Definition: symtbl.hxx:108
short GetLen() const
Definition: symtbl.hxx:125
bool bOpt
Definition: symtbl.hxx:100
SbiSymPool & GetPool()
Definition: symtbl.cxx:385
SbxDataType GetType() const
Definition: symtbl.hxx:115
bool bWithBrackets
Definition: symtbl.hxx:106
bool IsStatic() const
Definition: symtbl.hxx:145
void SetDefaultId(sal_uInt16 n)
Definition: symtbl.hxx:138
bool IsDefined() const
Definition: symtbl.hxx:128
void SetParamArray()
Definition: symtbl.hxx:130
sal_uInt32 Reference()
Definition: symtbl.cxx:357
sal_uInt32 nChain
Definition: symtbl.hxx:96
sal_uInt16 nDefaultId
Definition: symtbl.hxx:107
bool bGlobal
Definition: symtbl.hxx:103
const OUString & GetName()
Definition: symtbl.cxx:321
bool IsNew() const
Definition: symtbl.hxx:146
sal_uInt16 nProcId
Definition: symtbl.hxx:94
void SetDefinedAs()
Definition: symtbl.hxx:136
bool bWithEvents
Definition: symtbl.hxx:105
short GetFixedStringLength() const
Definition: symtbl.hxx:149
bool bParamArray
Definition: symtbl.hxx:104
short nDims
Definition: symtbl.hxx:91
sal_uInt16 GetDefaultId() const
Definition: symtbl.hxx:139
bool IsByVal() const
Definition: symtbl.hxx:144
bool IsOptional() const
Definition: symtbl.hxx:140
virtual ~SbiSymDef()
Definition: symtbl.cxx:306
bool bChained
Definition: symtbl.hxx:98
void SetGlobal(bool b)
Definition: symtbl.hxx:137
void SetTypeId(sal_uInt16 n)
Definition: symtbl.hxx:122
SbiSymPool * pIn
Definition: symtbl.hxx:88
bool bByVal
Definition: symtbl.hxx:99
std::unique_ptr< SbiSymPool > pPool
Definition: symtbl.hxx:89
void SetDims(short n)
Definition: symtbl.hxx:126
void SetWithBrackets()
Definition: symtbl.hxx:132
bool IsWithEvents() const
Definition: symtbl.hxx:142
void SetStatic(bool bAsStatic=true)
Definition: symtbl.hxx:134
virtual void SetType(SbxDataType)
Definition: symtbl.cxx:331
void SetFixedStringLength(short n)
Definition: symtbl.hxx:150
void SetByVal(bool bByVal_)
Definition: symtbl.hxx:133
bool IsDefinedAs() const
Definition: symtbl.hxx:147
SbiSymDef(const SbiSymDef &)=delete
bool bNew
Definition: symtbl.hxx:97
void SetWithEvents()
Definition: symtbl.hxx:131
~SbiSymPool()
Definition: symtbl.cxx:120
SbiSymDef * First()
Definition: symtbl.cxx:124
std::vector< std::unique_ptr< SbiSymDef > > m_Data
Definition: symtbl.hxx:53
sal_uInt32 Reference(const OUString &)
Definition: symtbl.cxx:256
sal_uInt16 nCur
Definition: symtbl.hxx:58
SbiSymDef * Next()
Definition: symtbl.cxx:130
SbiSymScope GetScope() const
Definition: symtbl.hxx:66
void SetProcId(short n)
Definition: symtbl.hxx:64
SbiSymPool(SbiStringPool &, SbiSymScope, SbiParser *pParser_)
Definition: symtbl.cxx:110
SbiSymDef * Find(const OUString &, bool bSearchInParents=true)
Definition: symtbl.cxx:202
SbiProcDef * AddProc(const OUString &)
Definition: symtbl.cxx:150
SbiParser * pParser
Definition: symtbl.hxx:55
void SetScope(SbiSymScope s)
Definition: symtbl.hxx:67
sal_uInt32 Define(const OUString &)
Definition: symtbl.cxx:239
SbiParser * GetParser()
Definition: symtbl.hxx:68
SbiSymScope eScope
Definition: symtbl.hxx:56
SbiSymDef * Get(sal_uInt16)
Definition: symtbl.cxx:227
void SetParent(SbiSymPool *p)
Definition: symtbl.hxx:63
void Add(SbiSymDef *)
Definition: symtbl.cxx:164
SbiSymPool * pParent
Definition: symtbl.hxx:54
sal_uInt16 nProcId
Definition: symtbl.hxx:57
SbiSymDef * AddSym(const OUString &)
Definition: symtbl.cxx:139
sal_uInt16 GetSize() const
Definition: symtbl.hxx:65
void CheckRefs()
Definition: symtbl.cxx:269
SbiStringPool & rStrings
Definition: symtbl.hxx:52
void * p
sal_Int64 n
PropertyMode
Definition: sbdef.hxx:66
SbxDataType
Definition: sbxdef.hxx:37
@ SbxOBJECT
Definition: sbxdef.hxx:47
SbiSymScope
Definition: symtbl.hxx:32
@ SbPARAM
Definition: symtbl.hxx:32
@ SbPUBLIC
Definition: symtbl.hxx:32
@ SbRTL
Definition: symtbl.hxx:32
@ SbLOCAL
Definition: symtbl.hxx:32
@ SbGLOBAL
Definition: symtbl.hxx:32