Make .hpp/.hdl more robust against accidental include of .hdl instead of .hpp.

.hdl failed to declare the inline cppu_detail_getUnoType functions defined in
.hpp, which if client code only includes .hdl instead of .hpp could lead to
runtime failures, now leads to compiler warnings.
This commit is contained in:
Stephan Bergmann
2011-11-02 17:01:25 +01:00
parent 8524330a74
commit b5ec39a65e
2 changed files with 61 additions and 125 deletions

View File

@@ -125,6 +125,10 @@ void CppuType::addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes)
} }
} }
void CppuType::dumpDeclaration(FileStream &) throw (CannotDumpException) {
OSL_ASSERT(false);
}
bool CppuType::dumpFiles(CppuOptions * options, rtl::OString const & outPath) { bool CppuType::dumpFiles(CppuOptions * options, rtl::OString const & outPath) {
return dumpFile(options, ".hdl", m_typeName, outPath) return dumpFile(options, ".hdl", m_typeName, outPath)
&& dumpFile(options, ".hpp", m_typeName, outPath); && dumpFile(options, ".hpp", m_typeName, outPath);
@@ -433,6 +437,42 @@ void CppuType::dumpInitializer(
out << ")"; out << ")";
} }
void CppuType::dumpHFileContent(
FileStream & out, codemaker::cppumaker::Includes & includes)
{
addDefaultHIncludes(includes);
dumpHeaderDefine(out, "HDL");
out << "\n";
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)) {
out << "\n";
}
dumpDeclaration(out);
if (!(m_typeName.equalsL(
RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XInterface")) ||
m_typeName.equalsL(
RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Exception")) ||
isPolymorphic()))
{
out << "\n" << indent()
<< ("inline ::com::sun::star::uno::Type const &"
" cppu_detail_getUnoType(");
dumpType(out, m_typeName, false, false, true);
out << " const *);\n";
}
if (codemaker::cppumaker::dumpNamespaceClose(out, m_typeName, false)) {
out << "\n";
}
out << "\n";
dumpTemplateHead(out);
out << "inline ::com::sun::star::uno::Type const & SAL_CALL getCppuType(";
dumpType(out, m_typeName, true);
dumpTemplateParameters(out);
out << " *) SAL_THROW(());\n\n#endif\n";
}
void CppuType::dumpGetCppuType(FileStream & out) { void CppuType::dumpGetCppuType(FileStream & out) {
if (m_typeName.equals("com/sun/star/uno/XInterface")) { if (m_typeName.equals("com/sun/star/uno/XInterface")) {
out << indent() out << indent()
@@ -1268,34 +1308,14 @@ sal_Bool InterfaceType::dumpHFile(
FileStream& o, codemaker::cppumaker::Includes & includes) FileStream& o, codemaker::cppumaker::Includes & includes)
throw( CannotDumpException ) throw( CannotDumpException )
{ {
OString headerDefine(dumpHeaderDefine(o, "HDL"));
o << "\n";
addDefaultHIncludes(includes);
if (m_reader.getMethodCount() != 0) { if (m_reader.getMethodCount() != 0) {
includes.add("com/sun/star/uno/RuntimeException"); includes.add("com/sun/star/uno/RuntimeException");
} }
includes.dump(o, 0); dumpHFileContent(o, includes);
o << ("\nnamespace com { namespace sun { namespace star { namespace uno {\n"
"class Type;\n} } } }\n\n");
if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) {
o << "\n";
}
dumpDeclaration(o);
if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) {
o << "\n";
}
o << "\ninline const ::com::sun::star::uno::Type& SAL_CALL getCppuType( ";
dumpType(o, m_typeName, sal_True, sal_False);
o << "* ) SAL_THROW( () );\n\n";
o << "#endif // "<< headerDefine << "\n";
return sal_True; return sal_True;
} }
sal_Bool InterfaceType::dumpDeclaration(FileStream& o) void InterfaceType::dumpDeclaration(FileStream& o)
throw( CannotDumpException ) throw( CannotDumpException )
{ {
// rtl::OString cppName(translateUnoToCppIdentifier( // rtl::OString cppName(translateUnoToCppIdentifier(
@@ -1323,8 +1343,6 @@ sal_Bool InterfaceType::dumpDeclaration(FileStream& o)
dec(); dec();
o << "};\n\n"; o << "};\n\n";
return sal_True;
} }
sal_Bool InterfaceType::dumpHxxFile( sal_Bool InterfaceType::dumpHxxFile(
@@ -2283,7 +2301,7 @@ sal_Bool ConstantsType::dumpHFile(
return sal_True; return sal_True;
} }
sal_Bool ConstantsType::dumpDeclaration(FileStream& o) void ConstantsType::dumpDeclaration(FileStream& o)
throw( CannotDumpException ) throw( CannotDumpException )
{ {
sal_uInt16 fieldCount = m_reader.getFieldCount(); sal_uInt16 fieldCount = m_reader.getFieldCount();
@@ -2302,8 +2320,6 @@ sal_Bool ConstantsType::dumpDeclaration(FileStream& o)
dumpConstantValue(o, i); dumpConstantValue(o, i);
o << ";\n"; o << ";\n";
} }
return sal_True;
} }
sal_Bool ConstantsType::hasConstants() sal_Bool ConstantsType::hasConstants()
@@ -2395,38 +2411,11 @@ sal_Bool StructureType::dumpHFile(
FileStream& o, codemaker::cppumaker::Includes & includes) FileStream& o, codemaker::cppumaker::Includes & includes)
throw( CannotDumpException ) throw( CannotDumpException )
{ {
OString headerDefine(dumpHeaderDefine(o, "HDL")); dumpHFileContent(o, includes);
o << "\n";
addDefaultHIncludes(includes);
includes.dump(o, 0);
o << "\n";
if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) {
o << "\n";
}
dumpDeclaration(o);
if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) {
o << "\n";
}
o << "\nnamespace com { namespace sun { namespace star { namespace uno {\n"
<< "class Type;\n} } } }\n\n";
dumpTemplateHead(o);
o << "inline const ::com::sun::star::uno::Type& SAL_CALL getCppuType( ";
dumpType(o, m_typeName, sal_True, sal_False);
dumpTemplateParameters(o);
o << "* );\n\n";
o << "#endif // "<< headerDefine << "\n";
return sal_True; return sal_True;
} }
sal_Bool StructureType::dumpDeclaration(FileStream& o) void StructureType::dumpDeclaration(FileStream& o)
throw( CannotDumpException ) throw( CannotDumpException )
{ {
o << "\n#ifdef SAL_W32\n" o << "\n#ifdef SAL_W32\n"
@@ -2508,8 +2497,6 @@ sal_Bool StructureType::dumpDeclaration(FileStream& o)
o << "#ifdef SAL_W32\n" o << "#ifdef SAL_W32\n"
<< "# pragma pack(pop)\n" << "# pragma pack(pop)\n"
<< "#endif\n\n"; << "#endif\n\n";
return sal_True;
} }
sal_Bool StructureType::dumpHxxFile( sal_Bool StructureType::dumpHxxFile(
@@ -3177,36 +3164,11 @@ sal_Bool ExceptionType::dumpHFile(
FileStream& o, codemaker::cppumaker::Includes & includes) FileStream& o, codemaker::cppumaker::Includes & includes)
throw( CannotDumpException ) throw( CannotDumpException )
{ {
OString headerDefine(dumpHeaderDefine(o, "HDL")); dumpHFileContent(o, includes);
o << "\n";
addDefaultHIncludes(includes);
includes.dump(o, 0);
o << "\n";
if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) {
o << "\n";
}
dumpDeclaration(o);
if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) {
o << "\n";
}
o << "\nnamespace com { namespace sun { namespace star { namespace uno {\n"
<< "class Type;\n} } } }\n\n";
o << "inline const ::com::sun::star::uno::Type& SAL_CALL getCppuType( ";
dumpType(o, m_typeName, sal_True, sal_False);
o << "* ) SAL_THROW( () );\n\n";
o << "#endif // "<< headerDefine << "\n";
return sal_True; return sal_True;
} }
sal_Bool ExceptionType::dumpDeclaration(FileStream& o) void ExceptionType::dumpDeclaration(FileStream& o)
throw( CannotDumpException ) throw( CannotDumpException )
{ {
o << "\nclass CPPU_GCC_DLLPUBLIC_EXPORT " << m_name; o << "\nclass CPPU_GCC_DLLPUBLIC_EXPORT " << m_name;
@@ -3291,8 +3253,6 @@ sal_Bool ExceptionType::dumpDeclaration(FileStream& o)
dec(); dec();
o << "};\n\n"; o << "};\n\n";
return sal_True;
} }
sal_Bool ExceptionType::dumpHxxFile( sal_Bool ExceptionType::dumpHxxFile(
@@ -3558,36 +3518,11 @@ sal_Bool EnumType::dumpHFile(
FileStream& o, codemaker::cppumaker::Includes & includes) FileStream& o, codemaker::cppumaker::Includes & includes)
throw( CannotDumpException ) throw( CannotDumpException )
{ {
OString headerDefine(dumpHeaderDefine(o, "HDL")); dumpHFileContent(o, includes);
o << "\n";
addDefaultHIncludes(includes);
includes.dump(o, 0);
o << "\n";
if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) {
o << "\n";
}
dumpDeclaration(o);
if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) {
o << "\n";
}
o << "\nnamespace com { namespace sun { namespace star { namespace uno {\n"
<< "class Type;\n} } } }\n\n";
o << "inline const ::com::sun::star::uno::Type& SAL_CALL getCppuType( ";
dumpType(o, m_typeName, sal_True, sal_False);
o << "* ) SAL_THROW( () );\n\n";
o << "#endif // "<< headerDefine << "\n";
return sal_True; return sal_True;
} }
sal_Bool EnumType::dumpDeclaration(FileStream& o) void EnumType::dumpDeclaration(FileStream& o)
throw( CannotDumpException ) throw( CannotDumpException )
{ {
o << "\nenum " << m_name << "\n{\n"; o << "\nenum " << m_name << "\n{\n";
@@ -3621,8 +3556,6 @@ sal_Bool EnumType::dumpDeclaration(FileStream& o)
dec(); dec();
o << "};\n\n"; o << "};\n\n";
return sal_True;
} }
sal_Bool EnumType::dumpHxxFile( sal_Bool EnumType::dumpHxxFile(
@@ -3800,7 +3733,7 @@ sal_Bool TypeDefType::dumpHFile(
return sal_True; return sal_True;
} }
sal_Bool TypeDefType::dumpDeclaration(FileStream& o) void TypeDefType::dumpDeclaration(FileStream& o)
throw( CannotDumpException ) throw( CannotDumpException )
{ {
o << "\ntypedef "; o << "\ntypedef ";
@@ -3809,8 +3742,6 @@ sal_Bool TypeDefType::dumpDeclaration(FileStream& o)
rtl::OUStringToOString( rtl::OUStringToOString(
m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8)); m_reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8));
o << " " << m_name << ";\n\n"; o << " " << m_name << ";\n\n";
return sal_True;
} }
sal_Bool TypeDefType::dumpHxxFile( sal_Bool TypeDefType::dumpHxxFile(

View File

@@ -110,6 +110,8 @@ protected:
codemaker::cpp::IdentifierTranslationMode isGlobal() const; codemaker::cpp::IdentifierTranslationMode isGlobal() const;
virtual void dumpDeclaration(FileStream & out) throw (CannotDumpException);
virtual void addSpecialDependencies() {} virtual void addSpecialDependencies() {}
virtual bool dumpFiles(CppuOptions * options, rtl::OString const & outPath); virtual bool dumpFiles(CppuOptions * options, rtl::OString const & outPath);
@@ -139,6 +141,9 @@ protected:
void dumpInitializer( void dumpInitializer(
FileStream & out, bool parameterized, rtl::OUString const & type) const; FileStream & out, bool parameterized, rtl::OUString const & type) const;
void dumpHFileContent(
FileStream & out, codemaker::cppumaker::Includes & includes);
protected: protected:
sal_uInt32 m_inheritedMemberCount; sal_uInt32 m_inheritedMemberCount;
@@ -165,7 +170,7 @@ public:
virtual ~InterfaceType(); virtual ~InterfaceType();
sal_Bool dumpDeclaration(FileStream& o) throw( CannotDumpException ); virtual void dumpDeclaration(FileStream& o) throw( CannotDumpException );
sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) 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 dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
@@ -227,7 +232,7 @@ public:
virtual sal_Bool dump(CppuOptions* pOptions) throw( CannotDumpException ); virtual sal_Bool dump(CppuOptions* pOptions) throw( CannotDumpException );
sal_Bool dumpDeclaration(FileStream& o) throw( CannotDumpException ); virtual void dumpDeclaration(FileStream& o) throw( CannotDumpException );
sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) 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 dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
sal_Bool hasConstants(); sal_Bool hasConstants();
@@ -255,7 +260,7 @@ public:
virtual ~StructureType(); virtual ~StructureType();
sal_Bool dumpDeclaration(FileStream& o) throw( CannotDumpException ); virtual void dumpDeclaration(FileStream& o) throw( CannotDumpException );
sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) 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 dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
@@ -293,7 +298,7 @@ public:
virtual ~ExceptionType(); virtual ~ExceptionType();
sal_Bool dumpDeclaration(FileStream& o) throw( CannotDumpException ); virtual void dumpDeclaration(FileStream& o) throw( CannotDumpException );
sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) 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 dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
@@ -309,7 +314,7 @@ public:
virtual ~EnumType(); virtual ~EnumType();
sal_Bool dumpDeclaration(FileStream& o) throw( CannotDumpException ); virtual void dumpDeclaration(FileStream& o) throw( CannotDumpException );
sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) 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 dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
@@ -326,7 +331,7 @@ public:
virtual ~TypeDefType(); virtual ~TypeDefType();
sal_Bool dumpDeclaration(FileStream& o) throw( CannotDumpException ); virtual void dumpDeclaration(FileStream& o) throw( CannotDumpException );
sal_Bool dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) 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 dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) throw( CannotDumpException );
}; };