1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef INCLUDED_CODEMAKER_SOURCE_CUNOMAKER_CUNOTYPE_HXX_
29 #define INCLUDED_CODEMAKER_SOURCE_CUNOMAKER_CUNOTYPE_HXX
30 
31 #include	<codemaker/typemanager.hxx>
32 #include	<codemaker/dependency.hxx>
33 
34 enum BASETYPE
35 {
36 	BT_INVALID,
37 	BT_VOID,
38 	BT_ANY,
39 	BT_TYPE,
40 	BT_BOOLEAN,
41 	BT_CHAR,
42 	BT_STRING,
43 	BT_FLOAT,
44 	BT_DOUBLE,
45 	BT_OCTET,
46 	BT_BYTE,
47 	BT_SHORT,
48 	BT_LONG,
49 	BT_HYPER,
50 	BT_UNSIGNED_SHORT,
51 	BT_UNSIGNED_LONG,
52 	BT_UNSIGNED_HYPER
53 };
54 
55 
56 enum CunoTypeDecl
57 {
58 	CUNOTYPEDECL_ALLTYPES,
59 	CUNOTYPEDECL_NOINTERFACES,
60 	CUNOTYPEDECL_ONLYINTERFACES
61 };
62 
63 class CunoOptions;
64 class FileStream;
65 
66 class CunoType
67 {
68 public:
69 	CunoType(TypeReader& typeReader,
70 			 const ::rtl::OString& typeName,
71 			 const TypeManager& typeMgr,
72 			 const TypeDependency& typeDependencies);
73 
74 	virtual ~CunoType();
75 
76 	virtual sal_Bool dump(CunoOptions* pOptions) throw( CannotDumpException );
77 	virtual sal_Bool dumpDependedTypes(CunoOptions* pOptions)  throw( CannotDumpException );
78 	virtual sal_Bool dumpHFile(FileStream& o) throw( CannotDumpException ) = 0;
79 	virtual sal_Bool dumpCFile(FileStream& o) throw( CannotDumpException ) = 0;
80 
81 	virtual ::rtl::OString dumpHeaderDefine(FileStream& o, sal_Char* prefix, sal_Bool bExtended=sal_False);
82 	virtual void dumpDefaultHIncludes(FileStream& o);
83 	virtual void dumpDefaultCIncludes(FileStream& o);
84 	virtual void dumpInclude(FileStream& o, const ::rtl::OString& typeName, sal_Char* prefix, sal_Bool bExtended=sal_False, sal_Bool bCaseSensitive=sal_False);
85 	virtual void dumpDepIncludes(FileStream& o, const ::rtl::OString& typeName, sal_Char* prefix);
86 
87 	virtual void dumpOpenExternC(FileStream& o);
88 	virtual void dumpCloseExternC(FileStream& o);
89 
90 	virtual void dumpGetCunoType(FileStream& o);
91 	virtual void dumpCGetCunoType(FileStream& o);
92 	virtual void dumpLGetCunoType(FileStream& o);
93 
94 	virtual void dumpType(FileStream& o, const ::rtl::OString& type, sal_Bool bConst=sal_False,
95 						  sal_Bool bPointer=sal_False, sal_Bool bParam=sal_False)
96 					throw( CannotDumpException );
97 	::rtl::OString	getTypeClass(const ::rtl::OString& type="", sal_Bool bCStyle=sal_False);
98 	::rtl::OString	getBaseType(const ::rtl::OString& type);
99 	void	dumpCppuGetType(FileStream& o, const ::rtl::OString& type, sal_Bool bDecl=sal_False, CunoTypeDecl eDeclFlag=CUNOTYPEDECL_ALLTYPES);
100 	void	dumpTypeInit(FileStream& o, const ::rtl::OString& type);
101 	BASETYPE isBaseType(const ::rtl::OString& type);
102 
103 	::rtl::OString typeToIdentifier(const ::rtl::OString& type);
104 
105 	void 	dumpConstantValue(FileStream& o, sal_uInt16 index);
106 
107 	virtual sal_uInt32  getMemberCount();
108 	virtual sal_uInt32	getInheritedMemberCount();
109 	void 	dumpInheritedMembers(FileStream& o, rtl::OString& superType);
110 
111 	sal_Bool isSeqType(const ::rtl::OString& type, ::rtl::OString& baseType, ::rtl::OString& seqPrefix);
112 	sal_Bool isArrayType(const ::rtl::OString& type, ::rtl::OString& baseType, ::rtl::OString& arrayPrefix);
113 	sal_Bool isVoid(const ::rtl::OString& type)
114 		{ return type.equals("void"); }
115 	void 			inc(sal_uInt32 num=4);
116 	void 			dec(sal_uInt32 num=4);
117 	::rtl::OString 	indent();
118 	::rtl::OString	indent(sal_uInt32 num);
119 protected:
120 	virtual sal_uInt32	checkInheritedMemberCount(const TypeReader* pReader);
121 
122 	::rtl::OString	checkSpecialCunoType(const ::rtl::OString& type);
123 	::rtl::OString	checkRealBaseType(const ::rtl::OString& type, sal_Bool bResolveTypeOnly = sal_False);
124 	void	dumpCppuGetTypeMemberDecl(FileStream& o, CunoTypeDecl eDeclFlag);
125 
126  	sal_Bool isNestedType()
127 		{ return m_bIsNestedType; };
128 
129  	RegistryKeyNames& getNestedTypeNames()
130 		{ return  m_nestedTypeNames; };
131 
132  	sal_Bool isNestedTypeByName(const ::rtl::OString& type);
133  	sal_Bool hasNestedType(const ::rtl::OString& type);
134 
135 protected:
136 	sal_uInt32 			m_inheritedMemberCount;
137 
138 	sal_Bool			m_cunoTypeLib;
139 	sal_Bool			m_cunoTypeLeak;
140 	sal_Bool			m_cunoTypeDynamic;
141 	sal_uInt32			m_indentLength;
142 	::rtl::OString		m_typeName;
143 	::rtl::OString		m_name;
144 	TypeReader			m_reader;
145 	TypeManager&		m_typeMgr;
146 	TypeDependency  	m_dependencies;
147 	sal_Bool 			m_bIsNestedType;
148 	RegistryKeyNames 	m_nestedTypeNames;
149 };
150 
151 class InterfaceType : public CunoType
152 {
153 public:
154 	InterfaceType(TypeReader& typeReader,
155 				 const ::rtl::OString& typeName,
156 				 const TypeManager& typeMgr,
157 				 const TypeDependency& typeDependencies);
158 
159 	virtual ~InterfaceType();
160 
161 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
162 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
163 	sal_Bool	dumpCFile(FileStream& o) throw( CannotDumpException );
164 
165 	void 		dumpInheritedFunctions(FileStream& o, rtl::OString& superType);
166 	void		dumpAttributes(FileStream& o, const ::rtl::OString& interfaceType, TypeReader& reader );
167 	void		dumpMethods(FileStream& o, const ::rtl::OString& interfaceType, TypeReader& reader );
168 	void		dumpGetCunoType(FileStream& o);
169 	void 		dumpCGetCunoType(FileStream& o);
170 	void 		dumpCUnoAttributeTypeNames(FileStream& o, sal_Bool bRelease=sal_False);
171 	void 		dumpCUnoMethodTypeNames(FileStream& o, sal_Bool bRelease=sal_False);
172 	void		dumpCUnoAttributeRefs(FileStream& o, sal_uInt32& index);
173 	void		dumpCUnoMethodRefs(FileStream& o, sal_uInt32& index);
174 	void		dumpCUnoAttributes(FileStream& o, sal_uInt32& index);
175 	void		dumpCUnoMethods(FileStream& o, sal_uInt32& index);
176 	void		dumpAttributesCppuDecl(FileStream& o, StringSet* pFinishedTypes, CunoTypeDecl eDeclFlag);
177 	void		dumpMethodsCppuDecl(FileStream& o, StringSet* pFinishedTypes, CunoTypeDecl eDeclFlag );
178 
179 	sal_uInt32	getMemberCount();
180 	sal_uInt32	getInheritedMemberCount();
181 
182 protected:
183 	sal_uInt32	checkInheritedMemberCount(const TypeReader* pReader);
184 
185 protected:
186 	sal_uInt32 	m_inheritedMemberCount;
187 	sal_Bool 	m_hasAttributes;
188 	sal_Bool 	m_hasMethods;
189 };
190 
191 class ModuleType : public CunoType
192 {
193 public:
194 	ModuleType(TypeReader& typeReader,
195 		   	   const ::rtl::OString& typeName,
196 			   const TypeManager& typeMgr,
197 			   const TypeDependency& typeDependencies);
198 
199 	virtual ~ModuleType();
200 
201 	virtual sal_Bool 	dump(CunoOptions* pOptions) throw( CannotDumpException );
202 
203 	sal_Bool			dumpDeclaration(FileStream& o) throw( CannotDumpException );
204 	sal_Bool			dumpHFile(FileStream& o) throw( CannotDumpException );
205 	sal_Bool			dumpCFile(FileStream& o) throw( CannotDumpException );
206 	sal_Bool			hasConstants();
207 };
208 
209 class ConstantsType : public ModuleType
210 {
211 public:
212 	ConstantsType(TypeReader& typeReader,
213 		   	   const ::rtl::OString& typeName,
214 			   const TypeManager& typeMgr,
215 			   const TypeDependency& typeDependencies);
216 
217 	virtual ~ConstantsType();
218 
219 	virtual sal_Bool 	dump(CunoOptions* pOptions) throw( CannotDumpException );
220 };
221 
222 class StructureType : public CunoType
223 {
224 public:
225 	StructureType(TypeReader& typeReader,
226 				  const ::rtl::OString& typeName,
227 				  const TypeManager& typeMgr,
228 				  const TypeDependency& typeDependencies);
229 
230 	virtual ~StructureType();
231 
232 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
233 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
234 	sal_Bool	dumpCFile(FileStream& o) throw( CannotDumpException );
235 };
236 
237 class ExceptionType : public CunoType
238 {
239 public:
240 	ExceptionType(TypeReader& typeReader,
241 				  const ::rtl::OString& typeName,
242 				  const TypeManager& typeMgr,
243 				  const TypeDependency& typeDependencies);
244 
245 	virtual ~ExceptionType();
246 
247 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
248 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
249 	sal_Bool	dumpCFile(FileStream& o) throw( CannotDumpException );
250 };
251 
252 class EnumType : public CunoType
253 {
254 public:
255 	EnumType(TypeReader& typeReader,
256 	 		 const ::rtl::OString& typeName,
257 	 		 const TypeManager& typeMgr,
258 	 		 const TypeDependency& typeDependencies);
259 
260 	virtual ~EnumType();
261 
262 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
263 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
264 	sal_Bool	dumpCFile(FileStream& o) throw( CannotDumpException );
265 
266 	void		dumpGetCunoType(FileStream& o);
267 	void 		dumpCGetCunoType(FileStream& o);
268 };
269 
270 class TypeDefType : public CunoType
271 {
272 public:
273 	TypeDefType(TypeReader& typeReader,
274 	 		 const ::rtl::OString& typeName,
275 	 		 const TypeManager& typeMgr,
276 	 		 const TypeDependency& typeDependencies);
277 
278 	virtual ~TypeDefType();
279 
280 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
281 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
282 	sal_Bool	dumpCFile(FileStream& o) throw( CannotDumpException );
283 
284 	void		dumpGetCunoType(FileStream& o);
285 	void		dumpLGetCunoType(FileStream& o);
286 	void 		dumpCGetCunoType(FileStream& o);
287 };
288 
289 
290 sal_Bool produceType(const ::rtl::OString& typeName,
291 					 TypeManager& typeMgr,
292 					 TypeDependency& typeDependencies,
293 					 CunoOptions* pOptions)
294 				 throw( CannotDumpException );
295 
296 /**
297  * This function returns a C++ scoped name, represents the namespace
298  * scoping of this type, e.g. com:.sun::star::uno::XInterface. If the scope of
299  * the type is equal scope, the relativ name will be used.
300  */
301 ::rtl::OString scopedName(const ::rtl::OString& scope, const ::rtl::OString& type,
302 				   sal_Bool bNoNameSpace=sal_False);
303 
304 ::rtl::OString shortScopedName(const ::rtl::OString& scope, const ::rtl::OString& type,
305 				   		sal_Bool bNoNameSpace=sal_False);
306 
307 
308 #endif // INCLUDED_CODEMAKER_SOURCE_CUNOMAKER_CUNOTYPE_HXX
309 
310