[objcmt] Rewrite messages to NSString's stringWithUTF8String:/stringWithCString:
to use the @() boxing syntax. It will also rewrite uses of stringWithCString:encoding: where the encoding that is used is NSASCIIStringEncoding or NSUTF8StringEncoding. rdar://11438360 llvm-svn: 156868
This commit is contained in:
@@ -9,11 +9,13 @@
|
||||
|
||||
#include "clang/AST/NSAPI.h"
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/Expr.h"
|
||||
|
||||
using namespace clang;
|
||||
|
||||
NSAPI::NSAPI(ASTContext &ctx)
|
||||
: Ctx(ctx), ClassIds(), BOOLId(0), NSIntegerId(0), NSUIntegerId(0) {
|
||||
: Ctx(ctx), ClassIds(), BOOLId(0), NSIntegerId(0), NSUIntegerId(0),
|
||||
NSASCIIStringEncodingId(0), NSUTF8StringEncodingId(0) {
|
||||
}
|
||||
|
||||
IdentifierInfo *NSAPI::getNSClassId(NSClassIdKindKind K) const {
|
||||
@@ -40,6 +42,21 @@ Selector NSAPI::getNSStringSelector(NSStringMethodKind MK) const {
|
||||
case NSStr_stringWithString:
|
||||
Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("stringWithString"));
|
||||
break;
|
||||
case NSStr_stringWithUTF8String:
|
||||
Sel = Ctx.Selectors.getUnarySelector(
|
||||
&Ctx.Idents.get("stringWithUTF8String"));
|
||||
break;
|
||||
case NSStr_stringWithCStringEncoding: {
|
||||
IdentifierInfo *KeyIdents[] = {
|
||||
&Ctx.Idents.get("stringWithCString"),
|
||||
&Ctx.Idents.get("encoding")
|
||||
};
|
||||
Sel = Ctx.Selectors.getSelector(2, KeyIdents);
|
||||
break;
|
||||
}
|
||||
case NSStr_stringWithCString:
|
||||
Sel= Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("stringWithCString"));
|
||||
break;
|
||||
case NSStr_initWithString:
|
||||
Sel = Ctx.Selectors.getUnarySelector(&Ctx.Idents.get("initWithString"));
|
||||
break;
|
||||
@@ -50,6 +67,17 @@ Selector NSAPI::getNSStringSelector(NSStringMethodKind MK) const {
|
||||
return NSStringSelectors[MK];
|
||||
}
|
||||
|
||||
llvm::Optional<NSAPI::NSStringMethodKind>
|
||||
NSAPI::getNSStringMethodKind(Selector Sel) const {
|
||||
for (unsigned i = 0; i != NumNSStringMethods; ++i) {
|
||||
NSStringMethodKind MK = NSStringMethodKind(i);
|
||||
if (Sel == getNSStringSelector(MK))
|
||||
return MK;
|
||||
}
|
||||
|
||||
return llvm::Optional<NSStringMethodKind>();
|
||||
}
|
||||
|
||||
Selector NSAPI::getNSArraySelector(NSArrayMethodKind MK) const {
|
||||
if (NSArraySelectors[MK].isNull()) {
|
||||
Selector Sel;
|
||||
@@ -353,3 +381,21 @@ bool NSAPI::isObjCTypedef(QualType T,
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NSAPI::isObjCEnumerator(const Expr *E,
|
||||
StringRef name, IdentifierInfo *&II) const {
|
||||
if (!Ctx.getLangOpts().ObjC1)
|
||||
return false;
|
||||
if (!E)
|
||||
return false;
|
||||
|
||||
if (!II)
|
||||
II = &Ctx.Idents.get(name);
|
||||
|
||||
if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts()))
|
||||
if (const EnumConstantDecl *
|
||||
EnumD = dyn_cast_or_null<EnumConstantDecl>(DRE->getDecl()))
|
||||
return EnumD->getIdentifier() == II;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user