sw a11y: clang-format SidebarWinAccessible code
[LibreOffice.git] / unoidl / source / sourceprovider-scanner.hxx
blob08ed189f9f6ba252ca4e51b0c4d8eb6fb0223353
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/.
8 */
10 #pragma once
12 #include <sal/config.h>
14 #include <cassert>
15 #include <map>
16 #include <set>
17 #include <utility>
18 #include <vector>
20 #include <rtl/ref.hxx>
21 #include <rtl/ustring.hxx>
22 #include <sal/types.h>
23 #include <salhelper/simplereferenceobject.hxx>
24 #include <unoidl/unoidl.hxx>
26 #include "sourceprovider-parser-requires.hxx"
27 #include <sourceprovider-parser.hxx>
29 namespace unoidl::detail {
31 struct SourceProviderScannerData;
33 class SourceProviderEntityPad: public salhelper::SimpleReferenceObject {
34 public:
35 bool isPublished() const { return published_; }
37 protected:
38 explicit SourceProviderEntityPad(bool published): published_(published) {}
40 virtual ~SourceProviderEntityPad() override {}
42 private:
43 bool const published_;
46 class SourceProviderEnumTypeEntityPad: public SourceProviderEntityPad {
47 public:
48 explicit SourceProviderEnumTypeEntityPad(bool published):
49 SourceProviderEntityPad(published)
52 std::vector<unoidl::EnumTypeEntity::Member> members;
54 private:
55 virtual ~SourceProviderEnumTypeEntityPad() noexcept override {}
58 class SourceProviderPlainStructTypeEntityPad: public SourceProviderEntityPad {
59 public:
60 SourceProviderPlainStructTypeEntityPad(
61 bool published, const OUString & theBaseName,
62 rtl::Reference<unoidl::PlainStructTypeEntity> const & theBaseEntity):
63 SourceProviderEntityPad(published), baseName(theBaseName),
64 baseEntity(theBaseEntity)
65 { assert(theBaseName.isEmpty() != theBaseEntity.is()); }
67 OUString const baseName;
68 rtl::Reference<unoidl::PlainStructTypeEntity> const baseEntity;
69 std::vector<unoidl::PlainStructTypeEntity::Member> members;
71 private:
72 virtual ~SourceProviderPlainStructTypeEntityPad() noexcept override {}
75 class SourceProviderPolymorphicStructTypeTemplateEntityPad:
76 public SourceProviderEntityPad
78 public:
79 explicit SourceProviderPolymorphicStructTypeTemplateEntityPad(bool published)
80 : SourceProviderEntityPad(published)
83 std::vector<OUString> typeParameters;
84 std::vector<unoidl::PolymorphicStructTypeTemplateEntity::Member> members;
86 private:
87 virtual ~SourceProviderPolymorphicStructTypeTemplateEntityPad() noexcept override {}
90 class SourceProviderExceptionTypeEntityPad: public SourceProviderEntityPad {
91 public:
92 SourceProviderExceptionTypeEntityPad(
93 bool published, const OUString & theBaseName,
94 rtl::Reference<unoidl::ExceptionTypeEntity> const & theBaseEntity):
95 SourceProviderEntityPad(published), baseName(theBaseName),
96 baseEntity(theBaseEntity)
97 { assert(theBaseName.isEmpty() != theBaseEntity.is()); }
99 OUString const baseName;
100 rtl::Reference<unoidl::ExceptionTypeEntity> const baseEntity;
101 std::vector<unoidl::ExceptionTypeEntity::Member> members;
103 private:
104 virtual ~SourceProviderExceptionTypeEntityPad() noexcept override {}
107 class SourceProviderInterfaceTypeEntityPad: public SourceProviderEntityPad {
108 public:
109 struct DirectBase {
110 DirectBase(
111 OUString theName,
112 rtl::Reference<unoidl::InterfaceTypeEntity> const & theEntity,
113 std::vector<OUString>&& theAnnotations):
114 name(std::move(theName)), entity(theEntity), annotations(std::move(theAnnotations))
115 { assert(theEntity.is()); }
117 OUString name;
118 rtl::Reference<unoidl::InterfaceTypeEntity> entity;
119 std::vector<OUString> annotations;
122 enum BaseKind {
123 BASE_INDIRECT_OPTIONAL, BASE_DIRECT_OPTIONAL, BASE_INDIRECT_MANDATORY,
124 BASE_DIRECT_MANDATORY
127 struct Member {
128 OUString mandatory;
129 std::set<OUString> optional;
131 explicit Member(OUString theMandatory): mandatory(std::move(theMandatory)) {}
134 SourceProviderInterfaceTypeEntityPad(bool published, bool theSingleBase):
135 SourceProviderEntityPad(published), singleBase(theSingleBase)
138 bool addDirectBase(
139 YYLTYPE location, yyscan_t yyscanner, SourceProviderScannerData * data,
140 DirectBase const & base, bool optional);
142 bool addDirectMember(
143 YYLTYPE location, yyscan_t yyscanner, SourceProviderScannerData * data,
144 OUString const & name);
146 bool singleBase;
147 std::vector<DirectBase> directMandatoryBases;
148 std::vector<DirectBase> directOptionalBases;
149 std::vector<unoidl::InterfaceTypeEntity::Attribute> directAttributes;
150 std::vector<unoidl::InterfaceTypeEntity::Method> directMethods;
151 std::map<OUString, BaseKind> allBases;
152 std::map<OUString, Member> allMembers;
154 private:
155 virtual ~SourceProviderInterfaceTypeEntityPad() noexcept override {}
157 bool checkBaseClashes(
158 YYLTYPE location, yyscan_t yyscanner, SourceProviderScannerData * data,
159 OUString const & name,
160 rtl::Reference<unoidl::InterfaceTypeEntity> const & entity,
161 bool direct, bool optional, bool outerOptional,
162 std::set<OUString> * seen) const;
164 bool checkMemberClashes(
165 YYLTYPE location, yyscan_t yyscanner, SourceProviderScannerData * data,
166 std::u16string_view interfaceName, OUString const & memberName,
167 bool checkOptional) const;
169 bool addBase(
170 YYLTYPE location, yyscan_t yyscanner, SourceProviderScannerData * data,
171 OUString const & directBaseName, OUString const & name,
172 rtl::Reference<unoidl::InterfaceTypeEntity> const & entity, bool direct,
173 bool optional);
175 bool addOptionalBaseMembers(
176 YYLTYPE location, yyscan_t yyscanner, SourceProviderScannerData * data,
177 OUString const & name,
178 rtl::Reference<unoidl::InterfaceTypeEntity> const & entity);
181 class SourceProviderConstantGroupEntityPad: public SourceProviderEntityPad {
182 public:
183 explicit SourceProviderConstantGroupEntityPad(bool published):
184 SourceProviderEntityPad(published)
187 std::vector<unoidl::ConstantGroupEntity::Member> members;
189 private:
190 virtual ~SourceProviderConstantGroupEntityPad() noexcept override {}
193 class SourceProviderSingleInterfaceBasedServiceEntityPad:
194 public SourceProviderEntityPad
196 public:
197 struct Constructor {
198 struct Parameter {
199 Parameter(
200 OUString theName,
201 SourceProviderType theType, bool theRest):
202 name(std::move(theName)), type(std::move(theType)), rest(theRest)
205 OUString name;
207 SourceProviderType type;
209 bool rest;
212 Constructor(
213 OUString theName,
214 std::vector< OUString >&& theAnnotations):
215 name(std::move(theName)), annotations(std::move(theAnnotations))
218 OUString name;
220 std::vector< Parameter > parameters;
222 std::vector< OUString > exceptions;
224 std::vector< OUString > annotations;
227 explicit SourceProviderSingleInterfaceBasedServiceEntityPad(
228 bool published, OUString theBase):
229 SourceProviderEntityPad(published), base(std::move(theBase))
232 OUString const base;
233 std::vector<Constructor> constructors;
235 private:
236 virtual ~SourceProviderSingleInterfaceBasedServiceEntityPad() noexcept override {}
239 class SourceProviderAccumulationBasedServiceEntityPad:
240 public SourceProviderEntityPad
242 public:
243 explicit SourceProviderAccumulationBasedServiceEntityPad(bool published):
244 SourceProviderEntityPad(published)
247 std::vector<unoidl::AnnotatedReference> directMandatoryBaseServices;
248 std::vector<unoidl::AnnotatedReference> directOptionalBaseServices;
249 std::vector<unoidl::AnnotatedReference> directMandatoryBaseInterfaces;
250 std::vector<unoidl::AnnotatedReference> directOptionalBaseInterfaces;
251 std::vector<unoidl::AccumulationBasedServiceEntity::Property>
252 directProperties;
254 private:
255 virtual ~SourceProviderAccumulationBasedServiceEntityPad() noexcept override {}
258 struct SourceProviderEntity {
259 enum Kind {
260 KIND_EXTERNAL, KIND_LOCAL, KIND_INTERFACE_DECL,
261 KIND_PUBLISHED_INTERFACE_DECL, KIND_MODULE
264 explicit SourceProviderEntity(
265 Kind theKind, rtl::Reference<unoidl::Entity> const & externalEntity):
266 kind(theKind), entity(externalEntity)
267 { assert(theKind <= KIND_LOCAL); assert(externalEntity.is()); }
269 explicit SourceProviderEntity(
270 rtl::Reference<SourceProviderEntityPad> const & localPad):
271 kind(KIND_LOCAL), pad(localPad)
272 { assert(localPad.is()); }
274 explicit SourceProviderEntity(Kind theKind): kind(theKind)
275 { assert(theKind >= KIND_INTERFACE_DECL); }
277 SourceProviderEntity(): // needed for std::map::operator []
278 kind() // avoid false warnings about uninitialized members
281 Kind kind;
282 rtl::Reference<unoidl::Entity> entity;
283 rtl::Reference<SourceProviderEntityPad> pad;
286 struct SourceProviderScannerData {
287 explicit SourceProviderScannerData(
288 rtl::Reference<unoidl::Manager> theManager):
289 manager(std::move(theManager)),
290 sourcePosition(), sourceEnd(),
291 // avoid false warnings about uninitialized members
292 errorLine(0), publishedContext(false)
293 { assert(manager.is()); }
295 void setSource(void const * address, sal_uInt64 size) {
296 sourcePosition = static_cast<char const *>(address);
297 sourceEnd = sourcePosition + size;
300 rtl::Reference<unoidl::Manager> manager;
302 char const * sourcePosition;
303 char const * sourceEnd;
304 YYLTYPE errorLine;
305 OString parserError;
306 OUString errorMessage;
308 std::map<OUString, SourceProviderEntity> entities;
309 std::vector<OUString> modules;
310 OUString currentName;
311 bool publishedContext;
314 bool parse(OUString const & uri, SourceProviderScannerData * data);
318 int yylex_init_extra(
319 unoidl::detail::SourceProviderScannerData * user_defined,
320 yyscan_t * yyscanner);
322 int yylex_destroy(yyscan_t yyscanner);
324 int yylex(YYSTYPE * yylval_param, YYLTYPE * yylloc_param, yyscan_t yyscanner);
326 unoidl::detail::SourceProviderScannerData * yyget_extra(yyscan_t yyscanner);
328 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */