summaryrefslogtreecommitdiff
path: root/autodoc/source/ary/idl/ia_type.cxx
blob: c029c8e1e877a99b374ed5892003da28429d285d (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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#include <precomp.h>
#include "ia_type.hxx"


// NOT FULLY DEFINED SERVICES
#include <ary/qualiname.hxx>
#include <ary/idl/i_module.hxx>
#include <ary/idl/i_type.hxx>
#include <ary/idl/ip_ce.hxx>
#include "ia_ce.hxx"
#include "is_type.hxx"
#include "it_builtin.hxx"
#include "it_ce.hxx"
#include "it_explicit.hxx"
#include "it_sequence.hxx"
#include "it_tplparam.hxx"
#include "it_xnameroom.hxx"



namespace ary
{
namespace idl
{

String              MakeTemplateName(
                        const String &      i_localName,
                        const std::vector<Type_id> &
                                            i_templateParameters );



inline CeAdmin &
TypeAdmin::my_Ces() const
    { return *pCes; }

inline void
TypeAdmin::lhf_Put2Storage_and_AssignId( DYN Type & pass_io_rType )
    { // This also assigns an ID to pass_io_rType:
      Storage().Store_Entity(pass_io_rType); }

inline Type_id
TypeAdmin::lhf_findBuiltInType( const String & i_sName )
    { return ary_cast<ExplicitNameRoom>(Storage()[nXNameRoom_Root])
                        .Search_Name(i_sName); }

inline const ExplicitNameRoom &
TypeAdmin::find_ExplicitNameRoom( Type_id i_nType ) const
{
    return ary_cast<ExplicitNameRoom>(Storage()[i_nType]);
}

inline ExplicitNameRoom &
TypeAdmin::find_ExplicitNameRoom( Type_id i_nType )
{
    return ary_cast<ExplicitNameRoom>(Storage()[i_nType]);
}

ExplicitNameRoom &
TypeAdmin::lhf_CheckIn_XNameRoom( const QualifiedName & i_rName,
                                       Ce_id                 i_nModuleOfOccurrence )
{
    Type_id nRoot = i_rName.IsAbsolute()
                        ?   Type_id( predefined::type_GlobalXNameRoom )
                        :   lhf_Get_NameRoomRoot_forModuleofOccurrence( i_nModuleOfOccurrence ).TypeId();

    if ( i_rName.NamespaceDepth() == 0 )
        return find_ExplicitNameRoom(nRoot);

    QualifiedName::namespace_iterator it = i_rName.first_namespace();
    ExplicitNameRoom *
        ret = & find_ExplicitNameRoom(nRoot);
    for ( ; it != i_rName.end_namespace(); ++it )
    {
        Type_id
            found = ret->Search_Name(*it);
        if (found.IsValid())
        {
            ret = & find_ExplicitNameRoom(found);
        }
        else
        {
            ExplicitNameRoom &
                rNew = *new ExplicitNameRoom(*it, *ret);
            lhf_Put2Storage_and_AssignId(rNew);
            ret->Add_Name( rNew.Name(), rNew.TypeId() );
            ret = &rNew;
        }

    }   // end for
    return *ret;
}

Type_id
TypeAdmin::lhf_CheckIn_TypeName( const String &        i_sLocalName,
                                      ExplicitNameRoom &    io_rXNameRoom,
                                      Ce_id                 i_nModuleOfOccurrence,
                                 const std::vector<Type_id> *   i_templateParameters )
{
    String sSearchLocalName( i_sLocalName );
    if ( i_templateParameters != 0
         ?  (!i_templateParameters->empty())
         :  false )
    {
        sSearchLocalName = MakeTemplateName(
                                i_sLocalName,
                                *i_templateParameters);
    }

    Type_id
        ret = io_rXNameRoom.Search_Name(sSearchLocalName);
    if (NOT ret.IsValid())
    {
        DYN Type &
            rNewType = *new ExplicitType(  i_sLocalName,
                                           io_rXNameRoom.TypeId(),
                                           i_nModuleOfOccurrence,
                                           i_templateParameters );
        lhf_Put2Storage_and_AssignId(rNewType);
        ret = rNewType.TypeId();
        io_rXNameRoom.Add_Name( sSearchLocalName, ret );
    }
    return ret;
}

Type_id
TypeAdmin::lhf_CheckIn_Sequence(Type_id i_nType)
{
    Type_id
        ret = Storage().Search_SequenceOf(i_nType);

    if (NOT ret.IsValid())
    {
        DYN Type &
            rNewSeq = *new Sequence(i_nType);
        lhf_Put2Storage_and_AssignId(rNewSeq);
        ret = rNewSeq.Id();
        Storage().Add_Sequence(i_nType, ret);
    }
    return ret;
}

void
TypeAdmin::lhf_CheckIn_BuiltInType( const char *       i_sName,
                                    Rid                i_nId )
{
    DYN BuiltInType &
        rNewType = *new BuiltInType(i_sName);
    Storage().Set_Reserved(i_nId, rNewType);

    // Put them into both roots, to catch the syntactically correct
    //   (though unlikely) ::Any, ::long etc.
    Type_id
        nId(i_nId);
    find_ExplicitNameRoom(nXNameRoom_Root).Add_Name(i_sName, nId);
    find_ExplicitNameRoom(nXNameRoom_Global).Add_Name(i_sName, nId);
}

ExplicitNameRoom &
TypeAdmin::lhf_Get_NameRoomRoot_forModuleofOccurrence( Ce_id i_nModuleOfOccurrence )
{
    const Type_id *
        pFound = csv::find_in_map( aMap_ModuleOfOccurrence2NameRoomRoot,
                                   i_nModuleOfOccurrence );
    if (pFound != 0)
        return find_ExplicitNameRoom(*pFound);

    ExplicitNameRoom &
        ret = *new ExplicitNameRoom;
    lhf_Put2Storage_and_AssignId(ret);
    aMap_ModuleOfOccurrence2NameRoomRoot.insert(std::pair< const Ce_id, Type_id>(i_nModuleOfOccurrence,ret.TypeId()));
    return ret;
}

TypeAdmin::TypeAdmin()
    :   pStorage(new Type_Storage),
        pCes(0),    // Needs to be set directly after creation.
        nXNameRoom_Root( static_cast<ary::Rid>(predefined::type_Root_ofXNameRooms) ),
        nXNameRoom_Global( static_cast<ary::Rid>(predefined::type_GlobalXNameRoom) ),
        aMap_ModuleOfOccurrence2NameRoomRoot()
{
    DYN ExplicitNameRoom &
        drRoot = *new ExplicitNameRoom;
    Storage().Set_Reserved( nXNameRoom_Root.Value(), drRoot );

    DYN ExplicitNameRoom &
        drGlobal = *new ExplicitNameRoom(String::Null_(), drRoot);
    Storage().Set_Reserved( nXNameRoom_Global.Value(), drGlobal );
    drRoot.Add_Name( drGlobal.Name(), nXNameRoom_Global );

    lhf_Setup_BuildInTypes();
}

TypeAdmin::~TypeAdmin()
{
}

void
TypeAdmin::lhf_Setup_BuildInTypes()
{
    lhf_CheckIn_BuiltInType("any", predefined::type_any);
    lhf_CheckIn_BuiltInType("boolean", predefined::type_boolean);
    lhf_CheckIn_BuiltInType("byte", predefined::type_byte);
    lhf_CheckIn_BuiltInType("char", predefined::type_char);
    lhf_CheckIn_BuiltInType("double", predefined::type_double);
    lhf_CheckIn_BuiltInType("float", predefined::type_float);
    lhf_CheckIn_BuiltInType("hyper", predefined::type_hyper);
    lhf_CheckIn_BuiltInType("long", predefined::type_long);
    lhf_CheckIn_BuiltInType("short", predefined::type_short);
    lhf_CheckIn_BuiltInType("string", predefined::type_string);
    lhf_CheckIn_BuiltInType("type", predefined::type_type);
    lhf_CheckIn_BuiltInType("void", predefined::type_void);
    lhf_CheckIn_BuiltInType("unsigned hyper", predefined::type_u_hyper);
    lhf_CheckIn_BuiltInType("unsigned long", predefined::type_u_long);
    lhf_CheckIn_BuiltInType("unsigned short", predefined::type_u_short);
}

const Type &
TypeAdmin::CheckIn_Type( QualifiedName &     i_rFullName,
                                 uintt               i_nSequenceCount,
                                 Ce_id               i_nModuleOfOccurrence,
                         const std::vector<Type_id> *   i_templateParameters )
{
    // Look in built-in types:
    Type_id
        nType = lhf_findBuiltInType(i_rFullName.LocalName());
    if (NOT nType.IsValid())
    {   // No built-in type:
        ExplicitNameRoom &
            rNameRoom = lhf_CheckIn_XNameRoom(i_rFullName,i_nModuleOfOccurrence);
        nType = lhf_CheckIn_TypeName( i_rFullName.LocalName(),
                                      rNameRoom,
                                      i_nModuleOfOccurrence,
                                      i_templateParameters );
    }   // endif

    for ( uintt s = 0; s < i_nSequenceCount; ++s )
    {
        nType = lhf_CheckIn_Sequence(nType);
    }

    return Storage()[nType];
}

TemplateParamType &
TypeAdmin::Store_TemplateParamType( String i_sName )
{
    DYN TemplateParamType &
        ret = *new TemplateParamType( i_sName );
    lhf_Put2Storage_and_AssignId(ret);
    return ret;
}

const Type &
TypeAdmin::Find_Type( Type_id i_nType ) const
{
    return Storage()[i_nType];
}

String
TypeAdmin::Search_LocalNameOf( Type_id i_nType ) const
{
    const Type *
        pType = Storage().Exists(i_nType)
                    ? 0
                    : & Storage()[i_nType];
    if (pType != 0)
    {
        switch (pType->AryClass())
        {
            case Ce_Type::class_id:
            case ExplicitType::class_id:
            case BuiltInType::class_id:
                    return static_cast< const Named_Type& >(*pType).Name();
        }
    }
    return String::Null_();
}

Ce_id
TypeAdmin::Search_CeRelatedTo( Type_id i_nType ) const
{
    const Ce_Type *
        ret = ary_cast<Ce_Type>( & Storage()[i_nType] );
    return ret != 0
            ?   ret->RelatedCe()
            :   Ce_id_Null();
}

const ExplicitNameRoom &
TypeAdmin::Find_XNameRoom( Type_id i_nType ) const
{
    return find_ExplicitNameRoom(i_nType);
}

bool
TypeAdmin::IsBuiltInOrRelated( const Type & i_rType ) const
{
    if ( is_type<BuiltInType>(i_rType) )
        return true;
    else
    {
        const Type *
            pType = &i_rType;
        while (is_type<Sequence>(*pType))
        {
            Type_id
                nt = ary_cast<Sequence>(pType)->RelatedType();
            if (NOT nt.IsValid())
                return false;
            pType = & Storage()[nt];
        }
        return is_type<BuiltInType>(*pType);
    }
}


String
MakeTemplateName( const String &                i_localName,
                  const std::vector<Type_id> &  )
{
    StreamLock
        sl(200);

    // This is the simple solution, assuming that there is only
    // one version of templatisation allowed with a given name.
    return
        sl()
            << i_localName
            << C_cTemplateDelimiter
            << c_str;
}



}   // namespace idl
}   // namespace ary

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