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
|
/* -*- 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <algorithm>
#include <ctype.h>
#include <stdio.h>
#include <tools/debug.hxx>
#include <types.hxx>
#include <globals.hxx>
#include <database.hxx>
SvMetaAttribute::SvMetaAttribute()
{
}
SvMetaAttribute::SvMetaAttribute( SvMetaType * pType )
: aType( pType )
{
}
SvMetaType * SvMetaAttribute::GetType() const
{
if( aType.Is() || !GetRef() ) return aType;
return static_cast<SvMetaAttribute *>(GetRef())->GetType();
}
const SvIdentifier & SvMetaAttribute::GetSlotId() const
{
if( aSlotId.IsSet() || !GetRef() ) return aSlotId;
return static_cast<SvMetaAttribute *>(GetRef())->GetSlotId();
}
bool SvMetaAttribute::Test( SvTokenStream & rInStm )
{
if( GetType()->IsItem() && !GetSlotId().IsSet() )
{
throw SvParseException( rInStm, "slot without id declared" );
}
return true;
}
bool SvMetaAttribute::ReadSvIdl( SvIdlDataBase & rBase,
SvTokenStream & rInStm )
{
sal_uInt32 nTokPos = rInStm.Tell();
if( !GetType() )
// no type in ctor passed on
aType = rBase.ReadKnownType( rInStm );
bool bOk = false;
if( GetType() )
{
ReadNameSvIdl( rInStm );
aSlotId.ReadSvIdl( rBase, rInStm );
bOk = true;
SvToken& rTok = rInStm.GetToken();
if( rTok.IsChar() && rTok.GetChar() == '(' )
{
tools::SvRef<SvMetaType> xT(new SvMetaType() );
xT->SetRef( GetType() );
aType = xT;
bOk = aType->ReadMethodArgs( rBase, rInStm );
}
if( bOk )
bOk = SvMetaObject::ReadSvIdl( rBase, rInStm );
}
else
{
SvToken& rTok = rInStm.GetToken();
rBase.SetError( "unknown type of token. Each new SID needs an "
"item statement in an SDI file, eg. "
"SfxVoidItem FooItem " + rTok.GetTokenAsString() +
" ... which describes the slot more fully", rTok );
}
if( !bOk )
rInStm.Seek( nTokPos );
return bOk;
}
void SvMetaAttribute::ReadAttributesSvIdl( SvIdlDataBase & rBase,
SvTokenStream & rInStm )
{
SvMetaReference::ReadAttributesSvIdl( rBase, rInStm );
}
sal_uLong SvMetaAttribute::MakeSfx( OStringBuffer& rAttrArray )
{
SvMetaType * pType = GetType();
DBG_ASSERT( pType, "no type for attribute" );
SvMetaType * pBaseType = pType->GetBaseType();
DBG_ASSERT( pBaseType, "no base type for attribute" );
if( pBaseType->GetMetaTypeType() == MetaTypeType::Struct )
return pBaseType->MakeSfx( rAttrArray );
else
{
rAttrArray.append('{');
rAttrArray.append(GetSlotId().getString());
rAttrArray.append(",\"");
rAttrArray.append(GetName());
rAttrArray.append("\"}");
return 1;
}
}
void SvMetaAttribute::Insert (SvSlotElementList&, const OString&, SvIdlDataBase&)
{
}
#define CTOR \
: nType( MetaTypeType::Base ) \
, bIsItem( false ) \
SvMetaType::SvMetaType()
CTOR
{
}
SvMetaType::SvMetaType( const OString& rName )
CTOR
{
SetName( rName );
}
SvMetaType::~SvMetaType()
{}
void SvMetaType::SetType( MetaTypeType nT )
{
nType = nT;
}
SvMetaType * SvMetaType::GetBaseType() const
{
if( GetRef() && GetMetaTypeType() == MetaTypeType::Base )
return static_cast<SvMetaType *>(GetRef())->GetBaseType();
return const_cast<SvMetaType *>(this);
}
SvMetaType * SvMetaType::GetReturnType() const
{
DBG_ASSERT( GetMetaTypeType() == MetaTypeType::Method, "no method" );
DBG_ASSERT( GetRef(), "no return type" );
return static_cast<SvMetaType *>(GetRef());
}
bool SvMetaType::ReadHeaderSvIdl( SvIdlDataBase & ,
SvTokenStream & rInStm )
{
bool bOk = false;
sal_uInt32 nTokPos = rInStm.Tell();
SvToken& rTok = rInStm.GetToken_Next();
if( rTok.Is( SvHash_interface() ) )
{
SetType( MetaTypeType::Interface );
bOk = ReadNamesSvIdl( rInStm );
}
else if( rTok.Is( SvHash_shell() ) )
{
SetType( MetaTypeType::Shell );
bOk = ReadNamesSvIdl( rInStm );
}
if( !bOk )
rInStm.Seek( nTokPos );
return bOk;
}
bool SvMetaType::ReadSvIdl( SvIdlDataBase & rBase,
SvTokenStream & rInStm )
{
if( ReadHeaderSvIdl( rBase, rInStm ) )
{
rBase.Write(OString('.'));
return SvMetaReference::ReadSvIdl( rBase, rInStm );
}
return false;
}
bool SvMetaType::ReadNamesSvIdl( SvTokenStream & rInStm )
{
return ReadNameSvIdl( rInStm );
}
void SvMetaType::ReadContextSvIdl( SvIdlDataBase & rBase,
SvTokenStream & rInStm )
{
tools::SvRef<SvMetaAttribute> xAttr( new SvMetaAttribute() );
if( xAttr->ReadSvIdl( rBase, rInStm ) )
{
if( xAttr->Test( rInStm ) )
GetAttrList().push_back( xAttr );
}
}
sal_uLong SvMetaType::MakeSfx( OStringBuffer& rAttrArray )
{
sal_uLong nC = 0;
if( GetBaseType()->GetMetaTypeType() == MetaTypeType::Struct )
{
sal_uLong nAttrCount = GetAttrCount();
// write the single attributes
for( sal_uLong n = 0; n < nAttrCount; n++ )
{
nC += aAttrList[n]->MakeSfx( rAttrArray );
if( n +1 < nAttrCount )
rAttrArray.append(", ");
}
}
return nC;
}
void SvMetaType::WriteSfxItem(
const OString& rItemName, SvIdlDataBase& rBase, SvStream& rOutStm )
{
WriteStars( rOutStm );
OString aVarName = " a" + rItemName + "_Impl";
OStringBuffer aAttrArray;
sal_uLong nAttrCount = MakeSfx( aAttrArray );
OString aAttrCount( OString::number(nAttrCount));
OString aTypeName = "SfxType" + aAttrCount;
bool bExport = false, bReturn = false;
// these are exported from sfx library
if (rItemName == "SfxBoolItem" ||
rItemName == "SfxStringItem" ||
rItemName == "SfxUInt16Item" ||
rItemName == "SfxUInt32Item" ||
rItemName == "SfxVoidItem")
{
bExport = true;
if (!rBase.sSlotMapFile.endsWith("sfxslots.hxx"))
bReturn = true;
}
rOutStm.WriteCharPtr( "extern " );
if (bExport)
rOutStm.WriteCharPtr( "SFX2_DLLPUBLIC " );
rOutStm.WriteOString( aTypeName )
.WriteOString( aVarName ).WriteChar( ';' ) << endl;
if (bReturn)
return;
// write the implementation part
rOutStm.WriteCharPtr( "#ifdef SFX_TYPEMAP" ) << endl;
rOutStm.WriteCharPtr( "#if !defined(_WIN32) && ((defined(DISABLE_DYNLOADING) && (defined(ANDROID) || defined(IOS))) || STATIC_LINKING)" ) << endl;
rOutStm.WriteCharPtr( "__attribute__((__weak__))" ) << endl;
rOutStm.WriteCharPtr( "#endif" ) << endl;
rOutStm.WriteOString( aTypeName ).WriteOString( aVarName )
.WriteCharPtr( " = " ) << endl;
rOutStm.WriteChar( '{' ) << endl;
rOutStm.WriteCharPtr( "\tcreateSfxPoolItem<" ).WriteOString( rItemName )
.WriteCharPtr(">, &typeid(").WriteOString( rItemName ).WriteCharPtr( "), " );
rOutStm.WriteOString( aAttrCount );
if( nAttrCount )
{
rOutStm.WriteCharPtr( ", { " );
// write the single attributes
rOutStm.WriteCharPtr( aAttrArray.getStr() );
rOutStm.WriteCharPtr( " }" );
}
rOutStm << endl;
rOutStm.WriteCharPtr( "};" ) << endl;
rOutStm.WriteCharPtr( "#endif" ) << endl << endl;
}
void SvMetaType::WriteSfx( SvIdlDataBase & rBase, SvStream & rOutStm )
{
if( IsItem() )
{
if( GetBaseType()->GetMetaTypeType() == MetaTypeType::Struct )
GetBaseType()->WriteSfxItem( GetName(), rBase, rOutStm );
else
WriteSfxItem( GetName(), rBase, rOutStm );
}
}
bool SvMetaType::ReadMethodArgs( SvIdlDataBase & rBase,
SvTokenStream & rInStm )
{
sal_uInt32 nTokPos = rInStm.Tell();
if( rInStm.ReadIf( '(' ) )
{
DoReadContextSvIdl( rBase, rInStm );
if( rInStm.ReadIf( ')' ) )
{
SetType( MetaTypeType::Method );
return true;
}
}
rInStm.Seek( nTokPos );
return false;
}
SvMetaTypeString::SvMetaTypeString()
: SvMetaType( "String" )
{
}
SvMetaEnumValue::SvMetaEnumValue()
{
}
SvMetaTypeEnum::SvMetaTypeEnum()
{
}
SvMetaTypevoid::SvMetaTypevoid()
: SvMetaType( "void" )
{
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|