clang 20.0.0git
NSAPI.h
Go to the documentation of this file.
1//===--- NSAPI.h - NSFoundation APIs ----------------------------*- C++ -*-===//
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#ifndef LLVM_CLANG_AST_NSAPI_H
10#define LLVM_CLANG_AST_NSAPI_H
11
13#include "llvm/ADT/ArrayRef.h"
14#include <optional>
15
16namespace clang {
17 class ASTContext;
18 class ObjCInterfaceDecl;
19 class QualType;
20 class Expr;
21
22// Provides info and caches identifiers/selectors for NSFoundation API.
23class NSAPI {
24public:
25 explicit NSAPI(ASTContext &Ctx);
26
27 ASTContext &getASTContext() const { return Ctx; }
28
40 };
41 static const unsigned NumClassIds = 10;
42
50 };
51 static const unsigned NumNSStringMethods = 6;
52
54
55 /// The Objective-C NSString selectors.
57
58 /// Returns true if the expression \param E is a reference of
59 /// "NSUTF8StringEncoding" enum constant.
61 return isObjCEnumerator(E, "NSUTF8StringEncoding", NSUTF8StringEncodingId);
62 }
63
64 /// Returns true if the expression \param E is a reference of
65 /// "NSASCIIStringEncoding" enum constant.
67 return isObjCEnumerator(E, "NSASCIIStringEncoding",NSASCIIStringEncodingId);
68 }
69
70 /// Enumerates the NSArray/NSMutableArray methods used to generate
71 /// literals and to apply some checks.
85 };
86 static const unsigned NumNSArrayMethods = 12;
87
88 /// The Objective-C NSArray selectors.
90
91 /// Return NSArrayMethodKind if \p Sel is such a selector.
92 std::optional<NSArrayMethodKind> getNSArrayMethodKind(Selector Sel);
93
94 /// Enumerates the NSDictionary/NSMutableDictionary methods used
95 /// to generate literals and to apply some checks.
110 };
111 static const unsigned NumNSDictionaryMethods = 13;
112
113 /// The Objective-C NSDictionary selectors.
115
116 /// Return NSDictionaryMethodKind if \p Sel is such a selector.
117 std::optional<NSDictionaryMethodKind> getNSDictionaryMethodKind(Selector Sel);
118
119 /// Enumerates the NSMutableSet/NSOrderedSet methods used
120 /// to apply some checks.
127 };
128 static const unsigned NumNSSetMethods = 5;
129
130 /// The Objective-C NSSet selectors.
132
133 /// Return NSSetMethodKind if \p Sel is such a selector.
134 std::optional<NSSetMethodKind> getNSSetMethodKind(Selector Sel);
135
136 /// Returns selector for "objectForKeyedSubscript:".
138 return getOrInitSelector(StringRef("objectForKeyedSubscript"),
139 objectForKeyedSubscriptSel);
140 }
141
142 /// Returns selector for "objectAtIndexedSubscript:".
144 return getOrInitSelector(StringRef("objectAtIndexedSubscript"),
145 objectAtIndexedSubscriptSel);
146 }
147
148 /// Returns selector for "setObject:forKeyedSubscript".
150 StringRef Ids[] = { "setObject", "forKeyedSubscript" };
151 return getOrInitSelector(Ids, setObjectForKeyedSubscriptSel);
152 }
153
154 /// Returns selector for "setObject:atIndexedSubscript".
156 StringRef Ids[] = { "setObject", "atIndexedSubscript" };
157 return getOrInitSelector(Ids, setObjectAtIndexedSubscriptSel);
158 }
159
160 /// Returns selector for "isEqual:".
162 return getOrInitSelector(StringRef("isEqual"), isEqualSel);
163 }
164
166 return getOrInitNullarySelector("new", NewSel);
167 }
168
170 return getOrInitNullarySelector("init", InitSel);
171 }
172
173 /// Enumerates the NSNumber methods used to generate literals.
190 };
191 static const unsigned NumNSNumberLiteralMethods = 15;
192
193 /// The Objective-C NSNumber selectors used to create NSNumber literals.
194 /// \param Instance if true it will return the selector for the init* method
195 /// otherwise it will return the selector for the number* method.
197 bool Instance) const;
198
200 Selector Sel) const {
201 return Sel == getNSNumberLiteralSelector(MK, false) ||
202 Sel == getNSNumberLiteralSelector(MK, true);
203 }
204
205 /// Return NSNumberLiteralMethodKind if \p Sel is such a selector.
206 std::optional<NSNumberLiteralMethodKind>
208
209 /// Determine the appropriate NSNumber factory method kind for a
210 /// literal of the given type.
211 std::optional<NSNumberLiteralMethodKind>
213
214 /// Returns true if \param T is a typedef of "BOOL" in objective-c.
215 bool isObjCBOOLType(QualType T) const;
216 /// Returns true if \param T is a typedef of "NSInteger" in objective-c.
217 bool isObjCNSIntegerType(QualType T) const;
218 /// Returns true if \param T is a typedef of "NSUInteger" in objective-c.
219 bool isObjCNSUIntegerType(QualType T) const;
220 /// Returns one of NSIntegral typedef names if \param T is a typedef
221 /// of that name in objective-c.
222 StringRef GetNSIntegralKind(QualType T) const;
223
224 /// Returns \c true if \p Id is currently defined as a macro.
225 bool isMacroDefined(StringRef Id) const;
226
227 /// Returns \c true if \p InterfaceDecl is subclass of \p NSClassKind
228 bool isSubclassOfNSClass(ObjCInterfaceDecl *InterfaceDecl,
229 NSClassIdKindKind NSClassKind) const;
230
231private:
232 bool isObjCTypedef(QualType T, StringRef name, IdentifierInfo *&II) const;
233 bool isObjCEnumerator(const Expr *E,
234 StringRef name, IdentifierInfo *&II) const;
235 Selector getOrInitSelector(ArrayRef<StringRef> Ids, Selector &Sel) const;
236 Selector getOrInitNullarySelector(StringRef Id, Selector &Sel) const;
237
238 ASTContext &Ctx;
239
240 mutable IdentifierInfo *ClassIds[NumClassIds];
241
242 mutable Selector NSStringSelectors[NumNSStringMethods];
243
244 /// The selectors for Objective-C NSArray methods.
245 mutable Selector NSArraySelectors[NumNSArrayMethods];
246
247 /// The selectors for Objective-C NSDictionary methods.
248 mutable Selector NSDictionarySelectors[NumNSDictionaryMethods];
249
250 /// The selectors for Objective-C NSSet methods.
251 mutable Selector NSSetSelectors[NumNSSetMethods];
252
253 /// The Objective-C NSNumber selectors used to create NSNumber literals.
254 mutable Selector NSNumberClassSelectors[NumNSNumberLiteralMethods];
255 mutable Selector NSNumberInstanceSelectors[NumNSNumberLiteralMethods];
256
257 mutable Selector objectForKeyedSubscriptSel, objectAtIndexedSubscriptSel,
258 setObjectForKeyedSubscriptSel,setObjectAtIndexedSubscriptSel,
259 isEqualSel, InitSel, NewSel;
260
261 mutable IdentifierInfo *BOOLId, *NSIntegerId, *NSUIntegerId;
262 mutable IdentifierInfo *NSASCIIStringEncodingId, *NSUTF8StringEncodingId;
263};
264
265} // end namespace clang
266
267#endif // LLVM_CLANG_AST_NSAPI_H
Expr * E
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
uint32_t Id
Definition: SemaARM.cpp:1143
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
This represents one expression.
Definition: Expr.h:110
One of these records is kept for each identifier that is lexed.
std::optional< NSNumberLiteralMethodKind > getNSNumberLiteralMethodKind(Selector Sel) const
Return NSNumberLiteralMethodKind if Sel is such a selector.
Definition: NSAPI.cpp:338
Selector getObjectAtIndexedSubscriptSelector() const
Returns selector for "objectAtIndexedSubscript:".
Definition: NSAPI.h:143
bool isObjCNSIntegerType(QualType T) const
Returns true if.
Definition: NSAPI.cpp:485
NSStringMethodKind
Definition: NSAPI.h:43
@ NSStr_initWithUTF8String
Definition: NSAPI.h:49
@ NSStr_initWithString
Definition: NSAPI.h:48
@ NSStr_stringWithCString
Definition: NSAPI.h:47
@ NSStr_stringWithString
Definition: NSAPI.h:44
@ NSStr_stringWithCStringEncoding
Definition: NSAPI.h:46
@ NSStr_stringWithUTF8String
Definition: NSAPI.h:45
Selector getSetObjectAtIndexedSubscriptSelector() const
Returns selector for "setObject:atIndexedSubscript".
Definition: NSAPI.h:155
Selector getNSDictionarySelector(NSDictionaryMethodKind MK) const
The Objective-C NSDictionary selectors.
Definition: NSAPI.cpp:148
static const unsigned NumNSArrayMethods
Definition: NSAPI.h:86
static const unsigned NumNSStringMethods
Definition: NSAPI.h:51
Selector getNewSelector() const
Definition: NSAPI.h:165
NSClassIdKindKind
Definition: NSAPI.h:29
@ ClassId_NSDictionary
Definition: NSAPI.h:34
@ ClassId_NSMutableArray
Definition: NSAPI.h:33
@ ClassId_NSValue
Definition: NSAPI.h:39
@ ClassId_NSMutableOrderedSet
Definition: NSAPI.h:38
@ ClassId_NSObject
Definition: NSAPI.h:30
@ ClassId_NSNumber
Definition: NSAPI.h:36
@ ClassId_NSMutableSet
Definition: NSAPI.h:37
@ ClassId_NSArray
Definition: NSAPI.h:32
@ ClassId_NSString
Definition: NSAPI.h:31
@ ClassId_NSMutableDictionary
Definition: NSAPI.h:35
Selector getIsEqualSelector() const
Returns selector for "isEqual:".
Definition: NSAPI.h:161
Selector getNSNumberLiteralSelector(NSNumberLiteralMethodKind MK, bool Instance) const
The Objective-C NSNumber selectors used to create NSNumber literals.
Definition: NSAPI.cpp:285
Selector getObjectForKeyedSubscriptSelector() const
Returns selector for "objectForKeyedSubscript:".
Definition: NSAPI.h:137
bool isMacroDefined(StringRef Id) const
Returns true if Id is currently defined as a macro.
Definition: NSAPI.cpp:519
std::optional< NSNumberLiteralMethodKind > getNSNumberFactoryMethodKind(QualType T) const
Determine the appropriate NSNumber factory method kind for a literal of the given type.
Definition: NSAPI.cpp:349
std::optional< NSDictionaryMethodKind > getNSDictionaryMethodKind(Selector Sel)
Return NSDictionaryMethodKind if Sel is such a selector.
Definition: NSAPI.cpp:226
static const unsigned NumClassIds
Definition: NSAPI.h:41
NSSetMethodKind
Enumerates the NSMutableSet/NSOrderedSet methods used to apply some checks.
Definition: NSAPI.h:121
@ NSOrderedSet_setObjectAtIndex
Definition: NSAPI.h:124
@ NSMutableSet_addObject
Definition: NSAPI.h:122
@ NSOrderedSet_replaceObjectAtIndexWithObject
Definition: NSAPI.h:126
@ NSOrderedSet_setObjectAtIndexedSubscript
Definition: NSAPI.h:125
@ NSOrderedSet_insertObjectAtIndex
Definition: NSAPI.h:123
NSDictionaryMethodKind
Enumerates the NSDictionary/NSMutableDictionary methods used to generate literals and to apply some c...
Definition: NSAPI.h:96
@ NSDict_objectForKey
Definition: NSAPI.h:106
@ NSMutableDict_setValueForKey
Definition: NSAPI.h:109
@ NSDict_dictionaryWithObjectsForKeys
Definition: NSAPI.h:100
@ NSDict_dictionaryWithDictionary
Definition: NSAPI.h:98
@ NSMutableDict_setObjectForKey
Definition: NSAPI.h:107
@ NSDict_initWithObjectsForKeys
Definition: NSAPI.h:105
@ NSDict_dictionaryWithObjectForKey
Definition: NSAPI.h:99
@ NSDict_dictionary
Definition: NSAPI.h:97
@ NSDict_initWithDictionary
Definition: NSAPI.h:103
@ NSDict_dictionaryWithObjectsForKeysCount
Definition: NSAPI.h:101
@ NSDict_initWithObjectsAndKeys
Definition: NSAPI.h:104
@ NSMutableDict_setObjectForKeyedSubscript
Definition: NSAPI.h:108
@ NSDict_dictionaryWithObjectsAndKeys
Definition: NSAPI.h:102
Selector getInitSelector() const
Definition: NSAPI.h:169
Selector getNSArraySelector(NSArrayMethodKind MK) const
The Objective-C NSArray selectors.
Definition: NSAPI.cpp:77
std::optional< NSArrayMethodKind > getNSArrayMethodKind(Selector Sel)
Return NSArrayMethodKind if Sel is such a selector.
Definition: NSAPI.cpp:138
NSArrayMethodKind
Enumerates the NSArray/NSMutableArray methods used to generate literals and to apply some checks.
Definition: NSAPI.h:72
@ NSArr_arrayWithObjects
Definition: NSAPI.h:76
@ NSArr_objectAtIndex
Definition: NSAPI.h:80
@ NSMutableArr_setObjectAtIndexedSubscript
Definition: NSAPI.h:84
@ NSMutableArr_insertObjectAtIndex
Definition: NSAPI.h:83
@ NSArr_arrayWithArray
Definition: NSAPI.h:74
@ NSMutableArr_addObject
Definition: NSAPI.h:82
@ NSArr_arrayWithObjectsCount
Definition: NSAPI.h:77
@ NSArr_array
Definition: NSAPI.h:73
@ NSArr_initWithObjects
Definition: NSAPI.h:79
@ NSMutableArr_replaceObjectAtIndex
Definition: NSAPI.h:81
@ NSArr_initWithArray
Definition: NSAPI.h:78
@ NSArr_arrayWithObject
Definition: NSAPI.h:75
bool isSubclassOfNSClass(ObjCInterfaceDecl *InterfaceDecl, NSClassIdKindKind NSClassKind) const
Returns true if InterfaceDecl is subclass of NSClassKind.
Definition: NSAPI.cpp:524
std::optional< NSSetMethodKind > getNSSetMethodKind(Selector Sel)
Return NSSetMethodKind if Sel is such a selector.
Definition: NSAPI.cpp:275
bool isNSUTF8StringEncodingConstant(const Expr *E) const
Returns true if the expression.
Definition: NSAPI.h:60
bool isNSNumberLiteralSelector(NSNumberLiteralMethodKind MK, Selector Sel) const
Definition: NSAPI.h:199
Selector getSetObjectForKeyedSubscriptSelector() const
Returns selector for "setObject:forKeyedSubscript".
Definition: NSAPI.h:149
static const unsigned NumNSNumberLiteralMethods
Definition: NSAPI.h:191
bool isObjCNSUIntegerType(QualType T) const
Returns true if.
Definition: NSAPI.cpp:489
ASTContext & getASTContext() const
Definition: NSAPI.h:27
NSNumberLiteralMethodKind
Enumerates the NSNumber methods used to generate literals.
Definition: NSAPI.h:174
@ NSNumberWithChar
Definition: NSAPI.h:175
@ NSNumberWithInteger
Definition: NSAPI.h:188
@ NSNumberWithDouble
Definition: NSAPI.h:186
@ NSNumberWithUnsignedChar
Definition: NSAPI.h:176
@ NSNumberWithUnsignedLongLong
Definition: NSAPI.h:184
@ NSNumberWithBool
Definition: NSAPI.h:187
@ NSNumberWithUnsignedInt
Definition: NSAPI.h:180
@ NSNumberWithLongLong
Definition: NSAPI.h:183
@ NSNumberWithLong
Definition: NSAPI.h:181
@ NSNumberWithFloat
Definition: NSAPI.h:185
@ NSNumberWithUnsignedLong
Definition: NSAPI.h:182
@ NSNumberWithShort
Definition: NSAPI.h:177
@ NSNumberWithUnsignedInteger
Definition: NSAPI.h:189
@ NSNumberWithInt
Definition: NSAPI.h:179
@ NSNumberWithUnsignedShort
Definition: NSAPI.h:178
Selector getNSStringSelector(NSStringMethodKind MK) const
The Objective-C NSString selectors.
Definition: NSAPI.cpp:43
static const unsigned NumNSDictionaryMethods
Definition: NSAPI.h:111
bool isNSASCIIStringEncodingConstant(const Expr *E) const
Returns true if the expression.
Definition: NSAPI.h:66
bool isObjCBOOLType(QualType T) const
Returns true if.
Definition: NSAPI.cpp:481
static const unsigned NumNSSetMethods
Definition: NSAPI.h:128
StringRef GetNSIntegralKind(QualType T) const
Returns one of NSIntegral typedef names if.
Definition: NSAPI.cpp:493
Selector getNSSetSelector(NSSetMethodKind MK) const
The Objective-C NSSet selectors.
Definition: NSAPI.cpp:236
IdentifierInfo * getNSClassId(NSClassIdKindKind K) const
Definition: NSAPI.cpp:23
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
A (possibly-)qualified type.
Definition: Type.h:941
Smart pointer class that efficiently represents Objective-C method names.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T