MCPcopy Create free account
hub / github.com/beefytech/Beef / ConstantToString

Method ConstantToString

IDEHelper/Compiler/BfAutoComplete.cpp:3907–3980  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3905}
3906
3907String BfAutoComplete::ConstantToString(BfIRConstHolder* constHolder, BfTypedValue typedValue)
3908{
3909 SetAndRestoreValue<BfTypeInstance*> prevTypeInst(mModule->mCurTypeInstance, typedValue.mType->ToTypeInstance());
3910 SetAndRestoreValue<BfMethodInstance*> prevMethodInst(mModule->mCurMethodInstance, NULL);
3911
3912 BF_ASSERT(typedValue.mValue.IsConst());
3913
3914 String result;
3915 result = "(";
3916 result += mModule->TypeToString(typedValue.mType);
3917 result += ")";
3918
3919 char str[32];
3920
3921 int stringId = mModule->GetStringPoolIdx(typedValue.mValue, constHolder);
3922 if (stringId != -1)
3923 {
3924 BfStringPoolEntry* entry;
3925 if (mModule->mContext->mStringObjectIdMap.TryGetValue(stringId, &entry))
3926 {
3927 String result = "\"";
3928 result += SlashString(entry->mString, true, true, true);
3929 result += "\"";
3930 return result;
3931 }
3932 }
3933
3934 auto constant = constHolder->GetConstant(typedValue.mValue);
3935 switch (constant->mTypeCode)
3936 {
3937 case BfTypeCode_Boolean:
3938 result += StrFormat(" %s", constant->mBool ? "true" : "false");
3939 break;
3940 case BfTypeCode_UInt8:
3941 result += StrFormat(" %llu", constant->mUInt64);
3942 break;
3943 case BfTypeCode_UInt16:
3944 result += StrFormat(" %llu", constant->mUInt64);
3945 break;
3946 case BfTypeCode_UInt32:
3947 result += StrFormat(" %llu", constant->mUInt64);
3948 break;
3949 case BfTypeCode_UInt64:
3950 result += StrFormat(" %llu", constant->mUInt64);
3951 break;
3952 case BfTypeCode_Int8:
3953 result += StrFormat(" %lld", constant->mInt64);
3954 break;
3955 case BfTypeCode_Int16:
3956 result += StrFormat(" %lld", constant->mInt64);
3957 break;
3958 case BfTypeCode_Int32:
3959 result += StrFormat(" %lld", constant->mInt64);
3960 break;
3961 case BfTypeCode_Int64:
3962 result += StrFormat(" %lld", constant->mInt64);
3963 break;
3964 case BfTypeCode_Float:

Callers 1

LoadFieldMethod · 0.80

Calls 6

GetStringPoolIdxMethod · 0.80
TryGetValueMethod · 0.80
ToTypeInstanceMethod · 0.45
IsConstMethod · 0.45
TypeToStringMethod · 0.45
GetConstantMethod · 0.45

Tested by

no test coverage detected