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

Method EncodeAttributeData

IDEHelper/Compiler/BfModule.cpp:5849–6022  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5847}
5848
5849void BfModule::EncodeAttributeData(BfTypeInstance* typeInstance, BfType* argType, BfIRValue arg, SizedArrayImpl<uint8>& data, Dictionary<int, int>& usedStringIdMap)
5850{
5851#define PUSH_INT8(val) data.push_back((uint8)val)
5852#define PUSH_INT16(val) { data.push_back(val & 0xFF); data.push_back((val >> 8) & 0xFF); }
5853#define PUSH_INT32(val) { data.push_back(val & 0xFF); data.push_back((val >> 8) & 0xFF); data.push_back((val >> 16) & 0xFF); data.push_back((val >> 24) & 0xFF); }
5854#define PUSH_INT64(val) { data.push_back(val & 0xFF); data.push_back((val >> 8) & 0xFF); data.push_back((val >> 16) & 0xFF); data.push_back((val >> 24) & 0xFF); \
5855 data.push_back((val >> 32) & 0xFF); data.push_back((val >> 40) & 0xFF); data.push_back((val >> 48) & 0xFF); data.push_back((val >> 56) & 0xFF); }
5856
5857 auto constant = typeInstance->mConstHolder->GetConstant(arg);
5858 bool handled = false;
5859
5860 if (constant == NULL)
5861 {
5862 Fail(StrFormat("Unhandled attribute constant data in '%s'", TypeToString(typeInstance).c_str()));
5863 return;
5864 }
5865
5866 if (argType->IsObject())
5867 {
5868 if ((argType->IsInstanceOf(mCompiler->mStringTypeDef)) || (argType == mContext->mBfObjectType))
5869 {
5870 if (constant->mTypeCode == BfTypeCode_StringId)
5871 {
5872 int stringId = constant->mInt32;
5873 int* orderedIdPtr;
5874 if (usedStringIdMap.TryAdd(stringId, NULL, &orderedIdPtr))
5875 {
5876 *orderedIdPtr = (int)usedStringIdMap.size() - 1;
5877 }
5878
5879 GetStringObjectValue(stringId, true, true);
5880 PUSH_INT8(0xFF); // String
5881 PUSH_INT32(*orderedIdPtr);
5882 return;
5883 }
5884 }
5885 }
5886
5887 if (argType->IsPointer())
5888 {
5889 if (argType->GetUnderlyingType() == GetPrimitiveType(BfTypeCode_Char8))
5890 {
5891 if (constant->mTypeCode == BfTypeCode_StringId)
5892 {
5893 int stringId = constant->mInt32;
5894 int* orderedIdPtr;
5895 if (usedStringIdMap.TryAdd(stringId, NULL, &orderedIdPtr))
5896 {
5897 *orderedIdPtr = (int)usedStringIdMap.size() - 1;
5898 }
5899
5900 GetStringObjectValue(stringId, true, true);
5901 PUSH_INT8(0xFF); // String
5902 PUSH_INT32(*orderedIdPtr);
5903 return;
5904 }
5905 }
5906 }

Callers

nothing calls this directly

Calls 15

FailFunction · 0.85
TypeToStringFunction · 0.85
BfIRValueClass · 0.85
FindTypeByIdMethod · 0.80
GetConstantMethod · 0.45
c_strMethod · 0.45
IsObjectMethod · 0.45
IsInstanceOfMethod · 0.45
TryAddMethod · 0.45
sizeMethod · 0.45
IsPointerMethod · 0.45
GetUnderlyingTypeMethod · 0.45

Tested by

no test coverage detected