diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-18 11:37:53 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-18 21:46:13 +0200 |
commit | ed0097845a07b6129f4e56cd28b90ce9b9368cf5 (patch) | |
tree | ebfc7bf30a62f69bafd22ed9d9e45738308e2ec6 /codemaker/source | |
parent | 1f59cbe36c9899f6fa9a869331c9be454abd4606 (diff) |
loplugin:flatten in codemaker
Change-Id: I973ecef5df990511a41e422b73ed2314434f2871
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92479
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'codemaker/source')
-rw-r--r-- | codemaker/source/codemaker/exceptiontree.cxx | 37 | ||||
-rw-r--r-- | codemaker/source/cppumaker/cpputype.cxx | 204 | ||||
-rw-r--r-- | codemaker/source/javamaker/javatype.cxx | 94 |
3 files changed, 170 insertions, 165 deletions
diff --git a/codemaker/source/codemaker/exceptiontree.cxx b/codemaker/source/codemaker/exceptiontree.cxx index b6c2aeee6f87..148f017b6877 100644 --- a/codemaker/source/codemaker/exceptiontree.cxx +++ b/codemaker/source/codemaker/exceptiontree.cxx @@ -63,27 +63,28 @@ void ExceptionTree::add( getDirectBase()); assert(!n.isEmpty()); } - if (!bRuntimeException) { - ExceptionTreeNode * node = &m_root; - for (std::vector< OString >::reverse_iterator i(list.rbegin()); - !node->present; ++i) + if (bRuntimeException) + return; + + ExceptionTreeNode * node = &m_root; + for (std::vector< OString >::reverse_iterator i(list.rbegin()); + !node->present; ++i) + { + if (i == list.rend()) { + node->setPresent(); + break; + } + for (ExceptionTreeNode::Children::iterator j( + node->children.begin());; + ++j) { - if (i == list.rend()) { - node->setPresent(); + if (j == node->children.end()) { + node = node->add(*i); break; } - for (ExceptionTreeNode::Children::iterator j( - node->children.begin());; - ++j) - { - if (j == node->children.end()) { - node = node->add(*i); - break; - } - if ((*j)->name == *i) { - node = j->get(); - break; - } + if ((*j)->name == *i) { + node = j->get(); + break; } } } diff --git a/codemaker/source/cppumaker/cpputype.cxx b/codemaker/source/cppumaker/cpputype.cxx index dcec84ccdc3f..12c951205c54 100644 --- a/codemaker/source/cppumaker/cpputype.cxx +++ b/codemaker/source/cppumaker/cpputype.cxx @@ -1441,115 +1441,117 @@ void InterfaceType::addComprehensiveGetCppuTypeIncludes( 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 (const unoidl::InterfaceTypeEntity::Attribute& attr : entity_->getDirectAttributes()) { - OUString type(resolveAllTypedefs(attr.type)); - out << indent() << "{\n"; - inc(); - out << indent() << "::rtl::OUString sAttributeType" << n << "( \"" - << type << "\" );\n" << indent() - << "::rtl::OUString sAttributeName" << n << "( \"" << name_ - << "::" << attr.name << "\" );\n"; - sal_Int32 getExcn = dumpExceptionTypeNames( - out, "get", attr.getExceptions, false); - sal_Int32 setExcn = dumpExceptionTypeNames( - out, "set", attr.setExceptions, false); - out << indent() - << ("typelib_typedescription_newExtendedInterfaceAttribute(" - " &pAttribute,\n"); - inc(); - out << indent() << index++ << ", sAttributeName" << n - << ".pData,\n" << indent() << "(typelib_TypeClass)" - << getTypeClass(type) << ", sAttributeType" << n << ".pData,\n" - << indent() << "sal_" << (attr.readOnly ? "True" : "False") - << ", " << getExcn << ", " - << (getExcn == 0 ? "0" : "the_getExceptions") << ", " << setExcn - << ", " << (setExcn == 0 ? "0" : "the_setExceptions") - << " );\n"; - dec(); - out << indent() - << ("typelib_typedescription_register(" - " (typelib_TypeDescription**)&pAttribute );\n"); - dec(); - out << indent() << "}\n"; - ++n; - } + if (entity_->getDirectAttributes().empty()) + return; + + out << "\n" << indent() + << "typelib_InterfaceAttributeTypeDescription * pAttribute = 0;\n"; + std::vector< unoidl::InterfaceTypeEntity::Attribute >::size_type n = 0; + for (const unoidl::InterfaceTypeEntity::Attribute& attr : entity_->getDirectAttributes()) { + OUString type(resolveAllTypedefs(attr.type)); + out << indent() << "{\n"; + inc(); + out << indent() << "::rtl::OUString sAttributeType" << n << "( \"" + << type << "\" );\n" << indent() + << "::rtl::OUString sAttributeName" << n << "( \"" << name_ + << "::" << attr.name << "\" );\n"; + sal_Int32 getExcn = dumpExceptionTypeNames( + out, "get", attr.getExceptions, false); + sal_Int32 setExcn = dumpExceptionTypeNames( + out, "set", attr.setExceptions, false); + out << indent() + << ("typelib_typedescription_newExtendedInterfaceAttribute(" + " &pAttribute,\n"); + inc(); + out << indent() << index++ << ", sAttributeName" << n + << ".pData,\n" << indent() << "(typelib_TypeClass)" + << getTypeClass(type) << ", sAttributeType" << n << ".pData,\n" + << indent() << "sal_" << (attr.readOnly ? "True" : "False") + << ", " << getExcn << ", " + << (getExcn == 0 ? "0" : "the_getExceptions") << ", " << setExcn + << ", " << (setExcn == 0 ? "0" : "the_setExceptions") + << " );\n"; + dec(); out << indent() - << ("typelib_typedescription_release(" - " (typelib_TypeDescription*)pAttribute );\n"); + << ("typelib_typedescription_register(" + " (typelib_TypeDescription**)&pAttribute );\n"); + dec(); + out << indent() << "}\n"; + ++n; } + out << indent() + << ("typelib_typedescription_release(" + " (typelib_TypeDescription*)pAttribute );\n"); } 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 (const unoidl::InterfaceTypeEntity::Method& method : entity_->getDirectMethods()) { - OUString returnType(resolveAllTypedefs(method.returnType)); - out << indent() << "{\n"; - inc(); - if (!method.parameters.empty()) { - out << indent() << "typelib_Parameter_Init aParameters[" - << method.parameters.size() << "];\n"; - } - std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >:: - size_type m = 0; - for (const unoidl::InterfaceTypeEntity::Method::Parameter& param : method.parameters) { - OUString type(resolveAllTypedefs(param.type)); - out << indent() << "::rtl::OUString sParamName" << m << "( \"" - << param.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 = " - << ((param.direction - == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_OUT) - ? "sal_False" : "sal_True") - << ";\n" << indent() << "aParameters[" << m << "].bOut = " - << ((param.direction - == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN) - ? "sal_False" : "sal_True") - << ";\n"; - ++m; - } - sal_Int32 excn = dumpExceptionTypeNames( - out, "", method.exceptions, - method.name != "acquire" && method.name != "release"); - out << indent() << "::rtl::OUString sReturnType" << n << "( \"" - << returnType << "\" );\n" << indent() - << "::rtl::OUString sMethodName" << n << "( \"" << name_ << "::" - << method.name << "\" );\n" << indent() - << "typelib_typedescription_newInterfaceMethod( &pMethod,\n"; - inc(); - out << indent() << index++ << ", sal_False,\n" << indent() - << "sMethodName" << n << ".pData,\n" << indent() - << "(typelib_TypeClass)" << getTypeClass(returnType) - << ", sReturnType" << n << ".pData,\n" << indent() - << method.parameters.size() << ", " - << (method.parameters.empty() ? "0" : "aParameters") << ",\n" - << indent() << excn << ", " - << (excn == 0 ? "0" : "the_Exceptions") << " );\n"; - dec(); - out << indent() - << ("typelib_typedescription_register(" - " (typelib_TypeDescription**)&pMethod );\n"); - dec(); - out << indent() << "}\n"; - ++n; - } + if (entity_->getDirectMethods().empty()) + return; + + out << "\n" << indent() + << "typelib_InterfaceMethodTypeDescription * pMethod = 0;\n"; + std::vector< unoidl::InterfaceTypeEntity::Method >::size_type n = 0; + for (const unoidl::InterfaceTypeEntity::Method& method : entity_->getDirectMethods()) { + OUString returnType(resolveAllTypedefs(method.returnType)); + out << indent() << "{\n"; + inc(); + if (!method.parameters.empty()) { + out << indent() << "typelib_Parameter_Init aParameters[" + << method.parameters.size() << "];\n"; + } + std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >:: + size_type m = 0; + for (const unoidl::InterfaceTypeEntity::Method::Parameter& param : method.parameters) { + OUString type(resolveAllTypedefs(param.type)); + out << indent() << "::rtl::OUString sParamName" << m << "( \"" + << param.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 = " + << ((param.direction + == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_OUT) + ? "sal_False" : "sal_True") + << ";\n" << indent() << "aParameters[" << m << "].bOut = " + << ((param.direction + == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN) + ? "sal_False" : "sal_True") + << ";\n"; + ++m; + } + sal_Int32 excn = dumpExceptionTypeNames( + out, "", method.exceptions, + method.name != "acquire" && method.name != "release"); + out << indent() << "::rtl::OUString sReturnType" << n << "( \"" + << returnType << "\" );\n" << indent() + << "::rtl::OUString sMethodName" << n << "( \"" << name_ << "::" + << method.name << "\" );\n" << indent() + << "typelib_typedescription_newInterfaceMethod( &pMethod,\n"; + inc(); + out << indent() << index++ << ", sal_False,\n" << indent() + << "sMethodName" << n << ".pData,\n" << indent() + << "(typelib_TypeClass)" << getTypeClass(returnType) + << ", sReturnType" << n << ".pData,\n" << indent() + << method.parameters.size() << ", " + << (method.parameters.empty() ? "0" : "aParameters") << ",\n" + << indent() << excn << ", " + << (excn == 0 ? "0" : "the_Exceptions") << " );\n"; + dec(); out << indent() - << ("typelib_typedescription_release(" - " (typelib_TypeDescription*)pMethod );\n"); + << ("typelib_typedescription_register(" + " (typelib_TypeDescription**)&pMethod );\n"); + dec(); + out << indent() << "}\n"; + ++n; } + out << indent() + << ("typelib_typedescription_release(" + " (typelib_TypeDescription*)pMethod );\n"); } void InterfaceType::dumpAttributesCppuDecl( diff --git a/codemaker/source/javamaker/javatype.cxx b/codemaker/source/javamaker/javatype.cxx index 16c2ef73e089..f800d7365852 100644 --- a/codemaker/source/javamaker/javatype.cxx +++ b/codemaker/source/javamaker/javatype.cxx @@ -64,22 +64,23 @@ void appendUnoName( buffer->append("[]"); } buffer->append(nucleus); - if (!arguments.empty()) { - buffer->append('<'); - for (std::vector< OUString >::const_iterator i(arguments.begin()); - i != arguments.end(); ++i) - { - if (i != arguments.begin()) { - buffer->append(','); - } - OUString n; - sal_Int32 k; - std::vector< OUString > args; - manager->decompose(*i, false, &n, &k, &args, nullptr); - appendUnoName(manager, n, k, args, buffer); + if (arguments.empty()) + return; + + buffer->append('<'); + for (std::vector< OUString >::const_iterator i(arguments.begin()); + i != arguments.end(); ++i) + { + if (i != arguments.begin()) { + buffer->append(','); } - buffer->append('>'); + OUString n; + sal_Int32 k; + std::vector< OUString > args; + manager->decompose(*i, false, &n, &k, &args, nullptr); + appendUnoName(manager, n, k, args, buffer); } + buffer->append('>'); } // Translate the name of a UNOIDL entity (enum type, plain struct type, @@ -643,39 +644,40 @@ void addTypeInfo( throw CannotDumpException( "UNOTYPEINFO array too big for Java class file format"); } - if (typeInfos != 0) { - classFile->addField( - static_cast< ClassFile::AccessFlags >( - ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC - | ClassFile::ACC_FINAL), - "UNOTYPEINFO", "[Lcom/sun/star/lib/uno/typeinfo/TypeInfo;", - 0, ""); - std::unique_ptr< ClassFile::Code > code(classFile->newCode()); - code->loadIntegerConstant(static_cast< sal_Int32 >(typeInfos)); - code->instrAnewarray("com/sun/star/lib/uno/typeinfo/TypeInfo"); - sal_Int32 index = 0; - sal_uInt16 stack = 0; - for (const TypeInfo& ti : typeInfo) - { - code->instrDup(); - code->loadIntegerConstant(index++); - stack = std::max(stack, ti.generateCode(*code, dependencies)); - code->instrAastore(); - } - code->instrPutstatic( - className, "UNOTYPEINFO", - "[Lcom/sun/star/lib/uno/typeinfo/TypeInfo;"); - code->instrReturn(); - if (stack > SAL_MAX_UINT16 - 4) { - throw CannotDumpException( - "Stack too big for Java class file format"); - } - code->setMaxStackAndLocals(static_cast< sal_uInt16 >(stack + 4), 0); - classFile->addMethod( - static_cast< ClassFile::AccessFlags >( - ClassFile::ACC_PRIVATE | ClassFile::ACC_STATIC), - "<clinit>", "()V", code.get(), std::vector< OString >(), ""); + if (typeInfos == 0) + return; + + classFile->addField( + static_cast< ClassFile::AccessFlags >( + ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC + | ClassFile::ACC_FINAL), + "UNOTYPEINFO", "[Lcom/sun/star/lib/uno/typeinfo/TypeInfo;", + 0, ""); + std::unique_ptr< ClassFile::Code > code(classFile->newCode()); + code->loadIntegerConstant(static_cast< sal_Int32 >(typeInfos)); + code->instrAnewarray("com/sun/star/lib/uno/typeinfo/TypeInfo"); + sal_Int32 index = 0; + sal_uInt16 stack = 0; + for (const TypeInfo& ti : typeInfo) + { + code->instrDup(); + code->loadIntegerConstant(index++); + stack = std::max(stack, ti.generateCode(*code, dependencies)); + code->instrAastore(); + } + code->instrPutstatic( + className, "UNOTYPEINFO", + "[Lcom/sun/star/lib/uno/typeinfo/TypeInfo;"); + code->instrReturn(); + if (stack > SAL_MAX_UINT16 - 4) { + throw CannotDumpException( + "Stack too big for Java class file format"); } + code->setMaxStackAndLocals(static_cast< sal_uInt16 >(stack + 4), 0); + classFile->addMethod( + static_cast< ClassFile::AccessFlags >( + ClassFile::ACC_PRIVATE | ClassFile::ACC_STATIC), + "<clinit>", "()V", code.get(), std::vector< OString >(), ""); } void handleEnumType( |