LibreOffice Module idl (master) 1
types.cxx
Go to the documentation of this file.
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#include <sal/config.h>
21
22#include <algorithm>
23
24#include <tools/debug.hxx>
25
26#include <types.hxx>
27#include <globals.hxx>
28#include <database.hxx>
29
31{
32}
33
35 : aType( pType )
36{
37}
38
40{
41 if( aType.is() || !GetRef() ) return aType.get();
42 return static_cast<SvMetaAttribute *>(GetRef())->GetType();
43}
44
46{
47 if( aSlotId.IsSet() || !GetRef() ) return aSlotId;
48 return static_cast<SvMetaAttribute *>(GetRef())->GetSlotId();
49}
50
52{
53 if( GetType()->IsItem() && !GetSlotId().IsSet() )
54 {
55 throw SvParseException( rInStm, "slot without id declared" );
56 }
57 return true;
58}
59
61 SvTokenStream & rInStm )
62{
63 sal_uInt32 nTokPos = rInStm.Tell();
64 if( !GetType() )
65 // no type in ctor passed on
66 aType = rBase.ReadKnownType( rInStm );
67 bool bOk = false;
68 if( GetType() )
69 {
70 ReadNameSvIdl( rInStm );
71 aSlotId.ReadSvIdl( rBase, rInStm );
72
73 bOk = true;
74 SvToken& rTok = rInStm.GetToken();
75 if( rTok.IsChar() && rTok.GetChar() == '(' )
76 {
78 xT->SetRef( GetType() );
79 aType = xT;
80 bOk = aType->ReadMethodArgs( rBase, rInStm );
81 }
82 if( bOk )
83 bOk = SvMetaObject::ReadSvIdl( rBase, rInStm );
84 }
85 else
86 {
87 SvToken& rTok = rInStm.GetToken();
88 rBase.SetError( "unknown type of token. Each new SID needs an "
89 "item statement in an SDI file, eg. "
90 "SfxVoidItem FooItem " + rTok.GetTokenAsString() +
91 " ... which describes the slot more fully", rTok );
92 }
93
94 if( !bOk )
95 rInStm.Seek( nTokPos );
96 return bOk;
97}
98
99size_t SvMetaAttribute::MakeSfx( OStringBuffer& rAttrArray ) const
100{
101 SvMetaType * pType = GetType();
102 DBG_ASSERT( pType, "no type for attribute" );
103 SvMetaType * pBaseType = pType->GetBaseType();
104 DBG_ASSERT( pBaseType, "no base type for attribute" );
105 if( pBaseType->GetMetaTypeType() == MetaTypeType::Struct )
106 return pBaseType->MakeSfx( rAttrArray );
107 else
108 {
109 rAttrArray.append('{');
110 rAttrArray.append(GetSlotId().getString());
111 rAttrArray.append(",\"");
112 rAttrArray.append(GetName());
113 rAttrArray.append("\"}");
114 return 1;
115 }
116}
117
119{
120}
121
124 , bIsItem( false )
125{
126}
127
128SvMetaType::SvMetaType( const OString& rName )
129 : SvMetaType()
130{
131 SetName( rName );
132}
133
135{}
136
138{
139 nType = nT;
140}
141
143{
145 return static_cast<SvMetaType *>(GetRef())->GetBaseType();
146 return const_cast<SvMetaType *>(this);
147}
148
150{
152 DBG_ASSERT( GetRef(), "no return type" );
153 return static_cast<SvMetaType *>(GetRef());
154}
155
157{
158 bool bOk = false;
159 sal_uInt32 nTokPos = rInStm.Tell();
160 SvToken& rTok = rInStm.GetToken_Next();
161
162 if( rTok.Is( SvHash_interface() ) )
163 {
165 bOk = ReadNameSvIdl( rInStm );
166 }
167 else if( rTok.Is( SvHash_shell() ) )
168 {
170 bOk = ReadNameSvIdl( rInStm );
171 }
172 if( !bOk )
173 rInStm.Seek( nTokPos );
174 return bOk;
175}
176
178 SvTokenStream & rInStm )
179{
180 if( ReadHeaderSvIdl( rInStm ) )
181 {
182 rBase.Write(OString('.'));
183 return SvMetaReference::ReadSvIdl( rBase, rInStm );
184 }
185 return false;
186}
187
189 SvTokenStream & rInStm )
190{
192 if( xAttr->ReadSvIdl( rBase, rInStm ) )
193 {
194 if( xAttr->Test( rInStm ) )
195 GetAttrList().push_back( xAttr.get() );
196 }
197}
198
199size_t SvMetaType::MakeSfx( OStringBuffer& rAttrArray )
200{
201 size_t nC = 0;
202
204 {
205 size_t nAttrCount = GetAttrCount();
206 // write the single attributes
207 for( size_t n = 0; n < nAttrCount; n++ )
208 {
209 nC += aAttrList[n]->MakeSfx( rAttrArray );
210 if( n +1 < nAttrCount )
211 rAttrArray.append(", ");
212 }
213 }
214 return nC;
215}
216
218 std::string_view rItemName, SvIdlDataBase const & rBase, SvStream& rOutStm )
219{
220 WriteStars( rOutStm );
221 OString aVarName = OString::Concat(" a") + rItemName + "_Impl";
222
223 OStringBuffer aAttrArray(1024);
224 size_t nAttrCount = MakeSfx( aAttrArray );
225 OString aAttrCount( OString::number(nAttrCount));
226 OString aTypeName = "SfxType" + aAttrCount;
227
228 bool bExport = false, bReturn = false;
229 // these are exported from sfx library
230 if (rItemName == "SfxBoolItem" ||
231 rItemName == "SfxInt16Item" ||
232 rItemName == "SfxStringItem" ||
233 rItemName == "SfxUInt16Item" ||
234 rItemName == "SfxUInt32Item" ||
235 rItemName == "SfxVoidItem")
236 {
237 bExport = true;
238 if (!rBase.sSlotMapFile.endsWith("sfxslots.hxx"))
239 bReturn = true;
240 }
241
242 rOutStm.WriteOString( "extern " );
243 if (bExport)
244 rOutStm.WriteOString( "SFX2_DLLPUBLIC " );
245 rOutStm.WriteOString( aTypeName )
246 .WriteOString( aVarName ).WriteChar( ';' ) << endl;
247 if (bReturn)
248 return;
249
250 // write the implementation part
251 rOutStm.WriteOString( "#ifdef SFX_TYPEMAP" ) << endl;
252 rOutStm.WriteOString( "#if !defined(_WIN32) && (defined(DISABLE_DYNLOADING) && (defined(ANDROID) || defined(IOS) || defined(EMSCRIPTEN) || defined(LINUX)))" ) << endl;
253 rOutStm.WriteOString( "__attribute__((__weak__))" ) << endl;
254 rOutStm.WriteOString( "#endif" ) << endl;
255 rOutStm.WriteOString( aTypeName ).WriteOString( aVarName )
256 .WriteOString( " = " ) << endl;
257 rOutStm.WriteChar( '{' ) << endl;
258
259 rOutStm.WriteOString( "\tcreateSfxPoolItem<" ).WriteOString( rItemName )
260 .WriteOString(">, &typeid(").WriteOString( rItemName ).WriteOString( "), " );
261 rOutStm.WriteOString( aAttrCount );
262 if( nAttrCount )
263 {
264 rOutStm.WriteOString( ", { " );
265 // write the single attributes
266 rOutStm.WriteOString( aAttrArray );
267 rOutStm.WriteOString( " }" );
268 }
269 rOutStm << endl;
270 rOutStm.WriteOString( "};" ) << endl;
271 rOutStm.WriteOString( "#endif" ) << endl << endl;
272}
273
275{
276 if( IsItem() )
277 {
279 GetBaseType()->WriteSfxItem( GetName(), rBase, rOutStm );
280 else
281 WriteSfxItem( GetName(), rBase, rOutStm );
282 }
283}
284
286 SvTokenStream & rInStm )
287{
288 sal_uInt32 nTokPos = rInStm.Tell();
289 if( rInStm.ReadIf( '(' ) )
290 {
291 DoReadContextSvIdl( rBase, rInStm );
292 if( rInStm.ReadIf( ')' ) )
293 {
295 return true;
296 }
297 }
298 rInStm.Seek( nTokPos );
299 return false;
300}
301
303 : SvMetaType( "String" )
304{
305}
306
308{
309}
310
312{
313}
314
316 : SvMetaType( "void" )
317{
318}
319
320/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void ReadSvIdl(SvStringHashEntry const *pName, SvTokenStream &rInStm)
Definition: bastype.cxx:49
bool IsSet() const
Definition: bastype.hxx:60
OUString sSlotMapFile
Definition: database.hxx:84
void SetError(const SvIdlError &r)
Definition: database.hxx:101
void Write(const OString &rText) const
Definition: database.cxx:394
SvMetaType * ReadKnownType(SvTokenStream &rInStm)
Definition: database.cxx:294
SvMetaType * GetType() const
Definition: types.cxx:39
const SvIdentifier & GetSlotId() const
Definition: types.cxx:45
virtual bool Test(SvTokenStream &rInStm)
Definition: types.cxx:51
SvIdentifier aSlotId
Definition: types.hxx:35
virtual bool ReadSvIdl(SvIdlDataBase &, SvTokenStream &rInStm) override
Definition: types.cxx:60
size_t MakeSfx(OStringBuffer &rAtrrArray) const
Definition: types.cxx:99
tools::SvRef< SvMetaType > aType
Definition: types.hxx:34
virtual void Insert(SvSlotElementList &)
Definition: types.cxx:118
void DoReadContextSvIdl(SvIdlDataBase &, SvTokenStream &rInStm)
Definition: basobj.cxx:92
void SetName(const OString &rName)
Definition: basobj.cxx:66
static void WriteStars(SvStream &)
Definition: basobj.cxx:33
bool ReadNameSvIdl(SvTokenStream &rInStm)
Definition: basobj.cxx:71
virtual bool ReadSvIdl(SvIdlDataBase &, SvTokenStream &rInStm)
Definition: basobj.cxx:108
SvMetaReference * GetRef() const
Definition: basobj.hxx:120
const OString & GetName() const override
Definition: basobj.hxx:112
bool IsItem() const
Definition: types.hxx:79
SvMetaType()
Definition: types.cxx:122
MetaTypeType nType
Definition: types.hxx:55
virtual bool ReadSvIdl(SvIdlDataBase &, SvTokenStream &rInStm) override
Definition: types.cxx:177
bool ReadMethodArgs(SvIdlDataBase &rBase, SvTokenStream &rInStm)
Definition: types.cxx:285
bool ReadHeaderSvIdl(SvTokenStream &rInStm)
Definition: types.cxx:156
MetaTypeType GetMetaTypeType() const
Definition: types.hxx:75
SvRefMemberList< SvMetaAttribute * > & GetAttrList()
Definition: types.hxx:71
size_t MakeSfx(OStringBuffer &rAtrrArray)
Definition: types.cxx:199
void WriteSfxItem(std::string_view rItemName, SvIdlDataBase const &rBase, SvStream &rOutStm)
Definition: types.cxx:217
SvMetaType * GetBaseType() const
Definition: types.cxx:142
void SetType(MetaTypeType nT)
Definition: types.cxx:137
virtual void ReadContextSvIdl(SvIdlDataBase &, SvTokenStream &rInStm) override
Definition: types.cxx:188
virtual ~SvMetaType() override
Definition: types.cxx:134
SvRefMemberList< SvMetaAttribute * > aAttrList
Definition: types.hxx:54
SvMetaType * GetReturnType() const
Definition: types.cxx:149
size_t GetAttrCount() const
Definition: types.hxx:72
virtual void WriteSfx(SvIdlDataBase &rBase, SvStream &rOutStm)
Definition: types.cxx:274
void push_back(T p)
Definition: basobj.hxx:62
SvStream & WriteOString(std::string_view rStr)
SvStream & WriteChar(char nChar)
void Seek(sal_uInt32 nPos)
Definition: lex.hxx:202
SvToken & GetToken() const
Definition: lex.hxx:177
bool ReadIf(char cChar)
Definition: lex.hxx:179
SvToken & GetToken_Next()
Definition: lex.hxx:165
sal_uInt32 Tell() const
Definition: lex.hxx:200
Definition: lex.hxx:36
bool IsChar() const
Definition: lex.hxx:73
OString GetTokenAsString() const
Definition: lex.cxx:27
bool Is(SvStringHashEntry const *pEntry) const
Definition: lex.hxx:88
char GetChar() const
Definition: lex.hxx:84
T * get() const
bool is() const
#define DBG_ASSERT(sCon, aError)
sal_Int64 n
OUString getString(const Any &_rAny)
QPRO_FUNC_TYPE nType
TOOLS_DLLPUBLIC SvStream & endl(SvStream &rStr)
MetaTypeType
Definition: types.hxx:50
@ Interface
Definition: types.hxx:50
@ Struct
Definition: types.hxx:50
@ Shell
Definition: types.hxx:50
@ Method
Definition: types.hxx:50
@ Base
Definition: types.hxx:50