Debian Codegraph @

basic/source/inc/symtbl.hxx

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