1*f4a2713aSLionel Sambuc //===--- NSAPI.cpp - NSFoundation APIs ------------------------------------===// 2*f4a2713aSLionel Sambuc // 3*f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4*f4a2713aSLionel Sambuc // 5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7*f4a2713aSLionel Sambuc // 8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9*f4a2713aSLionel Sambuc 10*f4a2713aSLionel Sambuc #include "clang/AST/NSAPI.h" 11*f4a2713aSLionel Sambuc #include "clang/AST/ASTContext.h" 12*f4a2713aSLionel Sambuc #include "clang/AST/Expr.h" 13*f4a2713aSLionel Sambuc 14*f4a2713aSLionel Sambuc using namespace clang; 15*f4a2713aSLionel Sambuc 16*f4a2713aSLionel Sambuc NSAPI::NSAPI(ASTContext &ctx) 17*f4a2713aSLionel Sambuc : Ctx(ctx), ClassIds(), BOOLId(0), NSIntegerId(0), NSUIntegerId(0), 18*f4a2713aSLionel Sambuc NSASCIIStringEncodingId(0), NSUTF8StringEncodingId(0) { 19*f4a2713aSLionel Sambuc } 20*f4a2713aSLionel Sambuc 21*f4a2713aSLionel Sambuc IdentifierInfo *NSAPI::getNSClassId(NSClassIdKindKind K) const { 22*f4a2713aSLionel Sambuc static const char *ClassName[NumClassIds] = { 23*f4a2713aSLionel Sambuc "NSObject", 24*f4a2713aSLionel Sambuc "NSString", 25*f4a2713aSLionel Sambuc "NSArray", 26*f4a2713aSLionel Sambuc "NSMutableArray", 27*f4a2713aSLionel Sambuc "NSDictionary", 28*f4a2713aSLionel Sambuc "NSMutableDictionary", 29*f4a2713aSLionel Sambuc "NSNumber" 30*f4a2713aSLionel Sambuc }; 31*f4a2713aSLionel Sambuc 32*f4a2713aSLionel Sambuc if (!ClassIds[K]) 33*f4a2713aSLionel Sambuc return (ClassIds[K] = &Ctx.Idents.get(ClassName[K])); 34*f4a2713aSLionel Sambuc 35*f4a2713aSLionel Sambuc return ClassIds[K]; 36*f4a2713aSLionel Sambuc } 37*f4a2713aSLionel Sambuc 38*f4a2713aSLionel Sambuc Selector NSAPI::getNSStringSelector(NSStringMethodKind MK) const { 39*f4a2713aSLionel Sambuc if (NSStringSelectors[MK].isNull()) { 40*f4a2713aSLionel Sambuc Selector Sel; 41*f4a2713aSLionel Sambuc switch (MK) { 42*f4a2713aSLionel Sambuc case NSStr_stringWithString: 43*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("stringWithString")); 44*f4a2713aSLionel Sambuc break; 45*f4a2713aSLionel Sambuc case NSStr_stringWithUTF8String: 46*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector( 47*f4a2713aSLionel Sambuc &Ctx.Idents.get("stringWithUTF8String")); 48*f4a2713aSLionel Sambuc break; 49*f4a2713aSLionel Sambuc case NSStr_stringWithCStringEncoding: { 50*f4a2713aSLionel Sambuc IdentifierInfo *KeyIdents[] = { 51*f4a2713aSLionel Sambuc &Ctx.Idents.get("stringWithCString"), 52*f4a2713aSLionel Sambuc &Ctx.Idents.get("encoding") 53*f4a2713aSLionel Sambuc }; 54*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getSelector(2, KeyIdents); 55*f4a2713aSLionel Sambuc break; 56*f4a2713aSLionel Sambuc } 57*f4a2713aSLionel Sambuc case NSStr_stringWithCString: 58*f4a2713aSLionel Sambuc Sel= Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("stringWithCString")); 59*f4a2713aSLionel Sambuc break; 60*f4a2713aSLionel Sambuc case NSStr_initWithString: 61*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("initWithString")); 62*f4a2713aSLionel Sambuc break; 63*f4a2713aSLionel Sambuc } 64*f4a2713aSLionel Sambuc return (NSStringSelectors[MK] = Sel); 65*f4a2713aSLionel Sambuc } 66*f4a2713aSLionel Sambuc 67*f4a2713aSLionel Sambuc return NSStringSelectors[MK]; 68*f4a2713aSLionel Sambuc } 69*f4a2713aSLionel Sambuc 70*f4a2713aSLionel Sambuc Optional<NSAPI::NSStringMethodKind> 71*f4a2713aSLionel Sambuc NSAPI::getNSStringMethodKind(Selector Sel) const { 72*f4a2713aSLionel Sambuc for (unsigned i = 0; i != NumNSStringMethods; ++i) { 73*f4a2713aSLionel Sambuc NSStringMethodKind MK = NSStringMethodKind(i); 74*f4a2713aSLionel Sambuc if (Sel == getNSStringSelector(MK)) 75*f4a2713aSLionel Sambuc return MK; 76*f4a2713aSLionel Sambuc } 77*f4a2713aSLionel Sambuc 78*f4a2713aSLionel Sambuc return None; 79*f4a2713aSLionel Sambuc } 80*f4a2713aSLionel Sambuc 81*f4a2713aSLionel Sambuc Selector NSAPI::getNSArraySelector(NSArrayMethodKind MK) const { 82*f4a2713aSLionel Sambuc if (NSArraySelectors[MK].isNull()) { 83*f4a2713aSLionel Sambuc Selector Sel; 84*f4a2713aSLionel Sambuc switch (MK) { 85*f4a2713aSLionel Sambuc case NSArr_array: 86*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getNullarySelector(&Ctx.Idents.get("array")); 87*f4a2713aSLionel Sambuc break; 88*f4a2713aSLionel Sambuc case NSArr_arrayWithArray: 89*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("arrayWithArray")); 90*f4a2713aSLionel Sambuc break; 91*f4a2713aSLionel Sambuc case NSArr_arrayWithObject: 92*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("arrayWithObject")); 93*f4a2713aSLionel Sambuc break; 94*f4a2713aSLionel Sambuc case NSArr_arrayWithObjects: 95*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("arrayWithObjects")); 96*f4a2713aSLionel Sambuc break; 97*f4a2713aSLionel Sambuc case NSArr_arrayWithObjectsCount: { 98*f4a2713aSLionel Sambuc IdentifierInfo *KeyIdents[] = { 99*f4a2713aSLionel Sambuc &Ctx.Idents.get("arrayWithObjects"), 100*f4a2713aSLionel Sambuc &Ctx.Idents.get("count") 101*f4a2713aSLionel Sambuc }; 102*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getSelector(2, KeyIdents); 103*f4a2713aSLionel Sambuc break; 104*f4a2713aSLionel Sambuc } 105*f4a2713aSLionel Sambuc case NSArr_initWithArray: 106*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("initWithArray")); 107*f4a2713aSLionel Sambuc break; 108*f4a2713aSLionel Sambuc case NSArr_initWithObjects: 109*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("initWithObjects")); 110*f4a2713aSLionel Sambuc break; 111*f4a2713aSLionel Sambuc case NSArr_objectAtIndex: 112*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("objectAtIndex")); 113*f4a2713aSLionel Sambuc break; 114*f4a2713aSLionel Sambuc case NSMutableArr_replaceObjectAtIndex: { 115*f4a2713aSLionel Sambuc IdentifierInfo *KeyIdents[] = { 116*f4a2713aSLionel Sambuc &Ctx.Idents.get("replaceObjectAtIndex"), 117*f4a2713aSLionel Sambuc &Ctx.Idents.get("withObject") 118*f4a2713aSLionel Sambuc }; 119*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getSelector(2, KeyIdents); 120*f4a2713aSLionel Sambuc break; 121*f4a2713aSLionel Sambuc } 122*f4a2713aSLionel Sambuc } 123*f4a2713aSLionel Sambuc return (NSArraySelectors[MK] = Sel); 124*f4a2713aSLionel Sambuc } 125*f4a2713aSLionel Sambuc 126*f4a2713aSLionel Sambuc return NSArraySelectors[MK]; 127*f4a2713aSLionel Sambuc } 128*f4a2713aSLionel Sambuc 129*f4a2713aSLionel Sambuc Optional<NSAPI::NSArrayMethodKind> NSAPI::getNSArrayMethodKind(Selector Sel) { 130*f4a2713aSLionel Sambuc for (unsigned i = 0; i != NumNSArrayMethods; ++i) { 131*f4a2713aSLionel Sambuc NSArrayMethodKind MK = NSArrayMethodKind(i); 132*f4a2713aSLionel Sambuc if (Sel == getNSArraySelector(MK)) 133*f4a2713aSLionel Sambuc return MK; 134*f4a2713aSLionel Sambuc } 135*f4a2713aSLionel Sambuc 136*f4a2713aSLionel Sambuc return None; 137*f4a2713aSLionel Sambuc } 138*f4a2713aSLionel Sambuc 139*f4a2713aSLionel Sambuc Selector NSAPI::getNSDictionarySelector( 140*f4a2713aSLionel Sambuc NSDictionaryMethodKind MK) const { 141*f4a2713aSLionel Sambuc if (NSDictionarySelectors[MK].isNull()) { 142*f4a2713aSLionel Sambuc Selector Sel; 143*f4a2713aSLionel Sambuc switch (MK) { 144*f4a2713aSLionel Sambuc case NSDict_dictionary: 145*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getNullarySelector(&Ctx.Idents.get("dictionary")); 146*f4a2713aSLionel Sambuc break; 147*f4a2713aSLionel Sambuc case NSDict_dictionaryWithDictionary: 148*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector( 149*f4a2713aSLionel Sambuc &Ctx.Idents.get("dictionaryWithDictionary")); 150*f4a2713aSLionel Sambuc break; 151*f4a2713aSLionel Sambuc case NSDict_dictionaryWithObjectForKey: { 152*f4a2713aSLionel Sambuc IdentifierInfo *KeyIdents[] = { 153*f4a2713aSLionel Sambuc &Ctx.Idents.get("dictionaryWithObject"), 154*f4a2713aSLionel Sambuc &Ctx.Idents.get("forKey") 155*f4a2713aSLionel Sambuc }; 156*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getSelector(2, KeyIdents); 157*f4a2713aSLionel Sambuc break; 158*f4a2713aSLionel Sambuc } 159*f4a2713aSLionel Sambuc case NSDict_dictionaryWithObjectsForKeys: { 160*f4a2713aSLionel Sambuc IdentifierInfo *KeyIdents[] = { 161*f4a2713aSLionel Sambuc &Ctx.Idents.get("dictionaryWithObjects"), 162*f4a2713aSLionel Sambuc &Ctx.Idents.get("forKeys") 163*f4a2713aSLionel Sambuc }; 164*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getSelector(2, KeyIdents); 165*f4a2713aSLionel Sambuc break; 166*f4a2713aSLionel Sambuc } 167*f4a2713aSLionel Sambuc case NSDict_dictionaryWithObjectsForKeysCount: { 168*f4a2713aSLionel Sambuc IdentifierInfo *KeyIdents[] = { 169*f4a2713aSLionel Sambuc &Ctx.Idents.get("dictionaryWithObjects"), 170*f4a2713aSLionel Sambuc &Ctx.Idents.get("forKeys"), 171*f4a2713aSLionel Sambuc &Ctx.Idents.get("count") 172*f4a2713aSLionel Sambuc }; 173*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getSelector(3, KeyIdents); 174*f4a2713aSLionel Sambuc break; 175*f4a2713aSLionel Sambuc } 176*f4a2713aSLionel Sambuc case NSDict_dictionaryWithObjectsAndKeys: 177*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector( 178*f4a2713aSLionel Sambuc &Ctx.Idents.get("dictionaryWithObjectsAndKeys")); 179*f4a2713aSLionel Sambuc break; 180*f4a2713aSLionel Sambuc case NSDict_initWithDictionary: 181*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector( 182*f4a2713aSLionel Sambuc &Ctx.Idents.get("initWithDictionary")); 183*f4a2713aSLionel Sambuc break; 184*f4a2713aSLionel Sambuc case NSDict_initWithObjectsAndKeys: 185*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector( 186*f4a2713aSLionel Sambuc &Ctx.Idents.get("initWithObjectsAndKeys")); 187*f4a2713aSLionel Sambuc break; 188*f4a2713aSLionel Sambuc case NSDict_initWithObjectsForKeys: { 189*f4a2713aSLionel Sambuc IdentifierInfo *KeyIdents[] = { 190*f4a2713aSLionel Sambuc &Ctx.Idents.get("initWithObjects"), 191*f4a2713aSLionel Sambuc &Ctx.Idents.get("forKeys") 192*f4a2713aSLionel Sambuc }; 193*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getSelector(2, KeyIdents); 194*f4a2713aSLionel Sambuc break; 195*f4a2713aSLionel Sambuc } 196*f4a2713aSLionel Sambuc case NSDict_objectForKey: 197*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("objectForKey")); 198*f4a2713aSLionel Sambuc break; 199*f4a2713aSLionel Sambuc case NSMutableDict_setObjectForKey: { 200*f4a2713aSLionel Sambuc IdentifierInfo *KeyIdents[] = { 201*f4a2713aSLionel Sambuc &Ctx.Idents.get("setObject"), 202*f4a2713aSLionel Sambuc &Ctx.Idents.get("forKey") 203*f4a2713aSLionel Sambuc }; 204*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getSelector(2, KeyIdents); 205*f4a2713aSLionel Sambuc break; 206*f4a2713aSLionel Sambuc } 207*f4a2713aSLionel Sambuc } 208*f4a2713aSLionel Sambuc return (NSDictionarySelectors[MK] = Sel); 209*f4a2713aSLionel Sambuc } 210*f4a2713aSLionel Sambuc 211*f4a2713aSLionel Sambuc return NSDictionarySelectors[MK]; 212*f4a2713aSLionel Sambuc } 213*f4a2713aSLionel Sambuc 214*f4a2713aSLionel Sambuc Optional<NSAPI::NSDictionaryMethodKind> 215*f4a2713aSLionel Sambuc NSAPI::getNSDictionaryMethodKind(Selector Sel) { 216*f4a2713aSLionel Sambuc for (unsigned i = 0; i != NumNSDictionaryMethods; ++i) { 217*f4a2713aSLionel Sambuc NSDictionaryMethodKind MK = NSDictionaryMethodKind(i); 218*f4a2713aSLionel Sambuc if (Sel == getNSDictionarySelector(MK)) 219*f4a2713aSLionel Sambuc return MK; 220*f4a2713aSLionel Sambuc } 221*f4a2713aSLionel Sambuc 222*f4a2713aSLionel Sambuc return None; 223*f4a2713aSLionel Sambuc } 224*f4a2713aSLionel Sambuc 225*f4a2713aSLionel Sambuc Selector NSAPI::getNSNumberLiteralSelector(NSNumberLiteralMethodKind MK, 226*f4a2713aSLionel Sambuc bool Instance) const { 227*f4a2713aSLionel Sambuc static const char *ClassSelectorName[NumNSNumberLiteralMethods] = { 228*f4a2713aSLionel Sambuc "numberWithChar", 229*f4a2713aSLionel Sambuc "numberWithUnsignedChar", 230*f4a2713aSLionel Sambuc "numberWithShort", 231*f4a2713aSLionel Sambuc "numberWithUnsignedShort", 232*f4a2713aSLionel Sambuc "numberWithInt", 233*f4a2713aSLionel Sambuc "numberWithUnsignedInt", 234*f4a2713aSLionel Sambuc "numberWithLong", 235*f4a2713aSLionel Sambuc "numberWithUnsignedLong", 236*f4a2713aSLionel Sambuc "numberWithLongLong", 237*f4a2713aSLionel Sambuc "numberWithUnsignedLongLong", 238*f4a2713aSLionel Sambuc "numberWithFloat", 239*f4a2713aSLionel Sambuc "numberWithDouble", 240*f4a2713aSLionel Sambuc "numberWithBool", 241*f4a2713aSLionel Sambuc "numberWithInteger", 242*f4a2713aSLionel Sambuc "numberWithUnsignedInteger" 243*f4a2713aSLionel Sambuc }; 244*f4a2713aSLionel Sambuc static const char *InstanceSelectorName[NumNSNumberLiteralMethods] = { 245*f4a2713aSLionel Sambuc "initWithChar", 246*f4a2713aSLionel Sambuc "initWithUnsignedChar", 247*f4a2713aSLionel Sambuc "initWithShort", 248*f4a2713aSLionel Sambuc "initWithUnsignedShort", 249*f4a2713aSLionel Sambuc "initWithInt", 250*f4a2713aSLionel Sambuc "initWithUnsignedInt", 251*f4a2713aSLionel Sambuc "initWithLong", 252*f4a2713aSLionel Sambuc "initWithUnsignedLong", 253*f4a2713aSLionel Sambuc "initWithLongLong", 254*f4a2713aSLionel Sambuc "initWithUnsignedLongLong", 255*f4a2713aSLionel Sambuc "initWithFloat", 256*f4a2713aSLionel Sambuc "initWithDouble", 257*f4a2713aSLionel Sambuc "initWithBool", 258*f4a2713aSLionel Sambuc "initWithInteger", 259*f4a2713aSLionel Sambuc "initWithUnsignedInteger" 260*f4a2713aSLionel Sambuc }; 261*f4a2713aSLionel Sambuc 262*f4a2713aSLionel Sambuc Selector *Sels; 263*f4a2713aSLionel Sambuc const char **Names; 264*f4a2713aSLionel Sambuc if (Instance) { 265*f4a2713aSLionel Sambuc Sels = NSNumberInstanceSelectors; 266*f4a2713aSLionel Sambuc Names = InstanceSelectorName; 267*f4a2713aSLionel Sambuc } else { 268*f4a2713aSLionel Sambuc Sels = NSNumberClassSelectors; 269*f4a2713aSLionel Sambuc Names = ClassSelectorName; 270*f4a2713aSLionel Sambuc } 271*f4a2713aSLionel Sambuc 272*f4a2713aSLionel Sambuc if (Sels[MK].isNull()) 273*f4a2713aSLionel Sambuc Sels[MK] = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get(Names[MK])); 274*f4a2713aSLionel Sambuc return Sels[MK]; 275*f4a2713aSLionel Sambuc } 276*f4a2713aSLionel Sambuc 277*f4a2713aSLionel Sambuc Optional<NSAPI::NSNumberLiteralMethodKind> 278*f4a2713aSLionel Sambuc NSAPI::getNSNumberLiteralMethodKind(Selector Sel) const { 279*f4a2713aSLionel Sambuc for (unsigned i = 0; i != NumNSNumberLiteralMethods; ++i) { 280*f4a2713aSLionel Sambuc NSNumberLiteralMethodKind MK = NSNumberLiteralMethodKind(i); 281*f4a2713aSLionel Sambuc if (isNSNumberLiteralSelector(MK, Sel)) 282*f4a2713aSLionel Sambuc return MK; 283*f4a2713aSLionel Sambuc } 284*f4a2713aSLionel Sambuc 285*f4a2713aSLionel Sambuc return None; 286*f4a2713aSLionel Sambuc } 287*f4a2713aSLionel Sambuc 288*f4a2713aSLionel Sambuc Optional<NSAPI::NSNumberLiteralMethodKind> 289*f4a2713aSLionel Sambuc NSAPI::getNSNumberFactoryMethodKind(QualType T) const { 290*f4a2713aSLionel Sambuc const BuiltinType *BT = T->getAs<BuiltinType>(); 291*f4a2713aSLionel Sambuc if (!BT) 292*f4a2713aSLionel Sambuc return None; 293*f4a2713aSLionel Sambuc 294*f4a2713aSLionel Sambuc const TypedefType *TDT = T->getAs<TypedefType>(); 295*f4a2713aSLionel Sambuc if (TDT) { 296*f4a2713aSLionel Sambuc QualType TDTTy = QualType(TDT, 0); 297*f4a2713aSLionel Sambuc if (isObjCBOOLType(TDTTy)) 298*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithBool; 299*f4a2713aSLionel Sambuc if (isObjCNSIntegerType(TDTTy)) 300*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithInteger; 301*f4a2713aSLionel Sambuc if (isObjCNSUIntegerType(TDTTy)) 302*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithUnsignedInteger; 303*f4a2713aSLionel Sambuc } 304*f4a2713aSLionel Sambuc 305*f4a2713aSLionel Sambuc switch (BT->getKind()) { 306*f4a2713aSLionel Sambuc case BuiltinType::Char_S: 307*f4a2713aSLionel Sambuc case BuiltinType::SChar: 308*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithChar; 309*f4a2713aSLionel Sambuc case BuiltinType::Char_U: 310*f4a2713aSLionel Sambuc case BuiltinType::UChar: 311*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithUnsignedChar; 312*f4a2713aSLionel Sambuc case BuiltinType::Short: 313*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithShort; 314*f4a2713aSLionel Sambuc case BuiltinType::UShort: 315*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithUnsignedShort; 316*f4a2713aSLionel Sambuc case BuiltinType::Int: 317*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithInt; 318*f4a2713aSLionel Sambuc case BuiltinType::UInt: 319*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithUnsignedInt; 320*f4a2713aSLionel Sambuc case BuiltinType::Long: 321*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithLong; 322*f4a2713aSLionel Sambuc case BuiltinType::ULong: 323*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithUnsignedLong; 324*f4a2713aSLionel Sambuc case BuiltinType::LongLong: 325*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithLongLong; 326*f4a2713aSLionel Sambuc case BuiltinType::ULongLong: 327*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithUnsignedLongLong; 328*f4a2713aSLionel Sambuc case BuiltinType::Float: 329*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithFloat; 330*f4a2713aSLionel Sambuc case BuiltinType::Double: 331*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithDouble; 332*f4a2713aSLionel Sambuc case BuiltinType::Bool: 333*f4a2713aSLionel Sambuc return NSAPI::NSNumberWithBool; 334*f4a2713aSLionel Sambuc 335*f4a2713aSLionel Sambuc case BuiltinType::Void: 336*f4a2713aSLionel Sambuc case BuiltinType::WChar_U: 337*f4a2713aSLionel Sambuc case BuiltinType::WChar_S: 338*f4a2713aSLionel Sambuc case BuiltinType::Char16: 339*f4a2713aSLionel Sambuc case BuiltinType::Char32: 340*f4a2713aSLionel Sambuc case BuiltinType::Int128: 341*f4a2713aSLionel Sambuc case BuiltinType::LongDouble: 342*f4a2713aSLionel Sambuc case BuiltinType::UInt128: 343*f4a2713aSLionel Sambuc case BuiltinType::NullPtr: 344*f4a2713aSLionel Sambuc case BuiltinType::ObjCClass: 345*f4a2713aSLionel Sambuc case BuiltinType::ObjCId: 346*f4a2713aSLionel Sambuc case BuiltinType::ObjCSel: 347*f4a2713aSLionel Sambuc case BuiltinType::OCLImage1d: 348*f4a2713aSLionel Sambuc case BuiltinType::OCLImage1dArray: 349*f4a2713aSLionel Sambuc case BuiltinType::OCLImage1dBuffer: 350*f4a2713aSLionel Sambuc case BuiltinType::OCLImage2d: 351*f4a2713aSLionel Sambuc case BuiltinType::OCLImage2dArray: 352*f4a2713aSLionel Sambuc case BuiltinType::OCLImage3d: 353*f4a2713aSLionel Sambuc case BuiltinType::OCLSampler: 354*f4a2713aSLionel Sambuc case BuiltinType::OCLEvent: 355*f4a2713aSLionel Sambuc case BuiltinType::BoundMember: 356*f4a2713aSLionel Sambuc case BuiltinType::Dependent: 357*f4a2713aSLionel Sambuc case BuiltinType::Overload: 358*f4a2713aSLionel Sambuc case BuiltinType::UnknownAny: 359*f4a2713aSLionel Sambuc case BuiltinType::ARCUnbridgedCast: 360*f4a2713aSLionel Sambuc case BuiltinType::Half: 361*f4a2713aSLionel Sambuc case BuiltinType::PseudoObject: 362*f4a2713aSLionel Sambuc case BuiltinType::BuiltinFn: 363*f4a2713aSLionel Sambuc break; 364*f4a2713aSLionel Sambuc } 365*f4a2713aSLionel Sambuc 366*f4a2713aSLionel Sambuc return None; 367*f4a2713aSLionel Sambuc } 368*f4a2713aSLionel Sambuc 369*f4a2713aSLionel Sambuc /// \brief Returns true if \param T is a typedef of "BOOL" in objective-c. 370*f4a2713aSLionel Sambuc bool NSAPI::isObjCBOOLType(QualType T) const { 371*f4a2713aSLionel Sambuc return isObjCTypedef(T, "BOOL", BOOLId); 372*f4a2713aSLionel Sambuc } 373*f4a2713aSLionel Sambuc /// \brief Returns true if \param T is a typedef of "NSInteger" in objective-c. 374*f4a2713aSLionel Sambuc bool NSAPI::isObjCNSIntegerType(QualType T) const { 375*f4a2713aSLionel Sambuc return isObjCTypedef(T, "NSInteger", NSIntegerId); 376*f4a2713aSLionel Sambuc } 377*f4a2713aSLionel Sambuc /// \brief Returns true if \param T is a typedef of "NSUInteger" in objective-c. 378*f4a2713aSLionel Sambuc bool NSAPI::isObjCNSUIntegerType(QualType T) const { 379*f4a2713aSLionel Sambuc return isObjCTypedef(T, "NSUInteger", NSUIntegerId); 380*f4a2713aSLionel Sambuc } 381*f4a2713aSLionel Sambuc 382*f4a2713aSLionel Sambuc bool NSAPI::isObjCTypedef(QualType T, 383*f4a2713aSLionel Sambuc StringRef name, IdentifierInfo *&II) const { 384*f4a2713aSLionel Sambuc if (!Ctx.getLangOpts().ObjC1) 385*f4a2713aSLionel Sambuc return false; 386*f4a2713aSLionel Sambuc if (T.isNull()) 387*f4a2713aSLionel Sambuc return false; 388*f4a2713aSLionel Sambuc 389*f4a2713aSLionel Sambuc if (!II) 390*f4a2713aSLionel Sambuc II = &Ctx.Idents.get(name); 391*f4a2713aSLionel Sambuc 392*f4a2713aSLionel Sambuc while (const TypedefType *TDT = T->getAs<TypedefType>()) { 393*f4a2713aSLionel Sambuc if (TDT->getDecl()->getDeclName().getAsIdentifierInfo() == II) 394*f4a2713aSLionel Sambuc return true; 395*f4a2713aSLionel Sambuc T = TDT->desugar(); 396*f4a2713aSLionel Sambuc } 397*f4a2713aSLionel Sambuc 398*f4a2713aSLionel Sambuc return false; 399*f4a2713aSLionel Sambuc } 400*f4a2713aSLionel Sambuc 401*f4a2713aSLionel Sambuc bool NSAPI::isObjCEnumerator(const Expr *E, 402*f4a2713aSLionel Sambuc StringRef name, IdentifierInfo *&II) const { 403*f4a2713aSLionel Sambuc if (!Ctx.getLangOpts().ObjC1) 404*f4a2713aSLionel Sambuc return false; 405*f4a2713aSLionel Sambuc if (!E) 406*f4a2713aSLionel Sambuc return false; 407*f4a2713aSLionel Sambuc 408*f4a2713aSLionel Sambuc if (!II) 409*f4a2713aSLionel Sambuc II = &Ctx.Idents.get(name); 410*f4a2713aSLionel Sambuc 411*f4a2713aSLionel Sambuc if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts())) 412*f4a2713aSLionel Sambuc if (const EnumConstantDecl * 413*f4a2713aSLionel Sambuc EnumD = dyn_cast_or_null<EnumConstantDecl>(DRE->getDecl())) 414*f4a2713aSLionel Sambuc return EnumD->getIdentifier() == II; 415*f4a2713aSLionel Sambuc 416*f4a2713aSLionel Sambuc return false; 417*f4a2713aSLionel Sambuc } 418*f4a2713aSLionel Sambuc 419*f4a2713aSLionel Sambuc Selector NSAPI::getOrInitSelector(ArrayRef<StringRef> Ids, 420*f4a2713aSLionel Sambuc Selector &Sel) const { 421*f4a2713aSLionel Sambuc if (Sel.isNull()) { 422*f4a2713aSLionel Sambuc SmallVector<IdentifierInfo *, 4> Idents; 423*f4a2713aSLionel Sambuc for (ArrayRef<StringRef>::const_iterator 424*f4a2713aSLionel Sambuc I = Ids.begin(), E = Ids.end(); I != E; ++I) 425*f4a2713aSLionel Sambuc Idents.push_back(&Ctx.Idents.get(*I)); 426*f4a2713aSLionel Sambuc Sel = Ctx.Selectors.getSelector(Idents.size(), Idents.data()); 427*f4a2713aSLionel Sambuc } 428*f4a2713aSLionel Sambuc return Sel; 429*f4a2713aSLionel Sambuc } 430