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_CUNOMAKER_CUNOTYPE_HXX_
25 #define INCLUDED_CODEMAKER_SOURCE_CUNOMAKER_CUNOTYPE_HXX
26 
27 #include	<codemaker/typemanager.hxx>
28 #include	<codemaker/dependency.hxx>
29 
30 enum BASETYPE
31 {
32 	BT_INVALID,
33 	BT_VOID,
34 	BT_ANY,
35 	BT_TYPE,
36 	BT_BOOLEAN,
37 	BT_CHAR,
38 	BT_STRING,
39 	BT_FLOAT,
40 	BT_DOUBLE,
41 	BT_OCTET,
42 	BT_BYTE,
43 	BT_SHORT,
44 	BT_LONG,
45 	BT_HYPER,
46 	BT_UNSIGNED_SHORT,
47 	BT_UNSIGNED_LONG,
48 	BT_UNSIGNED_HYPER
49 };
50 
51 
52 enum CunoTypeDecl
53 {
54 	CUNOTYPEDECL_ALLTYPES,
55 	CUNOTYPEDECL_NOINTERFACES,
56 	CUNOTYPEDECL_ONLYINTERFACES
57 };
58 
59 class CunoOptions;
60 class FileStream;
61 
62 class CunoType
63 {
64 public:
65 	CunoType(TypeReader& typeReader,
66 			 const ::rtl::OString& typeName,
67 			 const TypeManager& typeMgr,
68 			 const TypeDependency& typeDependencies);
69 
70 	virtual ~CunoType();
71 
72 	virtual sal_Bool dump(CunoOptions* pOptions) throw( CannotDumpException );
73 	virtual sal_Bool dumpDependedTypes(CunoOptions* pOptions)  throw( CannotDumpException );
74 	virtual sal_Bool dumpHFile(FileStream& o) throw( CannotDumpException ) = 0;
75 	virtual sal_Bool dumpCFile(FileStream& o) throw( CannotDumpException ) = 0;
76 
77 	virtual ::rtl::OString dumpHeaderDefine(FileStream& o, sal_Char* prefix, sal_Bool bExtended=sal_False);
78 	virtual void dumpDefaultHIncludes(FileStream& o);
79 	virtual void dumpDefaultCIncludes(FileStream& o);
80 	virtual void dumpInclude(FileStream& o, const ::rtl::OString& typeName, sal_Char* prefix, sal_Bool bExtended=sal_False, sal_Bool bCaseSensitive=sal_False);
81 	virtual void dumpDepIncludes(FileStream& o, const ::rtl::OString& typeName, sal_Char* prefix);
82 
83 	virtual void dumpOpenExternC(FileStream& o);
84 	virtual void dumpCloseExternC(FileStream& o);
85 
86 	virtual void dumpGetCunoType(FileStream& o);
87 	virtual void dumpCGetCunoType(FileStream& o);
88 	virtual void dumpLGetCunoType(FileStream& o);
89 
90 	virtual void dumpType(FileStream& o, const ::rtl::OString& type, sal_Bool bConst=sal_False,
91 						  sal_Bool bPointer=sal_False, sal_Bool bParam=sal_False)
92 					throw( CannotDumpException );
93 	::rtl::OString	getTypeClass(const ::rtl::OString& type="", sal_Bool bCStyle=sal_False);
94 	::rtl::OString	getBaseType(const ::rtl::OString& type);
95 	void	dumpCppuGetType(FileStream& o, const ::rtl::OString& type, sal_Bool bDecl=sal_False, CunoTypeDecl eDeclFlag=CUNOTYPEDECL_ALLTYPES);
96 	void	dumpTypeInit(FileStream& o, const ::rtl::OString& type);
97 	BASETYPE isBaseType(const ::rtl::OString& type);
98 
99 	::rtl::OString typeToIdentifier(const ::rtl::OString& type);
100 
101 	void 	dumpConstantValue(FileStream& o, sal_uInt16 index);
102 
103 	virtual sal_uInt32  getMemberCount();
104 	virtual sal_uInt32	getInheritedMemberCount();
105 	void 	dumpInheritedMembers(FileStream& o, rtl::OString& superType);
106 
107 	sal_Bool isSeqType(const ::rtl::OString& type, ::rtl::OString& baseType, ::rtl::OString& seqPrefix);
108 	sal_Bool isArrayType(const ::rtl::OString& type, ::rtl::OString& baseType, ::rtl::OString& arrayPrefix);
isVoid(const::rtl::OString & type)109 	sal_Bool isVoid(const ::rtl::OString& type)
110 		{ return type.equals("void"); }
111 	void 			inc(sal_uInt32 num=4);
112 	void 			dec(sal_uInt32 num=4);
113 	::rtl::OString 	indent();
114 	::rtl::OString	indent(sal_uInt32 num);
115 protected:
116 	virtual sal_uInt32	checkInheritedMemberCount(const TypeReader* pReader);
117 
118 	::rtl::OString	checkSpecialCunoType(const ::rtl::OString& type);
119 	::rtl::OString	checkRealBaseType(const ::rtl::OString& type, sal_Bool bResolveTypeOnly = sal_False);
120 	void	dumpCppuGetTypeMemberDecl(FileStream& o, CunoTypeDecl eDeclFlag);
121 
isNestedType()122  	sal_Bool isNestedType()
123 		{ return m_bIsNestedType; };
124 
getNestedTypeNames()125  	RegistryKeyNames& getNestedTypeNames()
126 		{ return  m_nestedTypeNames; };
127 
128  	sal_Bool isNestedTypeByName(const ::rtl::OString& type);
129  	sal_Bool hasNestedType(const ::rtl::OString& type);
130 
131 protected:
132 	sal_uInt32 			m_inheritedMemberCount;
133 
134 	sal_Bool			m_cunoTypeLib;
135 	sal_Bool			m_cunoTypeLeak;
136 	sal_Bool			m_cunoTypeDynamic;
137 	sal_uInt32			m_indentLength;
138 	::rtl::OString		m_typeName;
139 	::rtl::OString		m_name;
140 	TypeReader			m_reader;
141 	TypeManager&		m_typeMgr;
142 	TypeDependency  	m_dependencies;
143 	sal_Bool 			m_bIsNestedType;
144 	RegistryKeyNames 	m_nestedTypeNames;
145 };
146 
147 class InterfaceType : public CunoType
148 {
149 public:
150 	InterfaceType(TypeReader& typeReader,
151 				 const ::rtl::OString& typeName,
152 				 const TypeManager& typeMgr,
153 				 const TypeDependency& typeDependencies);
154 
155 	virtual ~InterfaceType();
156 
157 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
158 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
159 	sal_Bool	dumpCFile(FileStream& o) throw( CannotDumpException );
160 
161 	void 		dumpInheritedFunctions(FileStream& o, rtl::OString& superType);
162 	void		dumpAttributes(FileStream& o, const ::rtl::OString& interfaceType, TypeReader& reader );
163 	void		dumpMethods(FileStream& o, const ::rtl::OString& interfaceType, TypeReader& reader );
164 	void		dumpGetCunoType(FileStream& o);
165 	void 		dumpCGetCunoType(FileStream& o);
166 	void 		dumpCUnoAttributeTypeNames(FileStream& o, sal_Bool bRelease=sal_False);
167 	void 		dumpCUnoMethodTypeNames(FileStream& o, sal_Bool bRelease=sal_False);
168 	void		dumpCUnoAttributeRefs(FileStream& o, sal_uInt32& index);
169 	void		dumpCUnoMethodRefs(FileStream& o, sal_uInt32& index);
170 	void		dumpCUnoAttributes(FileStream& o, sal_uInt32& index);
171 	void		dumpCUnoMethods(FileStream& o, sal_uInt32& index);
172 	void		dumpAttributesCppuDecl(FileStream& o, StringSet* pFinishedTypes, CunoTypeDecl eDeclFlag);
173 	void		dumpMethodsCppuDecl(FileStream& o, StringSet* pFinishedTypes, CunoTypeDecl eDeclFlag );
174 
175 	sal_uInt32	getMemberCount();
176 	sal_uInt32	getInheritedMemberCount();
177 
178 protected:
179 	sal_uInt32	checkInheritedMemberCount(const TypeReader* pReader);
180 
181 protected:
182 	sal_uInt32 	m_inheritedMemberCount;
183 	sal_Bool 	m_hasAttributes;
184 	sal_Bool 	m_hasMethods;
185 };
186 
187 class ModuleType : public CunoType
188 {
189 public:
190 	ModuleType(TypeReader& typeReader,
191 		   	   const ::rtl::OString& typeName,
192 			   const TypeManager& typeMgr,
193 			   const TypeDependency& typeDependencies);
194 
195 	virtual ~ModuleType();
196 
197 	virtual sal_Bool 	dump(CunoOptions* pOptions) throw( CannotDumpException );
198 
199 	sal_Bool			dumpDeclaration(FileStream& o) throw( CannotDumpException );
200 	sal_Bool			dumpHFile(FileStream& o) throw( CannotDumpException );
201 	sal_Bool			dumpCFile(FileStream& o) throw( CannotDumpException );
202 	sal_Bool			hasConstants();
203 };
204 
205 class ConstantsType : public ModuleType
206 {
207 public:
208 	ConstantsType(TypeReader& typeReader,
209 		   	   const ::rtl::OString& typeName,
210 			   const TypeManager& typeMgr,
211 			   const TypeDependency& typeDependencies);
212 
213 	virtual ~ConstantsType();
214 
215 	virtual sal_Bool 	dump(CunoOptions* pOptions) throw( CannotDumpException );
216 };
217 
218 class StructureType : public CunoType
219 {
220 public:
221 	StructureType(TypeReader& typeReader,
222 				  const ::rtl::OString& typeName,
223 				  const TypeManager& typeMgr,
224 				  const TypeDependency& typeDependencies);
225 
226 	virtual ~StructureType();
227 
228 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
229 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
230 	sal_Bool	dumpCFile(FileStream& o) throw( CannotDumpException );
231 };
232 
233 class ExceptionType : public CunoType
234 {
235 public:
236 	ExceptionType(TypeReader& typeReader,
237 				  const ::rtl::OString& typeName,
238 				  const TypeManager& typeMgr,
239 				  const TypeDependency& typeDependencies);
240 
241 	virtual ~ExceptionType();
242 
243 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
244 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
245 	sal_Bool	dumpCFile(FileStream& o) throw( CannotDumpException );
246 };
247 
248 class EnumType : public CunoType
249 {
250 public:
251 	EnumType(TypeReader& typeReader,
252 	 		 const ::rtl::OString& typeName,
253 	 		 const TypeManager& typeMgr,
254 	 		 const TypeDependency& typeDependencies);
255 
256 	virtual ~EnumType();
257 
258 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
259 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
260 	sal_Bool	dumpCFile(FileStream& o) throw( CannotDumpException );
261 
262 	void		dumpGetCunoType(FileStream& o);
263 	void 		dumpCGetCunoType(FileStream& o);
264 };
265 
266 class TypeDefType : public CunoType
267 {
268 public:
269 	TypeDefType(TypeReader& typeReader,
270 	 		 const ::rtl::OString& typeName,
271 	 		 const TypeManager& typeMgr,
272 	 		 const TypeDependency& typeDependencies);
273 
274 	virtual ~TypeDefType();
275 
276 	sal_Bool	dumpDeclaration(FileStream& o) throw( CannotDumpException );
277 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
278 	sal_Bool	dumpCFile(FileStream& o) throw( CannotDumpException );
279 
280 	void		dumpGetCunoType(FileStream& o);
281 	void		dumpLGetCunoType(FileStream& o);
282 	void 		dumpCGetCunoType(FileStream& o);
283 };
284 
285 
286 sal_Bool produceType(const ::rtl::OString& typeName,
287 					 TypeManager& typeMgr,
288 					 TypeDependency& typeDependencies,
289 					 CunoOptions* pOptions)
290 				 throw( CannotDumpException );
291 
292 /**
293  * This function returns a C++ scoped name, represents the namespace
294  * scoping of this type, e.g. com:.sun::star::uno::XInterface. If the scope of
295  * the type is equal scope, the relativ name will be used.
296  */
297 ::rtl::OString scopedName(const ::rtl::OString& scope, const ::rtl::OString& type,
298 				   sal_Bool bNoNameSpace=sal_False);
299 
300 ::rtl::OString shortScopedName(const ::rtl::OString& scope, const ::rtl::OString& type,
301 				   		sal_Bool bNoNameSpace=sal_False);
302 
303 
304 #endif // INCLUDED_CODEMAKER_SOURCE_CUNOMAKER_CUNOTYPE_HXX
305 
306