| 5847 | } |
| 5848 | |
| 5849 | void 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 | } |
nothing calls this directly
no test coverage detected