1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "includes.hxx"
23 #include "dependencies.hxx"
24 #include "dumputils.hxx"
26 #include "codemaker/global.hxx"
27 #include "codemaker/typemanager.hxx"
28 #include "codemaker/unotype.hxx"
30 #include "osl/diagnose.h"
31 #include "rtl/ref.hxx"
32 #include "rtl/string.hxx"
33 #include "rtl/ustring.hxx"
34 #include "sal/types.h"
38 using codemaker::cppumaker::Includes
;
41 rtl::Reference
< TypeManager
> const & manager
,
42 codemaker::cppumaker::Dependencies
const & dependencies
, bool hpp
):
43 m_manager(manager
), m_map(dependencies
.getMap()), m_hpp(hpp
),
44 m_includeCassert(false), m_includeException(false),
45 m_includeAny(dependencies
.hasAnyDependency()), m_includeReference(false),
46 m_includeSequence(dependencies
.hasSequenceDependency()),
47 m_includeType(dependencies
.hasTypeDependency()),
48 m_includeCppuMacrosHxx(false), m_includeCppuUnotypeHxx(false),
49 m_includeOslDoublecheckedlockingH(false), m_includeOslMutexHxx(false),
50 m_includeRtlStrbufHxx(false), m_includeRtlStringH(false),
51 m_includeRtlTextencH(false), m_includeRtlUstrbufHxx(false),
52 m_includeRtlUstringH(false),
53 m_includeRtlUstringHxx(dependencies
.hasStringDependency()),
54 m_includeRtlInstanceHxx(false),
56 dependencies
.hasBooleanDependency() || dependencies
.hasByteDependency()
57 || dependencies
.hasShortDependency()
58 || dependencies
.hasUnsignedShortDependency()
59 || dependencies
.hasLongDependency()
60 || dependencies
.hasUnsignedShortDependency()
61 || dependencies
.hasHyperDependency()
62 || dependencies
.hasUnsignedHyperDependency()
63 || dependencies
.hasCharDependency()),
64 m_includeTypelibTypeclassH(false),
65 m_includeTypelibTypedescriptionH(false)
71 void Includes::add(OString
const & entityName
) {
73 std::vector
< OString
> args
;
74 OUString
n(b2u(codemaker::UnoType::decompose(entityName
, &k
, &args
)));
76 m_includeSequence
= true;
78 switch (m_manager
->getSort(n
)) {
79 case codemaker::UnoType::SORT_BOOLEAN
:
80 case codemaker::UnoType::SORT_BYTE
:
81 case codemaker::UnoType::SORT_SHORT
:
82 case codemaker::UnoType::SORT_UNSIGNED_SHORT
:
83 case codemaker::UnoType::SORT_LONG
:
84 case codemaker::UnoType::SORT_UNSIGNED_LONG
:
85 case codemaker::UnoType::SORT_HYPER
:
86 case codemaker::UnoType::SORT_UNSIGNED_HYPER
:
87 case codemaker::UnoType::SORT_CHAR
:
88 m_includeSalTypesH
= true;
90 case codemaker::UnoType::SORT_FLOAT
:
91 case codemaker::UnoType::SORT_DOUBLE
:
93 case codemaker::UnoType::SORT_STRING
:
94 m_includeRtlUstringHxx
= true;
96 case codemaker::UnoType::SORT_TYPE
:
99 case codemaker::UnoType::SORT_ANY
:
102 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE
:
103 for (std::vector
< OString
>::iterator
i(args
.begin()); i
!= args
.end();
109 case codemaker::UnoType::SORT_SEQUENCE_TYPE
:
110 case codemaker::UnoType::SORT_ENUM_TYPE
:
111 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE
:
112 case codemaker::UnoType::SORT_EXCEPTION_TYPE
:
113 case codemaker::UnoType::SORT_INTERFACE_TYPE
:
114 case codemaker::UnoType::SORT_TYPEDEF
:
116 Dependencies::Map::value_type(n
, Dependencies::KIND_NO_BASE
));
119 throw CannotDumpException(
120 "unexpected type \"" + b2u(entityName
)
121 + "\" in call to codemaker::cppumaker::Includes::add");
127 void dumpEmptyLineBeforeFirst(FileStream
& out
, bool * first
) {
128 OSL_ASSERT(first
!= 0);
137 void Includes::dump(FileStream
& out
, OUString
const * companionHdl
) {
138 OSL_ASSERT(companionHdl
== 0 || m_hpp
);
139 if (!m_includeReference
) {
140 for (Dependencies::Map::iterator
i(m_map
.begin()); i
!= m_map
.end();
143 if (isInterfaceType(u2b(i
->first
))) {
144 m_includeReference
= true;
149 out
<< "#include \"sal/config.h\"\n";
150 if (m_includeCassert
|| m_includeException
) {
152 if (m_includeCassert
) {
153 out
<< "#include <cassert>\n";
155 if (m_includeException
) {
156 out
<< "#include <exception>\n";
161 dumpInclude(out
, u2b(*companionHdl
), false);
164 for (Dependencies::Map::iterator
i(m_map
.begin()); i
!= m_map
.end(); ++i
)
166 dumpEmptyLineBeforeFirst(out
, &first
);
167 if (m_hpp
|| i
->second
== Dependencies::KIND_BASE
168 || !isInterfaceType(u2b(i
->first
)))
170 dumpInclude(out
, u2b(i
->first
), m_hpp
);
172 bool ns
= dumpNamespaceOpen(out
, i
->first
, false);
177 dumpTypeIdentifier(out
, i
->first
);
182 dumpNamespaceClose(out
, i
->first
, false);
186 static char const * hxxExtension
[2] = { "h", "hxx" };
188 dumpEmptyLineBeforeFirst(out
, &first
);
189 out
<< "#include \"com/sun/star/uno/Any." << hxxExtension
[m_hpp
]
192 if (m_includeReference
) {
193 dumpEmptyLineBeforeFirst(out
, &first
);
194 out
<< "#include \"com/sun/star/uno/Reference." << hxxExtension
[m_hpp
]
197 if (m_includeSequence
) {
198 dumpEmptyLineBeforeFirst(out
, &first
);
199 out
<< "#include \"com/sun/star/uno/Sequence." << hxxExtension
[m_hpp
]
203 dumpEmptyLineBeforeFirst(out
, &first
);
204 out
<< "#include \"com/sun/star/uno/Type." << hxxExtension
[m_hpp
]
207 if (m_includeCppuMacrosHxx
) {
208 dumpEmptyLineBeforeFirst(out
, &first
);
209 out
<< ("#include \"cppu/macros.hxx\"\n");
211 if (m_includeCppuUnotypeHxx
) {
212 dumpEmptyLineBeforeFirst(out
, &first
);
213 out
<< ("#include \"cppu/unotype.hxx\"\n");
215 if (m_includeOslDoublecheckedlockingH
) {
216 dumpEmptyLineBeforeFirst(out
, &first
);
217 out
<< ("#include \"osl/doublecheckedlocking.h\"\n");
219 if (m_includeOslMutexHxx
) {
220 dumpEmptyLineBeforeFirst(out
, &first
);
221 out
<< "#include \"osl/mutex.hxx\"\n";
223 if (m_includeRtlStrbufHxx
) {
224 dumpEmptyLineBeforeFirst(out
, &first
);
225 out
<< ("#include \"rtl/strbuf.hxx\"\n");
227 if (m_includeRtlStringH
) {
228 dumpEmptyLineBeforeFirst(out
, &first
);
229 out
<< "#include \"rtl/string.h\"\n";
231 if (m_includeRtlTextencH
) {
232 dumpEmptyLineBeforeFirst(out
, &first
);
233 out
<< "#include \"rtl/textenc.h\"\n";
235 if (m_includeRtlUstrbufHxx
) {
236 dumpEmptyLineBeforeFirst(out
, &first
);
237 out
<< ("#include \"rtl/ustrbuf.hxx\"\n");
239 if (m_includeRtlUstringH
) {
240 dumpEmptyLineBeforeFirst(out
, &first
);
241 out
<< "#include \"rtl/ustring.h\"\n";
243 if (m_includeRtlUstringHxx
) {
244 dumpEmptyLineBeforeFirst(out
, &first
);
245 out
<< ("#include \"rtl/ustring.hxx\"\n");
247 if (m_includeRtlInstanceHxx
) {
248 dumpEmptyLineBeforeFirst(out
, &first
);
249 out
<< "#include \"rtl/instance.hxx\"\n";
251 if (m_includeSalTypesH
) {
252 dumpEmptyLineBeforeFirst(out
, &first
);
253 out
<< "#include \"sal/types.h\"\n";
255 if (m_includeTypelibTypeclassH
) {
256 dumpEmptyLineBeforeFirst(out
, &first
);
257 out
<< ("#include \"typelib/typeclass.h\"\n");
259 if (m_includeTypelibTypedescriptionH
) {
260 dumpEmptyLineBeforeFirst(out
, &first
);
261 out
<< ("#include \"typelib/typedescription.h\"\n");
265 void Includes::dumpInclude(
266 FileStream
& out
, OString
const & entityName
, bool hpp
)
268 out
<< "#include \"" << entityName
.replace('.', '/') << "."
269 << (hpp
? "hpp" : "hdl") << "\"\n";
272 bool Includes::isInterfaceType(OString
const & entityName
) const {
273 return m_manager
->getSort(b2u(entityName
)) == UnoType::SORT_INTERFACE_TYPE
;
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */