1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
25 #include <globals.hxx>
26 #include <database.hxx>
27 #include <tools/debug.hxx>
28 #include <osl/file.hxx>
30 TYPEINIT1( SvMetaModule
, SvMetaExtern
);
32 SvMetaModule::SvMetaModule( const OUString
& rIdlFileName
, bool bImp
)
33 : aIdlFileName( rIdlFileName
)
34 , bImported( bImp
), bIsModified( false )
38 bool SvMetaModule::SetName( const OString
& rName
, SvIdlDataBase
* pBase
)
42 if( pBase
->GetModule( rName
) )
45 return SvMetaExtern::SetName( rName
);
48 bool SvMetaModule::FillNextName( SvGlobalName
* pName
)
52 if( aNextName
< aEndName
)
61 void SvMetaModule::ReadAttributesSvIdl( SvIdlDataBase
& rBase
,
62 SvTokenStream
& rInStm
)
64 SvMetaExtern::ReadAttributesSvIdl( rBase
, rInStm
);
66 aHelpFileName
.ReadSvIdl( SvHash_HelpFile(), rInStm
);
67 if( aSlotIdFile
.ReadSvIdl( SvHash_SlotIdFile(), rInStm
) )
69 sal_uInt32 nTokPos
= rInStm
.Tell();
70 if( !rBase
.ReadIdFile( OStringToOUString(aSlotIdFile
.getString(), RTL_TEXTENCODING_ASCII_US
)) )
72 OStringBuffer
aStr("cannot read file: ");
73 aStr
.append(aSlotIdFile
.getString());
74 rBase
.SetError( aStr
.makeStringAndClear(), rInStm
.GetToken() );
75 rBase
.WriteError( rInStm
);
77 rInStm
.Seek( nTokPos
);
80 aTypeLibFile
.ReadSvIdl( SvHash_TypeLibFile(), rInStm
);
81 aModulePrefix
.ReadSvIdl( SvHash_ModulePrefix(), rInStm
);
84 void SvMetaModule::ReadContextSvIdl( SvIdlDataBase
& rBase
,
85 SvTokenStream
& rInStm
)
87 sal_uInt32 nTokPos
= rInStm
.Tell();
88 if( rInStm
.GetToken()->Is( SvHash_interface() )
89 || rInStm
.GetToken()->Is( SvHash_shell() ) )
91 SvMetaClassRef aClass
= new SvMetaClass();
92 if( aClass
->ReadSvIdl( rBase
, rInStm
) )
94 aClassList
.push_back( aClass
);
96 rBase
.GetClassList().push_back( aClass
);
99 else if( rInStm
.GetToken()->Is( SvHash_enum() ) )
101 SvMetaTypeEnumRef aEnum
= new SvMetaTypeEnum();
103 if( aEnum
->ReadSvIdl( rBase
, rInStm
) )
105 // declared in module
106 aTypeList
.push_back( aEnum
);
108 rBase
.GetTypeList().push_back( aEnum
);
111 else if( rInStm
.GetToken()->Is( SvHash_item() )
112 || rInStm
.GetToken()->Is( SvHash_struct() )
113 || rInStm
.GetToken()->Is( SvHash_typedef() ) )
115 SvMetaTypeRef xItem
= new SvMetaType();
117 if( xItem
->ReadSvIdl( rBase
, rInStm
) )
119 // declared in module
120 aTypeList
.push_back( xItem
);
122 rBase
.GetTypeList().push_back( xItem
);
125 else if( rInStm
.GetToken()->Is( SvHash_include() ) )
128 rInStm
.GetToken_Next();
129 SvToken
* pTok
= rInStm
.GetToken_Next();
130 if( pTok
->IsString() )
132 OUString
aFullName(OStringToOUString(pTok
->GetString(), RTL_TEXTENCODING_ASCII_US
));
133 rBase
.StartNewFile( aFullName
);
134 osl::FileBase::RC searchError
= osl::File::searchFileURL(aFullName
, rBase
.GetPath(), aFullName
);
135 osl::FileBase::getSystemPathFromFileURL( aFullName
, aFullName
);
137 if( osl::FileBase::E_None
== searchError
)
139 rBase
.AddDepFile( aFullName
);
140 SvTokenStream
aTokStm( aFullName
);
142 if( SVSTREAM_OK
== aTokStm
.GetStream().GetError() )
144 // rescue error from old file
145 SvIdlError aOldErr
= rBase
.GetError();
147 rBase
.SetError( SvIdlError() );
149 sal_uInt32 nBeginPos
= 0xFFFFFFFF; // can not happen with Tell
150 while( nBeginPos
!= aTokStm
.Tell() )
152 nBeginPos
= aTokStm
.Tell();
153 ReadContextSvIdl( rBase
, aTokStm
);
154 aTokStm
.ReadDelemiter();
156 bOk
= aTokStm
.GetToken()->IsEof();
159 rBase
.WriteError( aTokStm
);
161 // recover error from old file
162 rBase
.SetError( aOldErr
);
166 OStringBuffer
aStr("cannot open file: ");
167 aStr
.append(OUStringToOString(aFullName
, RTL_TEXTENCODING_UTF8
));
168 rBase
.SetError(aStr
.makeStringAndClear(), pTok
);
173 OStringBuffer
aStr("cannot find file:");
174 aStr
.append(OUStringToOString(aFullName
, RTL_TEXTENCODING_UTF8
));
175 rBase
.SetError(aStr
.makeStringAndClear(), pTok
);
179 rInStm
.Seek( nTokPos
);
183 SvMetaSlotRef xSlot
= new SvMetaSlot();
185 if( xSlot
->ReadSvIdl( rBase
, rInStm
) )
187 if( xSlot
->Test( rBase
, rInStm
) )
189 // declared in module
190 aAttrList
.push_back( xSlot
);
192 rBase
.AppendAttr( xSlot
);
198 bool SvMetaModule::ReadSvIdl( SvIdlDataBase
& rBase
, SvTokenStream
& rInStm
)
200 bIsModified
= true; // up to now always when compiler running
202 sal_uInt32 nTokPos
= rInStm
.Tell();
203 SvToken
* pTok
= rInStm
.GetToken_Next();
204 bool bOk
= pTok
->Is( SvHash_module() );
207 pTok
= rInStm
.GetToken_Next();
208 if( pTok
->IsString() )
209 bOk
= aBeginName
.MakeId(OStringToOUString(pTok
->GetString(), RTL_TEXTENCODING_ASCII_US
));
211 rInStm
.ReadDelemiter();
214 pTok
= rInStm
.GetToken_Next();
215 if( pTok
->IsString() )
216 bOk
= aEndName
.MakeId(OStringToOUString(pTok
->GetString(), RTL_TEXTENCODING_ASCII_US
));
218 rInStm
.ReadDelemiter();
221 aNextName
= aBeginName
;
223 rBase
.Push( this ); // onto the context stack
225 if( ReadNameSvIdl( rBase
, rInStm
) )
227 // set pointer to itself
229 bOk
= SvMetaName::ReadSvIdl( rBase
, rInStm
);
231 rBase
.GetStack().Pop(); // remove from stack
234 rInStm
.Seek( nTokPos
);
238 void SvMetaModule::WriteSfx( SvIdlDataBase
& rBase
, SvStream
& rOutStm
)
240 for( sal_uLong n
= 0; n
< aClassList
.size(); n
++ )
242 SvMetaClass
* pClass
= aClassList
[n
];
243 pClass
->WriteSfx( rBase
, rOutStm
);
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */