summaryrefslogtreecommitdiff
path: root/unoidl/source/sourceprovider-scanner.hxx
blob: 14ac15421f082b9dc6ba706de6b305ba0a5c500c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef INCLUDED_UNOIDL_SOURCE_SOURCEPROVIDER_SCANNER_HXX
#define INCLUDED_UNOIDL_SOURCE_SOURCEPROVIDER_SCANNER_HXX

#include "sal/config.h"

#include <cassert>
#include <map>
#include <set>
#include <vector>

#include "rtl/ref.hxx"
#include "rtl/ustring.hxx"
#include "sal/types.h"
#include "salhelper/simplereferenceobject.hxx"
#include "unoidl/unoidl.hxx"

#include "sourceprovider-parser-requires.hxx"
#include "sourceprovider-parser.hxx"

namespace unoidl { namespace detail {

struct SourceProviderScannerData;

class SourceProviderEntityPad: public salhelper::SimpleReferenceObject {
public:
    bool isPublished() const { return published_; }

protected:
    explicit SourceProviderEntityPad(bool published): published_(published) {}

    virtual ~SourceProviderEntityPad() {}

private:
    bool const published_;
};

class SourceProviderEnumTypeEntityPad: public SourceProviderEntityPad {
public:
    explicit SourceProviderEnumTypeEntityPad(bool published):
        SourceProviderEntityPad(published)
    {}

    std::vector<unoidl::EnumTypeEntity::Member> members;

private:
    virtual ~SourceProviderEnumTypeEntityPad() throw () {}
};

class SourceProviderPlainStructTypeEntityPad: public SourceProviderEntityPad {
public:
    SourceProviderPlainStructTypeEntityPad(
        bool published, OUString theBaseName,
        rtl::Reference<unoidl::PlainStructTypeEntity> const & theBaseEntity):
        SourceProviderEntityPad(published), baseName(theBaseName),
        baseEntity(theBaseEntity)
    { assert(theBaseName.isEmpty() != (bool) theBaseEntity.is()); }

    OUString const baseName;
    rtl::Reference<unoidl::PlainStructTypeEntity> const baseEntity;
    std::vector<unoidl::PlainStructTypeEntity::Member> members;

private:
    virtual ~SourceProviderPlainStructTypeEntityPad() throw () {}
};

class SourceProviderPolymorphicStructTypeTemplateEntityPad:
    public SourceProviderEntityPad
{
public:
    SourceProviderPolymorphicStructTypeTemplateEntityPad(bool published):
        SourceProviderEntityPad(published)
    {}

    std::vector<OUString> typeParameters;
    std::vector<unoidl::PolymorphicStructTypeTemplateEntity::Member> members;

private:
    virtual ~SourceProviderPolymorphicStructTypeTemplateEntityPad() throw () {}
};

class SourceProviderExceptionTypeEntityPad: public SourceProviderEntityPad {
public:
    SourceProviderExceptionTypeEntityPad(
        bool published, OUString theBaseName,
        rtl::Reference<unoidl::ExceptionTypeEntity> const & theBaseEntity):
        SourceProviderEntityPad(published), baseName(theBaseName),
        baseEntity(theBaseEntity)
    { assert(theBaseName.isEmpty() != (bool) theBaseEntity.is()); }

    OUString const baseName;
    rtl::Reference<unoidl::ExceptionTypeEntity> const baseEntity;
    std::vector<unoidl::ExceptionTypeEntity::Member> members;

private:
    virtual ~SourceProviderExceptionTypeEntityPad() throw () {}
};

class SourceProviderInterfaceTypeEntityPad: public SourceProviderEntityPad {
public:
    struct DirectBase {
        DirectBase(
            OUString const & theName,
            rtl::Reference<unoidl::InterfaceTypeEntity> const & theEntity,
            std::vector<OUString> const & theAnnotations):
            name(theName), entity(theEntity), annotations(theAnnotations)
        { assert(theEntity.is()); }

        OUString name;
        rtl::Reference<unoidl::InterfaceTypeEntity> entity;
        std::vector<OUString> annotations;
    };

    enum BaseKind {
        BASE_INDIRECT_OPTIONAL, BASE_DIRECT_OPTIONAL, BASE_INDIRECT_MANDATORY,
        BASE_DIRECT_MANDATORY
    };

    struct Member {
        OUString mandatory;
        std::set<OUString> optional;

        explicit Member(OUString theMandatory): mandatory(theMandatory) {}
    };

    SourceProviderInterfaceTypeEntityPad(bool published, bool theSingleBase):
        SourceProviderEntityPad(published), singleBase(theSingleBase)
    {}

    bool addDirectBase(
        YYLTYPE location, yyscan_t yyscanner, SourceProviderScannerData * data,
        DirectBase const & base, bool optional);

    bool addDirectMember(
        YYLTYPE location, yyscan_t yyscanner, SourceProviderScannerData * data,
        OUString const & name);

    bool singleBase;
    std::vector<DirectBase> directMandatoryBases;
    std::vector<DirectBase> directOptionalBases;
    std::vector<unoidl::InterfaceTypeEntity::Attribute> directAttributes;
    std::vector<unoidl::InterfaceTypeEntity::Method> directMethods;
    std::map<OUString, BaseKind> allBases;
    std::map<OUString, Member> allMembers;

private:
    virtual ~SourceProviderInterfaceTypeEntityPad() throw () {}

    bool checkBaseClashes(
        YYLTYPE location, yyscan_t yyscanner, SourceProviderScannerData * data,
        OUString const & name,
        rtl::Reference<unoidl::InterfaceTypeEntity> const & entity,
        bool direct, bool optional, bool outerOptional,
        std::set<OUString> * seen) const;

    bool checkMemberClashes(
        YYLTYPE location, yyscan_t yyscanner, SourceProviderScannerData * data,
        OUString const & interfaceName, OUString const & memberName,
        bool checkOptional) const;

    bool addBase(
        YYLTYPE location, yyscan_t yyscanner, SourceProviderScannerData * data,
        OUString const & directBaseName, OUString const & name,
        rtl::Reference<unoidl::InterfaceTypeEntity> const & entity, bool direct,
        bool optional);

    bool addOptionalBaseMembers(
        YYLTYPE location, yyscan_t yyscanner, SourceProviderScannerData * data,
        OUString const & name,
        rtl::Reference<unoidl::InterfaceTypeEntity> const & entity);
};

class SourceProviderConstantGroupEntityPad: public SourceProviderEntityPad {
public:
    explicit SourceProviderConstantGroupEntityPad(bool published):
        SourceProviderEntityPad(published)
    {}

    std::vector<unoidl::ConstantGroupEntity::Member> members;

private:
    virtual ~SourceProviderConstantGroupEntityPad() throw () {}
};

class SourceProviderSingleInterfaceBasedServiceEntityPad:
    public SourceProviderEntityPad
{
public:
    struct Constructor {
        struct Parameter {
            Parameter(
                rtl::OUString const & theName,
                SourceProviderType const & theType, bool theRest):
                name(theName), type(theType), rest(theRest)
            {}

            rtl::OUString name;

            SourceProviderType type;

            bool rest;
        };

        Constructor(
            rtl::OUString const & theName,
            std::vector< rtl::OUString > const & theAnnotations):
            name(theName), annotations(theAnnotations)
        {}

        rtl::OUString name;

        std::vector< Parameter > parameters;

        std::vector< rtl::OUString > exceptions;

        std::vector< rtl::OUString > annotations;
    };

    explicit SourceProviderSingleInterfaceBasedServiceEntityPad(
        bool published, OUString const & theBase):
        SourceProviderEntityPad(published), base(theBase)
    {}

    OUString const base;
    std::vector<Constructor> constructors;

private:
    virtual ~SourceProviderSingleInterfaceBasedServiceEntityPad() throw () {}
};

class SourceProviderAccumulationBasedServiceEntityPad:
    public SourceProviderEntityPad
{
public:
    explicit SourceProviderAccumulationBasedServiceEntityPad(bool published):
        SourceProviderEntityPad(published)
    {}

    std::vector<unoidl::AnnotatedReference> directMandatoryBaseServices;
    std::vector<unoidl::AnnotatedReference> directOptionalBaseServices;
    std::vector<unoidl::AnnotatedReference> directMandatoryBaseInterfaces;
    std::vector<unoidl::AnnotatedReference> directOptionalBaseInterfaces;
    std::vector<unoidl::AccumulationBasedServiceEntity::Property>
        directProperties;

private:
    virtual ~SourceProviderAccumulationBasedServiceEntityPad() throw () {}
};

struct SourceProviderEntity {
    enum Kind {
        KIND_EXTERNAL, KIND_LOCAL, KIND_INTERFACE_DECL,
        KIND_PUBLISHED_INTERFACE_DECL, KIND_MODULE
    };

    explicit SourceProviderEntity(
        Kind theKind, rtl::Reference<unoidl::Entity> const & externalEntity):
        kind(theKind), entity(externalEntity)
    { assert(theKind <= KIND_LOCAL); assert(externalEntity.is()); }

    explicit SourceProviderEntity(
        rtl::Reference<SourceProviderEntityPad> const & localPad):
        kind(KIND_LOCAL), pad(localPad)
    { assert(localPad.is()); }

    explicit SourceProviderEntity(Kind theKind): kind(theKind)
    { assert(theKind >= KIND_INTERFACE_DECL); }

    SourceProviderEntity(): // needed for std::map::operator []
        kind() // avoid false warnings about uninitialized members
    {}

    Kind kind;
    rtl::Reference<unoidl::Entity> entity;
    rtl::Reference<SourceProviderEntityPad> pad;
};

struct SourceProviderScannerData {
    SourceProviderScannerData(
        rtl::Reference<unoidl::Manager> const & theManager):
        manager(theManager),
        sourcePosition(), sourceEnd(),
            // avoid false warnings about uninitialized members
        errorLine(0), publishedContext(false)
    { assert(manager.is()); }

    void setSource(void const * address, sal_uInt64 size) {
        sourcePosition = static_cast<char const *>(address);
        sourceEnd = sourcePosition + size;
    }

    rtl::Reference<unoidl::Manager> manager;

    char const * sourcePosition;
    char const * sourceEnd;
    YYLTYPE errorLine;
    OString parserError;
    OUString errorMessage;

    std::map<OUString, SourceProviderEntity> entities;
    std::vector<OUString> modules;
    OUString currentName;
    bool publishedContext;
};

bool parse(OUString const & uri, SourceProviderScannerData * data);

} }

int yylex_init_extra(
    unoidl::detail::SourceProviderScannerData * user_defined,
    yyscan_t * yyscanner);

int yylex_destroy(yyscan_t yyscanner);

int yylex(YYSTYPE * yylval_param, YYLTYPE * yylloc_param, yyscan_t yyscanner);

unoidl::detail::SourceProviderScannerData * yyget_extra(yyscan_t yyscanner);

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */