diff options
Diffstat (limited to 'codemaker/source')
20 files changed, 3647 insertions, 4597 deletions
diff --git a/codemaker/source/codemaker/codemaker.cxx b/codemaker/source/codemaker/codemaker.cxx index 0412e36d066b..2ed28e12da34 100644 --- a/codemaker/source/codemaker/codemaker.cxx +++ b/codemaker/source/codemaker/codemaker.cxx @@ -39,7 +39,7 @@ namespace { -void checkNoTypeArguments(std::vector< OString > const & arguments) { +void checkNoTypeArguments(std::vector< rtl::OString > const & arguments) { if (!arguments.empty()) { throw CannotDumpException("Bad type information"); //TODO @@ -50,8 +50,8 @@ void checkNoTypeArguments(std::vector< OString > const & arguments) { namespace codemaker { -OString convertString(OUString const & string) { - OString s; +rtl::OString convertString(rtl::OUString const & string) { + rtl::OString s; if (!string.convertToString( &s, RTL_TEXTENCODING_UTF8, (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR @@ -63,18 +63,18 @@ OString convertString(OUString const & string) { } codemaker::UnoType::Sort decomposeAndResolve( - rtl::Reference< TypeManager > const & manager, OString const & type, + rtl::Reference< TypeManager > const & manager, rtl::OString const & type, bool resolveTypedefs, bool allowVoid, bool allowExtraEntities, - RTTypeClass * typeClass, OString * name, sal_Int32 * rank, - std::vector< OString > * arguments) + RTTypeClass * typeClass, rtl::OString * name, sal_Int32 * rank, + std::vector< rtl::OString > * arguments) { OSL_ASSERT(typeClass != 0 && name != 0 && rank != 0 && arguments != 0); *rank = 0; - for (OString t(type);;) { + for (rtl::OString t(type);;) { sal_Int32 n = 0; *name = codemaker::UnoType::decompose(t, &n, arguments); if (n > SAL_MAX_INT32 - *rank) { - throw CannotDumpException("Bad type information: " + type); + throw CannotDumpException("Bad type information: " + b2u(type)); //TODO } *rank += n; @@ -86,7 +86,7 @@ codemaker::UnoType::Sort decomposeAndResolve( switch (sort) { case codemaker::UnoType::SORT_VOID: if (!allowVoid) { - throw CannotDumpException("Bad type information: " + type); + throw CannotDumpException("Bad type information: " + b2u(type)); //TODO } default: @@ -109,7 +109,7 @@ codemaker::UnoType::Sort decomposeAndResolve( || (static_cast< sal_uInt16 >(arguments->size()) != reader.getReferenceCount()))) { - throw CannotDumpException("Bad type information: " + type); + throw CannotDumpException("Bad type information: " + b2u(type)); //TODO } return sort; @@ -120,7 +120,7 @@ codemaker::UnoType::Sort decomposeAndResolve( case RT_TYPE_SINGLETON: case RT_TYPE_CONSTANTS: if (!allowExtraEntities) { - throw CannotDumpException("Bad type information: " + type); + throw CannotDumpException("Bad type information: " + b2u(type)); //TODO } checkNoTypeArguments(*arguments); @@ -142,7 +142,7 @@ codemaker::UnoType::Sort decomposeAndResolve( } } default: - throw CannotDumpException("Bad type information: " + type); + throw CannotDumpException("Bad type information: " + b2u(type)); //TODO } } diff --git a/codemaker/source/codemaker/dependencies.cxx b/codemaker/source/codemaker/dependencies.cxx deleted file mode 100644 index 143dc98ffdc3..000000000000 --- a/codemaker/source/codemaker/dependencies.cxx +++ /dev/null @@ -1,273 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include "codemaker/dependencies.hxx" - -#include "codemaker/typemanager.hxx" -#include "codemaker/unotype.hxx" - -#include "osl/diagnose.h" -#include "registry/reader.hxx" -#include "rtl/string.hxx" -#include "rtl/textcvt.h" -#include "rtl/textenc.h" -#include "rtl/ustring.hxx" -#include "sal/types.h" - -#include <vector> - -using codemaker::Dependencies; - -namespace { - -struct Bad {}; - -} - -Dependencies::Dependencies( - rtl::Reference< TypeManager > const & manager, OString const & type): - m_voidDependency(false), m_booleanDependency(false), - m_byteDependency(false), m_shortDependency(false), - m_unsignedShortDependency(false), m_longDependency(false), - m_unsignedLongDependency(false), m_hyperDependency(false), - m_unsignedHyperDependency(false), m_floatDependency(false), - m_doubleDependency(false), m_charDependency(false), - m_stringDependency(false), m_typeDependency(false), m_anyDependency(false), - m_sequenceDependency(false) -{ - typereg::Reader reader(manager->getTypeReader(type)); - m_valid = reader.isValid(); - if (m_valid) { - // Not everything is checked for consistency, just things that are cheap - // to test: - try { - RTTypeClass tc = reader.getTypeClass(); - if (tc != RT_TYPE_SERVICE) { - for (sal_Int16 i = 0; i < reader.getSuperTypeCount(); ++i) { - insert(reader.getSuperTypeName(i), true); - } - } - if (tc != RT_TYPE_ENUM) { - for (sal_Int16 i = 0; i < reader.getFieldCount(); ++i) { - if ((reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) - == 0) - { - insert(reader.getFieldTypeName(i), false); - } - } - } - for (sal_Int16 i = 0; i < reader.getMethodCount(); ++i) { - insert(reader.getMethodReturnTypeName(i), false); - for (sal_Int16 j = 0; j < reader.getMethodParameterCount(i); - ++j) - { - if ((reader.getMethodParameterFlags(i, j) & RT_PARAM_REST) - != 0) - { - m_sequenceDependency = true; - } - insert(reader.getMethodParameterTypeName(i, j), false); - } - for (sal_Int16 j = 0; j < reader.getMethodExceptionCount(i); - ++j) - { - insert(reader.getMethodExceptionTypeName(i, j), false); - } - } - for (sal_Int16 i = 0; i < reader.getReferenceCount(); ++i) { - if (reader.getReferenceSort(i) != RT_REF_TYPE_PARAMETER) { - insert(reader.getReferenceTypeName(i), false); - } - } - } catch (Bad &) { - m_map.clear(); - m_valid = false; - m_voidDependency = false; - m_booleanDependency = false; - m_byteDependency = false; - m_shortDependency = false; - m_unsignedShortDependency = false; - m_longDependency = false; - m_unsignedLongDependency = false; - m_hyperDependency = false; - m_unsignedHyperDependency = false; - m_floatDependency = false; - m_doubleDependency = false; - m_charDependency = false; - m_stringDependency = false; - m_typeDependency = false; - m_anyDependency = false; - m_sequenceDependency = false; - } - } -} - -Dependencies::~Dependencies() -{} - -void Dependencies::insert(OUString const & type, bool base) { - OString t; - if (!type.convertToString( - &t, RTL_TEXTENCODING_UTF8, - (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR - | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))) - { - throw Bad(); - } - insert(t, base); -} - -void Dependencies::insert(OString const & type, bool base) { - sal_Int32 rank; - std::vector< OString > args; - OString t(UnoType::decompose(type, &rank, &args)); - if (rank > 0) { - m_sequenceDependency = true; - } - switch (UnoType::getSort(t)) { - case UnoType::SORT_VOID: - if (rank != 0 || !args.empty()) { - throw Bad(); - } - m_voidDependency = true; - break; - - case UnoType::SORT_BOOLEAN: - if (!args.empty()) { - throw Bad(); - } - m_booleanDependency = true; - break; - - case UnoType::SORT_BYTE: - if (!args.empty()) { - throw Bad(); - } - m_byteDependency = true; - break; - - case UnoType::SORT_SHORT: - if (!args.empty()) { - throw Bad(); - } - m_shortDependency = true; - break; - - case UnoType::SORT_UNSIGNED_SHORT: - if (!args.empty()) { - throw Bad(); - } - m_unsignedShortDependency = true; - break; - - case UnoType::SORT_LONG: - if (!args.empty()) { - throw Bad(); - } - m_longDependency = true; - break; - - case UnoType::SORT_UNSIGNED_LONG: - if (!args.empty()) { - throw Bad(); - } - m_unsignedLongDependency = true; - break; - - case UnoType::SORT_HYPER: - if (!args.empty()) { - throw Bad(); - } - m_hyperDependency = true; - break; - - case UnoType::SORT_UNSIGNED_HYPER: - if (!args.empty()) { - throw Bad(); - } - m_unsignedHyperDependency = true; - break; - - case UnoType::SORT_FLOAT: - if (!args.empty()) { - throw Bad(); - } - m_floatDependency = true; - break; - - case UnoType::SORT_DOUBLE: - if (!args.empty()) { - throw Bad(); - } - m_doubleDependency = true; - break; - - case UnoType::SORT_CHAR: - if (!args.empty()) { - throw Bad(); - } - m_charDependency = true; - break; - - case UnoType::SORT_STRING: - if (!args.empty()) { - throw Bad(); - } - m_stringDependency = true; - break; - - case UnoType::SORT_TYPE: - if (!args.empty()) { - throw Bad(); - } - m_typeDependency = true; - break; - - case UnoType::SORT_ANY: - if (!args.empty()) { - throw Bad(); - } - m_anyDependency = true; - break; - - case UnoType::SORT_COMPLEX: - { - for (std::vector< OString >::iterator i(args.begin()); - i != args.end(); ++i) - { - insert(*i, false); - } - Map::iterator i(m_map.find(t)); - if (i == m_map.end()) { - m_map.insert( - Map::value_type(t, base ? KIND_BASE : KIND_NO_BASE)); - } else if (base) { - i->second = KIND_BASE; - } - break; - } - - default: - OSL_ASSERT(false); - break; - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/codemaker/source/codemaker/exceptiontree.cxx b/codemaker/source/codemaker/exceptiontree.cxx index 1b4915b65224..f8dd868f9180 100644 --- a/codemaker/source/codemaker/exceptiontree.cxx +++ b/codemaker/source/codemaker/exceptiontree.cxx @@ -22,11 +22,11 @@ #include "codemaker/typemanager.hxx" #include "osl/diagnose.h" -#include "registry/reader.hxx" -#include "registry/types.h" +#include "rtl/ref.hxx" #include "rtl/string.hxx" #include "rtl/textenc.h" #include "rtl/ustring.hxx" +#include "unoidl/unoidl.hxx" #include <memory> #include <vector> @@ -34,7 +34,7 @@ using codemaker::ExceptionTree; using codemaker::ExceptionTreeNode; -ExceptionTreeNode * ExceptionTreeNode::add(OString const & theName) { +ExceptionTreeNode * ExceptionTreeNode::add(rtl::OString const & theName) { std::auto_ptr< ExceptionTreeNode > node(new ExceptionTreeNode(theName)); children.push_back(node.get()); return node.release(); @@ -48,34 +48,30 @@ void ExceptionTreeNode::clearChildren() { } void ExceptionTree::add( - OString const & name, rtl::Reference< TypeManager > const & manager) - throw( CannotDumpException ) + rtl::OString const & name, rtl::Reference< TypeManager > const & manager) { - typedef std::vector< OString > OStringList; - OStringList stringlist; + std::vector< rtl::OString > list; bool runtimeException = false; - for (OString n(name); n != "com/sun/star/uno/Exception";) { - if (n == "com/sun/star/uno/RuntimeException") { + for (rtl::OString n(name); n != "com.sun.star.uno.Exception";) { + if (n == "com.sun.star.uno.RuntimeException") { runtimeException = true; break; } - stringlist.push_back(n); - typereg::Reader reader(manager->getTypeReader(n)); - if (!reader.isValid()) - throw CannotDumpException( - OString("Unknown type '" + n.replace('/', '.') - + "', incomplete type library.")); - - OSL_ASSERT( - reader.getTypeClass() == RT_TYPE_EXCEPTION - && reader.getSuperTypeCount() == 1); - n = OUStringToOString( - reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8); + list.push_back(n); + rtl::Reference< unoidl::Entity > ent; + codemaker::UnoType::Sort s = manager->getSort(b2u(n), &ent); + assert(s == codemaker::UnoType::SORT_EXCEPTION_TYPE); + n = u2b( + static_cast< unoidl::ExceptionTypeEntity * >(ent.get())-> + getDirectBase()); + assert(!n.isEmpty()); } if (!runtimeException) { ExceptionTreeNode * node = &m_root; - for (OStringList::reverse_iterator i(stringlist.rbegin()); !node->present; ++i) { - if (i == stringlist.rend()) { + for (std::vector< rtl::OString >::reverse_iterator i(list.rbegin()); + !node->present; ++i) + { + if (i == list.rend()) { node->setPresent(); break; } diff --git a/codemaker/source/codemaker/global.cxx b/codemaker/source/codemaker/global.cxx index 2630ee8b81ce..34c43a9a2459 100644 --- a/codemaker/source/codemaker/global.cxx +++ b/codemaker/source/codemaker/global.cxx @@ -68,7 +68,7 @@ OString createFileNameFromType( const OString& destination, sal_Bool bLowerCase, const OString prefix ) { - OString type(typeName); + OString type(typeName.replace('.', '/')); if (bLowerCase) { @@ -364,27 +364,33 @@ FileStream &operator<<(FileStream& o, char const * s) { osl_writeFile(o.m_file, s, strlen(s), &writtenBytes); return o; } -FileStream &operator<<(FileStream& o, OString* s) { +FileStream &operator<<(FileStream& o, ::rtl::OString* s) { sal_uInt64 writtenBytes; osl_writeFile(o.m_file, s->getStr(), s->getLength() * sizeof(sal_Char), &writtenBytes); return o; } -FileStream &operator<<(FileStream& o, const OString& s) { +FileStream &operator<<(FileStream& o, const ::rtl::OString& s) { sal_uInt64 writtenBytes; osl_writeFile(o.m_file, s.getStr(), s.getLength() * sizeof(sal_Char), &writtenBytes); return o; } -FileStream &operator<<(FileStream& o, OStringBuffer* s) { +FileStream &operator<<(FileStream& o, ::rtl::OStringBuffer* s) { sal_uInt64 writtenBytes; osl_writeFile(o.m_file, s->getStr(), s->getLength() * sizeof(sal_Char), &writtenBytes); return o; } -FileStream &operator<<(FileStream& o, const OStringBuffer& s) { +FileStream &operator<<(FileStream& o, const ::rtl::OStringBuffer& s) { sal_uInt64 writtenBytes; osl_writeFile( o.m_file, s.getStr(), s.getLength() * sizeof(sal_Char), &writtenBytes); return o; } +FileStream & operator <<(FileStream & out, rtl::OUString const & s) { + return out << OUStringToOString(s, RTL_TEXTENCODING_UTF8); +} + +CannotDumpException::~CannotDumpException() throw () {} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/codemaker/source/codemaker/options.cxx b/codemaker/source/codemaker/options.cxx index d233f6ff0bfc..328cc9ceb81c 100644 --- a/codemaker/source/codemaker/options.cxx +++ b/codemaker/source/codemaker/options.cxx @@ -20,6 +20,7 @@ #include "codemaker/options.hxx" +using ::rtl::OString; Options::Options() { @@ -35,21 +36,19 @@ const OString& Options::getProgramName() const return m_program; } -sal_Bool Options::isValid(const OString& option) +sal_Bool Options::isValid(const OString& option) const { - return (m_options.count(option) > 0); + return m_options.find(option) != m_options.end(); } -const OString Options::getOption(const OString& option) +const OString Options::getOption(const OString& option) const throw( IllegalArgument ) { - if (m_options.count(option) > 0) - { - return m_options[option]; - } else - { + OptionMap::const_iterator i(m_options.find(option)); + if (i == m_options.end()) { throw IllegalArgument("Option is not valid or currently not set."); } + return i->second; } const StringVector& Options::getInputFiles() diff --git a/codemaker/source/codemaker/typemanager.cxx b/codemaker/source/codemaker/typemanager.cxx index 9d4cf63f58f5..1c9a5ca67764 100644 --- a/codemaker/source/codemaker/typemanager.cxx +++ b/codemaker/source/codemaker/typemanager.cxx @@ -17,50 +17,22 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include "sal/config.h" + +#include <cstdlib> #include "rtl/alloc.h" #include "codemaker/typemanager.hxx" #include "registry/reader.hxx" #include "registry/version.h" +#include "unoidl/unoidl.hxx" +using ::rtl::OUString; +using ::rtl::OString; +using ::rtl::OStringToOUString; +using ::rtl::OUStringToOString; -sal_Bool TypeManager::isBaseType(const OString& name) -{ - if ( name == "short" ) - return sal_True; - if ( name == "unsigned short" ) - return sal_True; - if ( name == "long" ) - return sal_True; - if ( name == "unsigned long" ) - return sal_True; - if ( name == "hyper" ) - return sal_True; - if ( name == "unsigned hyper" ) - return sal_True; - if ( name == "string" ) - return sal_True; - if ( name == "boolean" ) - return sal_True; - if ( name == "char" ) - return sal_True; - if ( name == "byte" ) - return sal_True; - if ( name == "any" ) - return sal_True; - if ( name == "type" ) - return sal_True; - if ( name == "float" ) - return sal_True; - if ( name == "double" ) - return sal_True; - if ( name == "void" ) - return sal_True; - - return sal_False; -} - -TypeManager::TypeManager() {} +TypeManager::TypeManager(): m_base("UCR"), manager_(new unoidl::Manager) {} TypeManager::~TypeManager() { @@ -104,7 +76,7 @@ sal_Bool TypeManager::init( return sal_True; } -OString TypeManager::getTypeName(RegistryKey& rTypeKey) const +::rtl::OString TypeManager::getTypeName(RegistryKey& rTypeKey) const { OString typeName = OUStringToOString(rTypeKey.getName(), RTL_TEXTENCODING_UTF8); @@ -243,9 +215,9 @@ void TypeManager::setBase(const OString& base) { if (base.lastIndexOf('/') == (base.getLength() - 1)) - m_base += base.copy(0, base.lastIndexOf('/') - 1); + m_base = base.copy(0, base.lastIndexOf('/') - 1); else - m_base += base; + m_base = base; } void TypeManager::freeRegistries() @@ -302,7 +274,7 @@ RegistryKey TypeManager::searchTypeKey(const OString& name_, sal_Bool * pIsExtra return key; } -RegistryKeyList TypeManager::getTypeKeys(const OString& name_) const +RegistryKeyList TypeManager::getTypeKeys(const ::rtl::OString& name_) const { RegistryKeyList keyList= RegistryKeyList(); OString tmpName; @@ -346,4 +318,130 @@ RegistryKeyList TypeManager::getTypeKeys(const OString& name_) const return keyList; } + +void TypeManager::loadProvider(rtl::OUString const & uri, bool primary) { + rtl::Reference< unoidl::Provider > prov( + unoidl::loadProvider(manager_, uri)); + manager_->addProvider(prov); + if (primary) { + primaryProviders_.push_back(prov); + } +} + +bool TypeManager::foundAtPrimaryProvider(rtl::OUString const & name) const { + if (name.isEmpty()) { + return !primaryProviders_.empty(); + } + for (std::vector< rtl::Reference< unoidl::Provider > >::const_iterator i( + primaryProviders_.begin()); + i != primaryProviders_.end(); ++i) + { + if ((*i)->findEntity(name).is()) { + return true; + } + } + return false; +} + +codemaker::UnoType::Sort TypeManager::getSort( + rtl::OUString const & name, rtl::Reference< unoidl::Entity > * entity, + rtl::Reference< unoidl::MapCursor > * cursor) const +{ + if (name.isEmpty()) { + if (cursor != 0) { + *cursor = manager_->createCursor(""); + } + return codemaker::UnoType::SORT_MODULE; + } + if (name == "void") { + return codemaker::UnoType::SORT_VOID; + } + if (name == "boolean") { + return codemaker::UnoType::SORT_BOOLEAN; + } + if (name == "byte") { + return codemaker::UnoType::SORT_BYTE; + } + if (name == "short") { + return codemaker::UnoType::SORT_SHORT; + } + if (name == "unsigned short") { + return codemaker::UnoType::SORT_UNSIGNED_SHORT; + } + if (name == "long") { + return codemaker::UnoType::SORT_LONG; + } + if (name == "unsigned long") { + return codemaker::UnoType::SORT_UNSIGNED_LONG; + } + if (name == "hyper") { + return codemaker::UnoType::SORT_HYPER; + } + if (name == "unsigned hyper") { + return codemaker::UnoType::SORT_UNSIGNED_HYPER; + } + if (name == "float") { + return codemaker::UnoType::SORT_FLOAT; + } + if (name == "double") { + return codemaker::UnoType::SORT_DOUBLE; + } + if (name == "char") { + return codemaker::UnoType::SORT_CHAR; + } + if (name == "string") { + return codemaker::UnoType::SORT_STRING; + } + if (name == "type") { + return codemaker::UnoType::SORT_TYPE; + } + if (name == "any") { + return codemaker::UnoType::SORT_ANY; + } + if (name.startsWith("[")) { + return codemaker::UnoType::SORT_SEQUENCE_TYPE; + } + if (name.indexOf('<') != -1) { + return codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE; + } + rtl::Reference< unoidl::Entity > ent(manager_->findEntity(name)); + if (!ent.is()) { + throw CannotDumpException("Unknown entity '" + name + "'"); + } + if (entity != 0) { + *entity = ent; + } + switch (ent->getSort()) { + case unoidl::Entity::SORT_MODULE: + if (cursor != 0) { + *cursor = manager_->createCursor(name); + } + return codemaker::UnoType::SORT_MODULE; + case unoidl::Entity::SORT_ENUM_TYPE: + return codemaker::UnoType::SORT_ENUM_TYPE; + case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE: + return codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE; + case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE: + return codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE; + case unoidl::Entity::SORT_EXCEPTION_TYPE: + return codemaker::UnoType::SORT_EXCEPTION_TYPE; + case unoidl::Entity::SORT_INTERFACE_TYPE: + return codemaker::UnoType::SORT_INTERFACE_TYPE; + case unoidl::Entity::SORT_TYPEDEF: + return codemaker::UnoType::SORT_TYPEDEF; + case unoidl::Entity::SORT_CONSTANT_GROUP: + return codemaker::UnoType::SORT_CONSTANT_GROUP; + case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE: + return codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE; + case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE: + return codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE; + case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON: + return codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON; + case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON: + return codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON; + default: + for (;;) { std::abort(); } // this cannot happen + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/codemaker/source/codemaker/unotype.cxx b/codemaker/source/codemaker/unotype.cxx index 8f2c89537c77..a0872ea33a37 100644 --- a/codemaker/source/codemaker/unotype.cxx +++ b/codemaker/source/codemaker/unotype.cxx @@ -46,10 +46,6 @@ codemaker::UnoType::Sort codemaker::UnoType::getSort(OString const & type) : SORT_COMPLEX; } -bool codemaker::UnoType::isSequenceType(OString const & type) { - return !type.isEmpty() && type[0] == '['; -} - OString codemaker::UnoType::decompose( OString const & type, sal_Int32 * rank, std::vector< OString > * arguments) diff --git a/codemaker/source/cppumaker/cppumaker.cxx b/codemaker/source/cppumaker/cppumaker.cxx index 1f63ef26b5b2..8869e87df4d6 100644 --- a/codemaker/source/cppumaker/cppumaker.cxx +++ b/codemaker/source/cppumaker/cppumaker.cxx @@ -17,221 +17,87 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include "sal/config.h" -#include <stdio.h> +#include <cstdlib> +#include <cstring> +#include <iostream> +#include <vector> +#include "codemaker/generatedtypeset.hxx" +#include "codemaker/typemanager.hxx" #include "rtl/ref.hxx" +#include "rtl/string.hxx" +#include "rtl/ustring.hxx" #include "sal/main.h" - -#include "codemaker/typemanager.hxx" -#include "codemaker/generatedtypeset.hxx" +#include "sal/types.h" +#include "unoidl/unoidl.hxx" #include "cppuoptions.hxx" #include "cpputype.hxx" - -namespace { - -void failed(OString const & typeName, CppuOptions * options) { - fprintf(stderr, "%s ERROR: %s\n", options->getProgramName().getStr(), - OString("cannot dump Type '" + typeName + "'").getStr()); - exit(99); -} - -void produce( - RegistryKey& rTypeKey, bool bIsExtraType, - rtl::Reference< TypeManager > const & typeMgr, - codemaker::GeneratedTypeSet & generated, CppuOptions * options) -{ - if (!produceType(rTypeKey, bIsExtraType, typeMgr, generated, options)) { - OString typeName = typeMgr->getTypeName(rTypeKey); - failed(typeName, options); - } -} - -void produce( - OString const & typeName, - rtl::Reference< TypeManager > const & typeMgr, - codemaker::GeneratedTypeSet & generated, CppuOptions * options) -{ - if (!produceType(typeName, typeMgr, generated, options)) { - failed(typeName, options); - } -} - -void produceAllTypes(RegistryKey& rTypeKey, bool bIsExtraType, - rtl::Reference< TypeManager > const & typeMgr, - codemaker::GeneratedTypeSet & generated, - CppuOptions* pOptions, - sal_Bool bFullScope) - throw( CannotDumpException ) -{ - OString typeName = typeMgr->getTypeName(rTypeKey); - - produce(rTypeKey, bIsExtraType, typeMgr, generated, pOptions); - - RegistryKeyList typeKeys = typeMgr->getTypeKeys(typeName); - RegistryKeyList::const_iterator iter = typeKeys.begin(); - RegistryKey key, subKey; - RegistryKeyArray subKeys; - - while (iter != typeKeys.end()) - { - key = (*iter).first; - - if (!(*iter).second && !key.openSubKeys(OUString(), subKeys)) - { - for (sal_uInt32 i = 0; i < subKeys.getLength(); i++) - { - subKey = subKeys.getElement(i); - if (bFullScope) - { - produceAllTypes(subKey, (*iter).second, typeMgr, - generated, pOptions, true); - } else - { - produce(subKey, (*iter).second, - typeMgr, generated, pOptions); - } - } +SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { + CppuOptions options; + try { + if (!options.initOptions(argc, argv)) { + return EXIT_FAILURE; } - - ++iter; + } catch (IllegalArgument & e) { + std::cerr << "Illegal option " << e.m_message << '\n'; + return EXIT_FAILURE; } -} - -void produceAllTypes(const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr, - codemaker::GeneratedTypeSet & generated, - CppuOptions* pOptions, - sal_Bool bFullScope) - throw( CannotDumpException ) -{ - produce(typeName, typeMgr, generated, pOptions); - - RegistryKeyList typeKeys = typeMgr->getTypeKeys(typeName); - RegistryKeyList::const_iterator iter = typeKeys.begin(); - RegistryKey key, subKey; - RegistryKeyArray subKeys; - - while (iter != typeKeys.end()) - { - key = (*iter).first; - if (!(*iter).second && !key.openSubKeys(OUString(), subKeys)) + try { + rtl::Reference< TypeManager > typeMgr(new TypeManager); + for (std::vector< OString >::const_iterator i( + options.getExtraInputFiles().begin()); + i != options.getExtraInputFiles().end(); ++i) { - for (sal_uInt32 i = 0; i < subKeys.getLength(); i++) - { - subKey = subKeys.getElement(i); - if (bFullScope) - { - produceAllTypes(subKey, (*iter).second, typeMgr, - generated, pOptions, true); - } else - { - produce(subKey, (*iter).second, - typeMgr, generated, pOptions); - } - } + typeMgr->loadProvider(b2u(*i), false); } - - ++iter; - } -} - -} - -SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) -{ - CppuOptions options; - - try - { - if (!options.initOptions(argc, argv)) + for (std::vector< OString >::const_iterator i( + options.getInputFiles().begin()); + i != options.getInputFiles().end(); ++i) { - exit(1); + typeMgr->loadProvider(b2u(*i), true); } - } - catch( IllegalArgument& e) - { - fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr()); - exit(99); - } - - rtl::Reference< TypeManager > typeMgr(new TypeManager); - - if (!typeMgr->init(options.getInputFiles(), options.getExtraInputFiles())) - { - fprintf(stderr, "%s : init registries failed, check your registry files.\n", options.getProgramName().getStr()); - exit(99); - } - - if (options.isValid("-B")) - { - typeMgr->setBase(options.getOption("-B")); - } - - codemaker::GeneratedTypeSet generated; - try - { - if (options.isValid("-T")) - { - OString tOption(options.getOption("-T")); - - OString typeName, tmpName; - sal_Int32 nIndex = 0; - do - { - typeName = tOption.getToken(0, ';', nIndex); - - sal_Int32 nPos = typeName.lastIndexOf( '.' ); - tmpName = typeName.copy( nPos != -1 ? nPos+1 : 0 ); - if (tmpName == "*") - { - // produce this type and his scope - if (typeName == "*") - { - tmpName = "/"; - } else - { - tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/'); - if (tmpName.isEmpty()) - tmpName = "/"; - else - tmpName = tmpName.replace('.', '/'); - } - // related to task #116780# the scope is recursively - // generated. bFullScope = true - produceAllTypes( - tmpName, typeMgr, generated, &options, true); - } else - { - // produce only this type + codemaker::GeneratedTypeSet generated; + if (options.isValid("-T")) { + OUString names(b2u(options.getOption("-T"))); + for (sal_Int32 i = 0; i != -1;) { + OUString name(names.getToken(0, ';', i)); + if (!name.isEmpty()) { produce( - typeName.replace('.', '/'), typeMgr, generated, &options); + (name == "*" + ? "" + : name.endsWith(".*") + ? name.copy(0, name.getLength() - std::strlen(".*")) + : name), + typeMgr, generated, options); } - } while( nIndex != -1 ); - } else - { - // produce all types - produceAllTypes("/", typeMgr, generated, &options, true); + } + } else { + produce("", typeMgr, generated, options); } // C++ header files generated for the following UNO types are included // in header files in cppu/inc/com/sun/star/uno (Any.hxx, Reference.hxx, // Type.h), so it seems best to always generate those C++ header files: - produce("com/sun/star/uno/RuntimeException", typeMgr, generated, &options); - produce("com/sun/star/uno/TypeClass", typeMgr, generated, &options); - produce("com/sun/star/uno/XInterface", typeMgr, generated, &options); + produce( + "com.sun.star.uno.RuntimeException", typeMgr, generated, options); + produce("com.sun.star.uno.TypeClass", typeMgr, generated, options); + produce("com.sun.star.uno.XInterface", typeMgr, generated, options); + } catch (CannotDumpException & e) { + std::cerr << "ERROR: " << e.getMessage() << '\n'; + return EXIT_FAILURE; + } catch (unoidl::NoSuchFileException & e) { + std::cerr << "ERROR: No such file <" << e.getUri() << ">\n"; + return EXIT_FAILURE; + } catch (unoidl::FileFormatException & e) { + std::cerr + << "ERROR: Bad format of <" << e.getUri() << ">, \"" + << e.getDetail() << "\"\n"; + return EXIT_FAILURE; } - catch( CannotDumpException& e) - { - fprintf(stderr, "%s ERROR: %s\n", - options.getProgramName().getStr(), - e.m_message.getStr()); - exit(99); - } - - return 0; + return EXIT_SUCCESS; } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/codemaker/source/cppumaker/cppuoptions.cxx b/codemaker/source/cppumaker/cppuoptions.cxx index 8affab24dd56..3446134ab5d2 100644 --- a/codemaker/source/cppumaker/cppuoptions.cxx +++ b/codemaker/source/cppumaker/cppuoptions.cxx @@ -24,6 +24,9 @@ #include "osl/thread.h" #include "osl/process.h" +using ::rtl::OUString; +using ::rtl::OUStringToOString; +using ::rtl::OString; #ifdef SAL_UNX #define SEPARATOR '/' @@ -91,32 +94,6 @@ sal_Bool CppuOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile) m_options["-O"] = OString(s); break; - case 'B': - if (av[i][2] == '\0') - { - if (i < ac - 1 && av[i+1][0] != '-') - { - i++; - s = av[i]; - } - else - { - OString tmp("'-B', please check"); - if (i <= ac - 1) - { - tmp += " your input '" + OString(av[i+1]) + "'"; - } - - throw IllegalArgument(tmp); - } - } - else - { - s = av[i] + 2; - } - - m_options["-B"] = OString(s); - break; case 'T': if (av[i][2] == '\0') { @@ -337,8 +314,6 @@ OString CppuOptions::prepareHelp() help += " [t1;...] type is generated. If no '-T' option is specified,\n"; help += " then output for all types is generated.\n"; help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"; - help += " -B<name> = name specifies the base node. All types are searched under this\n"; - help += " node. Default is the root '/' of the registry files.\n"; help += " -L = UNO type functions are generated lightweight, that means only\n"; help += " the name and typeclass are given and everything else is retrieved\n"; help += " from the type library dynamically. The default is that UNO type\n"; diff --git a/codemaker/source/cppumaker/cpputype.cxx b/codemaker/source/cppumaker/cpputype.cxx index 4f90a53139e3..511cffb73308 100644..100755 --- a/codemaker/source/cppumaker/cpputype.cxx +++ b/codemaker/source/cppumaker/cpputype.cxx @@ -17,159 +17,236 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include "sal/config.h" #include <algorithm> +#include <cassert> #include <map> #include <set> -#include <stdio.h> -#include <string.h> #include <vector> -#include "registry/reader.hxx" +#include "boost/noncopyable.hpp" #include "rtl/alloc.h" #include "rtl/ref.hxx" +#include "rtl/ustrbuf.hxx" #include "rtl/ustring.hxx" #include "rtl/strbuf.hxx" +#include "unoidl/unoidl.hxx" -#include "codemaker/dependencies.hxx" +#include "codemaker/commoncpp.hxx" #include "codemaker/exceptiontree.hxx" #include "codemaker/generatedtypeset.hxx" +#include "codemaker/typemanager.hxx" #include "codemaker/unotype.hxx" #include "cpputype.hxx" #include "cppuoptions.hxx" +#include "dependencies.hxx" #include "dumputils.hxx" #include "includes.hxx" -using namespace codemaker::cpp; - - namespace { -OString translateSimpleUnoType(OString const & unoType, bool cppuUnoType=false) { - static OString const trans[codemaker::UnoType::SORT_COMPLEX + 1] = { - "void", "::sal_Bool", "::sal_Int8", "::sal_Int16", "::sal_uInt16", - "::sal_Int32", "::sal_uInt32", "::sal_Int64", "::sal_uInt64", "float", - "double", "::sal_Unicode", "rtl::OUString", - "::com::sun::star::uno::Type", "::com::sun::star::uno::Any", - OString() }; - - const codemaker::UnoType::Sort sort = codemaker::UnoType::getSort(unoType); - if (cppuUnoType && - (sort == codemaker::UnoType::SORT_UNSIGNED_SHORT || - sort == codemaker::UnoType::SORT_CHAR) ) - { - if (sort == codemaker::UnoType::SORT_CHAR) - return "::cppu::UnoCharType"; - else - return "::cppu::UnoUnsignedShortType"; - } - - return trans[sort]; -} - -bool isBootstrapType(OString const & name) { +bool isBootstrapType(OUString const & name) { static char const * const names[] = { - "com/sun/star/beans/PropertyAttribute", - "com/sun/star/beans/PropertyState", - "com/sun/star/beans/PropertyValue", - "com/sun/star/beans/XFastPropertySet", - "com/sun/star/beans/XMultiPropertySet", - "com/sun/star/beans/XPropertyAccess", - "com/sun/star/beans/XPropertySet", - "com/sun/star/beans/XPropertySetOption", - "com/sun/star/bridge/UnoUrlResolver", - "com/sun/star/bridge/XUnoUrlResolver", - "com/sun/star/connection/SocketPermission", - "com/sun/star/container/XElementAccess", - "com/sun/star/container/XEnumerationAccess", - "com/sun/star/container/XHierarchicalNameAccess", - "com/sun/star/container/XNameAccess", - "com/sun/star/container/XNameContainer", - "com/sun/star/container/XNameReplace", - "com/sun/star/container/XSet", - "com/sun/star/io/FilePermission", - "com/sun/star/io/IOException", - "com/sun/star/lang/DisposedException", - "com/sun/star/lang/WrappedTargetRuntimeException", - "com/sun/star/lang/XComponent", - "com/sun/star/lang/XEventListener", - "com/sun/star/lang/XInitialization", - "com/sun/star/lang/XMultiComponentFactory", - "com/sun/star/lang/XMultiServiceFactory", - "com/sun/star/lang/XServiceInfo", - "com/sun/star/lang/XSingleComponentFactory", - "com/sun/star/lang/XSingleServiceFactory", - "com/sun/star/lang/XTypeProvider", - "com/sun/star/loader/XImplementationLoader", - "com/sun/star/reflection/XArrayTypeDescription", - "com/sun/star/reflection/XCompoundTypeDescription", - "com/sun/star/reflection/XEnumTypeDescription", - "com/sun/star/reflection/XIdlClass", - "com/sun/star/reflection/XIdlField2", - "com/sun/star/reflection/XIdlReflection", - "com/sun/star/reflection/XIndirectTypeDescription", - "com/sun/star/reflection/XInterfaceAttributeTypeDescription", - "com/sun/star/reflection/XInterfaceAttributeTypeDescription2", - "com/sun/star/reflection/XInterfaceMemberTypeDescription", - "com/sun/star/reflection/XInterfaceMethodTypeDescription", - "com/sun/star/reflection/XInterfaceTypeDescription", - "com/sun/star/reflection/XInterfaceTypeDescription2", - "com/sun/star/reflection/XMethodParameter", - "com/sun/star/reflection/XStructTypeDescription", - "com/sun/star/reflection/XTypeDescription", - "com/sun/star/reflection/XTypeDescriptionEnumerationAccess", - "com/sun/star/reflection/XUnionTypeDescription", - "com/sun/star/registry/XImplementationRegistration", - "com/sun/star/registry/XRegistryKey", - "com/sun/star/registry/XSimpleRegistry", - "com/sun/star/security/RuntimePermission", - "com/sun/star/security/XAccessController", - "com/sun/star/uno/DeploymentException", - "com/sun/star/uno/RuntimeException", - "com/sun/star/uno/XAggregation", - "com/sun/star/uno/XComponentContext", - "com/sun/star/uno/XCurrentContext", - "com/sun/star/uno/XUnloadingPreference", - "com/sun/star/uno/XWeak", - "com/sun/star/util/XMacroExpander" - }; // cf. cppuhelper/unotypes/Makefile UNOTYPES (plus missing dependencies) + "com.sun.star.beans.PropertyAttribute", + "com.sun.star.beans.PropertyState", + "com.sun.star.beans.PropertyValue", + "com.sun.star.beans.XFastPropertySet", + "com.sun.star.beans.XMultiPropertySet", + "com.sun.star.beans.XPropertyAccess", + "com.sun.star.beans.XPropertySet", + "com.sun.star.beans.XPropertySetOption", + "com.sun.star.bridge.UnoUrlResolver", + "com.sun.star.bridge.XUnoUrlResolver", + "com.sun.star.connection.SocketPermission", + "com.sun.star.container.XElementAccess", + "com.sun.star.container.XEnumerationAccess", + "com.sun.star.container.XHierarchicalNameAccess", + "com.sun.star.container.XNameAccess", + "com.sun.star.container.XNameContainer", + "com.sun.star.container.XNameReplace", + "com.sun.star.container.XSet", + "com.sun.star.io.FilePermission", + "com.sun.star.io.IOException", + "com.sun.star.lang.DisposedException", + "com.sun.star.lang.WrappedTargetRuntimeException", + "com.sun.star.lang.XComponent", + "com.sun.star.lang.XEventListener", + "com.sun.star.lang.XInitialization", + "com.sun.star.lang.XMultiComponentFactory", + "com.sun.star.lang.XMultiServiceFactory", + "com.sun.star.lang.XServiceInfo", + "com.sun.star.lang.XSingleComponentFactory", + "com.sun.star.lang.XSingleServiceFactory", + "com.sun.star.lang.XTypeProvider", + "com.sun.star.loader.XImplementationLoader", + "com.sun.star.reflection.XArrayTypeDescription", + "com.sun.star.reflection.XCompoundTypeDescription", + "com.sun.star.reflection.XEnumTypeDescription", + "com.sun.star.reflection.XIdlClass", + "com.sun.star.reflection.XIdlField2", + "com.sun.star.reflection.XIdlReflection", + "com.sun.star.reflection.XIndirectTypeDescription", + "com.sun.star.reflection.XInterfaceAttributeTypeDescription", + "com.sun.star.reflection.XInterfaceAttributeTypeDescription2", + "com.sun.star.reflection.XInterfaceMemberTypeDescription", + "com.sun.star.reflection.XInterfaceMethodTypeDescription", + "com.sun.star.reflection.XInterfaceTypeDescription", + "com.sun.star.reflection.XInterfaceTypeDescription2", + "com.sun.star.reflection.XMethodParameter", + "com.sun.star.reflection.XStructTypeDescription", + "com.sun.star.reflection.XTypeDescription", + "com.sun.star.reflection.XTypeDescriptionEnumerationAccess", + "com.sun.star.reflection.XUnionTypeDescription", + "com.sun.star.registry.XImplementationRegistration", + "com.sun.star.registry.XRegistryKey", + "com.sun.star.registry.XSimpleRegistry", + "com.sun.star.security.RuntimePermission", + "com.sun.star.security.XAccessController", + "com.sun.star.uno.DeploymentException", + "com.sun.star.uno.RuntimeException", + "com.sun.star.uno.XAggregation", + "com.sun.star.uno.XComponentContext", + "com.sun.star.uno.XCurrentContext", + "com.sun.star.uno.XUnloadingPreference", + "com.sun.star.uno.XWeak", + "com.sun.star.util.XMacroExpander" }; + // cf. cppuhelper/unotypes/Makefile UNOTYPES (plus missing dependencies) for (std::size_t i = 0; i < SAL_N_ELEMENTS(names); ++i) { - if (name == names[i]) { + if (name.equalsAscii(names[i])) { return true; } } return false; } -} +class CppuType: private boost::noncopyable { +public: + CppuType( + OUString const & name, rtl::Reference< TypeManager > const & typeMgr); + + virtual ~CppuType() {} + + void dump(CppuOptions const & options); + + void dumpFile( + OUString const & uri, OUString const & name, bool hpp, + CppuOptions const & options); + + void dumpDependedTypes( + codemaker::GeneratedTypeSet & generated, CppuOptions const & options); + + virtual void dumpHFile( + FileStream & out, codemaker::cppumaker::Includes & includes) + { dumpHFileContent(out, includes); } + + virtual void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) = 0; + + OUString dumpHeaderDefine(FileStream& o, OUString const & extension); + + void dumpGetCppuType(FileStream & out); + + virtual void dumpLightGetCppuType(FileStream & out); + + virtual void dumpNormalGetCppuType(FileStream &) + { assert(false); } // this cannot happen + + virtual void dumpComprehensiveGetCppuType(FileStream &) + { assert(false); } // this cannot happen + + void dumpType( + FileStream & out, OUString const & name, bool isConst = false, + bool isRef = false, bool native = false, bool cppuUnoType = false) + const; + + OUString getTypeClass(OUString const & name, bool cStyle = false); + + void dumpCppuGetType(FileStream & out, OUString const & name); + + sal_uInt32 getInheritedMemberCount(); + + void inc(sal_Int32 num=4); + void dec(sal_Int32 num=4); + OUString indent() const; +protected: + virtual sal_uInt32 checkInheritedMemberCount() const + { assert(false); return 0; } // this cannot happen -//************************************************************************* -// CppuType -//************************************************************************* -CppuType::CppuType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr) - : m_inheritedMemberCount(0) + bool passByReference(OUString const & name) const; + + OUString resolveOuterTypedefs(OUString const & name) const; + + OUString resolveAllTypedefs(OUString const & name) const; + + codemaker::cpp::IdentifierTranslationMode isGlobal() const; + + virtual void dumpDeclaration(FileStream &) + { assert(false); } // this cannot happen + + virtual void dumpFiles(OUString const & uri, CppuOptions const & options); + + virtual void addLightGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const; + + virtual void addNormalGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const; + + virtual void addComprehensiveGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const; + + virtual bool isPolymorphic() const; + + virtual void dumpTemplateHead(FileStream &) const {} + + virtual void dumpTemplateParameters(FileStream &) const {} + + void dumpGetCppuTypePreamble(FileStream & out); + + void dumpGetCppuTypePostamble(FileStream & out); + + void addDefaultHIncludes(codemaker::cppumaker::Includes & includes) const; + void addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes) const; + + void dumpInitializer( + FileStream & out, bool parameterized, OUString const & name) const; + + void dumpHFileContent( + FileStream & out, codemaker::cppumaker::Includes & includes); + +protected: + sal_uInt32 m_inheritedMemberCount; + + bool m_cppuTypeLeak; + bool m_cppuTypeDynamic; + sal_Int32 m_indentLength; + OUString name_; + OUString id_; + rtl::Reference< TypeManager > m_typeMgr; + codemaker::cppumaker::Dependencies m_dependencies; + +private: + void addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes) + const; +}; + +CppuType::CppuType( + OUString const & name, rtl::Reference< TypeManager > const & typeMgr): + m_inheritedMemberCount(0) , m_cppuTypeLeak(false) , m_cppuTypeDynamic(true) , m_indentLength(0) - , m_typeName(typeName) - , m_name(typeName.copy(typeName.lastIndexOf('/') + 1)) - , m_reader(typeReader) + , name_(name) + , id_(name_.copy(name_.lastIndexOf('.') + 1)) , m_typeMgr(typeMgr) - , m_dependencies(typeMgr, typeName) + , m_dependencies(typeMgr, name_) {} -CppuType::~CppuType() -{ - -} - void CppuType::addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes) const { - if (m_typeName == "com/sun/star/uno/XInterface" || m_typeName == "com/sun/star/uno/Exception") + if (name_ == "com.sun.star.uno.XInterface" + || name_ == "com.sun.star.uno.Exception") { includes.addType(); includes.addCppuUnotypeHxx(); @@ -185,13 +262,9 @@ void CppuType::addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes) } } -void CppuType::dumpDeclaration(FileStream &) throw (CannotDumpException) { - OSL_ASSERT(false); -} - -bool CppuType::dumpFiles(CppuOptions * options, OString const & outPath) { - return dumpFile(options, ".hdl", m_typeName, outPath) - && dumpFile(options, ".hpp", m_typeName, outPath); +void CppuType::dumpFiles(OUString const & uri, CppuOptions const & options) { + dumpFile(uri, name_, false, options); + dumpFile(uri, name_, true, options); } void CppuType::addLightGetCppuTypeIncludes( @@ -220,28 +293,24 @@ void CppuType::addComprehensiveGetCppuTypeIncludes( bool CppuType::isPolymorphic() const { return false; } -void CppuType::dumpTemplateHead(FileStream &) const {} - -void CppuType::dumpTemplateParameters(FileStream &) const {} - void CppuType::dumpGetCppuTypePreamble(FileStream & out) { if (isPolymorphic()) { out << "namespace cppu {\n\n"; dumpTemplateHead(out); out << "class UnoType< "; - dumpType(out, m_typeName); + dumpType(out, name_); dumpTemplateParameters(out); out << " > {\npublic:\n"; inc(); out << indent() << "static inline ::com::sun::star::uno::Type const & get() {\n"; } else { - if (codemaker::cppumaker::dumpNamespaceOpen(out, m_typeName, false)) { + if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) { out << "\n\n"; } out << ("inline ::com::sun::star::uno::Type const &" " cppu_detail_getUnoType(SAL_UNUSED_PARAMETER "); - dumpType(out, m_typeName, false, false, true); + dumpType(out, name_, false, false, true); out << " const *) {\n"; } inc(); @@ -257,162 +326,105 @@ void CppuType::dumpGetCppuTypePostamble(FileStream & out) { << "void operator =(UnoType); // not defined\n};\n\n}\n\n"; } else { out << "}\n\n"; - if (codemaker::cppumaker::dumpNamespaceClose(out, m_typeName, false)) { + if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) { out << "\n\n"; } } dumpTemplateHead(out); out << ("inline ::com::sun::star::uno::Type const & SAL_CALL" " getCppuType(SAL_UNUSED_PARAMETER "); - dumpType(out, m_typeName); + dumpType(out, name_); dumpTemplateParameters(out); out << " const *) SAL_THROW(()) {\n"; inc(); out << indent() << "return ::cppu::UnoType< "; - dumpType(out, m_typeName); + dumpType(out, name_); dumpTemplateParameters(out); out << " >::get();\n"; dec(); out << indent() << "}\n"; } -sal_Bool CppuType::dump(CppuOptions* pOptions) - throw( CannotDumpException ) -{ - if (!m_dependencies.isValid()) { - return false; - } - addSpecialDependencies(); - - if (isBootstrapType(m_typeName)) { +void CppuType::dump(CppuOptions const & options) { + if (isBootstrapType(name_)) { m_cppuTypeDynamic = false; } else { // -CS was used as an undocumented option to generate static getCppuType // functions; since the introduction of cppu::UnoType this no longer is // meaningful (getCppuType is just a forward to cppu::UnoType::get now), // and -CS is handled the same way as -C now: - if (pOptions->isValid("-L")) + if (options.isValid("-L")) m_cppuTypeLeak = true; - if (pOptions->isValid("-C") || pOptions->isValid("-CS")) + if (options.isValid("-C") || options.isValid("-CS")) m_cppuTypeDynamic = false; } - - OString outPath; - if (pOptions->isValid("-O")) - outPath = pOptions->getOption("-O"); - - return dumpFiles(pOptions, outPath); + dumpFiles( + options.isValid("-O") ? b2u(options.getOption("-O")) : "", options); } -sal_Bool CppuType::dumpFile(CppuOptions* pOptions, - const OString& sExtension, - const OString& sName, - const OString& sOutPath ) - throw( CannotDumpException ) +void CppuType::dumpFile( + OUString const & uri, OUString const & name, bool hpp, + CppuOptions const & options) { - sal_Bool ret = sal_False; - - OString sTmpExt(".tml"); - sal_Bool bHdl = sal_True; ; - if (sExtension == ".hpp") { - sTmpExt = ".tmp"; - bHdl = sal_False; + OUString fileUri( + b2u(createFileNameFromType( + u2b(uri), u2b(name), hpp ? ".hpp" : ".hdl"))); + if (fileUri.isEmpty()) { + throw CannotDumpException("empty target URI for entity " + name); } - - OString sFileName = createFileNameFromType(sOutPath, sName, sExtension); - if (sFileName.isEmpty()) - return sal_False; - - sal_Bool bFileExists = fileExists( sFileName ); - sal_Bool bFileCheck = sal_False; - - if ( bFileExists && pOptions->isValid("-G") ) - return sal_True; - - if ( bFileExists && pOptions->isValid("-Gc") ) - bFileCheck = sal_True; - - OString sTmpDir = getTempDir(sFileName); - FileStream oFile; - oFile.createTempFile(sTmpDir); - OString sTmpFileName; - - if(!oFile.isValid()) - { - OString message("cannot open "); - message += sFileName + " for writing"; - throw CannotDumpException(message); - } else - sTmpFileName = oFile.getName(); - - codemaker::cppumaker::Includes includes(m_typeMgr, m_dependencies, !bHdl); - if (bHdl) - ret = dumpHFile(oFile, includes); - else { - addGetCppuTypeIncludes(includes); - ret = dumpHxxFile(oFile, includes); + bool exists = fileExists(u2b(fileUri)); + if (exists && options.isValid("-G")) { + return; } - - oFile.close(); - - if (ret) { - ret = makeValidTypeFile(sFileName, sTmpFileName, bFileCheck); - } else { - // remove existing type file if something goes wrong to ensure consistency - if (fileExists(sFileName)) - removeTypeFile(sFileName); - - // remove tmp file if something goes wrong - removeTypeFile(sTmpFileName); + FileStream out; + out.createTempFile(getTempDir(u2b(fileUri))); + OUString tmpUri(b2u(out.getName())); + if(!out.isValid()) { + throw CannotDumpException("cannot open " + tmpUri + " for writing"); } - - return ret; + codemaker::cppumaker::Includes includes(m_typeMgr, m_dependencies, hpp); + try { + if (hpp) { + addGetCppuTypeIncludes(includes); + dumpHxxFile(out, includes); + } else { + dumpHFile(out, includes); + } + } catch (...) { + out.close(); + // Remove existing type file if something goes wrong to ensure + // consistency: + if (fileExists(u2b(fileUri))) { + removeTypeFile(u2b(fileUri)); + } + removeTypeFile(u2b(tmpUri)); + throw; + } + out.close(); + makeValidTypeFile( + u2b(fileUri), u2b(tmpUri), exists && options.isValid("-Gc")); } void CppuType::dumpDependedTypes( - codemaker::GeneratedTypeSet & generated, CppuOptions * options) + codemaker::GeneratedTypeSet & generated, CppuOptions const & options) { - codemaker::Dependencies::Map const & map(m_dependencies.getMap()); - for (codemaker::Dependencies::Map::const_iterator i(map.begin()); + codemaker::cppumaker::Dependencies::Map const & map + = m_dependencies.getMap(); + for (codemaker::cppumaker::Dependencies::Map::const_iterator i(map.begin()); i != map.end(); ++i) { - if (!produceType(i->first, m_typeMgr, generated, options)) { - fprintf( - stderr, "%s ERROR: cannot dump Type '%s'\n", - options->getProgramName().getStr(), i->first.getStr()); - exit(99); - } + produce(i->first, m_typeMgr, generated, options); } } -OString CppuType::dumpHeaderDefine( - FileStream& o, char const * prefix, sal_Bool bExtended) +OUString CppuType::dumpHeaderDefine( + FileStream & out, OUString const & extension) { - if (m_typeName == "/") - { - bExtended = sal_False; - m_typeName = "global"; - } - - sal_uInt32 length = 3 + m_typeName.getLength() + strlen(prefix); - - if (bExtended) - length += m_name.getLength() + 1; - - OStringBuffer tmpBuf(length); - - tmpBuf.append("INCLUDED_" + m_typeName + "_"); - if (bExtended) - { - tmpBuf.append(m_name + "_"); - } - tmpBuf.append(prefix); - - OString tmp(tmpBuf.makeStringAndClear().replace('/', '_').toAsciiUpperCase()); - - o << "#ifndef " << tmp << "\n#define " << tmp << "\n"; - - return tmp; + OUString def( + "INCLUDED_" + name_.replace('.', '_').toAsciiUpperCase() + "_" + + extension); + out << "#ifndef " << def << "\n#define " << def << "\n"; + return def; } void CppuType::addDefaultHIncludes(codemaker::cppumaker::Includes & includes) @@ -420,7 +432,9 @@ void CppuType::addDefaultHIncludes(codemaker::cppumaker::Includes & includes) { //TODO: Only include what is really needed includes.addCppuMacrosHxx(); - if (m_typeMgr->getTypeClass(m_typeName) == RT_TYPE_INTERFACE) { + if (m_typeMgr->getSort(name_) + == codemaker::UnoType::SORT_INTERFACE_TYPE) + { includes.addReference(); } } @@ -432,68 +446,58 @@ void CppuType::addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes) includes.addRtlInstanceHxx(); includes.addOslMutexHxx(); includes.addType(); - if (m_typeMgr->getTypeClass(m_typeName) == RT_TYPE_INTERFACE) { + if (m_typeMgr->getSort(name_) + == codemaker::UnoType::SORT_INTERFACE_TYPE) + { includes.addReference(); } } void CppuType::dumpInitializer( - FileStream & out, bool parameterized, OUString const & type) const + FileStream & out, bool parameterized, OUString const & name) const { out << "("; if (!parameterized) { - for (OString t( - OUStringToOString(type, RTL_TEXTENCODING_UTF8));;) - { - sal_Int32 rank; - std::vector< OString > args; - t = codemaker::UnoType::decompose(t, &rank, &args); - if (rank == 0) { - switch (codemaker::UnoType::getSort(t)) { - case codemaker::UnoType::SORT_BOOLEAN: - out << "false"; - break; - - case codemaker::UnoType::SORT_BYTE: - case codemaker::UnoType::SORT_SHORT: - case codemaker::UnoType::SORT_UNSIGNED_SHORT: - case codemaker::UnoType::SORT_LONG: - case codemaker::UnoType::SORT_UNSIGNED_LONG: - case codemaker::UnoType::SORT_HYPER: - case codemaker::UnoType::SORT_UNSIGNED_HYPER: - case codemaker::UnoType::SORT_FLOAT: - case codemaker::UnoType::SORT_DOUBLE: - case codemaker::UnoType::SORT_CHAR: - out << "0"; - break; - - case codemaker::UnoType::SORT_COMPLEX: - switch (m_typeMgr->getTypeClass(t)) { - case RT_TYPE_ENUM: - { - typereg::Reader reader(m_typeMgr->getTypeReader(t)); - OSL_ASSERT(reader.isValid()); - out << scopedCppName(t) << "_" - << OUStringToOString( - reader.getFieldName(0), - RTL_TEXTENCODING_UTF8); - break; - } - - case RT_TYPE_TYPEDEF: - t = resolveTypedefs(t); - continue; - - default: - break; - } - break; - - default: - break; - } + sal_Int32 k; + std::vector< OString > args; + OUString n( + b2u(codemaker::UnoType::decompose( + u2b(resolveAllTypedefs(name)), &k, &args))); + if (k == 0) { + rtl::Reference< unoidl::Entity > ent; + switch (m_typeMgr->getSort(n, &ent)) { + case codemaker::UnoType::SORT_BOOLEAN: + out << "false"; + break; + case codemaker::UnoType::SORT_BYTE: + case codemaker::UnoType::SORT_SHORT: + case codemaker::UnoType::SORT_UNSIGNED_SHORT: + case codemaker::UnoType::SORT_LONG: + case codemaker::UnoType::SORT_UNSIGNED_LONG: + case codemaker::UnoType::SORT_HYPER: + case codemaker::UnoType::SORT_UNSIGNED_HYPER: + case codemaker::UnoType::SORT_FLOAT: + case codemaker::UnoType::SORT_DOUBLE: + case codemaker::UnoType::SORT_CHAR: + out << "0"; + break; + case codemaker::UnoType::SORT_ENUM_TYPE: + out << codemaker::cpp::scopedCppName(u2b(n)) << "_" + << (dynamic_cast< unoidl::EnumTypeEntity * >(ent.get())-> + getMembers()[0].name); + break; + case codemaker::UnoType::SORT_STRING: + case codemaker::UnoType::SORT_TYPE: + case codemaker::UnoType::SORT_ANY: + case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE: + case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE: + case codemaker::UnoType::SORT_INTERFACE_TYPE: + break; + default: + throw CannotDumpException( + "unexpected type \"" + name + + "\" in call to CppuType::dumpInitializer"); } - break; } } out << ")"; @@ -508,37 +512,37 @@ void CppuType::dumpHFileContent( includes.dump(out, 0); out << ("\nnamespace com { namespace sun { namespace star { namespace uno" " { class Type; } } } }\n\n"); - if (codemaker::cppumaker::dumpNamespaceOpen(out, m_typeName, false)) { + if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) { out << "\n"; } dumpDeclaration(out); - if (!(m_typeName == "com/sun/star/uno/XInterface" || - m_typeName == "com/sun/star/uno/Exception" || - isPolymorphic())) + if (!(name_ == "com.sun.star.uno.XInterface" + || name_ == "com.sun.star.uno.Exception" + || isPolymorphic())) { out << "\n" << indent() << ("inline ::com::sun::star::uno::Type const &" " cppu_detail_getUnoType(SAL_UNUSED_PARAMETER "); - dumpType(out, m_typeName, false, false, true); + dumpType(out, name_, false, false, true); out << " const *);\n"; } - if (codemaker::cppumaker::dumpNamespaceClose(out, m_typeName, false)) { + if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) { out << "\n"; } out << "\n"; dumpTemplateHead(out); out << "inline ::com::sun::star::uno::Type const & SAL_CALL getCppuType("; - dumpType(out, m_typeName, true); + dumpType(out, name_, true); dumpTemplateParameters(out); out << " *) SAL_THROW(());\n\n#endif\n"; } void CppuType::dumpGetCppuType(FileStream & out) { - if (m_typeName == "com/sun/star/uno/XInterface") { + if (name_ == "com.sun.star.uno.XInterface") { out << indent() << ("inline ::com::sun::star::uno::Type const & SAL_CALL" " getCppuType(SAL_UNUSED_PARAMETER "); - dumpType(out, m_typeName, true, false); + dumpType(out, name_, true); out << " *) SAL_THROW(()) {\n"; inc(); out << indent() @@ -546,11 +550,11 @@ void CppuType::dumpGetCppuType(FileStream & out) { " >::get();\n"); dec(); out << indent() << "}\n"; - } else if (m_typeName == "com/sun/star/uno/Exception") { + } else if (name_ == "com.sun.star.uno.Exception") { out << indent() << ("inline ::com::sun::star::uno::Type const & SAL_CALL" " getCppuType(SAL_UNUSED_PARAMETER "); - dumpType(out, m_typeName, true, false); + dumpType(out, name_, true); out << " *) SAL_THROW(()) {\n"; inc(); out << indent() @@ -567,752 +571,331 @@ void CppuType::dumpGetCppuType(FileStream & out) { } } -void CppuType::dumpLightGetCppuType(FileStream& o) -{ - dumpGetCppuTypePreamble(o); - o << indent() - << "static typelib_TypeDescriptionReference * the_type = 0;\n"; - - o << indent() << "if ( !the_type )\n" << indent() << "{\n"; - inc(); - o << indent() << "typelib_static_type_init( &the_type, " - << getTypeClass(m_typeName, sal_True) << ", \"" << m_typeName.replace('/', '.') << "\" );\n"; - dec(); - o << indent() << "}\n"; - o << indent() - << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >(" - " &the_type );\n"); - dumpGetCppuTypePostamble(o); -} - -void CppuType::dumpNormalGetCppuType(FileStream& o) -{ - dumpGetCppuTypePreamble(o); - - o << indent() - << "static typelib_TypeDescriptionReference * the_type = 0;\n"; - - o << indent() << "if ( !the_type )\n" << indent() << "{\n"; - inc(); - - OString superType; - if (m_reader.getSuperTypeCount() >= 1) { - superType = OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8); - } - sal_Bool bIsBaseException = sal_False; - if (!superType.isEmpty()) - { - if ( superType == "com/sun/star/uno/Exception" ) - { - bIsBaseException = sal_True; - } else - { - o << indent() << "const ::com::sun::star::uno::Type& rBaseType = ::cppu::UnoType< "; - dumpType(o, superType, true, false, false, true); - o << " >::get();\n\n"; - } - } - - sal_uInt32 count = getMemberCount(); - if (count) - { - o << indent() << "typelib_TypeDescriptionReference * aMemberRefs[" << count << "];\n"; - - sal_uInt16 fieldCount = m_reader.getFieldCount(); - RTFieldAccess access = RT_ACCESS_INVALID; - OString fieldType, fieldName; - OString modFieldType; - StringSet generatedTypeSet; - StringSet::iterator findIter; - - for (sal_uInt16 i=0; i < fieldCount; i++) - { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - fieldType = checkRealBaseType( - OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8), - sal_True); - - modFieldType = typeToIdentifier(fieldType); - - findIter = generatedTypeSet.find(fieldType); - if ( findIter == generatedTypeSet.end() ) - { - generatedTypeSet.insert(fieldType); - o << indent() << "const ::com::sun::star::uno::Type& rMemberType_" - << modFieldType/*i*/ << " = ::cppu::UnoType< "; - dumpType(o, fieldType, false, false, false, true); - o << " >::get();\n"; - } - - o << indent() << "aMemberRefs[" << i << "] = rMemberType_" - << modFieldType/*i*/ << ".getTypeLibType();\n"; - } - o << "\n"; - } - - o << indent() << "typelib_static_compound_type_init( &the_type, " - << getTypeClass(m_typeName, sal_True) << ", \"" << m_typeName.replace('/', '.') << "\", "; - if ( !superType.isEmpty() || bIsBaseException ) - { - if ( bIsBaseException ) - { - o << "* ::typelib_static_type_getByTypeClass( typelib_TypeClass_EXCEPTION ), " - << count << ", "; - } else - { - o << "rBaseType.getTypeLibType(), " << count << ", "; - } - } else - { - o << "0, " << count << ", "; - } - - if (count) - { - o << " aMemberRefs );\n"; - } else - { - o << " 0 );\n"; - } - dec(); - o << indent() << "}\n"; - o << indent() - << ("return * reinterpret_cast< const ::com::sun::star::uno::Type * >(" - " &the_type );\n"); - - dumpGetCppuTypePostamble(o); -} - -void CppuType::dumpComprehensiveGetCppuType(FileStream& o) -{ - if (!isPolymorphic()) - codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false); - else - o << "namespace cppu { "; - o << " namespace detail {\n\n"; - - OString sType = m_typeName.copy(m_typeName.lastIndexOf('/') + 1); - OString sStaticTypeClass = "the" + sType + "Type"; - o << indent() << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, " << sStaticTypeClass << " >\n"; - o << indent() << "{\n"; - inc(); - o << indent() << "::com::sun::star::uno::Type * operator()() const\n"; - o << indent() << "{\n"; - inc(); - - o << indent() << "rtl::OUString sTypeName( \"" - << m_typeName.replace('/', '.') << "\" );\n\n"; - - o << indent() << "// Start inline typedescription generation\n" - << indent() << "typelib_TypeDescription * pTD = 0;\n"; - - OString superType; - if (m_reader.getSuperTypeCount() >= 1) { - superType = OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8); - } - if (!superType.isEmpty()) { - o << indent() - << "const ::com::sun::star::uno::Type& rSuperType = ::cppu::UnoType< "; - dumpType(o, superType, false, false, false, true); - o << " >::get();\n"; - } - - dumpCppuGetTypeMemberDecl(o, CPPUTYPEDECL_ALLTYPES); - - sal_uInt32 count = getMemberCount(); - if (count) - { - o << "\n" << indent() << "typelib_CompoundMember_Init aMembers[" - << count << "];\n"; - - sal_uInt16 fieldCount = m_reader.getFieldCount(); - RTFieldAccess access = RT_ACCESS_INVALID; - OString fieldType, fieldName; - for (sal_uInt16 i=0; i < fieldCount; i++) - { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) { - continue; - } - - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - fieldType = checkRealBaseType( - OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8), - sal_True); - - o << indent() << "rtl::OUString sMemberType" << i - << "( \"" - << fieldType.replace('/', '.') << "\" );\n"; - o << indent() << "rtl::OUString sMemberName" << i - << "( \""; - o << fieldName << "\" );\n"; - o << indent() << "aMembers[" << i << "].eTypeClass = " - << "(typelib_TypeClass)" << getTypeClass(fieldType) << ";\n" - << indent() << "aMembers[" << i << "].pTypeName = sMemberType" - << i << ".pData;\n" - << indent() << "aMembers[" << i << "].pMemberName = sMemberName" - << i << ".pData;\n"; - } - } - - o << "\n" << indent() << "typelib_typedescription_new(\n"; +void CppuType::dumpLightGetCppuType(FileStream & out) { + dumpGetCppuTypePreamble(out); + out << indent() + << "static typelib_TypeDescriptionReference * the_type = 0;\n" + << indent() << "if ( !the_type )\n" << indent() << "{\n"; inc(); - o << indent() << "&pTD,\n" << indent() << "(typelib_TypeClass)" - << getTypeClass() << ", sTypeName.pData,\n"; - - if (!superType.isEmpty()) { - o << indent() << "rSuperType.getTypeLibType(),\n"; - } else { - o << indent() << "0,\n"; - } - - if ( count ) { - o << indent() << count << ",\n" << indent() << "aMembers );\n\n"; - } else { - o << indent() << count << ",\n" << indent() << "0 );\n\n"; - } + out << indent() << "typelib_static_type_init( &the_type, " + << getTypeClass(name_, true) << ", \"" << name_ << "\" );\n"; dec(); - - o << indent() - << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD" - " );\n\n"); - - o << indent() << "typelib_typedescription_release( pTD );\n" - << indent() << "// End inline typedescription generation\n\n"; - - o << indent() << "return new ::com::sun::star::uno::Type( " - << getTypeClass(m_typeName) << ", sTypeName ); // leaked\n"; - - dec(); - o << indent() << "}\n"; - dec(); - o << indent() << "};\n\n"; - - if (!isPolymorphic()) - codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false); - else - o << " }"; - - o << " }\n\n"; - - dumpGetCppuTypePreamble(o); - o << indent() << "return *detail::" << sStaticTypeClass << "::get();\n"; - dumpGetCppuTypePostamble(o); -} - -void CppuType::dumpCppuGetTypeMemberDecl(FileStream& o, CppuTypeDecl eDeclFlag) -{ - sal_uInt16 fieldCount = m_reader.getFieldCount(); - RTFieldAccess access = RT_ACCESS_INVALID; - - StringSet aFinishedTypes; - for (sal_uInt16 i=0; i < fieldCount; i++) - { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID - || (access & RT_ACCESS_PARAMETERIZED_TYPE) != 0) - continue; - - OString typeName( - OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8)); - if (aFinishedTypes.count(typeName) == 0) - { - aFinishedTypes.insert(typeName); - dumpCppuGetType(o, typeName, sal_True, eDeclFlag); - } - } -} - -IdentifierTranslationMode CppuType::isGlobal() const { - if ( m_typeName.indexOf('/') < 0 ) - return ITM_GLOBAL; - else - return ITM_NONGLOBAL; -} - -sal_uInt32 CppuType::getMemberCount() -{ - sal_uInt16 count = m_reader.getMethodCount(); - - sal_uInt16 fieldCount = m_reader.getFieldCount(); - RTFieldAccess access = RT_ACCESS_INVALID; - for (sal_uInt16 i=0; i < fieldCount; i++) - { - access = m_reader.getFieldFlags(i); - - if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID) - count++; - } - return count; + out << indent() << "}\n" << indent() + << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >(" + " &the_type );\n"); + dumpGetCppuTypePostamble(out); } -sal_uInt32 CppuType::checkInheritedMemberCount(const typereg::Reader* pReader) -{ - sal_Bool bSelfCheck = sal_True; - if (!pReader) - { - bSelfCheck = sal_False; - pReader = &m_reader; - } - - sal_uInt32 count = 0; - OString superType; - if (pReader->getSuperTypeCount() >= 1) { - superType = OUStringToOString( - pReader->getSuperTypeName(0), RTL_TEXTENCODING_UTF8); - } - if (!superType.isEmpty()) - { - typereg::Reader aSuperReader(m_typeMgr->getTypeReader(superType)); - if ( aSuperReader.isValid() ) - { - count = checkInheritedMemberCount(&aSuperReader); - } - } - - if (bSelfCheck) - { - count += pReader->getMethodCount(); - sal_uInt16 fieldCount = pReader->getFieldCount(); - RTFieldAccess access = RT_ACCESS_INVALID; - for (sal_uInt16 i=0; i < fieldCount; i++) - { - access = pReader->getFieldFlags(i); - - if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID) - { - count++; - } - } - } - - return count; +codemaker::cpp::IdentifierTranslationMode CppuType::isGlobal() const { + return name_.indexOf('.') == -1 + ? codemaker::cpp::ITM_GLOBAL : codemaker::cpp::ITM_NONGLOBAL; } sal_uInt32 CppuType::getInheritedMemberCount() { if (m_inheritedMemberCount == 0) { - m_inheritedMemberCount = checkInheritedMemberCount(0); + m_inheritedMemberCount = checkInheritedMemberCount(); } return m_inheritedMemberCount; } -OString CppuType::getTypeClass(const OString& type, sal_Bool bCStyle) -{ - OString typeName = (!type.isEmpty() ? type : m_typeName); - RTTypeClass rtTypeClass = RT_TYPE_INVALID; - - if (!type.isEmpty()) - { - typeName = type; - rtTypeClass = m_typeMgr->getTypeClass(typeName); - } else - { - typeName = m_typeName; - rtTypeClass = m_reader.getTypeClass(); - } - - if (codemaker::UnoType::isSequenceType(typeName)) - return bCStyle ? "typelib_TypeClass_SEQUENCE" : "::com::sun::star::uno::TypeClass_SEQUENCE"; - - switch (rtTypeClass) - { - case RT_TYPE_INTERFACE: - return bCStyle ? "typelib_TypeClass_INTERFACE" : "::com::sun::star::uno::TypeClass_INTERFACE"; - case RT_TYPE_MODULE: - return bCStyle ? "typelib_TypeClass_MODULE" : "::com::sun::star::uno::TypeClass_MODULE"; - case RT_TYPE_STRUCT: - return bCStyle ? "typelib_TypeClass_STRUCT" : "::com::sun::star::uno::TypeClass_STRUCT"; - case RT_TYPE_ENUM: - return bCStyle ? "typelib_TypeClass_ENUM" : "::com::sun::star::uno::TypeClass_ENUM"; - case RT_TYPE_EXCEPTION: - return bCStyle ? "typelib_TypeClass_EXCEPTION" : "::com::sun::star::uno::TypeClass_EXCEPTION"; - case RT_TYPE_TYPEDEF: - { - OString realType = checkRealBaseType( typeName ); - return getTypeClass( realType, bCStyle ); - } - case RT_TYPE_SERVICE: - return bCStyle ? "typelib_TypeClass_SERVICE" : "::com::sun::star::uno::TypeClass_SERVICE"; - case RT_TYPE_INVALID: - { - if (type == "long") - return bCStyle ? "typelib_TypeClass_LONG" : "::com::sun::star::uno::TypeClass_LONG"; - if (type == "short") - return bCStyle ? "typelib_TypeClass_SHORT" : "::com::sun::star::uno::TypeClass_SHORT"; - if (type == "hyper") - return bCStyle ? "typelib_TypeClass_HYPER" : "::com::sun::star::uno::TypeClass_HYPER"; - if (type == "string") - return bCStyle ? "typelib_TypeClass_STRING" : "::com::sun::star::uno::TypeClass_STRING"; - if (type == "boolean") - return bCStyle ? "typelib_TypeClass_BOOLEAN" : "::com::sun::star::uno::TypeClass_BOOLEAN"; - if (type == "char") - return bCStyle ? "typelib_TypeClass_CHAR" : "::com::sun::star::uno::TypeClass_CHAR"; - if (type == "byte") - return bCStyle ? "typelib_TypeClass_BYTE" : "::com::sun::star::uno::TypeClass_BYTE"; - if (type == "any") - return bCStyle ? "typelib_TypeClass_ANY" : "::com::sun::star::uno::TypeClass_ANY"; - if (type == "type") - return bCStyle ? "typelib_TypeClass_TYPE" : "::com::sun::star::uno::TypeClass_TYPE"; - if (type == "float") - return bCStyle ? "typelib_TypeClass_FLOAT" : "::com::sun::star::uno::TypeClass_FLOAT"; - if (type == "double") - return bCStyle ? "typelib_TypeClass_DOUBLE" : "::com::sun::star::uno::TypeClass_DOUBLE"; - if (type == "void") - return bCStyle ? "typelib_TypeClass_VOID" : "::com::sun::star::uno::TypeClass_VOID"; - if (type == "unsigned long") - return bCStyle ? "typelib_TypeClass_UNSIGNED_LONG" : "::com::sun::star::uno::TypeClass_UNSIGNED_LONG"; - if (type == "unsigned short") - return bCStyle ? "typelib_TypeClass_UNSIGNED_SHORT" : "::com::sun::star::uno::TypeClass_UNSIGNED_SHORT"; - if (type == "unsigned hyper") - return bCStyle ? "typelib_TypeClass_UNSIGNED_HYPER" : "::com::sun::star::uno::TypeClass_UNSIGNED_HYPER"; - } - break; - default: - OSL_ASSERT(false); - break; +OUString CppuType::getTypeClass(OUString const & name, bool cStyle) { + rtl::Reference< unoidl::Entity > ent; + switch (m_typeMgr->getSort(name, &ent)) { + case codemaker::UnoType::SORT_VOID: + return cStyle + ? OUString("typelib_TypeClass_VOID") + : OUString("::com::sun::star::uno::TypeClass_VOID"); + case codemaker::UnoType::SORT_BOOLEAN: + return cStyle + ? OUString("typelib_TypeClass_BOOLEAN") + : OUString("::com::sun::star::uno::TypeClass_BOOLEAN"); + case codemaker::UnoType::SORT_BYTE: + return cStyle + ? OUString("typelib_TypeClass_BYTE") + : OUString("::com::sun::star::uno::TypeClass_BYTE"); + case codemaker::UnoType::SORT_SHORT: + return cStyle + ? OUString("typelib_TypeClass_SHORT") + : OUString("::com::sun::star::uno::TypeClass_SHORT"); + case codemaker::UnoType::SORT_UNSIGNED_SHORT: + return cStyle + ? OUString("typelib_TypeClass_UNSIGNED_SHORT") + : OUString("::com::sun::star::uno::TypeClass_UNSIGNED_SHORT"); + case codemaker::UnoType::SORT_LONG: + return cStyle + ? OUString("typelib_TypeClass_LONG") + : OUString("::com::sun::star::uno::TypeClass_LONG"); + case codemaker::UnoType::SORT_UNSIGNED_LONG: + return cStyle + ? OUString("typelib_TypeClass_UNSIGNED_LONG") + : OUString("::com::sun::star::uno::TypeClass_UNSIGNED_LONG"); + case codemaker::UnoType::SORT_HYPER: + return cStyle + ? OUString("typelib_TypeClass_HYPER") + : OUString("::com::sun::star::uno::TypeClass_HYPER"); + case codemaker::UnoType::SORT_UNSIGNED_HYPER: + return cStyle + ? OUString("typelib_TypeClass_UNSIGNED_HYPER") + : OUString("::com::sun::star::uno::TypeClass_UNSIGNED_HYPER"); + case codemaker::UnoType::SORT_FLOAT: + return cStyle + ? OUString("typelib_TypeClass_FLOAT") + : OUString("::com::sun::star::uno::TypeClass_FLOAT"); + case codemaker::UnoType::SORT_DOUBLE: + return cStyle + ? OUString("typelib_TypeClass_DOUBLE") + : OUString("::com::sun::star::uno::TypeClass_DOUBLE"); + case codemaker::UnoType::SORT_CHAR: + return cStyle + ? OUString("typelib_TypeClass_CHAR") + : OUString("::com::sun::star::uno::TypeClass_CHAR"); + case codemaker::UnoType::SORT_STRING: + return cStyle + ? OUString("typelib_TypeClass_STRING") + : OUString("::com::sun::star::uno::TypeClass_STRING"); + case codemaker::UnoType::SORT_TYPE: + return cStyle + ? OUString("typelib_TypeClass_TYPE") + : OUString("::com::sun::star::uno::TypeClass_TYPE"); + case codemaker::UnoType::SORT_ANY: + return cStyle + ? OUString("typelib_TypeClass_ANY") + : OUString("::com::sun::star::uno::TypeClass_ANY"); + case codemaker::UnoType::SORT_SEQUENCE_TYPE: + return cStyle + ? OUString("typelib_TypeClass_SEQUENCE") + : OUString("::com::sun::star::uno::TypeClass_SEQUENCE"); + case codemaker::UnoType::SORT_ENUM_TYPE: + return cStyle + ? OUString("typelib_TypeClass_ENUM") + : OUString("::com::sun::star::uno::TypeClass_ENUM"); + case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE: + case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE: + case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE: + return cStyle + ? OUString("typelib_TypeClass_STRUCT") + : OUString("::com::sun::star::uno::TypeClass_STRUCT"); + case codemaker::UnoType::SORT_EXCEPTION_TYPE: + return cStyle + ? OUString("typelib_TypeClass_EXCEPTION") + : OUString("::com::sun::star::uno::TypeClass_EXCEPTION"); + case codemaker::UnoType::SORT_INTERFACE_TYPE: + return cStyle + ? OUString("typelib_TypeClass_INTERFACE") + : OUString("::com::sun::star::uno::TypeClass_INTERFACE"); + case codemaker::UnoType::SORT_TYPEDEF: + return getTypeClass( + dynamic_cast< unoidl::TypedefEntity * >(ent.get())->getType(), + cStyle); + default: + for (;;) { std::abort(); } } - - return bCStyle ? "typelib_TypeClass_UNKNOWN" : "::com::sun::star::uno::TypeClass_UNKNOWN"; } -void CppuType::dumpType(FileStream& o, const OString& type, - bool bConst, bool bRef, bool bNative, bool cppuUnoType) - const throw( CannotDumpException ) +void CppuType::dumpType( + FileStream & out, OUString const & name, bool isConst, bool isRef, + bool native, bool cppuUnoType) const { - sal_Int32 seqNum; + sal_Int32 k; std::vector< OString > args; - OString relType( - codemaker::UnoType::decompose( - checkRealBaseType(type, true), &seqNum, &args)); - - RTTypeClass typeClass = m_typeMgr->getTypeClass(relType); - - if (bConst) o << "const "; - - for (sal_Int32 i = 0; i < seqNum; ++i) { - if (cppuUnoType) - o << "::cppu::UnoSequenceType< "; - else - o << "::com::sun::star::uno::Sequence< "; - } - - switch (typeClass) - { - case RT_TYPE_INTERFACE: - if (bNative) - o << scopedCppName(relType); - else - o << "::com::sun::star::uno::Reference< " - << scopedCppName(relType) << " >"; - break; - case RT_TYPE_INVALID: - { - OString tmp(translateSimpleUnoType(relType, cppuUnoType)); - if (!tmp.isEmpty()) - { - o << tmp; - } else - throw CannotDumpException("Unknown type '" + relType + - "', incomplete type library."); - } - break; - case RT_TYPE_STRUCT: - case RT_TYPE_ENUM: - case RT_TYPE_TYPEDEF: - case RT_TYPE_EXCEPTION: + OUString n( + b2u(codemaker::UnoType::decompose( + u2b(resolveAllTypedefs(name)), &k, &args))); + if (isConst) { + out << "const "; + } + for (sal_Int32 i = 0; i != k; ++i) { + out << (cppuUnoType + ? "::cppu::UnoSequenceType" : "::com::sun::star::uno::Sequence") + << "< "; + } + switch (m_typeMgr->getSort(n)) { + case codemaker::UnoType::SORT_VOID: + out << "void"; + break; + case codemaker::UnoType::SORT_BOOLEAN: + out << "::sal_Bool"; + break; + case codemaker::UnoType::SORT_BYTE: + out << "::sal_Int8"; + break; + case codemaker::UnoType::SORT_SHORT: + out << "::sal_Int16"; + break; + case codemaker::UnoType::SORT_UNSIGNED_SHORT: + out << (cppuUnoType ? "::cppu::UnoUnsignedShortType" : "::sal_uInt16"); + break; + case codemaker::UnoType::SORT_LONG: + out << "::sal_Int32"; + break; + case codemaker::UnoType::SORT_UNSIGNED_LONG: + out << "::sal_uInt32"; + break; + case codemaker::UnoType::SORT_HYPER: + out << "::sal_Int64"; + break; + case codemaker::UnoType::SORT_UNSIGNED_HYPER: + out << "::sal_uInt64"; + break; + case codemaker::UnoType::SORT_FLOAT: + out << "float"; + break; + case codemaker::UnoType::SORT_DOUBLE: + out << "double"; + break; + case codemaker::UnoType::SORT_CHAR: + out << (cppuUnoType ? "::cppu::UnoCharType" : "::sal_Unicode"); + break; + case codemaker::UnoType::SORT_STRING: + out << "::rtl::OUString"; + break; + case codemaker::UnoType::SORT_TYPE: + out << "::com::sun::star::uno::Type"; + break; + case codemaker::UnoType::SORT_ANY: + out << "::com::sun::star::uno::Any"; + break; + case codemaker::UnoType::SORT_ENUM_TYPE: + case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE: + case codemaker::UnoType::SORT_EXCEPTION_TYPE: + out << codemaker::cpp::scopedCppName(u2b(n)); + break; + case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE: + out << codemaker::cpp::scopedCppName(u2b(n)); + if (!args.empty()) { + out << "< "; + for (std::vector< OString >::iterator i(args.begin()); + i != args.end(); ++i) { - o << scopedCppName(relType); - if (!args.empty()) { - o << "< "; - for (std::vector< OString >::iterator i(args.begin()); - i != args.end(); ++i) - { - if (i != args.begin()) { - o << ", "; - } - dumpType(o, *i); - } - o << " >"; + if (i != args.begin()) { + out << ", "; } - break; + dumpType(out, b2u(*i)); } - default: - OSL_ASSERT(false); - break; - } - - for (sal_Int32 i = 0; i < seqNum; ++i) { - o << " >"; - } - - if (bRef) o << "&"; -} - -void CppuType::dumpCppuGetType(FileStream& o, const OString& type, sal_Bool bDecl, CppuTypeDecl eDeclFlag) -{ - OString relType( - codemaker::UnoType::decompose(checkRealBaseType(type, true))); - - if (eDeclFlag == CPPUTYPEDECL_ONLYINTERFACES) - { - if (m_typeMgr->getTypeClass(relType) == RT_TYPE_INTERFACE) - { - o << indent() << "::cppu::UnoType< "; - dumpType(o, type, false, false, false, true); - o << " >::get()"; - - if (bDecl) - o << ";\n"; + out << " >"; } - } else - { - if (codemaker::UnoType::getSort(type) - != codemaker::UnoType::SORT_COMPLEX) - { - return; - } else - { - if (eDeclFlag == CPPUTYPEDECL_NOINTERFACES && - m_typeMgr->getTypeClass(relType) == RT_TYPE_INTERFACE) - return; - - o << indent() << "::cppu::UnoType< "; - dumpType(o, type, false, false, false, true); - o << " >::get()"; + break; + case codemaker::UnoType::SORT_INTERFACE_TYPE: + if (!native) { + out << "::com::sun::star::uno::Reference< "; } - if (bDecl) - o << ";\n"; - } -} - -OString CppuType::typeToIdentifier(const OString& type) -{ - sal_Int32 seqNum; - OString relType(codemaker::UnoType::decompose(type, &seqNum)); - OString sIdentifier; - - while( seqNum > 0 ) - { - sIdentifier += OString("seq"); - - if ( --seqNum == 0 ) - { - sIdentifier += OString("_"); + out << codemaker::cpp::scopedCppName(u2b(n)); + if (!native) { + out << " >"; } + break; + default: + throw CannotDumpException( + "unexpected type \"" + name + "\" in call to CppuType::dumpType"); } - - sIdentifier += relType.replace( - ((codemaker::UnoType::getSort(relType) - == codemaker::UnoType::SORT_COMPLEX) - ? '/' : ' '), - '_'); - - // TODO: find better solution to create an identifier - sIdentifier = sIdentifier.replace('<', '_'); - sIdentifier = sIdentifier.replace('>', '_'); - sIdentifier = sIdentifier.replace(',', '_'); - - return sIdentifier; -} - -bool CppuType::passByReference(OString const & unoType) { - OString type(resolveTypedefs(unoType)); - switch (codemaker::UnoType::getSort(type)) { + for (sal_Int32 i = 0; i != k; ++i) { + out << " >"; + } + if (isRef) { + out << "&"; + } +} + +void CppuType::dumpCppuGetType(FileStream & out, OUString const & name) { + switch (m_typeMgr->getSort(resolveOuterTypedefs(name))) { + case codemaker::UnoType::SORT_VOID: + case codemaker::UnoType::SORT_BOOLEAN: + case codemaker::UnoType::SORT_BYTE: + case codemaker::UnoType::SORT_SHORT: + case codemaker::UnoType::SORT_UNSIGNED_SHORT: + case codemaker::UnoType::SORT_LONG: + case codemaker::UnoType::SORT_UNSIGNED_LONG: + case codemaker::UnoType::SORT_HYPER: + case codemaker::UnoType::SORT_UNSIGNED_HYPER: + case codemaker::UnoType::SORT_FLOAT: + case codemaker::UnoType::SORT_DOUBLE: + case codemaker::UnoType::SORT_CHAR: + case codemaker::UnoType::SORT_STRING: + case codemaker::UnoType::SORT_TYPE: + case codemaker::UnoType::SORT_ANY: + break; + case codemaker::UnoType::SORT_SEQUENCE_TYPE: + case codemaker::UnoType::SORT_ENUM_TYPE: + case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE: + case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE: + case codemaker::UnoType::SORT_EXCEPTION_TYPE: + case codemaker::UnoType::SORT_INTERFACE_TYPE: + out << indent() << "::cppu::UnoType< "; + dumpType(out, name, false, false, false, true); + out << " >::get();\n"; + break; default: + throw CannotDumpException( + "unexpected type \"" + name + + "\" in call to CppuType::dumpCppuGetType"); + } +} + +bool CppuType::passByReference(OUString const & name) const { + switch (m_typeMgr->getSort(resolveOuterTypedefs(name))) { + case codemaker::UnoType::SORT_BOOLEAN: + case codemaker::UnoType::SORT_BYTE: + case codemaker::UnoType::SORT_SHORT: + case codemaker::UnoType::SORT_UNSIGNED_SHORT: + case codemaker::UnoType::SORT_LONG: + case codemaker::UnoType::SORT_UNSIGNED_LONG: + case codemaker::UnoType::SORT_HYPER: + case codemaker::UnoType::SORT_UNSIGNED_HYPER: + case codemaker::UnoType::SORT_FLOAT: + case codemaker::UnoType::SORT_DOUBLE: + case codemaker::UnoType::SORT_CHAR: + case codemaker::UnoType::SORT_ENUM_TYPE: return false; - case codemaker::UnoType::SORT_STRING: case codemaker::UnoType::SORT_TYPE: case codemaker::UnoType::SORT_ANY: + case codemaker::UnoType::SORT_SEQUENCE_TYPE: + case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE: + case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE: + case codemaker::UnoType::SORT_INTERFACE_TYPE: return true; - - case codemaker::UnoType::SORT_COMPLEX: - return m_typeMgr->getTypeClass(type) != RT_TYPE_ENUM; + default: + throw CannotDumpException( + "unexpected type \"" + name + + "\" in call to CppuType::passByReference"); } } -OString CppuType::resolveTypedefs(const OString& type) const -{ - OString baseType(type); - - RegistryKey key; - RTTypeClass typeClass; - sal_Bool isTypeDef = (m_typeMgr->getTypeClass(baseType) == RT_TYPE_TYPEDEF); - typereg::Reader reader; - - while (isTypeDef) - { - reader = m_typeMgr->getTypeReader(baseType); - - if (reader.isValid()) - { - typeClass = reader.getTypeClass(); - - if (typeClass == RT_TYPE_TYPEDEF) - baseType = OUStringToOString( - reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8); - else - isTypeDef = sal_False; - } else - { - break; +OUString CppuType::resolveOuterTypedefs(OUString const & name) const { + for (OUString n(name);;) { + rtl::Reference< unoidl::Entity > ent; + if (m_typeMgr->getSort(n, &ent) != codemaker::UnoType::SORT_TYPEDEF) { + return n; } + n = dynamic_cast< unoidl::TypedefEntity * >(ent.get())->getType(); } - - return baseType; } -OString CppuType::checkRealBaseType(const OString& type, sal_Bool bResolveTypeOnly) const -{ - sal_Int32 rank; - OString baseType(codemaker::UnoType::decompose(type, &rank)); - - RegistryKey key; - RTTypeClass typeClass; - sal_Bool mustBeChecked = (m_typeMgr->getTypeClass(baseType) == RT_TYPE_TYPEDEF); - typereg::Reader reader; - - while (mustBeChecked) - { - reader = m_typeMgr->getTypeReader(baseType); - - if (reader.isValid()) - { - typeClass = reader.getTypeClass(); - - if (typeClass == RT_TYPE_TYPEDEF) - { - sal_Int32 n; - baseType = codemaker::UnoType::decompose( - OUStringToOString( - reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8), - &n); - OSL_ASSERT(n <= SAL_MAX_INT32 - rank); //TODO - rank += n; - } else - mustBeChecked = sal_False; - } else - { +OUString CppuType::resolveAllTypedefs(OUString const & name) const { + sal_Int32 k1; + OUString n(b2u(codemaker::UnoType::decompose(u2b(name), &k1))); + for (;;) { + rtl::Reference< unoidl::Entity > ent; + if (m_typeMgr->getSort(n, &ent) != codemaker::UnoType::SORT_TYPEDEF) { break; } + sal_Int32 k2; + n = b2u( + codemaker::UnoType::decompose( + u2b(dynamic_cast< unoidl::TypedefEntity * >(ent.get())-> + getType()), + &k2)); + k1 += k2; //TODO: overflow } - - if (bResolveTypeOnly) { - OStringBuffer buf; - for (sal_Int32 i = 0; i < rank; ++i) { - buf.append("[]"); - } - baseType = buf.makeStringAndClear() + baseType; - } - - return baseType; -} - -void CppuType::dumpConstantValue(FileStream& o, sal_uInt16 index) -{ - RTConstValue constValue = m_reader.getFieldValue(index); - - switch (constValue.m_type) - { - case RT_TYPE_NONE: - break; - case RT_TYPE_BOOL: - if (constValue.m_value.aBool) - o << "sal_True"; - else - o << "sal_False"; - break; - case RT_TYPE_BYTE: - o << "(sal_Int8)" << constValue.m_value.aByte; - break; - case RT_TYPE_INT16: - o << "(sal_Int16)" << constValue.m_value.aShort; - break; - case RT_TYPE_UINT16: - o << "(sal_uInt16)" << constValue.m_value.aUShort; - break; - case RT_TYPE_INT32: - // Avoid C++ compiler warnings about (un)signedness of literal - // -2^31: - if (constValue.m_value.aLong == SAL_MIN_INT32) { - o << "SAL_MIN_INT32"; - } else { - o << "(sal_Int32)" << constValue.m_value.aLong; - } - break; - case RT_TYPE_UINT32: - o << "(sal_uInt32)" - << OString::valueOf( - static_cast< sal_Int64 >(constValue.m_value.aULong)).getStr() - << "U"; - break; - case RT_TYPE_INT64: - // Avoid C++ compiler warnings about (un)signedness of literal - // -2^63: - if (constValue.m_value.aHyper == SAL_MIN_INT64) { - o << "SAL_MIN_INT64"; - } else { - OString tmp(OString::valueOf(constValue.m_value.aHyper)); - o << "(sal_Int64) SAL_CONST_INT64(" << tmp.getStr() << ")"; - } - break; - case RT_TYPE_UINT64: - { - o << "SAL_CONST_UINT64("; - sal_uInt64 n = constValue.m_value.aUHyper; - if (n == 0) { - o << "0"; - } else { - std::vector< char > buf; - for (; n != 0; n /= 10) { - buf.push_back('0' + static_cast< char >(n % 10)); - } - for (std::vector< char >::reverse_iterator i(buf.rbegin()); - i != buf.rend(); ++i) - { - o << OString::valueOf(*i).getStr(); - } - } - o << ")"; - } - break; - case RT_TYPE_FLOAT: - { - OString tmp( OString::valueOf(constValue.m_value.aFloat) ); - o << "(float)" << tmp.getStr(); - } - break; - case RT_TYPE_DOUBLE: - { - OString tmp( OString::valueOf(constValue.m_value.aDouble) ); - o << "(double)" << tmp.getStr(); - } - break; - case RT_TYPE_STRING: - { - OUString aUStr(constValue.m_value.aString); - OString aStr = OUStringToOString(aUStr, RTL_TEXTENCODING_ASCII_US); - o << "rtl::OUString( \"" << aStr.getStr() << "\" )"; - } - break; + OUStringBuffer b; + for (sal_Int32 i = 0; i != k1; ++i) { + b.append("[]"); } + b.append(n); + return b.makeStringAndClear(); } void CppuType::inc(sal_Int32 num) @@ -1325,609 +908,424 @@ void CppuType::dec(sal_Int32 num) m_indentLength = std::max< sal_Int32 >(m_indentLength - num, 0); } -OString CppuType::indent() const -{ - OStringBuffer tmp(m_indentLength); - - for (sal_Int32 i=0; i < m_indentLength; i++) - { - tmp.append(' '); +OUString CppuType::indent() const { + OUStringBuffer buf(m_indentLength); + for (sal_Int32 i = 0; i != m_indentLength; ++i) { + buf.append(' '); } - return tmp.makeStringAndClear(); + return buf.makeStringAndClear(); } -//************************************************************************* -// InterfaceType -//************************************************************************* - -namespace { - bool isDocumentedDeprecated(OUString const & documentation) { return documentation.indexOf("@deprecated") != -1; //TODO: this check is somewhat crude } -void dumpDeprecation(FileStream & o, bool deprecated) { +void dumpDeprecation(FileStream & out, bool deprecated) { if (deprecated) { - o << "SAL_DEPRECATED_INTERNAL(\"marked @deprecated in UNOIDL\") "; + out << "SAL_DEPRECATED_INTERNAL(\"marked @deprecated in UNOIDL\") "; } } -} +class BaseOffset: private boost::noncopyable { +public: + BaseOffset( + rtl::Reference< TypeManager > const & manager, + rtl::Reference< unoidl::InterfaceTypeEntity > const & entity): + manager_(manager), offset_(0) { calculateBases(entity); } -InterfaceType::InterfaceType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr) - : CppuType(typeReader, typeName, typeMgr) -{ - m_inheritedMemberCount = 0; - m_hasAttributes = false; - m_hasMethods = false; - m_isDeprecated = isDocumentedDeprecated(m_reader.getDocumentation()); -} + sal_Int32 get() const { return offset_; } -InterfaceType::~InterfaceType() -{ +private: + void calculateBases( + rtl::Reference< unoidl::InterfaceTypeEntity > const & entity); -} + rtl::Reference< TypeManager > manager_; + std::set< OUString > set_; + sal_Int32 offset_; +}; -sal_Bool InterfaceType::dumpHFile( - FileStream& o, codemaker::cppumaker::Includes & includes) - throw( CannotDumpException ) +void BaseOffset::calculateBases( + rtl::Reference< unoidl::InterfaceTypeEntity > const & entity) { - if (m_reader.getMethodCount() != 0) { - includes.add("com/sun/star/uno/RuntimeException"); + assert(entity.is()); + for (std::vector< OUString >::const_iterator i( + entity->getDirectMandatoryBases().begin()); + i != entity->getDirectMandatoryBases().end(); ++i) + { + if (set_.insert(*i).second) { + rtl::Reference< unoidl::Entity > ent; + codemaker::UnoType::Sort sort = manager_->getSort(*i, &ent); + if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE) { + throw CannotDumpException( + "interface type base " + *i + " is not an interface type"); + } + rtl::Reference< unoidl::InterfaceTypeEntity > ent2( + dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get())); + assert(ent2.is()); + calculateBases(ent2); + offset_ += ent2->getDirectAttributes().size() + + ent2->getDirectMethods().size(); //TODO: overflow + } } - dumpHFileContent(o, includes); - return sal_True; } -void InterfaceType::dumpDeclaration(FileStream& o) - throw( CannotDumpException ) -{ - o << "\nclass SAL_NO_VTABLE " << m_name; +class InterfaceType: public CppuType { +public: + InterfaceType( + rtl::Reference< unoidl::InterfaceTypeEntity > const & entity, + OUString const & name, rtl::Reference< TypeManager > const & typeMgr); + + virtual void dumpDeclaration(FileStream& o); + void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes); + + void dumpAttributes(FileStream& o); + void dumpMethods(FileStream& o); + void dumpNormalGetCppuType(FileStream& o); + void dumpComprehensiveGetCppuType(FileStream& o); + void dumpCppuAttributeRefs(FileStream& o, sal_uInt32& index); + void dumpCppuMethodRefs(FileStream& o, sal_uInt32& index); + void dumpCppuAttributes(FileStream& o, sal_uInt32& index); + void dumpCppuMethods(FileStream& o, sal_uInt32& index); + void dumpAttributesCppuDecl(FileStream & out, std::set< OUString > * seen); + void dumpMethodsCppuDecl(FileStream & out, std::set< OUString > * seen); + +protected: + virtual void addComprehensiveGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const; + + virtual sal_uInt32 checkInheritedMemberCount() const + { return BaseOffset(m_typeMgr, entity_).get(); } + + sal_uInt32 m_inheritedMemberCount; + bool m_isDeprecated; - for (sal_Int16 i = 0; i < m_reader.getSuperTypeCount(); ++i) { - o << (i == 0 ? " :" : ",") << " public " - << scopedCppName(OUStringToOString( - m_reader.getSuperTypeName(i), RTL_TEXTENCODING_UTF8)); - } +private: + void dumpExceptionSpecification( + FileStream & out, std::vector< OUString > const & exceptions, + bool runtimeException); - o << "\n{\npublic:\n"; + void dumpExceptionTypeName( + FileStream & out, OUString const & prefix, sal_uInt32 index, + OUString const & name); - inc(); + sal_Int32 dumpExceptionTypeNames( + FileStream & out, OUString const & prefix, + std::vector< OUString > const & exceptions, bool runtimeException); - dumpAttributes(o); - dumpMethods(o); + rtl::Reference< unoidl::InterfaceTypeEntity > entity_; +}; + +InterfaceType::InterfaceType( + rtl::Reference< unoidl::InterfaceTypeEntity > const & entity, + OUString const & name, rtl::Reference< TypeManager > const & typeMgr): + CppuType(name, typeMgr), entity_(entity) +{ + assert(entity.is()); + m_inheritedMemberCount = 0; + m_isDeprecated = isDocumentedDeprecated("TODO"); +} - o << "\n" << indent() - << ("static inline ::com::sun::star::uno::Type const & SAL_CALL" - " static_type(void * = 0);\n\n"); +void InterfaceType::dumpDeclaration(FileStream & out) { + out << "\nclass SAL_NO_VTABLE " << id_; + for (std::vector< OUString >::const_iterator i( + entity_->getDirectMandatoryBases().begin()); + i != entity_->getDirectMandatoryBases().end(); ++i) + { + out << (i == entity_->getDirectMandatoryBases().begin() ? " :" : ",") + << " public " << codemaker::cpp::scopedCppName(u2b(*i)); + } + out << "\n{\npublic:\n"; + inc(); + dumpAttributes(out); + dumpMethods(out); + out << "\n" << indent() + << ("static inline ::com::sun::star::uno::Type const & SAL_CALL" + " static_type(void * = 0);\n\n"); dec(); - o << "protected:\n"; + out << "protected:\n"; inc(); - o << indent() << "~" << m_name - << ("() throw () {} // avoid warnings about virtual members and" - " non-virtual dtor\n"); + out << indent() << "~" << id_ + << ("() throw () {} // avoid warnings about virtual members and" + " non-virtual dtor\n"); dec(); - o << "};\n\n"; + out << "};\n\n"; } -sal_Bool InterfaceType::dumpHxxFile( - FileStream& o, codemaker::cppumaker::Includes & includes) - throw( CannotDumpException ) +void InterfaceType::dumpHxxFile( + FileStream & out, codemaker::cppumaker::Includes & includes) { - OString headerDefine(dumpHeaderDefine(o, "HPP")); - o << "\n"; - + OUString headerDefine(dumpHeaderDefine(out, "HPP")); + out << "\n"; addDefaultHxxIncludes(includes); - includes.dump(o, &m_typeName); - o << "\n"; - - dumpGetCppuType(o); - - o << "\n::com::sun::star::uno::Type const & " - << scopedCppName(m_typeName) - << "::static_type(SAL_UNUSED_PARAMETER void *) {\n"; + includes.dump(out, &name_); + out << "\n"; + dumpGetCppuType(out); + out << "\n::com::sun::star::uno::Type const & " + << codemaker::cpp::scopedCppName(u2b(name_)) + << "::static_type(SAL_UNUSED_PARAMETER void *) {\n"; inc(); - o << indent() << "return ::getCppuType(static_cast< "; - dumpType(o, m_typeName); - o << " * >(0));\n"; + out << indent() << "return ::getCppuType(static_cast< "; + dumpType(out, name_); + out << " * >(0));\n"; dec(); - o << "}\n"; - - o << "\n#endif // "<< headerDefine << "\n"; - return sal_True; + out << "}\n\n#endif // "<< headerDefine << "\n"; } -void InterfaceType::dumpAttributes(FileStream& o) -{ - sal_uInt16 fieldCount = m_reader.getFieldCount(); - sal_Bool first=sal_True; - - RTFieldAccess access = RT_ACCESS_INVALID; - OString fieldName; - OString fieldType; - for (sal_uInt16 i=0; i < fieldCount; i++) +void InterfaceType::dumpAttributes(FileStream & out) { + if (!entity_->getDirectAttributes().empty()) { + out << "\n" << indent() << "// Attributes\n"; + } + for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator + i(entity_->getDirectAttributes().begin()); + i != entity_->getDirectAttributes().end(); ++i) { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - OUString name(m_reader.getFieldName(i)); - fieldName = OUStringToOString(name, RTL_TEXTENCODING_UTF8); - fieldType = OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8); - - bool depr = m_isDeprecated - || isDocumentedDeprecated(m_reader.getFieldDocumentation(i)); - - if (first) - { - first = sal_False; - o << "\n" << indent() << "// Attributes\n"; - } - - o << indent(); - dumpDeprecation(o, depr); - o << "virtual "; - dumpType(o, fieldType); - o << " SAL_CALL get" << fieldName << "()"; - dumpAttributeExceptionSpecification(o, name, RT_MODE_ATTRIBUTE_GET); - o << " = 0;\n"; - - if ((access & RT_ACCESS_READONLY) == 0) - { - bool byRef = passByReference(fieldType); - o << indent(); - dumpDeprecation(o, depr); - o << "virtual void SAL_CALL set" << fieldName << "( "; - dumpType(o, fieldType, byRef, byRef); - o << " _" << fieldName.toAsciiLowerCase() << " )"; - dumpAttributeExceptionSpecification(o, name, RT_MODE_ATTRIBUTE_SET); - o << " = 0;\n"; + bool depr = m_isDeprecated || isDocumentedDeprecated("TODO"); + out << indent(); + dumpDeprecation(out, depr); + out << "virtual "; + dumpType(out, i->type); + out << " SAL_CALL get" << i->name << "()"; + dumpExceptionSpecification(out, i->getExceptions, true); + out << " = 0;\n"; + if (!i->readOnly) { + bool byRef = passByReference(i->type); + out << indent(); + dumpDeprecation(out, depr); + out << "virtual void SAL_CALL set" << i->name << "( "; + dumpType(out, i->type, byRef, byRef); + out << " _" << i->name.toAsciiLowerCase() << " )"; + dumpExceptionSpecification(out, i->setExceptions, true); + out << " = 0;\n"; } } } -void InterfaceType::dumpMethods(FileStream& o) -{ - sal_uInt16 methodCount = m_reader.getMethodCount(); - sal_Bool first=sal_True; - - OString methodName, returnType, paramType, paramName; - sal_uInt16 paramCount = 0; - RTMethodMode methodMode = RT_MODE_INVALID; - RTParamMode paramMode = RT_PARAM_INVALID; - - sal_Bool bRef = sal_False; - sal_Bool bConst = sal_False; - sal_Bool bWithRunTimeExcp = sal_True; - - for (sal_uInt16 i=0; i < methodCount; i++) +void InterfaceType::dumpMethods(FileStream & out) { + if (!entity_->getDirectMethods().empty()) { + out << "\n" << indent() << "// Methods\n"; + } + for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i( + entity_->getDirectMethods().begin()); + i != entity_->getDirectMethods().end(); ++i) { - methodMode = m_reader.getMethodFlags(i); - if (methodMode == RT_MODE_ATTRIBUTE_GET - || methodMode == RT_MODE_ATTRIBUTE_SET) - { - continue; - } - - methodName = OUStringToOString( - m_reader.getMethodName(i), RTL_TEXTENCODING_UTF8); - returnType = OUStringToOString( - m_reader.getMethodReturnTypeName(i), RTL_TEXTENCODING_UTF8); - paramCount = m_reader.getMethodParameterCount(i); - - if ( methodName == "acquire" || methodName == "release" ) - { - bWithRunTimeExcp = sal_False; - } - - if (first) - { - first = sal_False; - o << "\n" << indent() << "// Methods\n"; - } - - o << indent(); - dumpDeprecation( - o, - (m_isDeprecated - || isDocumentedDeprecated(m_reader.getMethodDocumentation(i)))); - o << "virtual "; - dumpType(o, returnType); - if ( !paramCount ) - { - // prettier output for nullary methods - o << " SAL_CALL " << methodName << "()"; - } - else - { - o << " SAL_CALL " << methodName << "( "; - for (sal_uInt16 j=0; j < paramCount; j++) + out << indent(); + dumpDeprecation(out, m_isDeprecated || isDocumentedDeprecated("TODO")); + out << "virtual "; + dumpType(out, i->returnType); + out << " SAL_CALL " << i->name << "("; + if (i->parameters.empty()) { + out << ")"; + } else { + out << " "; + for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >:: + const_iterator j(i->parameters.begin()); + j != i->parameters.end();) { - paramName = OUStringToOString( - m_reader.getMethodParameterName(i, j), RTL_TEXTENCODING_UTF8); - paramType = OUStringToOString( - m_reader.getMethodParameterTypeName(i, j), - RTL_TEXTENCODING_UTF8); - paramMode = m_reader.getMethodParameterFlags(i, j); - - switch (paramMode) + bool isConst; + bool isRef; + if (j->direction + == (unoidl::InterfaceTypeEntity::Method::Parameter:: + DIRECTION_IN)) { - case RT_PARAM_IN: - bConst = passByReference(paramType); - bRef = bConst; - break; - case RT_PARAM_OUT: - case RT_PARAM_INOUT: - bConst = sal_False; - bRef = sal_True; - break; - default: - break; + isConst = passByReference(j->type); + isRef = isConst; + } else { + isConst = false; + isRef = true; + } + dumpType(out, j->type, isConst, isRef); + out << " " << j->name; + ++j; + if (j != i->parameters.end()) { + out << ", "; } - - dumpType(o, paramType, bConst, bRef); - o << " " << paramName; - - if (j+1 < (sal_uInt16)paramCount) o << ", "; } - o << " )"; + out << " )"; } - dumpExceptionSpecification(o, i, bWithRunTimeExcp); - o << " = 0;\n"; + dumpExceptionSpecification( + out, i->exceptions, i->name != "acquire" && i->name != "release"); + out << " = 0;\n"; } } -void InterfaceType::dumpNormalGetCppuType(FileStream& o) -{ - dumpGetCppuTypePreamble(o); - - o << indent() - << "static typelib_TypeDescriptionReference * the_type = 0;\n"; - - o << indent() << "if ( !the_type )\n" << indent() << "{\n"; +void InterfaceType::dumpNormalGetCppuType(FileStream & out) { + dumpGetCppuTypePreamble(out); + out << indent() + << "static typelib_TypeDescriptionReference * the_type = 0;\n" + << indent() << "if ( !the_type )\n" << indent() << "{\n"; inc(); - sal_Int16 nBases = m_reader.getSuperTypeCount(); - OSL_ASSERT(nBases > 0); - if (nBases == 1 && m_reader.getSuperTypeName(0) == "com/sun/star/uno/XInterface" ) - { - nBases = 0; - } - if (nBases > 0) { - o << indent() << "typelib_TypeDescriptionReference * aSuperTypes[" - << nBases << "];\n"; - for (sal_Int16 i = 0; i < nBases; ++i) { - o << indent() << "aSuperTypes[" << i << "] = ::cppu::UnoType< "; - dumpType( - o, - OUStringToOString( - m_reader.getSuperTypeName(i), RTL_TEXTENCODING_UTF8), - true, false, false, true); - o << " >::get().getTypeLibType();\n"; + std::vector< OUString >::size_type bases( + entity_->getDirectMandatoryBases().size()); + if (bases == 1 + && (entity_->getDirectMandatoryBases()[0] + == "com.sun.star.uno.XInterface")) + { + bases = 0; + } + if (bases != 0) { + out << indent() << "typelib_TypeDescriptionReference * aSuperTypes[" + << entity_->getDirectMandatoryBases().size() << "];\n"; + std::vector< OUString >::size_type n = 0; + for (std::vector< OUString >::const_iterator i( + entity_->getDirectMandatoryBases().begin()); + i != entity_->getDirectMandatoryBases().end(); ++i) + { + out << indent() << "aSuperTypes[" << n++ << "] = ::cppu::UnoType< "; + dumpType(out, *i, true, false, false, true); + out << " >::get().getTypeLibType();\n"; } } - - o << indent() << "typelib_static_mi_interface_type_init( &the_type, \"" - << m_typeName.replace('/', '.') << "\", " << nBases << ", "; - - if ( nBases > 0 ) - { - o << "aSuperTypes );\n"; - } else - { - o << "0 );\n"; - } - + out << indent() << "typelib_static_mi_interface_type_init( &the_type, \"" + << name_ << "\", " << bases << ", " + << (bases == 0 ? "0" : "aSuperTypes") << " );\n"; dec(); - o << indent() << "}\n"; - o << indent() - << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >(" - " &the_type );\n"); - - dumpGetCppuTypePostamble(o); + out << indent() << "}\n" << indent() + << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >(" + " &the_type );\n"); + dumpGetCppuTypePostamble(out); } -void InterfaceType::dumpComprehensiveGetCppuType(FileStream& o) -{ - if (!isPolymorphic()) - codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false); - else - o << "namespace cppu { "; - o << " namespace detail {\n\n"; - - OString sType = m_typeName.copy(m_typeName.lastIndexOf('/') + 1); - OString sStaticTypeClass = "the" + sType + "Type"; - o << indent() << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, " << sStaticTypeClass << " >\n"; - o << indent() << "{\n"; +void InterfaceType::dumpComprehensiveGetCppuType(FileStream & out) { + codemaker::cppumaker::dumpNamespaceOpen(out, name_, false); + OUString staticTypeClass("the" + id_ + "Type"); + out << " namespace detail {\n\n" << indent() << "struct " << staticTypeClass + << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, " + << staticTypeClass << " >\n" << indent() << "{\n"; inc(); - o << indent() << "::com::sun::star::uno::Type * operator()() const\n"; - o << indent() << "{\n"; - + out << indent() << "::com::sun::star::uno::Type * operator()() const\n" + << indent() << "{\n"; inc(); - o << indent() << "rtl::OUString sTypeName( \"" - << m_typeName.replace('/', '.') << "\" );\n\n"; - - o << indent() << "// Start inline typedescription generation\n" - << indent() << "typelib_InterfaceTypeDescription * pTD = 0;\n\n"; - - OSL_ASSERT(m_reader.getSuperTypeCount() > 0); - o << indent() << "typelib_TypeDescriptionReference * aSuperTypes[" - << m_reader.getSuperTypeCount() << "];\n"; - for (sal_Int16 i = 0; i < m_reader.getSuperTypeCount(); ++i) { - o << indent() << "aSuperTypes[" << i << "] = ::cppu::UnoType< "; - dumpType( - o, - OUStringToOString( - m_reader.getSuperTypeName(i), RTL_TEXTENCODING_UTF8), - false, false, false, true); - o << " >::get().getTypeLibType();\n"; - } - - sal_uInt32 count = getMemberCount(); - if (count) - { - o << indent() << "typelib_TypeDescriptionReference * pMembers[" << count - << "] = { "; - for (sal_uInt32 i = 0; i < count; i++) - { - o << "0"; - if (i+1 < count) { - o << ","; - } else { - o << " };\n"; + out << indent() << "::rtl::OUString sTypeName( \"" << name_ << "\" );\n\n" + << indent() << "// Start inline typedescription generation\n" + << indent() << "typelib_InterfaceTypeDescription * pTD = 0;\n\n"; + out << indent() << "typelib_TypeDescriptionReference * aSuperTypes[" + << entity_->getDirectMandatoryBases().size() << "];\n"; + std::vector< OUString >::size_type n = 0; + for (std::vector< OUString >::const_iterator i( + entity_->getDirectMandatoryBases().begin()); + i != entity_->getDirectMandatoryBases().end(); ++i) + { + out << indent() << "aSuperTypes[" << n++ << "] = ::cppu::UnoType< "; + dumpType(out, *i, false, false, false, true); + out << " >::get().getTypeLibType();\n"; + } + std::size_t count = entity_->getDirectAttributes().size() + + entity_->getDirectMethods().size(); //TODO: overflow + if (count != 0) { + out << indent() << "typelib_TypeDescriptionReference * pMembers[" + << count << "] = { "; + for (std::size_t i = 0; i != count; ++i) { + out << "0"; + if (i + 1 != count) { + out << ","; } } - + out << " };\n"; sal_uInt32 index = 0; - dumpCppuAttributeRefs(o, index); - dumpCppuMethodRefs(o, index); + dumpCppuAttributeRefs(out, index); + dumpCppuMethodRefs(out, index); } - - o << "\n" << indent() << "typelib_typedescription_newMIInterface(\n"; + out << "\n" << indent() << "typelib_typedescription_newMIInterface(\n"; inc(); - o << indent() << "&pTD,\n" << indent() << "sTypeName.pData, "; - - o << "0x00000000, 0x0000, 0x0000, 0x00000000, 0x00000000,\n"; // UIK - - o << indent() << m_reader.getSuperTypeCount() << ", aSuperTypes,\n"; - - if ( count ) { - o << indent() << count << ",\n" << indent() << "pMembers );\n\n"; - } else { - o << indent() << count << ",\n" << indent() << "0 );\n\n"; - } + out << indent() << "&pTD,\n" << indent() + << ("sTypeName.pData, 0x00000000, 0x0000, 0x0000, 0x00000000," + " 0x00000000,\n") // UIK + << indent() << entity_->getDirectMandatoryBases().size() + << ", aSuperTypes,\n" << indent() << count << ",\n" << indent() + << (count == 0 ? "0" : "pMembers") << " );\n\n"; dec(); - - o << indent() - << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD" + out << indent() + << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD" " );\n"); - if ( count ) - { - for (sal_uInt16 i=0; i < count; i++) - { - o << indent() - << "typelib_typedescriptionreference_release( pMembers[" << i - << "] );\n"; - } + for (std::size_t i = 0; i != count; ++i) { + out << indent() << "typelib_typedescriptionreference_release( pMembers[" + << i << "] );\n"; } - o << indent() - << ("typelib_typedescription_release( (typelib_TypeDescription*)pTD" - " );\n\n"); - - o << indent() << "return new ::com::sun::star::uno::Type( " - << getTypeClass(m_typeName) << ", sTypeName ); // leaked\n"; - + out << indent() + << ("typelib_typedescription_release( (typelib_TypeDescription*)pTD" + " );\n\n") + << indent() << "return new ::com::sun::star::uno::Type( " + << getTypeClass(name_) << ", sTypeName ); // leaked\n"; dec(); - - o << indent() << "}\n"; + out << indent() << "}\n"; dec(); - o << indent() << "};\n\n"; - - if (!isPolymorphic()) - codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false); - else - o << " }"; - o << " }\n\n"; - - dumpGetCppuTypePreamble(o); - o << indent() << "const ::com::sun::star::uno::Type &rRet = *detail::" << sStaticTypeClass << "::get();\n"; - - o << indent() << "// End inline typedescription generation\n"; - - o << indent() << "static bool bInitStarted = false;\n"; - o << indent() << "if (!bInitStarted)\n"; - o << indent() << "{\n"; + out << indent() << "};\n\n"; + codemaker::cppumaker::dumpNamespaceClose(out, name_, false); + out << " }\n\n"; + dumpGetCppuTypePreamble(out); + out << indent() << "const ::com::sun::star::uno::Type &rRet = *detail::" + << staticTypeClass << "::get();\n" << indent() + << "// End inline typedescription generation\n" << indent() + << "static bool bInitStarted = false;\n" << indent() + << "if (!bInitStarted)\n" << indent() << "{\n"; inc(); - o << indent() << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n"; - o << indent() << "if (!bInitStarted)\n"; - o << indent() << "{\n"; + out << indent() + << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n" + << indent() << "if (!bInitStarted)\n" << indent() << "{\n"; inc(); - o << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n"; - o << indent() << "bInitStarted = true;\n"; - - StringSet aTypes; - // type for RuntimeException is always needed - OString sRunTimeExceptionType("com/sun/star/uno/RuntimeException"); - aTypes.insert(sRunTimeExceptionType); - dumpCppuGetType(o, sRunTimeExceptionType, sal_True, CPPUTYPEDECL_ALLTYPES); - - dumpAttributesCppuDecl(o, &aTypes, CPPUTYPEDECL_ALLTYPES); - dumpMethodsCppuDecl(o, &aTypes, CPPUTYPEDECL_ALLTYPES); - - if (count) - { + out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n" + << indent() << "bInitStarted = true;\n"; + std::set< OUString > seen; + // Type for RuntimeException is always needed: + seen.insert("com.sun.star.uno.RuntimeException"); + dumpCppuGetType(out, "com.sun.star.uno.RuntimeException"); + dumpAttributesCppuDecl(out, &seen); + dumpMethodsCppuDecl(out, &seen); + if (count != 0) { sal_uInt32 index = getInheritedMemberCount(); - dumpCppuAttributes(o, index); - dumpCppuMethods(o, index); + dumpCppuAttributes(out, index); + dumpCppuMethods(out, index); } - dec(); - o << indent() << "}\n"; + out << indent() << "}\n"; dec(); - o << indent() << "}\n"; - o << indent() << "else\n"; - o << indent() << "{\n"; + out << indent() << "}\n" << indent() << "else\n" << indent() << "{\n"; inc(); - o << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n"; + out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n"; dec(); - o << indent() << "}\n"; - - o << indent() << "return rRet;\n"; - dumpGetCppuTypePostamble(o); + out << indent() << "}\n" << indent() << "return rRet;\n"; + dumpGetCppuTypePostamble(out); } -void InterfaceType::dumpCppuAttributeRefs(FileStream& o, sal_uInt32& index) +void InterfaceType::dumpCppuAttributeRefs(FileStream & out, sal_uInt32 & index) { - sal_uInt16 fieldCount = m_reader.getFieldCount(); - - RTFieldAccess access = RT_ACCESS_INVALID; - OString fieldName; - OString scope = m_typeName.replace('/', '.'); - - for (sal_uInt16 i=0; i < fieldCount; i++) + std::vector< unoidl::InterfaceTypeEntity::Attribute >::size_type n = 0; + for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator + i(entity_->getDirectAttributes().begin()); + i != entity_->getDirectAttributes().end(); ++i) { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - - o << indent() << "rtl::OUString sAttributeName" << i << "( \"" - << scope.replace('/', '.') << "::" << fieldName << "\" );\n"; - o << indent() << "typelib_typedescriptionreference_new( &pMembers[" - << index << "],\n"; + out << indent() << "::rtl::OUString sAttributeName" << n << "( \"" + << name_ << "::" << i->name << "\" );\n" << indent() + << "typelib_typedescriptionreference_new( &pMembers[" << index++ + << "],\n"; inc(38); - o << indent() << "(typelib_TypeClass)::com::sun::star::uno::TypeClass_INTERFACE_ATTRIBUTE,\n" - << indent() << "sAttributeName" << i << ".pData );\n"; + out << indent() + << ("(typelib_TypeClass)" + "::com::sun::star::uno::TypeClass_INTERFACE_ATTRIBUTE,\n") + << indent() << "sAttributeName" << n << ".pData );\n"; dec(38); - index++; + ++n; } } -void InterfaceType::dumpCppuMethodRefs(FileStream& o, sal_uInt32& index) -{ - sal_uInt16 methodCount = m_reader.getMethodCount(); - OString methodName; - OString scope = m_typeName.replace('/', '.'); - - for (sal_uInt16 i = 0; i < methodCount; i++) +void InterfaceType::dumpCppuMethodRefs(FileStream & out, sal_uInt32 & index) { + std::vector< unoidl::InterfaceTypeEntity::Method >::size_type n = 0; + for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i( + entity_->getDirectMethods().begin()); + i != entity_->getDirectMethods().end(); ++i) { - RTMethodMode flags = m_reader.getMethodFlags(i); - if (flags == RT_MODE_ATTRIBUTE_GET || flags == RT_MODE_ATTRIBUTE_SET) { - continue; - } - - methodName = OUStringToOString( - m_reader.getMethodName(i), RTL_TEXTENCODING_UTF8); - - o << indent() << "rtl::OUString sMethodName" << i << "( \"" - << scope.replace('/', '.') << "::" << methodName << "\" );\n"; - o << indent() << "typelib_typedescriptionreference_new( &pMembers[" - << index << "],\n"; + out << indent() << "::rtl::OUString sMethodName" << n << "( \"" << name_ + << "::" << i->name << "\" );\n" << indent() + << "typelib_typedescriptionreference_new( &pMembers[" << index++ + << "],\n"; inc(38); - o << indent() << "(typelib_TypeClass)::com::sun::star::uno::TypeClass_INTERFACE_METHOD,\n" - << indent() << "sMethodName" << i << ".pData );\n"; + out << indent() + << ("(typelib_TypeClass)" + "::com::sun::star::uno::TypeClass_INTERFACE_METHOD,\n") + << indent() << "sMethodName" << n << ".pData );\n"; dec(38); - index++; - } -} - -sal_uInt32 InterfaceType::getMemberCount() { - sal_uInt16 count = 0; - sal_uInt16 methodCount = m_reader.getMethodCount(); - for (sal_uInt16 i = 0; i < methodCount; ++i) { - RTMethodMode flags = m_reader.getMethodFlags(i); - if (flags != RT_MODE_ATTRIBUTE_GET && flags != RT_MODE_ATTRIBUTE_SET) { - m_hasMethods = true; - ++count; - } - } - sal_uInt16 fieldCount = m_reader.getFieldCount(); - for (sal_uInt16 i = 0; i < fieldCount; ++i) { - RTFieldAccess flags = m_reader.getFieldFlags(i); - if (flags != RT_ACCESS_CONST && flags != RT_ACCESS_INVALID) { - m_hasAttributes = true; - ++count; - } - } - return count; -} - -namespace { - -class BaseOffset { -public: - BaseOffset( - rtl::Reference< TypeManager > const & theManager, - typereg::Reader const & reader); - - sal_Int32 get() const { return offset; } - -private: - void calculateBases(typereg::Reader const & reader); - - void calculate(typereg::Reader const & reader); - - rtl::Reference< TypeManager > manager; - std::set< OString > set; - sal_Int32 offset; -}; - -BaseOffset::BaseOffset( - rtl::Reference< TypeManager > const & theManager, - typereg::Reader const & reader): - manager(theManager) -{ - offset = 0; - calculateBases(reader); -} - -void BaseOffset::calculateBases(typereg::Reader const & reader) { - for (sal_Int16 i = 0; i < reader.getSuperTypeCount(); ++i) { - typereg::Reader super( - manager->getTypeReader( - OUStringToOString( - reader.getSuperTypeName(i), RTL_TEXTENCODING_UTF8))); - if (super.isValid()) { - calculate(super); - } - } -} - -void BaseOffset::calculate(typereg::Reader const & reader) { - if (set.insert( - OUStringToOString(reader.getTypeName(), RTL_TEXTENCODING_UTF8)) - .second) - { - calculateBases(reader); - for (sal_uInt16 i = 0; i < reader.getMethodCount(); ++i) { - RTMethodMode flags = reader.getMethodFlags(i); - if (flags != RT_MODE_ATTRIBUTE_GET - && flags != RT_MODE_ATTRIBUTE_SET) - { - ++offset; - } - } - for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) { - RTFieldAccess flags = reader.getFieldFlags(i); - if (flags != RT_ACCESS_CONST && flags != RT_ACCESS_INVALID) { - ++offset; - } - } - } -} - -} - -void InterfaceType::addSpecialDependencies() { - if (m_reader.getMethodCount() > 0 || m_reader.getFieldCount() > 0) { - m_dependencies.add("com/sun/star/uno/RuntimeException"); + ++n; } } @@ -1937,308 +1335,211 @@ void InterfaceType::addComprehensiveGetCppuTypeIncludes( // The comprehensive getCppuType method always includes a line // "getCppuType( (const ::com::sun::star::uno::RuntimeException*)0 );": includes.addCppuUnotypeHxx(); - includes.add("com/sun/star/uno/RuntimeException"); -} - -sal_uInt32 InterfaceType::checkInheritedMemberCount(const typereg::Reader*) -{ - return BaseOffset(m_typeMgr, m_reader).get(); + includes.add("com.sun.star.uno.RuntimeException"); } -sal_uInt32 InterfaceType::getInheritedMemberCount() -{ - if (m_inheritedMemberCount == 0) - { - m_inheritedMemberCount = checkInheritedMemberCount(0); - } - - return m_inheritedMemberCount; -} - -void InterfaceType::dumpCppuAttributes(FileStream& o, sal_uInt32& index) -{ - sal_uInt16 fieldCount = m_reader.getFieldCount(); - - RTFieldAccess access = RT_ACCESS_INVALID; - OString fieldName; - OString fieldType; - OString scope = m_typeName.replace('/', '.'); - - sal_uInt32 absoluteIndex = index; - - if (m_hasAttributes) - { - o << "\n" << indent() << "typelib_InterfaceAttributeTypeDescription * pAttribute = 0;\n"; - - for (sal_uInt16 i=0; i < fieldCount; i++) +void InterfaceType::dumpCppuAttributes(FileStream & out, sal_uInt32 & index) { + if (!entity_->getDirectAttributes().empty()) { + out << "\n" << indent() + << "typelib_InterfaceAttributeTypeDescription * pAttribute = 0;\n"; + std::vector< unoidl::InterfaceTypeEntity::Attribute >::size_type n = 0; + for (std::vector< unoidl::InterfaceTypeEntity::Attribute >:: + const_iterator i(entity_->getDirectAttributes().begin()); + i != entity_->getDirectAttributes().end(); ++i) { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - OUString name(m_reader.getFieldName(i)); - fieldName = OUStringToOString(name, RTL_TEXTENCODING_UTF8); - fieldType = checkRealBaseType( - OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8), - sal_True); - - o << indent() << "{\n"; + OUString type(resolveAllTypedefs(i->type)); + out << indent() << "{\n"; inc(); - o << indent() << "rtl::OUString sAttributeType" << i << "( \"" - << fieldType.replace('/', '.') << "\" );\n"; - - o << indent() << "rtl::OUString sAttributeName" << i << "( \"" - << scope.replace('/', '.') << "::" << fieldName << "\" );\n"; - - sal_Int32 getExceptions = dumpAttributeExceptionTypeNames( - o, "get", name, RT_MODE_ATTRIBUTE_GET); - sal_Int32 setExceptions = dumpAttributeExceptionTypeNames( - o, "set", name, RT_MODE_ATTRIBUTE_SET); - o << indent() - << ("typelib_typedescription_newExtendedInterfaceAttribute(" - " &pAttribute,\n"); + out << indent() << "::rtl::OUString sAttributeType" << n << "( \"" + << type << "\" );\n" << indent() + << "::rtl::OUString sAttributeName" << n << "( \"" << name_ + << "::" << i->name << "\" );\n"; + sal_Int32 getExcn = dumpExceptionTypeNames( + out, "get", i->getExceptions, false); + sal_Int32 setExcn = dumpExceptionTypeNames( + out, "set", i->setExceptions, false); + out << indent() + << ("typelib_typedescription_newExtendedInterfaceAttribute(" + " &pAttribute,\n"); inc(); - o << indent() << absoluteIndex++ << ", sAttributeName" << i << ".pData,\n"; - o << indent() << "(typelib_TypeClass)" << getTypeClass(fieldType) - << ", sAttributeType" << i << ".pData,\n"; - o << indent() << "sal_" - << ((access & RT_ACCESS_READONLY) == 0 ? "False" : "True") << ", " - << getExceptions << ", " - << (getExceptions == 0 ? "0" : "the_getExceptions") << ", " - << setExceptions << ", " - << (setExceptions == 0 ? "0" : "the_setExceptions") << " );\n"; + out << indent() << index++ << ", sAttributeName" << n + << ".pData,\n" << indent() << "(typelib_TypeClass)" + << getTypeClass(type) << ", sAttributeType" << n << ".pData,\n" + << indent() << "sal_" << (i->readOnly ? "True" : "False") + << ", " << getExcn << ", " + << (getExcn == 0 ? "0" : "the_getExceptions") << ", " << setExcn + << ", " << (setExcn == 0 ? "0" : "the_setExceptions") + << " );\n"; dec(); - o << indent() << "typelib_typedescription_register( (typelib_TypeDescription**)&pAttribute );\n"; + out << indent() + << ("typelib_typedescription_register(" + " (typelib_TypeDescription**)&pAttribute );\n"); dec(); - o << indent() << "}\n"; + out << indent() << "}\n"; + ++n; } - o << indent() << "typelib_typedescription_release( (typelib_TypeDescription*)pAttribute );\n"; - - index = absoluteIndex; + out << indent() + << ("typelib_typedescription_release(" + " (typelib_TypeDescription*)pAttribute );\n"); } } -void InterfaceType::dumpCppuMethods(FileStream& o, sal_uInt32& index) -{ - sal_uInt16 methodCount = m_reader.getMethodCount(); - OString methodName, returnType, paramType, paramName; - RTMethodMode methodMode = RT_MODE_INVALID; - RTParamMode paramMode = RT_PARAM_INVALID; - sal_Bool bWithRuntimeException = sal_True; - - sal_uInt32 absoluteIndex = index; - - if (m_hasMethods) - { - o << "\n" << indent() << "typelib_InterfaceMethodTypeDescription * pMethod = 0;\n"; - OString scope = m_typeName.replace('/', '.'); - - sal_uInt16 paramCount = 0; - for (sal_uInt16 i=0; i < methodCount; i++) +void InterfaceType::dumpCppuMethods(FileStream & out, sal_uInt32 & index) { + if (!entity_->getDirectMethods().empty()) { + out << "\n" << indent() + << "typelib_InterfaceMethodTypeDescription * pMethod = 0;\n"; + std::vector< unoidl::InterfaceTypeEntity::Method >::size_type n = 0; + for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator + i(entity_->getDirectMethods().begin()); + i != entity_->getDirectMethods().end(); ++i) { - methodMode = m_reader.getMethodFlags(i); - if (methodMode == RT_MODE_ATTRIBUTE_GET - || methodMode == RT_MODE_ATTRIBUTE_SET) - { - continue; - } - - methodName = OUStringToOString( - m_reader.getMethodName(i), RTL_TEXTENCODING_UTF8); - returnType = checkRealBaseType( - OUStringToOString( - m_reader.getMethodReturnTypeName(i), RTL_TEXTENCODING_UTF8), - sal_True); - paramCount = m_reader.getMethodParameterCount(i); - - if ( methodName == "acquire" || methodName == "release" ) - { - bWithRuntimeException = sal_False; - } - - o << indent() << "{\n"; + OUString returnType(resolveAllTypedefs(i->returnType)); + out << indent() << "{\n"; inc(); - - if (paramCount) + if (!i->parameters.empty()) { + out << indent() << "typelib_Parameter_Init aParameters[" + << i->parameters.size() << "];\n"; + } + std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >:: + size_type m = 0; + for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >:: + const_iterator j(i->parameters.begin()); + j != i->parameters.end(); ++j) { - o << indent() << "typelib_Parameter_Init aParameters[" << paramCount << "];\n"; - } - - for (sal_uInt16 j = 0; j < paramCount; j++) - { - paramName = OUStringToOString( - m_reader.getMethodParameterName(i, j), - RTL_TEXTENCODING_UTF8); - paramType = checkRealBaseType( - OUStringToOString( - m_reader.getMethodParameterTypeName(i, j), - RTL_TEXTENCODING_UTF8), - sal_True); - paramMode = m_reader.getMethodParameterFlags(i, j); - - o << indent() << "rtl::OUString sParamName" << j << "( \"" - << paramName << "\" );\n"; - o << indent() << "rtl::OUString sParamType" << j << "( \"" - << paramType.replace('/', '.') << "\" );\n"; - o << indent() << "aParameters[" << j << "].pParamName = sParamName" << j << ".pData;\n"; - o << indent() << "aParameters[" << j << "].eTypeClass = (typelib_TypeClass)" - << getTypeClass(paramType) << ";\n"; - o << indent() << "aParameters[" << j << "].pTypeName = sParamType" << j << ".pData;\n"; - - if (paramMode == RT_PARAM_IN || paramMode == RT_PARAM_INOUT) - o << indent() << "aParameters[" << j << "].bIn = sal_True;\n"; - else - o << indent() << "aParameters[" << j << "].bIn = sal_False;\n"; - - if (paramMode == RT_PARAM_OUT || paramMode == RT_PARAM_INOUT) - o << indent() << "aParameters[" << j << "].bOut = sal_True;\n"; - else - o << indent() << "aParameters[" << j << "].bOut = sal_False;\n"; - } - - sal_Int32 excCount = dumpExceptionTypeNames( - o, "", i, bWithRuntimeException); - - o << indent() << "rtl::OUString sReturnType" << i << "( \"" - << returnType.replace('/', '.') << "\" );\n"; - o << indent() << "rtl::OUString sMethodName" << i << - "( \"" - << scope.replace('/', '.') << "::" << methodName << "\" );\n"; - o << indent() << "typelib_typedescription_newInterfaceMethod( &pMethod,\n"; + OUString type(resolveAllTypedefs(j->type)); + out << indent() << "::rtl::OUString sParamName" << m << "( \"" + << j->name << "\" );\n" << indent() + << "::rtl::OUString sParamType" << m << "( \"" << type + << "\" );\n" << indent() << "aParameters[" << m + << "].pParamName = sParamName" << m << ".pData;\n" + << indent() << "aParameters[" << m + << "].eTypeClass = (typelib_TypeClass)" + << getTypeClass(type) << ";\n" << indent() << "aParameters[" + << m << "].pTypeName = sParamType" << m << ".pData;\n" + << indent() << "aParameters[" << m << "].bIn = " + << ((j->direction + == (unoidl::InterfaceTypeEntity::Method::Parameter:: + DIRECTION_OUT)) + ? "sal_False" : "sal_True") + << ";\n" << indent() << "aParameters[" << m << "].bOut = " + << ((j->direction + == (unoidl::InterfaceTypeEntity::Method::Parameter:: + DIRECTION_IN)) + ? "sal_False" : "sal_True") + << ";\n"; + ++m; + } + sal_Int32 excn = dumpExceptionTypeNames( + out, "", i->exceptions, + i->name != "acquire" && i->name != "release"); + out << indent() << "::rtl::OUString sReturnType" << n << "( \"" + << returnType << "\" );\n" << indent() + << "::rtl::OUString sMethodName" << n << "( \"" << name_ << "::" + << i->name << "\" );\n" << indent() + << "typelib_typedescription_newInterfaceMethod( &pMethod,\n"; inc(); - o << indent() << absoluteIndex++ << ", "; - if (methodMode == RT_MODE_ONEWAY || methodMode == RT_MODE_ONEWAY_CONST) - o << "sal_True,\n"; - else - o << "sal_False,\n"; - - o << indent() << "sMethodName" << i << ".pData,\n"; - o << indent() << "(typelib_TypeClass)" << getTypeClass(returnType) - << ", sReturnType" << i << ".pData,\n"; - if (paramCount) - o << indent() << paramCount << ", aParameters,\n"; - else - o << indent() << "0, 0,\n"; - o << indent() << excCount << ", " - << (excCount == 0 ? "0" : "the_Exceptions") << " );\n"; - + out << indent() << index++ << ", sal_False,\n" << indent() + << "sMethodName" << n << ".pData,\n" << indent() + << "(typelib_TypeClass)" << getTypeClass(returnType) + << ", sReturnType" << n << ".pData,\n" << indent() + << i->parameters.size() << ", " + << (i->parameters.empty() ? "0" : "aParameters") << ",\n" + << indent() << excn << ", " + << (excn == 0 ? "0" : "the_Exceptions") << " );\n"; dec(); - o << indent() << "typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );\n"; - + out << indent() + << ("typelib_typedescription_register(" + " (typelib_TypeDescription**)&pMethod );\n"); dec(); - o << indent() << "}\n"; + out << indent() << "}\n"; + ++n; } - o << indent() << "typelib_typedescription_release( (typelib_TypeDescription*)pMethod );\n"; - - index = absoluteIndex; + out << indent() + << ("typelib_typedescription_release(" + " (typelib_TypeDescription*)pMethod );\n"); } } -void InterfaceType::dumpAttributesCppuDecl(FileStream& o, StringSet* pFinishedTypes, CppuTypeDecl eDeclFlag) +void InterfaceType::dumpAttributesCppuDecl( + FileStream & out, std::set< OUString > * seen) { - sal_uInt16 fieldCount = m_reader.getFieldCount(); - - RTFieldAccess access = RT_ACCESS_INVALID; - OString fieldName; - OString fieldType; - for (sal_uInt16 i=0; i < fieldCount; i++) + assert(seen != 0); + for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator + i(entity_->getDirectAttributes().begin()); + i != entity_->getDirectAttributes().end(); ++i) { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - fieldType = OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8); - - if (pFinishedTypes->count(fieldType) == 0) + if (seen->insert(i->type).second) { + dumpCppuGetType(out, i->type); + } + for (std::vector< OUString >::const_iterator j( + i->getExceptions.begin()); + j != i->getExceptions.end(); ++j) + { + if (seen->insert(*j).second) { + dumpCppuGetType(out, *j); + } + } + for (std::vector< OUString >::const_iterator j( + i->setExceptions.begin()); + j != i->setExceptions.end(); ++j) { - pFinishedTypes->insert(fieldType); - dumpCppuGetType(o, fieldType, sal_True, eDeclFlag); + if (seen->insert(*j).second) { + dumpCppuGetType(out, *j); + } } } } -void InterfaceType::dumpMethodsCppuDecl(FileStream& o, StringSet* pFinishedTypes, CppuTypeDecl eDeclFlag) +void InterfaceType::dumpMethodsCppuDecl( + FileStream & out, std::set< OUString > * seen) { - sal_uInt16 methodCount = m_reader.getMethodCount(); - OString returnType, paramType, excType; - sal_uInt16 paramCount = 0; - sal_uInt16 excCount = 0; - - for (sal_uInt16 i=0; i < methodCount; i++) + assert(seen != 0); + for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i( + entity_->getDirectMethods().begin()); + i != entity_->getDirectMethods().end(); ++i) { - returnType = OUStringToOString( - m_reader.getMethodReturnTypeName(i), RTL_TEXTENCODING_UTF8); - paramCount = m_reader.getMethodParameterCount(i); - excCount = m_reader.getMethodExceptionCount(i); - - if (pFinishedTypes->count(returnType) == 0) - { - pFinishedTypes->insert(returnType); - dumpCppuGetType(o, returnType, sal_True, eDeclFlag); + if (seen->insert(i->returnType).second) { + dumpCppuGetType(out, i->returnType); } - sal_uInt16 j; - for (j=0; j < paramCount; j++) + for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >:: + const_iterator j(i->parameters.begin()); + j != i->parameters.end(); ++j) { - paramType = OUStringToOString( - m_reader.getMethodParameterTypeName(i, j), - RTL_TEXTENCODING_UTF8); - - if (pFinishedTypes->count(paramType) == 0) - { - pFinishedTypes->insert(paramType); - dumpCppuGetType(o, paramType, sal_True, eDeclFlag); + if (seen->insert(j->type).second) { + dumpCppuGetType(out, j->type); } } - - for (j=0; j < excCount; j++) + for (std::vector< OUString >::const_iterator j(i->exceptions.begin()); + j != i->exceptions.end(); ++j) { - excType = OUStringToOString( - m_reader.getMethodExceptionTypeName(i, j), - RTL_TEXTENCODING_UTF8); - if (pFinishedTypes->count(excType) == 0) - { - pFinishedTypes->insert(excType); - dumpCppuGetType(o, excType, sal_True, eDeclFlag); + if (seen->insert(*j).second) { + dumpCppuGetType(out, *j); } } } } void InterfaceType::dumpExceptionSpecification( - FileStream & out, sal_uInt32 methodIndex, bool runtimeException) + FileStream & out, std::vector< OUString > const & exceptions, + bool runtimeException) { - // exception specifications are undesirable in production code, but make + // Exception specifications are undesirable in production code, but make // for useful assertions in debug builds (on platforms where they are - // enforced at runtime) -#ifndef DBG_UTIL - (void) out; - (void) methodIndex; - (void) runtimeException; -#else + // enforced at runtime): +#if !defined DBG_UTIL + out << " /*"; +#endif out << " throw ("; bool first = true; - if (methodIndex <= SAL_MAX_UINT16) { - sal_uInt16 count = m_reader.getMethodExceptionCount( - static_cast< sal_uInt16 >(methodIndex)); - for (sal_uInt16 i = 0; i < count; ++i) { - OUString name( - m_reader.getMethodExceptionTypeName( - static_cast< sal_uInt16 >(methodIndex), i)); - if ( name != "com/sun/star/uno/RuntimeException" ) - { - if (!first) { - out << ", "; - } - first = false; - out << scopedCppName( - OUStringToOString(name, RTL_TEXTENCODING_UTF8)); + for (std::vector< OUString >::const_iterator i(exceptions.begin()); + i != exceptions.end(); ++i) + { + if (*i != "com.sun.star.uno.RuntimeException") { + if (!first) { + out << ", "; } + out << codemaker::cpp::scopedCppName(u2b(*i)); + first = false; } } if (runtimeException) { @@ -2248,54 +1549,38 @@ void InterfaceType::dumpExceptionSpecification( out << "::com::sun::star::uno::RuntimeException"; } out << ")"; +#if !defined DBG_UTIL + out << " */"; #endif } -void InterfaceType::dumpAttributeExceptionSpecification( - FileStream & out, OUString const & name, RTMethodMode sort) -{ - sal_uInt16 methodCount = m_reader.getMethodCount(); - for (sal_uInt16 i = 0; i < methodCount; ++i) { - if (m_reader.getMethodFlags(i) == sort - && m_reader.getMethodName(i) == name) - { - dumpExceptionSpecification(out, i, true); - return; - } - } - dumpExceptionSpecification(out, 0xFFFFFFFF, true); -} - void InterfaceType::dumpExceptionTypeName( - FileStream & out, char const * prefix, sal_uInt32 index, OUString name) + FileStream & out, OUString const & prefix, sal_uInt32 index, + OUString const & name) { - out << indent() << "rtl::OUString the_" << prefix << "ExceptionName" - << index << "( \"" - << OUStringToOString(name, RTL_TEXTENCODING_UTF8).replace('/', '.') - << "\" );\n"; + out << indent() << "::rtl::OUString the_" << prefix << "ExceptionName" + << index << "( \"" << name << "\" );\n"; } sal_Int32 InterfaceType::dumpExceptionTypeNames( - FileStream & out, char const * prefix, sal_uInt16 methodIndex, - bool runtimeException) + FileStream & out, OUString const & prefix, + std::vector< OUString > const & exceptions, bool runtimeException) { sal_Int32 count = 0; - sal_uInt16 n = m_reader.getMethodExceptionCount(methodIndex); - for (sal_uInt16 i = 0; i < n; ++i) { - OUString name(m_reader.getMethodExceptionTypeName(methodIndex, i)); - if ( name != "com/sun/star/uno/RuntimeException" ) - { - dumpExceptionTypeName(out, prefix, count++, name); + for (std::vector< OUString >::const_iterator i(exceptions.begin()); + i != exceptions.end(); ++i) + { + if (*i != "com.sun.star.uno.RuntimeException") { + dumpExceptionTypeName(out, prefix, count++, *i); } } if (runtimeException) { dumpExceptionTypeName( - out, prefix, count++, - OUString("com/sun/star/uno/RuntimeException")); + out, prefix, count++, "com.sun.star.uno.RuntimeException"); } - if (count > 0) { + if (count != 0) { out << indent() << "rtl_uString * the_" << prefix << "Exceptions[] = {"; - for (sal_Int32 i = 0; i < count; ++i) { + for (sal_Int32 i = 0; i != count; ++i) { out << (i == 0 ? " " : ", ") << "the_" << prefix << "ExceptionName" << i << ".pData"; } @@ -2304,480 +1589,736 @@ sal_Int32 InterfaceType::dumpExceptionTypeNames( return count; } -sal_Int32 InterfaceType::dumpAttributeExceptionTypeNames( - FileStream & out, char const * prefix, OUString const & name, - RTMethodMode sort) +class ConstantGroup: public CppuType { +public: + ConstantGroup( + rtl::Reference< unoidl::ConstantGroupEntity > const & entity, + OUString const & name, rtl::Reference< TypeManager > const & typeMgr): + CppuType(name, typeMgr), entity_(entity) + { assert(entity.is()); } + + bool hasConstants() const { return !entity_->getMembers().empty(); } + +private: + virtual void dumpHFile( + FileStream & out, codemaker::cppumaker::Includes & includes); + + virtual void dumpHxxFile( + FileStream & out, codemaker::cppumaker::Includes & includes); + + virtual void dumpDeclaration(FileStream & out); + + rtl::Reference< unoidl::ConstantGroupEntity > entity_; +}; + +void ConstantGroup::dumpHFile( + FileStream & out, codemaker::cppumaker::Includes & includes) { - sal_uInt16 methodCount = m_reader.getMethodCount(); - for (sal_uInt16 i = 0; i < methodCount; ++i) { - if (m_reader.getMethodFlags(i) == sort - && m_reader.getMethodName(i) == name) - { - return dumpExceptionTypeNames(out, prefix, i, false); - } + OUString headerDefine(dumpHeaderDefine(out, "HDL")); + out << "\n"; + addDefaultHIncludes(includes); + includes.dump(out, 0); + out << "\n"; + if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, true)) { + out << "\n"; } - return 0; + out << "\n"; + dumpDeclaration(out); + out << "\n"; + if (codemaker::cppumaker::dumpNamespaceClose(out, name_, true)) { + out << "\n"; + } + out << "\n#endif // "<< headerDefine << "\n"; } -//************************************************************************* -// ConstantsType -//************************************************************************* -ConstantsType::ConstantsType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr) - : CppuType(typeReader, typeName, typeMgr) +void ConstantGroup::dumpHxxFile( + FileStream & out, codemaker::cppumaker::Includes &) { + OUString headerDefine(dumpHeaderDefine(out, "HPP")); + out << "\n"; + codemaker::cppumaker::Includes::dumpInclude(out, u2b(name_), false); + out << "\n#endif // "<< headerDefine << "\n"; } -ConstantsType::~ConstantsType() -{ +void ConstantGroup::dumpDeclaration(FileStream & out) { + for (std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator i( + entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) + { + out << "static const "; + switch (i->value.type) { + case unoidl::ConstantValue::TYPE_BOOLEAN: + out << "::sal_Bool"; + break; + case unoidl::ConstantValue::TYPE_BYTE: + out << "::sal_Int8"; + break; + case unoidl::ConstantValue::TYPE_SHORT: + out << "::sal_Int16"; + break; + case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT: + out << "::sal_uInt16"; + break; + case unoidl::ConstantValue::TYPE_LONG: + out << "::sal_Int32"; + break; + case unoidl::ConstantValue::TYPE_UNSIGNED_LONG: + out << "::sal_uInt32"; + break; + case unoidl::ConstantValue::TYPE_HYPER: + out << "::sal_Int64"; + break; + case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER: + out << "::sal_uInt64"; + break; + case unoidl::ConstantValue::TYPE_FLOAT: + out << "float"; + break; + case unoidl::ConstantValue::TYPE_DOUBLE: + out << "double"; + break; + } + out << " " << i->name << " = "; + switch (i->value.type) { + case unoidl::ConstantValue::TYPE_BOOLEAN: + out << (i->value.booleanValue ? "sal_True" : "sal_False"); + break; + case unoidl::ConstantValue::TYPE_BYTE: + out << "(sal_Int8)" << OUString::number(i->value.byteValue); + break; + case unoidl::ConstantValue::TYPE_SHORT: + out << "(sal_Int16)" << OUString::number(i->value.shortValue); + break; + case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT: + out << "(sal_uInt16)" + << OUString::number(i->value.unsignedShortValue); + break; + case unoidl::ConstantValue::TYPE_LONG: + // Avoid C++ compiler warnings about (un)signedness of literal + // -2^31: + if (i->value.longValue == SAL_MIN_INT32) { + out << "SAL_MIN_INT32"; + } else { + out << "(sal_Int32)" << OUString::number(i->value.longValue); + } + break; + case unoidl::ConstantValue::TYPE_UNSIGNED_LONG: + out << "(sal_uInt32)" + << OUString::number(i->value.unsignedLongValue) << "U"; + break; + case unoidl::ConstantValue::TYPE_HYPER: + // Avoid C++ compiler warnings about (un)signedness of literal + // -2^63: + if (i->value.hyperValue == SAL_MIN_INT64) { + out << "SAL_MIN_INT64"; + } else { + out << "(sal_Int64) SAL_CONST_INT64(" + << OUString::number(i->value.hyperValue) << ")"; + } + break; + case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER: + out << "SAL_CONST_UINT64(" + << OUString::number(i->value.unsignedHyperValue) << ")"; + break; + case unoidl::ConstantValue::TYPE_FLOAT: + out << "(float)" << OUString::number(i->value.floatValue); + break; + case unoidl::ConstantValue::TYPE_DOUBLE: + out << "(double)" << OUString::number(i->value.doubleValue); + break; + } + out << ";\n"; + } +} +void dumpTypeParameterName(FileStream & out, OUString const & name) { + // Prefix all type parameters with "typeparam_" to avoid problems when a + // struct member has the same name as a type parameter, as in + // struct<T> { T T; }; + out << "typeparam_" << name; } -sal_Bool ConstantsType::dump(CppuOptions* pOptions) - throw( CannotDumpException ) -{ - if (!m_dependencies.isValid()) { - return false; - } - addSpecialDependencies(); +class PlainStructType: public CppuType { +public: + PlainStructType( + rtl::Reference< unoidl::PlainStructTypeEntity > const & entity, + OUString const & name, rtl::Reference< TypeManager > const & typeMgr): + CppuType(name, typeMgr), entity_(entity) + { assert(entity.is()); } - if (pOptions->isValid("-U")) - m_cppuTypeDynamic = true; +private: + virtual sal_uInt32 checkInheritedMemberCount() const + { return getTotalMemberCount(entity_->getDirectBase()); } - OString outPath; - if (pOptions->isValid("-O")) - outPath = pOptions->getOption("-O"); + virtual void dumpDeclaration(FileStream& o); - return dumpFiles(pOptions, outPath); -} + void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes); -sal_Bool ConstantsType::dumpHFile( - FileStream& o, codemaker::cppumaker::Includes & includes) - throw( CannotDumpException ) -{ - sal_Bool bSpecialDefine = sal_True; + virtual void dumpLightGetCppuType(FileStream & out); - if (m_reader.getTypeClass() == RT_TYPE_CONSTANTS) - { - bSpecialDefine = sal_False; - } + virtual void dumpNormalGetCppuType(FileStream & out); - OString headerDefine(dumpHeaderDefine(o, "HDL", bSpecialDefine)); - o << "\n"; + virtual void dumpComprehensiveGetCppuType(FileStream & out); - addDefaultHIncludes(includes); - includes.dump(o, 0); - o << "\n"; + virtual void addLightGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const; - if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, true)) { - o << "\n"; - } - o << "\n"; + virtual void addNormalGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const; - dumpDeclaration(o); - o << "\n"; + virtual void addComprehensiveGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const; - if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, true)) { - o << "\n"; - } - o << "\n#endif // "<< headerDefine << "\n"; + bool dumpBaseMembers( + FileStream & out, OUString const & base, bool withType); + + sal_uInt32 getTotalMemberCount(OUString const & base) const; - return sal_True; + rtl::Reference< unoidl::PlainStructTypeEntity > entity_; +}; + +void PlainStructType::dumpDeclaration(FileStream & out) { + out << "\n#ifdef SAL_W32\n# pragma pack(push, 8)\n#endif\n\n" << indent() + << "struct " << id_; + OUString base(entity_->getDirectBase()); + if (!base.isEmpty()) { + out << ": public " << codemaker::cpp::scopedCppName(u2b(base)); + } + out << " {\n"; + inc(); + out << indent() << "inline " << id_ << "() SAL_THROW(());\n"; + if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) { + out << "\n" << indent() << "inline " << id_ << "("; + bool first = !dumpBaseMembers(out, base, true); + for (std::vector< unoidl::PlainStructTypeEntity::Member >:: + const_iterator i(entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) + { + if (!first) { + out << ", "; + } + dumpType(out, i->type, true, true); + out << " " << i->name << "_"; + first = false; + } + out << ") SAL_THROW(());\n"; + } + if (!entity_->getDirectMembers().empty()) { + out << "\n"; + for (std::vector< unoidl::PlainStructTypeEntity::Member >:: + const_iterator i(entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) + { + out << indent(); + dumpType(out, i->type); + out << " " << i->name; + if (i == entity_->getDirectMembers().begin() && !base.isEmpty() + && i->type != "hyper" && i->type != "unsigned hyper" + && i->type != "double") + { + out << " CPPU_GCC3_ALIGN(" + << codemaker::cpp::scopedCppName(u2b(base)) << ")"; + } + out << ";\n"; + } + } + dec(); + out << "};\n\n#ifdef SAL_W32\n# pragma pack(pop)\n#endif\n\n"; } -void ConstantsType::dumpDeclaration(FileStream& o) - throw( CannotDumpException ) +void PlainStructType::dumpHxxFile( + FileStream & out, codemaker::cppumaker::Includes & includes) { - sal_uInt16 fieldCount = m_reader.getFieldCount(); - OString fieldName; - OString fieldType; - for (sal_uInt16 i=0; i < fieldCount; i++) + OUString headerDefine(dumpHeaderDefine(out, "HPP")); + out << "\n"; + includes.dump(out, &name_); + out << "\n"; + if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) { + out << "\n"; + } + out << "\ninline " << id_ << "::" << id_ << "() SAL_THROW(())\n"; + inc(); + OUString base(entity_->getDirectBase()); + bool first = true; + if (!base.isEmpty()) { + out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base)) + << "()\n"; + first = false; + } + for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i( + entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) { - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - fieldType = OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8); - - o << "static const "; - dumpType(o, fieldType); - o << " " << fieldName << " = "; - dumpConstantValue(o, i); - o << ";\n"; + out << indent() << (first ? ":" : ",") << " " << i->name; + dumpInitializer(out, false, i->type); + out << "\n"; + first = false; + } + dec(); + out << "{\n}\n\n"; + if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) { + out << "inline " << id_; + out << "::" << id_ << "("; + first = !dumpBaseMembers(out, base, true); + for (std::vector< unoidl::PlainStructTypeEntity::Member >:: + const_iterator i(entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) + { + if (!first) { + out << ", "; + } + dumpType(out, i->type, true, true); + out << " " << i->name << "_"; + first = false; + } + out << ") SAL_THROW(())\n"; + inc(); + first = true; + if (!base.isEmpty()) { + out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base)) + << "("; + dumpBaseMembers(out, base, false); + out << ")\n"; + first = false; + } + for (std::vector< unoidl::PlainStructTypeEntity::Member >:: + const_iterator i(entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) + { + out << indent() << (first ? ":" : ",") << " " << i->name << "(" + << i->name << "_)\n"; + first = false; + } + dec(); + out << "{\n}\n\n"; } + if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) { + out << "\n"; + } + out << "\n"; + dumpGetCppuType(out); + out << "\n#endif // "<< headerDefine << "\n"; } -sal_Bool ConstantsType::hasConstants() -{ - return m_reader.getFieldCount() > 0; +void PlainStructType::dumpLightGetCppuType(FileStream & out) { + dumpGetCppuTypePreamble(out); + out << indent() + << ("//TODO: On certain platforms with weak memory models, the" + " following code can result in some threads observing that the_type" + " points to garbage\n") + << indent() + << "static ::typelib_TypeDescriptionReference * the_type = 0;\n" + << indent() << "if (the_type == 0) {\n"; + inc(); + out << indent() << "::typelib_static_type_init(&the_type, " + << getTypeClass(name_, true) << ", \"" << name_ << "\");\n"; + dec(); + out << indent() << "}\n" << indent() + << ("return *reinterpret_cast< ::com::sun::star::uno::Type * >(" + "&the_type);\n"); + dumpGetCppuTypePostamble(out); } -sal_Bool ConstantsType::dumpHxxFile( - FileStream& o, codemaker::cppumaker::Includes &) - throw( CannotDumpException ) -{ - sal_Bool bSpecialDefine = sal_True; - - if (m_reader.getTypeClass() == RT_TYPE_CONSTANTS) +void PlainStructType::dumpNormalGetCppuType(FileStream & out) { + dumpGetCppuTypePreamble(out); + out << indent() + << ("//TODO: On certain platforms with weak memory models, the" + " following code can result in some threads observing that the_type" + " points to garbage\n") + << indent() + << "static ::typelib_TypeDescriptionReference * the_type = 0;\n" + << indent() << "if (the_type == 0) {\n"; + inc(); + out << indent() + << "::typelib_TypeDescriptionReference * the_members[] = {\n"; + inc(); + for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i( + entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end();) { - bSpecialDefine = sal_False; + out << indent() << "::cppu::UnoType< "; + dumpType(out, i->type, false, false, false, true); + ++i; + out << " >::get().getTypeLibType()" + << (i == entity_->getDirectMembers().end() ? " };" : ",") << "\n"; } - - OString headerDefine(dumpHeaderDefine(o, "HPP", bSpecialDefine)); - o << "\n"; - - OString suffix; - if (bSpecialDefine) { - suffix = m_name; + dec(); + out << indent() << "::typelib_static_struct_type_init(&the_type, \"" + << name_ << "\", "; + if (entity_->getDirectBase().isEmpty()) { + out << "0"; + } else { + out << "::cppu::UnoType< "; + dumpType(out, entity_->getDirectBase(), false, false, false, true); + out << " >::get().getTypeLibType()"; } - codemaker::cppumaker::Includes::dumpInclude(o, m_typeName, false, suffix); - - o << "\n#endif // "<< headerDefine << "\n"; + out << ", " << entity_->getDirectMembers().size() << ", the_members, 0);\n"; + dec(); + out << indent() << "}\n" << indent() + << ("return *reinterpret_cast< ::com::sun::star::uno::Type * >(" + "&the_type);\n"); + dumpGetCppuTypePostamble(out); +} - return sal_True; +void PlainStructType::dumpComprehensiveGetCppuType(FileStream & out) { + OUString staticTypeClass("the" + id_ + "Type"); + codemaker::cppumaker::dumpNamespaceOpen(out, name_, false); + out << " namespace detail {\n\n" << indent() << "struct " + << staticTypeClass + << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, " + << staticTypeClass << " >\n" << indent() << "{\n"; + inc(); + out << indent() << "::com::sun::star::uno::Type * operator()() const\n" + << indent() << "{\n"; + inc(); + out << indent() << "::rtl::OUString the_name( \"" << name_ << "\" );\n"; + std::map< OUString, sal_uInt32 > parameters; + std::map< OUString, sal_uInt32 > types; + std::vector< unoidl::PlainStructTypeEntity::Member >::size_type n = 0; + for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i( + entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) + { + if (types.insert( + std::map< OUString, sal_uInt32 >::value_type( + i->type, static_cast< sal_uInt32 >(types.size()))). + second) + { + if ((codemaker::UnoType::getSort(u2b(i->type)) + == codemaker::UnoType::SORT_COMPLEX) + && b2u(codemaker::UnoType::decompose(u2b(i->type))) != name_) + // take care of recursion like struct S { sequence<S> x; }; + { + out << indent() << "::cppu::UnoType< "; + dumpType(out, i->type, false, false, false, true); + out << " >::get();\n"; + } + // For typedefs, use the resolved type name, as there will be no + // information available about the typedef itself at runtime (the + // above getCppuType call will make available information about the + // resolved type); no extra #include for the resolved type is + // needed, as the header for the typedef includes it already: + out << indent() << "::rtl::OUString the_tname" + << static_cast< sal_uInt32 >(types.size() - 1) << "( \"" + << resolveAllTypedefs(i->type) << "\" );\n"; + } + out << indent() << "::rtl::OUString the_name" << n++ << "( \"" + << i->name << "\" );\n"; + } + out << indent() << "::typelib_StructMember_Init the_members[] = {\n"; + inc(); + n = 0; + for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i( + entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end();) + { + out << indent() << "{ { " << getTypeClass(i->type, true) + << ", the_tname" << types.find(i->type)->second + << ".pData, the_name" << n++ << ".pData }, false }"; + ++i; + out << (i == entity_->getDirectMembers().end() ? " };" : ",") << "\n"; + } + dec(); + out << indent() << "::typelib_TypeDescription * the_newType = 0;\n" + << indent() + << "::typelib_typedescription_newStruct(&the_newType, the_name.pData, "; + if (entity_->getDirectBase().isEmpty()) { + out << "0"; + } else { + out << "::cppu::UnoType< "; + dumpType(out, entity_->getDirectBase(), false, false, false, true); + out << " >::get().getTypeLibType()"; + } + out << ", " << entity_->getDirectMembers().size() << ", the_members);\n" + << indent() << "::typelib_typedescription_register(&the_newType);\n" + << indent() << "::typelib_typedescription_release(the_newType);\n" + << indent() << "return new ::com::sun::star::uno::Type(" + << getTypeClass(name_) << ", the_name); // leaked\n"; + dec(); + out << indent() << "}\n"; + dec(); + out << indent() << "};\n"; + codemaker::cppumaker::dumpNamespaceClose(out, name_, false); + out << " }\n\n"; + dumpGetCppuTypePreamble(out); + out << indent() << "return *detail::" << staticTypeClass << "::get();\n"; + dumpGetCppuTypePostamble(out); } -//************************************************************************* -// ModuleType -//************************************************************************* -ModuleType::ModuleType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr) - : ConstantsType(typeReader, typeName, typeMgr) +bool PlainStructType::dumpBaseMembers( + FileStream & out, OUString const & base, bool withType) { + bool hasMember = false; + if (!base.isEmpty()) { + rtl::Reference< unoidl::Entity > ent; + codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent); + if (sort != codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE) { + throw CannotDumpException( + "plain struct type base " + base + + " is not a plain struct type"); + } + rtl::Reference< unoidl::PlainStructTypeEntity > ent2( + dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get())); + assert(ent2.is()); + hasMember = dumpBaseMembers(out, ent2->getDirectBase(), withType); + for (std::vector< unoidl::PlainStructTypeEntity::Member >:: + const_iterator i(ent2->getDirectMembers().begin()); + i != ent2->getDirectMembers().end(); ++i) + { + if (hasMember) { + out << ", "; + } + if (withType) { + dumpType(out, i->type, true, true); + out << " "; + } + out << i->name << "_"; + hasMember = true; + } + } + return hasMember; } -ModuleType::~ModuleType() +void PlainStructType::addLightGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const { + includes.addType(); + includes.addCppuUnotypeHxx(); + includes.addSalTypesH(); + includes.addTypelibTypeclassH(); + includes.addTypelibTypedescriptionH(); +} +void PlainStructType::addNormalGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const +{ + includes.addType(); + includes.addCppuUnotypeHxx(); + includes.addSalTypesH(); + includes.addTypelibTypeclassH(); + includes.addTypelibTypedescriptionH(); } -bool ModuleType::dumpFiles( - CppuOptions * options, OString const & outPath) +void PlainStructType::addComprehensiveGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const { - OString tmpName(m_typeName); - if (tmpName == "/") { - tmpName = "global"; - } else { - tmpName += "/" + m_typeName.copy(m_typeName.lastIndexOf('/') + 1); + includes.addType(); + includes.addCppuUnotypeHxx(); + includes.addRtlInstanceHxx(); + includes.addOslMutexHxx(); + includes.addRtlUstringH(); + includes.addRtlUstringHxx(); + includes.addSalTypesH(); + includes.addTypelibTypeclassH(); + includes.addTypelibTypedescriptionH(); +} + +sal_uInt32 PlainStructType::getTotalMemberCount(OUString const & base) const { + if (base.isEmpty()) { + return 0; + } + rtl::Reference< unoidl::Entity > ent; + codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent); + if (sort != codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE) { + throw CannotDumpException( + "plain struct type base " + base + " is not a plain struct type"); } - return dumpFile(options, ".hdl", tmpName, outPath) - && dumpFile(options, ".hpp", tmpName, outPath); + rtl::Reference< unoidl::PlainStructTypeEntity > ent2( + dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get())); + assert(ent2.is()); + return getTotalMemberCount(ent2->getDirectBase()) + + ent2->getDirectMembers().size(); //TODO: overflow } -//************************************************************************* -// StructureType -//************************************************************************* +class PolyStructType: public CppuType { +public: + PolyStructType( + rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const & + entity, + OUString const & name, rtl::Reference< TypeManager > const & typeMgr): + CppuType(name, typeMgr), entity_(entity) + { assert(entity.is()); } -namespace { +private: + virtual void dumpDeclaration(FileStream& o); -void dumpTypeParameterName(FileStream & out, OString const & name) { - // Prefix all type parameters with "typeparam_" to avoid problems when a - // struct member has the same name as a type parameter, as in - // struct<T> { T T; }; - out << "typeparam_" << name; -} + void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes); -} + virtual void dumpLightGetCppuType(FileStream & out); -StructureType::StructureType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr) - : CppuType(typeReader, typeName, typeMgr) -{ -} + virtual void dumpNormalGetCppuType(FileStream & out); -StructureType::~StructureType() -{ + virtual void dumpComprehensiveGetCppuType(FileStream & out); -} + virtual void addLightGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const; -sal_Bool StructureType::dumpHFile( - FileStream& o, codemaker::cppumaker::Includes & includes) - throw( CannotDumpException ) -{ - dumpHFileContent(o, includes); - return sal_True; -} + virtual void addNormalGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const; -void StructureType::dumpDeclaration(FileStream& o) - throw( CannotDumpException ) -{ - o << "\n#ifdef SAL_W32\n" - << "# pragma pack(push, 8)\n" - << "#endif\n\n"; - - OSL_ASSERT(!isPolymorphic() || m_reader.getSuperTypeCount() == 0); //TODO - o << indent(); - dumpTemplateHead(o); - o << "struct " << m_name; - OString base; - if (m_reader.getSuperTypeCount() != 0) { - base = OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8); - OSL_ASSERT(!base.isEmpty()); //TODO - } - if (!base.isEmpty()) { - o << ": public " << scopedCppName(base); - } - o << " {\n"; + virtual void addComprehensiveGetCppuTypeIncludes( + codemaker::cppumaker::Includes & includes) const; + + virtual bool isPolymorphic() const { return true; } + + virtual void dumpTemplateHead(FileStream & out) const; + + virtual void dumpTemplateParameters(FileStream & out) const; + + rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_; +}; + +void PolyStructType::dumpDeclaration(FileStream & out) { + out << "\n#ifdef SAL_W32\n# pragma pack(push, 8)\n#endif\n\n" << indent(); + dumpTemplateHead(out); + out << "struct " << id_ << " {\n"; inc(); - o << indent() << "inline " << m_name << "() SAL_THROW(());\n"; - sal_uInt16 members = m_reader.getFieldCount(); - if (members > 0 || getInheritedMemberCount() > 0) { - o << "\n" << indent() << "inline " << m_name << "("; - bool prev = dumpSuperMember(o, base, true); - for (sal_uInt16 i = 0; i < members; ++i) { - if (prev) { - o << ", "; + out << indent() << "inline " << id_ << "() SAL_THROW(());\n"; + if (!entity_->getMembers().empty()) { + out << "\n" << indent() << "inline " << id_ << "("; + for (std::vector< + unoidl::PolymorphicStructTypeTemplateEntity::Member >:: + const_iterator i(entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) + { + if (i != entity_->getMembers().begin()) { + out << ", "; } - prev = true; - OString type( - OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8)); - if ((m_reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) != 0) - { - dumpTypeParameterName(o, type); - o << " const &"; + if (i->parameterized) { + dumpTypeParameterName(out, i->type); + out << " const &"; } else { - dumpType(o, type, true, true); + dumpType(out, i->type, true, true); } - o << " " - << OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8) - << "_"; + out << " " << i->name << "_"; } - o << ") SAL_THROW(());\n"; - } - if (members > 0) { - o << "\n"; - for (sal_uInt16 i = 0; i < members; ++i) { - o << indent(); - bool parameterized - = ((m_reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) - != 0); - OString type( - OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8)); - if (parameterized) { - dumpTypeParameterName(o, type); + out << ") SAL_THROW(());\n\n"; + for (std::vector< + unoidl::PolymorphicStructTypeTemplateEntity::Member >:: + const_iterator i(entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) + { + out << indent(); + if (i->parameterized) { + dumpTypeParameterName(out, i->type); } else { - dumpType(o, type); - } - o << " " - << OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - if (i == 0 && !base.isEmpty() && type != "double" - && type != "hyper" && type != "unsigned hyper") - { - OSL_ASSERT(!parameterized); - o << " CPPU_GCC3_ALIGN(" << scopedCppName(base) << ")"; + dumpType(out, i->type); } - o << ";\n"; + out << " " << i->name << ";\n"; } } dec(); - o << "};\n\n"; - - o << "#ifdef SAL_W32\n" - << "# pragma pack(pop)\n" - << "#endif\n\n"; + out << "};\n\n#ifdef SAL_W32\n# pragma pack(pop)\n#endif\n\n"; } -sal_Bool StructureType::dumpHxxFile( - FileStream& o, codemaker::cppumaker::Includes & includes) - throw( CannotDumpException ) +void PolyStructType::dumpHxxFile( + FileStream & out, codemaker::cppumaker::Includes & includes) { - OString headerDefine(dumpHeaderDefine(o, "HPP")); - o << "\n"; - - includes.dump(o, &m_typeName); - o << "\n"; - - if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) { - o << "\n"; + OUString headerDefine(dumpHeaderDefine(out, "HPP")); + out << "\n"; + includes.dump(out, &name_); + out << "\n"; + if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) { + out << "\n"; } - o << "\n"; - - dumpTemplateHead(o); - o << "inline " << m_name; - dumpTemplateParameters(o); - o << "::" << m_name << "() SAL_THROW(())\n"; + out << "\n"; + dumpTemplateHead(out); + out << "inline " << id_; + dumpTemplateParameters(out); + out << "::" << id_ << "() SAL_THROW(())\n"; inc(); - OString superType; - if (m_reader.getSuperTypeCount() >= 1) { - superType = OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8); - } - sal_Bool first = sal_True; - if (!superType.isEmpty()) + for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >:: + const_iterator i(entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) { - o << indent() << ": " << scopedCppName(superType) << "()\n"; - first = sal_False; - } - - sal_uInt16 fieldCount = m_reader.getFieldCount(); - RTFieldAccess access = RT_ACCESS_INVALID; - OString fieldName; - OString fieldType; - - for (sal_uInt16 i=0; i < fieldCount; i++) - { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - - if (first) - { - first = sal_False; - o << indent() << ": "; - } else - o << indent() << ", "; - - o << fieldName; - dumpInitializer( - o, (access & RT_ACCESS_PARAMETERIZED_TYPE) != 0, - m_reader.getFieldTypeName(i)); - o << "\n"; + out << indent() << (i == entity_->getMembers().begin() ? ":" : ",") + << " " << i->name; + dumpInitializer(out, i->parameterized, i->type); + out << "\n"; } dec(); - o << "{\n}\n\n"; - - if (fieldCount > 0 || getInheritedMemberCount() > 0) - { - dumpTemplateHead(o); - o << "inline " << m_name; - dumpTemplateParameters(o); - o << "::" << m_name << "("; - - sal_Bool superHasMember = dumpSuperMember(o, superType, sal_True); - - for (sal_uInt16 i=0; i < fieldCount; i++) + out << "{\n}\n\n"; + if (!entity_->getMembers().empty()) { + dumpTemplateHead(out); + out << "inline " << id_; + dumpTemplateParameters(out); + out << "::" << id_ << "("; + for (std::vector< + unoidl::PolymorphicStructTypeTemplateEntity::Member >:: + const_iterator i(entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - fieldType = OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8); - - if (superHasMember) - o << ", "; - else - superHasMember = sal_True; - - if ((access & RT_ACCESS_PARAMETERIZED_TYPE) != 0) { - dumpTypeParameterName(o, fieldType); - o << " const &"; + if (i != entity_->getMembers().begin()) { + out << ", "; + } + if (i->parameterized) { + dumpTypeParameterName(out, i->type); + out << " const &"; } else { - dumpType(o, fieldType, sal_True, sal_True); + dumpType(out, i->type, true, true); } - o << " " << fieldName << "_"; + out << " " << i->name << "_"; } - o << ") SAL_THROW(())\n"; - + out << ") SAL_THROW(())\n"; inc(); - first = sal_True; - if (!superType.isEmpty()) - { - o << indent() << ": " << scopedCppName(superType) << "("; - dumpSuperMember(o, superType, sal_False); - o << ")\n"; - first = sal_False; - } - - for (sal_uInt16 i=0; i < fieldCount; i++) + for (std::vector< + unoidl::PolymorphicStructTypeTemplateEntity::Member >:: + const_iterator i(entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - - if (first) - { - first = sal_False; - o << indent() << ": "; - } else - o << indent() << ", "; - - o << fieldName << "(" << fieldName << "_)\n"; + out << indent() << (i == entity_->getMembers().begin() ? ":" : ",") + << " " << i->name << "(" << i->name << "_)\n"; } - dec(); - o << "{\n}\n\n"; - } - - if (isPolymorphic() && fieldCount > 0) { - o << indent(); - dumpTemplateHead(o); - o << "\n"; - o << indent(); - o << "inline " << m_name; - dumpTemplateParameters(o); - o << "\n"; - o << indent(); - o << "make_" << m_name << "("; - for (sal_uInt16 i = 0; i < fieldCount; ++i) { - if (i > 0) { - o << ", "; + out << "{\n}\n\n" << indent(); + dumpTemplateHead(out); + out << "\n" << indent() << "inline " << id_; + dumpTemplateParameters(out); + out << "\n" << indent() << "make_" << id_ << "("; + for (std::vector< + unoidl::PolymorphicStructTypeTemplateEntity::Member >:: + const_iterator i(entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) + { + if (i != entity_->getMembers().begin()) { + out << ", "; } - OString type( - OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8)); - if ((m_reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) != 0) - { - dumpTypeParameterName(o, type); - o << " const &"; + if (i->parameterized) { + dumpTypeParameterName(out, i->type); + out << " const &"; } else { - dumpType(o, type, true, true); + dumpType(out, i->type, true, true); } - o << " " - << OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8) - << "_"; + out << " " << i->name << "_"; } - o << ") SAL_THROW(())\n"; - o << indent() << "{\n"; + out << ") SAL_THROW(())\n" << indent() << "{\n"; inc(); - o << indent() << "return " << m_name; - dumpTemplateParameters(o); - o << "("; - for (sal_uInt16 i = 0; i < fieldCount; ++i) { - if (i > 0) { - o << ", "; + out << indent() << "return " << id_; + dumpTemplateParameters(out); + out << "("; + for (std::vector< + unoidl::PolymorphicStructTypeTemplateEntity::Member >:: + const_iterator i(entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) + { + if (i != entity_->getMembers().begin()) { + out << ", "; } - o << OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8) - << "_"; + out << i->name << "_"; } - o << ");\n"; + out << ");\n"; dec(); - o << indent() << "}\n\n"; + out << indent() << "}\n\n"; } - - if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) { - o << "\n"; + if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) { + out << "\n"; } - - o << "\n"; - dumpGetCppuType(o); - - o << "\n#endif // "<< headerDefine << "\n"; - - return sal_True; + out << "\n"; + dumpGetCppuType(out); + out << "\n#endif // "<< headerDefine << "\n"; } -void StructureType::dumpLightGetCppuType(FileStream & out) { +void PolyStructType::dumpLightGetCppuType(FileStream & out) { dumpGetCppuTypePreamble(out); out << indent() << ("//TODO: On certain platforms with weak memory models, the" @@ -2787,33 +2328,25 @@ void StructureType::dumpLightGetCppuType(FileStream & out) { << "static ::typelib_TypeDescriptionReference * the_type = 0;\n" << indent() << "if (the_type == 0) {\n"; inc(); - if (isPolymorphic()) { - out << indent() << "OStringBuffer the_buffer(\"" - << m_typeName.replace('/', '.') << "<\");\n"; - sal_uInt16 n = m_reader.getReferenceCount(); - for (sal_uInt16 i = 0; i < n; ++i) { - out << indent() - << ("the_buffer.append(rtl::OUStringToOString(" - "::cppu::getTypeFavourChar(static_cast< "); - dumpTypeParameterName( - out, - OUStringToOString( - m_reader.getReferenceTypeName(i), RTL_TEXTENCODING_UTF8)); - out << " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n"; - if (i != n - 1) { - out << indent() << "the_buffer.append(',');\n"; - } - } - out << indent() << "the_buffer.append('>');\n"; - } - out << indent() << "::typelib_static_type_init(&the_type, " - << getTypeClass(m_typeName, true) << ", "; - if (isPolymorphic()) { - out << "the_buffer.getStr()"; - } else { - out << "\"" << m_typeName.replace('/', '.') << "\""; - } - out << ");\n"; + out << indent() << "::rtl::OStringBuffer the_buffer(\"" << name_ + << "<\");\n"; + for (std::vector< OUString >::const_iterator i( + entity_->getTypeParameters().begin()); + i != entity_->getTypeParameters().end();) + { + out << indent() + << ("the_buffer.append(::rtl::OUStringToOString(" + "::cppu::getTypeFavourChar(static_cast< "); + dumpTypeParameterName(out, *i); + out << " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n"; + ++i; + if (i != entity_->getTypeParameters().end()) { + out << indent() << "the_buffer.append(',');\n"; + } + } + out << indent() << "the_buffer.append('>');\n" << indent() + << "::typelib_static_type_init(&the_type, " << getTypeClass(name_, true) + << ", the_buffer.getStr());\n"; dec(); out << indent() << "}\n" << indent() << ("return *reinterpret_cast< ::com::sun::star::uno::Type * >(" @@ -2821,7 +2354,7 @@ void StructureType::dumpLightGetCppuType(FileStream & out) { dumpGetCppuTypePostamble(out); } -void StructureType::dumpNormalGetCppuType(FileStream & out) { +void PolyStructType::dumpNormalGetCppuType(FileStream & out) { dumpGetCppuTypePreamble(out); out << indent() << ("//TODO: On certain platforms with weak memory models, the" @@ -2831,80 +2364,59 @@ void StructureType::dumpNormalGetCppuType(FileStream & out) { << "static ::typelib_TypeDescriptionReference * the_type = 0;\n" << indent() << "if (the_type == 0) {\n"; inc(); - if (isPolymorphic()) { - out << indent() << "OStringBuffer the_buffer(\"" - << m_typeName.replace('/', '.') << "<\");\n"; - sal_uInt16 n = m_reader.getReferenceCount(); - for (sal_uInt16 i = 0; i < n; ++i) { - out << indent() - << ("the_buffer.append(rtl::OUStringToOString(" - "::cppu::getTypeFavourChar(static_cast< "); - dumpTypeParameterName( - out, - OUStringToOString( - m_reader.getReferenceTypeName(i), RTL_TEXTENCODING_UTF8)); - out << " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n"; - if (i != n - 1) { - out << indent() << "the_buffer.append(',');\n"; - } + out << indent() << "::rtl::OStringBuffer the_buffer(\"" << name_ + << "<\");\n"; + for (std::vector< OUString >::const_iterator i( + entity_->getTypeParameters().begin()); + i != entity_->getTypeParameters().end();) + { + out << indent() + << ("the_buffer.append(::rtl::OUStringToOString(" + "::cppu::getTypeFavourChar(static_cast< "); + dumpTypeParameterName(out, *i); + out << " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n"; + ++i; + if (i != entity_->getTypeParameters().end()) { + out << indent() << "the_buffer.append(',');\n"; } - out << indent() << "the_buffer.append('>');\n"; } - out << indent() + out << indent() << "the_buffer.append('>');\n" << indent() << "::typelib_TypeDescriptionReference * the_members[] = {\n"; inc(); - sal_uInt16 fields = m_reader.getFieldCount(); - for (sal_uInt16 i = 0; i < fields; ++i) { + for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >:: + const_iterator i(entity_->getMembers().begin()); + i != entity_->getMembers().end();) + { out << indent(); - OString type( - OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8)); - if ((m_reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) != 0) { + if (i->parameterized) { out << "::cppu::getTypeFavourChar(static_cast< "; - dumpTypeParameterName(out, type); + dumpTypeParameterName(out, i->type); out << " * >(0))"; } else { out << "::cppu::UnoType< "; - dumpType(out, type, false, false, false, true); + dumpType(out, i->type, false, false, false, true); out << " >::get()"; } - out << ".getTypeLibType()" << (i == fields - 1 ? " };" : ",") - << "\n"; + ++i; + out << ".getTypeLibType()" + << (i == entity_->getMembers().end() ? " };" : ",") << "\n"; } dec(); - if (isPolymorphic()) { - out << indent() - << "static ::sal_Bool const the_parameterizedTypes[] = { "; - for (sal_uInt16 i = 0; i < fields; ++i) { - if (i != 0) { - out << ", "; - } - out << (((m_reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) - == 0) - ? "false" : "true"); + out << indent() << "static ::sal_Bool const the_parameterizedTypes[] = { "; + for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >:: + const_iterator i(entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) + { + if (i != entity_->getMembers().begin()) { + out << ", "; } - out << " };\n"; - } - out << indent() << "::typelib_static_struct_type_init(&the_type, "; - if (isPolymorphic()) { - out << "the_buffer.getStr()"; - } else { - out << "\"" << m_typeName.replace('/', '.') << "\""; - } - out << ", "; - if (m_reader.getSuperTypeCount() == 0) { - out << "0"; - } else { - out << "::cppu::UnoType< "; - dumpType( - out, - OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8), - false, false, false, true); - out << " >::get().getTypeLibType()"; + out << (i->parameterized ? "true" : "false"); } - out << ", " << fields << ", the_members, " - << (isPolymorphic() ? "the_parameterizedTypes" : "0") << ");\n"; + out << " };\n" << indent() + << ("::typelib_static_struct_type_init(&the_type, the_buffer.getStr()," + " 0, ") + << entity_->getMembers().size() + << ", the_members, the_parameterizedTypes);\n"; dec(); out << indent() << "}\n" << indent() << ("return *reinterpret_cast< ::com::sun::star::uno::Type * >(" @@ -2912,97 +2424,77 @@ void StructureType::dumpNormalGetCppuType(FileStream & out) { dumpGetCppuTypePostamble(out); } -void StructureType::dumpComprehensiveGetCppuType(FileStream & out) -{ - if (!isPolymorphic()) - codemaker::cppumaker::dumpNamespaceOpen(out, m_typeName, false); - else - out << "namespace cppu { "; - out << " namespace detail {\n\n"; - - OString sType = m_typeName.copy(m_typeName.lastIndexOf('/') + 1); - OString sStaticTypeClass = "the" + sType + "Type"; - out << indent(); - if (isPolymorphic()) - dumpTemplateHead(out); - out << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, "; - out << sStaticTypeClass; - if (isPolymorphic()) - dumpTemplateParameters(out); - out << " >\n"; - - out << indent() << "{\n"; +void PolyStructType::dumpComprehensiveGetCppuType(FileStream & out) { + out << "namespace cppu { namespace detail {\n\n" << indent(); + dumpTemplateHead(out); + OUString staticTypeClass("the" + id_ + "Type"); + out << "struct " << staticTypeClass + << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, " + << staticTypeClass; + dumpTemplateParameters(out); + out << " >\n" << indent() << "{\n"; inc(); - out << indent() << "::com::sun::star::uno::Type * operator()() const\n"; - out << indent() << "{\n"; - + out << indent() << "::com::sun::star::uno::Type * operator()() const\n" + << indent() << "{\n"; inc(); - if (isPolymorphic()) { - out << indent() << "::rtl::OUStringBuffer the_buffer;\n" << indent() - << "the_buffer.append(\"" - << m_typeName.replace('/', '.') << "<\");\n"; - sal_uInt16 n = m_reader.getReferenceCount(); - for (sal_uInt16 i = 0; i < n; ++i) { + out << indent() << "::rtl::OUStringBuffer the_buffer;\n" << indent() + << "the_buffer.append(\"" << name_ << "<\");\n"; + for (std::vector< OUString >::const_iterator i( + entity_->getTypeParameters().begin()); + i != entity_->getTypeParameters().end();) + { + out << indent() + << "the_buffer.append(::cppu::getTypeFavourChar(static_cast< "; + dumpTypeParameterName(out, *i); + out << " * >(0)).getTypeName());\n"; + ++i; + if (i != entity_->getTypeParameters().end()) { out << indent() - << "the_buffer.append(::cppu::getTypeFavourChar(static_cast< "; - dumpTypeParameterName( - out, - OUStringToOString( - m_reader.getReferenceTypeName(i), RTL_TEXTENCODING_UTF8)); - out << " * >(0)).getTypeName());\n"; - if (i != n - 1) { - out << indent() - << ("the_buffer.append(" - "static_cast< ::sal_Unicode >(','));\n"); - } + << ("the_buffer.append(" + "static_cast< ::sal_Unicode >(','));\n"); } - out << indent() - << "the_buffer.append(static_cast< ::sal_Unicode >('>'));\n" - << indent() - << "::rtl::OUString the_name(the_buffer.makeStringAndClear());\n"; - } else { - out << indent() - << "::rtl::OUString the_name( \"" - << m_typeName.replace('/', '.') << "\" );\n"; } - sal_uInt16 fields = m_reader.getFieldCount(); - typedef std::map< OString, sal_uInt32 > Map; - Map parameters; - Map types; - for (sal_uInt16 i = 0; i < fields; ++i) { - OString type( - OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8)); - if ((m_reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) != 0) { + out << indent() << "the_buffer.append(static_cast< ::sal_Unicode >('>'));\n" + << indent() + << "::rtl::OUString the_name(the_buffer.makeStringAndClear());\n"; + std::map< OUString, sal_uInt32 > parameters; + std::map< OUString, sal_uInt32 > types; + std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >:: + size_type n = 0; + for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >:: + const_iterator i(entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) + { + if (i->parameterized) { if (parameters.insert( - Map::value_type( - type, static_cast< sal_uInt32 >(parameters.size()))). + std::map< OUString, sal_uInt32 >::value_type( + i->type, static_cast< sal_uInt32 >(parameters.size()))). second) { - sal_uInt32 n = static_cast< sal_uInt32 >(parameters.size() - 1); + sal_uInt32 k = static_cast< sal_uInt32 >(parameters.size() - 1); out << indent() - << "::com::sun::star::uno::Type const & the_ptype" << n + << "::com::sun::star::uno::Type const & the_ptype" << k << " = ::cppu::getTypeFavourChar(static_cast< "; - dumpTypeParameterName(out, type); + dumpTypeParameterName(out, i->type); out << " * >(0));\n" << indent() - << "::typelib_TypeClass the_pclass" << n - << " = (::typelib_TypeClass) the_ptype" << n + << "::typelib_TypeClass the_pclass" << k + << " = (::typelib_TypeClass) the_ptype" << k << ".getTypeClass();\n" << indent() - << "rtl::OUString the_pname" << n << "(the_ptype" << n + << "::rtl::OUString the_pname" << k << "(the_ptype" << k << ".getTypeName());\n"; } } else if (types.insert( - Map::value_type( - type, static_cast< sal_uInt32 >(types.size()))). + std::map< OUString, sal_uInt32 >::value_type( + i->type, static_cast< sal_uInt32 >(types.size()))). second) { - if ((codemaker::UnoType::getSort(type) == - codemaker::UnoType::SORT_COMPLEX) && - codemaker::UnoType::decompose(type) != m_typeName) + if ((codemaker::UnoType::getSort(u2b(i->type)) + == codemaker::UnoType::SORT_COMPLEX) + && b2u(codemaker::UnoType::decompose(u2b(i->type))) != name_) // take care of recursion like struct S { sequence<S> x; }; { out << indent() << "::cppu::UnoType< "; - dumpType(out, type, false, false, false, true); + dumpType(out, i->type, false, false, false, true); out << " >::get();\n"; } // For typedefs, use the resolved type name, as there will be no @@ -3010,132 +2502,55 @@ void StructureType::dumpComprehensiveGetCppuType(FileStream & out) // above getCppuType call will make available information about the // resolved type); no extra #include for the resolved type is // needed, as the header for the typedef includes it already: - out << indent() << "rtl::OUString the_tname" - << static_cast< sal_uInt32 >(types.size() - 1) - << "( \"" - << checkRealBaseType(type, true).replace('/', '.') << "\" );\n"; + out << indent() << "::rtl::OUString the_tname" + << static_cast< sal_uInt32 >(types.size() - 1) << "( \"" + << resolveAllTypedefs(i->type) << "\" );\n"; } - out << indent() << "rtl::OUString the_name" << i - << "( \"" - << OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8).replace( - '/', '.') - << "\" );\n"; + out << indent() << "::rtl::OUString the_name" << n++ << "( \"" + << i->name << "\" );\n"; } out << indent() << "::typelib_StructMember_Init the_members[] = {\n"; inc(); - for (sal_uInt16 i = 0; i < fields; ++i) { + n = 0; + for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >:: + const_iterator i(entity_->getMembers().begin()); + i != entity_->getMembers().end();) + { out << indent() << "{ { "; - OString type( - OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8)); - if ((m_reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) != 0) { - sal_uInt32 n = parameters.find(type)->second; - out << "the_pclass" << n << ", the_pname" << n << ".pData"; + if (i->parameterized) { + sal_uInt32 k = parameters.find(i->type)->second; + out << "the_pclass" << k << ", the_pname" << k << ".pData"; } else { - out << getTypeClass(type, true) << ", the_tname" - << types.find(type)->second << ".pData"; + out << getTypeClass(i->type, true) << ", the_tname" + << types.find(i->type)->second << ".pData"; } - out << ", the_name" << i << ".pData }, " - << ((m_reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) == 0 - ? "false" : "true") - << " }" << (i == fields - 1 ? " };" : ",") << "\n"; + out << ", the_name" << n++ << ".pData }, " + << (i->parameterized ? "true" : "false") << " }"; + ++i; + out << (i == entity_->getMembers().end() ? " };" : ",") << "\n"; } dec(); out << indent() << "::typelib_TypeDescription * the_newType = 0;\n"; out << indent() - << "::typelib_typedescription_newStruct(&the_newType, the_name.pData, "; - if (m_reader.getSuperTypeCount() == 0) { - out << "0"; - } else { - out << "::cppu::UnoType< "; - dumpType( - out, - OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8), - false, false, false, true); - out << " >::get().getTypeLibType()"; - } - out << ", " << fields << ", the_members);\n"; - out << indent() << "::typelib_typedescription_register(&the_newType);\n"; - out << indent() << "::typelib_typedescription_release(the_newType);\n"; - - out << indent() << "return new ::com::sun::star::uno::Type(" - << getTypeClass(m_typeName) << ", the_name); // leaked\n"; + << ("::typelib_typedescription_newStruct(&the_newType, the_name.pData," + " 0, ") + << entity_->getMembers().size() << ", the_members);\n" << indent() + << "::typelib_typedescription_register(&the_newType);\n" << indent() + << "::typelib_typedescription_release(the_newType);\n" << indent() + << "return new ::com::sun::star::uno::Type(" << getTypeClass(name_) + << ", the_name); // leaked\n"; dec(); out << indent() << "}\n"; dec(); - out << indent() << "};\n"; - - if (!isPolymorphic()) - codemaker::cppumaker::dumpNamespaceClose(out, m_typeName, false); - else - out << " }"; - out << " }\n\n"; - + out << indent() << "};\n" << " }" << " }\n\n"; dumpGetCppuTypePreamble(out); - out << indent() << "return *detail::" << sStaticTypeClass; - if (isPolymorphic()) - dumpTemplateParameters(out); - out << "::get();\n"; + out << indent() << "return *detail::" << staticTypeClass; + dumpTemplateParameters(out); + out << "::get();\n"; dumpGetCppuTypePostamble(out); } -sal_Bool StructureType::dumpSuperMember(FileStream& o, const OString& superType, sal_Bool bWithType) -{ - sal_Bool hasMember = sal_False; - - if (!superType.isEmpty()) - { - typereg::Reader aSuperReader(m_typeMgr->getTypeReader(superType)); - - if (aSuperReader.isValid()) - { - OString superSuper; - if (aSuperReader.getSuperTypeCount() >= 1) { - superSuper = OUStringToOString( - aSuperReader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8); - } - hasMember = dumpSuperMember(o, superSuper, bWithType); - - sal_uInt16 fieldCount = aSuperReader.getFieldCount(); - RTFieldAccess access = RT_ACCESS_INVALID; - OString fieldName; - OString fieldType; - for (sal_uInt16 i=0; i < fieldCount; i++) - { - access = aSuperReader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - fieldName = OUStringToOString( - aSuperReader.getFieldName(i), RTL_TEXTENCODING_UTF8); - fieldType = OUStringToOString( - aSuperReader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8); - - if (hasMember) - { - o << ", "; - } else - { - hasMember = (fieldCount > 0); - } - - if (bWithType) - { - dumpType(o, fieldType, sal_True, sal_True); - o << " "; - } - o << fieldName << "_"; - } - } - } - - return hasMember; -} - -void StructureType::addLightGetCppuTypeIncludes( +void PolyStructType::addLightGetCppuTypeIncludes( codemaker::cppumaker::Includes & includes) const { includes.addType(); @@ -3143,14 +2558,12 @@ void StructureType::addLightGetCppuTypeIncludes( includes.addSalTypesH(); includes.addTypelibTypeclassH(); includes.addTypelibTypedescriptionH(); - if (isPolymorphic()) { - includes.addRtlStrbufHxx(); - includes.addRtlTextencH(); - includes.addRtlUstringHxx(); - } + includes.addRtlStrbufHxx(); + includes.addRtlTextencH(); + includes.addRtlUstringHxx(); } -void StructureType::addNormalGetCppuTypeIncludes( +void PolyStructType::addNormalGetCppuTypeIncludes( codemaker::cppumaker::Includes & includes) const { includes.addType(); @@ -3158,14 +2571,12 @@ void StructureType::addNormalGetCppuTypeIncludes( includes.addSalTypesH(); includes.addTypelibTypeclassH(); includes.addTypelibTypedescriptionH(); - if (isPolymorphic()) { - includes.addRtlStrbufHxx(); - includes.addRtlTextencH(); - includes.addRtlUstringHxx(); - } + includes.addRtlStrbufHxx(); + includes.addRtlTextencH(); + includes.addRtlUstringHxx(); } -void StructureType::addComprehensiveGetCppuTypeIncludes( +void PolyStructType::addComprehensiveGetCppuTypeIncludes( codemaker::cppumaker::Includes & includes) const { includes.addType(); @@ -3177,479 +2588,522 @@ void StructureType::addComprehensiveGetCppuTypeIncludes( includes.addSalTypesH(); includes.addTypelibTypeclassH(); includes.addTypelibTypedescriptionH(); - if (isPolymorphic()) { - includes.addRtlStringH(); - includes.addRtlUstrbufHxx(); - } + includes.addRtlStringH(); + includes.addRtlUstrbufHxx(); } -bool StructureType::isPolymorphic() const { - return m_reader.getReferenceCount() > 0; -} - -void StructureType::dumpTemplateHead(FileStream & out) const { - if (isPolymorphic()) { - out << "template< "; - for (sal_uInt16 i = 0; i < m_reader.getReferenceCount(); ++i) { - if (i != 0) { - out << ", "; - } - OSL_ASSERT( - m_reader.getReferenceFlags(i) == RT_ACCESS_INVALID - && m_reader.getReferenceSort(i) == RT_REF_TYPE_PARAMETER); - out << "typename "; - dumpTypeParameterName( - out, - OUStringToOString( - m_reader.getReferenceTypeName(i), RTL_TEXTENCODING_UTF8)); +void PolyStructType::dumpTemplateHead(FileStream & out) const { + out << "template< "; + for (std::vector< OUString >::const_iterator i( + entity_->getTypeParameters().begin()); + i != entity_->getTypeParameters().end(); ++i) + { + if (i != entity_->getTypeParameters().begin()) { + out << ", "; } - out << " > "; + out << "typename "; + dumpTypeParameterName(out, *i); } + out << " > "; } -void StructureType::dumpTemplateParameters(FileStream & out) const { - if (isPolymorphic()) { - out << "< "; - for (sal_uInt16 i = 0; i < m_reader.getReferenceCount(); ++i) { - if (i != 0) { - out << ", "; - } - OSL_ASSERT( - m_reader.getReferenceFlags(i) == RT_ACCESS_INVALID - && m_reader.getReferenceSort(i) == RT_REF_TYPE_PARAMETER); - dumpTypeParameterName( - out, - OUStringToOString( - m_reader.getReferenceTypeName(i), RTL_TEXTENCODING_UTF8)); +void PolyStructType::dumpTemplateParameters(FileStream & out) const { + out << "< "; + for (std::vector< OUString >::const_iterator i( + entity_->getTypeParameters().begin()); + i != entity_->getTypeParameters().end(); ++i) + { + if (i != entity_->getTypeParameters().begin()) { + out << ", "; } - out << " >"; + dumpTypeParameterName(out, *i); } + out << " >"; } -//************************************************************************* -// ExceptionType -//************************************************************************* -ExceptionType::ExceptionType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr) - : CppuType(typeReader, typeName, typeMgr) -{ -} - -ExceptionType::~ExceptionType() -{ - -} - -sal_Bool ExceptionType::dumpHFile( - FileStream& o, codemaker::cppumaker::Includes & includes) - throw( CannotDumpException ) -{ - dumpHFileContent(o, includes); - return sal_True; -} - -void ExceptionType::dumpDeclaration(FileStream& o) - throw( CannotDumpException ) -{ - o << "\nclass CPPU_GCC_DLLPUBLIC_EXPORT " << m_name; - - OString superType; - if (m_reader.getSuperTypeCount() >= 1) { - superType = OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8); +OUString typeToIdentifier(OUString const & name) { + sal_Int32 k; + OUString n(b2u(codemaker::UnoType::decompose(u2b(name), &k))); + OUStringBuffer b; + for (sal_Int32 i = 0; i != k; ++i) { + b.append("seq_"); } - if (!superType.isEmpty()) - o << " : public " << scopedCppName(superType); - - o << "\n{\npublic:\n"; - inc(); - o << indent() << "inline CPPU_GCC_DLLPRIVATE " << m_name - << "() SAL_THROW(());\n\n"; - - sal_uInt16 fieldCount = m_reader.getFieldCount(); - RTFieldAccess access = RT_ACCESS_INVALID; - OString fieldName; - OString fieldType; - sal_uInt16 i = 0; - - if (fieldCount > 0 || getInheritedMemberCount() > 0) - { - o << indent() << "inline CPPU_GCC_DLLPRIVATE " << m_name << "("; - - sal_Bool superHasMember = dumpSuperMember(o, superType, sal_True); - - for (i=0; i < fieldCount; i++) - { - access = m_reader.getFieldFlags(i); + b.append(n); + b.replace(' ', '_'); + b.replace(',', '_'); + b.replace('.', '_'); + b.replace('<', '_'); + b.replace('>', '_'); + return b.makeStringAndClear(); +} - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; +class ExceptionType: public CppuType { +public: + ExceptionType( + rtl::Reference< unoidl::ExceptionTypeEntity > const & entity, + OUString const & name, rtl::Reference< TypeManager > const & typeMgr): + CppuType(name, typeMgr), entity_(entity) + { assert(entity.is()); } - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - fieldType = OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8); +private: + virtual void dumpHxxFile( + FileStream & out, codemaker::cppumaker::Includes & includes); - if (superHasMember) - o << ", "; - else - superHasMember = sal_True; + virtual void dumpLightGetCppuType(FileStream & out); - dumpType(o, fieldType, sal_True, sal_True); - o << " " << fieldName << "_"; - } - o << ") SAL_THROW(());\n\n"; - } - o << indent() << "inline CPPU_GCC_DLLPRIVATE " << m_name << "(" << m_name - << " const &);\n\n" - << indent() << "inline CPPU_GCC_DLLPRIVATE ~" << m_name << "();\n\n" - << indent() << "inline CPPU_GCC_DLLPRIVATE " << m_name << " & operator =(" - << m_name << " const &);\n\n"; + virtual void dumpNormalGetCppuType(FileStream & out); - for (i=0; i < fieldCount; i++) - { - access = m_reader.getFieldFlags(i); + virtual void dumpComprehensiveGetCppuType(FileStream & out); - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; + virtual sal_uInt32 checkInheritedMemberCount() const + { return getTotalMemberCount(entity_->getDirectBase()); } - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - fieldType = OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8); + virtual void dumpDeclaration(FileStream & out); - o << indent(); - dumpType(o, fieldType); - o << " " << fieldName; - if (i == 0 && !superType.isEmpty() && - !(fieldType == "double") && !(fieldType == "hyper") && !(fieldType == "unsigned hyper")) - { - o << " CPPU_GCC3_ALIGN( " << scopedCppName(superType) << " )"; - } - o << ";\n"; - } + bool dumpBaseMembers( + FileStream & out, OUString const & base, bool withType); + sal_uInt32 getTotalMemberCount(OUString const & base) const; - dec(); - o << "};\n\n"; -} + rtl::Reference< unoidl::ExceptionTypeEntity > entity_; +}; -sal_Bool ExceptionType::dumpHxxFile( - FileStream& o, codemaker::cppumaker::Includes & includes) - throw( CannotDumpException ) +void ExceptionType::dumpHxxFile( + FileStream & out, codemaker::cppumaker::Includes & includes) { - OString headerDefine(dumpHeaderDefine(o, "HPP")); - o << "\n"; - + OUString headerDefine(dumpHeaderDefine(out, "HPP")); + out << "\n"; addDefaultHxxIncludes(includes); - includes.dump(o, &m_typeName); - o << "\n"; - - if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) { - o << "\n"; + includes.dump(out, &name_); + out << "\n"; + if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) { + out << "\n"; } - o << "\n"; - - o << "inline " << m_name << "::" << m_name << "() SAL_THROW(())\n"; + out << "\ninline " << id_ << "::" << id_ << "() SAL_THROW(())\n"; inc(); - OString superType; - if (m_reader.getSuperTypeCount() >= 1) { - superType = OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8); - } - sal_Bool first = sal_True; - if (!superType.isEmpty()) - { - o << indent() << ": " << scopedCppName(superType) << "()\n"; - first = sal_False; + OUString base(entity_->getDirectBase()); + bool first = true; + if (!base.isEmpty()) { + out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base)) + << "()\n"; + first = false; } - - sal_uInt16 fieldCount = m_reader.getFieldCount(); - RTFieldAccess access = RT_ACCESS_INVALID; - OString fieldName; - OString fieldType; - - for (sal_uInt16 i=0; i < fieldCount; i++) + for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i( + entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - - if (first) - { - first = sal_False; - o << indent() << ": "; - } else - o << indent() << ", "; - - o << fieldName; - dumpInitializer(o, false, m_reader.getFieldTypeName(i)); - o << "\n"; + out << indent() << (first ? ":" : ",") << " "; + out << i->name; + dumpInitializer(out, false, i->type); + out << "\n"; + first = false; } dec(); - if ( !m_cppuTypeDynamic ) - { - o << "{\n"; + out << "{"; + if (!m_cppuTypeDynamic) { + out << "\n"; inc(); - dumpCppuGetType(o, m_typeName, sal_True); + dumpCppuGetType(out, name_); dec(); - o << "}\n\n"; - } else - { - o << "{ }\n\n"; - } - - if (fieldCount > 0 || getInheritedMemberCount() > 0) - { - o << indent() << "inline " << m_name << "::" << m_name << "("; - - sal_Bool superHasMember = dumpSuperMember(o, superType, sal_True); - - for (sal_uInt16 i=0; i < fieldCount; i++) + } else { + out << " "; + } + out << "}\n\n"; + if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) { + out << indent() << "inline " << id_ << "::" << id_ << "("; + first = !dumpBaseMembers(out, base, true); + for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator + i(entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - fieldType = OUStringToOString( - m_reader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8); - - if (superHasMember) - o << ", "; - else - superHasMember = sal_True; - - dumpType(o, fieldType, sal_True, sal_True); - o << " " << fieldName << "_"; + if (!first) { + out << ", "; + } + dumpType(out, i->type, true, true); + out << " " << i->name << "_"; + first = false; } - o << ") SAL_THROW(())\n"; - + out << ") SAL_THROW(())\n"; inc(); - first = sal_True; - if (!superType.isEmpty()) - { - o << indent() << ": " << scopedCppName(superType) << "("; - dumpSuperMember(o, superType, sal_False); - o << ")\n"; - first = sal_False; - } - - for (sal_uInt16 i=0; i < fieldCount; i++) + first = true; + if (!base.isEmpty()) { + out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base)) + << "("; + dumpBaseMembers(out, base, false); + out << ")\n"; + first = false; + } + for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator + i(entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) { - access = m_reader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - - if (first) - { - first = sal_False; - o << indent() << ": "; - } else - o << indent() << ", "; - - o << fieldName << "(" << fieldName << "_)\n"; + out << indent() << (first ? ":" : ",") << " " << i->name << "(" + << i->name << "_)\n"; + first = false; } - dec(); - if ( !m_cppuTypeDynamic ) - { - o << "{\n"; + out << "{"; + if (!m_cppuTypeDynamic) { + out << "\n"; inc(); - dumpCppuGetType(o, m_typeName, sal_True); + dumpCppuGetType(out, name_); dec(); - o << "}\n\n"; - } else - { - o << "{ }\n\n"; + } else { + out << " "; } + out << "}\n\n"; } - o << indent() << m_name << "::" << m_name << "(" << m_name - << " const & the_other)"; + out << indent() << id_ << "::" << id_ << "(" << id_ + << " const & the_other)"; first = true; - if (!superType.isEmpty()) { - o << ": " << scopedCppName(superType) << "(the_other)"; + if (!base.isEmpty()) { + out << ": " << codemaker::cpp::scopedCppName(u2b(base)) + << "(the_other)"; first = false; } - for (sal_uInt16 i = 0; i < fieldCount; ++i) { - OString name( - OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8)); - o << (first ? ": " : ", ") << name << "(the_other." << name << ")"; + for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i( + entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) + { + out << (first ? ":" : ",") << " " << i->name << "(the_other." << i->name + << ")"; first = false; } - o << indent() << " {}\n\n" - << indent() << m_name << "::~" << m_name << "() {}\n\n" - << indent() << m_name << " & " << m_name << "::operator =(" << m_name - << " const & the_other) {\n"; + out << indent() << " {}\n\n" << indent() << id_ << "::~" << id_ + << "() {}\n\n" << indent() << id_ << " & " << id_ << "::operator =(" + << id_ << " const & the_other) {\n"; inc(); - o << indent() - << ("//TODO: Just like its implicitly-defined counterpart, this function" - " definition is not exception-safe\n"); - if (!superType.isEmpty()) { - o << indent() << scopedCppName(superType) - << "::operator =(the_other);\n"; + out << indent() + << ("//TODO: Just like its implicitly-defined counterpart, this" + " function definition is not exception-safe\n"); + if (!base.isEmpty()) { + out << indent() << codemaker::cpp::scopedCppName(u2b(base)) + << "::operator =(the_other);\n"; } - for (sal_uInt16 i = 0; i < fieldCount; ++i) { - OString name( - OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8)); - o << indent() << name << " = the_other." << name << ";\n"; + for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i( + entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) + { + out << indent() << i->name << " = the_other." << i->name << ";\n"; } - o << indent() << "return *this;\n"; + out << indent() << "return *this;\n"; dec(); - o << indent() << "}\n\n"; - - if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) { - o << "\n"; + out << indent() << "}\n\n"; + if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) { + out << "\n"; } + out << "\n"; + dumpGetCppuType(out); + out << "\n#endif // "<< headerDefine << "\n"; +} - o << "\n"; - dumpGetCppuType(o); +void ExceptionType::dumpLightGetCppuType(FileStream & out) { + dumpGetCppuTypePreamble(out); + out << indent() + << "static typelib_TypeDescriptionReference * the_type = 0;\n" + << indent() << "if ( !the_type )\n" << indent() << "{\n"; + inc(); + out << indent() << "typelib_static_type_init( &the_type, " + << getTypeClass(name_, true) << ", \"" << name_ << "\" );\n"; + dec(); + out << indent() << "}\n" << indent() + << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >(" + " &the_type );\n"); + dumpGetCppuTypePostamble(out); +} - o << "\n#endif // "<< headerDefine << "\n"; - return sal_True; +void ExceptionType::dumpNormalGetCppuType(FileStream & out) { + dumpGetCppuTypePreamble(out); + out << indent() + << "static typelib_TypeDescriptionReference * the_type = 0;\n" + << indent() << "if ( !the_type )\n" << indent() << "{\n"; + inc(); + OUString base(entity_->getDirectBase()); + bool baseException = false; + if (!base.isEmpty()) { + if (base == "com.sun.star.uno.Exception") { + baseException = true; + } else { + out << indent() + << ("const ::com::sun::star::uno::Type& rBaseType =" + " ::cppu::UnoType< "); + dumpType(out, base, true, false, false, true); + out << " >::get();\n\n"; + } + } + if (!entity_->getDirectMembers().empty()) { + out << indent() << "typelib_TypeDescriptionReference * aMemberRefs[" + << entity_->getDirectMembers().size() << "];\n"; + std::set< OUString > seen; + std::vector< unoidl::ExceptionTypeEntity::Member >::size_type n = 0; + for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator + i(entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) + { + OUString type(resolveAllTypedefs(i->type)); + OUString modType(typeToIdentifier(type)); + if (seen.insert(type).second) { + out << indent() + << "const ::com::sun::star::uno::Type& rMemberType_" + << modType << " = ::cppu::UnoType< "; + dumpType(out, type, false, false, false, true); + out << " >::get();\n"; + } + out << indent() << "aMemberRefs[" << n++ << "] = rMemberType_" + << modType << ".getTypeLibType();\n"; + } + out << "\n"; + } + out << indent() << "typelib_static_compound_type_init( &the_type, " + << getTypeClass(name_, true) << ", \"" << name_ << "\", "; + if (baseException) { + out << ("* ::typelib_static_type_getByTypeClass(" + " typelib_TypeClass_EXCEPTION )"); + } else if (base.isEmpty()) { + out << "0"; + } else { + out << "rBaseType.getTypeLibType()"; + } + out << ", " << entity_->getDirectMembers().size() << ", " + << (entity_->getDirectMembers().empty() ? "0" : "aMemberRefs") + << " );\n"; + dec(); + out << indent() << "}\n" << indent() + << ("return * reinterpret_cast< const ::com::sun::star::uno::Type * >(" + " &the_type );\n"); + dumpGetCppuTypePostamble(out); } -sal_Bool ExceptionType::dumpSuperMember(FileStream& o, const OString& superType, sal_Bool bWithType) -{ - sal_Bool hasMember = sal_False; +void ExceptionType::dumpComprehensiveGetCppuType(FileStream & out) { + codemaker::cppumaker::dumpNamespaceOpen(out, name_, false); + out << " namespace detail {\n\n"; + OUString staticTypeClass("the" + id_ + "Type"); + out << indent() << "struct " << staticTypeClass + << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, " + << staticTypeClass << " >\n" << indent() << "{\n"; + inc(); + out << indent() << "::com::sun::star::uno::Type * operator()() const\n" + << indent() << "{\n"; + inc(); + out << indent() << "::rtl::OUString sTypeName( \"" << name_ << "\" );\n\n" + << indent() << "// Start inline typedescription generation\n" + << indent() << "typelib_TypeDescription * pTD = 0;\n"; + OUString base(entity_->getDirectBase()); + if (!base.isEmpty()) { + out << indent() + << ("const ::com::sun::star::uno::Type& rSuperType =" + " ::cppu::UnoType< "); + dumpType(out, base, false, false, false, true); + out << " >::get();\n"; + } + std::set< OUString > seen; + for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i( + entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) + { + if (seen.insert(i->type).second) { + dumpCppuGetType(out, i->type); + } + } + if (!entity_->getDirectMembers().empty()) { + out << "\n" << indent() << "typelib_CompoundMember_Init aMembers[" + << entity_->getDirectMembers().size() << "];\n"; + std::vector< unoidl::ExceptionTypeEntity::Member >::size_type n = 0; + for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator + i(entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) + { + OUString type(resolveAllTypedefs(i->type)); + out << indent() << "::rtl::OUString sMemberType" << n << "( \"" + << type << "\" );\n" << indent() + << "::rtl::OUString sMemberName" << n << "( \"" << i->name + << "\" );\n" << indent() << "aMembers[" << n + << "].eTypeClass = (typelib_TypeClass)" << getTypeClass(type) + << ";\n" << indent() << "aMembers[" << n + << "].pTypeName = sMemberType" << n << ".pData;\n" << indent() + << "aMembers[" << n << "].pMemberName = sMemberName" << n + << ".pData;\n"; + ++n; + } + } + out << "\n" << indent() << "typelib_typedescription_new(\n"; + inc(); + out << indent() << "&pTD,\n" << indent() << "(typelib_TypeClass)" + << getTypeClass(name_) << ", sTypeName.pData,\n" << indent() + << (base.isEmpty() ? "0" : "rSuperType.getTypeLibType()") << ",\n" + << indent() << entity_->getDirectMembers().size() << ",\n" << indent() + << (entity_->getDirectMembers().empty() ? "0" : "aMembers") + << " );\n\n"; + dec(); + out << indent() + << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD" + " );\n\n") + << indent() << "typelib_typedescription_release( pTD );\n" << indent() + << "// End inline typedescription generation\n\n" << indent() + << "return new ::com::sun::star::uno::Type( " << getTypeClass(name_) + << ", sTypeName ); // leaked\n"; + dec(); + out << indent() << "}\n"; + dec(); + out << indent() << "};\n\n"; + codemaker::cppumaker::dumpNamespaceClose(out, name_, false); + out << " }\n\n"; + dumpGetCppuTypePreamble(out); + out << indent() << "return *detail::" << staticTypeClass << "::get();\n"; + dumpGetCppuTypePostamble(out); +} - if (!superType.isEmpty()) +void ExceptionType::dumpDeclaration(FileStream & out) { + out << "\nclass CPPU_GCC_DLLPUBLIC_EXPORT " << id_; + OUString base(entity_->getDirectBase()); + if (!base.isEmpty()) { + out << " : public " << codemaker::cpp::scopedCppName(u2b(base)); + } + out << "\n{\npublic:\n"; + inc(); + out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ + << "() SAL_THROW(());\n\n"; + if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) { + out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "("; + bool first = !dumpBaseMembers(out, base, true); + for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator + i(entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) + { + if (!first) { + out << ", "; + } + dumpType(out, i->type, true, true); + out << " " << i->name << "_"; + first = false; + } + out << ") SAL_THROW(());\n\n"; + } + out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "(" << id_ + << " const &);\n\n" << indent() << "inline CPPU_GCC_DLLPRIVATE ~" + << id_ << "();\n\n" << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ + << " & operator =(" << id_ << " const &);\n\n"; + for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i( + entity_->getDirectMembers().begin()); + i != entity_->getDirectMembers().end(); ++i) { - typereg::Reader aSuperReader(m_typeMgr->getTypeReader(superType)); + out << indent(); + dumpType(out, i->type); + out << " " << i->name; + if (i == entity_->getDirectMembers().begin() && !base.isEmpty() + && i->type != "hyper" && i->type != "unsigned hyper" + && i->type != "double") + { + out << " CPPU_GCC3_ALIGN( " + << codemaker::cpp::scopedCppName(u2b(base)) << " )"; + } + out << ";\n"; + } + dec(); + out << "};\n\n"; +} - if (aSuperReader.isValid()) +bool ExceptionType::dumpBaseMembers( + FileStream & out, OUString const & base, bool withType) +{ + bool hasMember = false; + if (!base.isEmpty()) { + rtl::Reference< unoidl::Entity > ent; + codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent); + if (sort != codemaker::UnoType::SORT_EXCEPTION_TYPE) { + throw CannotDumpException( + "exception type base " + base + " is not an exception type"); + } + rtl::Reference< unoidl::ExceptionTypeEntity > ent2( + dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get())); + assert(ent2.is()); + hasMember = dumpBaseMembers(out, ent2->getDirectBase(), withType); + for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator + i(ent2->getDirectMembers().begin()); + i != ent2->getDirectMembers().end(); ++i) { - OString superSuper; - if (aSuperReader.getSuperTypeCount() >= 1) { - superSuper = OUStringToOString( - aSuperReader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8); + if (hasMember) { + out << ", "; } - hasMember = dumpSuperMember(o, superSuper, bWithType); - - sal_uInt16 fieldCount = aSuperReader.getFieldCount(); - RTFieldAccess access = RT_ACCESS_INVALID; - OString fieldName; - OString fieldType; - for (sal_uInt16 i=0; i < fieldCount; i++) - { - access = aSuperReader.getFieldFlags(i); - - if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) - continue; - - fieldName = OUStringToOString( - aSuperReader.getFieldName(i), RTL_TEXTENCODING_UTF8); - fieldType = OUStringToOString( - aSuperReader.getFieldTypeName(i), RTL_TEXTENCODING_UTF8); - - if (hasMember) - { - o << ", "; - } else - { - hasMember = (fieldCount > 0); - } - - if (bWithType) - { - dumpType(o, fieldType, sal_True, sal_True); - o << " "; - } - o << fieldName << "_"; + if (withType) { + dumpType(out, i->type, true, true); + out << " "; } + out << i->name << "_"; + hasMember = true; } } - return hasMember; } -//************************************************************************* -// EnumType -//************************************************************************* -EnumType::EnumType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr) - : CppuType(typeReader, typeName, typeMgr) -{ +sal_uInt32 ExceptionType::getTotalMemberCount(OUString const & base) const { + if (base.isEmpty()) { + return 0; + } + rtl::Reference< unoidl::Entity > ent; + codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent); + if (sort != codemaker::UnoType::SORT_EXCEPTION_TYPE) { + throw CannotDumpException( + "exception type base " + base + " is not an exception type"); + } + rtl::Reference< unoidl::ExceptionTypeEntity > ent2( + dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get())); + assert(ent2.is()); + return getTotalMemberCount(ent2->getDirectBase()) + + ent2->getDirectMembers().size(); //TODO: overflow } -EnumType::~EnumType() -{ +class EnumType: public CppuType { +public: + EnumType( + rtl::Reference< unoidl::EnumTypeEntity > const & entity, + OUString const & name, rtl::Reference< TypeManager > const & typeMgr): + CppuType(name, typeMgr), entity_(entity) + { assert(entity.is()); } -} +private: + virtual void dumpDeclaration(FileStream& o); -sal_Bool EnumType::dumpHFile( - FileStream& o, codemaker::cppumaker::Includes & includes) - throw( CannotDumpException ) -{ - dumpHFileContent(o, includes); - return sal_True; -} + void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes); + + void dumpNormalGetCppuType(FileStream& o); + void dumpComprehensiveGetCppuType(FileStream& o); + + rtl::Reference< unoidl::EnumTypeEntity > entity_; +}; void EnumType::dumpDeclaration(FileStream& o) - throw( CannotDumpException ) { - o << "\nenum " << m_name << "\n{\n"; + o << "\nenum " << id_ << "\n{\n"; inc(); - sal_uInt16 fieldCount = m_reader.getFieldCount(); - RTFieldAccess access = RT_ACCESS_INVALID; - RTConstValue constValue; - OString fieldName; - sal_Int32 value=0; - for (sal_uInt16 i=0; i < fieldCount; i++) + for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i( + entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) { - access = m_reader.getFieldFlags(i); - - if (access != RT_ACCESS_CONST) - continue; - - fieldName = OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8); - constValue = m_reader.getFieldValue(i); - - if (constValue.m_type == RT_TYPE_INT32) - value = constValue.m_value.aLong; - else - value++; - - o << indent() << m_name << "_" << fieldName << " = " << value << ",\n"; + o << indent() << id_ << "_" << u2b(i->name) << " = " << i->value + << ",\n"; } - o << indent() << m_name << "_MAKE_FIXED_SIZE = SAL_MAX_ENUM\n"; + o << indent() << id_ << "_MAKE_FIXED_SIZE = SAL_MAX_ENUM\n"; dec(); o << "};\n\n"; } -sal_Bool EnumType::dumpHxxFile( +void EnumType::dumpHxxFile( FileStream& o, codemaker::cppumaker::Includes & includes) - throw( CannotDumpException ) { - OString headerDefine(dumpHeaderDefine(o, "HPP")); + OUString headerDefine(dumpHeaderDefine(o, "HPP")); o << "\n"; addDefaultHxxIncludes(includes); - includes.dump(o, &m_typeName); + includes.dump(o, &name_); o << "\n"; dumpGetCppuType(o); o << "\n#endif // "<< headerDefine << "\n"; - return sal_True; } void EnumType::dumpNormalGetCppuType(FileStream& o) @@ -3664,10 +3118,9 @@ void EnumType::dumpNormalGetCppuType(FileStream& o) o << indent() << "typelib_static_enum_type_init( &the_type,\n"; inc(31); - o << indent() << "\"" << m_typeName.replace('/', '.') << "\",\n" - << indent() << scopedCppName(m_typeName) << "_" - << OUStringToOString(m_reader.getFieldName(0), RTL_TEXTENCODING_UTF8) - << " );\n"; + o << indent() << "\"" << name_ << "\",\n" + << indent() << codemaker::cpp::scopedCppName(u2b(name_)) << "_" + << u2b(entity_->getMembers()[0].name) << " );\n"; dec(31); dec(); o << indent() << "}\n"; @@ -3680,13 +3133,12 @@ void EnumType::dumpNormalGetCppuType(FileStream& o) void EnumType::dumpComprehensiveGetCppuType(FileStream& o) { if (!isPolymorphic()) - codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false); + codemaker::cppumaker::dumpNamespaceOpen(o, name_, false); else o << "namespace cppu { "; o << " namespace detail {\n\n"; - OString sType = m_typeName.copy(m_typeName.lastIndexOf('/') + 1); - OString sStaticTypeClass = "the" + sType + "Type"; + OUString sStaticTypeClass("the" + id_ + "Type"); o << indent() << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, " << sStaticTypeClass << " >\n"; o << indent() << "{\n"; inc(); @@ -3694,48 +3146,44 @@ void EnumType::dumpComprehensiveGetCppuType(FileStream& o) o << indent() << "{\n"; inc(); - o << indent() << "rtl::OUString sTypeName( \"" - << m_typeName.replace('/', '.') << "\" );\n\n"; + o << indent() << "::rtl::OUString sTypeName( \"" << name_ + << "\" );\n\n"; o << indent() << "// Start inline typedescription generation\n" << indent() << "typelib_TypeDescription * pTD = 0;\n\n"; - sal_uInt16 count = m_reader.getFieldCount(); - o << indent() << "rtl_uString* enumValueNames[" << count << "];\n"; - sal_uInt16 i; - for (i = 0; i < count; i++) + o << indent() << "rtl_uString* enumValueNames[" + << entity_->getMembers().size() << "];\n"; + std::vector< unoidl::EnumTypeEntity::Member >::size_type n = 0; + for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i( + entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) { - o << indent() << "rtl::OUString sEnumValue" << i - << "( \"" - << OUStringToOString( - m_reader.getFieldName(i), RTL_TEXTENCODING_UTF8) - << "\" );\n"; - o << indent() << "enumValueNames[" << i << "] = sEnumValue" << i + o << indent() << "::rtl::OUString sEnumValue" << n << "( \"" + << u2b(i->name) << "\" );\n"; + o << indent() << "enumValueNames[" << n << "] = sEnumValue" << n << ".pData;\n"; + ++n; } - o << "\n" << indent() << "sal_Int32 enumValues[" << count << "];\n"; - RTConstValue constValue; - sal_Int32 value=0; - for (i = 0; i < count; i++) + o << "\n" << indent() << "sal_Int32 enumValues[" + << entity_->getMembers().size() << "];\n"; + n = 0; + for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i( + entity_->getMembers().begin()); + i != entity_->getMembers().end(); ++i) { - o << indent() << "enumValues[" << i << "] = "; - constValue = m_reader.getFieldValue(i); - if (constValue.m_type == RT_TYPE_INT32) - value = constValue.m_value.aLong; - else - value++; - o << value << ";\n"; + o << indent() << "enumValues[" << n++ << "] = " << i->value << ";\n"; } o << "\n" << indent() << "typelib_typedescription_newEnum( &pTD,\n"; inc(); o << indent() << "sTypeName.pData,\n" - << indent() << "(sal_Int32)" << scopedCppName(m_typeName, sal_False) - << "_" - << OUStringToOString(m_reader.getFieldName(0), RTL_TEXTENCODING_UTF8) - << ",\n" - << indent() << count << ", enumValueNames, enumValues );\n\n"; + << indent() << "(sal_Int32)" + << codemaker::cpp::scopedCppName(u2b(name_), false) << "_" + << u2b(entity_->getMembers()[0].name) << ",\n" + << indent() << entity_->getMembers().size() + << ", enumValueNames, enumValues );\n\n"; dec(); o << indent() @@ -3745,7 +3193,7 @@ void EnumType::dumpComprehensiveGetCppuType(FileStream& o) << indent() << "// End inline typedescription generation\n\n"; o << indent() << "return new ::com::sun::star::uno::Type( " - << getTypeClass(m_typeName) << ", sTypeName ); // leaked\n"; + << getTypeClass(name_) << ", sTypeName ); // leaked\n"; dec(); o << indent() << "}\n"; @@ -3753,7 +3201,7 @@ void EnumType::dumpComprehensiveGetCppuType(FileStream& o) o << indent() << "};\n\n"; if (!isPolymorphic()) - codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false); + codemaker::cppumaker::dumpNamespaceClose(o, name_, false); else o << " }"; o << " }\n\n"; @@ -3763,96 +3211,88 @@ void EnumType::dumpComprehensiveGetCppuType(FileStream& o) dumpGetCppuTypePostamble(o); } -//************************************************************************* -// TypeDefType -//************************************************************************* -TypeDefType::TypeDefType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr) - : CppuType(typeReader, typeName, typeMgr) -{ -} +class Typedef: public CppuType { +public: + Typedef( + rtl::Reference< unoidl::TypedefEntity > const & entity, + OUString const & name, rtl::Reference< TypeManager > const & typeMgr): + CppuType(name, typeMgr), entity_(entity) + { assert(entity.is()); } -TypeDefType::~TypeDefType() -{ +private: + virtual void dumpDeclaration(FileStream& o); -} + void dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes); + + void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes); + + rtl::Reference< unoidl::TypedefEntity > entity_; +}; -sal_Bool TypeDefType::dumpHFile( +void Typedef::dumpHFile( FileStream& o, codemaker::cppumaker::Includes & includes) - throw( CannotDumpException ) { - OString headerDefine(dumpHeaderDefine(o, "HDL")); + OUString headerDefine(dumpHeaderDefine(o, "HDL")); o << "\n"; addDefaultHIncludes(includes); includes.dump(o, 0); o << "\n"; - if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) { + if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) { o << "\n"; } dumpDeclaration(o); - if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) { + if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) { o << "\n"; } o << "#endif // "<< headerDefine << "\n"; - - return sal_True; } -void TypeDefType::dumpDeclaration(FileStream& o) - throw( CannotDumpException ) +void Typedef::dumpDeclaration(FileStream& o) { o << "\ntypedef "; - dumpType( - o, - OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8)); - o << " " << m_name << ";\n\n"; + dumpType(o, entity_->getType()); + o << " " << id_ << ";\n\n"; } -sal_Bool TypeDefType::dumpHxxFile( +void Typedef::dumpHxxFile( FileStream& o, codemaker::cppumaker::Includes & includes) - throw( CannotDumpException ) { - OString headerDefine(dumpHeaderDefine(o, "HPP")); + OUString headerDefine(dumpHeaderDefine(o, "HPP")); o << "\n"; addDefaultHxxIncludes(includes); - includes.dump(o, &m_typeName); + includes.dump(o, &name_); o << "\n"; o << "\n#endif // "<< headerDefine << "\n"; - return sal_True; } -//************************************************************************* -// ConstructiveType -//************************************************************************* +class ConstructiveType: public CppuType { +public: + ConstructiveType( + OUString const & name, rtl::Reference< TypeManager > const & manager): + CppuType(name, manager) {} + +private: + virtual void dumpHFile(FileStream &, codemaker::cppumaker::Includes &) + { assert(false); } // this cannot happen -sal_Bool ConstructiveType::dumpHFile( - FileStream &, codemaker::cppumaker::Includes &) throw (CannotDumpException) -{ - OSL_ASSERT(false); - return false; -} + virtual void dumpFiles(OUString const & uri, CppuOptions const & options) + { dumpFile(uri, name_, true, options); } +}; -bool ConstructiveType::dumpFiles( - CppuOptions * options, OString const & outPath) +bool hasRestParameter( + unoidl::SingleInterfaceBasedServiceEntity::Constructor const & constructor) { - return dumpFile(options, ".hpp", m_typeName, outPath); + return !constructor.parameters.empty() + && constructor.parameters.back().rest; } -//************************************************************************* -// ServiceType -//************************************************************************* - -namespace { - void includeExceptions( codemaker::cppumaker::Includes & includes, codemaker::ExceptionTreeNode const * node) @@ -3869,18 +3309,29 @@ void includeExceptions( } } -} +class ServiceType: public ConstructiveType { +public: + ServiceType( + rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > const & + entity, + OUString const & name, rtl::Reference< TypeManager > const & manager): + ConstructiveType(name, manager), entity_(entity) + { assert(entity.is()); } -bool ServiceType::isSingleInterfaceBased() { - return m_reader.getSuperTypeCount() == 1; -} +private: + virtual void dumpHxxFile( + FileStream & o, codemaker::cppumaker::Includes & includes); + + void dumpCatchClauses( + FileStream & out, codemaker::ExceptionTreeNode const * node); + + rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > entity_; +}; -sal_Bool ServiceType::dumpHxxFile( +void ServiceType::dumpHxxFile( FileStream & o, codemaker::cppumaker::Includes & includes) - throw (CannotDumpException) { - sal_uInt16 ctors = m_reader.getMethodCount(); - if (ctors > 0) { + if (!entity_->getConstructors().empty()) { //TODO: Decide whether the types added to includes should rather be // added to m_dependencies (and thus be generated during // dumpDependedTypes): @@ -3888,25 +3339,29 @@ sal_Bool ServiceType::dumpHxxFile( includes.addReference(); includes.addRtlUstringH(); includes.addRtlUstringHxx(); - includes.add("com/sun/star/uno/DeploymentException"); - includes.add("com/sun/star/uno/XComponentContext"); - for (sal_uInt16 i = 0; i < ctors; ++i) { - if (isDefaultConstructor(i)) { - includes.add("com/sun/star/uno/Exception"); - includes.add("com/sun/star/uno/RuntimeException"); + includes.add("com.sun.star.uno.DeploymentException"); + includes.add("com.sun.star.uno.XComponentContext"); + for (std::vector< + unoidl::SingleInterfaceBasedServiceEntity::Constructor >:: + const_iterator i(entity_->getConstructors().begin()); + i != entity_->getConstructors().end(); ++i) + { + if (i->defaultConstructor) { + includes.add("com.sun.star.uno.Exception"); + includes.add("com.sun.star.uno.RuntimeException"); } else { - if (!hasRestParameter(i)) { + if (!hasRestParameter(*i)) { includes.addAny(); includes.addSequence(); - sal_uInt16 params = m_reader.getMethodParameterCount(i); - for (sal_uInt16 j = 0; j < params; ++j) { + for (std::vector< + unoidl::SingleInterfaceBasedServiceEntity:: + Constructor::Parameter >::const_iterator j( + i->parameters.begin()); + j != i->parameters.end(); ++j) + { if (codemaker::UnoType::getSort( codemaker::UnoType::decompose( - OUStringToOString( - m_reader.getMethodParameterTypeName( - i, j), - RTL_TEXTENCODING_UTF8), - 0, 0)) + u2b(j->type), 0, 0)) == codemaker::UnoType::SORT_CHAR) { includes.addCppuUnotypeHxx(); @@ -3915,48 +3370,47 @@ sal_Bool ServiceType::dumpHxxFile( } } codemaker::ExceptionTree tree; - for (sal_uInt16 j = 0; j < m_reader.getMethodExceptionCount(i); - ++j) + for (std::vector< OUString >::const_iterator j( + i->exceptions.begin()); + j != i->exceptions.end(); ++j) { - tree.add( - OUStringToOString( - m_reader.getMethodExceptionTypeName(i, j), - RTL_TEXTENCODING_UTF8), - m_typeMgr); + tree.add(u2b(*j), m_typeMgr); } if (!tree.getRoot()->present) { - includes.add("com/sun/star/uno/Exception"); - includes.add("com/sun/star/uno/RuntimeException"); + includes.add("com.sun.star.uno.Exception"); + includes.add("com.sun.star.uno.RuntimeException"); includeExceptions(includes, tree.getRoot()); } } } } - OString cppName(translateUnoToCppIdentifier( - m_name, "service", isGlobal())); - OString headerDefine(dumpHeaderDefine(o, "HPP")); + OString cppName( + codemaker::cpp::translateUnoToCppIdentifier( + u2b(id_), "service", isGlobal())); + OUString headerDefine(dumpHeaderDefine(o, "HPP")); o << "\n"; includes.dump(o, 0); o << "\n"; - if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) { + if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) { o << "\n"; } o << "\nclass " << cppName << " {\n"; inc(); - if (ctors > 0) { - OString fullName(m_typeName.replace('/', '.')); - OString baseName( - OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8)); - OString fullBaseName(baseName.replace('/', '.')); - OString scopedBaseName(scopedCppName(baseName)); + if (!entity_->getConstructors().empty()) { + OString baseName(u2b(entity_->getBase())); + OString scopedBaseName(codemaker::cpp::scopedCppName(baseName)); o << "public:\n"; - for (sal_uInt16 i = 0; i < ctors; ++i) { - if (isDefaultConstructor(i)) { + for (std::vector< + unoidl::SingleInterfaceBasedServiceEntity::Constructor >:: + const_iterator i(entity_->getConstructors().begin()); + i != entity_->getConstructors().end(); ++i) + { + if (i->defaultConstructor) { o << indent() << "static ::com::sun::star::uno::Reference< " << scopedBaseName << " > " - << translateUnoToCppIdentifier( - "create", "method", ITM_NONGLOBAL, &cppName) + << codemaker::cpp::translateUnoToCppIdentifier( + "create", "method", codemaker::cpp::ITM_NONGLOBAL, + &cppName) << ("(::com::sun::star::uno::Reference<" " ::com::sun::star::uno::XComponentContext > const &" " the_context) {\n"); @@ -3969,9 +3423,9 @@ sal_Bool ServiceType::dumpHxxFile( << "the_instance = ::com::sun::star::uno::Reference< " << scopedBaseName << (" >(the_context->getServiceManager()->" - "createInstanceWithContext(rtl::OUString(" + "createInstanceWithContext(::rtl::OUString(" " \"") - << fullName + << name_ << "\" ), the_context), ::com::sun::star::uno::UNO_QUERY);\n"; dec(); o << indent() @@ -3985,9 +3439,9 @@ sal_Bool ServiceType::dumpHxxFile( inc(); o << indent() << ("throw ::com::sun::star::uno::DeploymentException(" - "rtl::OUString( " + "::rtl::OUString( " "\"component context fails to supply service ") - << fullName << " of type " << fullBaseName + << name_ << " of type " << baseName << ": \" ) + the_exception.Message, the_context);\n"; dec(); o << indent() << "}\n" << indent() @@ -3995,9 +3449,9 @@ sal_Bool ServiceType::dumpHxxFile( inc(); o << indent() << ("throw ::com::sun::star::uno::DeploymentException(" - "rtl::OUString( " + "::rtl::OUString( " "\"component context fails to supply service ") - << fullName << " of type " << fullBaseName + << name_ << " of type " << baseName << "\" ), the_context);\n"; dec(); o << indent() << "}\n" << indent() << "return the_instance;\n"; @@ -4006,61 +3460,57 @@ sal_Bool ServiceType::dumpHxxFile( } else { o << indent() << "static ::com::sun::star::uno::Reference< " << scopedBaseName << " > " - << translateUnoToCppIdentifier( - OUStringToOString( - m_reader.getMethodName(i), RTL_TEXTENCODING_UTF8), - "method", ITM_NONGLOBAL, &cppName) + << codemaker::cpp::translateUnoToCppIdentifier( + u2b(i->name), "method", codemaker::cpp::ITM_NONGLOBAL, + &cppName) << ("(::com::sun::star::uno::Reference<" " ::com::sun::star::uno::XComponentContext > const &" " the_context"); - sal_uInt16 params = m_reader.getMethodParameterCount(i); - bool rest = hasRestParameter(i); - for (sal_uInt16 j = 0; j < params; ++j) { + bool rest = hasRestParameter(*i); + for (std::vector< + unoidl::SingleInterfaceBasedServiceEntity::Constructor:: + Parameter >::const_iterator j(i->parameters.begin()); + j != i->parameters.end(); ++j) + { o << ", "; - OStringBuffer buf; - if ((m_reader.getMethodParameterFlags(i, j) & RT_PARAM_REST) - != 0) - { + OUStringBuffer buf; + if (j->rest) { buf.append("[]"); } - buf.append( - OUStringToOString( - m_reader.getMethodParameterTypeName(i, j), - RTL_TEXTENCODING_UTF8)); - OString type(buf.makeStringAndClear()); + buf.append(j->type); + OUString type(buf.makeStringAndClear()); bool byRef = passByReference(type); dumpType(o, type, byRef, byRef); o << " " - << translateUnoToCppIdentifier( - OUStringToOString( - m_reader.getMethodParameterName(i, j), - RTL_TEXTENCODING_UTF8), - "param", ITM_NONGLOBAL); + << codemaker::cpp::translateUnoToCppIdentifier( + u2b(j->name), "param", codemaker::cpp::ITM_NONGLOBAL); } o << ") {\n"; inc(); o << indent() << "assert(the_context.is());\n"; - if (!rest && params > 0) { + if (!rest && !i->parameters.empty()) { o << indent() << ("::com::sun::star::uno::Sequence<" " ::com::sun::star::uno::Any > the_arguments(") - << params << ");\n"; - for (sal_uInt16 j = 0; j < params; ++j) { - o << indent() << "the_arguments[" << j << "] "; + << i->parameters.size() << ");\n"; + std::vector< + unoidl::SingleInterfaceBasedServiceEntity::Constructor:: + Parameter >::size_type n = 0; + for (std::vector< + unoidl::SingleInterfaceBasedServiceEntity:: + Constructor::Parameter >::const_iterator j( + i->parameters.begin()); + j != i->parameters.end(); ++j) + { + o << indent() << "the_arguments[" << n++ << "] "; OString param( - translateUnoToCppIdentifier( - OUStringToOString( - m_reader.getMethodParameterName(i, j), - RTL_TEXTENCODING_UTF8), - "param", ITM_NONGLOBAL)); + codemaker::cpp::translateUnoToCppIdentifier( + u2b(j->name), "param", + codemaker::cpp::ITM_NONGLOBAL)); sal_Int32 rank; if (codemaker::UnoType::getSort( codemaker::UnoType::decompose( - OUStringToOString( - m_reader.getMethodParameterTypeName( - i, j), - RTL_TEXTENCODING_UTF8), - &rank, 0)) + u2b(j->type), &rank, 0)) == codemaker::UnoType::SORT_CHAR) { o << "= ::com::sun::star::uno::Any(&" << param @@ -4082,13 +3532,11 @@ sal_Bool ServiceType::dumpHxxFile( o << indent() << "::com::sun::star::uno::Reference< " << scopedBaseName << " > the_instance;\n"; codemaker::ExceptionTree tree; - sal_uInt16 exceptions = m_reader.getMethodExceptionCount(i); - for (sal_uInt16 j = 0; j < exceptions; ++j) { - tree.add( - OUStringToOString( - m_reader.getMethodExceptionTypeName(i, j), - RTL_TEXTENCODING_UTF8), - m_typeMgr); + for (std::vector< OUString >::const_iterator j( + i->exceptions.begin()); + j != i->exceptions.end(); ++j) + { + tree.add(u2b(*j), m_typeMgr); } if (!tree.getRoot()->present) { o << indent() << "try {\n"; @@ -4098,16 +3546,14 @@ sal_Bool ServiceType::dumpHxxFile( << "the_instance = ::com::sun::star::uno::Reference< " << scopedBaseName << (" >(the_context->getServiceManager()->" - "createInstanceWithArgumentsAndContext(rtl::OUString(" + "createInstanceWithArgumentsAndContext(::rtl::OUString(" " \"") - << fullName << "\" ), "; + << name_ << "\" ), "; if (rest) { - o << translateUnoToCppIdentifier( - OUStringToOString( - m_reader.getMethodParameterName(i, 0), - RTL_TEXTENCODING_UTF8), - "param", ITM_NONGLOBAL); - } else if (params == 0) { + o << codemaker::cpp::translateUnoToCppIdentifier( + u2b(i->parameters.back().name), "param", + codemaker::cpp::ITM_NONGLOBAL); + } else if (i->parameters.empty()) { o << ("::com::sun::star::uno::Sequence<" " ::com::sun::star::uno::Any >()"); } else { @@ -4129,9 +3575,9 @@ sal_Bool ServiceType::dumpHxxFile( inc(); o << indent() << ("throw ::com::sun::star::uno::DeploymentException(" - "rtl::OUString( " + "::rtl::OUString( " "\"component context fails to supply service ") - << fullName << " of type " << fullBaseName + << name_ << " of type " << baseName << ": \" ) + the_exception.Message, the_context);\n"; dec(); o << indent() << "}\n"; @@ -4140,9 +3586,9 @@ sal_Bool ServiceType::dumpHxxFile( inc(); o << indent() << ("throw ::com::sun::star::uno::DeploymentException(" - "rtl::OUString( " + "::rtl::OUString( " "\"component context fails to supply service ") - << fullName << " of type " << fullBaseName + << name_ << " of type " << baseName << "\" ), the_context);\n"; dec(); o << indent() << "}\n" << indent() << "return the_instance;\n"; @@ -4158,30 +3604,10 @@ sal_Bool ServiceType::dumpHxxFile( << indent() << "void operator =(" << cppName << "); // not implemented\n"; dec(); o << "};\n\n"; - if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) { + if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) { o << "\n"; } o << "\n#endif // "<< headerDefine << "\n"; - return true; -} - -void ServiceType::addSpecialDependencies() { - if (m_reader.getMethodCount() > 0) { - OSL_ASSERT(m_reader.getSuperTypeCount() == 1); - m_dependencies.add( - OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8)); - } -} - -bool ServiceType::isDefaultConstructor(sal_uInt16 ctorIndex) const { - return m_reader.getMethodName(ctorIndex).isEmpty(); -} - -bool ServiceType::hasRestParameter(sal_uInt16 ctorIndex) const { - return m_reader.getMethodParameterCount(ctorIndex) == 1 - && ((m_reader.getMethodParameterFlags(ctorIndex, 0) & RT_PARAM_REST) - != 0); } void ServiceType::dumpCatchClauses( @@ -4189,7 +3615,7 @@ void ServiceType::dumpCatchClauses( { if (node->present) { out << indent() << "} catch (const "; - dumpType(out, node->name); + dumpType(out, b2u(node->name)); out << " &) {\n"; inc(); out << indent() << "throw;\n"; @@ -4204,35 +3630,35 @@ void ServiceType::dumpCatchClauses( } } -//************************************************************************* -// SingletonType -//************************************************************************* +class SingletonType: public ConstructiveType { +public: + SingletonType( + rtl::Reference< unoidl::InterfaceBasedSingletonEntity > const & entity, + OUString const & name, rtl::Reference< TypeManager > const & manager): + ConstructiveType(name, manager), entity_(entity) + { assert(entity.is()); } -bool SingletonType::isInterfaceBased() { - return (m_typeMgr->getTypeClass( - OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8))) - == RT_TYPE_INTERFACE; -} +private: + virtual void dumpHxxFile( + FileStream & o, codemaker::cppumaker::Includes & includes); -sal_Bool SingletonType::dumpHxxFile( + rtl::Reference< unoidl::InterfaceBasedSingletonEntity > entity_; +}; + +void SingletonType::dumpHxxFile( FileStream & o, codemaker::cppumaker::Includes & includes) - throw (CannotDumpException) { - OString cppName(translateUnoToCppIdentifier( - m_name, "singleton", isGlobal())); - OString fullName(m_typeName.replace('/', '.')); - OString baseName( - OUStringToOString( - m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8)); - OString fullBaseName(baseName.replace('/', '.')); - OString scopedBaseName(scopedCppName(baseName)); - OString headerDefine(dumpHeaderDefine(o, "HPP")); + OString cppName( + codemaker::cpp::translateUnoToCppIdentifier( + u2b(id_), "singleton", isGlobal())); + OString baseName(u2b(entity_->getBase())); + OString scopedBaseName(codemaker::cpp::scopedCppName(baseName)); + OUString headerDefine(dumpHeaderDefine(o, "HPP")); o << "\n"; //TODO: Decide whether the types added to includes should rather be added to // m_dependencies (and thus be generated during dumpDependedTypes): - includes.add("com/sun/star/uno/DeploymentException"); - includes.add("com/sun/star/uno/XComponentContext"); + includes.add("com.sun.star.uno.DeploymentException"); + includes.add("com.sun.star.uno.XComponentContext"); includes.addCassert(); includes.addAny(); includes.addReference(); @@ -4240,14 +3666,15 @@ sal_Bool SingletonType::dumpHxxFile( includes.addRtlUstringHxx(); includes.dump(o, 0); o << "\n"; - if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) { + if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) { o << "\n"; } o << "\nclass " << cppName << " {\npublic:\n"; inc(); o << indent() << "static ::com::sun::star::uno::Reference< " << scopedBaseName << " > " - << translateUnoToCppIdentifier("get", "method", ITM_NONGLOBAL, &cppName) + << codemaker::cpp::translateUnoToCppIdentifier( + "get", "method", codemaker::cpp::ITM_NONGLOBAL, &cppName) << ("(::com::sun::star::uno::Reference<" " ::com::sun::star::uno::XComponentContext > const & the_context)" " {\n"); @@ -4256,14 +3683,14 @@ sal_Bool SingletonType::dumpHxxFile( << "::com::sun::star::uno::Reference< " << scopedBaseName << " > instance;\n" << indent() << ("if (!(the_context->getValueByName(" - "rtl::OUString( \"/singletons/") - << fullName << "\" )) >>= instance) || !instance.is()) {\n"; + "::rtl::OUString( \"/singletons/") + << name_ << "\" )) >>= instance) || !instance.is()) {\n"; inc(); o << indent() << ("throw ::com::sun::star::uno::DeploymentException(" - "rtl::OUString( \"component context" + "::rtl::OUString( \"component context" " fails to supply singleton ") - << fullName << " of type " << fullBaseName << "\" ), the_context);\n"; + << name_ << " of type " << baseName << "\" ), the_context);\n"; dec(); o << indent() << "}\n" << indent() << "return instance;\n"; dec(); @@ -4275,283 +3702,135 @@ sal_Bool SingletonType::dumpHxxFile( << indent() << "void operator =(" << cppName << "); // not implemented\n"; dec(); o << "};\n\n"; - if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) { + if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) { o << "\n"; } o << "\n#endif // "<< headerDefine << "\n"; - return true; } -//************************************************************************* -// produceType -//************************************************************************* -bool produceType(const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr, - codemaker::GeneratedTypeSet & generated, - CppuOptions* pOptions) - throw( CannotDumpException ) -{ - if (typeName == "/" || typeName == typeMgr->getBase() || - TypeManager::isBaseType(typeName) || generated.contains(typeName)) - { - return true; - } - - sal_Bool bIsExtraType = sal_False; - typereg::Reader reader(typeMgr->getTypeReader(typeName, &bIsExtraType)); - if (bIsExtraType) { - generated.add(typeName); - return true; - } - - if (!reader.isValid()) { - return false; - } - - RTTypeClass typeClass = reader.getTypeClass(); - bool ret = false; - switch (typeClass) - { - case RT_TYPE_INTERFACE: - { - InterfaceType iType(reader, typeName, typeMgr); - ret = iType.dump(pOptions); - if (ret) generated.add(typeName); - iType.dumpDependedTypes(generated, pOptions); - } - break; - case RT_TYPE_MODULE: - { - ModuleType mType(reader, typeName, typeMgr); - if (mType.hasConstants()) - { - ret = mType.dump(pOptions); - if (ret) generated.add(typeName); - } else - { - generated.add(typeName); - ret = true; - } - } - break; - case RT_TYPE_STRUCT: - { - StructureType sType(reader, typeName, typeMgr); - ret = sType.dump(pOptions); - if (ret) generated.add(typeName); - sType.dumpDependedTypes(generated, pOptions); - } - break; - case RT_TYPE_ENUM: - { - EnumType enType(reader, typeName, typeMgr); - ret = enType.dump(pOptions); - if (ret) generated.add(typeName); - enType.dumpDependedTypes(generated, pOptions); - } - break; - case RT_TYPE_EXCEPTION: - { - ExceptionType eType(reader, typeName, typeMgr); - ret = eType.dump(pOptions); - if (ret) generated.add(typeName); - eType.dumpDependedTypes(generated, pOptions); - } - break; - case RT_TYPE_TYPEDEF: - { - TypeDefType tdType(reader, typeName, typeMgr); - ret = tdType.dump(pOptions); - if (ret) generated.add(typeName); - tdType.dumpDependedTypes(generated, pOptions); - } - break; - case RT_TYPE_CONSTANTS: - { - ConstantsType cType(reader, typeName, typeMgr); - if (cType.hasConstants()) - { - ret = cType.dump(pOptions); - if (ret) generated.add(typeName); - } else - { - generated.add(typeName); - ret = true; - } - } - break; - case RT_TYPE_SERVICE: - { - ServiceType t(reader, typeName, typeMgr); - if (t.isSingleInterfaceBased()) { - ret = t.dump(pOptions); - if (ret) { - generated.add(typeName); - t.dumpDependedTypes(generated, pOptions); - } - } else { - ret = true; - } - } - break; - case RT_TYPE_SINGLETON: - { - SingletonType t(reader, typeName, typeMgr); - if (t.isInterfaceBased()) { - ret = t.dump(pOptions); - if (ret) { - generated.add(typeName); - t.dumpDependedTypes(generated, pOptions); - } - } else { - ret = true; - } - } - break; - case RT_TYPE_OBJECT: - ret = true; - break; - default: - OSL_ASSERT(false); - break; - } - - return ret; } -bool produceType(RegistryKey& rTypeKey, bool bIsExtraType, - rtl::Reference< TypeManager > const & typeMgr, - codemaker::GeneratedTypeSet & generated, - CppuOptions* pOptions) - throw( CannotDumpException ) +void produce( + OUString const & name, rtl::Reference< TypeManager > const & manager, + codemaker::GeneratedTypeSet & generated, CppuOptions const & options) { - OString typeName = typeMgr->getTypeName(rTypeKey); - - if (typeName == "/" ||typeName == typeMgr->getBase() || - TypeManager::isBaseType(typeName) || generated.contains(typeName)) - { - return true; - } - - if (bIsExtraType) { - generated.add(typeName); - return true; + if (generated.contains(u2b(name))) { + return; } - - typereg::Reader reader(typeMgr->getTypeReader(rTypeKey)); - if (!reader.isValid()) { - return false; + generated.add(u2b(name)); + if (!manager->foundAtPrimaryProvider(name)) { + return; } - - RTTypeClass typeClass = reader.getTypeClass(); - bool ret = false; - switch (typeClass) - { - case RT_TYPE_INTERFACE: - { - InterfaceType iType(reader, typeName, typeMgr); - ret = iType.dump(pOptions); - if (ret) generated.add(typeName); - iType.dumpDependedTypes(generated, pOptions); + rtl::Reference< unoidl::Entity > ent; + rtl::Reference< unoidl::MapCursor > cur; + switch (manager->getSort(name, &ent, &cur)) { + case codemaker::UnoType::SORT_MODULE: + { + OUString prefix; + if (!name.isEmpty()) { + prefix = name + "."; } - break; - case RT_TYPE_MODULE: - { - ModuleType mType(reader, typeName, typeMgr); - if (mType.hasConstants()) - { - ret = mType.dump(pOptions); - if (ret) generated.add(typeName); - } else - { - generated.add(typeName); - ret = true; + for (;;) { + OUString mem; + if (!cur->getNext(&mem).is()) { + break; } + produce(prefix + mem, manager, generated, options); } break; - case RT_TYPE_STRUCT: - { - StructureType sType(reader, typeName, typeMgr); - ret = sType.dump(pOptions); - if (ret) generated.add(typeName); - sType.dumpDependedTypes(generated, pOptions); - } + } + case codemaker::UnoType::SORT_ENUM_TYPE: + { + EnumType t( + dynamic_cast< unoidl::EnumTypeEntity * >(ent.get()), name, + manager); + t.dump(options); + t.dumpDependedTypes(generated, options); break; - case RT_TYPE_ENUM: - { - EnumType enType(reader, typeName, typeMgr); - ret = enType.dump(pOptions); - if (ret) generated.add(typeName); - enType.dumpDependedTypes(generated, pOptions); - } + } + case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE: + { + PlainStructType t( + dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get()), + name, manager); + t.dump(options); + t.dumpDependedTypes(generated, options); break; - case RT_TYPE_EXCEPTION: - { - ExceptionType eType(reader, typeName, typeMgr); - ret = eType.dump(pOptions); - if (ret) generated.add(typeName); - eType.dumpDependedTypes(generated, pOptions); - } + } + case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE: + { + PolyStructType t( + dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >( + ent.get()), + name, manager); + t.dump(options); + t.dumpDependedTypes(generated, options); break; - case RT_TYPE_TYPEDEF: - { - TypeDefType tdType(reader, typeName, typeMgr); - ret = tdType.dump(pOptions); - if (ret) generated.add(typeName); - tdType.dumpDependedTypes(generated, pOptions); - } + } + case codemaker::UnoType::SORT_EXCEPTION_TYPE: + { + ExceptionType t( + dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()), name, + manager); + t.dump(options); + t.dumpDependedTypes(generated, options); break; - case RT_TYPE_CONSTANTS: - { - ConstantsType cType(reader, typeName, typeMgr); - if (cType.hasConstants()) - { - ret = cType.dump(pOptions); - if (ret) generated.add(typeName); - } else - { - generated.add(typeName); - ret = true; - } - } + } + case codemaker::UnoType::SORT_INTERFACE_TYPE: + { + InterfaceType t( + dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()), name, + manager); + t.dump(options); + t.dumpDependedTypes(generated, options); break; - case RT_TYPE_SERVICE: - { - ServiceType t(reader, typeName, typeMgr); - if (t.isSingleInterfaceBased()) { - ret = t.dump(pOptions); - if (ret) { - generated.add(typeName); - t.dumpDependedTypes(generated, pOptions); - } - } else { - ret = true; - } - } + } + case codemaker::UnoType::SORT_TYPEDEF: + { + Typedef t( + dynamic_cast< unoidl::TypedefEntity * >(ent.get()), name, + manager); + t.dump(options); + t.dumpDependedTypes(generated, options); break; - case RT_TYPE_SINGLETON: - { - SingletonType t(reader, typeName, typeMgr); - if (t.isInterfaceBased()) { - ret = t.dump(pOptions); - if (ret) { - generated.add(typeName); - t.dumpDependedTypes(generated, pOptions); - } - } else { - ret = true; - } + } + case codemaker::UnoType::SORT_CONSTANT_GROUP: + { + ConstantGroup t( + dynamic_cast< unoidl::ConstantGroupEntity * >(ent.get()), name, + manager); + if (t.hasConstants()) { + t.dump(options); } break; - case RT_TYPE_OBJECT: - ret = true; + } + case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE: + { + ServiceType t( + dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >( + ent.get()), + name, manager); + t.dump(options); + t.dumpDependedTypes(generated, options); break; - default: - OSL_ASSERT(false); + } + case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON: + { + SingletonType t( + dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >( + ent.get()), + name, manager); + t.dump(options); + t.dumpDependedTypes(generated, options); break; + } + case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE: + case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON: + break; + default: + throw CannotDumpException( + "unexpected type \"" + name + "\" in call to produce"); } - - return ret; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/codemaker/source/cppumaker/cpputype.hxx b/codemaker/source/cppumaker/cpputype.hxx index 9d92a014b8bd..fd254b06ca65 100644 --- a/codemaker/source/cppumaker/cpputype.hxx +++ b/codemaker/source/cppumaker/cpputype.hxx @@ -20,379 +20,19 @@ #ifndef INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_CPPUTYPE_HXX #define INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_CPPUTYPE_HXX -#include "codemaker/dependencies.hxx" -#include "codemaker/options.hxx" -#include "codemaker/typemanager.hxx" -#include "codemaker/commoncpp.hxx" -#include "registry/reader.hxx" -#include "registry/types.h" -#include "rtl/ref.hxx" -#include "rtl/string.hxx" - -namespace codemaker { - namespace cppumaker { class Includes; } - struct ExceptionTreeNode; - class GeneratedTypeSet; -} +#include "sal/config.h" -enum CppuTypeDecl -{ - CPPUTYPEDECL_ALLTYPES, - CPPUTYPEDECL_NOINTERFACES, - CPPUTYPEDECL_ONLYINTERFACES -}; +#include "rtl/ref.hxx" +namespace codemaker { class GeneratedTypeSet; } +namespace rtl { class OUString; } class CppuOptions; -class FileStream; - -class CppuType -{ -public: - CppuType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr); - - virtual ~CppuType(); - - virtual sal_Bool dump(CppuOptions* pOptions) throw( CannotDumpException ); - sal_Bool dumpFile(CppuOptions* pOptions, - const OString& sExtension, - const OString& sName, - const OString& sOutPath ) - throw( CannotDumpException ); - void dumpDependedTypes( - codemaker::GeneratedTypeSet & generated, CppuOptions * options); - virtual sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ) = 0; - virtual sal_Bool dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ) = 0; - - OString dumpHeaderDefine( - FileStream& o, char const * prefix, sal_Bool bExtended=sal_False); - - void dumpGetCppuType(FileStream & out); - virtual void dumpLightGetCppuType(FileStream& o); - virtual void dumpNormalGetCppuType(FileStream& o); - virtual void dumpComprehensiveGetCppuType(FileStream& o); - - virtual void dumpType(FileStream& o, const OString& type, bool bConst=false, - bool bRef=false, bool bNative=false, bool cppuUnoType=false) - const throw( CannotDumpException ); - OString getTypeClass(const OString& type="", sal_Bool bCStyle=sal_False); - void dumpCppuGetType(FileStream& o, const OString& type, sal_Bool bDecl=sal_False, CppuTypeDecl eDeclFlag=CPPUTYPEDECL_ALLTYPES); - - OString typeToIdentifier(const OString& type); - - void dumpConstantValue(FileStream& o, sal_uInt16 index); - - virtual sal_uInt32 getMemberCount(); - virtual sal_uInt32 getInheritedMemberCount(); - - void inc(sal_Int32 num=4); - void dec(sal_Int32 num=4); - OString indent() const; -protected: - virtual sal_uInt32 checkInheritedMemberCount( - const typereg::Reader* pReader); - - bool passByReference(OString const & unoType); - - OString resolveTypedefs(const OString& type) const; - OString checkRealBaseType(const OString& type, sal_Bool bResolveTypeOnly = sal_False) const; - void dumpCppuGetTypeMemberDecl(FileStream& o, CppuTypeDecl eDeclFlag); - - codemaker::cpp::IdentifierTranslationMode isGlobal() const; - - virtual void dumpDeclaration(FileStream & out) throw (CannotDumpException); - - virtual void addSpecialDependencies() {} - - virtual bool dumpFiles(CppuOptions * options, OString const & outPath); - - virtual void addLightGetCppuTypeIncludes( - codemaker::cppumaker::Includes & includes) const; - - virtual void addNormalGetCppuTypeIncludes( - codemaker::cppumaker::Includes & includes) const; - - virtual void addComprehensiveGetCppuTypeIncludes( - codemaker::cppumaker::Includes & includes) const; - - virtual bool isPolymorphic() const; - - virtual void dumpTemplateHead(FileStream & out) const; - - virtual void dumpTemplateParameters(FileStream & out) const; - - void dumpGetCppuTypePreamble(FileStream & out); - - void dumpGetCppuTypePostamble(FileStream & out); - - void addDefaultHIncludes(codemaker::cppumaker::Includes & includes) const; - void addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes) const; - - void dumpInitializer( - FileStream & out, bool parameterized, OUString const & type) const; - - void dumpHFileContent( - FileStream & out, codemaker::cppumaker::Includes & includes); - -protected: - sal_uInt32 m_inheritedMemberCount; - - bool m_cppuTypeLeak; - bool m_cppuTypeDynamic; - sal_Int32 m_indentLength; - OString m_typeName; - OString m_name; - typereg::Reader m_reader; - rtl::Reference< TypeManager > m_typeMgr; - codemaker::Dependencies m_dependencies; - -private: - void addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes) - const; -}; - -class InterfaceType : public CppuType -{ -public: - InterfaceType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr); - - virtual ~InterfaceType(); - - virtual void dumpDeclaration(FileStream& o) throw( CannotDumpException ); - sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ); - sal_Bool dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ); - - void dumpAttributes(FileStream& o); - void dumpMethods(FileStream& o); - void dumpNormalGetCppuType(FileStream& o); - void dumpComprehensiveGetCppuType(FileStream& o); - void dumpCppuAttributeRefs(FileStream& o, sal_uInt32& index); - void dumpCppuMethodRefs(FileStream& o, sal_uInt32& index); - void dumpCppuAttributes(FileStream& o, sal_uInt32& index); - void dumpCppuMethods(FileStream& o, sal_uInt32& index); - void dumpAttributesCppuDecl(FileStream& o, StringSet* pFinishedTypes, CppuTypeDecl eDeclFlag); - void dumpMethodsCppuDecl(FileStream& o, StringSet* pFinishedTypes, CppuTypeDecl eDeclFlag ); - - sal_uInt32 getMemberCount(); - sal_uInt32 getInheritedMemberCount(); - -protected: - virtual void addSpecialDependencies(); - - virtual void addComprehensiveGetCppuTypeIncludes( - codemaker::cppumaker::Includes & includes) const; - - sal_uInt32 checkInheritedMemberCount(const typereg::Reader* pReader); - -protected: - sal_uInt32 m_inheritedMemberCount; - bool m_hasAttributes; - bool m_hasMethods; - bool m_isDeprecated; - -private: - void dumpExceptionSpecification( - FileStream & out, sal_uInt32 methodIndex, bool runtimeException); - - void dumpAttributeExceptionSpecification( - FileStream & out, OUString const & name, RTMethodMode sort); - - void dumpExceptionTypeName( - FileStream & out, char const * prefix, sal_uInt32 index, - OUString name); - - sal_Int32 dumpExceptionTypeNames( - FileStream & out, char const * prefix, sal_uInt16 methodIndex, - bool runtimeException); - - sal_Int32 dumpAttributeExceptionTypeNames( - FileStream & out, char const * prefix, OUString const & name, - RTMethodMode sort); -}; - -class ConstantsType : public CppuType -{ -public: - ConstantsType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr); - - virtual ~ConstantsType(); - - virtual sal_Bool dump(CppuOptions* pOptions) throw( CannotDumpException ); - - virtual void dumpDeclaration(FileStream& o) throw( CannotDumpException ); - sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ); - sal_Bool dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ); - sal_Bool hasConstants(); -}; - -class ModuleType : public ConstantsType -{ -public: - ModuleType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr); - - virtual ~ModuleType(); - -protected: - virtual bool dumpFiles(CppuOptions * options, OString const & outPath); -}; - -class StructureType : public CppuType -{ -public: - StructureType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr); - - virtual ~StructureType(); - - virtual void dumpDeclaration(FileStream& o) throw( CannotDumpException ); - sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ); - sal_Bool dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ); - - virtual void dumpLightGetCppuType(FileStream & out); - - virtual void dumpNormalGetCppuType(FileStream & out); - - virtual void dumpComprehensiveGetCppuType(FileStream & out); - - sal_Bool dumpSuperMember(FileStream& o, const OString& super, sal_Bool bWithType); - -protected: - virtual void addLightGetCppuTypeIncludes( - codemaker::cppumaker::Includes & includes) const; - - virtual void addNormalGetCppuTypeIncludes( - codemaker::cppumaker::Includes & includes) const; - - virtual void addComprehensiveGetCppuTypeIncludes( - codemaker::cppumaker::Includes & includes) const; - - virtual bool isPolymorphic() const; - - virtual void dumpTemplateHead(FileStream & out) const; - - virtual void dumpTemplateParameters(FileStream & out) const; -}; - -class ExceptionType : public CppuType -{ -public: - ExceptionType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr); - - virtual ~ExceptionType(); - - virtual void dumpDeclaration(FileStream& o) throw( CannotDumpException ); - sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ); - sal_Bool dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ); - - sal_Bool dumpSuperMember(FileStream& o, const OString& super, sal_Bool bWithType); -}; - -class EnumType : public CppuType -{ -public: - EnumType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr); - - virtual ~EnumType(); - - virtual void dumpDeclaration(FileStream& o) throw( CannotDumpException ); - sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ); - sal_Bool dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ); - - void dumpNormalGetCppuType(FileStream& o); - void dumpComprehensiveGetCppuType(FileStream& o); -}; - -class TypeDefType : public CppuType -{ -public: - TypeDefType(typereg::Reader& typeReader, - const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr); - - virtual ~TypeDefType(); - - virtual void dumpDeclaration(FileStream& o) throw( CannotDumpException ); - sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ); - sal_Bool dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException ); -}; - -class ConstructiveType: public CppuType { -public: - ConstructiveType( - typereg::Reader & reader, OString const & name, - rtl::Reference< TypeManager > const & manager): - CppuType(reader, name, manager) {} - - virtual sal_Bool dumpHFile( - FileStream & o, codemaker::cppumaker::Includes & includes) - throw (CannotDumpException); - -protected: - virtual bool dumpFiles(CppuOptions * options, OString const & outPath); -}; - -class ServiceType: public ConstructiveType { -public: - ServiceType( - typereg::Reader & reader, OString const & name, - rtl::Reference< TypeManager > const & manager): - ConstructiveType(reader, name, manager) {} - - bool isSingleInterfaceBased(); - - virtual sal_Bool dumpHxxFile( - FileStream & o, codemaker::cppumaker::Includes & includes) - throw (CannotDumpException); - -private: - virtual void addSpecialDependencies(); - - bool isDefaultConstructor(sal_uInt16 ctorIndex) const; - - bool hasRestParameter(sal_uInt16 ctorIndex) const; - - void dumpCatchClauses( - FileStream & out, codemaker::ExceptionTreeNode const * node); -}; - -class SingletonType: public ConstructiveType { -public: - SingletonType( - typereg::Reader & reader, OString const & name, - rtl::Reference< TypeManager > const & manager): - ConstructiveType(reader, name, manager) {} - - bool isInterfaceBased(); - - virtual sal_Bool dumpHxxFile( - FileStream & o, codemaker::cppumaker::Includes & includes) - throw (CannotDumpException); -}; - -bool produceType(const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr, - codemaker::GeneratedTypeSet & generated, - CppuOptions* pOptions) - throw( CannotDumpException ); +class TypeManager; -bool produceType(RegistryKey& typeName, bool bIsExtraType, - rtl::Reference< TypeManager > const & typeMgr, - codemaker::GeneratedTypeSet & generated, - CppuOptions* pOptions) - throw( CannotDumpException ); +void produce( + rtl::OUString const & name, rtl::Reference< TypeManager > const & manager, + codemaker::GeneratedTypeSet & generated, CppuOptions const & options); -#endif // INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_CPPUTYPE_HXX +#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/codemaker/source/cppumaker/dependencies.cxx b/codemaker/source/cppumaker/dependencies.cxx new file mode 100644 index 000000000000..35a4ab37cd86 --- /dev/null +++ b/codemaker/source/cppumaker/dependencies.cxx @@ -0,0 +1,330 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "sal/config.h" + +#include <cassert> +#include <utility> +#include <vector> + +#include "codemaker/typemanager.hxx" +#include "codemaker/unotype.hxx" + +#include "osl/diagnose.h" +#include "rtl/ref.hxx" +#include "rtl/string.hxx" +#include "rtl/ustring.hxx" +#include "sal/types.h" +#include "unoidl/unoidl.hxx" + +#include "dependencies.hxx" + +namespace codemaker { namespace cppumaker { + +Dependencies::Dependencies( + rtl::Reference< TypeManager > const & manager, OUString const & name): + m_manager(manager), m_voidDependency(false), m_booleanDependency(false), + m_byteDependency(false), m_shortDependency(false), + m_unsignedShortDependency(false), m_longDependency(false), + m_unsignedLongDependency(false), m_hyperDependency(false), + m_unsignedHyperDependency(false), m_floatDependency(false), + m_doubleDependency(false), m_charDependency(false), + m_stringDependency(false), m_typeDependency(false), m_anyDependency(false), + m_sequenceDependency(false) +{ + assert(manager.is()); + rtl::Reference< unoidl::Entity > ent; + switch (m_manager->getSort(name, &ent)) { + case UnoType::SORT_ENUM_TYPE: + break; + case UnoType::SORT_PLAIN_STRUCT_TYPE: + { + rtl::Reference< unoidl::PlainStructTypeEntity > ent2( + static_cast< unoidl::PlainStructTypeEntity * >(ent.get())); + if (!ent2->getDirectBase().isEmpty()) { + insert(ent2->getDirectBase()); + } + for (std::vector< unoidl::PlainStructTypeEntity::Member >:: + const_iterator i(ent2->getDirectMembers().begin()); + i != ent2->getDirectMembers().end(); ++i) + { + insert(i->type); + } + break; + } + case UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE: + { + rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2( + static_cast< unoidl::PolymorphicStructTypeTemplateEntity * >( + ent.get())); + for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity:: + Member >::const_iterator i(ent2->getMembers().begin()); + i != ent2->getMembers().end(); ++i) + { + if (!i->parameterized) { + insert(i->type); + } + } + break; + } + case UnoType::SORT_EXCEPTION_TYPE: + { + rtl::Reference< unoidl::ExceptionTypeEntity > ent2( + static_cast< unoidl::ExceptionTypeEntity * >(ent.get())); + if (!ent2->getDirectBase().isEmpty()) { + insert(ent2->getDirectBase()); + } + for (std::vector< unoidl::ExceptionTypeEntity::Member >:: + const_iterator i(ent2->getDirectMembers().begin()); + i != ent2->getDirectMembers().end(); ++i) + { + insert(i->type); + } + break; + } + case UnoType::SORT_INTERFACE_TYPE: + { + rtl::Reference< unoidl::InterfaceTypeEntity > ent2( + static_cast< unoidl::InterfaceTypeEntity * >(ent.get())); + for (std::vector< OUString >::const_iterator i( + ent2->getDirectMandatoryBases().begin()); + i != ent2->getDirectMandatoryBases().end(); ++i) + { + insert(*i, true); + } + if (!(ent2->getDirectAttributes().empty() + && ent2->getDirectMethods().empty())) + { + insert("com.sun.star.uno.RuntimeException"); + } + for (std::vector< unoidl::InterfaceTypeEntity::Attribute >:: + const_iterator i(ent2->getDirectAttributes().begin()); + i != ent2->getDirectAttributes().end(); ++i) + { + insert(i->type); + for (std::vector< OUString >::const_iterator j( + i->getExceptions.begin()); + j != i->getExceptions.end(); ++j) + { + insert(*j); + } + for (std::vector< OUString >::const_iterator j( + i->setExceptions.begin()); + j != i->setExceptions.end(); ++j) + { + insert(*j); + } + } + for (std::vector< unoidl::InterfaceTypeEntity::Method >:: + const_iterator i(ent2->getDirectMethods().begin()); + i != ent2->getDirectMethods().end(); ++i) + { + insert(i->returnType); + for (std::vector< + unoidl::InterfaceTypeEntity::Method::Parameter >:: + const_iterator j(i->parameters.begin()); + j != i->parameters.end(); ++j) + { + insert(j->type); + } + for (std::vector< OUString >::const_iterator j( + i->exceptions.begin()); + j != i->exceptions.end(); ++j) + { + insert(*j); + } + } + break; + } + case UnoType::SORT_TYPEDEF: + insert(static_cast< unoidl::TypedefEntity * >(ent.get())->getType()); + break; + case UnoType::SORT_CONSTANT_GROUP: + { + rtl::Reference< unoidl::ConstantGroupEntity > ent2( + static_cast< unoidl::ConstantGroupEntity * >(ent.get())); + for (std::vector< unoidl::ConstantGroupEntity::Member >:: + const_iterator i(ent2->getMembers().begin()); + i != ent2->getMembers().end(); ++i) + { + switch (i->value.type) { + case unoidl::ConstantValue::TYPE_BOOLEAN: + m_booleanDependency = true; + break; + case unoidl::ConstantValue::TYPE_BYTE: + m_byteDependency = true; + break; + case unoidl::ConstantValue::TYPE_SHORT: + m_shortDependency = true; + break; + case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT: + m_unsignedShortDependency = true; + break; + case unoidl::ConstantValue::TYPE_LONG: + m_longDependency = true; + break; + case unoidl::ConstantValue::TYPE_UNSIGNED_LONG: + m_unsignedLongDependency = true; + break; + case unoidl::ConstantValue::TYPE_HYPER: + m_hyperDependency = true; + break; + case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER: + m_unsignedHyperDependency = true; + break; + case unoidl::ConstantValue::TYPE_FLOAT: + m_floatDependency = true; + break; + case unoidl::ConstantValue::TYPE_DOUBLE: + m_doubleDependency = true; + break; + } + } + break; + } + case UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE: + { + rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2( + static_cast< unoidl::SingleInterfaceBasedServiceEntity * >( + ent.get())); + if (!ent2->getConstructors().empty()) { + insert(ent2->getBase()); + } + for (std::vector< + unoidl::SingleInterfaceBasedServiceEntity::Constructor >:: + const_iterator i(ent2->getConstructors().begin()); + i != ent2->getConstructors().end(); ++i) + { + for (std::vector< + unoidl::SingleInterfaceBasedServiceEntity:: + Constructor::Parameter >::const_iterator j( + i->parameters.begin()); + j != i->parameters.end(); ++j) + { + insert(j->type); + if (j->rest) { + m_sequenceDependency = true; + } + } + for (std::vector< OUString >::const_iterator j( + i->exceptions.begin()); + j != i->exceptions.end(); ++j) + { + insert(*j); + } + } + break; + } + case UnoType::SORT_INTERFACE_BASED_SINGLETON: + insert( + static_cast< unoidl::InterfaceBasedSingletonEntity * >(ent.get())-> + getBase()); + break; + default: + assert(false); // this cannot happen + } +} + +Dependencies::~Dependencies() {} + +void Dependencies::insert(OUString const & name, bool base) { + sal_Int32 k; + std::vector< OString > args; + OUString n(b2u(UnoType::decompose(u2b(name), &k, &args))); + if (k != 0) { + m_sequenceDependency = true; + } + switch (m_manager->getSort(n)) { + case UnoType::SORT_VOID: + m_voidDependency = true; + break; + case UnoType::SORT_BOOLEAN: + m_booleanDependency = true; + break; + case UnoType::SORT_BYTE: + m_byteDependency = true; + break; + case UnoType::SORT_SHORT: + m_shortDependency = true; + break; + case UnoType::SORT_UNSIGNED_SHORT: + m_unsignedShortDependency = true; + break; + case UnoType::SORT_LONG: + m_longDependency = true; + break; + case UnoType::SORT_UNSIGNED_LONG: + m_unsignedLongDependency = true; + break; + case UnoType::SORT_HYPER: + m_hyperDependency = true; + break; + case UnoType::SORT_UNSIGNED_HYPER: + m_unsignedHyperDependency = true; + break; + case UnoType::SORT_FLOAT: + m_floatDependency = true; + break; + case UnoType::SORT_DOUBLE: + m_doubleDependency = true; + break; + case UnoType::SORT_CHAR: + m_charDependency = true; + break; + case UnoType::SORT_STRING: + m_stringDependency = true; + break; + case UnoType::SORT_TYPE: + m_typeDependency = true; + break; + case UnoType::SORT_ANY: + m_anyDependency = true; + break; + case UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE: + for (std::vector< OString >::iterator i(args.begin()); i != args.end(); + ++i) + { + insert(b2u(*i), false); + } + // fall through + case UnoType::SORT_SEQUENCE_TYPE: + case UnoType::SORT_ENUM_TYPE: + case UnoType::SORT_PLAIN_STRUCT_TYPE: + case UnoType::SORT_EXCEPTION_TYPE: + case UnoType::SORT_INTERFACE_TYPE: + case UnoType::SORT_TYPEDEF: + { + std::pair< Map::iterator, bool > i( + m_map.insert( + Map::value_type(n, base ? KIND_BASE : KIND_NO_BASE))); + if (!i.second && base) { + i.first->second = KIND_BASE; + } + break; + } + default: + throw CannotDumpException( + "unexpected type \"" + name + + "\" in call to codemaker::cppumaker::Dependencies::Dependencies"); + } +} + +} } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/codemaker/source/cppumaker/dependencies.hxx b/codemaker/source/cppumaker/dependencies.hxx new file mode 100644 index 000000000000..d0c09aed59f0 --- /dev/null +++ b/codemaker/source/cppumaker/dependencies.hxx @@ -0,0 +1,140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_DEPENDENCIES_HXX +#define INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_DEPENDENCIES_HXX + +#include "sal/config.h" + +#include <map> + +#include "boost/noncopyable.hpp" +#include "rtl/ref.hxx" + +namespace rtl { class OUString; } +class TypeManager; + +/// @HTML + +namespace codemaker { namespace cppumaker { + +/** + A simple class to track which other entites a given entity depends on. + + <p>This class is not multi-thread–safe.</p> + */ +class Dependencies: private boost::noncopyable { +public: + /** + Flags to distinguish whether or not one entity depends on another entity + because the second is a direct base of the first. + */ + enum Kind { KIND_NO_BASE, KIND_BASE }; + + typedef std::map< rtl::OUString, Kind > Map; + + /** + Constructs the dependencies for a given entity. + + @param manager a type manager, to obtain information about the given + entity; must not be null + + @param name the UNOIDL name of an enum type, plain struct type, + polymorphic struct type template, exception type, interface type, + typedef, constant group, single-interface--based service, or + interface-based singleton entity + */ + Dependencies( + rtl::Reference< TypeManager > const & manager, + rtl::OUString const & name); + + ~Dependencies(); + + /** + Add a special dependency (which is not obvious from the entity's data + available at the type manager). + + @param name a UNOIDL entity name + */ + void add(rtl::OUString const & name) { insert(name); } + + Map const & getMap() const { return m_map; } + + bool hasVoidDependency() const { return m_voidDependency; } + + bool hasBooleanDependency() const { return m_booleanDependency; } + + bool hasByteDependency() const { return m_byteDependency; } + + bool hasShortDependency() const { return m_shortDependency; } + + bool hasUnsignedShortDependency() const + { return m_unsignedShortDependency; } + + bool hasLongDependency() const { return m_longDependency; } + + bool hasUnsignedLongDependency() const { return m_unsignedLongDependency; } + + bool hasHyperDependency() const { return m_hyperDependency; } + + bool hasUnsignedHyperDependency() const + { return m_unsignedHyperDependency; } + + bool hasFloatDependency() const { return m_floatDependency; } + + bool hasDoubleDependency() const { return m_doubleDependency; } + + bool hasCharDependency() const { return m_charDependency; } + + bool hasStringDependency() const { return m_stringDependency; } + + bool hasTypeDependency() const { return m_typeDependency; } + + bool hasAnyDependency() const { return m_anyDependency; } + + bool hasSequenceDependency() const { return m_sequenceDependency; } + +private: + void insert(rtl::OUString const & name, bool base = false); + + rtl::Reference< TypeManager > m_manager; + Map m_map; + bool m_voidDependency; + bool m_booleanDependency; + bool m_byteDependency; + bool m_shortDependency; + bool m_unsignedShortDependency; + bool m_longDependency; + bool m_unsignedLongDependency; + bool m_hyperDependency; + bool m_unsignedHyperDependency; + bool m_floatDependency; + bool m_doubleDependency; + bool m_charDependency; + bool m_stringDependency; + bool m_typeDependency; + bool m_anyDependency; + bool m_sequenceDependency; +}; + +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/codemaker/source/cppumaker/dumputils.cxx b/codemaker/source/cppumaker/dumputils.cxx index bc1781314789..4c8282443dba 100644 --- a/codemaker/source/cppumaker/dumputils.cxx +++ b/codemaker/source/cppumaker/dumputils.cxx @@ -30,52 +30,48 @@ namespace codemaker { namespace cppumaker { bool dumpNamespaceOpen( - FileStream & out, OString const & registryType, bool fullModuleType) + FileStream & out, rtl::OUString const & entityName, bool fullModuleType) { bool output = false; - if (registryType != "/") { - bool first = true; - for (sal_Int32 i = 0; i >= 0;) { - OString id(registryType.getToken(0, '/', i)); - if (fullModuleType || i >= 0) { - if (!first) { - out << " "; - } - out << "namespace " << id << " {"; - first = false; - output = true; + bool first = true; + for (sal_Int32 i = 0; i >= 0;) { + rtl::OUString id(entityName.getToken(0, '.', i)); + if (fullModuleType || i >= 0) { + if (!first) { + out << " "; } + out << "namespace " << id << " {"; + first = false; + output = true; } } return output; } bool dumpNamespaceClose( - FileStream & out, OString const & registryType, bool fullModuleType) + FileStream & out, rtl::OUString const & entityName, bool fullModuleType) { bool output = false; - if (registryType != "/") { - bool first = true; - for (sal_Int32 i = 0; i >= 0;) { - i = registryType.indexOf('/', i); - if (i >= 0) { - ++i; - } - if (fullModuleType || i >= 0) { - if (!first) { - out << " "; - } - out << "}"; - first = false; - output = true; + bool first = true; + for (sal_Int32 i = 0; i >= 0;) { + i = entityName.indexOf('.', i); + if (i >= 0) { + ++i; + } + if (fullModuleType || i >= 0) { + if (!first) { + out << " "; } + out << "}"; + first = false; + output = true; } } return output; } -void dumpTypeIdentifier(FileStream & out, OString const & registryType) { - out << registryType.copy(registryType.lastIndexOf('/') + 1); +void dumpTypeIdentifier(FileStream & out, rtl::OUString const & entityName) { + out << entityName.copy(entityName.lastIndexOf('.') + 1); } } } diff --git a/codemaker/source/cppumaker/dumputils.hxx b/codemaker/source/cppumaker/dumputils.hxx index 855e412534de..c00bd266b87a 100644 --- a/codemaker/source/cppumaker/dumputils.hxx +++ b/codemaker/source/cppumaker/dumputils.hxx @@ -20,22 +20,23 @@ #ifndef INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_DUMPUTILS_HXX #define INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_DUMPUTILS_HXX -#include <rtl/ustring.hxx> +#include "sal/config.h" +namespace rtl { class OUString; } class FileStream; namespace codemaker { namespace cppumaker { bool dumpNamespaceOpen( - FileStream & out, OString const & registryType, bool fullModuleType); + FileStream & out, rtl::OUString const & entityName, bool fullModuleType); bool dumpNamespaceClose( - FileStream & out, OString const & registryType, bool fullModuleType); + FileStream & out, rtl::OUString const & entityName, bool fullModuleType); -void dumpTypeIdentifier(FileStream & out, OString const & registryType); +void dumpTypeIdentifier(FileStream & out, rtl::OUString const & entityName); } } -#endif // INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_DUMPUTILS_HXX +#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/codemaker/source/cppumaker/includes.cxx b/codemaker/source/cppumaker/includes.cxx index 34f23e954bf1..c6516745a5d2 100644..100755 --- a/codemaker/source/cppumaker/includes.cxx +++ b/codemaker/source/cppumaker/includes.cxx @@ -20,9 +20,9 @@ #include "includes.hxx" +#include "dependencies.hxx" #include "dumputils.hxx" -#include "codemaker/dependencies.hxx" #include "codemaker/global.hxx" #include "codemaker/typemanager.hxx" #include "codemaker/unotype.hxx" @@ -39,7 +39,7 @@ using codemaker::cppumaker::Includes; Includes::Includes( rtl::Reference< TypeManager > const & manager, - codemaker::Dependencies const & dependencies, bool hpp): + codemaker::cppumaker::Dependencies const & dependencies, bool hpp): m_manager(manager), m_map(dependencies.getMap()), m_hpp(hpp), m_includeCassert(false), m_includeAny(dependencies.hasAnyDependency()), m_includeReference(false), @@ -68,20 +68,14 @@ Includes::Includes( Includes::~Includes() {} -void Includes::add(OString const & registryType) { - sal_Int32 rank; +void Includes::add(OString const & entityName) { + sal_Int32 k; std::vector< OString > args; - OString type( - codemaker::UnoType::decompose(registryType, &rank, &args)); - if (rank > 0) { + OUString n(b2u(codemaker::UnoType::decompose(entityName, &k, &args))); + if (k != 0) { m_includeSequence = true; } - switch (codemaker::UnoType::getSort(type)) { - case codemaker::UnoType::SORT_VOID: - OSL_ASSERT(args.empty()); - OSL_ASSERT(false); - break; - + switch (m_manager->getSort(n)) { case codemaker::UnoType::SORT_BOOLEAN: case codemaker::UnoType::SORT_BYTE: case codemaker::UnoType::SORT_SHORT: @@ -91,44 +85,40 @@ void Includes::add(OString const & registryType) { case codemaker::UnoType::SORT_HYPER: case codemaker::UnoType::SORT_UNSIGNED_HYPER: case codemaker::UnoType::SORT_CHAR: - OSL_ASSERT(args.empty()); m_includeSalTypesH = true; break; - case codemaker::UnoType::SORT_FLOAT: case codemaker::UnoType::SORT_DOUBLE: - OSL_ASSERT(args.empty()); break; - case codemaker::UnoType::SORT_STRING: - OSL_ASSERT(args.empty()); m_includeRtlUstringHxx = true; break; - case codemaker::UnoType::SORT_TYPE: - OSL_ASSERT(args.empty()); m_includeType = true; break; - case codemaker::UnoType::SORT_ANY: - OSL_ASSERT(args.empty()); m_includeAny = true; break; - - case codemaker::UnoType::SORT_COMPLEX: - m_map.insert( - codemaker::Dependencies::Map::value_type( - type, codemaker::Dependencies::KIND_NO_BASE)); - for (std::vector< OString >::iterator i(args.begin()); - i != args.end(); ++i) + case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE: + for (std::vector< OString >::iterator i(args.begin()); i != args.end(); + ++i) { add(*i); } + // fall through + case codemaker::UnoType::SORT_SEQUENCE_TYPE: + case codemaker::UnoType::SORT_ENUM_TYPE: + case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE: + case codemaker::UnoType::SORT_EXCEPTION_TYPE: + case codemaker::UnoType::SORT_INTERFACE_TYPE: + case codemaker::UnoType::SORT_TYPEDEF: + m_map.insert( + Dependencies::Map::value_type(n, Dependencies::KIND_NO_BASE)); break; - default: - OSL_ASSERT(false); - break; + throw CannotDumpException( + "unexpected type \"" + b2u(entityName) + + "\" in call to codemaker::cppumaker::Includes::add"); } } @@ -144,13 +134,13 @@ void dumpEmptyLineBeforeFirst(FileStream & out, bool * first) { } -void Includes::dump(FileStream & out, OString const * companionHdl) { +void Includes::dump(FileStream & out, OUString const * companionHdl) { OSL_ASSERT(companionHdl == 0 || m_hpp); if (!m_includeReference) { - for (codemaker::Dependencies::Map::iterator i(m_map.begin()); - i != m_map.end(); ++i) + for (Dependencies::Map::iterator i(m_map.begin()); i != m_map.end(); + ++i) { - if (isInterfaceType(i->first)) { + if (isInterfaceType(u2b(i->first))) { m_includeReference = true; break; } @@ -162,17 +152,16 @@ void Includes::dump(FileStream & out, OString const * companionHdl) { } if (companionHdl) { out << "\n"; - dumpInclude(out, *companionHdl, false); + dumpInclude(out, u2b(*companionHdl), false); } bool first = true; - for (codemaker::Dependencies::Map::iterator i(m_map.begin()); - i != m_map.end(); ++i) + for (Dependencies::Map::iterator i(m_map.begin()); i != m_map.end(); ++i) { dumpEmptyLineBeforeFirst(out, &first); - if (m_hpp || i->second == codemaker::Dependencies::KIND_BASE - || !isInterfaceType(i->first)) + if (m_hpp || i->second == Dependencies::KIND_BASE + || !isInterfaceType(u2b(i->first))) { - dumpInclude(out, i->first, m_hpp); + dumpInclude(out, u2b(i->first), m_hpp); } else { bool ns = dumpNamespaceOpen(out, i->first, false); if (ns) { @@ -191,19 +180,23 @@ void Includes::dump(FileStream & out, OString const * companionHdl) { static char const * hxxExtension[2] = { "h", "hxx" }; if (m_includeAny) { dumpEmptyLineBeforeFirst(out, &first); - out << "#include \"com/sun/star/uno/Any." << hxxExtension[m_hpp] << "\"\n"; + out << "#include \"com/sun/star/uno/Any." << hxxExtension[m_hpp] + << "\"\n"; } if (m_includeReference) { dumpEmptyLineBeforeFirst(out, &first); - out << "#include \"com/sun/star/uno/Reference." << hxxExtension[m_hpp] << "\"\n"; + out << "#include \"com/sun/star/uno/Reference." << hxxExtension[m_hpp] + << "\"\n"; } if (m_includeSequence) { dumpEmptyLineBeforeFirst(out, &first); - out << "#include \"com/sun/star/uno/Sequence." << hxxExtension[m_hpp] << "\"\n"; + out << "#include \"com/sun/star/uno/Sequence." << hxxExtension[m_hpp] + << "\"\n"; } if (m_includeType) { dumpEmptyLineBeforeFirst(out, &first); - out << "#include \"com/sun/star/uno/Type." << hxxExtension[m_hpp] << "\"\n"; + out << "#include \"com/sun/star/uno/Type." << hxxExtension[m_hpp] + << "\"\n"; } if (m_includeCppuMacrosHxx) { dumpEmptyLineBeforeFirst(out, &first); @@ -264,19 +257,14 @@ void Includes::dump(FileStream & out, OString const * companionHdl) { } void Includes::dumpInclude( - FileStream & out, OString const & registryType, bool hpp, - OString const & suffix) + FileStream & out, OString const & entityName, bool hpp) { - static char const * extension[2] = { "hdl", "hpp" }; - out << "#include \"" << registryType; - if (!suffix.isEmpty()) { - out << "/" << suffix; - } - out << "." << extension[hpp] << "\"\n"; + out << "#include \"" << entityName.replace('.', '/') << "." + << (hpp ? "hpp" : "hdl") << "\"\n"; } -bool Includes::isInterfaceType(OString const & registryType) const { - return m_manager->getTypeClass(registryType) == RT_TYPE_INTERFACE; +bool Includes::isInterfaceType(OString const & entityName) const { + return m_manager->getSort(b2u(entityName)) == UnoType::SORT_INTERFACE_TYPE; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/codemaker/source/cppumaker/includes.hxx b/codemaker/source/cppumaker/includes.hxx index 80b842cd09d9..a70aa9b06b38 100644 --- a/codemaker/source/cppumaker/includes.hxx +++ b/codemaker/source/cppumaker/includes.hxx @@ -20,10 +20,11 @@ #ifndef INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_INCLUDES_HXX #define INCLUDED_CODEMAKER_SOURCE_CPPUMAKER_INCLUDES_HXX -#include "codemaker/dependencies.hxx" #include "rtl/ref.hxx" #include "rtl/ustring.hxx" +#include "dependencies.hxx" + class FileStream; class TypeManager; @@ -33,11 +34,11 @@ class Includes { public: Includes( rtl::Reference< TypeManager > const & manager, - codemaker::Dependencies const & dependencies, bool hpp); + Dependencies const & dependencies, bool hpp); ~Includes(); - void add(OString const & registryType); + void add(OString const & entityName); void addCassert() { m_includeCassert = true; } void addAny() { m_includeAny = true; } void addReference() { m_includeReference = true; } @@ -59,20 +60,19 @@ public: void addTypelibTypeclassH() { m_includeTypelibTypeclassH = true; } void addTypelibTypedescriptionH() { m_includeTypelibTypedescriptionH = true; } - void dump(FileStream & out, OString const * companionHdl); + void dump(FileStream & out, OUString const * companionHdl); static void dumpInclude( - FileStream & out, OString const & registryType, bool hpp, - OString const & suffix = OString()); + FileStream & out, OString const & entityName, bool hpp); private: Includes(Includes &); // not implemented void operator =(Includes); // not implemented; - bool isInterfaceType(OString const & registryType) const; + bool isInterfaceType(OString const & entityName) const; rtl::Reference< TypeManager > m_manager; - codemaker::Dependencies::Map m_map; + Dependencies::Map m_map; bool m_hpp; bool m_includeCassert; bool m_includeAny; diff --git a/codemaker/source/javamaker/classfile.hxx b/codemaker/source/javamaker/classfile.hxx index 488660b7a175..15465d0132c7 100644 --- a/codemaker/source/javamaker/classfile.hxx +++ b/codemaker/source/javamaker/classfile.hxx @@ -55,53 +55,53 @@ public: void instrAastore(); void instrAconstNull(); - void instrAnewarray(OString const & type); + void instrAnewarray(rtl::OString const & type); void instrAreturn(); void instrAthrow(); - void instrCheckcast(OString const & type); + void instrCheckcast(rtl::OString const & type); void instrDup(); void instrGetstatic( - OString const & type, OString const & name, - OString const & descriptor); + rtl::OString const & type, rtl::OString const & name, + rtl::OString const & descriptor); Branch instrIfAcmpne(); Branch instrIfeq(); Branch instrIfnull(); - void instrInstanceof(OString const & type); + void instrInstanceof(rtl::OString const & type); void instrInvokeinterface( - OString const & type, OString const & name, - OString const & descriptor, sal_uInt8 args); + rtl::OString const & type, rtl::OString const & name, + rtl::OString const & descriptor, sal_uInt8 args); void instrInvokespecial( - OString const & type, OString const & name, - OString const & descriptor); + rtl::OString const & type, rtl::OString const & name, + rtl::OString const & descriptor); void instrInvokestatic( - OString const & type, OString const & name, - OString const & descriptor); + rtl::OString const & type, rtl::OString const & name, + rtl::OString const & descriptor); void instrInvokevirtual( - OString const & type, OString const & name, - OString const & descriptor); + rtl::OString const & type, rtl::OString const & name, + rtl::OString const & descriptor); void instrLookupswitch( Code const * defaultBlock, std::list< std::pair< sal_Int32, Code * > > const & blocks); - void instrNew(OString const & type); + void instrNew(rtl::OString const & type); void instrNewarray(codemaker::UnoType::Sort sort); void instrPop(); void instrPutfield( - OString const & type, OString const & name, - OString const & descriptor); + rtl::OString const & type, rtl::OString const & name, + rtl::OString const & descriptor); void instrPutstatic( - OString const & type, OString const & name, - OString const & descriptor); + rtl::OString const & type, rtl::OString const & name, + rtl::OString const & descriptor); void instrReturn(); void instrSwap(); @@ -111,7 +111,7 @@ public: std::list< Code * > const & blocks); void loadIntegerConstant(sal_Int32 value); - void loadStringConstant(OString const & value); + void loadStringConstant(rtl::OString const & value); void loadLocalInteger(sal_uInt16 index); void loadLocalLong(sal_uInt16 index); void loadLocalFloat(sal_uInt16 index); @@ -122,7 +122,7 @@ public: void addException( Position start, Position end, Position handler, - OString const & type); + rtl::OString const & type); void setMaxStackAndLocals(sal_uInt16 maxStack, sal_uInt16 maxLocals) { m_maxStack = maxStack; m_maxLocals = maxLocals; } @@ -151,8 +151,8 @@ public: }; ClassFile( - AccessFlags accessFlags, OString const & thisClass, - OString const & superClass, OString const & signature); + AccessFlags accessFlags, rtl::OString const & thisClass, + rtl::OString const & superClass, rtl::OString const & signature); ~ClassFile(); @@ -163,53 +163,53 @@ public: sal_uInt16 addLongInfo(sal_Int64 value); sal_uInt16 addDoubleInfo(double value); - void addInterface(OString const & interface); + void addInterface(rtl::OString const & interface); void addField( - AccessFlags accessFlags, OString const & name, - OString const & descriptor, sal_uInt16 constantValueIndex, - OString const & signature); + AccessFlags accessFlags, rtl::OString const & name, + rtl::OString const & descriptor, sal_uInt16 constantValueIndex, + rtl::OString const & signature); void addMethod( - AccessFlags accessFlags, OString const & name, - OString const & descriptor, Code const * code, - std::vector< OString > const & exceptions, - OString const & signature); + AccessFlags accessFlags, rtl::OString const & name, + rtl::OString const & descriptor, Code const * code, + std::vector< rtl::OString > const & exceptions, + rtl::OString const & signature); void write(FileStream & file) const; //TODO private: - typedef std::map< OString, sal_uInt16 > Map; + typedef std::map< rtl::OString, sal_uInt16 > Map; ClassFile(ClassFile &); // not implemented void operator =(ClassFile); // not implemented sal_uInt16 nextConstantPoolIndex(sal_uInt16 width); - sal_uInt16 addUtf8Info(OString const & value); - sal_uInt16 addClassInfo(OString const & type); - sal_uInt16 addStringInfo(OString const & value); + sal_uInt16 addUtf8Info(rtl::OString const & value); + sal_uInt16 addClassInfo(rtl::OString const & type); + sal_uInt16 addStringInfo(rtl::OString const & value); sal_uInt16 addFieldrefInfo( - OString const & type, OString const & name, - OString const & descriptor); + rtl::OString const & type, rtl::OString const & name, + rtl::OString const & descriptor); sal_uInt16 addMethodrefInfo( - OString const & type, OString const & name, - OString const & descriptor); + rtl::OString const & type, rtl::OString const & name, + rtl::OString const & descriptor); sal_uInt16 addInterfaceMethodrefInfo( - OString const & type, OString const & name, - OString const & descriptor); + rtl::OString const & type, rtl::OString const & name, + rtl::OString const & descriptor); sal_uInt16 addNameAndTypeInfo( - OString const & name, OString const & descriptor); + rtl::OString const & name, rtl::OString const & descriptor); void appendSignatureAttribute( - std::vector< unsigned char > & stream, OString const & signature); + std::vector< unsigned char > & stream, rtl::OString const & signature); sal_uInt16 m_constantPoolCount; std::vector< unsigned char > m_constantPool; - std::map< OString, sal_uInt16 > m_utf8Infos; + std::map< rtl::OString, sal_uInt16 > m_utf8Infos; std::map< sal_Int32, sal_uInt16 > m_integerInfos; std::map< sal_Int64, sal_uInt16 > m_longInfos; std::map< float, sal_uInt16 > m_floatInfos; diff --git a/codemaker/source/javamaker/javamaker.cxx b/codemaker/source/javamaker/javamaker.cxx index 912285ab2f6e..c10406bcaf79 100644 --- a/codemaker/source/javamaker/javamaker.cxx +++ b/codemaker/source/javamaker/javamaker.cxx @@ -28,12 +28,13 @@ #include "javaoptions.hxx" #include "javatype.hxx" +using ::rtl::OUString; +using ::rtl::OString; sal_Bool produceAllTypes(RegistryKey& rTypeKey, sal_Bool bIsExtraType, rtl::Reference< TypeManager > const & typeMgr, codemaker::GeneratedTypeSet & generated, JavaOptions* pOptions, sal_Bool bFullScope) - throw( CannotDumpException ) { OString typeName = typeMgr->getTypeName(rTypeKey); @@ -85,7 +86,6 @@ sal_Bool produceAllTypes(const OString& typeName, codemaker::GeneratedTypeSet & generated, JavaOptions* pOptions, sal_Bool bFullScope) - throw( CannotDumpException ) { if (!produceType(typeName, typeMgr, generated, pOptions)) { @@ -159,6 +159,19 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) typeMgr->setBase(options.getOption("-B")); } + for (std::vector< rtl::OString >::const_iterator i( + options.getExtraInputFiles().begin()); + i != options.getExtraInputFiles().end(); ++i) + { + typeMgr->loadProvider(b2u(*i), false); + } + for (std::vector< rtl::OString >::const_iterator i( + options.getInputFiles().begin()); + i != options.getInputFiles().end(); ++i) + { + typeMgr->loadProvider(b2u(*i), true); + } + try { if (options.isValid("-T")) @@ -226,7 +239,7 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { fprintf(stderr, "%s ERROR: %s\n", options.getProgramName().getStr(), - e.m_message.getStr()); + u2b(e.getMessage()).getStr()); exit(99); } diff --git a/codemaker/source/javamaker/javatype.cxx b/codemaker/source/javamaker/javatype.cxx index 77d3042ac8da..82c4f5150bea 100644 --- a/codemaker/source/javamaker/javatype.cxx +++ b/codemaker/source/javamaker/javatype.cxx @@ -59,8 +59,8 @@ namespace { // helper function for createUnoName void appendUnoName( - rtl::Reference< TypeManager > const & manager, OString const & nucleus, sal_Int32 rank, - std::vector< OString > const & arguments, OStringBuffer * buffer) + rtl::Reference< TypeManager > const & manager, rtl::OString const & nucleus, sal_Int32 rank, + std::vector< rtl::OString > const & arguments, rtl::OStringBuffer * buffer) { OSL_ASSERT(rank >= 0 && buffer != 0); for (sal_Int32 i = 0; i < rank; ++i) { @@ -69,16 +69,16 @@ void appendUnoName( buffer->append(nucleus.replace('/', '.')); if (!arguments.empty()) { buffer->append('<'); - for (std::vector< OString >::const_iterator i(arguments.begin()); + for (std::vector< rtl::OString >::const_iterator i(arguments.begin()); i != arguments.end(); ++i) { if (i != arguments.begin()) { buffer->append(','); } RTTypeClass argTypeClass; - OString argNucleus; + rtl::OString argNucleus; sal_Int32 argRank; - std::vector< OString > argArgs; + std::vector< rtl::OString > argArgs; codemaker::decomposeAndResolve( manager, *i, true, false, false, &argTypeClass, &argNucleus, &argRank, &argArgs); @@ -91,11 +91,11 @@ void appendUnoName( // Translate the name of a UNO type registry entity (enum type, plain struct // type, polymorphic struct type template, or interface type, decomposed into // nucleus, rank, and arguments) into a core UNO type name: -OString createUnoName( - rtl::Reference< TypeManager > const & manager, OString const & nucleus, sal_Int32 rank, - std::vector< OString > const & arguments) +rtl::OString createUnoName( + rtl::Reference< TypeManager > const & manager, rtl::OString const & nucleus, sal_Int32 rank, + std::vector< rtl::OString > const & arguments) { - OStringBuffer buf; + rtl::OStringBuffer buf; appendUnoName(manager, nucleus, rank, arguments, &buf); return buf.makeStringAndClear(); } @@ -109,7 +109,7 @@ OString createUnoName( constant groupds, single-interface--based services, accumulation-based services, interface-based singletons, and service-based singletons. */ -typedef std::set< OString > Dependencies; +typedef std::set< rtl::OString > Dependencies; enum SpecialType { SPECIAL_TYPE_NONE, @@ -122,8 +122,8 @@ bool isSpecialType(SpecialType special) { return special >= SPECIAL_TYPE_UNSIGNED; } -OString translateUnoTypeToJavaFullyQualifiedName( - OString const & type, OString const & prefix) +rtl::OString translateUnoTypeToJavaFullyQualifiedName( + rtl::OString const & type, rtl::OString const & prefix) { sal_Int32 i = type.lastIndexOf('/') + 1; return type.copy(0, i) + @@ -135,22 +135,22 @@ struct PolymorphicUnoType { enum Kind { KIND_NONE, KIND_STRUCT, KIND_SEQUENCE }; Kind kind; - OString name; + rtl::OString name; }; SpecialType translateUnoTypeToDescriptor( - rtl::Reference< TypeManager > const & manager, OString const & type, + rtl::Reference< TypeManager > const & manager, rtl::OString const & type, bool array, bool classType, Dependencies * dependencies, - OStringBuffer * descriptor, OStringBuffer * signature, + rtl::OStringBuffer * descriptor, rtl::OStringBuffer * signature, bool * needsSignature, PolymorphicUnoType * polymorphicUnoType); SpecialType translateUnoTypeToDescriptor( rtl::Reference< TypeManager > const & manager, codemaker::UnoType::Sort sort, RTTypeClass typeClass, - OString const & nucleus, sal_Int32 rank, - std::vector< OString > const & arguments, bool array, bool classType, - Dependencies * dependencies, OStringBuffer * descriptor, - OStringBuffer * signature, bool * needsSignature, + rtl::OString const & nucleus, sal_Int32 rank, + std::vector< rtl::OString > const & arguments, bool array, bool classType, + Dependencies * dependencies, rtl::OStringBuffer * descriptor, + rtl::OStringBuffer * signature, bool * needsSignature, PolymorphicUnoType * polymorphicUnoType) { OSL_ASSERT(rank >= 0 && (signature == 0) == (needsSignature == 0)); @@ -193,7 +193,7 @@ SpecialType translateUnoTypeToDescriptor( signature->append("L" + nucleus); if (!arguments.empty()) { signature->append('<'); - for (std::vector< OString >::const_iterator i( + for (std::vector< rtl::OString >::const_iterator i( arguments.begin()); i != arguments.end(); ++i) { @@ -220,7 +220,7 @@ SpecialType translateUnoTypeToDescriptor( return SPECIAL_TYPE_NONE; } } else { - static OString const + static rtl::OString const simpleTypeDescriptors[codemaker::UnoType::SORT_ANY + 1][2] = { { "V", "Ljava/lang/Void;" }, { "Z", "Ljava/lang/Boolean;" }, @@ -237,7 +237,7 @@ SpecialType translateUnoTypeToDescriptor( { "Ljava/lang/String;", "Ljava/lang/String;" }, { "Lcom/sun/star/uno/Type;", "Lcom/sun/star/uno/Type;" }, { "Ljava/lang/Object;", "Ljava/lang/Object;" } }; - OString const & s + rtl::OString const & s = simpleTypeDescriptors[sort][rank == 0 && classType]; if (descriptor != 0) { descriptor->append(s); @@ -260,15 +260,15 @@ SpecialType translateUnoTypeToDescriptor( } SpecialType translateUnoTypeToDescriptor( - rtl::Reference< TypeManager > const & manager, OString const & type, + rtl::Reference< TypeManager > const & manager, rtl::OString const & type, bool array, bool classType, Dependencies * dependencies, - OStringBuffer * descriptor, OStringBuffer * signature, + rtl::OStringBuffer * descriptor, rtl::OStringBuffer * signature, bool * needsSignature, PolymorphicUnoType * polymorphicUnoType) { RTTypeClass typeClass; - OString nucleus; + rtl::OString nucleus; sal_Int32 rank; - std::vector< OString > args; + std::vector< rtl::OString > args; codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve( manager, type, true, true, false, &typeClass, &nucleus, &rank, &args); OSL_ASSERT(rank < SAL_MAX_INT32); @@ -280,12 +280,12 @@ SpecialType translateUnoTypeToDescriptor( SpecialType getFieldDescriptor( rtl::Reference< TypeManager > const & manager, Dependencies * dependencies, - OString const & type, OString * descriptor, - OString * signature, PolymorphicUnoType * polymorphicUnoType) + rtl::OString const & type, rtl::OString * descriptor, + rtl::OString * signature, PolymorphicUnoType * polymorphicUnoType) { OSL_ASSERT(dependencies != 0 && descriptor != 0); - OStringBuffer desc; - OStringBuffer sig; + rtl::OStringBuffer desc; + rtl::OStringBuffer sig; bool needsSig = false; SpecialType specialType = translateUnoTypeToDescriptor( manager, type, false, false, dependencies, &desc, &sig, &needsSig, @@ -295,7 +295,7 @@ SpecialType getFieldDescriptor( if (needsSig) { *signature = sig.makeStringAndClear(); } else { - *signature = OString(); + *signature = rtl::OString(); } } return specialType; @@ -305,42 +305,42 @@ class MethodDescriptor { public: MethodDescriptor( rtl::Reference< TypeManager > const & manager, - Dependencies * dependencies, OString const & returnType, + Dependencies * dependencies, rtl::OString const & returnType, SpecialType * specialReturnType, PolymorphicUnoType * polymorphicUnoType); SpecialType addParameter( - OString const & type, bool array, bool dependency, + rtl::OString const & type, bool array, bool dependency, PolymorphicUnoType * polymorphicUnoType); - void addTypeParameter(OString const & name); + void addTypeParameter(rtl::OString const & name); - OString getDescriptor() const; + rtl::OString getDescriptor() const; - OString getSignature() const; + rtl::OString getSignature() const; private: rtl::Reference< TypeManager > m_manager; Dependencies * m_dependencies; - OStringBuffer m_descriptorStart; - OString m_descriptorEnd; - OStringBuffer m_signatureStart; - OString m_signatureEnd; + rtl::OStringBuffer m_descriptorStart; + rtl::OString m_descriptorEnd; + rtl::OStringBuffer m_signatureStart; + rtl::OString m_signatureEnd; bool m_needsSignature; }; MethodDescriptor::MethodDescriptor( rtl::Reference< TypeManager > const & manager, Dependencies * dependencies, - OString const & returnType, SpecialType * specialReturnType, + rtl::OString const & returnType, SpecialType * specialReturnType, PolymorphicUnoType * polymorphicUnoType): m_manager(manager), m_dependencies(dependencies), m_needsSignature(false) { OSL_ASSERT(dependencies != 0); m_descriptorStart.append('('); m_signatureStart.append('('); - OStringBuffer descEnd; + rtl::OStringBuffer descEnd; descEnd.append(')'); - OStringBuffer sigEnd; + rtl::OStringBuffer sigEnd; sigEnd.append(')'); SpecialType special = translateUnoTypeToDescriptor( m_manager, returnType, false, false, m_dependencies, &descEnd, &sigEnd, @@ -353,7 +353,7 @@ MethodDescriptor::MethodDescriptor( } SpecialType MethodDescriptor::addParameter( - OString const & type, bool array, bool dependency, + rtl::OString const & type, bool array, bool dependency, PolymorphicUnoType * polymorphicUnoType) { return translateUnoTypeToDescriptor( @@ -368,17 +368,17 @@ void MethodDescriptor::addTypeParameter(OString const & name) { m_needsSignature = true; } -OString MethodDescriptor::getDescriptor() const { - OStringBuffer buf(m_descriptorStart); +rtl::OString MethodDescriptor::getDescriptor() const { + rtl::OStringBuffer buf(m_descriptorStart); buf.append(m_descriptorEnd); return buf.makeStringAndClear(); } -OString MethodDescriptor::getSignature() const { +rtl::OString MethodDescriptor::getSignature() const { if (m_needsSignature) { return m_signatureStart + m_signatureEnd; } else { - return OString(); + return rtl::OString(); } } @@ -393,20 +393,20 @@ public: // KIND_MEMBER: TypeInfo( - OString const & name, SpecialType specialType, sal_Int32 index, + rtl::OString const & name, SpecialType specialType, sal_Int32 index, PolymorphicUnoType const & polymorphicUnoType, sal_Int32 typeParameterIndex); // KIND_ATTRIBUTE/METHOD: TypeInfo( - Kind kind, OString const & name, SpecialType specialType, + Kind kind, rtl::OString const & name, SpecialType specialType, Flags flags, sal_Int32 index, PolymorphicUnoType const & polymorphicUnoType); // KIND_PARAMETER: TypeInfo( - OString const & parameterName, SpecialType specialType, - bool inParameter, bool outParameter, OString const & methodName, + rtl::OString const & parameterName, SpecialType specialType, + bool inParameter, bool outParameter, rtl::OString const & methodName, sal_Int32 index, PolymorphicUnoType const & polymorphicUnoType); sal_uInt16 generateCode(ClassFile::Code & code, Dependencies * dependencies) @@ -417,10 +417,10 @@ public: private: Kind m_kind; - OString m_name; + rtl::OString m_name; sal_Int32 m_flags; sal_Int32 m_index; - OString m_methodName; + rtl::OString m_methodName; PolymorphicUnoType m_polymorphicUnoType; sal_Int32 m_typeParameterIndex; }; @@ -441,7 +441,7 @@ sal_Int32 translateSpecialTypeFlags( } TypeInfo::TypeInfo( - OString const & name, SpecialType specialType, sal_Int32 index, + rtl::OString const & name, SpecialType specialType, sal_Int32 index, PolymorphicUnoType const & polymorphicUnoType, sal_Int32 typeParameterIndex): m_kind(KIND_MEMBER), m_name(name), @@ -455,7 +455,7 @@ TypeInfo::TypeInfo( } TypeInfo::TypeInfo( - Kind kind, OString const & name, SpecialType specialType, + Kind kind, rtl::OString const & name, SpecialType specialType, Flags flags, sal_Int32 index, PolymorphicUnoType const & polymorphicUnoType): m_kind(kind), m_name(name), @@ -466,8 +466,8 @@ TypeInfo::TypeInfo( } TypeInfo::TypeInfo( - OString const & parameterName, SpecialType specialType, - bool inParameter, bool outParameter, OString const & methodName, + rtl::OString const & parameterName, SpecialType specialType, + bool inParameter, bool outParameter, rtl::OString const & methodName, sal_Int32 index, PolymorphicUnoType const & polymorphicUnoType): m_kind(KIND_PARAMETER), m_name(parameterName), m_flags(translateSpecialTypeFlags(specialType, inParameter, outParameter)), @@ -600,9 +600,9 @@ void writeClassFile( FileStream tempfile; tempfile.createTempFile(getTempDir(filename)); if (!tempfile.isValid()) { - throw CannotDumpException("Cannot create temporary file for " + filename); + throw CannotDumpException("Cannot create temporary file for " + b2u(filename)); } - OString tempname(tempfile.getName()); + rtl::OString tempname(tempfile.getName()); try { classFile.write(tempfile); } catch (...) { @@ -616,12 +616,12 @@ void writeClassFile( } tempfile.close(); if (!makeValidTypeFile(filename, tempname, check)) { - throw CannotDumpException("Cannot create " + filename + " from temporary file " + tempname); + throw CannotDumpException("Cannot create " + b2u(filename) + " from temporary file " + b2u(tempname)); } } void addTypeInfo( - OString const & className, std::vector< TypeInfo > const & typeInfo, + rtl::OString const & className, std::vector< TypeInfo > const & typeInfo, Dependencies * dependencies, ClassFile * classFile) { OSL_ASSERT(dependencies != 0 && classFile != 0); @@ -661,7 +661,7 @@ void addTypeInfo( static_cast< ClassFile::AccessFlags >( ClassFile::ACC_PRIVATE | ClassFile::ACC_STATIC), "<clinit>", "()V", code.get(), - std::vector< OString >(), ""); + std::vector< rtl::OString >(), ""); } } @@ -682,7 +682,7 @@ void handleEnumType( throw CannotDumpException("Bad type information"); //TODO } - OString className(codemaker::convertString(reader.getTypeName())); + rtl::OString className(codemaker::convertString(reader.getTypeName())); SAL_WNODEPRECATED_DECLARATIONS_PUSH std::auto_ptr< ClassFile > cf( new ClassFile( @@ -691,7 +691,7 @@ void handleEnumType( | ClassFile::ACC_SUPER), className, "com/sun/star/uno/Enum", "")); SAL_WNODEPRECATED_DECLARATIONS_POP - OString classDescriptor("L" + className + ";"); + rtl::OString classDescriptor("L" + className + ";"); for (sal_uInt16 i = 0; i < fields; ++i) { RTConstValue fieldValue(reader.getFieldValue(i)); if (fieldValue.m_type != RT_TYPE_INT32 @@ -700,13 +700,13 @@ void handleEnumType( { throw CannotDumpException("Bad type information"); //TODO } - OString fieldName( + rtl::OString fieldName( codemaker::convertString(reader.getFieldName(i))); cf->addField( static_cast< ClassFile::AccessFlags >( ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC | ClassFile::ACC_FINAL), - fieldName, classDescriptor, 0, OString()); + fieldName, classDescriptor, 0, rtl::OString()); cf->addField( static_cast< ClassFile::AccessFlags >( ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC @@ -739,7 +739,7 @@ void handleEnumType( code.get(), std::vector< OString >(), ""); code.reset(cf->newCode()); code->loadLocalInteger(0); - std::map< sal_Int32, OString > map; + std::map< sal_Int32, rtl::OString > map; sal_Int32 min = SAL_MAX_INT32; sal_Int32 max = SAL_MIN_INT32; for (sal_uInt16 i = 0; i < fields; ++i) { @@ -747,7 +747,7 @@ void handleEnumType( min = std::min(min, value); max = std::max(max, value); map.insert( - std::map< sal_Int32, OString >::value_type( + std::map< sal_Int32, rtl::OString >::value_type( value, codemaker::convertString(reader.getFieldName(i)))); } sal_uInt64 size = static_cast< sal_uInt64 >(map.size()); @@ -763,7 +763,7 @@ void handleEnumType( std::list< ClassFile::Code * > blocks; //FIXME: pointers contained in blocks may leak sal_Int32 last = SAL_MAX_INT32; - for (std::map< sal_Int32, OString >::iterator i(map.begin()); + for (std::map< sal_Int32, rtl::OString >::iterator i(map.begin()); i != map.end(); ++i) { sal_Int32 value = i->first; @@ -795,7 +795,7 @@ void handleEnumType( defCode->instrAreturn(); std::list< std::pair< sal_Int32, ClassFile::Code * > > blocks; //FIXME: pointers contained in blocks may leak - for (std::map< sal_Int32, OString >::iterator i(map.begin()); + for (std::map< sal_Int32, rtl::OString >::iterator i(map.begin()); i != map.end(); ++i) { SAL_WNODEPRECATED_DECLARATIONS_PUSH @@ -819,7 +819,7 @@ void handleEnumType( static_cast< ClassFile::AccessFlags >( ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC), "fromInt", "(I)" + classDescriptor, - code.get(), std::vector< OString >(), ""); + code.get(), std::vector< rtl::OString >(), ""); code.reset(cf->newCode()); for (sal_uInt16 i = 0; i < fields; ++i) { code->instrNew(className); @@ -837,19 +837,19 @@ void handleEnumType( static_cast< ClassFile::AccessFlags >( ClassFile::ACC_PRIVATE | ClassFile::ACC_STATIC), "<clinit>", "()V", code.get(), - std::vector< OString >(), ""); + std::vector< rtl::OString >(), ""); writeClassFile(options, className, *cf.get()); } void addField( rtl::Reference< TypeManager > const & manager, Dependencies * dependencies, ClassFile * classFile, std::vector< TypeInfo > * typeInfo, - sal_Int32 typeParameterIndex, OString const & type, - OString const & name, sal_Int32 index) + sal_Int32 typeParameterIndex, rtl::OString const & type, + rtl::OString const & name, sal_Int32 index) { OSL_ASSERT(dependencies != 0 && classFile != 0 && typeInfo != 0); - OString descriptor; - OString signature; + rtl::OString descriptor; + rtl::OString signature; SpecialType specialType; PolymorphicUnoType polymorphicUnoType; if (typeParameterIndex >= 0) { @@ -869,8 +869,8 @@ void addField( sal_uInt16 addFieldInit( rtl::Reference< TypeManager > const & manager, - OString const & className, OString const & fieldName, - bool typeParameter, OString const & fieldType, + rtl::OString const & className, rtl::OString const & fieldName, + bool typeParameter, rtl::OString const & fieldType, Dependencies * dependencies, ClassFile::Code * code) { OSL_ASSERT(dependencies != 0 && code != 0); @@ -878,9 +878,9 @@ sal_uInt16 addFieldInit( return 0; } else { RTTypeClass typeClass; - OString nucleus; + rtl::OString nucleus; sal_Int32 rank; - std::vector< OString > args; + std::vector< rtl::OString > args; codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve( manager, fieldType, true, false, false, &typeClass, &nucleus, &rank, &args); @@ -888,7 +888,7 @@ sal_uInt16 addFieldInit( switch (sort) { case codemaker::UnoType::SORT_STRING: code->loadLocalReference(0); - code->loadStringConstant(OString()); + code->loadStringConstant(rtl::OString()); code->instrPutfield(className, fieldName, "Ljava/lang/String;"); return 2; @@ -913,12 +913,12 @@ sal_uInt16 addFieldInit( if (reader.getFieldCount() == 0) { throw CannotDumpException("Bad type information"); //TODO } - OStringBuffer descBuf; + rtl::OStringBuffer descBuf; translateUnoTypeToDescriptor( manager, sort, typeClass, nucleus, 0, - std::vector< OString >(), false, false, + std::vector< rtl::OString >(), false, false, dependencies, &descBuf, 0, 0, 0); - OString desc(descBuf.makeStringAndClear()); + rtl::OString desc(descBuf.makeStringAndClear()); code->instrGetstatic( nucleus, codemaker::convertString(reader.getFieldName(0)), @@ -933,10 +933,10 @@ sal_uInt16 addFieldInit( code->instrNew(nucleus); code->instrDup(); code->instrInvokespecial(nucleus, "<init>", "()V"); - OStringBuffer desc; + rtl::OStringBuffer desc; translateUnoTypeToDescriptor( manager, sort, typeClass, nucleus, 0, - std::vector< OString >(), false, false, + std::vector< rtl::OString >(), false, false, dependencies, &desc, 0, 0, 0); code->instrPutfield( className, fieldName, desc.makeStringAndClear()); @@ -965,17 +965,17 @@ sal_uInt16 addFieldInit( nucleus, 0)); } } else { - OStringBuffer desc; + rtl::OStringBuffer desc; translateUnoTypeToDescriptor( manager, sort, typeClass, nucleus, rank - 1, - std::vector< OString >(), false, false, dependencies, + std::vector< rtl::OString >(), false, false, dependencies, &desc, 0, 0, 0); code->instrAnewarray(desc.makeStringAndClear()); } - OStringBuffer desc; + rtl::OStringBuffer desc; translateUnoTypeToDescriptor( manager, sort, typeClass, nucleus, rank, - std::vector< OString >(), false, false, dependencies, + std::vector< rtl::OString >(), false, false, dependencies, &desc, 0, 0, 0); code->instrPutfield( className, fieldName, desc.makeStringAndClear()); @@ -986,7 +986,7 @@ sal_uInt16 addFieldInit( sal_uInt16 addLoadLocal( rtl::Reference< TypeManager > const & manager, ClassFile::Code * code, - sal_uInt16 * index, bool typeParameter, OString const & type, bool any, + sal_uInt16 * index, bool typeParameter, rtl::OString const & type, bool any, Dependencies * dependencies) { OSL_ASSERT( @@ -999,9 +999,9 @@ sal_uInt16 addLoadLocal( stack = size = 1; } else { RTTypeClass typeClass; - OString nucleus; + rtl::OString nucleus; sal_Int32 rank; - std::vector< OString > args; + std::vector< rtl::OString > args; codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve( manager, type, true, false, false, &typeClass, &nucleus, &rank, &args); if (rank == 0) { @@ -1327,7 +1327,7 @@ sal_uInt16 addLoadLocal( void addBaseArguments( rtl::Reference< TypeManager > const & manager, Dependencies * dependencies, MethodDescriptor * methodDescriptor, ClassFile::Code * code, - RTTypeClass typeClass, OString const & type, sal_uInt16 * index) + RTTypeClass typeClass, rtl::OString const & type, sal_uInt16 * index) { OSL_ASSERT( dependencies != 0 && methodDescriptor != 0 && code != 0 && index != 0); @@ -1368,7 +1368,7 @@ void addBaseArguments( { throw CannotDumpException("Bad type information"); //TODO } - OString fieldType( + rtl::OString fieldType( codemaker::convertString(reader.getFieldTypeName(i))); methodDescriptor->addParameter(fieldType, false, true, 0); addLoadLocal( @@ -1379,13 +1379,13 @@ void addBaseArguments( sal_uInt16 addDirectArgument( rtl::Reference< TypeManager > const & manager, Dependencies * dependencies, MethodDescriptor * methodDescriptor, ClassFile::Code * code, - sal_uInt16 * index, OString const & className, - OString const & fieldName, bool typeParameter, - OString const & fieldType) + sal_uInt16 * index, rtl::OString const & className, + rtl::OString const & fieldName, bool typeParameter, + rtl::OString const & fieldType) { OSL_ASSERT( dependencies != 0 && methodDescriptor != 0 && code != 0 && index != 0); - OString desc; + rtl::OString desc; if (typeParameter) { methodDescriptor->addTypeParameter(fieldType); desc = "Ljava/lang/Object;"; @@ -1412,13 +1412,13 @@ void handleAggregatingType( //TODO } RTTypeClass typeClass = reader.getTypeClass(); - OString className(codemaker::convertString(reader.getTypeName())); + rtl::OString className(codemaker::convertString(reader.getTypeName())); sal_uInt16 superTypes = reader.getSuperTypeCount(); sal_uInt16 fields = reader.getFieldCount(); sal_uInt16 firstField = 0; sal_uInt16 references = reader.getReferenceCount(); bool runtimeException = false; - OString superClass; + rtl::OString superClass; if (className == "com/sun/star/uno/Exception") { if (typeClass != RT_TYPE_EXCEPTION || superTypes != 0 || fields != 2 @@ -1459,10 +1459,10 @@ void handleAggregatingType( dependencies->insert(superClass); } } - OString sig; - std::map< OString, sal_Int32 > typeParameters; + rtl::OString sig; + std::map< rtl::OString, sal_Int32 > typeParameters; if (references != 0) { - OStringBuffer buf; + rtl::OStringBuffer buf; buf.append('<'); for (sal_uInt16 i = 0; i < references; ++i) { if (reader.getReferenceFlags(i) != RT_ACCESS_INVALID @@ -1471,11 +1471,11 @@ void handleAggregatingType( throw CannotDumpException("Bad type information"); //TODO } - OString name( + rtl::OString name( codemaker::convertString(reader.getReferenceTypeName(i))); buf.append(name + ":Ljava/lang/Object;"); if (!typeParameters.insert( - std::map< OString, sal_Int32 >::value_type(name, i)). + std::map< rtl::OString, sal_Int32 >::value_type(name, i)). second) { throw CannotDumpException("Bad type information"); @@ -1502,13 +1502,13 @@ void handleAggregatingType( { throw CannotDumpException("Bad type information"); //TODO } - OString type( + rtl::OString type( codemaker::convertString(reader.getFieldTypeName(i))); sal_Int32 typeParameterIndex; if ((flags & RT_ACCESS_PARAMETERIZED_TYPE) == 0) { typeParameterIndex = -1; } else { - std::map< OString, sal_Int32 >::iterator it( + std::map< rtl::OString, sal_Int32 >::iterator it( typeParameters.find(type)); if (it == typeParameters.end()) { throw CannotDumpException("Bad type information"); @@ -1551,7 +1551,7 @@ void handleAggregatingType( cf->addMethod( ClassFile::ACC_PUBLIC, "<init>", "()V", code.get(), - std::vector< OString >(), ""); + std::vector< rtl::OString >(), ""); if (typeClass == RT_TYPE_EXCEPTION) { code.reset(cf->newCode()); code->loadLocalReference(0); @@ -1578,7 +1578,7 @@ void handleAggregatingType( code->instrReturn(); code->setMaxStackAndLocals(stack + 2, 2); cf->addMethod(ClassFile::ACC_PUBLIC, "<init>", "(Ljava/lang/String;)V", - code.get(), std::vector< OString >(), ""); + code.get(), std::vector< rtl::OString >(), ""); } MethodDescriptor desc(manager, dependencies, "void", 0, 0); code.reset(cf->newCode()); @@ -1613,7 +1613,7 @@ void handleAggregatingType( code->instrReturn(); code->setMaxStackAndLocals(maxSize, index); cf->addMethod(ClassFile::ACC_PUBLIC, "<init>", - desc.getDescriptor(), code.get(), std::vector< OString >(), + desc.getDescriptor(), code.get(), std::vector< rtl::OString >(), desc.getSignature()); addTypeInfo(className, typeInfo, dependencies, cf.get()); writeClassFile(options, className, *cf.get()); @@ -1622,19 +1622,19 @@ void handleAggregatingType( void createExceptionsAttribute( rtl::Reference< TypeManager > const & manager, typereg::Reader const & reader, sal_uInt16 methodIndex, - Dependencies * dependencies, std::vector< OString > * exceptions, + Dependencies * dependencies, std::vector< rtl::OString > * exceptions, codemaker::ExceptionTree * tree) { OSL_ASSERT(dependencies != 0 && exceptions != 0); sal_uInt16 n = reader.getMethodExceptionCount(methodIndex); for (sal_uInt16 i = 0; i < n; ++i) { - OString type( + rtl::OString type( codemaker::convertString( reader.getMethodExceptionTypeName(methodIndex, i))); dependencies->insert(type); exceptions->push_back(type); if (tree != 0) { - tree->add(type, manager); + tree->add(type.replace('/', '.'), manager); } } } @@ -1646,7 +1646,7 @@ void handleInterfaceType( { OSL_ASSERT(dependencies != 0); - OString className(codemaker::convertString(reader.getTypeName())); + rtl::OString className(codemaker::convertString(reader.getTypeName())); sal_uInt16 superTypes = reader.getSuperTypeCount(); sal_uInt16 fields = reader.getFieldCount(); sal_uInt16 methods = reader.getMethodCount(); @@ -1669,7 +1669,7 @@ void handleInterfaceType( className, "java/lang/Object", "")); SAL_WNODEPRECATED_DECLARATIONS_POP for (sal_uInt16 i = 0; i < superTypes; ++i) { - OString t(codemaker::convertString(reader.getSuperTypeName(i))); + rtl::OString t(codemaker::convertString(reader.getSuperTypeName(i))); dependencies->insert(t); cf->addInterface(t); } @@ -1698,7 +1698,7 @@ void handleInterfaceType( } //TODO: exploit the fact that attribute getter/setter methods preceed // real methods - OUString attrNameUtf16(reader.getFieldName(i)); + rtl::OUString attrNameUtf16(reader.getFieldName(i)); sal_uInt16 getter = SAL_MAX_UINT16; sal_uInt16 setter = SAL_MAX_UINT16; for (sal_uInt16 j = 0; j < methods; ++j) { @@ -1720,19 +1720,19 @@ void handleInterfaceType( (mflags == RT_MODE_ATTRIBUTE_GET ? getter : setter) = j; } } - OString fieldType( + rtl::OString fieldType( codemaker::convertString(reader.getFieldTypeName(i))); SpecialType specialType; PolymorphicUnoType polymorphicUnoType; MethodDescriptor gdesc( manager, dependencies, fieldType, &specialType, &polymorphicUnoType); - std::vector< OString > exc; + std::vector< rtl::OString > exc; if (getter != SAL_MAX_UINT16) { createExceptionsAttribute( manager, reader, getter, dependencies, &exc, 0); } - OString attrName(codemaker::convertString(attrNameUtf16)); + rtl::OString attrName(codemaker::convertString(attrNameUtf16)); cf->addMethod( static_cast< ClassFile::AccessFlags >( ClassFile::ACC_PUBLIC | ClassFile::ACC_ABSTRACT), @@ -1741,7 +1741,7 @@ void handleInterfaceType( MethodDescriptor sdesc( manager, dependencies, "void", 0, 0); sdesc.addParameter(fieldType, false, true, 0); - std::vector< OString > exc2; + std::vector< rtl::OString > exc2; if (setter != SAL_MAX_UINT16) { createExceptionsAttribute( manager, reader, setter, dependencies, &exc2, 0); @@ -1768,7 +1768,7 @@ void handleInterfaceType( case RT_MODE_ONEWAY: case RT_MODE_TWOWAY: { - OString methodName( + rtl::OString methodName( codemaker::convertString(reader.getMethodName(i))); SpecialType specialReturnType; PolymorphicUnoType polymorphicUnoReturnType; @@ -1825,7 +1825,7 @@ void handleInterfaceType( polymorphicUnoType)); } } - std::vector< OString > exc2; + std::vector< rtl::OString > exc2; createExceptionsAttribute( manager, reader, i, dependencies, &exc2, 0); cf->addMethod( @@ -1841,7 +1841,7 @@ void handleInterfaceType( { //TODO: exploit the fact that attribute getter/setter methods // are ordered the same way as the attribute fields themselves - OUString methodNameUtf16(reader.getMethodName(i)); + rtl::OUString methodNameUtf16(reader.getMethodName(i)); bool found = false; for (sal_uInt16 j = 0; j < fields; ++j) { if (reader.getFieldName(j) == methodNameUtf16) { @@ -1874,9 +1874,9 @@ void handleTypedef( //TODO } RTTypeClass typeClass; - OString nucleus; + rtl::OString nucleus; sal_Int32 rank; - std::vector< OString > args; + std::vector< rtl::OString > args; if (codemaker::decomposeAndResolve( manager, codemaker::convertString(reader.getSuperTypeName(0)), false, false, false, &typeClass, &nucleus, &rank, &args) @@ -1917,9 +1917,9 @@ void addConstant( RTConstValue fieldValue(reader.getFieldValue(index)); sal_uInt16 valueIndex; RTTypeClass typeClass; - OString nucleus; + rtl::OString nucleus; sal_Int32 rank; - std::vector< OString > args; + std::vector< rtl::OString > args; switch (codemaker::decomposeAndResolve( manager, codemaker::convertString(reader.getFieldTypeName(index)), @@ -2002,8 +2002,8 @@ void addConstant( throw CannotDumpException("Bad type information"); //TODO } - OString desc; - OString sig; + rtl::OString desc; + rtl::OString sig; getFieldDescriptor( manager, dependencies, codemaker::convertString(reader.getFieldTypeName(index)), @@ -2028,7 +2028,7 @@ void handleConstantGroup( throw CannotDumpException("Bad type information"); //TODO } - OString className(codemaker::convertString(reader.getTypeName())); + rtl::OString className(codemaker::convertString(reader.getTypeName())); SAL_WNODEPRECATED_DECLARATIONS_PUSH std::auto_ptr< ClassFile > cf( new ClassFile( @@ -2056,10 +2056,10 @@ void handleModule( throw CannotDumpException("Bad type information"); //TODO } - OString prefix(codemaker::convertString(reader.getTypeName()) + "/"); + rtl::OString prefix(codemaker::convertString(reader.getTypeName()) + "/"); sal_uInt16 fields = reader.getFieldCount(); for (sal_uInt16 i = 0; i < fields; ++i) { - OString className( + rtl::OString className( prefix + codemaker::convertString(reader.getFieldName(i))); SAL_WNODEPRECATED_DECLARATIONS_PUSH std::auto_ptr< ClassFile > cf( @@ -2081,7 +2081,7 @@ void addExceptionHandlers( { OSL_ASSERT(node != 0 && code != 0); if (node->present) { - code->addException(start, end, handler, node->name); + code->addException(start, end, handler, node->name.replace('.', '/')); } else { for (codemaker::ExceptionTreeNode::Children::const_iterator i( node->children.begin()); @@ -2094,10 +2094,10 @@ void addExceptionHandlers( void addConstructor( rtl::Reference< TypeManager > const & manager, - OString const & realJavaBaseName, OString const & unoName, - OString const & className, typereg::Reader const & reader, - sal_uInt16 methodIndex, OString const & methodName, - OString const & returnType, bool defaultConstructor, + rtl::OString const & realJavaBaseName, rtl::OString const & unoName, + rtl::OString const & className, typereg::Reader const & reader, + sal_uInt16 methodIndex, rtl::OString const & methodName, + rtl::OString const & returnType, bool defaultConstructor, Dependencies * dependencies, ClassFile * classFile) { OSL_ASSERT(dependencies != 0 && classFile != 0); @@ -2116,7 +2116,7 @@ void addConstructor( codemaker::ExceptionTree tree; ClassFile::Code::Position tryStart; ClassFile::Code::Position tryEnd; - std::vector< OString > exc; + std::vector< rtl::OString > exc; sal_uInt16 stack; sal_uInt16 localIndex = 1; ClassFile::AccessFlags access = static_cast< ClassFile::AccessFlags >( @@ -2153,7 +2153,7 @@ void addConstructor( for (sal_uInt16 i = 0; i < parameters; ++i) { RTParamMode flags = reader.getMethodParameterFlags( methodIndex, i); - OString paramType( + rtl::OString paramType( codemaker::convertString( reader.getMethodParameterTypeName(methodIndex, i))); if ((flags != RT_PARAM_IN @@ -2258,8 +2258,8 @@ void handleService( if (superTypes == 0) { return; } - OString unoName(codemaker::convertString(reader.getTypeName())); - OString className( + rtl::OString unoName(codemaker::convertString(reader.getTypeName())); + rtl::OString className( translateUnoTypeToJavaFullyQualifiedName(unoName, "service")); unoName = unoName.replace('/', '.'); SAL_WNODEPRECATED_DECLARATIONS_PUSH @@ -2271,16 +2271,16 @@ void handleService( className, "java/lang/Object", "")); SAL_WNODEPRECATED_DECLARATIONS_POP if (methods > 0) { - OString base(codemaker::convertString( + rtl::OString base(codemaker::convertString( reader.getSuperTypeName(0))); - OString realJavaBaseName(base.replace('/', '.')); + rtl::OString realJavaBaseName(base.replace('/', '.')); dependencies->insert(base); dependencies->insert("com/sun/star/lang/XMultiComponentFactory"); dependencies->insert("com/sun/star/uno/DeploymentException"); dependencies->insert("com/sun/star/uno/TypeClass"); dependencies->insert("com/sun/star/uno/XComponentContext"); for (sal_uInt16 i = 0; i < methods; ++i) { - OString name(codemaker::convertString( + rtl::OString name(codemaker::convertString( reader.getMethodName(i))); bool defaultCtor = name.isEmpty(); if (reader.getMethodFlags(i) != RT_MODE_TWOWAY @@ -2351,7 +2351,7 @@ void handleService( | ClassFile::ACC_SYNTHETIC), "$castInstance", "(Ljava/lang/Object;Lcom/sun/star/uno/" "XComponentContext;)Ljava/lang/Object;", - code.get(), std::vector< OString >(), ""); + code.get(), std::vector< rtl::OString >(), ""); } } writeClassFile(options, className, *cf.get()); @@ -2369,8 +2369,8 @@ void handleSingleton( throw CannotDumpException("Bad type information"); //TODO } - OString base(codemaker::convertString(reader.getSuperTypeName(0))); - OString realJavaBaseName(base.replace('/', '.')); + rtl::OString base(codemaker::convertString(reader.getSuperTypeName(0))); + rtl::OString realJavaBaseName(base.replace('/', '.')); switch (manager->getTypeReader(base).getTypeClass()) { case RT_TYPE_INTERFACE: break; @@ -2475,14 +2475,14 @@ void handleSingleton( static_cast< ClassFile::AccessFlags >( ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC), "get", desc.getDescriptor(), - code.get(), std::vector< OString >(), desc.getSignature()); + code.get(), std::vector< rtl::OString >(), desc.getSignature()); writeClassFile(options, className, *cf.get()); } } bool produceType( - OString const & type, rtl::Reference< TypeManager > const & manager, + rtl::OString const & type, rtl::Reference< TypeManager > const & manager, codemaker::GeneratedTypeSet & generated, JavaOptions * options) { OSL_ASSERT(options != 0); @@ -2556,7 +2556,7 @@ bool produceType( rtl::Reference< TypeManager > const & manager, codemaker::GeneratedTypeSet & generated, JavaOptions * options) { - OString typeName = manager->getTypeName(rTypeKey); + ::rtl::OString typeName = manager->getTypeName(rTypeKey); OSL_ASSERT(options != 0); if (typeName == "/" || typeName == manager->getBase() |