1 //===--- NSAPI.h - NSFoundation APIs ----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_AST_NSAPI_H
11 #define LLVM_CLANG_AST_NSAPI_H
13 #include "clang/Basic/IdentifierTable.h"
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/Optional.h"
22 // \brief Provides info and caches identifiers/selectors for NSFoundation API.
25 explicit NSAPI(ASTContext
&Ctx
);
27 ASTContext
&getASTContext() const { return Ctx
; }
29 enum NSClassIdKindKind
{
33 ClassId_NSMutableArray
,
35 ClassId_NSMutableDictionary
,
38 static const unsigned NumClassIds
= 7;
40 enum NSStringMethodKind
{
41 NSStr_stringWithString
,
42 NSStr_stringWithUTF8String
,
43 NSStr_stringWithCStringEncoding
,
44 NSStr_stringWithCString
,
47 static const unsigned NumNSStringMethods
= 5;
49 IdentifierInfo
*getNSClassId(NSClassIdKindKind K
) const;
51 /// \brief The Objective-C NSString selectors.
52 Selector
getNSStringSelector(NSStringMethodKind MK
) const;
54 /// \brief Return NSStringMethodKind if \param Sel is such a selector.
55 llvm::Optional
<NSStringMethodKind
> getNSStringMethodKind(Selector Sel
) const;
57 /// \brief Returns true if the expression \param E is a reference of
58 /// "NSUTF8StringEncoding" enum constant.
59 bool isNSUTF8StringEncodingConstant(const Expr
*E
) const {
60 return isObjCEnumerator(E
, "NSUTF8StringEncoding", NSUTF8StringEncodingId
);
63 /// \brief Returns true if the expression \param E is a reference of
64 /// "NSASCIIStringEncoding" enum constant.
65 bool isNSASCIIStringEncodingConstant(const Expr
*E
) const {
66 return isObjCEnumerator(E
, "NSASCIIStringEncoding",NSASCIIStringEncodingId
);
69 /// \brief Enumerates the NSArray methods used to generate literals.
70 enum NSArrayMethodKind
{
73 NSArr_arrayWithObject
,
74 NSArr_arrayWithObjects
,
75 NSArr_arrayWithObjectsCount
,
77 NSArr_initWithObjects
,
79 NSMutableArr_replaceObjectAtIndex
81 static const unsigned NumNSArrayMethods
= 9;
83 /// \brief The Objective-C NSArray selectors.
84 Selector
getNSArraySelector(NSArrayMethodKind MK
) const;
86 /// \brief Return NSArrayMethodKind if \p Sel is such a selector.
87 llvm::Optional
<NSArrayMethodKind
> getNSArrayMethodKind(Selector Sel
);
89 /// \brief Enumerates the NSDictionary methods used to generate literals.
90 enum NSDictionaryMethodKind
{
92 NSDict_dictionaryWithDictionary
,
93 NSDict_dictionaryWithObjectForKey
,
94 NSDict_dictionaryWithObjectsForKeys
,
95 NSDict_dictionaryWithObjectsForKeysCount
,
96 NSDict_dictionaryWithObjectsAndKeys
,
97 NSDict_initWithDictionary
,
98 NSDict_initWithObjectsAndKeys
,
100 NSMutableDict_setObjectForKey
102 static const unsigned NumNSDictionaryMethods
= 10;
104 /// \brief The Objective-C NSDictionary selectors.
105 Selector
getNSDictionarySelector(NSDictionaryMethodKind MK
) const;
107 /// \brief Return NSDictionaryMethodKind if \p Sel is such a selector.
108 llvm::Optional
<NSDictionaryMethodKind
>
109 getNSDictionaryMethodKind(Selector Sel
);
111 /// \brief Returns selector for "objectForKeyedSubscript:".
112 Selector
getObjectForKeyedSubscriptSelector() const {
113 return getOrInitSelector(StringRef("objectForKeyedSubscript"),
114 objectForKeyedSubscriptSel
);
117 /// \brief Returns selector for "objectAtIndexedSubscript:".
118 Selector
getObjectAtIndexedSubscriptSelector() const {
119 return getOrInitSelector(StringRef("objectAtIndexedSubscript"),
120 objectAtIndexedSubscriptSel
);
123 /// \brief Returns selector for "setObject:forKeyedSubscript".
124 Selector
getSetObjectForKeyedSubscriptSelector() const {
125 StringRef Ids
[] = { "setObject", "forKeyedSubscript" };
126 return getOrInitSelector(Ids
, setObjectForKeyedSubscriptSel
);
129 /// \brief Returns selector for "setObject:atIndexedSubscript".
130 Selector
getSetObjectAtIndexedSubscriptSelector() const {
131 StringRef Ids
[] = { "setObject", "atIndexedSubscript" };
132 return getOrInitSelector(Ids
, setObjectAtIndexedSubscriptSel
);
135 /// \brief Returns selector for "isEqual:".
136 Selector
getIsEqualSelector() const {
137 return getOrInitSelector(StringRef("isEqual"), isEqualSel
);
140 /// \brief Enumerates the NSNumber methods used to generate literals.
141 enum NSNumberLiteralMethodKind
{
143 NSNumberWithUnsignedChar
,
145 NSNumberWithUnsignedShort
,
147 NSNumberWithUnsignedInt
,
149 NSNumberWithUnsignedLong
,
150 NSNumberWithLongLong
,
151 NSNumberWithUnsignedLongLong
,
156 NSNumberWithUnsignedInteger
158 static const unsigned NumNSNumberLiteralMethods
= 15;
160 /// \brief The Objective-C NSNumber selectors used to create NSNumber literals.
161 /// \param Instance if true it will return the selector for the init* method
162 /// otherwise it will return the selector for the number* method.
163 Selector
getNSNumberLiteralSelector(NSNumberLiteralMethodKind MK
,
164 bool Instance
) const;
166 bool isNSNumberLiteralSelector(NSNumberLiteralMethodKind MK
,
167 Selector Sel
) const {
168 return Sel
== getNSNumberLiteralSelector(MK
, false) ||
169 Sel
== getNSNumberLiteralSelector(MK
, true);
172 /// \brief Return NSNumberLiteralMethodKind if \p Sel is such a selector.
173 llvm::Optional
<NSNumberLiteralMethodKind
>
174 getNSNumberLiteralMethodKind(Selector Sel
) const;
176 /// \brief Determine the appropriate NSNumber factory method kind for a
177 /// literal of the given type.
178 llvm::Optional
<NSNumberLiteralMethodKind
>
179 getNSNumberFactoryMethodKind(QualType T
) const;
181 /// \brief Returns true if \param T is a typedef of "BOOL" in objective-c.
182 bool isObjCBOOLType(QualType T
) const;
183 /// \brief Returns true if \param T is a typedef of "NSInteger" in objective-c.
184 bool isObjCNSIntegerType(QualType T
) const;
185 /// \brief Returns true if \param T is a typedef of "NSUInteger" in objective-c.
186 bool isObjCNSUIntegerType(QualType T
) const;
189 bool isObjCTypedef(QualType T
, StringRef name
, IdentifierInfo
*&II
) const;
190 bool isObjCEnumerator(const Expr
*E
,
191 StringRef name
, IdentifierInfo
*&II
) const;
192 Selector
getOrInitSelector(ArrayRef
<StringRef
> Ids
, Selector
&Sel
) const;
196 mutable IdentifierInfo
*ClassIds
[NumClassIds
];
198 mutable Selector NSStringSelectors
[NumNSStringMethods
];
200 /// \brief The selectors for Objective-C NSArray methods.
201 mutable Selector NSArraySelectors
[NumNSArrayMethods
];
203 /// \brief The selectors for Objective-C NSDictionary methods.
204 mutable Selector NSDictionarySelectors
[NumNSDictionaryMethods
];
206 /// \brief The Objective-C NSNumber selectors used to create NSNumber literals.
207 mutable Selector NSNumberClassSelectors
[NumNSNumberLiteralMethods
];
208 mutable Selector NSNumberInstanceSelectors
[NumNSNumberLiteralMethods
];
210 mutable Selector objectForKeyedSubscriptSel
, objectAtIndexedSubscriptSel
,
211 setObjectForKeyedSubscriptSel
,setObjectAtIndexedSubscriptSel
,
214 mutable IdentifierInfo
*BOOLId
, *NSIntegerId
, *NSUIntegerId
;
215 mutable IdentifierInfo
*NSASCIIStringEncodingId
, *NSUTF8StringEncodingId
;
218 } // end namespace clang
220 #endif // LLVM_CLANG_AST_NSAPI_H