clang  19.0.0git
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/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include <memory>

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 3866 of file RewriteModernObjC.cpp.

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 6391 of file RewriteModernObjC.cpp.

Function Documentation

◆ BuildUniqueMethodName()

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

Definition at line 4439 of file RewriteModernObjC.cpp.

◆ getFunctionSourceLocation()

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

getFunctionSourceLocation - returns start location of a function definition.

Complication arises when function has declared as extern "C" or extern "C" {...}

Definition at line 3043 of file RewriteModernObjC.cpp.

References clang::Decl::getDeclContext(), clang::FunctionDecl::getStorageClass(), clang::DeclaratorDecl::getTypeSpecStartLoc(), clang::FunctionDecl::isExternC(), clang::FunctionDecl::isMain(), and clang::SC_None.

◆ HasLocalVariableExternalStorage()

static bool HasLocalVariableExternalStorage ( ValueDecl VD)
static

Definition at line 4032 of file RewriteModernObjC.cpp.

◆ hasObjCExceptionAttribute()

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

hasObjCExceptionAttribute - Return true if this class or any super class has the objc_exception attribute.

FIXME. Move this to ASTContext.cpp as it is also used for IRGen.

Definition at line 6991 of file RewriteModernObjC.cpp.

◆ IsHeaderFile()

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

◆ mustSynthesizeSetterGetterMethod()

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

mustSynthesizeSetterGetterMethod - returns true if setter or getter has not been found in the class implementation.

In this case, it must be synthesized.

Definition at line 910 of file RewriteModernObjC.cpp.

References clang::ObjCPropertyDecl::getGetterName(), clang::ObjCContainerDecl::getInstanceMethod(), clang::ObjCPropertyDecl::getSetterName(), and clang::ObjCMethodDecl::isSynthesizedAccessorStub().

◆ RewriteOneForwardClassDecl()

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

Definition at line 1045 of file RewriteModernObjC.cpp.

References clang::NamedDecl::getNameAsString().

◆ scanForProtocolRefs()

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

Definition at line 2120 of file RewriteModernObjC.cpp.

◆ scanToNextArgument()

static void scanToNextArgument ( const char *&  argRef)
static

Definition at line 2137 of file RewriteModernObjC.cpp.

◆ 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

Definition at line 6404 of file RewriteModernObjC.cpp.

◆ Write__extendedMethodTypes_initializer()

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

Definition at line 6693 of file RewriteModernObjC.cpp.

◆ 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

Definition at line 6763 of file RewriteModernObjC.cpp.

◆ Write__ivar_list_t_TypeDecl()

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

Definition at line 6282 of file RewriteModernObjC.cpp.

◆ Write__prop_list_t_TypeDecl()

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

Definition at line 6272 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

Definition at line 6611 of file RewriteModernObjC.cpp.

◆ Write_class_t()

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

Definition at line 6471 of file RewriteModernObjC.cpp.

◆ 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 should be: HiddenVisibility; else Visibility should be: DefaultVisibility;

Definition at line 6720 of file RewriteModernObjC.cpp.

◆ 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

Definition at line 6315 of file RewriteModernObjC.cpp.

◆ Write_method_list_t_TypeDecl()

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

Definition at line 6262 of file RewriteModernObjC.cpp.

◆ 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 6355 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

Definition at line 6292 of file RewriteModernObjC.cpp.

◆ Write_protocol_list_t_TypeDecl()

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

Definition at line 6253 of file RewriteModernObjC.cpp.

◆ 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 5809 of file RewriteModernObjC.cpp.

◆ Write_RethrowObject()

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

Definition at line 1852 of file RewriteModernObjC.cpp.

◆ WriteInternalIvarName()

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

Definition at line 832 of file RewriteModernObjC.cpp.

◆ 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 6175 of file RewriteModernObjC.cpp.