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/.
12 #include <sal/config.h>
19 #include <rtl/ref.hxx>
20 #include <rtl/ustring.hxx>
21 #include <sal/types.h>
22 #include <salhelper/simplereferenceobject.hxx>
23 #include <unoidl/unoidl.hxx>
25 #include "sourceprovider-parser-requires.hxx"
26 #include <sourceprovider-parser.hxx>
28 namespace unoidl::detail
{
30 struct SourceProviderScannerData
;
32 class SourceProviderEntityPad
: public salhelper::SimpleReferenceObject
{
34 bool isPublished() const { return published_
; }
37 explicit SourceProviderEntityPad(bool published
): published_(published
) {}
39 virtual ~SourceProviderEntityPad() override
{}
42 bool const published_
;
45 class SourceProviderEnumTypeEntityPad
: public SourceProviderEntityPad
{
47 explicit SourceProviderEnumTypeEntityPad(bool published
):
48 SourceProviderEntityPad(published
)
51 std::vector
<unoidl::EnumTypeEntity::Member
> members
;
54 virtual ~SourceProviderEnumTypeEntityPad() noexcept override
{}
57 class SourceProviderPlainStructTypeEntityPad
: public SourceProviderEntityPad
{
59 SourceProviderPlainStructTypeEntityPad(
60 bool published
, const OUString
& theBaseName
,
61 rtl::Reference
<unoidl::PlainStructTypeEntity
> const & theBaseEntity
):
62 SourceProviderEntityPad(published
), baseName(theBaseName
),
63 baseEntity(theBaseEntity
)
64 { assert(theBaseName
.isEmpty() != theBaseEntity
.is()); }
66 OUString
const baseName
;
67 rtl::Reference
<unoidl::PlainStructTypeEntity
> const baseEntity
;
68 std::vector
<unoidl::PlainStructTypeEntity::Member
> members
;
71 virtual ~SourceProviderPlainStructTypeEntityPad() noexcept override
{}
74 class SourceProviderPolymorphicStructTypeTemplateEntityPad
:
75 public SourceProviderEntityPad
78 explicit SourceProviderPolymorphicStructTypeTemplateEntityPad(bool published
)
79 : SourceProviderEntityPad(published
)
82 std::vector
<OUString
> typeParameters
;
83 std::vector
<unoidl::PolymorphicStructTypeTemplateEntity::Member
> members
;
86 virtual ~SourceProviderPolymorphicStructTypeTemplateEntityPad() noexcept override
{}
89 class SourceProviderExceptionTypeEntityPad
: public SourceProviderEntityPad
{
91 SourceProviderExceptionTypeEntityPad(
92 bool published
, const OUString
& theBaseName
,
93 rtl::Reference
<unoidl::ExceptionTypeEntity
> const & theBaseEntity
):
94 SourceProviderEntityPad(published
), baseName(theBaseName
),
95 baseEntity(theBaseEntity
)
96 { assert(theBaseName
.isEmpty() != theBaseEntity
.is()); }
98 OUString
const baseName
;
99 rtl::Reference
<unoidl::ExceptionTypeEntity
> const baseEntity
;
100 std::vector
<unoidl::ExceptionTypeEntity::Member
> members
;
103 virtual ~SourceProviderExceptionTypeEntityPad() noexcept override
{}
106 class SourceProviderInterfaceTypeEntityPad
: public SourceProviderEntityPad
{
110 OUString
const & theName
,
111 rtl::Reference
<unoidl::InterfaceTypeEntity
> const & theEntity
,
112 std::vector
<OUString
>&& theAnnotations
):
113 name(theName
), entity(theEntity
), annotations(std::move(theAnnotations
))
114 { assert(theEntity
.is()); }
117 rtl::Reference
<unoidl::InterfaceTypeEntity
> entity
;
118 std::vector
<OUString
> annotations
;
122 BASE_INDIRECT_OPTIONAL
, BASE_DIRECT_OPTIONAL
, BASE_INDIRECT_MANDATORY
,
123 BASE_DIRECT_MANDATORY
128 std::set
<OUString
> optional
;
130 explicit Member(const OUString
& theMandatory
): mandatory(theMandatory
) {}
133 SourceProviderInterfaceTypeEntityPad(bool published
, bool theSingleBase
):
134 SourceProviderEntityPad(published
), singleBase(theSingleBase
)
138 YYLTYPE location
, yyscan_t yyscanner
, SourceProviderScannerData
* data
,
139 DirectBase
const & base
, bool optional
);
141 bool addDirectMember(
142 YYLTYPE location
, yyscan_t yyscanner
, SourceProviderScannerData
* data
,
143 OUString
const & name
);
146 std::vector
<DirectBase
> directMandatoryBases
;
147 std::vector
<DirectBase
> directOptionalBases
;
148 std::vector
<unoidl::InterfaceTypeEntity::Attribute
> directAttributes
;
149 std::vector
<unoidl::InterfaceTypeEntity::Method
> directMethods
;
150 std::map
<OUString
, BaseKind
> allBases
;
151 std::map
<OUString
, Member
> allMembers
;
154 virtual ~SourceProviderInterfaceTypeEntityPad() noexcept override
{}
156 bool checkBaseClashes(
157 YYLTYPE location
, yyscan_t yyscanner
, SourceProviderScannerData
* data
,
158 OUString
const & name
,
159 rtl::Reference
<unoidl::InterfaceTypeEntity
> const & entity
,
160 bool direct
, bool optional
, bool outerOptional
,
161 std::set
<OUString
> * seen
) const;
163 bool checkMemberClashes(
164 YYLTYPE location
, yyscan_t yyscanner
, SourceProviderScannerData
* data
,
165 std::u16string_view interfaceName
, OUString
const & memberName
,
166 bool checkOptional
) const;
169 YYLTYPE location
, yyscan_t yyscanner
, SourceProviderScannerData
* data
,
170 OUString
const & directBaseName
, OUString
const & name
,
171 rtl::Reference
<unoidl::InterfaceTypeEntity
> const & entity
, bool direct
,
174 bool addOptionalBaseMembers(
175 YYLTYPE location
, yyscan_t yyscanner
, SourceProviderScannerData
* data
,
176 OUString
const & name
,
177 rtl::Reference
<unoidl::InterfaceTypeEntity
> const & entity
);
180 class SourceProviderConstantGroupEntityPad
: public SourceProviderEntityPad
{
182 explicit SourceProviderConstantGroupEntityPad(bool published
):
183 SourceProviderEntityPad(published
)
186 std::vector
<unoidl::ConstantGroupEntity::Member
> members
;
189 virtual ~SourceProviderConstantGroupEntityPad() noexcept override
{}
192 class SourceProviderSingleInterfaceBasedServiceEntityPad
:
193 public SourceProviderEntityPad
199 OUString
const & theName
,
200 SourceProviderType
const & theType
, bool theRest
):
201 name(theName
), type(theType
), rest(theRest
)
206 SourceProviderType type
;
212 OUString
const & theName
,
213 std::vector
< OUString
>&& theAnnotations
):
214 name(theName
), annotations(std::move(theAnnotations
))
219 std::vector
< Parameter
> parameters
;
221 std::vector
< OUString
> exceptions
;
223 std::vector
< OUString
> annotations
;
226 explicit SourceProviderSingleInterfaceBasedServiceEntityPad(
227 bool published
, OUString
const & theBase
):
228 SourceProviderEntityPad(published
), base(theBase
)
232 std::vector
<Constructor
> constructors
;
235 virtual ~SourceProviderSingleInterfaceBasedServiceEntityPad() noexcept override
{}
238 class SourceProviderAccumulationBasedServiceEntityPad
:
239 public SourceProviderEntityPad
242 explicit SourceProviderAccumulationBasedServiceEntityPad(bool published
):
243 SourceProviderEntityPad(published
)
246 std::vector
<unoidl::AnnotatedReference
> directMandatoryBaseServices
;
247 std::vector
<unoidl::AnnotatedReference
> directOptionalBaseServices
;
248 std::vector
<unoidl::AnnotatedReference
> directMandatoryBaseInterfaces
;
249 std::vector
<unoidl::AnnotatedReference
> directOptionalBaseInterfaces
;
250 std::vector
<unoidl::AccumulationBasedServiceEntity::Property
>
254 virtual ~SourceProviderAccumulationBasedServiceEntityPad() noexcept override
{}
257 struct SourceProviderEntity
{
259 KIND_EXTERNAL
, KIND_LOCAL
, KIND_INTERFACE_DECL
,
260 KIND_PUBLISHED_INTERFACE_DECL
, KIND_MODULE
263 explicit SourceProviderEntity(
264 Kind theKind
, rtl::Reference
<unoidl::Entity
> const & externalEntity
):
265 kind(theKind
), entity(externalEntity
)
266 { assert(theKind
<= KIND_LOCAL
); assert(externalEntity
.is()); }
268 explicit SourceProviderEntity(
269 rtl::Reference
<SourceProviderEntityPad
> const & localPad
):
270 kind(KIND_LOCAL
), pad(localPad
)
271 { assert(localPad
.is()); }
273 explicit SourceProviderEntity(Kind theKind
): kind(theKind
)
274 { assert(theKind
>= KIND_INTERFACE_DECL
); }
276 SourceProviderEntity(): // needed for std::map::operator []
277 kind() // avoid false warnings about uninitialized members
281 rtl::Reference
<unoidl::Entity
> entity
;
282 rtl::Reference
<SourceProviderEntityPad
> pad
;
285 struct SourceProviderScannerData
{
286 explicit SourceProviderScannerData(
287 rtl::Reference
<unoidl::Manager
> const & theManager
):
289 sourcePosition(), sourceEnd(),
290 // avoid false warnings about uninitialized members
291 errorLine(0), publishedContext(false)
292 { assert(manager
.is()); }
294 void setSource(void const * address
, sal_uInt64 size
) {
295 sourcePosition
= static_cast<char const *>(address
);
296 sourceEnd
= sourcePosition
+ size
;
299 rtl::Reference
<unoidl::Manager
> manager
;
301 char const * sourcePosition
;
302 char const * sourceEnd
;
305 OUString errorMessage
;
307 std::map
<OUString
, SourceProviderEntity
> entities
;
308 std::vector
<OUString
> modules
;
309 OUString currentName
;
310 bool publishedContext
;
313 bool parse(OUString
const & uri
, SourceProviderScannerData
* data
);
317 int yylex_init_extra(
318 unoidl::detail::SourceProviderScannerData
* user_defined
,
319 yyscan_t
* yyscanner
);
321 int yylex_destroy(yyscan_t yyscanner
);
323 int yylex(YYSTYPE
* yylval_param
, YYLTYPE
* yylloc_param
, yyscan_t yyscanner
);
325 unoidl::detail::SourceProviderScannerData
* yyget_extra(yyscan_t yyscanner
);
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */