1*ff7655f0SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ff7655f0SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ff7655f0SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ff7655f0SAndrew Rist * distributed with this work for additional information 6*ff7655f0SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ff7655f0SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ff7655f0SAndrew Rist * "License"); you may not use this file except in compliance 9*ff7655f0SAndrew Rist * with the License. You may obtain a copy of the License at 10*ff7655f0SAndrew Rist * 11*ff7655f0SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ff7655f0SAndrew Rist * 13*ff7655f0SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ff7655f0SAndrew Rist * software distributed under the License is distributed on an 15*ff7655f0SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ff7655f0SAndrew Rist * KIND, either express or implied. See the License for the 17*ff7655f0SAndrew Rist * specific language governing permissions and limitations 18*ff7655f0SAndrew Rist * under the License. 19*ff7655f0SAndrew Rist * 20*ff7655f0SAndrew Rist *************************************************************/ 21*ff7655f0SAndrew Rist 22*ff7655f0SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_codemaker.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "includes.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "dumputils.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include "codemaker/dependencies.hxx" 32cdf0e10cSrcweir #include "codemaker/global.hxx" 33cdf0e10cSrcweir #include "codemaker/typemanager.hxx" 34cdf0e10cSrcweir #include "codemaker/unotype.hxx" 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include "osl/diagnose.h" 37cdf0e10cSrcweir #include "rtl/string.hxx" 38cdf0e10cSrcweir #include "rtl/ustring.hxx" 39cdf0e10cSrcweir #include "sal/types.h" 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include <vector> 42cdf0e10cSrcweir 43cdf0e10cSrcweir using codemaker::cppumaker::Includes; 44cdf0e10cSrcweir 45cdf0e10cSrcweir Includes::Includes( 46cdf0e10cSrcweir TypeManager const & manager, codemaker::Dependencies const & dependencies, 47cdf0e10cSrcweir bool hpp): 48cdf0e10cSrcweir m_manager(manager), m_map(dependencies.getMap()), m_hpp(hpp), 49cdf0e10cSrcweir m_includeAny(dependencies.hasAnyDependency()), m_includeReference(false), 50cdf0e10cSrcweir m_includeSequence(dependencies.hasSequenceDependency()), 51cdf0e10cSrcweir m_includeType(dependencies.hasTypeDependency()), 52cdf0e10cSrcweir m_includeCppuMacrosHxx(false), m_includeCppuUnotypeHxx(false), 53cdf0e10cSrcweir m_includeOslDoublecheckedlockingH(false), m_includeOslMutexHxx(false), 54cdf0e10cSrcweir m_includeRtlStrbufHxx(false), m_includeRtlStringH(false), 55cdf0e10cSrcweir m_includeRtlTextencH(false), m_includeRtlUstrbufHxx(false), 56cdf0e10cSrcweir m_includeRtlUstringH(false), 57cdf0e10cSrcweir m_includeRtlUstringHxx(dependencies.hasStringDependency()), 58cdf0e10cSrcweir m_includeSalTypesH( 59cdf0e10cSrcweir dependencies.hasBooleanDependency() || dependencies.hasByteDependency() 60cdf0e10cSrcweir || dependencies.hasShortDependency() 61cdf0e10cSrcweir || dependencies.hasUnsignedShortDependency() 62cdf0e10cSrcweir || dependencies.hasLongDependency() 63cdf0e10cSrcweir || dependencies.hasUnsignedShortDependency() 64cdf0e10cSrcweir || dependencies.hasHyperDependency() 65cdf0e10cSrcweir || dependencies.hasUnsignedHyperDependency() 66cdf0e10cSrcweir || dependencies.hasCharDependency()), 67cdf0e10cSrcweir m_includeTypelibTypeclassH(false), 68cdf0e10cSrcweir m_includeTypelibTypedescriptionH(false) 69cdf0e10cSrcweir {} 70cdf0e10cSrcweir 71cdf0e10cSrcweir Includes::~Includes() 72cdf0e10cSrcweir {} 73cdf0e10cSrcweir 74cdf0e10cSrcweir void Includes::add(rtl::OString const & registryType) { 75cdf0e10cSrcweir sal_Int32 rank; 76cdf0e10cSrcweir std::vector< rtl::OString > args; 77cdf0e10cSrcweir rtl::OString type( 78cdf0e10cSrcweir codemaker::UnoType::decompose(registryType, &rank, &args)); 79cdf0e10cSrcweir if (rank > 0) { 80cdf0e10cSrcweir m_includeSequence = true; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir switch (codemaker::UnoType::getSort(type)) { 83cdf0e10cSrcweir case codemaker::UnoType::SORT_VOID: 84cdf0e10cSrcweir OSL_ASSERT(args.empty()); 85cdf0e10cSrcweir OSL_ASSERT(false); 86cdf0e10cSrcweir break; 87cdf0e10cSrcweir 88cdf0e10cSrcweir case codemaker::UnoType::SORT_BOOLEAN: 89cdf0e10cSrcweir case codemaker::UnoType::SORT_BYTE: 90cdf0e10cSrcweir case codemaker::UnoType::SORT_SHORT: 91cdf0e10cSrcweir case codemaker::UnoType::SORT_UNSIGNED_SHORT: 92cdf0e10cSrcweir case codemaker::UnoType::SORT_LONG: 93cdf0e10cSrcweir case codemaker::UnoType::SORT_UNSIGNED_LONG: 94cdf0e10cSrcweir case codemaker::UnoType::SORT_HYPER: 95cdf0e10cSrcweir case codemaker::UnoType::SORT_UNSIGNED_HYPER: 96cdf0e10cSrcweir case codemaker::UnoType::SORT_CHAR: 97cdf0e10cSrcweir OSL_ASSERT(args.empty()); 98cdf0e10cSrcweir m_includeSalTypesH = true; 99cdf0e10cSrcweir break; 100cdf0e10cSrcweir 101cdf0e10cSrcweir case codemaker::UnoType::SORT_FLOAT: 102cdf0e10cSrcweir case codemaker::UnoType::SORT_DOUBLE: 103cdf0e10cSrcweir OSL_ASSERT(args.empty()); 104cdf0e10cSrcweir break; 105cdf0e10cSrcweir 106cdf0e10cSrcweir case codemaker::UnoType::SORT_STRING: 107cdf0e10cSrcweir OSL_ASSERT(args.empty()); 108cdf0e10cSrcweir m_includeRtlUstringHxx = true; 109cdf0e10cSrcweir break; 110cdf0e10cSrcweir 111cdf0e10cSrcweir case codemaker::UnoType::SORT_TYPE: 112cdf0e10cSrcweir OSL_ASSERT(args.empty()); 113cdf0e10cSrcweir m_includeType = true; 114cdf0e10cSrcweir break; 115cdf0e10cSrcweir 116cdf0e10cSrcweir case codemaker::UnoType::SORT_ANY: 117cdf0e10cSrcweir OSL_ASSERT(args.empty()); 118cdf0e10cSrcweir m_includeAny = true; 119cdf0e10cSrcweir break; 120cdf0e10cSrcweir 121cdf0e10cSrcweir case codemaker::UnoType::SORT_COMPLEX: 122cdf0e10cSrcweir m_map.insert( 123cdf0e10cSrcweir codemaker::Dependencies::Map::value_type( 124cdf0e10cSrcweir type, codemaker::Dependencies::KIND_NO_BASE)); 125cdf0e10cSrcweir {for (std::vector< rtl::OString >::iterator i(args.begin()); 126cdf0e10cSrcweir i != args.end(); ++i) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir add(*i); 129cdf0e10cSrcweir }} 130cdf0e10cSrcweir break; 131cdf0e10cSrcweir 132cdf0e10cSrcweir default: 133cdf0e10cSrcweir OSL_ASSERT(false); 134cdf0e10cSrcweir break; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir namespace { 139cdf0e10cSrcweir 140cdf0e10cSrcweir void dumpEmptyLineBeforeFirst(FileStream & out, bool * first) { 141cdf0e10cSrcweir OSL_ASSERT(first != 0); 142cdf0e10cSrcweir if (*first) { 143cdf0e10cSrcweir out << "\n"; 144cdf0e10cSrcweir *first = false; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir void Includes::dump(FileStream & out, rtl::OString const * companionHdl) { 151cdf0e10cSrcweir OSL_ASSERT(companionHdl == 0 || m_hpp); 152cdf0e10cSrcweir if (!m_includeReference) { 153cdf0e10cSrcweir for (codemaker::Dependencies::Map::iterator i(m_map.begin()); 154cdf0e10cSrcweir i != m_map.end(); ++i) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir if (isInterfaceType(i->first)) { 157cdf0e10cSrcweir m_includeReference = true; 158cdf0e10cSrcweir break; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir } 161cdf0e10cSrcweir } 162cdf0e10cSrcweir out << "#include \"sal/config.h\"\n"; 163cdf0e10cSrcweir if (companionHdl) { 164cdf0e10cSrcweir out << "\n"; 165cdf0e10cSrcweir dumpInclude(out, *companionHdl, false); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir bool first = true; 168cdf0e10cSrcweir for (codemaker::Dependencies::Map::iterator i(m_map.begin()); 169cdf0e10cSrcweir i != m_map.end(); ++i) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 172cdf0e10cSrcweir if (m_hpp || i->second == codemaker::Dependencies::KIND_BASE 173cdf0e10cSrcweir || !isInterfaceType(i->first)) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir dumpInclude(out, i->first, m_hpp); 176cdf0e10cSrcweir } else { 177cdf0e10cSrcweir bool ns = dumpNamespaceOpen(out, i->first, false); 178cdf0e10cSrcweir if (ns) { 179cdf0e10cSrcweir out << " "; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir out << "class "; 182cdf0e10cSrcweir dumpTypeIdentifier(out, i->first); 183cdf0e10cSrcweir out << ";"; 184cdf0e10cSrcweir if (ns) { 185cdf0e10cSrcweir out << " "; 186cdf0e10cSrcweir } 187cdf0e10cSrcweir dumpNamespaceClose(out, i->first, false); 188cdf0e10cSrcweir out << "\n"; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir } 191cdf0e10cSrcweir static char const * hxxExtension[2] = { "h", "hxx" }; 192cdf0e10cSrcweir if (m_includeAny) { 193cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 194cdf0e10cSrcweir out << "#include \"com/sun/star/uno/Any." << hxxExtension[m_hpp] << "\"\n"; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir if (m_includeReference) { 197cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 198cdf0e10cSrcweir out << "#include \"com/sun/star/uno/Reference." << hxxExtension[m_hpp] << "\"\n"; 199cdf0e10cSrcweir } 200cdf0e10cSrcweir if (m_includeSequence) { 201cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 202cdf0e10cSrcweir out << "#include \"com/sun/star/uno/Sequence." << hxxExtension[m_hpp] << "\"\n"; 203cdf0e10cSrcweir } 204cdf0e10cSrcweir if (m_includeType) { 205cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 206cdf0e10cSrcweir out << "#include \"com/sun/star/uno/Type." << hxxExtension[m_hpp] << "\"\n"; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir if (m_includeCppuMacrosHxx) { 209cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 210cdf0e10cSrcweir out << ("#include \"cppu/macros.hxx\"\n"); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir if (m_includeCppuUnotypeHxx) { 213cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 214cdf0e10cSrcweir out << ("#include \"cppu/unotype.hxx\"\n"); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir if (m_includeOslDoublecheckedlockingH) { 217cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 218cdf0e10cSrcweir out << ("#include \"osl/doublecheckedlocking.h\"\n"); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir if (m_includeOslMutexHxx) { 221cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 222cdf0e10cSrcweir out << "#include \"osl/mutex.hxx\"\n"; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir if (m_includeRtlStrbufHxx) { 225cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 226cdf0e10cSrcweir out << ("#include \"rtl/strbuf.hxx\"\n"); 227cdf0e10cSrcweir } 228cdf0e10cSrcweir if (m_includeRtlStringH) { 229cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 230cdf0e10cSrcweir out << "#include \"rtl/string.h\"\n"; 231cdf0e10cSrcweir } 232cdf0e10cSrcweir if (m_includeRtlTextencH) { 233cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 234cdf0e10cSrcweir out << "#include \"rtl/textenc.h\"\n"; 235cdf0e10cSrcweir } 236cdf0e10cSrcweir if (m_includeRtlUstrbufHxx) { 237cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 238cdf0e10cSrcweir out << ("#include \"rtl/ustrbuf.hxx\"\n"); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir if (m_includeRtlUstringH) { 241cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 242cdf0e10cSrcweir out << "#include \"rtl/ustring.h\"\n"; 243cdf0e10cSrcweir } 244cdf0e10cSrcweir if (m_includeRtlUstringHxx) { 245cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 246cdf0e10cSrcweir out << ("#include \"rtl/ustring.hxx\"\n"); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir if (m_includeSalTypesH) { 249cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 250cdf0e10cSrcweir out << "#include \"sal/types.h\"\n"; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir if (m_includeTypelibTypeclassH) { 253cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 254cdf0e10cSrcweir out << ("#include \"typelib/typeclass.h\"\n"); 255cdf0e10cSrcweir } 256cdf0e10cSrcweir if (m_includeTypelibTypedescriptionH) { 257cdf0e10cSrcweir dumpEmptyLineBeforeFirst(out, &first); 258cdf0e10cSrcweir out << ("#include \"typelib/typedescription.h\"\n"); 259cdf0e10cSrcweir } 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir void Includes::dumpInclude( 263cdf0e10cSrcweir FileStream & out, rtl::OString const & registryType, bool hpp, 264cdf0e10cSrcweir rtl::OString const & suffix) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir static char const * extension[2] = { "hdl", "hpp" }; 267cdf0e10cSrcweir out << "#include \"" << registryType; 268cdf0e10cSrcweir if (suffix.getLength() > 0) { 269cdf0e10cSrcweir out << "/" << suffix; 270cdf0e10cSrcweir } 271cdf0e10cSrcweir out << "." << extension[hpp] << "\"\n"; 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir bool Includes::isInterfaceType(rtl::OString const & registryType) const { 275cdf0e10cSrcweir return m_manager.getTypeClass(registryType) == RT_TYPE_INTERFACE; 276cdf0e10cSrcweir } 277