File indexing completed on 2026-05-10 08:36:38
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_AST_NSAPI_H
0010 #define LLVM_CLANG_AST_NSAPI_H
0011
0012 #include "clang/Basic/IdentifierTable.h"
0013 #include "llvm/ADT/ArrayRef.h"
0014 #include <optional>
0015
0016 namespace clang {
0017 class ASTContext;
0018 class ObjCInterfaceDecl;
0019 class QualType;
0020 class Expr;
0021
0022
0023 class NSAPI {
0024 public:
0025 explicit NSAPI(ASTContext &Ctx);
0026
0027 ASTContext &getASTContext() const { return Ctx; }
0028
0029 enum NSClassIdKindKind {
0030 ClassId_NSObject,
0031 ClassId_NSString,
0032 ClassId_NSArray,
0033 ClassId_NSMutableArray,
0034 ClassId_NSDictionary,
0035 ClassId_NSMutableDictionary,
0036 ClassId_NSNumber,
0037 ClassId_NSMutableSet,
0038 ClassId_NSMutableOrderedSet,
0039 ClassId_NSValue
0040 };
0041 static const unsigned NumClassIds = 10;
0042
0043 enum NSStringMethodKind {
0044 NSStr_stringWithString,
0045 NSStr_stringWithUTF8String,
0046 NSStr_stringWithCStringEncoding,
0047 NSStr_stringWithCString,
0048 NSStr_initWithString,
0049 NSStr_initWithUTF8String
0050 };
0051 static const unsigned NumNSStringMethods = 6;
0052
0053 IdentifierInfo *getNSClassId(NSClassIdKindKind K) const;
0054
0055
0056 Selector getNSStringSelector(NSStringMethodKind MK) const;
0057
0058
0059
0060 bool isNSUTF8StringEncodingConstant(const Expr *E) const {
0061 return isObjCEnumerator(E, "NSUTF8StringEncoding", NSUTF8StringEncodingId);
0062 }
0063
0064
0065
0066 bool isNSASCIIStringEncodingConstant(const Expr *E) const {
0067 return isObjCEnumerator(E, "NSASCIIStringEncoding",NSASCIIStringEncodingId);
0068 }
0069
0070
0071
0072 enum NSArrayMethodKind {
0073 NSArr_array,
0074 NSArr_arrayWithArray,
0075 NSArr_arrayWithObject,
0076 NSArr_arrayWithObjects,
0077 NSArr_arrayWithObjectsCount,
0078 NSArr_initWithArray,
0079 NSArr_initWithObjects,
0080 NSArr_objectAtIndex,
0081 NSMutableArr_replaceObjectAtIndex,
0082 NSMutableArr_addObject,
0083 NSMutableArr_insertObjectAtIndex,
0084 NSMutableArr_setObjectAtIndexedSubscript
0085 };
0086 static const unsigned NumNSArrayMethods = 12;
0087
0088
0089 Selector getNSArraySelector(NSArrayMethodKind MK) const;
0090
0091
0092 std::optional<NSArrayMethodKind> getNSArrayMethodKind(Selector Sel);
0093
0094
0095
0096 enum NSDictionaryMethodKind {
0097 NSDict_dictionary,
0098 NSDict_dictionaryWithDictionary,
0099 NSDict_dictionaryWithObjectForKey,
0100 NSDict_dictionaryWithObjectsForKeys,
0101 NSDict_dictionaryWithObjectsForKeysCount,
0102 NSDict_dictionaryWithObjectsAndKeys,
0103 NSDict_initWithDictionary,
0104 NSDict_initWithObjectsAndKeys,
0105 NSDict_initWithObjectsForKeys,
0106 NSDict_objectForKey,
0107 NSMutableDict_setObjectForKey,
0108 NSMutableDict_setObjectForKeyedSubscript,
0109 NSMutableDict_setValueForKey
0110 };
0111 static const unsigned NumNSDictionaryMethods = 13;
0112
0113
0114 Selector getNSDictionarySelector(NSDictionaryMethodKind MK) const;
0115
0116
0117 std::optional<NSDictionaryMethodKind> getNSDictionaryMethodKind(Selector Sel);
0118
0119
0120
0121 enum NSSetMethodKind {
0122 NSMutableSet_addObject,
0123 NSOrderedSet_insertObjectAtIndex,
0124 NSOrderedSet_setObjectAtIndex,
0125 NSOrderedSet_setObjectAtIndexedSubscript,
0126 NSOrderedSet_replaceObjectAtIndexWithObject
0127 };
0128 static const unsigned NumNSSetMethods = 5;
0129
0130
0131 Selector getNSSetSelector(NSSetMethodKind MK) const;
0132
0133
0134 std::optional<NSSetMethodKind> getNSSetMethodKind(Selector Sel);
0135
0136
0137 Selector getObjectForKeyedSubscriptSelector() const {
0138 return getOrInitSelector(StringRef("objectForKeyedSubscript"),
0139 objectForKeyedSubscriptSel);
0140 }
0141
0142
0143 Selector getObjectAtIndexedSubscriptSelector() const {
0144 return getOrInitSelector(StringRef("objectAtIndexedSubscript"),
0145 objectAtIndexedSubscriptSel);
0146 }
0147
0148
0149 Selector getSetObjectForKeyedSubscriptSelector() const {
0150 StringRef Ids[] = { "setObject", "forKeyedSubscript" };
0151 return getOrInitSelector(Ids, setObjectForKeyedSubscriptSel);
0152 }
0153
0154
0155 Selector getSetObjectAtIndexedSubscriptSelector() const {
0156 StringRef Ids[] = { "setObject", "atIndexedSubscript" };
0157 return getOrInitSelector(Ids, setObjectAtIndexedSubscriptSel);
0158 }
0159
0160
0161 Selector getIsEqualSelector() const {
0162 return getOrInitSelector(StringRef("isEqual"), isEqualSel);
0163 }
0164
0165 Selector getNewSelector() const {
0166 return getOrInitNullarySelector("new", NewSel);
0167 }
0168
0169 Selector getInitSelector() const {
0170 return getOrInitNullarySelector("init", InitSel);
0171 }
0172
0173
0174 enum NSNumberLiteralMethodKind {
0175 NSNumberWithChar,
0176 NSNumberWithUnsignedChar,
0177 NSNumberWithShort,
0178 NSNumberWithUnsignedShort,
0179 NSNumberWithInt,
0180 NSNumberWithUnsignedInt,
0181 NSNumberWithLong,
0182 NSNumberWithUnsignedLong,
0183 NSNumberWithLongLong,
0184 NSNumberWithUnsignedLongLong,
0185 NSNumberWithFloat,
0186 NSNumberWithDouble,
0187 NSNumberWithBool,
0188 NSNumberWithInteger,
0189 NSNumberWithUnsignedInteger
0190 };
0191 static const unsigned NumNSNumberLiteralMethods = 15;
0192
0193
0194
0195
0196 Selector getNSNumberLiteralSelector(NSNumberLiteralMethodKind MK,
0197 bool Instance) const;
0198
0199 bool isNSNumberLiteralSelector(NSNumberLiteralMethodKind MK,
0200 Selector Sel) const {
0201 return Sel == getNSNumberLiteralSelector(MK, false) ||
0202 Sel == getNSNumberLiteralSelector(MK, true);
0203 }
0204
0205
0206 std::optional<NSNumberLiteralMethodKind>
0207 getNSNumberLiteralMethodKind(Selector Sel) const;
0208
0209
0210
0211 std::optional<NSNumberLiteralMethodKind>
0212 getNSNumberFactoryMethodKind(QualType T) const;
0213
0214
0215 bool isObjCBOOLType(QualType T) const;
0216
0217 bool isObjCNSIntegerType(QualType T) const;
0218
0219 bool isObjCNSUIntegerType(QualType T) const;
0220
0221
0222 StringRef GetNSIntegralKind(QualType T) const;
0223
0224
0225 bool isMacroDefined(StringRef Id) const;
0226
0227
0228 bool isSubclassOfNSClass(ObjCInterfaceDecl *InterfaceDecl,
0229 NSClassIdKindKind NSClassKind) const;
0230
0231 private:
0232 bool isObjCTypedef(QualType T, StringRef name, IdentifierInfo *&II) const;
0233 bool isObjCEnumerator(const Expr *E,
0234 StringRef name, IdentifierInfo *&II) const;
0235 Selector getOrInitSelector(ArrayRef<StringRef> Ids, Selector &Sel) const;
0236 Selector getOrInitNullarySelector(StringRef Id, Selector &Sel) const;
0237
0238 ASTContext &Ctx;
0239
0240 mutable IdentifierInfo *ClassIds[NumClassIds];
0241
0242 mutable Selector NSStringSelectors[NumNSStringMethods];
0243
0244
0245 mutable Selector NSArraySelectors[NumNSArrayMethods];
0246
0247
0248 mutable Selector NSDictionarySelectors[NumNSDictionaryMethods];
0249
0250
0251 mutable Selector NSSetSelectors[NumNSSetMethods];
0252
0253
0254 mutable Selector NSNumberClassSelectors[NumNSNumberLiteralMethods];
0255 mutable Selector NSNumberInstanceSelectors[NumNSNumberLiteralMethods];
0256
0257 mutable Selector objectForKeyedSubscriptSel, objectAtIndexedSubscriptSel,
0258 setObjectForKeyedSubscriptSel,setObjectAtIndexedSubscriptSel,
0259 isEqualSel, InitSel, NewSel;
0260
0261 mutable IdentifierInfo *BOOLId, *NSIntegerId, *NSUIntegerId;
0262 mutable IdentifierInfo *NSASCIIStringEncodingId, *NSUTF8StringEncodingId;
0263 };
0264
0265 }
0266
0267 #endif