MCPcopy Create free account
hub / github.com/andreasfertig/cppinsights / GetValueOfValueInit

Method GetValueOfValueInit

CodeGenerator.cpp:3023–3078  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3021//-----------------------------------------------------------------------------
3022
3023std::string CodeGenerator::GetValueOfValueInit(const QualType& t)
3024{
3025 const QualType& type = t.getCanonicalType();
3026
3027 if(type->isScalarType()) {
3028 switch(type->getScalarTypeKind()) {
3029 case Type::STK_CPointer:
3030 case Type::STK_BlockPointer:
3031 case Type::STK_ObjCObjectPointer:
3032 case Type::STK_MemberPointer: return std::string{kwNullptr};
3033
3034 case Type::STK_Bool: return std::string{kwFalse};
3035
3036 case Type::STK_Integral:
3037 case Type::STK_Floating:
3038 if(const auto* bt = type->getAs<BuiltinType>()) {
3039 switch(bt->getKind()) {
3040 // Type::STK_Integral
3041 case BuiltinType::Char_U:
3042 case BuiltinType::UChar:
3043 case BuiltinType::Char_S:
3044 case BuiltinType::SChar: return "'\\0'";
3045 case BuiltinType::WChar_U:
3046 case BuiltinType::WChar_S: return "L'\\0'";
3047 case BuiltinType::Char16: return "u'\\0'";
3048 case BuiltinType::Char32: return "U'\\0'";
3049 // Type::STK_Floating
3050 case BuiltinType::Half:
3051 case BuiltinType::Float: return "0.0f";
3052 case BuiltinType::Double: return "0.0";
3053 default: break;
3054 }
3055 }
3056
3057 break;
3058
3059 case Type::STK_FloatingComplex:
3060 case Type::STK_IntegralComplex:
3061 if(const auto* complexType = type->getAs<ComplexType>()) {
3062 return GetValueOfValueInit(complexType->getElementType());
3063 }
3064
3065 break;
3066
3067 case Type::STK_FixedPoint: Error("STK_FixedPoint is not implemented"); break;
3068 }
3069
3070 } else if(const auto* tt = dyn_cast_or_null<ConstantArrayType>(t.getTypePtrOrNull())) {
3071 const auto& elementType{tt->getElementType()};
3072 const std::string elementTypeInitValue{GetValueOfValueInit(elementType)};
3073
3074 return FillConstantArray(tt, elementTypeInitValue, uint64_t{0});
3075 }
3076
3077 return std::string{"0"sv};
3078}
3079//-----------------------------------------------------------------------------
3080

Callers

nothing calls this directly

Calls 1

ErrorFunction · 0.85

Tested by

no test coverage detected