NSAPI.h revision ebcb57a8d298862c65043e88b2429591ab3c58d3
1//===--- NSAPI.h - NSFoundation APIs ----------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef LLVM_CLANG_AST_NSAPI_H 11#define LLVM_CLANG_AST_NSAPI_H 12 13#include "clang/Basic/IdentifierTable.h" 14#include "llvm/ADT/Optional.h" 15 16namespace clang { 17 class ASTContext; 18 class QualType; 19 20// \brief Provides info and caches identifiers/selectors for NSFoundation API. 21class NSAPI { 22public: 23 explicit NSAPI(ASTContext &Ctx); 24 25 ASTContext &getASTContext() const { return Ctx; } 26 27 enum NSClassIdKindKind { 28 ClassId_NSString, 29 ClassId_NSArray, 30 ClassId_NSMutableArray, 31 ClassId_NSDictionary, 32 ClassId_NSMutableDictionary, 33 ClassId_NSNumber 34 }; 35 static const unsigned NumClassIds = 6; 36 37 enum NSStringMethodKind { 38 NSStr_stringWithString, 39 NSStr_initWithString 40 }; 41 static const unsigned NumNSStringMethods = 2; 42 43 IdentifierInfo *getNSClassId(NSClassIdKindKind K) const; 44 45 /// \brief The Objective-C NSString selectors. 46 Selector getNSStringSelector(NSStringMethodKind MK) const; 47 48 /// \brief Enumerates the NSArray methods used to generate literals. 49 enum NSArrayMethodKind { 50 NSArr_array, 51 NSArr_arrayWithArray, 52 NSArr_arrayWithObject, 53 NSArr_arrayWithObjects, 54 NSArr_arrayWithObjectsCount, 55 NSArr_initWithArray, 56 NSArr_initWithObjects, 57 NSArr_objectAtIndex, 58 NSMutableArr_replaceObjectAtIndex 59 }; 60 static const unsigned NumNSArrayMethods = 9; 61 62 /// \brief The Objective-C NSArray selectors. 63 Selector getNSArraySelector(NSArrayMethodKind MK) const; 64 65 /// \brief Return NSArrayMethodKind if \arg Sel is such a selector. 66 llvm::Optional<NSArrayMethodKind> getNSArrayMethodKind(Selector Sel); 67 68 /// \brief Enumerates the NSDictionary methods used to generate literals. 69 enum NSDictionaryMethodKind { 70 NSDict_dictionary, 71 NSDict_dictionaryWithDictionary, 72 NSDict_dictionaryWithObjectForKey, 73 NSDict_dictionaryWithObjectsForKeys, 74 NSDict_dictionaryWithObjectsForKeysCount, 75 NSDict_dictionaryWithObjectsAndKeys, 76 NSDict_initWithDictionary, 77 NSDict_initWithObjectsAndKeys, 78 NSDict_objectForKey, 79 NSMutableDict_setObjectForKey 80 }; 81 static const unsigned NumNSDictionaryMethods = 10; 82 83 /// \brief The Objective-C NSDictionary selectors. 84 Selector getNSDictionarySelector(NSDictionaryMethodKind MK) const; 85 86 /// \brief Return NSDictionaryMethodKind if \arg Sel is such a selector. 87 llvm::Optional<NSDictionaryMethodKind> 88 getNSDictionaryMethodKind(Selector Sel); 89 90 /// \brief Enumerates the NSNumber methods used to generate literals. 91 enum NSNumberLiteralMethodKind { 92 NSNumberWithChar, 93 NSNumberWithUnsignedChar, 94 NSNumberWithShort, 95 NSNumberWithUnsignedShort, 96 NSNumberWithInt, 97 NSNumberWithUnsignedInt, 98 NSNumberWithLong, 99 NSNumberWithUnsignedLong, 100 NSNumberWithLongLong, 101 NSNumberWithUnsignedLongLong, 102 NSNumberWithFloat, 103 NSNumberWithDouble, 104 NSNumberWithBool, 105 NSNumberWithInteger, 106 NSNumberWithUnsignedInteger 107 }; 108 static const unsigned NumNSNumberLiteralMethods = 15; 109 110 /// \brief The Objective-C NSNumber selectors used to create NSNumber literals. 111 /// \param Instance if true it will return the selector for the init* method 112 /// otherwise it will return the selector for the number* method. 113 Selector getNSNumberLiteralSelector(NSNumberLiteralMethodKind MK, 114 bool Instance) const; 115 116 bool isNSNumberLiteralSelector(NSNumberLiteralMethodKind MK, 117 Selector Sel) const { 118 return Sel == getNSNumberLiteralSelector(MK, false) || 119 Sel == getNSNumberLiteralSelector(MK, true); 120 } 121 122 /// \brief Return NSNumberLiteralMethodKind if \arg Sel is such a selector. 123 llvm::Optional<NSNumberLiteralMethodKind> 124 getNSNumberLiteralMethodKind(Selector Sel) const; 125 126 /// \brief Determine the appropriate NSNumber factory method kind for a 127 /// literal of the given type. 128 static llvm::Optional<NSNumberLiteralMethodKind> 129 getNSNumberFactoryMethodKind(QualType T); 130 131private: 132 ASTContext &Ctx; 133 134 mutable IdentifierInfo *ClassIds[NumClassIds]; 135 136 mutable Selector NSStringSelectors[NumNSStringMethods]; 137 138 /// \brief The selectors for Objective-C NSArray methods. 139 mutable Selector NSArraySelectors[NumNSArrayMethods]; 140 141 /// \brief The selectors for Objective-C NSDictionary methods. 142 mutable Selector NSDictionarySelectors[NumNSDictionaryMethods]; 143 144 /// \brief The Objective-C NSNumber selectors used to create NSNumber literals. 145 mutable Selector NSNumberClassSelectors[NumNSNumberLiteralMethods]; 146 mutable Selector NSNumberInstanceSelectors[NumNSNumberLiteralMethods]; 147}; 148 149} // end namespace clang 150 151#endif // LLVM_CLANG_AST_NSAPI_H 152