Kaydet (Commit) 7a69e30f authored tarafından Caolán McNamara's avatar Caolán McNamara

use rtl_Instance for the auto-generated local statics

üst 9276f7d5
...@@ -363,6 +363,7 @@ void CppuType::addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes) ...@@ -363,6 +363,7 @@ void CppuType::addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes)
const const
{ {
//TODO: Only include what is really needed //TODO: Only include what is really needed
includes.addRtlInstanceHxx();
includes.addOslMutexHxx(); includes.addOslMutexHxx();
includes.addType(); includes.addType();
if (m_typeMgr.getTypeClass(m_typeName) == RT_TYPE_INTERFACE) { if (m_typeMgr.getTypeClass(m_typeName) == RT_TYPE_INTERFACE) {
...@@ -593,16 +594,19 @@ void CppuType::dumpNormalGetCppuType(FileStream& o) ...@@ -593,16 +594,19 @@ void CppuType::dumpNormalGetCppuType(FileStream& o)
void CppuType::dumpComprehensiveGetCppuType(FileStream& o) void CppuType::dumpComprehensiveGetCppuType(FileStream& o)
{ {
dumpGetCppuTypePreamble(o); if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) {
o << " namespace detail {\n\n";
o << indent() << "static ::com::sun::star::uno::Type * the_pType = 0;\n"; }
o << indent() << "if (the_pType == 0)\n" << indent() << "{\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(); inc();
o << indent() << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n"; o << indent() << "::com::sun::star::uno::Type operator()() const\n";
o << indent() << "{\n";
o << indent() << "if (the_pType == 0)\n" << indent() << "{\n";
inc(); inc();
o << indent() << "::rtl::OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM(\"" o << indent() << "::rtl::OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM(\""
<< m_typeName.replace('/', '.') << "\") );\n\n"; << m_typeName.replace('/', '.') << "\") );\n\n";
...@@ -679,8 +683,8 @@ void CppuType::dumpComprehensiveGetCppuType(FileStream& o) ...@@ -679,8 +683,8 @@ void CppuType::dumpComprehensiveGetCppuType(FileStream& o)
} else { } else {
o << indent() << count << ",\n" << indent() << "0 );\n\n"; o << indent() << count << ",\n" << indent() << "0 );\n\n";
} }
dec(); dec();
o << indent() o << indent()
<< ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD" << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
" );\n\n"); " );\n\n");
...@@ -688,15 +692,21 @@ void CppuType::dumpComprehensiveGetCppuType(FileStream& o) ...@@ -688,15 +692,21 @@ void CppuType::dumpComprehensiveGetCppuType(FileStream& o)
o << indent() << "typelib_typedescription_release( pTD );\n" o << indent() << "typelib_typedescription_release( pTD );\n"
<< indent() << "// End inline typedescription generation\n\n"; << indent() << "// End inline typedescription generation\n\n";
o << indent() << "static ::com::sun::star::uno::Type the_staticType( " o << indent() << "::com::sun::star::uno::Type the_staticType( "
<< getTypeClass(m_typeName) << ", sTypeName );\n"; << getTypeClass(m_typeName) << ", sTypeName );\n";
o << indent() << "the_pType = &the_staticType;\n"; o << indent() << "return the_staticType;\n";
dec(); dec();
o << indent() << "}\n"; o << indent() << "}\n";
dec(); dec();
o << indent() << "}\n\n"; o << indent() << "};\n\n";
o << indent() << "return *the_pType;\n";
if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) {
o << " }\n\n";
}
dumpGetCppuTypePreamble(o);
o << indent() << "return detail::" << sStaticTypeClass << "::get();\n";
dumpGetCppuTypePostamble(o); dumpGetCppuTypePostamble(o);
} }
...@@ -1519,15 +1529,18 @@ void InterfaceType::dumpNormalGetCppuType(FileStream& o) ...@@ -1519,15 +1529,18 @@ void InterfaceType::dumpNormalGetCppuType(FileStream& o)
void InterfaceType::dumpComprehensiveGetCppuType(FileStream& o) void InterfaceType::dumpComprehensiveGetCppuType(FileStream& o)
{ {
dumpGetCppuTypePreamble(o); if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) {
o << " namespace detail {\n\n";
o << indent() << "static ::com::sun::star::uno::Type * the_pType = 0;\n"; }
o << indent() << "if (the_pType == 0)\n" << indent() << "{\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(); inc();
o << indent() << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n"; o << indent() << "::com::sun::star::uno::Type operator()() const\n";
o << indent() << "{\n";
o << indent() << "if (the_pType == 0)\n" << indent() << "{\n";
inc(); inc();
o << indent() << "::rtl::OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM(\"" o << indent() << "::rtl::OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM(\""
<< m_typeName.replace('/', '.') << "\") );\n\n"; << m_typeName.replace('/', '.') << "\") );\n\n";
...@@ -1599,9 +1612,8 @@ void InterfaceType::dumpComprehensiveGetCppuType(FileStream& o) ...@@ -1599,9 +1612,8 @@ void InterfaceType::dumpComprehensiveGetCppuType(FileStream& o)
<< ("typelib_typedescription_release( (typelib_TypeDescription*)pTD" << ("typelib_typedescription_release( (typelib_TypeDescription*)pTD"
" );\n\n"); " );\n\n");
o << indent() << "static ::com::sun::star::uno::Type the_staticType( " o << indent() << "::com::sun::star::uno::Type the_staticType( "
<< getTypeClass(m_typeName) << ", sTypeName );\n"; << getTypeClass(m_typeName) << ", sTypeName );\n";
o << indent() << "the_pType = &the_staticType;\n";
StringSet aTypes; StringSet aTypes;
// type for RuntimeException is always needed // type for RuntimeException is always needed
...@@ -1621,12 +1633,20 @@ void InterfaceType::dumpComprehensiveGetCppuType(FileStream& o) ...@@ -1621,12 +1633,20 @@ void InterfaceType::dumpComprehensiveGetCppuType(FileStream& o)
o << indent() << "// End inline typedescription generation\n"; o << indent() << "// End inline typedescription generation\n";
o << indent() << "return the_staticType;\n";
dec(); dec();
o << indent() << "}\n"; o << indent() << "}\n";
dec(); dec();
o << indent() << "}\n\n" o << indent() << "};\n\n";
<< indent() << "return *the_pType;\n";
if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) {
o << " }\n\n";
}
dumpGetCppuTypePreamble(o);
o << indent() << "return detail::" << sStaticTypeClass << "::get();\n";
dumpGetCppuTypePostamble(o); dumpGetCppuTypePostamble(o);
} }
...@@ -2781,14 +2801,20 @@ void StructureType::dumpNormalGetCppuType(FileStream & out) { ...@@ -2781,14 +2801,20 @@ void StructureType::dumpNormalGetCppuType(FileStream & out) {
dumpGetCppuTypePostamble(out); dumpGetCppuTypePostamble(out);
} }
void StructureType::dumpComprehensiveGetCppuType(FileStream & out) { void StructureType::dumpComprehensiveGetCppuType(FileStream & out)
dumpGetCppuTypePreamble(out); {
out << indent() << "static ::com::sun::star::uno::Type * the_pType = 0;\n" if (codemaker::cppumaker::dumpNamespaceOpen(out, m_typeName, false)) {
<< indent() << "if (the_pType == 0) {\n"; out << " namespace detail {\n\n";
}
OString sType = m_typeName.copy(m_typeName.lastIndexOf('/') + 1);
OString sStaticTypeClass = "the" + sType + "Type";
out << indent() << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type, " << sStaticTypeClass << " >\n";
out << indent() << "{\n";
inc(); inc();
out << indent() out << indent() << "::com::sun::star::uno::Type operator()() const\n";
<< "::osl::MutexGuard the_guard(::osl::Mutex::getGlobalMutex());\n" out << indent() << "{\n";
<< indent() << "if (the_pType == 0) {\n";
inc(); inc();
if (isPolymorphic()) { if (isPolymorphic()) {
out << indent() << "::rtl::OUStringBuffer the_buffer;\n" << indent() out << indent() << "::rtl::OUStringBuffer the_buffer;\n" << indent()
...@@ -2912,18 +2938,21 @@ void StructureType::dumpComprehensiveGetCppuType(FileStream & out) { ...@@ -2912,18 +2938,21 @@ void StructureType::dumpComprehensiveGetCppuType(FileStream & out) {
out << ", " << fields << ", the_members);\n"; out << ", " << fields << ", the_members);\n";
out << indent() << "::typelib_typedescription_register(&the_newType);\n"; out << indent() << "::typelib_typedescription_register(&the_newType);\n";
out << indent() << "::typelib_typedescription_release(the_newType);\n"; out << indent() << "::typelib_typedescription_release(the_newType);\n";
out << indent() << "static ::com::sun::star::uno::Type the_staticType("
out << indent() << "::com::sun::star::uno::Type the_staticType("
<< getTypeClass(m_typeName) << ", the_name);\n"; << getTypeClass(m_typeName) << ", the_name);\n";
out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n"; out << indent() << "return the_staticType;\n";
out << indent() << "the_pType = &the_staticType;\n";
dec(); dec();
out << indent() << "}\n"; out << indent() << "}\n";
dec(); dec();
out << indent() << "} else {\n"; out << indent() << "};\n";
inc();
out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n"; if (codemaker::cppumaker::dumpNamespaceClose(out, m_typeName, false)) {
dec(); out << " }\n\n";
out << indent() << "}\n" << indent() << "return *the_pType;\n"; }
dumpGetCppuTypePreamble(out);
out << indent() << "return detail::" << sStaticTypeClass << "::get();\n";
dumpGetCppuTypePostamble(out); dumpGetCppuTypePostamble(out);
} }
...@@ -3584,15 +3613,18 @@ void EnumType::dumpNormalGetCppuType(FileStream& o) ...@@ -3584,15 +3613,18 @@ void EnumType::dumpNormalGetCppuType(FileStream& o)
void EnumType::dumpComprehensiveGetCppuType(FileStream& o) void EnumType::dumpComprehensiveGetCppuType(FileStream& o)
{ {
dumpGetCppuTypePreamble(o); if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) {
o << " namespace detail {\n\n";
o << indent() << "static ::com::sun::star::uno::Type * the_pType = 0;\n"; }
o << indent() << "if (the_pType == 0)\n" << indent() << "{\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(); inc();
o << indent() << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n"; o << indent() << "::com::sun::star::uno::Type operator()() const\n";
o << indent() << "{\n";
o << indent() << "if (the_pType == 0)\n" << indent() << "{\n";
inc(); inc();
o << indent() << "::rtl::OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM(\"" o << indent() << "::rtl::OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM(\""
<< m_typeName.replace('/', '.') << "\") );\n\n"; << m_typeName.replace('/', '.') << "\") );\n\n";
...@@ -3644,16 +3676,21 @@ void EnumType::dumpComprehensiveGetCppuType(FileStream& o) ...@@ -3644,16 +3676,21 @@ void EnumType::dumpComprehensiveGetCppuType(FileStream& o)
o << indent() << "typelib_typedescription_release( pTD );\n" o << indent() << "typelib_typedescription_release( pTD );\n"
<< indent() << "// End inline typedescription generation\n\n"; << indent() << "// End inline typedescription generation\n\n";
o << indent() << "static ::com::sun::star::uno::Type the_staticType( " o << indent() << "::com::sun::star::uno::Type the_staticType( "
<< getTypeClass(m_typeName) << ", sTypeName );\n"; << getTypeClass(m_typeName) << ", sTypeName );\n";
o << indent() << "the_pType = &the_staticType;\n"; o << indent() << "return the_staticType;\n";
dec(); dec();
o << indent() << "}\n"; o << indent() << "}\n";
dec(); dec();
o << indent() << "}\n\n" o << indent() << "};\n\n";
<< indent() << "return *the_pType;\n";
if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) {
o << " }\n\n";
}
dumpGetCppuTypePreamble(o);
o << indent() << "return detail::" << sStaticTypeClass << "::get();\n";
dumpGetCppuTypePostamble(o); dumpGetCppuTypePostamble(o);
} }
......
...@@ -60,6 +60,7 @@ Includes::Includes( ...@@ -60,6 +60,7 @@ Includes::Includes(
m_includeRtlTextencH(false), m_includeRtlUstrbufHxx(false), m_includeRtlTextencH(false), m_includeRtlUstrbufHxx(false),
m_includeRtlUstringH(false), m_includeRtlUstringH(false),
m_includeRtlUstringHxx(dependencies.hasStringDependency()), m_includeRtlUstringHxx(dependencies.hasStringDependency()),
m_includeRtlInstanceHxx(false),
m_includeSalTypesH( m_includeSalTypesH(
dependencies.hasBooleanDependency() || dependencies.hasByteDependency() dependencies.hasBooleanDependency() || dependencies.hasByteDependency()
|| dependencies.hasShortDependency() || dependencies.hasShortDependency()
...@@ -250,6 +251,10 @@ void Includes::dump(FileStream & out, rtl::OString const * companionHdl) { ...@@ -250,6 +251,10 @@ void Includes::dump(FileStream & out, rtl::OString const * companionHdl) {
dumpEmptyLineBeforeFirst(out, &first); dumpEmptyLineBeforeFirst(out, &first);
out << ("#include \"rtl/ustring.hxx\"\n"); out << ("#include \"rtl/ustring.hxx\"\n");
} }
if (m_includeRtlInstanceHxx) {
dumpEmptyLineBeforeFirst(out, &first);
out << "#include \"rtl/instance.hxx\"\n";
}
if (m_includeSalTypesH) { if (m_includeSalTypesH) {
dumpEmptyLineBeforeFirst(out, &first); dumpEmptyLineBeforeFirst(out, &first);
out << "#include \"sal/types.h\"\n"; out << "#include \"sal/types.h\"\n";
......
...@@ -61,6 +61,7 @@ public: ...@@ -61,6 +61,7 @@ public:
void addRtlUstrbufHxx() { m_includeRtlUstrbufHxx = true; } void addRtlUstrbufHxx() { m_includeRtlUstrbufHxx = true; }
void addRtlUstringH() { m_includeRtlUstringH = true; } void addRtlUstringH() { m_includeRtlUstringH = true; }
void addRtlUstringHxx() { m_includeRtlUstringHxx = true; } void addRtlUstringHxx() { m_includeRtlUstringHxx = true; }
void addRtlInstanceHxx() { m_includeRtlInstanceHxx = true; }
void addSalTypesH() { m_includeSalTypesH = true; } void addSalTypesH() { m_includeSalTypesH = true; }
void addTypelibTypeclassH() { m_includeTypelibTypeclassH = true; } void addTypelibTypeclassH() { m_includeTypelibTypeclassH = true; }
void addTypelibTypedescriptionH() void addTypelibTypedescriptionH()
...@@ -94,6 +95,7 @@ private: ...@@ -94,6 +95,7 @@ private:
bool m_includeRtlUstrbufHxx; bool m_includeRtlUstrbufHxx;
bool m_includeRtlUstringH; bool m_includeRtlUstringH;
bool m_includeRtlUstringHxx; bool m_includeRtlUstringHxx;
bool m_includeRtlInstanceHxx;
bool m_includeSalTypesH; bool m_includeSalTypesH;
bool m_includeTypelibTypeclassH; bool m_includeTypelibTypeclassH;
bool m_includeTypelibTypedescriptionH; bool m_includeTypelibTypedescriptionH;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment