LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / basic / source / inc / symtbl.hxx
blobb8a2f6ebbaad9e17b4c34b07725e84c99992e97f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <memory>
23 #include <vector>
24 #include <basic/sbdef.hxx>
26 class SbiConstDef;
27 class SbiParser;
28 class SbiProcDef;
29 class SbiStringPool;
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.
37 class SbiStringPool {
38 std::vector<OUString> aData;
39 public:
40 SbiStringPool();
41 ~SbiStringPool();
42 sal_uInt32 GetSize() const { return aData.size(); }
43 short Add( const OUString& );
44 short Add( double, SbxDataType );
45 OUString Find( sal_uInt32 ) const;
49 class SbiSymPool final {
50 friend class SbiSymDef;
51 friend class SbiProcDef;
52 SbiStringPool& rStrings;
53 std::vector<std::unique_ptr<SbiSymDef>> m_Data;
54 SbiSymPool* pParent;
55 SbiParser* pParser;
56 SbiSymScope eScope;
57 sal_uInt16 nProcId; // for STATIC-variable
58 sal_uInt16 nCur; // iterator
59 public:
60 SbiSymPool( SbiStringPool&, SbiSymScope, SbiParser* pParser_ );
61 ~SbiSymPool();
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; }
68 SbiParser* GetParser() { return pParser; }
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
77 sal_uInt32 Define( const OUString& );
78 sal_uInt32 Reference( const OUString& );
79 void CheckRefs();
83 class SbiSymDef { // general symbol entry
84 friend class SbiSymPool;
85 protected:
86 OUString aName;
87 SbxDataType eType;
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
109 public:
110 SbiSymDef( const OUString& );
111 virtual ~SbiSymDef();
112 virtual SbiProcDef* GetProcDef();
113 virtual SbiConstDef* GetConstDef();
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; }
132 void SetWithBrackets(){ bWithBrackets = 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; }
150 void SetFixedStringLength( short n ) { nFixedStringLength = n; }
152 SbiSymPool& GetPool();
153 sal_uInt32 Define(); // define symbol in code
154 sal_uInt32 Reference(); // reference symbol in code
156 private:
157 SbiSymDef( const SbiSymDef& ) = delete;
161 class SbiProcDef final : public SbiSymDef { // procedure definition (from basic):
162 SbiSymPool aParams;
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
172 public:
173 SbiProcDef( SbiParser*, const OUString&, bool bProcDecl=false );
174 virtual ~SbiProcDef() override;
175 virtual SbiProcDef* GetProcDef() override;
176 virtual void SetType( SbxDataType ) override;
177 SbiSymPool& GetParams() { return aParams; }
178 SbiSymPool& GetLabels() { return aLabels; }
179 SbiSymPool& GetLocals() { return GetPool();}
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; }
191 PropertyMode getPropertyMode() const { return mePropMode; }
192 void setPropertyMode( PropertyMode ePropMode );
193 const OUString& GetPropName() const { return maPropName; }
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 );
199 private:
200 SbiProcDef( const SbiProcDef& ) = delete;
204 class SbiConstDef final : public SbiSymDef
206 double nVal;
207 OUString aVal;
208 public:
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; }
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */