Skip to content

Commit ef2f1a4

Browse files
committed
Remove hardcoded default values
1 parent 29d10fa commit ef2f1a4

2 files changed

Lines changed: 2 additions & 38 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,10 +3985,6 @@ std::string Converter::GetArrayDefaultAsString(clang::QualType qual_type) {
39853985
}
39863986

39873987
std::string Converter::GetDefaultAsString(clang::QualType qual_type) {
3988-
if (qual_type->isVoidType()) {
3989-
return "()";
3990-
}
3991-
39923988
if (IsVaListType(qual_type)) {
39933989
computed_expr_type_ = ComputedExprType::FreshValue;
39943990
return "VaList::default()";
@@ -4021,18 +4017,6 @@ std::string Converter::GetDefaultAsString(clang::QualType qual_type) {
40214017
std::string Converter::GetDefaultAsStringFallback(clang::QualType qual_type) {
40224018
qual_type = qual_type.getUnqualifiedType().getCanonicalType();
40234019

4024-
if (qual_type->isBooleanType()) {
4025-
return "false";
4026-
}
4027-
4028-
if (qual_type->isIntegerType() && !qual_type->isEnumeralType()) {
4029-
return getTypedLiteral("0", ToString(qual_type));
4030-
}
4031-
4032-
if (qual_type->isFloatingType()) {
4033-
return getTypedLiteral("0.0", ToString(qual_type));
4034-
}
4035-
40364020
if (auto record = qual_type->getAsRecordDecl()) {
40374021
if (ctx_.getSourceManager().isInSystemHeader(record->getLocation()) &&
40384022
qual_type.isPODType(ctx_)) {

‎cpp2rust/converter/models/converter_refcount.cpp‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,10 +2089,6 @@ ConverterRefCount::GetArrayDefaultAsString(clang::QualType qual_type) {
20892089
}
20902090

20912091
std::string ConverterRefCount::GetDefaultAsString(clang::QualType qual_type) {
2092-
if (qual_type->isVoidType()) {
2093-
return "()";
2094-
}
2095-
20962092
if (IsVaListType(qual_type)) {
20972093
computed_expr_type_ = ComputedExprType::FreshValue;
20982094
return BoxValue("VaList::default()");
@@ -2117,12 +2113,8 @@ std::string ConverterRefCount::GetDefaultAsString(clang::QualType qual_type) {
21172113
ret =
21182114
std::format("FnPtr::<{}>::null()", ConvertFunctionPointerType(proto));
21192115
} else {
2120-
if (pointee_type->isVoidType()) {
2121-
ret = "AnyPtr::default()";
2122-
} else {
2123-
PushConversionKind push(*this, ConversionKind::Unboxed);
2124-
ret = std::format("Ptr::<{}>::null()", ConvertPointeeType(qual_type));
2125-
}
2116+
PushConversionKind push(*this, ConversionKind::Unboxed);
2117+
ret = std::format("Ptr::<{}>::null()", ConvertPointeeType(qual_type));
21262118
}
21272119
} else {
21282120
return Converter::GetDefaultAsString(qual_type);
@@ -2133,18 +2125,6 @@ std::string ConverterRefCount::GetDefaultAsString(clang::QualType qual_type) {
21332125

21342126
std::string
21352127
ConverterRefCount::GetDefaultAsStringFallback(clang::QualType qual_type) {
2136-
auto canonical = qual_type.getUnqualifiedType().getCanonicalType();
2137-
if (canonical->isBooleanType() ||
2138-
(canonical->isIntegerType() && !canonical->isEnumeralType()) ||
2139-
canonical->isFloatingType()) {
2140-
std::string unboxed;
2141-
{
2142-
PushConversionKind push(*this, ConversionKind::Unboxed);
2143-
unboxed = Converter::GetDefaultAsStringFallback(qual_type);
2144-
}
2145-
return BoxValue(std::move(unboxed));
2146-
}
2147-
21482128
return std::format("<{}>::default()", ToString(qual_type));
21492129
}
21502130

0 commit comments

Comments
 (0)