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/.
10 #ifndef INCLUDED_UNOIDL_SOURCE_SOURCEPROVIDER_SCANNER_HXX
11 #define INCLUDED_UNOIDL_SOURCE_SOURCEPROVIDER_SCANNER_HXX
13 #include "sal/config.h"
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
{ namespace detail
{
31 struct SourceProviderScannerData
;
33 class SourceProviderEntityPad
: public salhelper::SimpleReferenceObject
{
35 bool isPublished() const { return published_
; }
38 explicit SourceProviderEntityPad(bool published
): published_(published
) {}
40 virtual ~SourceProviderEntityPad() {}
43 bool const published_
;
46 class SourceProviderEnumTypeEntityPad
: public SourceProviderEntityPad
{
48 explicit SourceProviderEnumTypeEntityPad(bool published
):
49 SourceProviderEntityPad(published
)
52 std::vector
<unoidl::EnumTypeEntity::Member
> members
;
55 virtual ~SourceProviderEnumTypeEntityPad() throw () {}
58 class SourceProviderPlainStructTypeEntityPad
: public SourceProviderEntityPad
{
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() != (bool) theBaseEntity
.is()); }
67 OUString
const baseName
;
68 rtl::Reference
<unoidl::PlainStructTypeEntity
> const baseEntity
;
69 std::vector
<unoidl::PlainStructTypeEntity::Member
> members
;
72 virtual ~SourceProviderPlainStructTypeEntityPad() throw () {}
75 class SourceProviderPolymorphicStructTypeTemplateEntityPad
:
76 public SourceProviderEntityPad
79 SourceProviderPolymorphicStructTypeTemplateEntityPad(bool published
):
80 SourceProviderEntityPad(published
)
83 std::vector
<OUString
> typeParameters
;
84 std::vector
<unoidl::PolymorphicStructTypeTemplateEntity::Member
> members
;
87 virtual ~SourceProviderPolymorphicStructTypeTemplateEntityPad() throw () {}
90 class SourceProviderExceptionTypeEntityPad
: public SourceProviderEntityPad
{
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() != (bool) theBaseEntity
.is()); }
99 OUString
const baseName
;
100 rtl::Reference
<unoidl::ExceptionTypeEntity
> const baseEntity
;
101 std::vector
<unoidl::ExceptionTypeEntity::Member
> members
;
104 virtual ~SourceProviderExceptionTypeEntityPad() throw () {}
107 class SourceProviderInterfaceTypeEntityPad
: public SourceProviderEntityPad
{
111 OUString
const & theName
,
112 rtl::Reference
<unoidl::InterfaceTypeEntity
> const & theEntity
,
113 std::vector
<OUString
> const & theAnnotations
):
114 name(theName
), entity(theEntity
), annotations(theAnnotations
)
115 { assert(theEntity
.is()); }
118 rtl::Reference
<unoidl::InterfaceTypeEntity
> entity
;
119 std::vector
<OUString
> annotations
;
123 BASE_INDIRECT_OPTIONAL
, BASE_DIRECT_OPTIONAL
, BASE_INDIRECT_MANDATORY
,
124 BASE_DIRECT_MANDATORY
129 std::set
<OUString
> optional
;
131 explicit Member(const OUString
& theMandatory
): mandatory(theMandatory
) {}
134 SourceProviderInterfaceTypeEntityPad(bool published
, bool theSingleBase
):
135 SourceProviderEntityPad(published
), singleBase(theSingleBase
)
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
);
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
;
155 virtual ~SourceProviderInterfaceTypeEntityPad() throw () {}
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 OUString
const & interfaceName
, OUString
const & memberName
,
167 bool checkOptional
) const;
170 YYLTYPE location
, yyscan_t yyscanner
, SourceProviderScannerData
* data
,
171 OUString
const & directBaseName
, OUString
const & name
,
172 rtl::Reference
<unoidl::InterfaceTypeEntity
> const & entity
, bool direct
,
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
{
183 explicit SourceProviderConstantGroupEntityPad(bool published
):
184 SourceProviderEntityPad(published
)
187 std::vector
<unoidl::ConstantGroupEntity::Member
> members
;
190 virtual ~SourceProviderConstantGroupEntityPad() throw () {}
193 class SourceProviderSingleInterfaceBasedServiceEntityPad
:
194 public SourceProviderEntityPad
200 rtl::OUString
const & theName
,
201 SourceProviderType
const & theType
, bool theRest
):
202 name(theName
), type(theType
), rest(theRest
)
207 SourceProviderType type
;
213 rtl::OUString
const & theName
,
214 std::vector
< rtl::OUString
> const & theAnnotations
):
215 name(theName
), annotations(theAnnotations
)
220 std::vector
< Parameter
> parameters
;
222 std::vector
< rtl::OUString
> exceptions
;
224 std::vector
< rtl::OUString
> annotations
;
227 explicit SourceProviderSingleInterfaceBasedServiceEntityPad(
228 bool published
, OUString
const & theBase
):
229 SourceProviderEntityPad(published
), base(theBase
)
233 std::vector
<Constructor
> constructors
;
236 virtual ~SourceProviderSingleInterfaceBasedServiceEntityPad() throw () {}
239 class SourceProviderAccumulationBasedServiceEntityPad
:
240 public SourceProviderEntityPad
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
>
255 virtual ~SourceProviderAccumulationBasedServiceEntityPad() throw () {}
258 struct SourceProviderEntity
{
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
282 rtl::Reference
<unoidl::Entity
> entity
;
283 rtl::Reference
<SourceProviderEntityPad
> pad
;
286 struct SourceProviderScannerData
{
287 SourceProviderScannerData(
288 rtl::Reference
<unoidl::Manager
> const & 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
;
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
);
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */