clang  6.0.0svn
Macros | Enumerations | Functions
RewriteModernObjC.cpp File Reference
#include "clang/Rewrite/Frontend/ASTConsumers.h"
#include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/Attr.h"
#include "clang/AST/ParentMap.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Config/config.h"
#include "clang/Lex/Lexer.h"
#include "clang/Rewrite/Core/Rewriter.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include <memory>
Include dependency graph for RewriteModernObjC.cpp:

Go to the source code of this file.

Macros

#define SKIP_BITFIELDS(IX, ENDIX, VEC)
 

Enumerations

enum  MetaDataDlags {
  CLS = 0x0, CLS_META = 0x1, CLS_ROOT = 0x2, OBJC2_CLS_HIDDEN = 0x10,
  CLS_EXCEPTION = 0x20, CLS_HAS_IVAR_RELEASER = 0x40, CLS_COMPILED_BY_ARC = 0x80
}
 

Functions

static bool IsHeaderFile (const std::string &Filename)
 
static void WriteInternalIvarName (const ObjCInterfaceDecl *IDecl, ObjCIvarDecl *IvarDecl, std::string &Result)
 
static bool mustSynthesizeSetterGetterMethod (ObjCImplementationDecl *IMP, ObjCPropertyDecl *PD, bool getter)
 mustSynthesizeSetterGetterMethod - returns true if setter or getter has not been found in the class implementation. More...
 
static void RewriteOneForwardClassDecl (ObjCInterfaceDecl *ForwardDecl, std::string &typedefString)
 
static void Write_RethrowObject (std::string &buf)
 
static bool scanForProtocolRefs (const char *startBuf, const char *endBuf, const char *&startRef, const char *&endRef)
 
static void scanToNextArgument (const char *&argRef)
 
static SourceLocation getFunctionSourceLocation (RewriteModernObjC &R, FunctionDecl *FD)
 getFunctionSourceLocation - returns start location of a function definition. More...
 
static bool HasLocalVariableExternalStorage (ValueDecl *VD)
 
static void BuildUniqueMethodName (std::string &Name, ObjCMethodDecl *MD)
 
static void Write_ProtocolExprReferencedMetadata (ASTContext *Context, ObjCProtocolDecl *PDecl, std::string &Result)
 Write_ProtocolExprReferencedMetadata - This routine writer out the protocol reference symbols in the for of: struct _protocol_t *PROTOCOL_REF = &PROTOCOL_METADATA. More...
 
static void WriteModernMetadataDeclarations (ASTContext *Context, std::string &Result)
 WriteModernMetadataDeclarations - Writes out metadata declarations for modern ABI. More...
 
static void Write_protocol_list_t_TypeDecl (std::string &Result, long super_protocol_count)
 
static void Write_method_list_t_TypeDecl (std::string &Result, unsigned int method_count)
 
static void Write__prop_list_t_TypeDecl (std::string &Result, unsigned int property_count)
 
static void Write__ivar_list_t_TypeDecl (std::string &Result, unsigned int ivar_count)
 
static void Write_protocol_list_initializer (ASTContext *Context, std::string &Result, ArrayRef< ObjCProtocolDecl *> SuperProtocols, StringRef VarName, StringRef ProtocolName)
 
static void Write_method_list_t_initializer (RewriteModernObjC &RewriteObj, ASTContext *Context, std::string &Result, ArrayRef< ObjCMethodDecl *> Methods, StringRef VarName, StringRef TopLevelDeclName, bool MethodImpl)
 
static void Write_prop_list_t_initializer (RewriteModernObjC &RewriteObj, ASTContext *Context, std::string &Result, ArrayRef< ObjCPropertyDecl *> Properties, const Decl *Container, StringRef VarName, StringRef ProtocolName)
 
static void Write__class_ro_t_initializer (ASTContext *Context, std::string &Result, unsigned int flags, const std::string &InstanceStart, const std::string &InstanceSize, ArrayRef< ObjCMethodDecl *>baseMethods, ArrayRef< ObjCProtocolDecl *>baseProtocols, ArrayRef< ObjCIvarDecl *>ivars, ArrayRef< ObjCPropertyDecl *>Properties, StringRef VarName, StringRef ClassName)
 
static void Write_class_t (ASTContext *Context, std::string &Result, StringRef VarName, const ObjCInterfaceDecl *CDecl, bool metaclass)
 
static void Write_category_t (RewriteModernObjC &RewriteObj, ASTContext *Context, std::string &Result, ObjCCategoryDecl *CatDecl, ObjCInterfaceDecl *ClassDecl, ArrayRef< ObjCMethodDecl *> InstanceMethods, ArrayRef< ObjCMethodDecl *> ClassMethods, ArrayRef< ObjCProtocolDecl *> RefedProtocols, ArrayRef< ObjCPropertyDecl *> ClassProperties)
 
static void Write__extendedMethodTypes_initializer (RewriteModernObjC &RewriteObj, ASTContext *Context, std::string &Result, ArrayRef< ObjCMethodDecl *> Methods, StringRef VarName, StringRef ProtocolName)
 
static void Write_IvarOffsetVar (RewriteModernObjC &RewriteObj, ASTContext *Context, std::string &Result, ArrayRef< ObjCIvarDecl *> Ivars, ObjCInterfaceDecl *CDecl)
 
static void Write__ivar_list_t_initializer (RewriteModernObjC &RewriteObj, ASTContext *Context, std::string &Result, ArrayRef< ObjCIvarDecl *> OriginalIvars, StringRef VarName, ObjCInterfaceDecl *CDecl)
 
static bool hasObjCExceptionAttribute (ASTContext &Context, const ObjCInterfaceDecl *OID)
 hasObjCExceptionAttribute - Return true if this class or any super class has the objc_exception attribute. More...
 

Macro Definition Documentation

◆ SKIP_BITFIELDS

#define SKIP_BITFIELDS (   IX,
  ENDIX,
  VEC 
)
Value:
{ \
while ((IX < ENDIX) && VEC[IX]->isBitField()) \
++IX; \
if (IX < ENDIX) \
--IX; \
}

Definition at line 3879 of file RewriteModernObjC.cpp.

Referenced by Write__ivar_list_t_initializer(), and Write_IvarOffsetVar().

Enumeration Type Documentation

◆ MetaDataDlags

Enumerator
CLS 
CLS_META 
CLS_ROOT 
OBJC2_CLS_HIDDEN 
CLS_EXCEPTION 
CLS_HAS_IVAR_RELEASER 

(Obsolete) ARC-specific: this class has a .release_ivars method

CLS_COMPILED_BY_ARC 

class was compiled with -fobjc-arr

Definition at line 6407 of file RewriteModernObjC.cpp.

Function Documentation

◆ BuildUniqueMethodName()

static void BuildUniqueMethodName ( std::string &  Name,
ObjCMethodDecl MD 
)
static

◆ getFunctionSourceLocation()

static SourceLocation getFunctionSourceLocation ( RewriteModernObjC &  R,
FunctionDecl FD 
)
static

◆ HasLocalVariableExternalStorage()

static bool HasLocalVariableExternalStorage ( ValueDecl VD)
static

◆ hasObjCExceptionAttribute()

static bool hasObjCExceptionAttribute ( ASTContext Context,
const ObjCInterfaceDecl OID 
)
static

◆ IsHeaderFile()

static bool IsHeaderFile ( const std::string &  Filename)
static

◆ mustSynthesizeSetterGetterMethod()

static bool mustSynthesizeSetterGetterMethod ( ObjCImplementationDecl IMP,
ObjCPropertyDecl PD,
bool  getter 
)
static

◆ RewriteOneForwardClassDecl()

static void RewriteOneForwardClassDecl ( ObjCInterfaceDecl ForwardDecl,
std::string &  typedefString 
)
static

◆ scanForProtocolRefs()

static bool scanForProtocolRefs ( const char *  startBuf,
const char *  endBuf,
const char *&  startRef,
const char *&  endRef 
)
static

Definition at line 2117 of file RewriteModernObjC.cpp.

Referenced by scanToNextArgument().

◆ scanToNextArgument()

static void scanToNextArgument ( const char *&  argRef)
static

◆ Write__class_ro_t_initializer()

static void Write__class_ro_t_initializer ( ASTContext Context,
std::string &  Result,
unsigned int  flags,
const std::string &  InstanceStart,
const std::string &  InstanceSize,
ArrayRef< ObjCMethodDecl *>  baseMethods,
ArrayRef< ObjCProtocolDecl *>  baseProtocols,
ArrayRef< ObjCIvarDecl *>  ivars,
ArrayRef< ObjCPropertyDecl *>  Properties,
StringRef  VarName,
StringRef  ClassName 
)
static

◆ Write__extendedMethodTypes_initializer()

static void Write__extendedMethodTypes_initializer ( RewriteModernObjC &  RewriteObj,
ASTContext Context,
std::string &  Result,
ArrayRef< ObjCMethodDecl *>  Methods,
StringRef  VarName,
StringRef  ProtocolName 
)
static

◆ Write__ivar_list_t_initializer()

static void Write__ivar_list_t_initializer ( RewriteModernObjC &  RewriteObj,
ASTContext Context,
std::string &  Result,
ArrayRef< ObjCIvarDecl *>  OriginalIvars,
StringRef  VarName,
ObjCInterfaceDecl CDecl 
)
static

◆ Write__ivar_list_t_TypeDecl()

static void Write__ivar_list_t_TypeDecl ( std::string &  Result,
unsigned int  ivar_count 
)
static

Definition at line 6298 of file RewriteModernObjC.cpp.

Referenced by Write__ivar_list_t_initializer().

◆ Write__prop_list_t_TypeDecl()

static void Write__prop_list_t_TypeDecl ( std::string &  Result,
unsigned int  property_count 
)
static

Definition at line 6288 of file RewriteModernObjC.cpp.

◆ Write_category_t()

static void Write_category_t ( RewriteModernObjC &  RewriteObj,
ASTContext Context,
std::string &  Result,
ObjCCategoryDecl CatDecl,
ObjCInterfaceDecl ClassDecl,
ArrayRef< ObjCMethodDecl *>  InstanceMethods,
ArrayRef< ObjCMethodDecl *>  ClassMethods,
ArrayRef< ObjCProtocolDecl *>  RefedProtocols,
ArrayRef< ObjCPropertyDecl *>  ClassProperties 
)
static

◆ Write_class_t()

static void Write_class_t ( ASTContext Context,
std::string &  Result,
StringRef  VarName,
const ObjCInterfaceDecl CDecl,
bool  metaclass 
)
static

◆ Write_IvarOffsetVar()

static void Write_IvarOffsetVar ( RewriteModernObjC &  RewriteObj,
ASTContext Context,
std::string &  Result,
ArrayRef< ObjCIvarDecl *>  Ivars,
ObjCInterfaceDecl CDecl 
)
static

if (Ivar->getAccessControl() == ObjCIvarDecl::Private || Ivar->getAccessControl() == ObjCIvarDecl::Package || Class->getVisibility() == HiddenVisibility) Visibility shoud be: HiddenVisibility; else Visibility shoud be: DefaultVisibility;

Definition at line 6736 of file RewriteModernObjC.cpp.

References clang::ObjCIvarDecl::getAccessControl(), clang::ASTContext::getLangOpts(), clang::ObjCIvarDecl::Package, clang::ObjCIvarDecl::Private, SKIP_BITFIELDS, and WriteInternalIvarName().

Referenced by Write__ivar_list_t_initializer().

◆ Write_method_list_t_initializer()

static void Write_method_list_t_initializer ( RewriteModernObjC &  RewriteObj,
ASTContext Context,
std::string &  Result,
ArrayRef< ObjCMethodDecl *>  Methods,
StringRef  VarName,
StringRef  TopLevelDeclName,
bool  MethodImpl 
)
static

◆ Write_method_list_t_TypeDecl()

static void Write_method_list_t_TypeDecl ( std::string &  Result,
unsigned int  method_count 
)
static

Definition at line 6278 of file RewriteModernObjC.cpp.

Referenced by Write_method_list_t_initializer().

◆ Write_prop_list_t_initializer()

static void Write_prop_list_t_initializer ( RewriteModernObjC &  RewriteObj,
ASTContext Context,
std::string &  Result,
ArrayRef< ObjCPropertyDecl *>  Properties,
const Decl Container,
StringRef  VarName,
StringRef  ProtocolName 
)
static

Definition at line 6371 of file RewriteModernObjC.cpp.

◆ Write_protocol_list_initializer()

static void Write_protocol_list_initializer ( ASTContext Context,
std::string &  Result,
ArrayRef< ObjCProtocolDecl *>  SuperProtocols,
StringRef  VarName,
StringRef  ProtocolName 
)
static

◆ Write_protocol_list_t_TypeDecl()

static void Write_protocol_list_t_TypeDecl ( std::string &  Result,
long  super_protocol_count 
)
static

Definition at line 6269 of file RewriteModernObjC.cpp.

Referenced by Write_protocol_list_initializer().

◆ Write_ProtocolExprReferencedMetadata()

static void Write_ProtocolExprReferencedMetadata ( ASTContext Context,
ObjCProtocolDecl PDecl,
std::string &  Result 
)
static

Write_ProtocolExprReferencedMetadata - This routine writer out the protocol reference symbols in the for of: struct _protocol_t *PROTOCOL_REF = &PROTOCOL_METADATA.

Definition at line 5825 of file RewriteModernObjC.cpp.

References clang::C, clang::ObjCIvarDecl::getContainingInterface(), clang::ASTContext::getLangOpts(), clang::SourceManager::getLocForStartOfFile(), clang::NamedDecl::getNameAsString(), clang::Rewriter::getRewriteBufferFor(), clang::DiagnosticsEngine::hasErrorOccurred(), and clang::FieldDecl::isBitField().

◆ Write_RethrowObject()

static void Write_RethrowObject ( std::string &  buf)
static

◆ WriteInternalIvarName()

static void WriteInternalIvarName ( const ObjCInterfaceDecl IDecl,
ObjCIvarDecl IvarDecl,
std::string &  Result 
)
static

◆ WriteModernMetadataDeclarations()

static void WriteModernMetadataDeclarations ( ASTContext Context,
std::string &  Result 
)
static

WriteModernMetadataDeclarations - Writes out metadata declarations for modern ABI.

struct _prop_t { const char *name; char *attributes; } struct _prop_list_t { uint32_t entsize; // sizeof(struct _prop_t) uint32_t count_of_properties; struct _prop_t prop_list[count_of_properties]; } struct _protocol_t; struct _protocol_list_t { long protocol_count; // Note, this is 32/64 bit struct _protocol_t * protocol_list[protocol_count]; } struct _objc_method { SEL _cmd; const char *method_type; char *_imp; } struct _method_list_t { uint32_t entsize; // sizeof(struct _objc_method) uint32_t method_count; struct _objc_method method_list[method_count]; } struct _protocol_t { id isa; // NULL const char *protocol_name; const struct _protocol_list_t * protocol_list; // super protocols const struct method_list_t *instance_methods; const struct method_list_t *class_methods; const struct method_list_t *optionalInstanceMethods; const struct method_list_t *optionalClassMethods; const struct _prop_list_t * properties; const uint32_t size; // sizeof(struct _protocol_t) const uint32_t flags; // = 0 const char ** extendedMethodTypes; } struct _ivar_t { unsigned long int *offset; // pointer to ivar offset location const char *name; const char *type; uint32_t alignment; uint32_t size; } struct _ivar_list_t { uint32 entsize; // sizeof(struct _ivar_t) uint32 count; struct _ivar_t list[count]; } struct _class_ro_t { uint32_t flags; uint32_t instanceStart; uint32_t instanceSize; uint32_t reserved; // only when building for 64bit targets const uint8_t *ivarLayout; const char *name; const struct _method_list_t *baseMethods; const struct _protocol_list_t *baseProtocols; const struct _ivar_list_t *ivars; const uint8_t *weakIvarLayout; const struct _prop_list_t *properties; } struct _class_t { struct _class_t *isa; struct _class_t *superclass; void *cache; IMP *vtable; struct _class_ro_t *ro; } struct _category_t { const char *name; struct _class_t *cls; const struct _method_list_t *instance_methods; const struct _method_list_t *class_methods; const struct _protocol_list_t *protocols; const struct _prop_list_t *properties; } MessageRefTy - LLVM for: struct _message_ref_t { IMP messenger; SEL name; }; SuperMessageRefTy - LLVM for: struct _super_message_ref_t { SUPER_IMP messenger; SEL name; };

Definition at line 6191 of file RewriteModernObjC.cpp.

References clang::ASTContext::getTargetInfo(), and clang::TargetInfo::getTriple().

Referenced by hasObjCExceptionAttribute(), and Write__ivar_list_t_initializer().