15#ifndef LLVM_CLANG_LIB_CODEGEN_CGOBJCMACCONSTANTLITERALUTIL_H
16#define LLVM_CLANG_LIB_CODEGEN_CGOBJCMACCONSTANTLITERALUTIL_H
21#include "llvm/ADT/APFloat.h"
22#include "llvm/ADT/APSInt.h"
23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/DenseMapInfo.h"
25#include "llvm/ADT/STLExtras.h"
26#include "llvm/Support/ConvertUTF.h"
33class NSConstantNumberMapInfo {
35 enum class MapInfoType {
47 explicit NSConstantNumberMapInfo(MapInfoType I = MapInfoType::Empty)
48 : InfoType(I), QType(),
Int(),
Float(0.0) {}
50 bool isEmpty()
const {
return InfoType == MapInfoType::Empty; }
54 : InfoType(MapInfoType::Int), QType(QT), Int(
V), Float(0.0) {}
56 : InfoType(MapInfoType::Float), QType(QT), Int(), Float(
V) {}
59 assert(!isEmpty() &&
"Cannot hash empty map info!");
61 unsigned QTypeHash = llvm::DenseMapInfo<QualType>::getHashValue(QType);
63 if (InfoType == MapInfoType::Int)
64 return llvm::detail::combineHashValue((
unsigned)Int.getZExtValue(),
67 assert(InfoType == MapInfoType::Float);
68 return llvm::detail::combineHashValue(
69 (
unsigned)Float.bitcastToAPInt().getZExtValue(), QTypeHash);
72 bool operator==(
const NSConstantNumberMapInfo &RHS)
const {
73 if (InfoType != RHS.InfoType || QType != RHS.QType)
80 if (InfoType == MapInfoType::Int)
81 return llvm::APSInt::isSameValue(Int, RHS.Int);
83 assert(InfoType == MapInfoType::Float);
86 return Float.bitwiseIsEqual(RHS.Float);
101 ArrayRef<std::pair<llvm::Constant *, llvm::Constant *>> KeysAndObjects,
108 bool SortKeysByUTF16 =
true) {
110 uint64_t const NumElements = KeysAndObjects.size();
113 Elements.reserve(NumElements);
117 std::iota(ElementIndicies.begin(), ElementIndicies.end(), 0);
142 KeysUTF8.reserve(NumElements);
144 for (
size_t I = 0; I < NumElements; ++I) {
149 StringRef KS = SL->getString()->getString();
150 KeysUTF8.push_back(KS);
151 if (!SortKeysByUTF16)
154 Dst.resize(KS.size());
155 const llvm::UTF8 *SrcPtr =
156 reinterpret_cast<const llvm::UTF8 *
>(KS.data());
157 llvm::UTF16 *DstPtr = Dst.data();
158 llvm::ConvertUTF8toUTF16(&SrcPtr, SrcPtr + KS.size(), &DstPtr,
159 DstPtr + Dst.size(), llvm::strictConversion);
161 Dst.truncate(DstPtr - Dst.data());
165 llvm::stable_sort(ElementIndicies, [O, SortKeysByUTF16, &KeysUTF8,
166 &KeysUTF16](
size_t LI,
size_t RI) {
177 return KeysUTF8[LI] < KeysUTF8[RI];
179 llvm_unreachable(
"Unexpected `NSDictionaryBuilder::Options given");
183 for (
auto &Idx : ElementIndicies) {
184 Elements.push_back(KeysAndObjects[Idx]);
204using namespace clang::CodeGen::CGObjCMacConstantLiteralUtil;
C Language Family Type Representation.
NSConstantNumberMapInfo(CanQualType QT, const llvm::APFloat &V)
NSConstantNumberMapInfo(CanQualType QT, const llvm::APSInt &V)
unsigned getHashValue() const
bool operator==(const NSConstantNumberMapInfo &RHS) const
NSDictionaryBuilder(const ObjCDictionaryLiteral *E, ArrayRef< std::pair< llvm::Constant *, llvm::Constant * > > KeysAndObjects, const Options O=Options::Sorted, bool SortKeysByUTF16=true)
uint64_t getNumElements() const
SmallVectorImpl< std::pair< llvm::Constant *, llvm::Constant * > > & getElements()
Options getOptions() const
This represents one expression.
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCDictionaryElement getKeyValueElement(unsigned Index) const
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
U cast(CodeGen::Address addr)
Diagnostic wrappers for TextAPI types for error reporting.
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
Expr * Key
The key for the dictionary element.
static unsigned getHashValue(const NSConstantNumberMapInfo &S)
static bool isEqual(const NSConstantNumberMapInfo &LHS, const NSConstantNumberMapInfo &RHS)