1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | #ifndef LLVM_CLANG_AST_NSAPI_H |
10 | #define LLVM_CLANG_AST_NSAPI_H |
11 | |
12 | #include "clang/Basic/IdentifierTable.h" |
13 | #include "llvm/ADT/ArrayRef.h" |
14 | #include "llvm/ADT/Optional.h" |
15 | |
16 | namespace clang { |
17 | class ASTContext; |
18 | class ObjCInterfaceDecl; |
19 | class QualType; |
20 | class Expr; |
21 | |
22 | |
23 | class NSAPI { |
24 | public: |
25 | explicit NSAPI(ASTContext &Ctx); |
26 | |
27 | ASTContext &getASTContext() const { return Ctx; } |
28 | |
29 | enum NSClassIdKindKind { |
30 | ClassId_NSObject, |
31 | ClassId_NSString, |
32 | ClassId_NSArray, |
33 | ClassId_NSMutableArray, |
34 | ClassId_NSDictionary, |
35 | ClassId_NSMutableDictionary, |
36 | ClassId_NSNumber, |
37 | ClassId_NSMutableSet, |
38 | ClassId_NSMutableOrderedSet, |
39 | ClassId_NSValue |
40 | }; |
41 | static const unsigned NumClassIds = 10; |
42 | |
43 | enum NSStringMethodKind { |
44 | NSStr_stringWithString, |
45 | NSStr_stringWithUTF8String, |
46 | NSStr_stringWithCStringEncoding, |
47 | NSStr_stringWithCString, |
48 | NSStr_initWithString, |
49 | NSStr_initWithUTF8String |
50 | }; |
51 | static const unsigned NumNSStringMethods = 6; |
52 | |
53 | IdentifierInfo *getNSClassId(NSClassIdKindKind K) const; |
54 | |
55 | |
56 | Selector getNSStringSelector(NSStringMethodKind MK) const; |
57 | |
58 | |
59 | Optional<NSStringMethodKind> getNSStringMethodKind(Selector Sel) const; |
60 | |
61 | |
62 | |
63 | bool isNSUTF8StringEncodingConstant(const Expr *E) const { |
64 | return isObjCEnumerator(E, "NSUTF8StringEncoding", NSUTF8StringEncodingId); |
65 | } |
66 | |
67 | |
68 | |
69 | bool isNSASCIIStringEncodingConstant(const Expr *E) const { |
70 | return isObjCEnumerator(E, "NSASCIIStringEncoding",NSASCIIStringEncodingId); |
71 | } |
72 | |
73 | |
74 | |
75 | enum NSArrayMethodKind { |
76 | NSArr_array, |
77 | NSArr_arrayWithArray, |
78 | NSArr_arrayWithObject, |
79 | NSArr_arrayWithObjects, |
80 | NSArr_arrayWithObjectsCount, |
81 | NSArr_initWithArray, |
82 | NSArr_initWithObjects, |
83 | NSArr_objectAtIndex, |
84 | NSMutableArr_replaceObjectAtIndex, |
85 | NSMutableArr_addObject, |
86 | NSMutableArr_insertObjectAtIndex, |
87 | NSMutableArr_setObjectAtIndexedSubscript |
88 | }; |
89 | static const unsigned NumNSArrayMethods = 12; |
90 | |
91 | |
92 | Selector getNSArraySelector(NSArrayMethodKind MK) const; |
93 | |
94 | |
95 | Optional<NSArrayMethodKind> getNSArrayMethodKind(Selector Sel); |
96 | |
97 | |
98 | |
99 | enum NSDictionaryMethodKind { |
100 | NSDict_dictionary, |
101 | NSDict_dictionaryWithDictionary, |
102 | NSDict_dictionaryWithObjectForKey, |
103 | NSDict_dictionaryWithObjectsForKeys, |
104 | NSDict_dictionaryWithObjectsForKeysCount, |
105 | NSDict_dictionaryWithObjectsAndKeys, |
106 | NSDict_initWithDictionary, |
107 | NSDict_initWithObjectsAndKeys, |
108 | NSDict_initWithObjectsForKeys, |
109 | NSDict_objectForKey, |
110 | NSMutableDict_setObjectForKey, |
111 | NSMutableDict_setObjectForKeyedSubscript, |
112 | NSMutableDict_setValueForKey |
113 | }; |
114 | static const unsigned NumNSDictionaryMethods = 13; |
115 | |
116 | |
117 | Selector getNSDictionarySelector(NSDictionaryMethodKind MK) const; |
118 | |
119 | |
120 | Optional<NSDictionaryMethodKind> getNSDictionaryMethodKind(Selector Sel); |
121 | |
122 | |
123 | |
124 | enum NSSetMethodKind { |
125 | NSMutableSet_addObject, |
126 | NSOrderedSet_insertObjectAtIndex, |
127 | NSOrderedSet_setObjectAtIndex, |
128 | NSOrderedSet_setObjectAtIndexedSubscript, |
129 | NSOrderedSet_replaceObjectAtIndexWithObject |
130 | }; |
131 | static const unsigned NumNSSetMethods = 5; |
132 | |
133 | |
134 | Selector getNSSetSelector(NSSetMethodKind MK) const; |
135 | |
136 | |
137 | Optional<NSSetMethodKind> getNSSetMethodKind(Selector Sel); |
138 | |
139 | |
140 | Selector getObjectForKeyedSubscriptSelector() const { |
141 | return getOrInitSelector(StringRef("objectForKeyedSubscript"), |
142 | objectForKeyedSubscriptSel); |
143 | } |
144 | |
145 | |
146 | Selector getObjectAtIndexedSubscriptSelector() const { |
147 | return getOrInitSelector(StringRef("objectAtIndexedSubscript"), |
148 | objectAtIndexedSubscriptSel); |
149 | } |
150 | |
151 | |
152 | Selector getSetObjectForKeyedSubscriptSelector() const { |
153 | StringRef Ids[] = { "setObject", "forKeyedSubscript" }; |
154 | return getOrInitSelector(Ids, setObjectForKeyedSubscriptSel); |
155 | } |
156 | |
157 | |
158 | Selector getSetObjectAtIndexedSubscriptSelector() const { |
159 | StringRef Ids[] = { "setObject", "atIndexedSubscript" }; |
160 | return getOrInitSelector(Ids, setObjectAtIndexedSubscriptSel); |
161 | } |
162 | |
163 | |
164 | Selector getIsEqualSelector() const { |
165 | return getOrInitSelector(StringRef("isEqual"), isEqualSel); |
166 | } |
167 | |
168 | Selector getNewSelector() const { |
169 | return getOrInitNullarySelector("new", NewSel); |
170 | } |
171 | |
172 | Selector getInitSelector() const { |
173 | return getOrInitNullarySelector("init", InitSel); |
174 | } |
175 | |
176 | |
177 | enum NSNumberLiteralMethodKind { |
178 | NSNumberWithChar, |
179 | NSNumberWithUnsignedChar, |
180 | NSNumberWithShort, |
181 | NSNumberWithUnsignedShort, |
182 | NSNumberWithInt, |
183 | NSNumberWithUnsignedInt, |
184 | NSNumberWithLong, |
185 | NSNumberWithUnsignedLong, |
186 | NSNumberWithLongLong, |
187 | NSNumberWithUnsignedLongLong, |
188 | NSNumberWithFloat, |
189 | NSNumberWithDouble, |
190 | NSNumberWithBool, |
191 | NSNumberWithInteger, |
192 | NSNumberWithUnsignedInteger |
193 | }; |
194 | static const unsigned NumNSNumberLiteralMethods = 15; |
195 | |
196 | |
197 | |
198 | |
199 | Selector getNSNumberLiteralSelector(NSNumberLiteralMethodKind MK, |
200 | bool Instance) const; |
201 | |
202 | bool isNSNumberLiteralSelector(NSNumberLiteralMethodKind MK, |
203 | Selector Sel) const { |
204 | return Sel == getNSNumberLiteralSelector(MK, false) || |
205 | Sel == getNSNumberLiteralSelector(MK, true); |
206 | } |
207 | |
208 | |
209 | Optional<NSNumberLiteralMethodKind> |
210 | getNSNumberLiteralMethodKind(Selector Sel) const; |
211 | |
212 | |
213 | |
214 | Optional<NSNumberLiteralMethodKind> |
215 | getNSNumberFactoryMethodKind(QualType T) const; |
216 | |
217 | |
218 | bool isObjCBOOLType(QualType T) const; |
219 | |
220 | bool isObjCNSIntegerType(QualType T) const; |
221 | |
222 | bool isObjCNSUIntegerType(QualType T) const; |
223 | |
224 | |
225 | StringRef GetNSIntegralKind(QualType T) const; |
226 | |
227 | |
228 | bool isMacroDefined(StringRef Id) const; |
229 | |
230 | |
231 | bool isSubclassOfNSClass(ObjCInterfaceDecl *InterfaceDecl, |
232 | NSClassIdKindKind NSClassKind) const; |
233 | |
234 | private: |
235 | bool isObjCTypedef(QualType T, StringRef name, IdentifierInfo *&II) const; |
236 | bool isObjCEnumerator(const Expr *E, |
237 | StringRef name, IdentifierInfo *&II) const; |
238 | Selector getOrInitSelector(ArrayRef<StringRef> Ids, Selector &Sel) const; |
239 | Selector getOrInitNullarySelector(StringRef Id, Selector &Sel) const; |
240 | |
241 | ASTContext &Ctx; |
242 | |
243 | mutable IdentifierInfo *ClassIds[NumClassIds]; |
244 | |
245 | mutable Selector NSStringSelectors[NumNSStringMethods]; |
246 | |
247 | |
248 | mutable Selector NSArraySelectors[NumNSArrayMethods]; |
249 | |
250 | |
251 | mutable Selector NSDictionarySelectors[NumNSDictionaryMethods]; |
252 | |
253 | |
254 | mutable Selector NSSetSelectors[NumNSSetMethods]; |
255 | |
256 | |
257 | mutable Selector NSNumberClassSelectors[NumNSNumberLiteralMethods]; |
258 | mutable Selector NSNumberInstanceSelectors[NumNSNumberLiteralMethods]; |
259 | |
260 | mutable Selector objectForKeyedSubscriptSel, objectAtIndexedSubscriptSel, |
261 | setObjectForKeyedSubscriptSel,setObjectAtIndexedSubscriptSel, |
262 | isEqualSel, InitSel, NewSel; |
263 | |
264 | mutable IdentifierInfo *BOOLId, *NSIntegerId, *NSUIntegerId; |
265 | mutable IdentifierInfo *NSASCIIStringEncodingId, *NSUTF8StringEncodingId; |
266 | }; |
267 | |
268 | } |
269 | |
270 | #endif |
271 | |