clang 19.0.0git
Functions
RewriteObjCFoundationAPI.cpp File Reference
#include "clang/Edit/Rewriters.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/NSAPI.h"
#include "clang/AST/ParentMap.h"
#include "clang/Edit/Commit.h"
#include "clang/Lex/Lexer.h"
#include <optional>

Go to the source code of this file.

Functions

static bool checkForLiteralCreation (const ObjCMessageExpr *Msg, IdentifierInfo *&ClassId, const LangOptions &LangOpts)
 
static const ObjCInterfaceDeclmaybeAdjustInterfaceForSubscriptingCheck (const ObjCInterfaceDecl *IFace, const Expr *Receiver, ASTContext &Ctx)
 Check for classes that accept 'objectForKey:' (or the other selectors that the migrator handles) but return their instances as 'id', resulting in the compiler resolving 'objectForKey:' as the method from NSDictionary.
 
static bool canRewriteToSubscriptSyntax (const ObjCInterfaceDecl *&IFace, const ObjCMessageExpr *Msg, ASTContext &Ctx, Selector subscriptSel)
 
static bool subscriptOperatorNeedsParens (const Expr *FullExpr)
 
static void maybePutParensOnReceiver (const Expr *Receiver, Commit &commit)
 
static bool rewriteToSubscriptGetCommon (const ObjCMessageExpr *Msg, Commit &commit)
 
static bool rewriteToArraySubscriptGet (const ObjCInterfaceDecl *IFace, const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit)
 
static bool rewriteToDictionarySubscriptGet (const ObjCInterfaceDecl *IFace, const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit)
 
static bool rewriteToArraySubscriptSet (const ObjCInterfaceDecl *IFace, const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit)
 
static bool rewriteToDictionarySubscriptSet (const ObjCInterfaceDecl *IFace, const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit)
 
static bool rewriteToArrayLiteral (const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit, const ParentMap *PMap)
 
static bool rewriteToDictionaryLiteral (const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit)
 
static bool rewriteToNumberLiteral (const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit)
 
static bool rewriteToNumericBoxedExpression (const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit)
 
static bool rewriteToStringBoxedExpression (const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit)
 
static bool shouldNotRewriteImmediateMessageArgs (const ObjCMessageExpr *Msg, const NSAPI &NS)
 Returns true if the immediate message arguments of Msg should not be rewritten because it will interfere with the rewrite of the parent message expression.
 
static void objectifyExpr (const Expr *E, Commit &commit)
 Adds an explicit cast to 'id' if the type is not objc object.
 
static bool getNSArrayObjects (const Expr *E, const NSAPI &NS, SmallVectorImpl< const Expr * > &Objs)
 If Msg is an NSArray creation message or literal, this gets the objects that were used to create it.
 
static bool rewriteToCharLiteral (const ObjCMessageExpr *Msg, const CharacterLiteral *Arg, const NSAPI &NS, Commit &commit)
 
static bool rewriteToBoolLiteral (const ObjCMessageExpr *Msg, const Expr *Arg, const NSAPI &NS, Commit &commit)
 
static bool getLiteralInfo (SourceRange literalRange, bool isFloat, bool isIntZero, ASTContext &Ctx, LiteralInfo &Info)
 
static bool castOperatorNeedsParens (const Expr *FullExpr)
 
static bool isEnumConstant (const Expr *E)
 
static bool doRewriteToUTF8StringBoxedExpressionHelper (const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit)
 

Function Documentation

◆ canRewriteToSubscriptSyntax()

static bool canRewriteToSubscriptSyntax ( const ObjCInterfaceDecl *&  IFace,
const ObjCMessageExpr Msg,
ASTContext Ctx,
Selector  subscriptSel 
)
static

◆ castOperatorNeedsParens()

static bool castOperatorNeedsParens ( const Expr FullExpr)
static

Definition at line 910 of file RewriteObjCFoundationAPI.cpp.

References clang::Expr::IgnoreImpCasts().

Referenced by objectifyExpr().

◆ checkForLiteralCreation()

static bool checkForLiteralCreation ( const ObjCMessageExpr Msg,
IdentifierInfo *&  ClassId,
const LangOptions LangOpts 
)
static

◆ doRewriteToUTF8StringBoxedExpressionHelper()

static bool doRewriteToUTF8StringBoxedExpressionHelper ( const ObjCMessageExpr Msg,
const NSAPI NS,
Commit commit 
)
static

◆ getLiteralInfo()

static bool getLiteralInfo ( SourceRange  literalRange,
bool  isFloat,
bool  isIntZero,
ASTContext Ctx,
LiteralInfo &  Info 
)
static

◆ getNSArrayObjects()

static bool getNSArrayObjects ( const Expr E,
const NSAPI NS,
SmallVectorImpl< const Expr * > &  Objs 
)
static

◆ isEnumConstant()

static bool isEnumConstant ( const Expr E)
static

◆ maybeAdjustInterfaceForSubscriptingCheck()

static const ObjCInterfaceDecl * maybeAdjustInterfaceForSubscriptingCheck ( const ObjCInterfaceDecl IFace,
const Expr Receiver,
ASTContext Ctx 
)
static

Check for classes that accept 'objectForKey:' (or the other selectors that the migrator handles) but return their instances as 'id', resulting in the compiler resolving 'objectForKey:' as the method from NSDictionary.

When checking if we can convert to subscripting syntax, check whether the receiver is a result of a class method from a hardcoded list of such classes. In such a case return the specific class as the interface of the receiver.

FIXME: Remove this when these classes start using 'instancetype'.

Definition at line 109 of file RewriteObjCFoundationAPI.cpp.

References clang::ObjCMessageExpr::Class, clang::Type::getAs(), clang::ObjCMessageExpr::getClassReceiver(), clang::ObjCObjectType::getInterface(), clang::NamedDecl::getName(), clang::ObjCMessageExpr::getReceiverKind(), clang::ObjCMessageExpr::getSuperType(), clang::Expr::getType(), clang::QualType::getUnqualifiedType(), clang::Expr::IgnoreParenCasts(), clang::ObjCMessageExpr::Instance, clang::QualType::isNull(), clang::ASTContext::isObjCIdType(), clang::ObjCMessageExpr::SuperClass, and clang::ObjCMessageExpr::SuperInstance.

Referenced by canRewriteToSubscriptSyntax().

◆ maybePutParensOnReceiver()

static void maybePutParensOnReceiver ( const Expr Receiver,
Commit commit 
)
static

◆ objectifyExpr()

static void objectifyExpr ( const Expr E,
Commit commit 
)
static

◆ rewriteToArrayLiteral()

static bool rewriteToArrayLiteral ( const ObjCMessageExpr Msg,
const NSAPI NS,
Commit commit,
const ParentMap PMap 
)
static

◆ rewriteToArraySubscriptGet()

static bool rewriteToArraySubscriptGet ( const ObjCInterfaceDecl IFace,
const ObjCMessageExpr Msg,
const NSAPI NS,
Commit commit 
)
static

◆ rewriteToArraySubscriptSet()

static bool rewriteToArraySubscriptSet ( const ObjCInterfaceDecl IFace,
const ObjCMessageExpr Msg,
const NSAPI NS,
Commit commit 
)
static

◆ rewriteToBoolLiteral()

static bool rewriteToBoolLiteral ( const ObjCMessageExpr Msg,
const Expr Arg,
const NSAPI NS,
Commit commit 
)
static

◆ rewriteToCharLiteral()

static bool rewriteToCharLiteral ( const ObjCMessageExpr Msg,
const CharacterLiteral Arg,
const NSAPI NS,
Commit commit 
)
static

◆ rewriteToDictionaryLiteral()

static bool rewriteToDictionaryLiteral ( const ObjCMessageExpr Msg,
const NSAPI NS,
Commit commit 
)
static

◆ rewriteToDictionarySubscriptGet()

static bool rewriteToDictionarySubscriptGet ( const ObjCInterfaceDecl IFace,
const ObjCMessageExpr Msg,
const NSAPI NS,
Commit commit 
)
static

◆ rewriteToDictionarySubscriptSet()

static bool rewriteToDictionarySubscriptSet ( const ObjCInterfaceDecl IFace,
const ObjCMessageExpr Msg,
const NSAPI NS,
Commit commit 
)
static

◆ rewriteToNumberLiteral()

static bool rewriteToNumberLiteral ( const ObjCMessageExpr Msg,
const NSAPI NS,
Commit commit 
)
static

◆ rewriteToNumericBoxedExpression()

static bool rewriteToNumericBoxedExpression ( const ObjCMessageExpr Msg,
const NSAPI NS,
Commit commit 
)
static

◆ rewriteToStringBoxedExpression()

static bool rewriteToStringBoxedExpression ( const ObjCMessageExpr Msg,
const NSAPI NS,
Commit commit 
)
static

◆ rewriteToSubscriptGetCommon()

static bool rewriteToSubscriptGetCommon ( const ObjCMessageExpr Msg,
Commit commit 
)
static

◆ shouldNotRewriteImmediateMessageArgs()

static bool shouldNotRewriteImmediateMessageArgs ( const ObjCMessageExpr Msg,
const NSAPI NS 
)
static

Returns true if the immediate message arguments of Msg should not be rewritten because it will interfere with the rewrite of the parent message expression.

e.g.

[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"1", @"2", nil]
forKeys:[NSArray arrayWithObjects:@"A", @"B", nil]];

It will return true for this because we are going to rewrite this directly to a dictionary literal without any array literals.

Definition at line 603 of file RewriteObjCFoundationAPI.cpp.

References checkForLiteralCreation(), clang::NSAPI::ClassId_NSDictionary, clang::ObjCMessageExpr::getArg(), clang::NSAPI::getASTContext(), clang::ASTContext::getLangOpts(), getNSArrayObjects(), clang::NSAPI::getNSClassId(), clang::NSAPI::getNSDictionarySelector(), clang::ObjCMessageExpr::getNumArgs(), clang::ObjCMessageExpr::getSelector(), clang::NSAPI::NSDict_dictionaryWithObjectsForKeys, and clang::NSAPI::NSDict_initWithObjectsForKeys.

Referenced by rewriteToArrayLiteral().

◆ subscriptOperatorNeedsParens()

static bool subscriptOperatorNeedsParens ( const Expr FullExpr)
static

Definition at line 888 of file RewriteObjCFoundationAPI.cpp.

References clang::Expr::IgnoreImpCasts().

Referenced by maybePutParensOnReceiver().