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