Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/AST/NSAPI.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- NSAPI.cpp - NSFoundation APIs ------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "clang/AST/NSAPI.h"
10
#include "clang/AST/ASTContext.h"
11
#include "clang/AST/DeclObjC.h"
12
#include "clang/AST/Expr.h"
13
#include "llvm/ADT/StringSwitch.h"
14
15
using namespace clang;
16
17
NSAPI::NSAPI(ASTContext &ctx)
18
  : Ctx(ctx), ClassIds(), BOOLId(nullptr), NSIntegerId(nullptr),
19
    NSUIntegerId(nullptr), NSASCIIStringEncodingId(nullptr),
20
5.07k
    NSUTF8StringEncodingId(nullptr) {}
21
22
37.2k
IdentifierInfo *NSAPI::getNSClassId(NSClassIdKindKind K) const {
23
37.2k
  static const char *ClassName[NumClassIds] = {
24
37.2k
    "NSObject",
25
37.2k
    "NSString",
26
37.2k
    "NSArray",
27
37.2k
    "NSMutableArray",
28
37.2k
    "NSDictionary",
29
37.2k
    "NSMutableDictionary",
30
37.2k
    "NSNumber",
31
37.2k
    "NSMutableSet",
32
37.2k
    "NSMutableOrderedSet",
33
37.2k
    "NSValue"
34
37.2k
  };
35
37.2k
36
37.2k
  if (!ClassIds[K])
37
6.25k
    return (ClassIds[K] = &Ctx.Idents.get(ClassName[K]));
38
30.9k
39
30.9k
  return ClassIds[K];
40
30.9k
}
41
42
41
Selector NSAPI::getNSStringSelector(NSStringMethodKind MK) const {
43
41
  if (NSStringSelectors[MK].isNull()) {
44
12
    Selector Sel;
45
12
    switch (MK) {
46
12
    case NSStr_stringWithString:
47
4
      Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("stringWithString"));
48
4
      break;
49
12
    case NSStr_stringWithUTF8String:
50
1
      Sel = Ctx.Selectors.getUnarySelector(
51
1
                                       &Ctx.Idents.get("stringWithUTF8String"));
52
1
      break;
53
12
    case NSStr_initWithUTF8String:
54
1
      Sel = Ctx.Selectors.getUnarySelector(
55
1
                                       &Ctx.Idents.get("initWithUTF8String"));
56
1
      break;
57
12
    case NSStr_stringWithCStringEncoding: {
58
1
      IdentifierInfo *KeyIdents[] = {
59
1
        &Ctx.Idents.get("stringWithCString"),
60
1
        &Ctx.Idents.get("encoding")
61
1
      };
62
1
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
63
1
      break;
64
12
    }
65
12
    case NSStr_stringWithCString:
66
1
      Sel= Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("stringWithCString"));
67
1
      break;
68
12
    case NSStr_initWithString:
69
4
      Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("initWithString"));
70
4
      break;
71
12
    }
72
12
    return (NSStringSelectors[MK] = Sel);
73
12
  }
74
29
75
29
  return NSStringSelectors[MK];
76
29
}
77
78
Optional<NSAPI::NSStringMethodKind>
79
0
NSAPI::getNSStringMethodKind(Selector Sel) const {
80
0
  for (unsigned i = 0; i != NumNSStringMethods; ++i) {
81
0
    NSStringMethodKind MK = NSStringMethodKind(i);
82
0
    if (Sel == getNSStringSelector(MK))
83
0
      return MK;
84
0
  }
85
0
86
0
  return None;
87
0
}
88
89
2.01k
Selector NSAPI::getNSArraySelector(NSArrayMethodKind MK) const {
90
2.01k
  if (NSArraySelectors[MK].isNull()) {
91
665
    Selector Sel;
92
665
    switch (MK) {
93
665
    case NSArr_array:
94
53
      Sel = Ctx.Selectors.getNullarySelector(&Ctx.Idents.get("array"));
95
53
      break;
96
665
    case NSArr_arrayWithArray:
97
53
      Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("arrayWithArray"));
98
53
      break;
99
665
    case NSArr_arrayWithObject:
100
53
      Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("arrayWithObject"));
101
53
      break;
102
665
    case NSArr_arrayWithObjects:
103
53
      Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("arrayWithObjects"));
104
53
      break;
105
665
    case NSArr_arrayWithObjectsCount: {
106
113
      IdentifierInfo *KeyIdents[] = {
107
113
        &Ctx.Idents.get("arrayWithObjects"),
108
113
        &Ctx.Idents.get("count")
109
113
      };
110
113
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
111
113
      break;
112
665
    }
113
665
    case NSArr_initWithArray:
114
50
      Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("initWithArray"));
115
50
      break;
116
665
    case NSArr_initWithObjects:
117
51
      Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("initWithObjects"));
118
51
      break;
119
665
    case NSArr_objectAtIndex:
120
55
      Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("objectAtIndex"));
121
55
      break;
122
665
    case NSMutableArr_replaceObjectAtIndex: {
123
52
      IdentifierInfo *KeyIdents[] = {
124
52
        &Ctx.Idents.get("replaceObjectAtIndex"),
125
52
        &Ctx.Idents.get("withObject")
126
52
      };
127
52
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
128
52
      break;
129
665
    }
130
665
    case NSMutableArr_addObject:
131
46
      Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("addObject"));
132
46
      break;
133
665
    case NSMutableArr_insertObjectAtIndex: {
134
43
      IdentifierInfo *KeyIdents[] = {
135
43
        &Ctx.Idents.get("insertObject"),
136
43
        &Ctx.Idents.get("atIndex")
137
43
      };
138
43
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
139
43
      break;
140
665
    }
141
665
    case NSMutableArr_setObjectAtIndexedSubscript: {
142
43
      IdentifierInfo *KeyIdents[] = {
143
43
        &Ctx.Idents.get("setObject"),
144
43
        &Ctx.Idents.get("atIndexedSubscript")
145
43
      };
146
43
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
147
43
      break;
148
665
    }
149
665
    }
150
665
    return (NSArraySelectors[MK] = Sel);
151
665
  }
152
1.34k
153
1.34k
  return NSArraySelectors[MK];
154
1.34k
}
155
156
158
Optional<NSAPI::NSArrayMethodKind> NSAPI::getNSArrayMethodKind(Selector Sel) {
157
1.83k
  for (unsigned i = 0; i != NumNSArrayMethods; 
++i1.67k
) {
158
1.76k
    NSArrayMethodKind MK = NSArrayMethodKind(i);
159
1.76k
    if (Sel == getNSArraySelector(MK))
160
89
      return MK;
161
1.76k
  }
162
158
163
158
  
return None69
;
164
158
}
165
166
Selector NSAPI::getNSDictionarySelector(
167
1.87k
                                       NSDictionaryMethodKind MK) const {
168
1.87k
  if (NSDictionarySelectors[MK].isNull()) {
169
515
    Selector Sel;
170
515
    switch (MK) {
171
515
    case NSDict_dictionary:
172
38
      Sel = Ctx.Selectors.getNullarySelector(&Ctx.Idents.get("dictionary"));
173
38
      break;
174
515
    case NSDict_dictionaryWithDictionary:
175
38
      Sel = Ctx.Selectors.getUnarySelector(
176
38
                                   &Ctx.Idents.get("dictionaryWithDictionary"));
177
38
      break;
178
515
    case NSDict_dictionaryWithObjectForKey: {
179
38
      IdentifierInfo *KeyIdents[] = {
180
38
        &Ctx.Idents.get("dictionaryWithObject"),
181
38
        &Ctx.Idents.get("forKey")
182
38
      };
183
38
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
184
38
      break;
185
515
    }
186
515
    case NSDict_dictionaryWithObjectsForKeys: {
187
37
      IdentifierInfo *KeyIdents[] = {
188
37
        &Ctx.Idents.get("dictionaryWithObjects"),
189
37
        &Ctx.Idents.get("forKeys")
190
37
      };
191
37
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
192
37
      break;
193
515
    }
194
515
    case NSDict_dictionaryWithObjectsForKeysCount: {
195
82
      IdentifierInfo *KeyIdents[] = {
196
82
        &Ctx.Idents.get("dictionaryWithObjects"),
197
82
        &Ctx.Idents.get("forKeys"),
198
82
        &Ctx.Idents.get("count")
199
82
      };
200
82
      Sel = Ctx.Selectors.getSelector(3, KeyIdents);
201
82
      break;
202
515
    }
203
515
    case NSDict_dictionaryWithObjectsAndKeys:
204
37
      Sel = Ctx.Selectors.getUnarySelector(
205
37
                               &Ctx.Idents.get("dictionaryWithObjectsAndKeys"));
206
37
      break;
207
515
    case NSDict_initWithDictionary:
208
35
      Sel = Ctx.Selectors.getUnarySelector(
209
35
                                         &Ctx.Idents.get("initWithDictionary"));
210
35
      break;
211
515
    case NSDict_initWithObjectsAndKeys:
212
37
      Sel = Ctx.Selectors.getUnarySelector(
213
37
                                     &Ctx.Idents.get("initWithObjectsAndKeys"));
214
37
      break;
215
515
    case NSDict_initWithObjectsForKeys: {
216
37
      IdentifierInfo *KeyIdents[] = {
217
37
        &Ctx.Idents.get("initWithObjects"),
218
37
        &Ctx.Idents.get("forKeys")
219
37
      };
220
37
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
221
37
      break;
222
515
    }
223
515
    case NSDict_objectForKey:
224
40
      Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("objectForKey"));
225
40
      break;
226
515
    case NSMutableDict_setObjectForKey: {
227
37
      IdentifierInfo *KeyIdents[] = {
228
37
        &Ctx.Idents.get("setObject"),
229
37
        &Ctx.Idents.get("forKey")
230
37
      };
231
37
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
232
37
      break;
233
515
    }
234
515
    case NSMutableDict_setObjectForKeyedSubscript: {
235
30
      IdentifierInfo *KeyIdents[] = {
236
30
        &Ctx.Idents.get("setObject"),
237
30
        &Ctx.Idents.get("forKeyedSubscript")
238
30
      };
239
30
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
240
30
      break;
241
515
    }
242
515
    case NSMutableDict_setValueForKey: {
243
29
      IdentifierInfo *KeyIdents[] = {
244
29
        &Ctx.Idents.get("setValue"),
245
29
        &Ctx.Idents.get("forKey")
246
29
      };
247
29
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
248
29
      break;
249
515
    }
250
515
    }
251
515
    return (NSDictionarySelectors[MK] = Sel);
252
515
  }
253
1.35k
254
1.35k
  return NSDictionarySelectors[MK];
255
1.35k
}
256
257
Optional<NSAPI::NSDictionaryMethodKind>
258
138
NSAPI::getNSDictionaryMethodKind(Selector Sel) {
259
1.73k
  for (unsigned i = 0; i != NumNSDictionaryMethods; 
++i1.59k
) {
260
1.67k
    NSDictionaryMethodKind MK = NSDictionaryMethodKind(i);
261
1.67k
    if (Sel == getNSDictionarySelector(MK))
262
78
      return MK;
263
1.67k
  }
264
138
265
138
  
return None60
;
266
138
}
267
268
186
Selector NSAPI::getNSSetSelector(NSSetMethodKind MK) const {
269
186
  if (NSSetSelectors[MK].isNull()) {
270
15
    Selector Sel;
271
15
    switch (MK) {
272
15
    case NSMutableSet_addObject:
273
3
      Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("addObject"));
274
3
      break;
275
15
    case NSOrderedSet_insertObjectAtIndex: {
276
3
      IdentifierInfo *KeyIdents[] = {
277
3
        &Ctx.Idents.get("insertObject"),
278
3
        &Ctx.Idents.get("atIndex")
279
3
      };
280
3
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
281
3
      break;
282
15
    }
283
15
    case NSOrderedSet_setObjectAtIndex: {
284
3
      IdentifierInfo *KeyIdents[] = {
285
3
        &Ctx.Idents.get("setObject"),
286
3
        &Ctx.Idents.get("atIndex")
287
3
      };
288
3
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
289
3
      break;
290
15
    }
291
15
    case NSOrderedSet_setObjectAtIndexedSubscript: {
292
3
      IdentifierInfo *KeyIdents[] = {
293
3
        &Ctx.Idents.get("setObject"),
294
3
        &Ctx.Idents.get("atIndexedSubscript")
295
3
      };
296
3
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
297
3
      break;
298
15
    }
299
15
    case NSOrderedSet_replaceObjectAtIndexWithObject: {
300
3
      IdentifierInfo *KeyIdents[] = {
301
3
        &Ctx.Idents.get("replaceObjectAtIndex"),
302
3
        &Ctx.Idents.get("withObject")
303
3
      };
304
3
      Sel = Ctx.Selectors.getSelector(2, KeyIdents);
305
3
      break;
306
15
    }
307
15
    }
308
15
    return (NSSetSelectors[MK] = Sel);
309
15
  }
310
171
311
171
  return NSSetSelectors[MK];
312
171
}
313
314
Optional<NSAPI::NSSetMethodKind>
315
56
NSAPI::getNSSetMethodKind(Selector Sel) {
316
216
  for (unsigned i = 0; i != NumNSSetMethods; 
++i160
) {
317
186
    NSSetMethodKind MK = NSSetMethodKind(i);
318
186
    if (Sel == getNSSetSelector(MK))
319
26
      return MK;
320
186
  }
321
56
322
56
  
return None30
;
323
56
}
324
325
Selector NSAPI::getNSNumberLiteralSelector(NSNumberLiteralMethodKind MK,
326
8.64k
                                           bool Instance) const {
327
8.64k
  static const char *ClassSelectorName[NumNSNumberLiteralMethods] = {
328
8.64k
    "numberWithChar",
329
8.64k
    "numberWithUnsignedChar",
330
8.64k
    "numberWithShort",
331
8.64k
    "numberWithUnsignedShort",
332
8.64k
    "numberWithInt",
333
8.64k
    "numberWithUnsignedInt",
334
8.64k
    "numberWithLong",
335
8.64k
    "numberWithUnsignedLong",
336
8.64k
    "numberWithLongLong",
337
8.64k
    "numberWithUnsignedLongLong",
338
8.64k
    "numberWithFloat",
339
8.64k
    "numberWithDouble",
340
8.64k
    "numberWithBool",
341
8.64k
    "numberWithInteger",
342
8.64k
    "numberWithUnsignedInteger"
343
8.64k
  };
344
8.64k
  static const char *InstanceSelectorName[NumNSNumberLiteralMethods] = {
345
8.64k
    "initWithChar",
346
8.64k
    "initWithUnsignedChar",
347
8.64k
    "initWithShort",
348
8.64k
    "initWithUnsignedShort",
349
8.64k
    "initWithInt",
350
8.64k
    "initWithUnsignedInt",
351
8.64k
    "initWithLong",
352
8.64k
    "initWithUnsignedLong",
353
8.64k
    "initWithLongLong",
354
8.64k
    "initWithUnsignedLongLong",
355
8.64k
    "initWithFloat",
356
8.64k
    "initWithDouble",
357
8.64k
    "initWithBool",
358
8.64k
    "initWithInteger",
359
8.64k
    "initWithUnsignedInteger"
360
8.64k
  };
361
8.64k
362
8.64k
  Selector *Sels;
363
8.64k
  const char **Names;
364
8.64k
  if (Instance) {
365
3.94k
    Sels = NSNumberInstanceSelectors;
366
3.94k
    Names = InstanceSelectorName;
367
4.70k
  } else {
368
4.70k
    Sels = NSNumberClassSelectors;
369
4.70k
    Names = ClassSelectorName;
370
4.70k
  }
371
8.64k
372
8.64k
  if (Sels[MK].isNull())
373
252
    Sels[MK] = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get(Names[MK]));
374
8.64k
  return Sels[MK];
375
8.64k
}
376
377
Optional<NSAPI::NSNumberLiteralMethodKind>
378
593
NSAPI::getNSNumberLiteralMethodKind(Selector Sel) const {
379
4.46k
  for (unsigned i = 0; i != NumNSNumberLiteralMethods; 
++i3.86k
) {
380
4.46k
    NSNumberLiteralMethodKind MK = NSNumberLiteralMethodKind(i);
381
4.46k
    if (isNSNumberLiteralSelector(MK, Sel))
382
593
      return MK;
383
4.46k
  }
384
593
385
593
  
return None0
;
386
593
}
387
388
Optional<NSAPI::NSNumberLiteralMethodKind>
389
509
NSAPI::getNSNumberFactoryMethodKind(QualType T) const {
390
509
  const BuiltinType *BT = T->getAs<BuiltinType>();
391
509
  if (!BT)
392
0
    return None;
393
509
394
509
  const TypedefType *TDT = T->getAs<TypedefType>();
395
509
  if (TDT) {
396
13
    QualType TDTTy = QualType(TDT, 0);
397
13
    if (isObjCBOOLType(TDTTy))
398
7
      return NSAPI::NSNumberWithBool;
399
6
    if (isObjCNSIntegerType(TDTTy))
400
5
      return NSAPI::NSNumberWithInteger;
401
1
    if (isObjCNSUIntegerType(TDTTy))
402
1
      return NSAPI::NSNumberWithUnsignedInteger;
403
496
  }
404
496
405
496
  switch (BT->getKind()) {
406
496
  case BuiltinType::Char_S:
407
22
  case BuiltinType::SChar:
408
22
    return NSAPI::NSNumberWithChar;
409
22
  case BuiltinType::Char_U:
410
0
  case BuiltinType::UChar:
411
0
    return NSAPI::NSNumberWithUnsignedChar;
412
0
  case BuiltinType::Short:
413
0
    return NSAPI::NSNumberWithShort;
414
0
  case BuiltinType::UShort:
415
0
    return NSAPI::NSNumberWithUnsignedShort;
416
225
  case BuiltinType::Int:
417
225
    return NSAPI::NSNumberWithInt;
418
43
  case BuiltinType::UInt:
419
43
    return NSAPI::NSNumberWithUnsignedInt;
420
22
  case BuiltinType::Long:
421
22
    return NSAPI::NSNumberWithLong;
422
16
  case BuiltinType::ULong:
423
16
    return NSAPI::NSNumberWithUnsignedLong;
424
21
  case BuiltinType::LongLong:
425
21
    return NSAPI::NSNumberWithLongLong;
426
15
  case BuiltinType::ULongLong:
427
15
    return NSAPI::NSNumberWithUnsignedLongLong;
428
31
  case BuiltinType::Float:
429
31
    return NSAPI::NSNumberWithFloat;
430
50
  case BuiltinType::Double:
431
50
    return NSAPI::NSNumberWithDouble;
432
49
  case BuiltinType::Bool:
433
49
    return NSAPI::NSNumberWithBool;
434
0
435
2
  case BuiltinType::Void:
436
2
  case BuiltinType::WChar_U:
437
2
  case BuiltinType::WChar_S:
438
2
  case BuiltinType::Char8:
439
2
  case BuiltinType::Char16:
440
2
  case BuiltinType::Char32:
441
2
  case BuiltinType::Int128:
442
2
  case BuiltinType::LongDouble:
443
2
  case BuiltinType::ShortAccum:
444
2
  case BuiltinType::Accum:
445
2
  case BuiltinType::LongAccum:
446
2
  case BuiltinType::UShortAccum:
447
2
  case BuiltinType::UAccum:
448
2
  case BuiltinType::ULongAccum:
449
2
  case BuiltinType::ShortFract:
450
2
  case BuiltinType::Fract:
451
2
  case BuiltinType::LongFract:
452
2
  case BuiltinType::UShortFract:
453
2
  case BuiltinType::UFract:
454
2
  case BuiltinType::ULongFract:
455
2
  case BuiltinType::SatShortAccum:
456
2
  case BuiltinType::SatAccum:
457
2
  case BuiltinType::SatLongAccum:
458
2
  case BuiltinType::SatUShortAccum:
459
2
  case BuiltinType::SatUAccum:
460
2
  case BuiltinType::SatULongAccum:
461
2
  case BuiltinType::SatShortFract:
462
2
  case BuiltinType::SatFract:
463
2
  case BuiltinType::SatLongFract:
464
2
  case BuiltinType::SatUShortFract:
465
2
  case BuiltinType::SatUFract:
466
2
  case BuiltinType::SatULongFract:
467
2
  case BuiltinType::UInt128:
468
2
  case BuiltinType::Float16:
469
2
  case BuiltinType::Float128:
470
2
  case BuiltinType::NullPtr:
471
2
  case BuiltinType::ObjCClass:
472
2
  case BuiltinType::ObjCId:
473
2
  case BuiltinType::ObjCSel:
474
2
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
475
72
  case BuiltinType::Id:
476
72
#include 
"clang/Basic/OpenCLImageTypes.def"2
477
72
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
478
72
  
case BuiltinType::Id:24
479
72
#include 
"clang/Basic/OpenCLExtensionTypes.def"2
480
24
  case BuiltinType::OCLSampler:
481
2
  case BuiltinType::OCLEvent:
482
2
  case BuiltinType::OCLClkEvent:
483
2
  case BuiltinType::OCLQueue:
484
2
  case BuiltinType::OCLReserveID:
485
2
  case BuiltinType::BoundMember:
486
2
  case BuiltinType::Dependent:
487
2
  case BuiltinType::Overload:
488
2
  case BuiltinType::UnknownAny:
489
2
  case BuiltinType::ARCUnbridgedCast:
490
2
  case BuiltinType::Half:
491
2
  case BuiltinType::PseudoObject:
492
2
  case BuiltinType::BuiltinFn:
493
2
  case BuiltinType::OMPArraySection:
494
2
    break;
495
2
  }
496
2
497
2
  return None;
498
2
}
499
500
/// Returns true if \param T is a typedef of "BOOL" in objective-c.
501
1.90k
bool NSAPI::isObjCBOOLType(QualType T) const {
502
1.90k
  return isObjCTypedef(T, "BOOL", BOOLId);
503
1.90k
}
504
/// Returns true if \param T is a typedef of "NSInteger" in objective-c.
505
48
bool NSAPI::isObjCNSIntegerType(QualType T) const {
506
48
  return isObjCTypedef(T, "NSInteger", NSIntegerId);
507
48
}
508
/// Returns true if \param T is a typedef of "NSUInteger" in objective-c.
509
43
bool NSAPI::isObjCNSUIntegerType(QualType T) const {
510
43
  return isObjCTypedef(T, "NSUInteger", NSUIntegerId);
511
43
}
512
513
50
StringRef NSAPI::GetNSIntegralKind(QualType T) const {
514
50
  if (!Ctx.getLangOpts().ObjC || T.isNull())
515
0
    return StringRef();
516
50
517
50
  while (const TypedefType *TDT = T->getAs<TypedefType>()) {
518
22
    StringRef NSIntegralResust =
519
22
      llvm::StringSwitch<StringRef>(
520
22
        TDT->getDecl()->getDeclName().getAsIdentifierInfo()->getName())
521
22
    .Case("int8_t", "int8_t")
522
22
    .Case("int16_t", "int16_t")
523
22
    .Case("int32_t", "int32_t")
524
22
    .Case("NSInteger", "NSInteger")
525
22
    .Case("int64_t", "int64_t")
526
22
    .Case("uint8_t", "uint8_t")
527
22
    .Case("uint16_t", "uint16_t")
528
22
    .Case("uint32_t", "uint32_t")
529
22
    .Case("NSUInteger", "NSUInteger")
530
22
    .Case("uint64_t", "uint64_t")
531
22
    .Default(StringRef());
532
22
    if (!NSIntegralResust.empty())
533
22
      return NSIntegralResust;
534
0
    T = TDT->desugar();
535
0
  }
536
50
  
return StringRef()28
;
537
50
}
538
539
122
bool NSAPI::isMacroDefined(StringRef Id) const {
540
122
  // FIXME: Check whether the relevant module macros are visible.
541
122
  return Ctx.Idents.get(Id).hasMacroDefinition();
542
122
}
543
544
bool NSAPI::isSubclassOfNSClass(ObjCInterfaceDecl *InterfaceDecl,
545
39.1k
                                NSClassIdKindKind NSClassKind) const {
546
39.1k
  if (!InterfaceDecl) {
547
6.41k
    return false;
548
6.41k
  }
549
32.7k
550
32.7k
  IdentifierInfo *NSClassID = getNSClassId(NSClassKind);
551
32.7k
552
32.7k
  bool IsSubclass = false;
553
51.6k
  do {
554
51.6k
    IsSubclass = NSClassID == InterfaceDecl->getIdentifier();
555
51.6k
556
51.6k
    if (IsSubclass) {
557
352
      break;
558
352
    }
559
51.2k
  } while ((InterfaceDecl = InterfaceDecl->getSuperClass()));
560
32.7k
561
32.7k
  return IsSubclass;
562
32.7k
}
563
564
bool NSAPI::isObjCTypedef(QualType T,
565
1.99k
                          StringRef name, IdentifierInfo *&II) const {
566
1.99k
  if (!Ctx.getLangOpts().ObjC)
567
143
    return false;
568
1.85k
  if (T.isNull())
569
0
    return false;
570
1.85k
571
1.85k
  if (!II)
572
218
    II = &Ctx.Idents.get(name);
573
1.85k
574
2.24k
  while (const TypedefType *TDT = T->getAs<TypedefType>()) {
575
642
    if (TDT->getDecl()->getDeclName().getAsIdentifierInfo() == II)
576
248
      return true;
577
394
    T = TDT->desugar();
578
394
  }
579
1.85k
580
1.85k
  
return false1.60k
;
581
1.85k
}
582
583
bool NSAPI::isObjCEnumerator(const Expr *E,
584
7
                             StringRef name, IdentifierInfo *&II) const {
585
7
  if (!Ctx.getLangOpts().ObjC)
586
0
    return false;
587
7
  if (!E)
588
0
    return false;
589
7
590
7
  if (!II)
591
2
    II = &Ctx.Idents.get(name);
592
7
593
7
  if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts()))
594
7
    if (const EnumConstantDecl *
595
7
          EnumD = dyn_cast_or_null<EnumConstantDecl>(DRE->getDecl()))
596
5
      return EnumD->getIdentifier() == II;
597
2
598
2
  return false;
599
2
}
600
601
Selector NSAPI::getOrInitSelector(ArrayRef<StringRef> Ids,
602
149
                                  Selector &Sel) const {
603
149
  if (Sel.isNull()) {
604
15
    SmallVector<IdentifierInfo *, 4> Idents;
605
15
    for (ArrayRef<StringRef>::const_iterator
606
34
           I = Ids.begin(), E = Ids.end(); I != E; 
++I19
)
607
19
      Idents.push_back(&Ctx.Idents.get(*I));
608
15
    Sel = Ctx.Selectors.getSelector(Idents.size(), Idents.data());
609
15
  }
610
149
  return Sel;
611
149
}
612
613
4.66k
Selector NSAPI::getOrInitNullarySelector(StringRef Id, Selector &Sel) const {
614
4.66k
  if (Sel.isNull()) {
615
831
    IdentifierInfo *Ident = &Ctx.Idents.get(Id);
616
831
    Sel = Ctx.Selectors.getSelector(0, &Ident);
617
831
  }
618
4.66k
  return Sel;
619
4.66k
}