clang  7.0.0svn
Classes | Namespaces | Functions
ObjCMT.cpp File Reference
#include "Transforms.h"
#include "clang/ARCMigrate/ARCMT.h"
#include "clang/ARCMigrate/ARCMTActions.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
#include "clang/AST/NSAPI.h"
#include "clang/AST/ParentMap.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Analysis/DomainSpecific/CocoaConventions.h"
#include "clang/Basic/FileManager.h"
#include "clang/Edit/Commit.h"
#include "clang/Edit/EditedSource.h"
#include "clang/Edit/EditsReceiver.h"
#include "clang/Edit/Rewriters.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/MultiplexConsumer.h"
#include "clang/Lex/PPConditionalDirectiveRecord.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Rewrite/Core/Rewriter.h"
#include "clang/StaticAnalyzer/Checkers/ObjCRetainCount.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/YAMLParser.h"
Include dependency graph for ObjCMT.cpp:

Go to the source code of this file.


struct  llvm::DenseMapInfo< EditEntry >


 DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterators.


static void append_attr (std::string &PropertyString, const char *attr, bool &LParenAdded)
static void MigrateBlockOrFunctionPointerTypeVariable (std::string &PropertyString, const std::string &TypeString, const char *name)
static const char * PropertyMemoryAttribute (ASTContext &Context, QualType ArgType)
static void rewriteToObjCProperty (const ObjCMethodDecl *Getter, const ObjCMethodDecl *Setter, const NSAPI &NS, edit::Commit &commit, unsigned LengthOfPrefix, bool Atomic, bool UseNsIosOnlyMacro, bool AvailabilityArgsMatch)
static bool IsCategoryNameWithDeprecatedSuffix (ObjCContainerDecl *D)
static bool ClassImplementsAllMethodsAndProperties (ASTContext &Ctx, const ObjCImplementationDecl *ImpDecl, const ObjCInterfaceDecl *IDecl, ObjCProtocolDecl *Protocol)
static bool rewriteToObjCInterfaceDecl (const ObjCInterfaceDecl *IDecl, llvm::SmallVectorImpl< ObjCProtocolDecl *> &ConformingProtocols, const NSAPI &NS, edit::Commit &commit)
static StringRef GetUnsignedName (StringRef NSIntegerName)
static bool rewriteToNSEnumDecl (const EnumDecl *EnumDcl, const TypedefDecl *TypedefDcl, const NSAPI &NS, edit::Commit &commit, StringRef NSIntegerName, bool NSOptions)
static void rewriteToNSMacroDecl (ASTContext &Ctx, const EnumDecl *EnumDcl, const TypedefDecl *TypedefDcl, const NSAPI &NS, edit::Commit &commit, bool IsNSIntegerType)
static bool UseNSOptionsMacro (Preprocessor &PP, ASTContext &Ctx, const EnumDecl *EnumDcl)
static void ReplaceWithInstancetype (ASTContext &Ctx, const ObjCMigrateASTConsumer &ASTC, ObjCMethodDecl *OM)
static void ReplaceWithClasstype (const ObjCMigrateASTConsumer &ASTC, ObjCMethodDecl *OM)
static bool TypeIsInnerPointer (QualType T)
static bool versionsMatch (const VersionTuple &X, const VersionTuple &Y)
 Check whether the two versions match. More...
static bool AvailabilityAttrsMatch (Attr *At1, Attr *At2)
 AvailabilityAttrsMatch - This routine checks that if comparing two availability attributes, all their components match. More...
static bool MatchTwoAttributeLists (const AttrVec &Attrs1, const AttrVec &Attrs2, bool &AvailabilityArgsMatch)
static bool AttributesMatch (const Decl *Decl1, const Decl *Decl2, bool &AvailabilityArgsMatch)
 AttributesMatch - This routine checks list of attributes for two decls. More...
static bool IsValidIdentifier (ASTContext &Ctx, const char *Name)
static bool IsVoidStarType (QualType Ty)
static bool AuditedType (QualType AT)
 AuditedType - This routine audits the type AT and returns false if it is one of known CF object types or of the "void *" variety. More...
static bool hasSuperInitCall (const ObjCMethodDecl *MD)
static std::vector< std::string > getWhiteListFilenames (StringRef DirPath)
static bool reportDiag (const Twine &Err, DiagnosticsEngine &Diag)
static std::string applyEditsToTemp (const FileEntry *FE, ArrayRef< EditEntry > Edits, FileManager &FileMgr, DiagnosticsEngine &Diag)

Function Documentation

◆ append_attr()

static void append_attr ( std::string &  PropertyString,
const char *  attr,
bool LParenAdded 

Definition at line 383 of file ObjCMT.cpp.

Referenced by rewriteToObjCProperty().

◆ applyEditsToTemp()

static std::string applyEditsToTemp ( const FileEntry FE,
ArrayRef< EditEntry >  Edits,
FileManager FileMgr,
DiagnosticsEngine Diag 

Definition at line 2157 of file ObjCMT.cpp.

References clang::SrcMgr::C_User, clang::SourceManager::createFileID(), and SM.

◆ AttributesMatch()

static bool AttributesMatch ( const Decl Decl1,
const Decl Decl2,
bool AvailabilityArgsMatch 

AttributesMatch - This routine checks list of attributes for two decls.

It returns false, if there is a mismatch in kind of attributes seen in the decls. It returns true if the two decls have list of same kind of attributes. Furthermore, when there are availability attributes in the two decls, it sets the AvailabilityArgsMatch to false if availability attributes have different versions, etc.

Definition at line 1127 of file ObjCMT.cpp.

References clang::Decl::getAttrs(), clang::Decl::hasAttrs(), clang::ast_matchers::match(), and MatchTwoAttributeLists().

◆ AuditedType()

static bool AuditedType ( QualType  AT)

AuditedType - This routine audits the type AT and returns false if it is one of known CF object types or of the "void *" variety.

It returns true if we don't care about the type such as a non-pointer or pointers which have no ownership issues (such as "int *").

Definition at line 1370 of file ObjCMT.cpp.

References clang::ento::objc_retain::DecRef, clang::ento::objc_retain::DecRefMsg, clang::SourceManager::getFileID(), clang::Token::getLocation(), clang::Decl::getLocation(), clang::ObjCMethodDecl::getLocEnd(), clang::Decl::getLocEnd(), clang::Preprocessor::getLocForEndOfToken(), clang::Decl::getLocStart(), clang::ObjCMethodDecl::getMethodFamily(), clang::FunctionDecl::getNumParams(), clang::Preprocessor::getRawToken(), clang::ObjCMethodDecl::getReturnType(), clang::FunctionDecl::getReturnType(), clang::Preprocessor::getSourceManager(), clang::ValueDecl::getType(), clang::Decl::hasAttr(), clang::ObjCMethodDecl::hasBody(), clang::FunctionDecl::hasBody(), clang::ento::objc_retain::IncRef, clang::edit::Commit::insertAfterToken(), clang::edit::Commit::insertBefore(), clang::Type::isAnyPointerType(), clang::Type::isBlockPointerType(), clang::ento::coreFoundation::isCFObjectRef(), clang::Decl::isDeprecated(), clang::Decl::isImplicit(), clang::FileID::isInvalid(), clang::Type::isObjCBuiltinType(), clang::Type::isObjCObjectPointerType(), IsVoidStarType(), clang::ObjCContainerDecl::methods(), AttributeLangSupport::ObjC, clang::OMF_alloc, clang::OMF_copy, clang::OMF_init, clang::OMF_mutableCopy, clang::OMF_new, clang::OMF_release, clang::ObjCMethodDecl::param_begin(), clang::FunctionDecl::param_begin(), clang::ObjCMethodDecl::param_end(), clang::FunctionDecl::param_end(), and clang::format::Tok.

◆ AvailabilityAttrsMatch()

static bool AvailabilityAttrsMatch ( Attr At1,
Attr At2 

AvailabilityAttrsMatch - This routine checks that if comparing two availability attributes, all their components match.

It returns true, if not dealing with availability or when all components of availability attributes match. This routine is only called when the attributes are of the same kind.

Definition at line 1078 of file ObjCMT.cpp.

References versionsMatch().

Referenced by MatchTwoAttributeLists().

◆ ClassImplementsAllMethodsAndProperties()

static bool ClassImplementsAllMethodsAndProperties ( ASTContext Ctx,
const ObjCImplementationDecl ImpDecl,
const ObjCInterfaceDecl IDecl,
ObjCProtocolDecl Protocol 

◆ GetUnsignedName()

static StringRef GetUnsignedName ( StringRef  NSIntegerName)

Definition at line 694 of file ObjCMT.cpp.

Referenced by rewriteToNSEnumDecl().

◆ getWhiteListFilenames()

static std::vector<std::string> getWhiteListFilenames ( StringRef  DirPath)

Definition at line 1986 of file ObjCMT.cpp.

Referenced by clang::arcmt::MigrateSourceAction::CreateASTConsumer().

◆ hasSuperInitCall()

static bool hasSuperInitCall ( const ObjCMethodDecl MD)

Definition at line 1691 of file ObjCMT.cpp.

References Begin, clang::DeclContext::decls_begin(), clang::DeclContext::decls_end(), End, clang::DiagnosticsEngine::Error, clang::IdentifierTable::get(), clang::CharSourceRange::getBegin(), clang::ObjCMethodDecl::getBody(), clang::ObjCImplDecl::getClassInterface(), clang::DiagnosticsEngine::getCustomDiagID(), clang::SourceManager::getDecomposedLoc(), clang::ASTContext::getDiagnostics(), clang::CharSourceRange::getEnd(), clang::SourceManager::getFileEntryForID(), clang::SourceManager::getFileID(), clang::ASTContext::getLangOpts(), clang::ObjCMethodDecl::getLocEnd(), clang::Preprocessor::getMacroDefinitionAtLoc(), clang::ObjCContainerDecl::getMethod(), clang::FileEntry::getName(), clang::Rewriter::getRangeSize(), clang::ASTContext::getSourceManager(), clang::Preprocessor::getSourceManager(), clang::ASTContext::getTranslationUnitDecl(), clang::ObjCInterfaceDecl::hasDesignatedInitializers(), clang::ASTContext::Idents, clang::edit::Commit::insert(), clang::Rewriter::InsertText(), clang::ObjCContainerDecl::instance_methods(), clang::CharSourceRange::isCharRange(), clang::SourceLocation::isInvalid(), clang::FileID::isValid(), clang::FrontendOptions::ObjCMT_Annotation, clang::FrontendOptions::ObjCMT_DesignatedInitializer, clang::FrontendOptions::ObjCMT_Instancetype, clang::FrontendOptions::ObjCMT_MigrateDecls, clang::FrontendOptions::ObjCMT_NsMacros, clang::FrontendOptions::ObjCMT_ProtocolConformance, clang::OMF_init, clang::Rewriter::ReplaceText(), clang::DiagnosticsEngine::Report(), SM, clang::comments::tok::text, and Text.

◆ IsCategoryNameWithDeprecatedSuffix()

static bool IsCategoryNameWithDeprecatedSuffix ( ObjCContainerDecl D)

Definition at line 563 of file ObjCMT.cpp.

◆ IsValidIdentifier()

static bool IsValidIdentifier ( ASTContext Ctx,
const char *  Name 

Definition at line 1142 of file ObjCMT.cpp.

◆ IsVoidStarType()

static bool IsVoidStarType ( QualType  Ty)

◆ MatchTwoAttributeLists()

static bool MatchTwoAttributeLists ( const AttrVec Attrs1,
const AttrVec Attrs2,
bool AvailabilityArgsMatch 

Definition at line 1098 of file ObjCMT.cpp.

References AvailabilityAttrsMatch(), getKind(), and clang::ast_matchers::match().

Referenced by AttributesMatch().

◆ MigrateBlockOrFunctionPointerTypeVariable()

static void MigrateBlockOrFunctionPointerTypeVariable ( std::string &  PropertyString,
const std::string &  TypeString,
const char *  name 

Definition at line 395 of file ObjCMT.cpp.

Referenced by rewriteToObjCProperty().

◆ PropertyMemoryAttribute()

static const char* PropertyMemoryAttribute ( ASTContext Context,
QualType  ArgType 

◆ ReplaceWithClasstype()

static void ReplaceWithClasstype ( const ObjCMigrateASTConsumer &  ASTC,
ObjCMethodDecl OM 

◆ ReplaceWithInstancetype()

static void ReplaceWithInstancetype ( ASTContext Ctx,
const ObjCMigrateASTConsumer &  ASTC,
ObjCMethodDecl OM 

◆ reportDiag()

static bool reportDiag ( const Twine &  Err,
DiagnosticsEngine Diag 

◆ rewriteToNSEnumDecl()

static bool rewriteToNSEnumDecl ( const EnumDecl EnumDcl,
const TypedefDecl TypedefDcl,
const NSAPI NS,
edit::Commit commit,
StringRef  NSIntegerName,
bool  NSOptions 

◆ rewriteToNSMacroDecl()

static void rewriteToNSMacroDecl ( ASTContext Ctx,
const EnumDecl EnumDcl,
const TypedefDecl TypedefDcl,
const NSAPI NS,
edit::Commit commit,
bool  IsNSIntegerType 

◆ rewriteToObjCInterfaceDecl()

static bool rewriteToObjCInterfaceDecl ( const ObjCInterfaceDecl IDecl,
llvm::SmallVectorImpl< ObjCProtocolDecl *> &  ConformingProtocols,
const NSAPI NS,
edit::Commit commit 

◆ rewriteToObjCProperty()

static void rewriteToObjCProperty ( const ObjCMethodDecl Getter,
const ObjCMethodDecl Setter,
const NSAPI NS,
edit::Commit commit,
unsigned  LengthOfPrefix,
bool  Atomic,
bool  UseNsIosOnlyMacro,
bool  AvailabilityArgsMatch 

◆ TypeIsInnerPointer()

static bool TypeIsInnerPointer ( QualType  T)

◆ UseNSOptionsMacro()

static bool UseNSOptionsMacro ( Preprocessor PP,
ASTContext Ctx,
const EnumDecl EnumDcl 

◆ versionsMatch()

static bool versionsMatch ( const VersionTuple X,
const VersionTuple Y 

Check whether the two versions match.

Definition at line 1069 of file ObjCMT.cpp.

Referenced by AvailabilityAttrsMatch().