clang  6.0.0svn
NSAPI.h
Go to the documentation of this file.
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 
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/Optional.h"
16 
17 namespace clang {
18  class ASTContext;
19  class ObjCInterfaceDecl;
20  class QualType;
21  class Expr;
22 
23 // \brief Provides info and caches identifiers/selectors for NSFoundation API.
24 class NSAPI {
25 public:
26  explicit NSAPI(ASTContext &Ctx);
27 
28  ASTContext &getASTContext() const { return Ctx; }
29 
41  };
42  static const unsigned NumClassIds = 10;
43 
51  };
52  static const unsigned NumNSStringMethods = 6;
53 
55 
56  /// \brief The Objective-C NSString selectors.
58 
59  /// \brief Return NSStringMethodKind if \param Sel is such a selector.
61 
62  /// \brief Returns true if the expression \param E is a reference of
63  /// "NSUTF8StringEncoding" enum constant.
64  bool isNSUTF8StringEncodingConstant(const Expr *E) const {
65  return isObjCEnumerator(E, "NSUTF8StringEncoding", NSUTF8StringEncodingId);
66  }
67 
68  /// \brief Returns true if the expression \param E is a reference of
69  /// "NSASCIIStringEncoding" enum constant.
70  bool isNSASCIIStringEncodingConstant(const Expr *E) const {
71  return isObjCEnumerator(E, "NSASCIIStringEncoding",NSASCIIStringEncodingId);
72  }
73 
74  /// \brief Enumerates the NSArray/NSMutableArray methods used to generate
75  /// literals and to apply some checks.
89  };
90  static const unsigned NumNSArrayMethods = 12;
91 
92  /// \brief The Objective-C NSArray selectors.
94 
95  /// \brief Return NSArrayMethodKind if \p Sel is such a selector.
97 
98  /// \brief Enumerates the NSDictionary/NSMutableDictionary methods used
99  /// to generate literals and to apply some checks.
114  };
115  static const unsigned NumNSDictionaryMethods = 13;
116 
117  /// \brief The Objective-C NSDictionary selectors.
119 
120  /// \brief Return NSDictionaryMethodKind if \p Sel is such a selector.
122 
123  /// \brief Enumerates the NSMutableSet/NSOrderedSet methods used
124  /// to apply some checks.
131  };
132  static const unsigned NumNSSetMethods = 5;
133 
134  /// \brief The Objective-C NSSet selectors.
136 
137  /// \brief Return NSSetMethodKind if \p Sel is such a selector.
139 
140  /// \brief Returns selector for "objectForKeyedSubscript:".
142  return getOrInitSelector(StringRef("objectForKeyedSubscript"),
143  objectForKeyedSubscriptSel);
144  }
145 
146  /// \brief Returns selector for "objectAtIndexedSubscript:".
148  return getOrInitSelector(StringRef("objectAtIndexedSubscript"),
149  objectAtIndexedSubscriptSel);
150  }
151 
152  /// \brief Returns selector for "setObject:forKeyedSubscript".
154  StringRef Ids[] = { "setObject", "forKeyedSubscript" };
155  return getOrInitSelector(Ids, setObjectForKeyedSubscriptSel);
156  }
157 
158  /// \brief Returns selector for "setObject:atIndexedSubscript".
160  StringRef Ids[] = { "setObject", "atIndexedSubscript" };
161  return getOrInitSelector(Ids, setObjectAtIndexedSubscriptSel);
162  }
163 
164  /// \brief Returns selector for "isEqual:".
166  return getOrInitSelector(StringRef("isEqual"), isEqualSel);
167  }
168 
169  /// \brief Enumerates the NSNumber methods used to generate literals.
186  };
187  static const unsigned NumNSNumberLiteralMethods = 15;
188 
189  /// \brief The Objective-C NSNumber selectors used to create NSNumber literals.
190  /// \param Instance if true it will return the selector for the init* method
191  /// otherwise it will return the selector for the number* method.
193  bool Instance) const;
194 
196  Selector Sel) const {
197  return Sel == getNSNumberLiteralSelector(MK, false) ||
198  Sel == getNSNumberLiteralSelector(MK, true);
199  }
200 
201  /// \brief Return NSNumberLiteralMethodKind if \p Sel is such a selector.
204 
205  /// \brief Determine the appropriate NSNumber factory method kind for a
206  /// literal of the given type.
209 
210  /// \brief Returns true if \param T is a typedef of "BOOL" in objective-c.
211  bool isObjCBOOLType(QualType T) const;
212  /// \brief Returns true if \param T is a typedef of "NSInteger" in objective-c.
213  bool isObjCNSIntegerType(QualType T) const;
214  /// \brief Returns true if \param T is a typedef of "NSUInteger" in objective-c.
215  bool isObjCNSUIntegerType(QualType T) const;
216  /// \brief Returns one of NSIntegral typedef names if \param T is a typedef
217  /// of that name in objective-c.
218  StringRef GetNSIntegralKind(QualType T) const;
219 
220  /// \brief Returns \c true if \p Id is currently defined as a macro.
221  bool isMacroDefined(StringRef Id) const;
222 
223  /// \brief Returns \c true if \p InterfaceDecl is subclass of \p NSClassKind
224  bool isSubclassOfNSClass(ObjCInterfaceDecl *InterfaceDecl,
225  NSClassIdKindKind NSClassKind) const;
226 
227 private:
228  bool isObjCTypedef(QualType T, StringRef name, IdentifierInfo *&II) const;
229  bool isObjCEnumerator(const Expr *E,
230  StringRef name, IdentifierInfo *&II) const;
231  Selector getOrInitSelector(ArrayRef<StringRef> Ids, Selector &Sel) const;
232 
233  ASTContext &Ctx;
234 
235  mutable IdentifierInfo *ClassIds[NumClassIds];
236 
237  mutable Selector NSStringSelectors[NumNSStringMethods];
238 
239  /// \brief The selectors for Objective-C NSArray methods.
240  mutable Selector NSArraySelectors[NumNSArrayMethods];
241 
242  /// \brief The selectors for Objective-C NSDictionary methods.
243  mutable Selector NSDictionarySelectors[NumNSDictionaryMethods];
244 
245  /// \brief The selectors for Objective-C NSSet methods.
246  mutable Selector NSSetSelectors[NumNSSetMethods];
247 
248  /// \brief The Objective-C NSNumber selectors used to create NSNumber literals.
249  mutable Selector NSNumberClassSelectors[NumNSNumberLiteralMethods];
250  mutable Selector NSNumberInstanceSelectors[NumNSNumberLiteralMethods];
251 
252  mutable Selector objectForKeyedSubscriptSel, objectAtIndexedSubscriptSel,
253  setObjectForKeyedSubscriptSel,setObjectAtIndexedSubscriptSel,
254  isEqualSel;
255 
256  mutable IdentifierInfo *BOOLId, *NSIntegerId, *NSUIntegerId;
257  mutable IdentifierInfo *NSASCIIStringEncodingId, *NSUTF8StringEncodingId;
258 };
259 
260 } // end namespace clang
261 
262 #endif // LLVM_CLANG_AST_NSAPI_H
Selector getObjectAtIndexedSubscriptSelector() const
Returns selector for "objectAtIndexedSubscript:".
Definition: NSAPI.h:147
Optional< NSNumberLiteralMethodKind > getNSNumberFactoryMethodKind(QualType T) const
Determine the appropriate NSNumber factory method kind for a literal of the given type...
Definition: NSAPI.cpp:390
Smart pointer class that efficiently represents Objective-C method names.
A (possibly-)qualified type.
Definition: Type.h:653
Optional< NSDictionaryMethodKind > getNSDictionaryMethodKind(Selector Sel)
Return NSDictionaryMethodKind if Sel is such a selector.
Definition: NSAPI.cpp:259
NSNumberLiteralMethodKind
Enumerates the NSNumber methods used to generate literals.
Definition: NSAPI.h:170
Selector getIsEqualSelector() const
Returns selector for "isEqual:".
Definition: NSAPI.h:165
NSDictionaryMethodKind
Enumerates the NSDictionary/NSMutableDictionary methods used to generate literals and to apply some c...
Definition: NSAPI.h:100
One of these records is kept for each identifier that is lexed.
Selector getSetObjectForKeyedSubscriptSelector() const
Returns selector for "setObject:forKeyedSubscript".
Definition: NSAPI.h:153
Optional< NSSetMethodKind > getNSSetMethodKind(Selector Sel)
Return NSSetMethodKind if Sel is such a selector.
Definition: NSAPI.cpp:316
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
Selector getNSStringSelector(NSStringMethodKind MK) const
The Objective-C NSString selectors.
Definition: NSAPI.cpp:43
Selector getNSNumberLiteralSelector(NSNumberLiteralMethodKind MK, bool Instance) const
The Objective-C NSNumber selectors used to create NSNumber literals.
Definition: NSAPI.cpp:326
Optional< NSNumberLiteralMethodKind > getNSNumberLiteralMethodKind(Selector Sel) const
Return NSNumberLiteralMethodKind if Sel is such a selector.
Definition: NSAPI.cpp:379
static const unsigned NumClassIds
Definition: NSAPI.h:42
static const unsigned NumNSNumberLiteralMethods
Definition: NSAPI.h:187
NSSetMethodKind
Enumerates the NSMutableSet/NSOrderedSet methods used to apply some checks.
Definition: NSAPI.h:125
NSAPI(ASTContext &Ctx)
Definition: NSAPI.cpp:18
Represents an ObjC class declaration.
Definition: DeclObjC.h:1191
static const unsigned NumNSSetMethods
Definition: NSAPI.h:132
NSClassIdKindKind
Definition: NSAPI.h:30
NSArrayMethodKind
Enumerates the NSArray/NSMutableArray methods used to generate literals and to apply some checks...
Definition: NSAPI.h:76
Expr - This represents one expression.
Definition: Expr.h:106
Selector getNSArraySelector(NSArrayMethodKind MK) const
The Objective-C NSArray selectors.
Definition: NSAPI.cpp:90
int Id
Definition: ASTDiff.cpp:191
const FunctionProtoType * T
ASTContext & getASTContext() const
Definition: NSAPI.h:28
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
StringRef GetNSIntegralKind(QualType T) const
Returns one of NSIntegral typedef names if.
Definition: NSAPI.cpp:486
bool isNSUTF8StringEncodingConstant(const Expr *E) const
Returns true if the expression.
Definition: NSAPI.h:64
bool isObjCBOOLType(QualType T) const
Returns true if.
Definition: NSAPI.cpp:474
bool isObjCNSUIntegerType(QualType T) const
Returns true if.
Definition: NSAPI.cpp:482
Selector getNSSetSelector(NSSetMethodKind MK) const
The Objective-C NSSet selectors.
Definition: NSAPI.cpp:269
bool isObjCNSIntegerType(QualType T) const
Returns true if.
Definition: NSAPI.cpp:478
bool isSubclassOfNSClass(ObjCInterfaceDecl *InterfaceDecl, NSClassIdKindKind NSClassKind) const
Returns true if InterfaceDecl is subclass of NSClassKind.
Definition: NSAPI.cpp:517
IdentifierInfo * getNSClassId(NSClassIdKindKind K) const
Definition: NSAPI.cpp:23
NSStringMethodKind
Definition: NSAPI.h:44
Optional< NSStringMethodKind > getNSStringMethodKind(Selector Sel) const
Return NSStringMethodKind if.
Definition: NSAPI.cpp:80
Dataflow Directional Tag Classes.
bool isMacroDefined(StringRef Id) const
Returns true if Id is currently defined as a macro.
Definition: NSAPI.cpp:512
bool isNSNumberLiteralSelector(NSNumberLiteralMethodKind MK, Selector Sel) const
Definition: NSAPI.h:195
static const unsigned NumNSArrayMethods
Definition: NSAPI.h:90
Selector getNSDictionarySelector(NSDictionaryMethodKind MK) const
The Objective-C NSDictionary selectors.
Definition: NSAPI.cpp:167
static const unsigned NumNSDictionaryMethods
Definition: NSAPI.h:115
Optional< NSArrayMethodKind > getNSArrayMethodKind(Selector Sel)
Return NSArrayMethodKind if Sel is such a selector.
Definition: NSAPI.cpp:157
Selector getObjectForKeyedSubscriptSelector() const
Returns selector for "objectForKeyedSubscript:".
Definition: NSAPI.h:141
static const unsigned NumNSStringMethods
Definition: NSAPI.h:52
bool isNSASCIIStringEncodingConstant(const Expr *E) const
Returns true if the expression.
Definition: NSAPI.h:70
Selector getSetObjectAtIndexedSubscriptSelector() const
Returns selector for "setObject:atIndexedSubscript".
Definition: NSAPI.h:159