#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 "clang/Rewrite/Frontend/ASTConsumers.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>
#if CLANG_ENABLE_OBJC_REWRITER
usingnamespaceclang;
RewriteBuffer;
utostr;
namespace {
class RewriteModernObjC : public ASTConsumer { … };
}
void RewriteModernObjC::RewriteBlocksInFunctionProtoType(QualType funcType,
NamedDecl *D) { … }
void RewriteModernObjC::CheckFunctionPointerDecl(QualType funcType, NamedDecl *ND) { … }
static bool IsHeaderFile(const std::string &Filename) { … }
RewriteModernObjC::RewriteModernObjC(std::string inFile,
std::unique_ptr<raw_ostream> OS,
DiagnosticsEngine &D,
const LangOptions &LOpts,
bool silenceMacroWarn, bool LineInfo)
: … { … }
std::unique_ptr<ASTConsumer> clang::CreateModernObjCRewriter(
const std::string &InFile, std::unique_ptr<raw_ostream> OS,
DiagnosticsEngine &Diags, const LangOptions &LOpts,
bool SilenceRewriteMacroWarning, bool LineInfo) { … }
void RewriteModernObjC::InitializeCommon(ASTContext &context) { … }
void RewriteModernObjC::HandleTopLevelSingleDecl(Decl *D) { … }
void RewriteModernObjC::RewriteInclude() { … }
static void WriteInternalIvarName(const ObjCInterfaceDecl *IDecl,
ObjCIvarDecl *IvarDecl, std::string &Result) { … }
std::string
RewriteModernObjC::getIvarAccessString(ObjCIvarDecl *D) { … }
static bool mustSynthesizeSetterGetterMethod(ObjCImplementationDecl *IMP,
ObjCPropertyDecl *PD,
bool getter) { … }
void RewriteModernObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID,
ObjCImplementationDecl *IMD,
ObjCCategoryImplDecl *CID) { … }
static void RewriteOneForwardClassDecl(ObjCInterfaceDecl *ForwardDecl,
std::string &typedefString) { … }
void RewriteModernObjC::RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl,
const std::string &typedefString) { … }
void RewriteModernObjC::RewriteForwardClassDecl(DeclGroupRef D) { … }
void RewriteModernObjC::RewriteForwardClassDecl(
const SmallVectorImpl<Decl *> &D) { … }
void RewriteModernObjC::RewriteMethodDeclaration(ObjCMethodDecl *Method) { … }
void RewriteModernObjC::RewriteProperty(ObjCPropertyDecl *prop) { … }
void RewriteModernObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) { … }
void RewriteModernObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { … }
void RewriteModernObjC::RewriteForwardProtocolDecl(DeclGroupRef D) { … }
void
RewriteModernObjC::RewriteForwardProtocolDecl(const SmallVectorImpl<Decl *> &DG) { … }
void RewriteModernObjC::RewriteTypeIntoString(QualType T, std::string &ResultStr,
const FunctionType *&FPRetType) { … }
void RewriteModernObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl,
ObjCMethodDecl *OMD,
std::string &ResultStr) { … }
void RewriteModernObjC::RewriteImplementationDecl(Decl *OID) { … }
void RewriteModernObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) { … }
Stmt *RewriteModernObjC::RewritePropertyOrImplicitSetter(PseudoObjectExpr *PseudoOp) { … }
Stmt *RewriteModernObjC::RewritePropertyOrImplicitGetter(PseudoObjectExpr *PseudoOp) { … }
void RewriteModernObjC::SynthCountByEnumWithState(std::string &buf) { … }
Stmt *RewriteModernObjC::RewriteBreakStmt(BreakStmt *S) { … }
void RewriteModernObjC::ConvertSourceLocationToLineDirective(
SourceLocation Loc,
std::string &LineString) { … }
Stmt *RewriteModernObjC::RewriteContinueStmt(ContinueStmt *S) { … }
Stmt *RewriteModernObjC::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S,
SourceLocation OrigEnd) { … }
static void Write_RethrowObject(std::string &buf) { … }
Stmt *RewriteModernObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) { … }
void RewriteModernObjC::WarnAboutReturnGotoStmts(Stmt *S)
{ … }
Stmt *RewriteModernObjC::RewriteObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) { … }
Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { … }
Stmt *RewriteModernObjC::RewriteObjCThrowStmt(ObjCAtThrowStmt *S) { … }
Stmt *RewriteModernObjC::RewriteAtEncode(ObjCEncodeExpr *Exp) { … }
Stmt *RewriteModernObjC::RewriteAtSelector(ObjCSelectorExpr *Exp) { … }
CallExpr *
RewriteModernObjC::SynthesizeCallToFunctionDecl(FunctionDecl *FD,
ArrayRef<Expr *> Args,
SourceLocation StartLoc,
SourceLocation EndLoc) { … }
static bool scanForProtocolRefs(const char *startBuf, const char *endBuf,
const char *&startRef, const char *&endRef) { … }
static void scanToNextArgument(const char *&argRef) { … }
bool RewriteModernObjC::needToScanForQualifiers(QualType T) { … }
void RewriteModernObjC::RewriteObjCQualifiedInterfaceTypes(Expr *E) { … }
void RewriteModernObjC::RewriteObjCQualifiedInterfaceTypes(Decl *Dcl) { … }
void RewriteModernObjC::RewriteTypeOfDecl(VarDecl *ND) { … }
void RewriteModernObjC::SynthSelGetUidFunctionDecl() { … }
void RewriteModernObjC::RewriteFunctionDecl(FunctionDecl *FD) { … }
void RewriteModernObjC::RewriteBlockPointerType(std::string& Str, QualType Type) { … }
void RewriteModernObjC::RewriteBlockPointerTypeVariable(std::string& Str,
ValueDecl *VD) { … }
void RewriteModernObjC::RewriteBlockLiteralFunctionDecl(FunctionDecl *FD) { … }
void RewriteModernObjC::SynthSuperConstructorFunctionDecl() { … }
void RewriteModernObjC::SynthMsgSendFunctionDecl() { … }
void RewriteModernObjC::SynthMsgSendSuperFunctionDecl() { … }
void RewriteModernObjC::SynthMsgSendStretFunctionDecl() { … }
void RewriteModernObjC::SynthMsgSendSuperStretFunctionDecl() { … }
void RewriteModernObjC::SynthMsgSendFpretFunctionDecl() { … }
void RewriteModernObjC::SynthGetClassFunctionDecl() { … }
void RewriteModernObjC::SynthGetSuperClassFunctionDecl() { … }
void RewriteModernObjC::SynthGetMetaClassFunctionDecl() { … }
Stmt *RewriteModernObjC::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) { … }
Stmt *RewriteModernObjC::RewriteObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Exp) { … }
Stmt *RewriteModernObjC::RewriteObjCBoxedExpr(ObjCBoxedExpr *Exp) { … }
Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { … }
Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral *Exp) { … }
QualType RewriteModernObjC::getSuperStructType() { … }
QualType RewriteModernObjC::getConstantStringStructType() { … }
static SourceLocation getFunctionSourceLocation (RewriteModernObjC &R,
FunctionDecl *FD) { … }
void RewriteModernObjC::RewriteLineDirective(const Decl *D) { … }
Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavor,
QualType returnType,
SmallVectorImpl<QualType> &ArgTypes,
SmallVectorImpl<Expr*> &MsgExprs,
ObjCMethodDecl *Method) { … }
Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp,
SourceLocation StartLoc,
SourceLocation EndLoc) { … }
Stmt *RewriteModernObjC::RewriteMessageExpr(ObjCMessageExpr *Exp) { … }
QualType RewriteModernObjC::getProtocolType() { … }
Stmt *RewriteModernObjC::RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp) { … }
bool RewriteModernObjC::IsTagDefinedInsideClass(ObjCContainerDecl *IDecl,
TagDecl *Tag,
bool &IsNamedDefinition) { … }
bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type,
std::string &Result) { … }
void RewriteModernObjC::RewriteObjCFieldDecl(FieldDecl *fieldDecl,
std::string &Result) { … }
void RewriteModernObjC::RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDecl,
std::string &Result) { … }
unsigned RewriteModernObjC::ObjCIvarBitfieldGroupNo(ObjCIvarDecl *IV) { … }
QualType RewriteModernObjC::SynthesizeBitfieldGroupStructType(
ObjCIvarDecl *IV,
SmallVectorImpl<ObjCIvarDecl *> &IVars) { … }
QualType RewriteModernObjC::GetGroupRecordTypeForObjCIvarBitfield(ObjCIvarDecl *IV) { … }
void RewriteModernObjC::ObjCIvarBitfieldGroupDecl(ObjCIvarDecl *IV,
std::string &Result) { … }
void RewriteModernObjC::ObjCIvarBitfieldGroupType(ObjCIvarDecl *IV,
std::string &Result) { … }
void RewriteModernObjC::ObjCIvarBitfieldGroupOffset(ObjCIvarDecl *IV,
std::string &Result) { … }
#define SKIP_BITFIELDS(IX, ENDIX, VEC) …
void RewriteModernObjC::RewriteObjCInternalStruct(ObjCInterfaceDecl *CDecl,
std::string &Result) { … }
void RewriteModernObjC::RewriteIvarOffsetSymbols(ObjCInterfaceDecl *CDecl,
std::string &Result) { … }
void RewriteModernObjC::RewriteImplementations() { … }
void RewriteModernObjC::RewriteByRefString(std::string &ResultStr,
const std::string &Name,
ValueDecl *VD, bool def) { … }
static bool HasLocalVariableExternalStorage(ValueDecl *VD) { … }
std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
StringRef funcName,
const std::string &Tag) { … }
std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(
BlockExpr *CE, int i, StringRef funcName, const std::string &Tag) { … }
std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
const std::string &Tag,
const std::string &Desc) { … }
std::string RewriteModernObjC::SynthesizeBlockDescriptor(
const std::string &DescTag, const std::string &ImplTag, int i,
StringRef FunName, unsigned hasCopy) { … }
void RewriteModernObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
StringRef FunName) { … }
void RewriteModernObjC::InsertBlockLiteralsWithinFunction(FunctionDecl *FD) { … }
static void BuildUniqueMethodName(std::string &Name,
ObjCMethodDecl *MD) { … }
void RewriteModernObjC::InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD) { … }
void RewriteModernObjC::GetBlockDeclRefExprs(Stmt *S) { … }
void RewriteModernObjC::GetInnerBlockDeclRefExprs(Stmt *S,
SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs,
llvm::SmallPtrSetImpl<const DeclContext *> &InnerContexts) { … }
bool RewriteModernObjC::convertObjCTypeToCStyleType(QualType &T) { … }
QualType RewriteModernObjC::convertFunctionTypeOfBlocks(const FunctionType *FT) { … }
Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) { … }
Stmt *RewriteModernObjC::RewriteBlockDeclRefExpr(DeclRefExpr *DeclRefExp) { … }
Stmt *RewriteModernObjC::RewriteLocalVariableExternalStorage(DeclRefExpr *DRE) { … }
void RewriteModernObjC::RewriteCastExpr(CStyleCastExpr *CE) { … }
void RewriteModernObjC::RewriteImplicitCastObjCExpr(CastExpr *IC) { … }
void RewriteModernObjC::RewriteBlockPointerFunctionArgs(FunctionDecl *FD) { … }
bool RewriteModernObjC::PointerTypeTakesAnyBlockArguments(QualType QT) { … }
bool RewriteModernObjC::PointerTypeTakesAnyObjCQualifiedType(QualType QT) { … }
void RewriteModernObjC::GetExtentOfArgList(const char *Name, const char *&LParen,
const char *&RParen) { … }
void RewriteModernObjC::RewriteBlockPointerDecl(NamedDecl *ND) { … }
std::string RewriteModernObjC::SynthesizeByrefCopyDestroyHelper(VarDecl *VD,
int flag) { … }
void RewriteModernObjC::RewriteByRefVar(VarDecl *ND, bool firstDecl,
bool lastDecl) { … }
void RewriteModernObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) { … }
FunctionDecl *RewriteModernObjC::SynthBlockInitFunctionDecl(StringRef name) { … }
Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,
const SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs) { … }
bool RewriteModernObjC::IsDeclStmtInForeachHeader(DeclStmt *DS) { … }
Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { … }
void RewriteModernObjC::RewriteRecordBody(RecordDecl *RD) { … }
void RewriteModernObjC::HandleDeclInMainFile(Decl *D) { … }
static void Write_ProtocolExprReferencedMetadata(ASTContext *Context,
ObjCProtocolDecl *PDecl,
std::string &Result) { … }
void RewriteModernObjC::HandleTranslationUnit(ASTContext &C) { … }
void RewriteModernObjC::Initialize(ASTContext &context) { … }
void RewriteModernObjC::RewriteIvarOffsetComputation(ObjCIvarDecl *ivar,
std::string &Result) { … }
static void WriteModernMetadataDeclarations(ASTContext *Context, std::string &Result) { … }
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) { … }
enum MetaDataDlags { … };
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) { … }
void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl,
std::string &Result) { … }
static bool hasObjCExceptionAttribute(ASTContext &Context,
const ObjCInterfaceDecl *OID) { … }
void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
std::string &Result) { … }
void RewriteModernObjC::RewriteClassSetupInitHook(std::string &Result) { … }
void RewriteModernObjC::RewriteMetaDataIntoBuffer(std::string &Result) { … }
void RewriteModernObjC::WriteImageInfo(std::string &Result) { … }
void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl,
std::string &Result) { … }
void RewriteModernObjC::RewriteCategorySetupInitHook(std::string &Result) { … }
template<typename MethodIterator>
void RewriteModernObjC::RewriteObjCMethodsMetaData(MethodIterator MethodBegin,
MethodIterator MethodEnd,
bool IsInstanceMethod,
StringRef prefix,
StringRef ClassName,
std::string &Result) { … }
Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { … }
#endif