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 "includes.hxx"
22 :
23 : #include "dumputils.hxx"
24 :
25 : #include "codemaker/dependencies.hxx"
26 : #include "codemaker/global.hxx"
27 : #include "codemaker/typemanager.hxx"
28 : #include "codemaker/unotype.hxx"
29 :
30 : #include "osl/diagnose.h"
31 : #include "rtl/string.hxx"
32 : #include "rtl/ustring.hxx"
33 : #include "sal/types.h"
34 :
35 : #include <vector>
36 :
37 : using codemaker::cppumaker::Includes;
38 :
39 15049 : Includes::Includes(
40 : TypeManager const & manager, codemaker::Dependencies const & dependencies,
41 : bool hpp):
42 15049 : m_manager(manager), m_map(dependencies.getMap()), m_hpp(hpp),
43 15049 : m_includeCassert(false), m_includeAny(dependencies.hasAnyDependency()),
44 : m_includeReference(false),
45 15049 : m_includeSequence(dependencies.hasSequenceDependency()),
46 15049 : m_includeType(dependencies.hasTypeDependency()),
47 : m_includeCppuMacrosHxx(false), m_includeCppuUnotypeHxx(false),
48 : m_includeOslDoublecheckedlockingH(false), m_includeOslMutexHxx(false),
49 : m_includeRtlStrbufHxx(false), m_includeRtlStringH(false),
50 : m_includeRtlTextencH(false), m_includeRtlUstrbufHxx(false),
51 : m_includeRtlUstringH(false),
52 15049 : m_includeRtlUstringHxx(dependencies.hasStringDependency()),
53 : m_includeRtlInstanceHxx(false),
54 : m_includeSalTypesH(
55 27779 : dependencies.hasBooleanDependency() || dependencies.hasByteDependency()
56 12331 : || dependencies.hasShortDependency()
57 11053 : || dependencies.hasUnsignedShortDependency()
58 11025 : || dependencies.hasLongDependency()
59 7454 : || dependencies.hasUnsignedShortDependency()
60 7454 : || dependencies.hasHyperDependency()
61 7404 : || dependencies.hasUnsignedHyperDependency()
62 7400 : || dependencies.hasCharDependency()),
63 : m_includeTypelibTypeclassH(false),
64 182194 : m_includeTypelibTypedescriptionH(false)
65 15049 : {}
66 :
67 15049 : Includes::~Includes()
68 15049 : {}
69 :
70 8017 : void Includes::add(rtl::OString const & registryType) {
71 : sal_Int32 rank;
72 8017 : std::vector< rtl::OString > args;
73 : rtl::OString type(
74 8017 : codemaker::UnoType::decompose(registryType, &rank, &args));
75 8017 : if (rank > 0) {
76 0 : m_includeSequence = true;
77 : }
78 8017 : switch (codemaker::UnoType::getSort(type)) {
79 : case codemaker::UnoType::SORT_VOID:
80 : OSL_ASSERT(args.empty());
81 : OSL_ASSERT(false);
82 0 : break;
83 :
84 : case codemaker::UnoType::SORT_BOOLEAN:
85 : case codemaker::UnoType::SORT_BYTE:
86 : case codemaker::UnoType::SORT_SHORT:
87 : case codemaker::UnoType::SORT_UNSIGNED_SHORT:
88 : case codemaker::UnoType::SORT_LONG:
89 : case codemaker::UnoType::SORT_UNSIGNED_LONG:
90 : case codemaker::UnoType::SORT_HYPER:
91 : case codemaker::UnoType::SORT_UNSIGNED_HYPER:
92 : case codemaker::UnoType::SORT_CHAR:
93 : OSL_ASSERT(args.empty());
94 0 : m_includeSalTypesH = true;
95 0 : break;
96 :
97 : case codemaker::UnoType::SORT_FLOAT:
98 : case codemaker::UnoType::SORT_DOUBLE:
99 : OSL_ASSERT(args.empty());
100 0 : break;
101 :
102 : case codemaker::UnoType::SORT_STRING:
103 : OSL_ASSERT(args.empty());
104 0 : m_includeRtlUstringHxx = true;
105 0 : break;
106 :
107 : case codemaker::UnoType::SORT_TYPE:
108 : OSL_ASSERT(args.empty());
109 0 : m_includeType = true;
110 0 : break;
111 :
112 : case codemaker::UnoType::SORT_ANY:
113 : OSL_ASSERT(args.empty());
114 0 : m_includeAny = true;
115 0 : break;
116 :
117 : case codemaker::UnoType::SORT_COMPLEX:
118 : m_map.insert(
119 : codemaker::Dependencies::Map::value_type(
120 8017 : type, codemaker::Dependencies::KIND_NO_BASE));
121 24051 : {for (std::vector< rtl::OString >::iterator i(args.begin());
122 16034 : i != args.end(); ++i)
123 : {
124 0 : add(*i);
125 : }}
126 8017 : break;
127 :
128 : default:
129 : OSL_ASSERT(false);
130 0 : break;
131 8017 : }
132 8017 : }
133 :
134 : namespace {
135 :
136 91748 : void dumpEmptyLineBeforeFirst(FileStream & out, bool * first) {
137 : OSL_ASSERT(first != 0);
138 91748 : if (*first) {
139 13518 : out << "\n";
140 13518 : *first = false;
141 : }
142 91748 : }
143 :
144 : }
145 :
146 13518 : void Includes::dump(FileStream & out, rtl::OString const * companionHdl) {
147 : OSL_ASSERT(companionHdl == 0 || m_hpp);
148 13518 : if (!m_includeReference) {
149 22179 : for (codemaker::Dependencies::Map::iterator i(m_map.begin());
150 14786 : i != m_map.end(); ++i)
151 : {
152 2390 : if (isInterfaceType(i->first)) {
153 298 : m_includeReference = true;
154 298 : break;
155 : }
156 : }
157 : }
158 13518 : out << "#include \"sal/config.h\"\n";
159 13518 : if (m_includeCassert) {
160 755 : out << "\n#include <cassert>\n";
161 : }
162 13518 : if (companionHdl) {
163 5595 : out << "\n";
164 5595 : dumpInclude(out, *companionHdl, false);
165 : }
166 13518 : bool first = true;
167 146211 : for (codemaker::Dependencies::Map::iterator i(m_map.begin());
168 97474 : i != m_map.end(); ++i)
169 : {
170 35219 : dumpEmptyLineBeforeFirst(out, &first);
171 46092 : if (m_hpp || i->second == codemaker::Dependencies::KIND_BASE
172 10873 : || !isInterfaceType(i->first))
173 : {
174 32222 : dumpInclude(out, i->first, m_hpp);
175 : } else {
176 2997 : bool ns = dumpNamespaceOpen(out, i->first, false);
177 2997 : if (ns) {
178 2997 : out << " ";
179 : }
180 2997 : out << "class ";
181 2997 : dumpTypeIdentifier(out, i->first);
182 2997 : out << ";";
183 2997 : if (ns) {
184 2997 : out << " ";
185 : }
186 2997 : dumpNamespaceClose(out, i->first, false);
187 2997 : out << "\n";
188 : }
189 : }
190 : static char const * hxxExtension[2] = { "h", "hxx" };
191 13518 : if (m_includeAny) {
192 1826 : dumpEmptyLineBeforeFirst(out, &first);
193 1826 : out << "#include \"com/sun/star/uno/Any." << hxxExtension[m_hpp] << "\"\n";
194 : }
195 13518 : if (m_includeReference) {
196 8515 : dumpEmptyLineBeforeFirst(out, &first);
197 8515 : out << "#include \"com/sun/star/uno/Reference." << hxxExtension[m_hpp] << "\"\n";
198 : }
199 13518 : if (m_includeSequence) {
200 2599 : dumpEmptyLineBeforeFirst(out, &first);
201 2599 : out << "#include \"com/sun/star/uno/Sequence." << hxxExtension[m_hpp] << "\"\n";
202 : }
203 13518 : if (m_includeType) {
204 5670 : dumpEmptyLineBeforeFirst(out, &first);
205 5670 : out << "#include \"com/sun/star/uno/Type." << hxxExtension[m_hpp] << "\"\n";
206 : }
207 13518 : if (m_includeCppuMacrosHxx) {
208 7126 : dumpEmptyLineBeforeFirst(out, &first);
209 7126 : out << ("#include \"cppu/macros.hxx\"\n");
210 : }
211 13518 : if (m_includeCppuUnotypeHxx) {
212 6392 : dumpEmptyLineBeforeFirst(out, &first);
213 6392 : out << ("#include \"cppu/unotype.hxx\"\n");
214 : }
215 13518 : if (m_includeOslDoublecheckedlockingH) {
216 0 : dumpEmptyLineBeforeFirst(out, &first);
217 0 : out << ("#include \"osl/doublecheckedlocking.h\"\n");
218 : }
219 13518 : if (m_includeOslMutexHxx) {
220 5162 : dumpEmptyLineBeforeFirst(out, &first);
221 5162 : out << "#include \"osl/mutex.hxx\"\n";
222 : }
223 13518 : if (m_includeRtlStrbufHxx) {
224 10 : dumpEmptyLineBeforeFirst(out, &first);
225 10 : out << ("#include \"rtl/strbuf.hxx\"\n");
226 : }
227 13518 : if (m_includeRtlStringH) {
228 6 : dumpEmptyLineBeforeFirst(out, &first);
229 6 : out << "#include \"rtl/string.h\"\n";
230 : }
231 13518 : if (m_includeRtlTextencH) {
232 10 : dumpEmptyLineBeforeFirst(out, &first);
233 10 : out << "#include \"rtl/textenc.h\"\n";
234 : }
235 13518 : if (m_includeRtlUstrbufHxx) {
236 6 : dumpEmptyLineBeforeFirst(out, &first);
237 6 : out << ("#include \"rtl/ustrbuf.hxx\"\n");
238 : }
239 13518 : if (m_includeRtlUstringH) {
240 1157 : dumpEmptyLineBeforeFirst(out, &first);
241 1157 : out << "#include \"rtl/ustring.h\"\n";
242 : }
243 13518 : if (m_includeRtlUstringHxx) {
244 4728 : dumpEmptyLineBeforeFirst(out, &first);
245 4728 : out << ("#include \"rtl/ustring.hxx\"\n");
246 : }
247 13518 : if (m_includeRtlInstanceHxx) {
248 5162 : dumpEmptyLineBeforeFirst(out, &first);
249 5162 : out << "#include \"rtl/instance.hxx\"\n";
250 : }
251 13518 : if (m_includeSalTypesH) {
252 6478 : dumpEmptyLineBeforeFirst(out, &first);
253 6478 : out << "#include \"sal/types.h\"\n";
254 : }
255 13518 : if (m_includeTypelibTypeclassH) {
256 841 : dumpEmptyLineBeforeFirst(out, &first);
257 841 : out << ("#include \"typelib/typeclass.h\"\n");
258 : }
259 13518 : if (m_includeTypelibTypedescriptionH) {
260 841 : dumpEmptyLineBeforeFirst(out, &first);
261 841 : out << ("#include \"typelib/typedescription.h\"\n");
262 : }
263 13518 : }
264 :
265 39348 : void Includes::dumpInclude(
266 : FileStream & out, rtl::OString const & registryType, bool hpp,
267 : rtl::OString const & suffix)
268 : {
269 : static char const * extension[2] = { "hdl", "hpp" };
270 39348 : out << "#include \"" << registryType;
271 39348 : if (!suffix.isEmpty()) {
272 0 : out << "/" << suffix;
273 : }
274 39348 : out << "." << extension[hpp] << "\"\n";
275 39348 : }
276 :
277 13263 : bool Includes::isInterfaceType(rtl::OString const & registryType) const {
278 13263 : return m_manager.getTypeClass(registryType) == RT_TYPE_INTERFACE;
279 : }
280 :
281 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|