rustmaker: Use OString literals (loplugin:ostr)

This fixes clang plugin errors like the following
seen in an --enable-rust-uno build:

    .../libreoffice/codemaker/source/rustmaker/rustproduce.cxx:1063:16: error: use a _ostr user-defined string literal instead of constructing an instance of 'OString' from an ordinary string literal [loplugin:ostr]
     1063 |         return "u8";
          |                ^~~~

Change-Id: I5891641b80b46e19f1ceb401e48b6a8fb0286e58
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190848
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn
2025-09-12 13:56:29 +02:00
parent 7d40ccfe19
commit 82df59fa8e
2 changed files with 38 additions and 38 deletions
+17 -17
View File
@@ -1104,7 +1104,7 @@ OString CppProducer::getCFunctionPrefix(std::string_view unoName)
{
// Convert com.sun.star.lang.XMain to com__sun__star__lang__XMain for function names
OString temp(unoName);
return temp.replaceAll(".", "__");
return temp.replaceAll("."_ostr, "__"_ostr);
}
OString CppProducer::getMethodReturnType(std::u16string_view returnType) const
@@ -1120,13 +1120,13 @@ OString CppProducer::getMethodDefaultReturn(std::u16string_view returnType) cons
// Handle void vs non-void return types properly
if (resolvedType == u"void")
return ""; // void methods don't return anything
return ""_ostr; // void methods don't return anything
// Return appropriate default values for different types
if (resolvedType == u"double")
return "0.0";
return "0.0"_ostr;
else if (resolvedType == u"float")
return "0.0f";
return "0.0f"_ostr;
else if (resolvedType == u"sal_Int32" || resolvedType == u"long" || resolvedType == u"sal_Int16"
|| resolvedType == u"short" || resolvedType == u"sal_Int8" || resolvedType == u"byte"
|| resolvedType == u"sal_uInt8" || resolvedType == u"sal_uInt16"
@@ -1134,9 +1134,9 @@ OString CppProducer::getMethodDefaultReturn(std::u16string_view returnType) cons
|| resolvedType == u"sal_uInt64" || resolvedType == u"sal_Unicode"
|| resolvedType == u"unsigned short" || resolvedType == u"unsigned long"
|| resolvedType == u"unsigned hyper" || resolvedType == u"hyper")
return "0";
return "0"_ostr;
else if (resolvedType == u"sal_Bool" || resolvedType == u"boolean")
return "false";
return "false"_ostr;
else
{
// Check if it's an enum type
@@ -1154,11 +1154,11 @@ OString CppProducer::getMethodDefaultReturn(std::u16string_view returnType) cons
else if (isUnoType(resolvedType) && isUnoStruct(resolvedType))
{
// Return empty struct for struct types
return OString("{}"); // Empty struct literal
return "{}"_ostr; // Empty struct literal
}
else
{
return "nullptr"; // For pointer/interface/any types
return "nullptr"_ostr; // For pointer/interface/any types
}
}
}
@@ -2485,25 +2485,25 @@ OString CppProducer::convertBasicType(const OString& typeName) const
// Convert UNO primitive types to C++ types
if (result == "long")
result = "sal_Int32";
result = "sal_Int32"_ostr;
else if (result == "short")
result = "sal_Int16";
result = "sal_Int16"_ostr;
else if (result == "byte")
result = "sal_Int8";
result = "sal_Int8"_ostr;
else if (result == "boolean")
result = "sal_Bool";
result = "sal_Bool"_ostr;
else if (result == "double")
result = "double";
result = "double"_ostr;
else if (result == "float")
result = "float";
result = "float"_ostr;
else if (result == "string")
result = "OUString";
result = "OUString"_ostr;
else if (result == "any")
result = "Any";
result = "Any"_ostr;
else if (result.indexOf('.') != -1)
{
// For UNO types with namespace, convert dots to double colons
result = result.replaceAll(".", "::");
result = result.replaceAll("."_ostr, "::"_ostr);
}
return result;
+21 -21
View File
@@ -1060,44 +1060,44 @@ OString RustProducer::getRustWrapperTypeName(std::u16string_view unoType) const
// Handle primitive types
if (rustType == "boolean")
return "u8";
return "u8"_ostr;
if (rustType == "byte")
return "i8";
return "i8"_ostr;
if (rustType == "short")
return "i16";
return "i16"_ostr;
if (rustType == "unsigned short")
return "u16";
return "u16"_ostr;
if (rustType == "long")
return "i32";
return "i32"_ostr;
if (rustType == "unsigned long")
return "u32";
return "u32"_ostr;
if (rustType == "hyper")
return "i64";
return "i64"_ostr;
if (rustType == "unsigned hyper")
return "u64";
return "u64"_ostr;
if (rustType == "float")
return "f32";
return "f32"_ostr;
if (rustType == "double")
return "f64";
return "f64"_ostr;
if (rustType == "char")
return "u16";
return "u16"_ostr;
// Handle special UNO types
if (rustType == "string")
return "Option<crate::core::OUString>";
return "Option<crate::core::OUString>"_ostr;
if (rustType == "any" || rustType == "com.sun.star.uno.Any")
return "Option<crate::core::Any>";
return "Option<crate::core::Any>"_ostr;
// Handle sequence types (arrays) - return raw pointer for now
if (rustType.startsWith("[]"))
{
return "*mut c_void";
return "*mut c_void"_ostr;
}
// Handle template types like Pair<T,U> - return raw pointer for now to avoid parsing issues
if (rustType.indexOf('<') != -1 && rustType.indexOf('>') != -1)
{
return "*mut c_void";
return "*mut c_void"_ostr;
}
// Handle generated UNO types (interface, struct, enum)
@@ -1106,7 +1106,7 @@ OString RustProducer::getRustWrapperTypeName(std::u16string_view unoType) const
// Skip types that look malformed or have invalid characters
if (rustType.indexOf('[') != -1 || rustType.indexOf('<') != -1)
{
return "*mut c_void";
return "*mut c_void"_ostr;
}
// First resolve typedefs
@@ -1130,7 +1130,7 @@ OString RustProducer::getRustWrapperTypeName(std::u16string_view unoType) const
}
// Default to raw pointer for unknown types
return "*mut c_void";
return "*mut c_void"_ostr;
}
OString RustProducer::resolveTypedef(std::u16string_view unoType) const
@@ -1159,7 +1159,7 @@ OString RustProducer::getRustReturnType(std::u16string_view unoType) const
// Handle void returns
if (unoType == u"void")
{
return "()";
return "()"_ostr;
}
// For interfaces, structs, enums - return Option<TypeWrapper> like services
@@ -1169,7 +1169,7 @@ OString RustProducer::getRustReturnType(std::u16string_view unoType) const
if (rustType.indexOf('.') != -1)
{
// Convert dots to :: for module path
OString modulePath = rustType.replaceAll(".", "::");
OString modulePath = rustType.replaceAll("."_ostr, "::"_ostr);
// Extract simple type name
sal_Int32 lastDot = rustType.lastIndexOf('.');
@@ -1191,7 +1191,7 @@ OString RustProducer::getRustFFIReturnType(std::u16string_view unoType) const
// Handle void returns
if (unoType == u"void")
{
return "()";
return "()"_ostr;
}
// For interfaces, structs, enums - return their opaque handle typedef
@@ -1204,7 +1204,7 @@ OString RustProducer::getRustFFIReturnType(std::u16string_view unoType) const
}
// For other types (primitives, sequences, etc) - use void*
return "*mut c_void";
return "*mut c_void"_ostr;
}
bool RustProducer::isUnoInterface(std::u16string_view typeName) const