xref: /AOO41X/main/codemaker/source/cppumaker/cppumaker.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_codemaker.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <stdio.h>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "sal/main.h"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "codemaker/typemanager.hxx"
36*cdf0e10cSrcweir #include "codemaker/generatedtypeset.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include "cppuoptions.hxx"
39*cdf0e10cSrcweir #include "cpputype.hxx"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir using namespace rtl;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir namespace {
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir void failed(rtl::OString const & typeName, CppuOptions * options) {
46*cdf0e10cSrcweir     fprintf(stderr, "%s ERROR: %s\n", options->getProgramName().getStr(),
47*cdf0e10cSrcweir             rtl::OString("cannot dump Type '" + typeName + "'").getStr());
48*cdf0e10cSrcweir     exit(99);
49*cdf0e10cSrcweir }
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir void produce(
52*cdf0e10cSrcweir     RegistryKey& rTypeKey, bool bIsExtraType, TypeManager const & typeMgr,
53*cdf0e10cSrcweir     codemaker::GeneratedTypeSet & generated, CppuOptions * options)
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir     if (!produceType(rTypeKey, bIsExtraType, typeMgr, generated, options)) {
56*cdf0e10cSrcweir         OString typeName = typeMgr.getTypeName(rTypeKey);
57*cdf0e10cSrcweir         failed(typeName, options);
58*cdf0e10cSrcweir     }
59*cdf0e10cSrcweir }
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir void produce(
62*cdf0e10cSrcweir     rtl::OString const & typeName, TypeManager const & typeMgr,
63*cdf0e10cSrcweir     codemaker::GeneratedTypeSet & generated, CppuOptions * options)
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir     if (!produceType(typeName, typeMgr, generated, options)) {
66*cdf0e10cSrcweir         failed(typeName, options);
67*cdf0e10cSrcweir     }
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir void produceAllTypes(RegistryKey& rTypeKey, bool bIsExtraType,
71*cdf0e10cSrcweir 						 TypeManager const & typeMgr,
72*cdf0e10cSrcweir                          codemaker::GeneratedTypeSet & generated,
73*cdf0e10cSrcweir 						 CppuOptions* pOptions,
74*cdf0e10cSrcweir 						 sal_Bool bFullScope)
75*cdf0e10cSrcweir 	throw( CannotDumpException )
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     OString typeName = typeMgr.getTypeName(rTypeKey);
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     produce(rTypeKey, bIsExtraType, typeMgr, generated, pOptions);
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     RegistryKeyList typeKeys = typeMgr.getTypeKeys(typeName);
82*cdf0e10cSrcweir 	RegistryKeyList::const_iterator iter = typeKeys.begin();
83*cdf0e10cSrcweir     RegistryKey key, subKey;
84*cdf0e10cSrcweir     RegistryKeyArray subKeys;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 	while (iter != typeKeys.end())
87*cdf0e10cSrcweir 	{
88*cdf0e10cSrcweir         key = (*iter).first;
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir         if (!(*iter).second  && !key.openSubKeys(OUString(), subKeys))
91*cdf0e10cSrcweir         {
92*cdf0e10cSrcweir             for (sal_uInt32 i = 0; i < subKeys.getLength(); i++)
93*cdf0e10cSrcweir             {
94*cdf0e10cSrcweir                 subKey = subKeys.getElement(i);
95*cdf0e10cSrcweir                 if (bFullScope)
96*cdf0e10cSrcweir                 {
97*cdf0e10cSrcweir                     produceAllTypes(subKey, (*iter).second, typeMgr,
98*cdf0e10cSrcweir                                     generated, pOptions, true);
99*cdf0e10cSrcweir                 } else
100*cdf0e10cSrcweir                 {
101*cdf0e10cSrcweir                     produce(subKey, (*iter).second,
102*cdf0e10cSrcweir                             typeMgr, generated, pOptions);
103*cdf0e10cSrcweir                 }
104*cdf0e10cSrcweir             }
105*cdf0e10cSrcweir         }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir         ++iter;
108*cdf0e10cSrcweir 	}
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir void produceAllTypes(const OString& typeName,
112*cdf0e10cSrcweir                      TypeManager const & typeMgr,
113*cdf0e10cSrcweir                      codemaker::GeneratedTypeSet & generated,
114*cdf0e10cSrcweir                      CppuOptions* pOptions,
115*cdf0e10cSrcweir                      sal_Bool bFullScope)
116*cdf0e10cSrcweir 	throw( CannotDumpException )
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir     produce(typeName, typeMgr, generated, pOptions);
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     RegistryKeyList typeKeys = typeMgr.getTypeKeys(typeName);
121*cdf0e10cSrcweir 	RegistryKeyList::const_iterator iter = typeKeys.begin();
122*cdf0e10cSrcweir     RegistryKey key, subKey;
123*cdf0e10cSrcweir     RegistryKeyArray subKeys;
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 	while (iter != typeKeys.end())
126*cdf0e10cSrcweir 	{
127*cdf0e10cSrcweir         key = (*iter).first;
128*cdf0e10cSrcweir         if (!(*iter).second  && !key.openSubKeys(OUString(), subKeys))
129*cdf0e10cSrcweir         {
130*cdf0e10cSrcweir             for (sal_uInt32 i = 0; i < subKeys.getLength(); i++)
131*cdf0e10cSrcweir             {
132*cdf0e10cSrcweir                 subKey = subKeys.getElement(i);
133*cdf0e10cSrcweir                 if (bFullScope)
134*cdf0e10cSrcweir                 {
135*cdf0e10cSrcweir                     produceAllTypes(subKey, (*iter).second, typeMgr,
136*cdf0e10cSrcweir                                     generated, pOptions, true);
137*cdf0e10cSrcweir                 } else
138*cdf0e10cSrcweir                 {
139*cdf0e10cSrcweir                     produce(subKey, (*iter).second,
140*cdf0e10cSrcweir                             typeMgr, generated, pOptions);
141*cdf0e10cSrcweir                 }
142*cdf0e10cSrcweir             }
143*cdf0e10cSrcweir         }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir         ++iter;
146*cdf0e10cSrcweir 	}
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
152*cdf0e10cSrcweir {
153*cdf0e10cSrcweir 	CppuOptions options;
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	try
156*cdf0e10cSrcweir 	{
157*cdf0e10cSrcweir 		if (!options.initOptions(argc, argv))
158*cdf0e10cSrcweir 		{
159*cdf0e10cSrcweir 			exit(1);
160*cdf0e10cSrcweir 		}
161*cdf0e10cSrcweir 	}
162*cdf0e10cSrcweir 	catch( IllegalArgument& e)
163*cdf0e10cSrcweir 	{
164*cdf0e10cSrcweir 		fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr());
165*cdf0e10cSrcweir 		exit(99);
166*cdf0e10cSrcweir 	}
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	RegistryTypeManager typeMgr;
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	if (!typeMgr.init(options.getInputFiles(), options.getExtraInputFiles()))
171*cdf0e10cSrcweir 	{
172*cdf0e10cSrcweir 		fprintf(stderr, "%s : init registries failed, check your registry files.\n", options.getProgramName().getStr());
173*cdf0e10cSrcweir 		exit(99);
174*cdf0e10cSrcweir 	}
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	if (options.isValid("-B"))
177*cdf0e10cSrcweir 	{
178*cdf0e10cSrcweir 		typeMgr.setBase(options.getOption("-B"));
179*cdf0e10cSrcweir 	}
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir     codemaker::GeneratedTypeSet generated;
182*cdf0e10cSrcweir 	try
183*cdf0e10cSrcweir 	{
184*cdf0e10cSrcweir 		if (options.isValid("-T"))
185*cdf0e10cSrcweir 		{
186*cdf0e10cSrcweir 			OString tOption(options.getOption("-T"));
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 			OString typeName, tmpName;
189*cdf0e10cSrcweir             sal_Int32 nIndex = 0;
190*cdf0e10cSrcweir             do
191*cdf0e10cSrcweir 			{
192*cdf0e10cSrcweir 				typeName = tOption.getToken(0, ';', nIndex);
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir                 sal_Int32 nPos = typeName.lastIndexOf( '.' );
195*cdf0e10cSrcweir                 tmpName = typeName.copy( nPos != -1 ? nPos+1 : 0 );
196*cdf0e10cSrcweir 				if (tmpName == "*")
197*cdf0e10cSrcweir 				{
198*cdf0e10cSrcweir 					// produce this type and his scope
199*cdf0e10cSrcweir 					if (typeName.equals("*"))
200*cdf0e10cSrcweir 					{
201*cdf0e10cSrcweir 						tmpName = "/";
202*cdf0e10cSrcweir 					} else
203*cdf0e10cSrcweir 					{
204*cdf0e10cSrcweir 						tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/');
205*cdf0e10cSrcweir 						if (tmpName.getLength() == 0)
206*cdf0e10cSrcweir 							tmpName = "/";
207*cdf0e10cSrcweir 						else
208*cdf0e10cSrcweir 							tmpName.replace('.', '/');
209*cdf0e10cSrcweir 					}
210*cdf0e10cSrcweir                     // related to task #116780# the scope is recursively
211*cdf0e10cSrcweir                     // generated.  bFullScope = true
212*cdf0e10cSrcweir 					produceAllTypes(
213*cdf0e10cSrcweir                         tmpName, typeMgr, generated, &options, true);
214*cdf0e10cSrcweir 				} else
215*cdf0e10cSrcweir 				{
216*cdf0e10cSrcweir 					// produce only this type
217*cdf0e10cSrcweir                     produce(
218*cdf0e10cSrcweir                         typeName.replace('.', '/'), typeMgr, generated, &options);
219*cdf0e10cSrcweir 				}
220*cdf0e10cSrcweir 			} while( nIndex != -1 );
221*cdf0e10cSrcweir 		} else
222*cdf0e10cSrcweir 		{
223*cdf0e10cSrcweir 			// produce all types
224*cdf0e10cSrcweir 			produceAllTypes("/", typeMgr, generated, &options, true);
225*cdf0e10cSrcweir 		}
226*cdf0e10cSrcweir         // C++ header files generated for the following UNO types are included
227*cdf0e10cSrcweir         // in header files in cppu/inc/com/sun/star/uno (Any.hxx, Reference.hxx,
228*cdf0e10cSrcweir         // Type.h), so it seems best to always generate those C++ header files:
229*cdf0e10cSrcweir         produce("com/sun/star/uno/RuntimeException", typeMgr, generated, &options);
230*cdf0e10cSrcweir         produce("com/sun/star/uno/TypeClass", typeMgr, generated, &options);
231*cdf0e10cSrcweir         produce("com/sun/star/uno/XInterface", typeMgr, generated, &options);
232*cdf0e10cSrcweir 	}
233*cdf0e10cSrcweir 	catch( CannotDumpException& e)
234*cdf0e10cSrcweir 	{
235*cdf0e10cSrcweir 		fprintf(stderr, "%s ERROR: %s\n",
236*cdf0e10cSrcweir 				options.getProgramName().getStr(),
237*cdf0e10cSrcweir 				e.m_message.getStr());
238*cdf0e10cSrcweir 		exit(99);
239*cdf0e10cSrcweir 	}
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 	return 0;
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 
245