1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_CPPUTYPE_HXX
25 #define INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_CPPUTYPE_HXX
26 
27 #include "codemaker/dependencies.hxx"
28 #include "codemaker/options.hxx"
29 #include "codemaker/typemanager.hxx"
30 #include "codemaker/commoncpp.hxx"
31 #include "registry/reader.hxx"
32 #include "registry/types.h"
33 #include "rtl/string.hxx"
34 
35 namespace rtl { class OUString; }
36 namespace codemaker {
37     namespace cppumaker { class Includes; }
38     struct ExceptionTreeNode;
39     class GeneratedTypeSet;
40 }
41 
42 enum CppuTypeDecl
43 {
44 	CPPUTYPEDECL_ALLTYPES,
45 	CPPUTYPEDECL_NOINTERFACES,
46 	CPPUTYPEDECL_ONLYINTERFACES
47 };
48 
49 class CppuOptions;
50 class FileStream;
51 
52 class CppuType
53 {
54 public:
55 	CppuType(typereg::Reader& typeReader,
56 			 const ::rtl::OString& typeName,
57 			 const TypeManager& typeMgr);
58 
59 	virtual ~CppuType();
60 
61 	virtual sal_Bool dump(CppuOptions* pOptions) throw( CannotDumpException );
62     sal_Bool dumpFile(CppuOptions* pOptions,
63                       const ::rtl::OString& sExtension,
64                       const ::rtl::OString& sName,
65                       const ::rtl::OString& sOutPath )
66         throw( CannotDumpException );
67     void dumpDependedTypes(
68         codemaker::GeneratedTypeSet & generated, CppuOptions * options);
69 	virtual sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ) = 0;
70 	virtual sal_Bool dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ) = 0;
71 
72     ::rtl::OString dumpHeaderDefine(
73         FileStream& o, char const * prefix, sal_Bool bExtended=sal_False);
74 
75     void dumpGetCppuType(FileStream & out);
76 	virtual void dumpLightGetCppuType(FileStream& o);
77 	virtual void dumpNormalGetCppuType(FileStream& o);
78 	virtual void dumpComprehensiveGetCppuType(FileStream& o);
79 
80 	virtual void dumpType(FileStream& o, const ::rtl::OString& type, bool bConst=false,
81 						  bool bRef=false, bool bNative=false, bool cppuUnoType=false)
82         const throw( CannotDumpException );
83 	::rtl::OString	getTypeClass(const ::rtl::OString& type="", sal_Bool bCStyle=sal_False);
84 	void	dumpCppuGetType(FileStream& o, const ::rtl::OString& type, sal_Bool bDecl=sal_False, CppuTypeDecl eDeclFlag=CPPUTYPEDECL_ALLTYPES);
85 
86 	::rtl::OString typeToIdentifier(const ::rtl::OString& type);
87 
88 	void 	dumpConstantValue(FileStream& o, sal_uInt16 index);
89 
90 	virtual sal_uInt32  getMemberCount();
91 	virtual sal_uInt32	getInheritedMemberCount();
92 
93 	void 			inc(sal_Int32 num=4);
94 	void 			dec(sal_Int32 num=4);
95 	::rtl::OString 	indent() const;
96 protected:
97     virtual sal_uInt32 checkInheritedMemberCount(
98         const typereg::Reader* pReader);
99 
100     bool passByReference(rtl::OString const & unoType);
101 
102 	::rtl::OString	resolveTypedefs(const ::rtl::OString& type) const;
103 	::rtl::OString	checkRealBaseType(const ::rtl::OString& type, sal_Bool bResolveTypeOnly = sal_False) const;
104 	void	dumpCppuGetTypeMemberDecl(FileStream& o, CppuTypeDecl eDeclFlag);
105 
106     codemaker::cpp::IdentifierTranslationMode isGlobal() const;
107 
addSpecialDependencies()108     virtual void addSpecialDependencies() {}
109 
110     virtual bool dumpFiles(CppuOptions * options, rtl::OString const & outPath);
111 
112     virtual void addLightGetCppuTypeIncludes(
113         codemaker::cppumaker::Includes & includes) const;
114 
115     virtual void addNormalGetCppuTypeIncludes(
116         codemaker::cppumaker::Includes & includes) const;
117 
118     virtual void addComprehensiveGetCppuTypeIncludes(
119         codemaker::cppumaker::Includes & includes) const;
120 
121     virtual bool isPolymorphic() const;
122 
123     virtual void dumpTemplateHead(FileStream & out) const;
124 
125     virtual void dumpTemplateParameters(FileStream & out) const;
126 
127     void dumpGetCppuTypePreamble(FileStream & out);
128 
129     void dumpGetCppuTypePostamble(FileStream & out);
130 
131     void addDefaultHIncludes(codemaker::cppumaker::Includes & includes) const;
132     void addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes) const;
133 
134     void dumpInitializer(
135         FileStream & out, bool parameterized, rtl::OUString const & type) const;
136 
137 protected:
138 	sal_uInt32 			m_inheritedMemberCount;
139 
140 	sal_Bool			m_cppuTypeLeak;
141 	sal_Bool			m_cppuTypeDynamic;
142 	sal_Int32			m_indentLength;
143 	::rtl::OString		m_typeName;
144 	::rtl::OString		m_name;
145     typereg::Reader     m_reader;
146     TypeManager const & m_typeMgr;
147     codemaker::Dependencies m_dependencies;
148 
149 private:
150     void addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes)
151         const;
152 };
153 
154 class InterfaceType : public CppuType
155 {
156 public:
157 	InterfaceType(typereg::Reader& typeReader,
158 				 const ::rtl::OString& typeName,
159                  const TypeManager& typeMgr);
160 
161 	virtual ~InterfaceType();
162 
163 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
164 	sal_Bool	dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
165 	sal_Bool	dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
166 
167 	void		dumpAttributes(FileStream& o);
168 	void		dumpMethods(FileStream& o);
169 	void		dumpNormalGetCppuType(FileStream& o);
170 	void 		dumpComprehensiveGetCppuType(FileStream& o);
171 	void		dumpCppuAttributeRefs(FileStream& o, sal_uInt32& index);
172 	void		dumpCppuMethodRefs(FileStream& o, sal_uInt32& index);
173 	void		dumpCppuAttributes(FileStream& o, sal_uInt32& index);
174 	void		dumpCppuMethods(FileStream& o, sal_uInt32& index);
175 	void		dumpAttributesCppuDecl(FileStream& o, StringSet* pFinishedTypes, CppuTypeDecl eDeclFlag);
176 	void		dumpMethodsCppuDecl(FileStream& o, StringSet* pFinishedTypes, CppuTypeDecl eDeclFlag );
177 
178 	sal_uInt32	getMemberCount();
179 	sal_uInt32	getInheritedMemberCount();
180 
181 protected:
182     virtual void addSpecialDependencies();
183 
184     virtual void addComprehensiveGetCppuTypeIncludes(
185         codemaker::cppumaker::Includes & includes) const;
186 
187 	sal_uInt32	checkInheritedMemberCount(const typereg::Reader* pReader);
188 
189 protected:
190 	sal_uInt32 	m_inheritedMemberCount;
191 	sal_Bool 	m_hasAttributes;
192 	sal_Bool 	m_hasMethods;
193 
194 private:
195     void dumpExceptionSpecification(
196         FileStream & out, sal_uInt32 methodIndex, bool runtimeException);
197 
198     void dumpAttributeExceptionSpecification(
199         FileStream & out, rtl::OUString const & name, RTMethodMode sort);
200 
201     void dumpExceptionTypeName(
202         FileStream & out, char const * prefix, sal_uInt32 index,
203         rtl::OUString name);
204 
205     sal_Int32 dumpExceptionTypeNames(
206         FileStream & out, char const * prefix, sal_uInt16 methodIndex,
207         bool runtimeException);
208 
209     sal_Int32 dumpAttributeExceptionTypeNames(
210         FileStream & out, char const * prefix, rtl::OUString const & name,
211         RTMethodMode sort);
212 };
213 
214 class ConstantsType : public CppuType
215 {
216 public:
217 	ConstantsType(typereg::Reader& typeReader,
218                   const ::rtl::OString& typeName,
219                   const TypeManager& typeMgr);
220 
221 	virtual ~ConstantsType();
222 
223 	virtual sal_Bool 	dump(CppuOptions* pOptions) throw( CannotDumpException );
224 
225 	sal_Bool			dumpDeclaration(FileStream& o) throw( CannotDumpException );
226 	sal_Bool			dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
227 	sal_Bool			dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
228 	sal_Bool			hasConstants();
229 };
230 
231 class ModuleType : public ConstantsType
232 {
233 public:
234 	ModuleType(typereg::Reader& typeReader,
235 		   	   const ::rtl::OString& typeName,
236 			   const TypeManager& typeMgr);
237 
238 	virtual ~ModuleType();
239 
240 protected:
241     virtual bool dumpFiles(CppuOptions * options, rtl::OString const & outPath);
242 };
243 
244 class StructureType : public CppuType
245 {
246 public:
247 	StructureType(typereg::Reader& typeReader,
248 				  const ::rtl::OString& typeName,
249 				  const TypeManager& typeMgr);
250 
251 	virtual ~StructureType();
252 
253 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
254 	sal_Bool	dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
255 	sal_Bool	dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
256 
257     virtual void dumpLightGetCppuType(FileStream & out);
258 
259     virtual void dumpNormalGetCppuType(FileStream & out);
260 
261     virtual void dumpComprehensiveGetCppuType(FileStream & out);
262 
263 	sal_Bool	dumpSuperMember(FileStream& o, const ::rtl::OString& super, sal_Bool bWithType);
264 
265 protected:
266     virtual void addLightGetCppuTypeIncludes(
267         codemaker::cppumaker::Includes & includes) const;
268 
269     virtual void addNormalGetCppuTypeIncludes(
270         codemaker::cppumaker::Includes & includes) const;
271 
272     virtual void addComprehensiveGetCppuTypeIncludes(
273         codemaker::cppumaker::Includes & includes) const;
274 
275     virtual bool isPolymorphic() const;
276 
277     virtual void dumpTemplateHead(FileStream & out) const;
278 
279     virtual void dumpTemplateParameters(FileStream & out) const;
280 };
281 
282 class ExceptionType : public CppuType
283 {
284 public:
285 	ExceptionType(typereg::Reader& typeReader,
286 				  const ::rtl::OString& typeName,
287 				  const TypeManager& typeMgr);
288 
289 	virtual ~ExceptionType();
290 
291 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
292 	sal_Bool	dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
293 	sal_Bool	dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
294 
295 	sal_Bool	dumpSuperMember(FileStream& o, const ::rtl::OString& super, sal_Bool bWithType);
296 };
297 
298 class EnumType : public CppuType
299 {
300 public:
301 	EnumType(typereg::Reader& typeReader,
302 	 		 const ::rtl::OString& typeName,
303 	 		 const TypeManager& typeMgr);
304 
305 	virtual ~EnumType();
306 
307 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
308 	sal_Bool	dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
309 	sal_Bool	dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
310 
311 	void		dumpNormalGetCppuType(FileStream& o);
312 	void 		dumpComprehensiveGetCppuType(FileStream& o);
313 };
314 
315 class TypeDefType : public CppuType
316 {
317 public:
318 	TypeDefType(typereg::Reader& typeReader,
319 	 		 const ::rtl::OString& typeName,
320 	 		 const TypeManager& typeMgr);
321 
322 	virtual ~TypeDefType();
323 
324 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
325 	sal_Bool	dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
326 	sal_Bool	dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
327 };
328 
329 class ConstructiveType: public CppuType {
330 public:
ConstructiveType(typereg::Reader & reader,rtl::OString const & name,TypeManager const & manager)331     ConstructiveType(
332         typereg::Reader & reader, rtl::OString const & name,
333         TypeManager const & manager):
334         CppuType(reader, name, manager) {}
335 
336     virtual sal_Bool dumpHFile(
337         FileStream & o, codemaker::cppumaker::Includes & includes)
338         throw (CannotDumpException);
339 
340 protected:
341     virtual bool dumpFiles(CppuOptions * options, rtl::OString const & outPath);
342 };
343 
344 class ServiceType: public ConstructiveType {
345 public:
ServiceType(typereg::Reader & reader,rtl::OString const & name,TypeManager const & manager)346     ServiceType(
347         typereg::Reader & reader, rtl::OString const & name,
348         TypeManager const & manager):
349         ConstructiveType(reader, name, manager) {}
350 
351     bool isSingleInterfaceBased();
352 
353     virtual sal_Bool dumpHxxFile(
354         FileStream & o, codemaker::cppumaker::Includes & includes)
355         throw (CannotDumpException);
356 
357 private:
358     virtual void addSpecialDependencies();
359 
360     bool isDefaultConstructor(sal_uInt16 ctorIndex) const;
361 
362     bool hasRestParameter(sal_uInt16 ctorIndex) const;
363 
364     void dumpCatchClauses(
365         FileStream & out, codemaker::ExceptionTreeNode const * node);
366 };
367 
368 class SingletonType: public ConstructiveType {
369 public:
SingletonType(typereg::Reader & reader,rtl::OString const & name,TypeManager const & manager)370     SingletonType(
371         typereg::Reader & reader, rtl::OString const & name,
372         TypeManager const & manager):
373         ConstructiveType(reader, name, manager) {}
374 
375     bool isInterfaceBased();
376 
377     virtual sal_Bool dumpHxxFile(
378         FileStream & o, codemaker::cppumaker::Includes & includes)
379         throw (CannotDumpException);
380 };
381 
382 bool produceType(const ::rtl::OString& typeName,
383 					 TypeManager const & typeMgr,
384                      codemaker::GeneratedTypeSet & generated,
385 					 CppuOptions* pOptions)
386 				 throw( CannotDumpException );
387 
388 bool produceType(RegistryKey& typeName, bool bIsExtraType,
389 					 TypeManager const & typeMgr,
390                      codemaker::GeneratedTypeSet & generated,
391 					 CppuOptions* pOptions)
392 				 throw( CannotDumpException );
393 
394 /**
395  * This function returns a C++ scoped name, represents the namespace
396  * scoping of this type, e.g. com:.sun::star::uno::XInterface.
397  */
398 // ::rtl::OString scopedName(const ::rtl::OString& scope, const ::rtl::OString& type,
399 // 				   sal_Bool bNoNameSpace=sal_False);
400 
401 #endif // INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_CPPUTYPE_HXX
402 
403