Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <ctype.h>
22 : #include <stdio.h>
23 :
24 : #include <tools/debug.hxx>
25 :
26 : #include <types.hxx>
27 : #include <globals.hxx>
28 : #include <database.hxx>
29 :
30 48 : TYPEINIT1( SvMetaAttribute, SvMetaReference );
31 17835 : SvMetaAttribute::SvMetaAttribute()
32 : : aAutomation( true, false )
33 : , aExport( true, false )
34 : , aIsCollection ( false, false )
35 : , aReadOnlyDoc ( true, false )
36 : , aHidden( false, false )
37 17835 : , bNewAttr( false )
38 : {
39 17835 : }
40 :
41 4302 : SvMetaAttribute::SvMetaAttribute( SvMetaType * pType )
42 : : aType( pType )
43 : , aAutomation( true, false )
44 : , aExport( true, false )
45 : , aIsCollection ( false, false)
46 : , aReadOnlyDoc ( true, false)
47 : , aHidden( false, false )
48 4302 : , bNewAttr( false )
49 : {
50 4302 : }
51 :
52 204023 : SvMetaType * SvMetaAttribute::GetType() const
53 : {
54 204023 : if( aType.Is() || !GetRef() ) return aType;
55 61243 : return static_cast<SvMetaAttribute *>(GetRef())->GetType();
56 : }
57 :
58 9412485 : const SvNumberIdentifier & SvMetaAttribute::GetSlotId() const
59 : {
60 9412485 : if( aSlotId.IsSet() || !GetRef() ) return aSlotId;
61 959849 : return static_cast<SvMetaAttribute *>(GetRef())->GetSlotId();
62 : }
63 :
64 4976 : bool SvMetaAttribute::GetReadonly() const
65 : {
66 4976 : if( aReadonly.IsSet() || !GetRef() ) return aReadonly;
67 2488 : return static_cast<SvMetaAttribute *>(GetRef())->GetReadonly();
68 : }
69 :
70 33711 : bool SvMetaAttribute::GetExport() const
71 : {
72 33711 : if( aExport.IsSet() || !GetRef() ) return aExport;
73 15858 : return static_cast<SvMetaAttribute *>(GetRef())->GetExport();
74 : }
75 :
76 1725 : bool SvMetaAttribute::GetHidden() const
77 : {
78 : // when export is set, but hidden is not the default is used
79 1725 : if ( aExport.IsSet() && !aHidden.IsSet() )
80 1725 : return !aExport;
81 0 : else if( aHidden.IsSet() || !GetRef() )
82 0 : return aHidden;
83 : else
84 0 : return static_cast<SvMetaAttribute *>(GetRef())->GetHidden();
85 : }
86 :
87 0 : bool SvMetaAttribute::GetAutomation() const
88 : {
89 0 : if( aAutomation.IsSet() || !GetRef() ) return aAutomation;
90 0 : return static_cast<SvMetaAttribute *>(GetRef())->GetAutomation();
91 : }
92 :
93 0 : bool SvMetaAttribute::GetIsCollection() const
94 : {
95 0 : if( aIsCollection.IsSet() || !GetRef() )
96 : {
97 0 : return aIsCollection;
98 : }
99 :
100 0 : return static_cast<SvMetaSlot *>(GetRef())->GetIsCollection();
101 : }
102 :
103 11816 : bool SvMetaAttribute::GetReadOnlyDoc() const
104 : {
105 11816 : if( aReadOnlyDoc.IsSet() || !GetRef() ) return aReadOnlyDoc;
106 5865 : return static_cast<SvMetaSlot *>(GetRef())->GetReadOnlyDoc();
107 : }
108 :
109 23694 : bool SvMetaAttribute::IsMethod() const
110 : {
111 23694 : SvMetaType * pType = GetType();
112 : DBG_ASSERT( pType, "no type for attribute" );
113 23694 : return pType->GetType() == TYPE_METHOD;
114 : }
115 :
116 11283 : bool SvMetaAttribute::IsVariable() const
117 : {
118 11283 : SvMetaType * pType = GetType();
119 11283 : return pType->GetType() != TYPE_METHOD;
120 : }
121 :
122 0 : OString SvMetaAttribute::GetMangleName( bool ) const
123 : {
124 0 : return GetName().getString();
125 : }
126 :
127 17092 : bool SvMetaAttribute::Test( SvIdlDataBase & rBase,
128 : SvTokenStream & rInStm )
129 : {
130 17092 : bool bOk = true;
131 17092 : if( GetType()->IsItem() && !GetSlotId().IsSet() )
132 : {
133 0 : rBase.SetError( "slot without id declared", rInStm.GetToken() );
134 0 : rBase.WriteError( rInStm );
135 0 : bOk = false;
136 : }
137 17092 : return bOk;
138 : }
139 :
140 18067 : bool SvMetaAttribute::ReadSvIdl( SvIdlDataBase & rBase,
141 : SvTokenStream & rInStm )
142 : {
143 18067 : sal_uInt32 nTokPos = rInStm.Tell();
144 18067 : if( !GetType() )
145 : // no type in ctor passed on
146 18025 : aType = rBase.ReadKnownType( rInStm );
147 18067 : bool bOk = false;
148 18067 : if( GetType() )
149 : {
150 13022 : ReadNameSvIdl( rBase, rInStm );
151 13022 : aSlotId.ReadSvIdl( rBase, rInStm );
152 :
153 13022 : bOk = true;
154 13022 : SvToken * pTok = rInStm.GetToken();
155 13022 : if( bOk && pTok->IsChar() && pTok->GetChar() == '(' )
156 : {
157 4407 : SvMetaTypeRef xT = new SvMetaType();
158 4407 : xT->SetRef( GetType() );
159 4407 : aType = xT;
160 4407 : bOk = aType->ReadMethodArgs( rBase, rInStm );
161 : }
162 13022 : if( bOk )
163 13022 : bOk = SvMetaName::ReadSvIdl( rBase, rInStm );
164 : }
165 : else
166 : {
167 5045 : SvToken *pTok = rInStm.GetToken();
168 : rBase.SetError( "unknown type of token. Each new SID needs an "
169 : "item statement in an SDI file, eg. "
170 10090 : "SfxVoidItem FooItem " + pTok->GetTokenAsString() +
171 5045 : " ... which describes the slot more fully", pTok );
172 : }
173 :
174 18067 : if( !bOk )
175 5045 : rInStm.Seek( nTokPos );
176 18067 : return bOk;
177 : }
178 :
179 163575 : void SvMetaAttribute::ReadAttributesSvIdl( SvIdlDataBase & rBase,
180 : SvTokenStream & rInStm )
181 : {
182 163575 : SvMetaReference::ReadAttributesSvIdl( rBase, rInStm );
183 163575 : aSlotId.ReadSvIdl( rBase, SvHash_SlotId(), rInStm );
184 163575 : aExport.ReadSvIdl( SvHash_Export(), rInStm );
185 163575 : aHidden.ReadSvIdl( SvHash_Hidden(), rInStm );
186 163575 : aAutomation.ReadSvIdl( SvHash_Automation(), rInStm );
187 163575 : aIsCollection.ReadSvIdl( SvHash_IsCollection(), rInStm );
188 163575 : aReadOnlyDoc.ReadSvIdl( SvHash_ReadOnlyDoc(), rInStm );
189 163575 : if( aReadonly.ReadSvIdl( SvHash_Readonly(), rInStm ) )
190 : {
191 3469 : if( GetType()->GetType() == TYPE_METHOD )
192 : {
193 : // set error
194 0 : rBase.SetError( "Readonly in function attribute", rInStm.GetToken() );
195 0 : rBase.WriteError( rInStm );
196 : }
197 : }
198 163575 : }
199 :
200 683 : sal_uLong SvMetaAttribute::MakeSfx( OStringBuffer& rAttrArray )
201 : {
202 683 : SvMetaType * pType = GetType();
203 : DBG_ASSERT( pType, "no type for attribute" );
204 683 : SvMetaType * pBaseType = pType->GetBaseType();
205 : DBG_ASSERT( pBaseType, "no base type for attribute" );
206 683 : if( pBaseType->GetType() == TYPE_STRUCT )
207 0 : return pBaseType->MakeSfx( rAttrArray );
208 : else
209 : {
210 683 : rAttrArray.append('{');
211 683 : rAttrArray.append(GetSlotId().getString());
212 683 : rAttrArray.append(",\"");
213 683 : rAttrArray.append(GetName().getString());
214 683 : rAttrArray.append("\"}");
215 683 : return 1;
216 : }
217 : }
218 :
219 9 : void SvMetaAttribute::Insert (SvSlotElementList&, const OString&, SvIdlDataBase&)
220 : {
221 9 : }
222 :
223 17275 : TYPEINIT1( SvMetaType, SvMetaExtern );
224 : #define CTOR \
225 : : aCall0( CALL_VALUE, false ) \
226 : , aCall1( CALL_VALUE, false ) \
227 : , aSbxDataType( 0, false ) \
228 : , pAttrList( NULL ) \
229 : , nType( TYPE_BASE ) \
230 : , bIsItem( false ) \
231 : , bIsShell( false ) \
232 : , cParserChar( 'h' )
233 :
234 6296 : SvMetaType::SvMetaType()
235 6296 : CTOR
236 : {
237 6296 : }
238 :
239 0 : SvMetaType::SvMetaType( const OString& rName, char cPC,
240 : const OString& rCName )
241 0 : CTOR
242 : {
243 0 : SetName( rName );
244 0 : cParserChar = cPC;
245 0 : aCName.setString(rCName);
246 0 : }
247 :
248 104 : SvMetaType::SvMetaType( const OString& rName,
249 : const OString& rSbxName,
250 : const OString& rOdlName,
251 : char cPc,
252 : const OString& rCName,
253 : const OString& rBasicName,
254 : const OString& rBasicPostfix )
255 104 : CTOR
256 : {
257 104 : SetName( rName );
258 104 : aSbxName.setString(rSbxName);
259 104 : aOdlName.setString(rOdlName);
260 104 : cParserChar = cPc;
261 104 : aCName.setString(rCName);
262 104 : aBasicName.setString(rBasicName);
263 104 : aBasicPostfix.setString(rBasicPostfix);
264 104 : }
265 :
266 18775 : SvMetaType::~SvMetaType() {
267 6400 : delete pAttrList;
268 12375 : }
269 :
270 8264 : SvMetaAttributeMemberList & SvMetaType::GetAttrList() const
271 : {
272 8264 : if( !pAttrList )
273 3110 : const_cast<SvMetaType *>(this)->pAttrList = new SvMetaAttributeMemberList();
274 8264 : return *pAttrList;
275 : }
276 :
277 5123 : void SvMetaType::SetType( int nT )
278 : {
279 5123 : nType = nT;
280 5123 : if( nType == TYPE_ENUM )
281 : {
282 219 : aOdlName.setString("short");
283 : }
284 4904 : else if( nType == TYPE_CLASS )
285 : {
286 190 : OStringBuffer aTmp(C_PREF);
287 190 : aTmp.append("Object *");
288 190 : aCName.setString(aTmp.makeStringAndClear());
289 : }
290 5123 : }
291 :
292 11063 : SvMetaType * SvMetaType::GetBaseType() const
293 : {
294 11063 : if( GetRef() && GetType() == TYPE_BASE )
295 3424 : return static_cast<SvMetaType *>(GetRef())->GetBaseType();
296 7639 : return const_cast<SvMetaType *>(this);
297 : }
298 :
299 6771 : SvMetaType * SvMetaType::GetReturnType() const
300 : {
301 : DBG_ASSERT( GetType() == TYPE_METHOD, "no method" );
302 : DBG_ASSERT( GetRef(), "no return type" );
303 6771 : return static_cast<SvMetaType *>(GetRef());
304 : }
305 :
306 0 : const OString& SvMetaType::GetBasicName() const
307 : {
308 0 : if( aBasicName.IsSet() || !GetRef() )
309 0 : return aBasicName.getString();
310 : else
311 0 : return static_cast<SvMetaType*>(GetRef())->GetBasicName();
312 : }
313 :
314 0 : bool SvMetaType::GetIn() const
315 : {
316 0 : if( aIn.IsSet() || !GetRef() )
317 0 : return aIn;
318 : else
319 0 : return static_cast<SvMetaType *>(GetRef())->GetIn();
320 : }
321 :
322 0 : bool SvMetaType::GetOut() const
323 : {
324 0 : if( aOut.IsSet() || !GetRef() )
325 0 : return aOut;
326 : else
327 0 : return static_cast<SvMetaType *>(GetRef())->GetOut();
328 : }
329 :
330 0 : void SvMetaType::SetCall0( int e )
331 : {
332 0 : aCall0 = (int)e;
333 0 : if( aCall0 == CALL_VALUE && aCall1 == CALL_VALUE )
334 : {
335 0 : if( GetType() == TYPE_POINTER )
336 0 : SetType( TYPE_BASE );
337 : }
338 : else
339 : {
340 : DBG_ASSERT( nType == TYPE_POINTER || nType == TYPE_BASE,
341 : "set no base type to pointer" );
342 0 : SetType( TYPE_POINTER );
343 : }
344 0 : }
345 :
346 0 : int SvMetaType::GetCall0() const
347 : {
348 0 : if( aCall0.IsSet() || !GetRef() )
349 0 : return aCall0;
350 : else
351 0 : return static_cast<SvMetaType *>(GetRef())->GetCall0();
352 : }
353 :
354 0 : void SvMetaType::SetCall1( int e )
355 : {
356 0 : aCall1 = (int)e;
357 0 : if( aCall0 == CALL_VALUE && aCall1 == CALL_VALUE )
358 : {
359 0 : if( GetType() == TYPE_POINTER )
360 0 : SetType( TYPE_BASE );
361 : }
362 : else
363 : {
364 : DBG_ASSERT( nType == TYPE_POINTER || nType == TYPE_BASE,
365 : "set no base type to pointer" );
366 0 : SetType( TYPE_POINTER );
367 : }
368 0 : }
369 :
370 0 : int SvMetaType::GetCall1() const
371 : {
372 0 : if( aCall1.IsSet() || !GetRef() )
373 0 : return aCall1;
374 : else
375 0 : return static_cast<SvMetaType *>(GetRef())->GetCall1();
376 : }
377 :
378 0 : const OString& SvMetaType::GetSvName() const
379 : {
380 0 : if( aSvName.IsSet() || !GetRef() )
381 0 : return aSvName.getString();
382 : else
383 0 : return static_cast<SvMetaType *>(GetRef())->GetSvName();
384 : }
385 :
386 0 : const OString& SvMetaType::GetSbxName() const
387 : {
388 0 : if( aSbxName.IsSet() || !GetRef() )
389 0 : return aSbxName.getString();
390 : else
391 0 : return static_cast<SvMetaType *>(GetRef())->GetSbxName();
392 : }
393 :
394 0 : const OString& SvMetaType::GetOdlName() const
395 : {
396 0 : if( aOdlName.IsSet() || !GetRef() )
397 0 : return aOdlName.getString();
398 : else
399 0 : return static_cast<SvMetaType *>(GetRef())->GetOdlName();
400 : }
401 :
402 0 : const OString& SvMetaType::GetCName() const
403 : {
404 0 : if( aCName.IsSet() || !GetRef() )
405 0 : return aCName.getString();
406 : else
407 0 : return static_cast<SvMetaType *>(GetRef())->GetCName();
408 : }
409 :
410 1993 : bool SvMetaType::SetName( const OString& rName, SvIdlDataBase * pBase )
411 : {
412 1993 : aSvName.setString(rName);
413 1993 : aSbxName.setString(rName);
414 1993 : aCName.setString(rName);
415 1993 : if( GetType() != TYPE_ENUM )
416 1774 : aOdlName.setString(rName);
417 1993 : return SvMetaReference::SetName( rName, pBase );
418 : }
419 :
420 1889 : bool SvMetaType::ReadHeaderSvIdl( SvIdlDataBase & rBase,
421 : SvTokenStream & rInStm )
422 : {
423 1889 : bool bOk = false;
424 1889 : sal_uInt32 nTokPos = rInStm.Tell();
425 1889 : SvToken * pTok = rInStm.GetToken_Next();
426 :
427 3778 : if( pTok->Is( SvHash_interface() )
428 1889 : || pTok->Is( SvHash_shell() ) )
429 : {
430 190 : if( pTok->Is( SvHash_shell() ) )
431 83 : bIsShell = true;
432 190 : SetType( TYPE_CLASS );
433 190 : bOk = ReadNamesSvIdl( rBase, rInStm );
434 :
435 : }
436 1699 : else if( pTok->Is( SvHash_struct() ) )
437 : {
438 307 : SetType( TYPE_STRUCT );
439 307 : bOk = ReadNamesSvIdl( rBase, rInStm );
440 : }
441 1392 : else if( pTok->Is( SvHash_union() ) )
442 : {
443 0 : SetType( TYPE_UNION );
444 0 : if( ReadNameSvIdl( rBase, rInStm ) )
445 0 : return true;
446 : }
447 1392 : else if( pTok->Is( SvHash_enum() ) )
448 : {
449 219 : SetType( TYPE_ENUM );
450 219 : bOk = ReadNameSvIdl( rBase, rInStm );
451 : }
452 2346 : else if( pTok->Is( SvHash_typedef() )
453 1173 : || pTok->Is( SvHash_item() ) )
454 : {
455 1173 : if( pTok->Is( SvHash_item() ) )
456 1173 : bIsItem = true;
457 :
458 1173 : SvMetaType * pType = rBase.ReadKnownType( rInStm );
459 1173 : if( pType )
460 : {
461 1173 : SetRef( pType );
462 1173 : if( ReadNameSvIdl( rBase, rInStm ) )
463 : {
464 1173 : if( rInStm.Read( '(' ) )
465 : {
466 0 : DoReadContextSvIdl( rBase, rInStm );
467 0 : if( rInStm.Read( ')' ) )
468 : {
469 0 : SetType( TYPE_METHOD );
470 0 : bOk = true;
471 : }
472 : }
473 : else
474 : {
475 1173 : bOk = true;
476 : }
477 : }
478 : }
479 : else
480 : {
481 0 : OString aStr("wrong typedef: ");
482 0 : rBase.SetError( aStr, rInStm.GetToken() );
483 0 : rBase.WriteError( rInStm );
484 : }
485 : }
486 1889 : if( bOk )
487 1889 : SetModule( rBase );
488 : else
489 0 : rInStm.Seek( nTokPos );
490 1889 : return bOk;
491 : }
492 :
493 1480 : bool SvMetaType::ReadSvIdl( SvIdlDataBase & rBase,
494 : SvTokenStream & rInStm )
495 : {
496 1480 : if( ReadHeaderSvIdl( rBase, rInStm ) )
497 : {
498 1480 : rBase.Write(OString('.'));
499 1480 : return SvMetaExtern::ReadSvIdl( rBase, rInStm );
500 : }
501 0 : return false;
502 : }
503 :
504 497 : bool SvMetaType::ReadNamesSvIdl( SvIdlDataBase & rBase,
505 : SvTokenStream & rInStm )
506 : {
507 497 : bool bOk = ReadNameSvIdl( rBase, rInStm );
508 :
509 497 : return bOk;
510 : }
511 :
512 184 : void SvMetaType::ReadAttributesSvIdl( SvIdlDataBase & rBase,
513 : SvTokenStream & rInStm )
514 : {
515 184 : SvMetaExtern::ReadAttributesSvIdl( rBase, rInStm );
516 184 : aSvName.ReadSvIdl( SvHash_SvName(), rInStm );
517 184 : aSbxName.ReadSvIdl( SvHash_SbxName(), rInStm );
518 184 : aOdlName.ReadSvIdl( SvHash_OdlName(), rInStm );
519 184 : }
520 :
521 9539 : void SvMetaType::ReadContextSvIdl( SvIdlDataBase & rBase,
522 : SvTokenStream & rInStm )
523 : {
524 9539 : SvMetaAttributeRef xAttr = new SvMetaAttribute();
525 9539 : if( xAttr->ReadSvIdl( rBase, rInStm ) )
526 : {
527 4825 : if( xAttr->Test( rBase, rInStm ) )
528 4825 : GetAttrList().push_back( xAttr );
529 9539 : }
530 9539 : }
531 :
532 430 : sal_uLong SvMetaType::MakeSfx( OStringBuffer& rAttrArray )
533 : {
534 430 : sal_uLong nC = 0;
535 :
536 430 : if( GetBaseType()->GetType() == TYPE_STRUCT )
537 : {
538 145 : sal_uLong nAttrCount = GetAttrCount();
539 : // write the single attributes
540 828 : for( sal_uLong n = 0; n < nAttrCount; n++ )
541 : {
542 683 : nC += (*pAttrList)[n]->MakeSfx( rAttrArray );
543 683 : if( n +1 < nAttrCount )
544 538 : rAttrArray.append(", ");
545 : }
546 : }
547 430 : return nC;
548 : }
549 :
550 430 : void SvMetaType::WriteSfxItem(
551 : const OString& rItemName, SvIdlDataBase& rBase, SvStream& rOutStm )
552 : {
553 430 : WriteStars( rOutStm );
554 430 : OStringBuffer aVarName(" a");
555 430 : aVarName.append(rItemName).append("_Impl");
556 :
557 826 : OStringBuffer aTypeName("SfxType");
558 826 : OStringBuffer aAttrArray;
559 430 : sal_uLong nAttrCount = MakeSfx( aAttrArray );
560 : OString aAttrCount(
561 826 : OString::number(nAttrCount));
562 430 : aTypeName.append(aAttrCount);
563 :
564 430 : bool bExport = false, bReturn = false;
565 : // these are exported from sfx library
566 1282 : if (rItemName == "SfxBoolItem" ||
567 836 : rItemName == "SfxStringItem" ||
568 820 : rItemName == "SfxUInt16Item" ||
569 1235 : rItemName == "SfxUInt32Item" ||
570 399 : rItemName == "SfxVoidItem")
571 : {
572 39 : bExport = true;
573 39 : if (!rBase.sSlotMapFile.endsWith("sfxslots.hxx"))
574 34 : bReturn = true;
575 : }
576 :
577 430 : rOutStm.WriteCharPtr( "extern " );
578 430 : if (bExport)
579 39 : rOutStm.WriteCharPtr( "SFX2_DLLPUBLIC " );
580 430 : rOutStm.WriteCharPtr( aTypeName.getStr() )
581 860 : .WriteCharPtr( aVarName.getStr() ).WriteChar( ';' ) << endl;
582 430 : if (bReturn)
583 464 : return;
584 :
585 : // write the implementation part
586 396 : rOutStm.WriteCharPtr( "#ifdef SFX_TYPEMAP" ) << endl;
587 396 : rOutStm.WriteCharPtr( "#if !defined(_WIN32) && ((defined(DISABLE_DYNLOADING) && (defined(ANDROID) || defined(IOS))) || STATIC_LINKING)" ) << endl;
588 396 : rOutStm.WriteCharPtr( "__attribute__((__weak__))" ) << endl;
589 396 : rOutStm.WriteCharPtr( "#endif" ) << endl;
590 396 : if (bExport)
591 5 : rOutStm.WriteCharPtr( "SFX2_DLLPUBLIC " );
592 396 : rOutStm.WriteCharPtr( aTypeName.getStr() ).WriteCharPtr( aVarName.getStr() )
593 396 : .WriteCharPtr( " = " ) << endl;
594 396 : rOutStm.WriteChar( '{' ) << endl;
595 396 : rOutStm.WriteCharPtr( "\tTYPE(" ).WriteCharPtr( rItemName.getStr() ).WriteCharPtr( "), " )
596 792 : .WriteCharPtr( aAttrCount.getStr() );
597 396 : if( nAttrCount )
598 : {
599 145 : rOutStm.WriteCharPtr( ", { " );
600 : // write the single attributes
601 145 : rOutStm.WriteCharPtr( aAttrArray.getStr() );
602 145 : rOutStm.WriteCharPtr( " }" );
603 : }
604 396 : rOutStm << endl;
605 396 : rOutStm.WriteCharPtr( "};" ) << endl;
606 792 : rOutStm.WriteCharPtr( "#endif" ) << endl << endl;
607 : }
608 :
609 2345 : void SvMetaType::WriteSfx( SvIdlDataBase & rBase, SvStream & rOutStm )
610 : {
611 2345 : if( IsItem() )
612 : {
613 430 : if( GetBaseType()->GetType() == TYPE_STRUCT )
614 145 : GetBaseType()->WriteSfxItem( GetName().getString(), rBase, rOutStm );
615 : else
616 285 : WriteSfxItem( GetName().getString(), rBase, rOutStm );
617 : }
618 2345 : }
619 :
620 4407 : bool SvMetaType::ReadMethodArgs( SvIdlDataBase & rBase,
621 : SvTokenStream & rInStm )
622 : {
623 4407 : sal_uInt32 nTokPos = rInStm.Tell();
624 4407 : if( rInStm.Read( '(' ) )
625 : {
626 4407 : DoReadContextSvIdl( rBase, rInStm );
627 4407 : if( rInStm.Read( ')' ) )
628 : {
629 4407 : SetType( TYPE_METHOD );
630 4407 : return true;
631 : }
632 : }
633 0 : rInStm.Seek( nTokPos );
634 0 : return false;
635 : }
636 :
637 0 : OString SvMetaType::GetParserString() const
638 : {
639 0 : SvMetaType * pBT = GetBaseType();
640 0 : if( pBT != this )
641 0 : return pBT->GetParserString();
642 :
643 0 : int type = GetType();
644 0 : OString aPStr;
645 :
646 0 : if( TYPE_METHOD == type || TYPE_STRUCT == type )
647 : {
648 0 : sal_uLong nAttrCount = GetAttrCount();
649 : // write the single attributes
650 0 : for( sal_uLong n = 0; n < nAttrCount; n++ )
651 : {
652 0 : SvMetaAttribute * pT = (*pAttrList)[n];
653 0 : aPStr += pT->GetType()->GetParserString();
654 0 : }
655 : }
656 : else
657 0 : aPStr = OString(GetParserChar());
658 0 : return aPStr;
659 : }
660 :
661 747 : TYPEINIT1( SvMetaTypeString, SvMetaType );
662 8 : SvMetaTypeString::SvMetaTypeString()
663 8 : : SvMetaType( "String", "SbxSTRING", "BSTR", 's', "char *", "String", "$" )
664 : {
665 8 : }
666 :
667 0 : TYPEINIT1( SvMetaEnumValue, SvMetaName );
668 1699 : SvMetaEnumValue::SvMetaEnumValue()
669 : {
670 1699 : }
671 :
672 1699 : bool SvMetaEnumValue::ReadSvIdl( SvIdlDataBase & rBase,
673 : SvTokenStream & rInStm )
674 : {
675 1699 : if( !ReadNameSvIdl( rBase, rInStm ) )
676 219 : return false;
677 1480 : return true;
678 : }
679 :
680 6197 : TYPEINIT1( SvMetaTypeEnum, SvMetaType );
681 219 : SvMetaTypeEnum::SvMetaTypeEnum()
682 : {
683 219 : SetBasicName("Integer");
684 219 : }
685 :
686 : namespace
687 : {
688 1261 : OString getCommonSubPrefix(const OString &rA, const OString &rB)
689 : {
690 1261 : sal_Int32 nMax = std::min(rA.getLength(), rB.getLength());
691 1261 : sal_Int32 nI = 0;
692 16333 : while (nI < nMax)
693 : {
694 14044 : if (rA[nI] != rB[nI])
695 233 : break;
696 13811 : ++nI;
697 : }
698 1261 : return rA.copy(0, nI);
699 : }
700 : }
701 :
702 1699 : void SvMetaTypeEnum::ReadContextSvIdl( SvIdlDataBase & rBase,
703 : SvTokenStream & rInStm )
704 : {
705 1699 : sal_uInt32 nTokPos = rInStm.Tell();
706 :
707 1699 : SvMetaEnumValueRef aEnumVal = new SvMetaEnumValue();
708 1699 : bool bOk = aEnumVal->ReadSvIdl( rBase, rInStm );
709 1699 : if( bOk )
710 : {
711 1480 : if( aEnumValueList.empty() )
712 : {
713 : // the first
714 219 : aPrefix = aEnumVal->GetName().getString();
715 : }
716 : else
717 : {
718 1261 : aPrefix = getCommonSubPrefix(aPrefix, aEnumVal->GetName().getString());
719 : }
720 1480 : aEnumValueList.push_back( aEnumVal );
721 : }
722 1699 : if( !bOk )
723 219 : rInStm.Seek( nTokPos );
724 1699 : }
725 :
726 219 : bool SvMetaTypeEnum::ReadSvIdl( SvIdlDataBase & rBase,
727 : SvTokenStream & rInStm )
728 : {
729 219 : sal_uInt32 nTokPos = rInStm.Tell();
730 438 : if( SvMetaType::ReadHeaderSvIdl( rBase, rInStm )
731 219 : && GetType() == TYPE_ENUM )
732 : {
733 219 : if( SvMetaName::ReadSvIdl( rBase, rInStm ) )
734 219 : return true;
735 : }
736 0 : rInStm.Seek( nTokPos );
737 0 : return false;
738 : }
739 :
740 249 : TYPEINIT1( SvMetaTypevoid, SvMetaType );
741 8 : SvMetaTypevoid::SvMetaTypevoid()
742 8 : : SvMetaType( "void", "SbxVOID", "void", 'v', "void", "", "" )
743 : {
744 8 : }
745 :
746 0 : OString SvMetaAttribute::Compare( SvMetaAttribute* pAttr )
747 : {
748 0 : OStringBuffer aStr;
749 :
750 0 : if ( aType.Is() )
751 : {
752 0 : if ( aType->GetType() == TYPE_METHOD )
753 : {
754 : // Test only when the attribute is a method not if it has one!
755 0 : if ( pAttr->GetType()->GetType() != TYPE_METHOD )
756 0 : aStr.append(" IsMethod\n");
757 0 : else if ( aType->GetReturnType() &&
758 0 : aType->GetReturnType()->GetType() != pAttr->GetType()->GetReturnType()->GetType() )
759 : {
760 0 : aStr.append(" ReturnType\n");
761 : }
762 :
763 0 : if ( aType->GetAttrCount() )
764 : {
765 0 : sal_uLong nCount = aType->GetAttrCount();
766 0 : SvMetaAttributeMemberList& rList = aType->GetAttrList();
767 0 : SvMetaAttributeMemberList& rOtherList = pAttr->GetType()->GetAttrList();
768 0 : if ( pAttr->GetType()->GetAttrCount() != nCount )
769 : {
770 0 : aStr.append(" AttributeCount\n");
771 : }
772 : else
773 : {
774 0 : for ( sal_uLong n=0; n<nCount; n++ )
775 : {
776 0 : SvMetaAttribute *pAttr1 = rList[n];
777 0 : SvMetaAttribute *pAttr2 = rOtherList[n];
778 0 : pAttr1->Compare( pAttr2 );
779 : }
780 : }
781 : }
782 : }
783 :
784 0 : if ( GetType()->GetType() != pAttr->GetType()->GetType() )
785 0 : aStr.append(" Type\n");
786 :
787 0 : if ( !GetType()->GetSvName().equals( pAttr->GetType()->GetSvName() ) )
788 0 : aStr.append(" ItemType\n");
789 : }
790 :
791 0 : if ( GetExport() != pAttr->GetExport() )
792 0 : aStr.append(" Export\n");
793 :
794 0 : if ( GetAutomation() != pAttr->GetAutomation() )
795 0 : aStr.append(" Automation\n");
796 :
797 0 : if ( GetIsCollection() != pAttr->GetIsCollection() )
798 0 : aStr.append(" IsCollection\n");
799 :
800 0 : if ( GetReadOnlyDoc() != pAttr->GetReadOnlyDoc() )
801 0 : aStr.append(" ReadOnlyDoc\n");
802 :
803 0 : if ( GetExport() && GetReadonly() != pAttr->GetReadonly() )
804 0 : aStr.append(" Readonly\n");
805 :
806 0 : return aStr.makeStringAndClear();
807 : }
808 :
809 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|