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::UnsignedShort
:
83 case codemaker::UnoType::Sort::Long
:
84 case codemaker::UnoType::Sort::UnsignedLong
:
85 case codemaker::UnoType::Sort::Hyper
:
86 case codemaker::UnoType::Sort::UnsignedHyper
:
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::PolymorphicStructTemplate
:
103 for (const OString
& arg
: args
)
108 case codemaker::UnoType::Sort::Sequence
:
109 case codemaker::UnoType::Sort::Enum
:
110 case codemaker::UnoType::Sort::PlainStruct
:
111 case codemaker::UnoType::Sort::Exception
:
112 case codemaker::UnoType::Sort::Interface
:
113 case codemaker::UnoType::Sort::Typedef
:
115 Dependencies::Map::value_type(n
, Dependencies::KIND_NO_BASE
));
118 throw CannotDumpException(
119 "unexpected type \"" + b2u(entityName
)
120 + "\" in call to codemaker::cppumaker::Includes::add");
126 void dumpEmptyLineBeforeFirst(FileStream
& out
, bool * first
) {
127 OSL_ASSERT(first
!= nullptr);
136 void Includes::dump(FileStream
& out
, OUString
const * companionHdl
) {
137 OSL_ASSERT(companionHdl
== nullptr || m_hpp
);
138 if (!m_includeReference
) {
139 for (const std::pair
<OUString
, codemaker::cppumaker::Dependencies::Kind
>& pair
: m_map
)
141 if (isInterfaceType(u2b(pair
.first
))) {
142 m_includeReference
= true;
147 out
<< "#include \"sal/config.h\"\n";
148 if (m_includeCassert
|| m_includeException
) {
150 if (m_includeCassert
) {
151 out
<< "#include <cassert>\n";
153 if (m_includeException
) {
154 out
<< "#include <exception>\n";
159 dumpInclude(out
, u2b(*companionHdl
), false);
162 for (const std::pair
<OUString
, codemaker::cppumaker::Dependencies::Kind
>& pair
: m_map
)
164 dumpEmptyLineBeforeFirst(out
, &first
);
165 if (m_hpp
|| pair
.second
== Dependencies::KIND_BASE
166 || !isInterfaceType(u2b(pair
.first
)))
168 dumpInclude(out
, u2b(pair
.first
), m_hpp
);
170 bool ns
= dumpNamespaceOpen(out
, pair
.first
, false);
175 dumpTypeIdentifier(out
, pair
.first
);
180 dumpNamespaceClose(out
, pair
.first
, false);
184 static char const * hxxExtension
[2] = { "h", "hxx" };
186 dumpEmptyLineBeforeFirst(out
, &first
);
187 out
<< "#include \"com/sun/star/uno/Any." << hxxExtension
[m_hpp
]
190 if (m_includeReference
) {
191 dumpEmptyLineBeforeFirst(out
, &first
);
192 out
<< "#include \"com/sun/star/uno/Reference." << hxxExtension
[m_hpp
]
195 if (m_includeSequence
) {
196 dumpEmptyLineBeforeFirst(out
, &first
);
197 out
<< "#include \"com/sun/star/uno/Sequence." << hxxExtension
[m_hpp
]
201 dumpEmptyLineBeforeFirst(out
, &first
);
202 out
<< "#include \"com/sun/star/uno/Type." << hxxExtension
[m_hpp
]
205 if (m_includeCppuMacrosHxx
) {
206 dumpEmptyLineBeforeFirst(out
, &first
);
207 out
<< ("#include \"cppu/macros.hxx\"\n");
209 if (m_includeCppuUnotypeHxx
) {
210 dumpEmptyLineBeforeFirst(out
, &first
);
211 out
<< ("#include \"cppu/unotype.hxx\"\n");
213 if (m_includeOslDoublecheckedlockingH
) {
214 dumpEmptyLineBeforeFirst(out
, &first
);
215 out
<< ("#include \"osl/doublecheckedlocking.h\"\n");
217 if (m_includeOslMutexHxx
) {
218 dumpEmptyLineBeforeFirst(out
, &first
);
219 out
<< "#include \"osl/mutex.hxx\"\n";
221 if (m_includeRtlStrbufHxx
) {
222 dumpEmptyLineBeforeFirst(out
, &first
);
223 out
<< ("#include \"rtl/strbuf.hxx\"\n");
225 if (m_includeRtlStringH
) {
226 dumpEmptyLineBeforeFirst(out
, &first
);
227 out
<< "#include \"rtl/string.h\"\n";
229 if (m_includeRtlTextencH
) {
230 dumpEmptyLineBeforeFirst(out
, &first
);
231 out
<< "#include \"rtl/textenc.h\"\n";
233 if (m_includeRtlUstrbufHxx
) {
234 dumpEmptyLineBeforeFirst(out
, &first
);
235 out
<< ("#include \"rtl/ustrbuf.hxx\"\n");
237 if (m_includeRtlUstringH
) {
238 dumpEmptyLineBeforeFirst(out
, &first
);
239 out
<< "#include \"rtl/ustring.h\"\n";
241 if (m_includeRtlUstringHxx
) {
242 dumpEmptyLineBeforeFirst(out
, &first
);
243 out
<< ("#include \"rtl/ustring.hxx\"\n");
245 if (m_includeRtlInstanceHxx
) {
246 dumpEmptyLineBeforeFirst(out
, &first
);
247 out
<< "#include \"rtl/instance.hxx\"\n";
249 if (m_includeSalTypesH
) {
250 dumpEmptyLineBeforeFirst(out
, &first
);
251 out
<< "#include \"sal/types.h\"\n";
253 if (m_includeTypelibTypeclassH
) {
254 dumpEmptyLineBeforeFirst(out
, &first
);
255 out
<< ("#include \"typelib/typeclass.h\"\n");
257 if (m_includeTypelibTypedescriptionH
) {
258 dumpEmptyLineBeforeFirst(out
, &first
);
259 out
<< ("#include \"typelib/typedescription.h\"\n");
263 void Includes::dumpInclude(
264 FileStream
& out
, OString
const & entityName
, bool hpp
)
266 out
<< "#include \"" << entityName
.replace('.', '/') << "."
267 << (hpp
? "hpp" : "hdl") << "\"\n";
270 bool Includes::isInterfaceType(OString
const & entityName
) const {
271 return m_manager
->getSort(b2u(entityName
)) == UnoType::Sort::Interface
;
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */