Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <stdio.h>
22 :
23 : #include "sal/main.h"
24 :
25 : #include "codemaker/typemanager.hxx"
26 : #include "codemaker/generatedtypeset.hxx"
27 :
28 : #include "cppuoptions.hxx"
29 : #include "cpputype.hxx"
30 :
31 : using ::rtl::OString;
32 : using ::rtl::OUString;
33 :
34 : namespace {
35 :
36 0 : void failed(rtl::OString const & typeName, CppuOptions * options) {
37 0 : fprintf(stderr, "%s ERROR: %s\n", options->getProgramName().getStr(),
38 0 : rtl::OString("cannot dump Type '" + typeName + "'").getStr());
39 0 : exit(99);
40 : }
41 :
42 10444 : void produce(
43 : RegistryKey& rTypeKey, bool bIsExtraType, TypeManager const & typeMgr,
44 : codemaker::GeneratedTypeSet & generated, CppuOptions * options)
45 : {
46 10444 : if (!produceType(rTypeKey, bIsExtraType, typeMgr, generated, options)) {
47 0 : OString typeName = typeMgr.getTypeName(rTypeKey);
48 0 : failed(typeName, options);
49 : }
50 10444 : }
51 :
52 40 : void produce(
53 : rtl::OString const & typeName, TypeManager const & typeMgr,
54 : codemaker::GeneratedTypeSet & generated, CppuOptions * options)
55 : {
56 40 : if (!produceType(typeName, typeMgr, generated, options)) {
57 0 : failed(typeName, options);
58 : }
59 40 : }
60 :
61 10444 : void produceAllTypes(RegistryKey& rTypeKey, bool bIsExtraType,
62 : TypeManager const & typeMgr,
63 : codemaker::GeneratedTypeSet & generated,
64 : CppuOptions* pOptions,
65 : sal_Bool bFullScope)
66 : throw( CannotDumpException )
67 : {
68 10444 : OString typeName = typeMgr.getTypeName(rTypeKey);
69 :
70 10444 : produce(rTypeKey, bIsExtraType, typeMgr, generated, pOptions);
71 :
72 10444 : RegistryKeyList typeKeys = typeMgr.getTypeKeys(typeName);
73 10444 : RegistryKeyList::const_iterator iter = typeKeys.begin();
74 10444 : RegistryKey key, subKey;
75 10444 : RegistryKeyArray subKeys;
76 :
77 31390 : while (iter != typeKeys.end())
78 : {
79 10502 : key = (*iter).first;
80 :
81 10502 : if (!(*iter).second && !key.openSubKeys(OUString(), subKeys))
82 : {
83 20854 : for (sal_uInt32 i = 0; i < subKeys.getLength(); i++)
84 : {
85 10410 : subKey = subKeys.getElement(i);
86 10410 : if (bFullScope)
87 : {
88 10410 : produceAllTypes(subKey, (*iter).second, typeMgr,
89 10410 : generated, pOptions, true);
90 : } else
91 : {
92 0 : produce(subKey, (*iter).second,
93 0 : typeMgr, generated, pOptions);
94 : }
95 : }
96 : }
97 :
98 10502 : ++iter;
99 10444 : }
100 10444 : }
101 :
102 10 : void produceAllTypes(const OString& typeName,
103 : TypeManager const & typeMgr,
104 : codemaker::GeneratedTypeSet & generated,
105 : CppuOptions* pOptions,
106 : sal_Bool bFullScope)
107 : throw( CannotDumpException )
108 : {
109 10 : produce(typeName, typeMgr, generated, pOptions);
110 :
111 10 : RegistryKeyList typeKeys = typeMgr.getTypeKeys(typeName);
112 10 : RegistryKeyList::const_iterator iter = typeKeys.begin();
113 10 : RegistryKey key, subKey;
114 10 : RegistryKeyArray subKeys;
115 :
116 41 : while (iter != typeKeys.end())
117 : {
118 21 : key = (*iter).first;
119 21 : if (!(*iter).second && !key.openSubKeys(OUString(), subKeys))
120 : {
121 44 : for (sal_uInt32 i = 0; i < subKeys.getLength(); i++)
122 : {
123 34 : subKey = subKeys.getElement(i);
124 34 : if (bFullScope)
125 : {
126 34 : produceAllTypes(subKey, (*iter).second, typeMgr,
127 34 : generated, pOptions, true);
128 : } else
129 : {
130 0 : produce(subKey, (*iter).second,
131 0 : typeMgr, generated, pOptions);
132 : }
133 : }
134 : }
135 :
136 21 : ++iter;
137 10 : }
138 10 : }
139 :
140 : }
141 :
142 20 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
143 : {
144 10 : CppuOptions options;
145 :
146 : try
147 : {
148 10 : if (!options.initOptions(argc, argv))
149 : {
150 0 : exit(1);
151 : }
152 : }
153 0 : catch( IllegalArgument& e)
154 : {
155 0 : fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr());
156 0 : exit(99);
157 : }
158 :
159 10 : RegistryTypeManager typeMgr;
160 :
161 10 : if (!typeMgr.init(options.getInputFiles(), options.getExtraInputFiles()))
162 : {
163 0 : fprintf(stderr, "%s : init registries failed, check your registry files.\n", options.getProgramName().getStr());
164 0 : exit(99);
165 : }
166 :
167 10 : if (options.isValid("-B"))
168 : {
169 10 : typeMgr.setBase(options.getOption("-B"));
170 : }
171 :
172 10 : codemaker::GeneratedTypeSet generated;
173 : try
174 : {
175 10 : if (options.isValid("-T"))
176 : {
177 0 : OString tOption(options.getOption("-T"));
178 :
179 0 : OString typeName, tmpName;
180 0 : sal_Int32 nIndex = 0;
181 0 : do
182 : {
183 0 : typeName = tOption.getToken(0, ';', nIndex);
184 :
185 0 : sal_Int32 nPos = typeName.lastIndexOf( '.' );
186 0 : tmpName = typeName.copy( nPos != -1 ? nPos+1 : 0 );
187 0 : if (tmpName == "*")
188 : {
189 : // produce this type and his scope
190 0 : if (typeName.equals("*"))
191 : {
192 0 : tmpName = "/";
193 : } else
194 : {
195 0 : tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/');
196 0 : if (tmpName.isEmpty())
197 0 : tmpName = "/";
198 : else
199 0 : tmpName = tmpName.replace('.', '/');
200 : }
201 : // related to task #116780# the scope is recursively
202 : // generated. bFullScope = true
203 : produceAllTypes(
204 0 : tmpName, typeMgr, generated, &options, true);
205 : } else
206 : {
207 : // produce only this type
208 : produce(
209 0 : typeName.replace('.', '/'), typeMgr, generated, &options);
210 : }
211 0 : } while( nIndex != -1 );
212 : } else
213 : {
214 : // produce all types
215 10 : produceAllTypes("/", typeMgr, generated, &options, true);
216 : }
217 : // C++ header files generated for the following UNO types are included
218 : // in header files in cppu/inc/com/sun/star/uno (Any.hxx, Reference.hxx,
219 : // Type.h), so it seems best to always generate those C++ header files:
220 10 : produce("com/sun/star/uno/RuntimeException", typeMgr, generated, &options);
221 10 : produce("com/sun/star/uno/TypeClass", typeMgr, generated, &options);
222 10 : produce("com/sun/star/uno/XInterface", typeMgr, generated, &options);
223 : }
224 0 : catch( CannotDumpException& e)
225 : {
226 : fprintf(stderr, "%s ERROR: %s\n",
227 0 : options.getProgramName().getStr(),
228 0 : e.m_message.getStr());
229 0 : exit(99);
230 : }
231 :
232 10 : return 0;
233 : }
234 :
235 :
236 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|