diff options
Diffstat (limited to 'gnu/llvm/tools/clang/lib/Frontend/Rewrite')
5 files changed, 119 insertions, 256 deletions
diff --git a/gnu/llvm/tools/clang/lib/Frontend/Rewrite/FrontendActions.cpp b/gnu/llvm/tools/clang/lib/Frontend/Rewrite/FrontendActions.cpp index 8cf8adf37ed..13d410e2138 100644 --- a/gnu/llvm/tools/clang/lib/Frontend/Rewrite/FrontendActions.cpp +++ b/gnu/llvm/tools/clang/lib/Frontend/Rewrite/FrontendActions.cpp @@ -23,6 +23,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include <memory> +#include <utility> using namespace clang; @@ -32,8 +33,9 @@ using namespace clang; std::unique_ptr<ASTConsumer> HTMLPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { - if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile)) - return CreateHTMLPrinter(OS, CI.getPreprocessor()); + if (std::unique_ptr<raw_ostream> OS = + CI.createDefaultOutputFile(false, InFile)) + return CreateHTMLPrinter(std::move(OS), CI.getPreprocessor()); return nullptr; } @@ -60,8 +62,8 @@ class FixItActionSuffixInserter : public FixItOptions { public: FixItActionSuffixInserter(std::string NewSuffix, bool FixWhatYouCan) - : NewSuffix(NewSuffix) { - this->FixWhatYouCan = FixWhatYouCan; + : NewSuffix(std::move(NewSuffix)) { + this->FixWhatYouCan = FixWhatYouCan; } std::string RewriteFilename(const std::string &Filename, int &fd) override { @@ -151,15 +153,15 @@ bool FixItRecompile::BeginInvocation(CompilerInstance &CI) { std::unique_ptr<ASTConsumer> RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { - if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile, "cpp")) { + if (std::unique_ptr<raw_ostream> OS = + CI.createDefaultOutputFile(false, InFile, "cpp")) { if (CI.getLangOpts().ObjCRuntime.isNonFragile()) - return CreateModernObjCRewriter(InFile, OS, - CI.getDiagnostics(), CI.getLangOpts(), - CI.getDiagnosticOpts().NoRewriteMacros, - (CI.getCodeGenOpts().getDebugInfo() != - CodeGenOptions::NoDebugInfo)); - return CreateObjCRewriter(InFile, OS, - CI.getDiagnostics(), CI.getLangOpts(), + return CreateModernObjCRewriter( + InFile, std::move(OS), CI.getDiagnostics(), CI.getLangOpts(), + CI.getDiagnosticOpts().NoRewriteMacros, + (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo)); + return CreateObjCRewriter(InFile, std::move(OS), CI.getDiagnostics(), + CI.getLangOpts(), CI.getDiagnosticOpts().NoRewriteMacros); } return nullptr; @@ -173,25 +175,28 @@ RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { void RewriteMacrosAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); - raw_ostream *OS = CI.createDefaultOutputFile(true, getCurrentFile()); + std::unique_ptr<raw_ostream> OS = + CI.createDefaultOutputFile(true, getCurrentFile()); if (!OS) return; - RewriteMacrosInInput(CI.getPreprocessor(), OS); + RewriteMacrosInInput(CI.getPreprocessor(), OS.get()); } void RewriteTestAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); - raw_ostream *OS = CI.createDefaultOutputFile(false, getCurrentFile()); + std::unique_ptr<raw_ostream> OS = + CI.createDefaultOutputFile(false, getCurrentFile()); if (!OS) return; - DoRewriteTest(CI.getPreprocessor(), OS); + DoRewriteTest(CI.getPreprocessor(), OS.get()); } void RewriteIncludesAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); - raw_ostream *OS = CI.createDefaultOutputFile(true, getCurrentFile()); + std::unique_ptr<raw_ostream> OS = + CI.createDefaultOutputFile(true, getCurrentFile()); if (!OS) return; - RewriteIncludesInInput(CI.getPreprocessor(), OS, + RewriteIncludesInInput(CI.getPreprocessor(), OS.get(), CI.getPreprocessorOutputOpts()); } diff --git a/gnu/llvm/tools/clang/lib/Frontend/Rewrite/HTMLPrint.cpp b/gnu/llvm/tools/clang/lib/Frontend/Rewrite/HTMLPrint.cpp index 22ccfe6936b..f5fad346124 100644 --- a/gnu/llvm/tools/clang/lib/Frontend/Rewrite/HTMLPrint.cpp +++ b/gnu/llvm/tools/clang/lib/Frontend/Rewrite/HTMLPrint.cpp @@ -32,14 +32,14 @@ using namespace clang; namespace { class HTMLPrinter : public ASTConsumer { Rewriter R; - raw_ostream *Out; + std::unique_ptr<raw_ostream> Out; Preprocessor &PP; bool SyntaxHighlight, HighlightMacros; public: - HTMLPrinter(raw_ostream *OS, Preprocessor &pp, + HTMLPrinter(std::unique_ptr<raw_ostream> OS, Preprocessor &pp, bool _SyntaxHighlight, bool _HighlightMacros) - : Out(OS), PP(pp), SyntaxHighlight(_SyntaxHighlight), + : Out(std::move(OS)), PP(pp), SyntaxHighlight(_SyntaxHighlight), HighlightMacros(_HighlightMacros) {} void Initialize(ASTContext &context) override; @@ -47,11 +47,10 @@ namespace { }; } -std::unique_ptr<ASTConsumer> clang::CreateHTMLPrinter(raw_ostream *OS, - Preprocessor &PP, - bool SyntaxHighlight, - bool HighlightMacros) { - return llvm::make_unique<HTMLPrinter>(OS, PP, SyntaxHighlight, +std::unique_ptr<ASTConsumer> +clang::CreateHTMLPrinter(std::unique_ptr<raw_ostream> OS, Preprocessor &PP, + bool SyntaxHighlight, bool HighlightMacros) { + return llvm::make_unique<HTMLPrinter>(std::move(OS), PP, SyntaxHighlight, HighlightMacros); } diff --git a/gnu/llvm/tools/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp b/gnu/llvm/tools/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp index ca8226251fd..b761c34fcbd 100644 --- a/gnu/llvm/tools/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp +++ b/gnu/llvm/tools/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp @@ -450,7 +450,9 @@ bool InclusionRewriter::Process(FileID FileId, WriteLineInfo(FileName, Line - 1, FileType, ""); StringRef LineInfoExtra; SourceLocation Loc = HashToken.getLocation(); - if (const Module *Mod = FindModuleAtLocation(Loc)) + if (const Module *Mod = PP.getLangOpts().ObjC2 + ? FindModuleAtLocation(Loc) + : nullptr) WriteImplicitModuleImport(Mod); else if (const IncludedFile *Inc = FindIncludeAtLocation(Loc)) { // include and recursively process the file diff --git a/gnu/llvm/tools/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/gnu/llvm/tools/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp index be68d42affa..ad217517d7d 100644 --- a/gnu/llvm/tools/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/gnu/llvm/tools/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -72,7 +72,7 @@ namespace { Stmt *CurrentBody; ParentMap *PropParentMap; // created lazily. std::string InFileName; - raw_ostream* OutFile; + std::unique_ptr<raw_ostream> OutFile; std::string Preamble; TypeDecl *ProtocolTypeDecl; @@ -135,7 +135,6 @@ namespace { SmallVector<DeclRefExpr *, 32> BlockDeclRefs; - // Block related declarations. SmallVector<ValueDecl *, 8> BlockByCopyDecls; llvm::SmallPtrSet<ValueDecl *, 8> BlockByCopyDeclsPtrSet; @@ -186,6 +185,7 @@ namespace { public: llvm::DenseMap<ObjCMethodDecl*, std::string> MethodInternalNames; + // Top Level Driver code. bool HandleTopLevelDecl(DeclGroupRef D) override { for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { @@ -235,14 +235,13 @@ namespace { RewriteObjCQualifiedInterfaceTypes(TD); } } - return; } void HandleTopLevelSingleDecl(Decl *D); void HandleDeclInMainFile(Decl *D); - RewriteModernObjC(std::string inFile, raw_ostream *OS, - DiagnosticsEngine &D, const LangOptions &LOpts, - bool silenceMacroWarn, bool LineInfo); + RewriteModernObjC(std::string inFile, std::unique_ptr<raw_ostream> OS, + DiagnosticsEngine &D, const LangOptions &LOpts, + bool silenceMacroWarn, bool LineInfo); ~RewriteModernObjC() override {} @@ -367,7 +366,6 @@ namespace { Stmt *RewriteContinueStmt(ContinueStmt *S); void RewriteCastExpr(CStyleCastExpr *CE); void RewriteImplicitCastObjCExpr(CastExpr *IE); - void RewriteLinkageSpec(LinkageSpecDecl *LSD); // Computes ivar bitfield group no. unsigned ObjCIvarBitfieldGroupNo(ObjCIvarDecl *IV); @@ -448,9 +446,6 @@ namespace { std::string &Result); void RewriteObjCProtocolMetaData(ObjCProtocolDecl *Protocol, std::string &Result); - void RewriteObjCProtocolListMetaData( - const ObjCList<ObjCProtocolDecl> &Prots, - StringRef prefix, StringRef ClassName, std::string &Result); void RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, std::string &Result); void RewriteClassSetupInitHook(std::string &Result); @@ -523,7 +518,6 @@ namespace { QualType getSuperStructType(); QualType getConstantStringStructType(); QualType convertFunctionTypeOfBlocks(const FunctionType *FT); - bool BufferContainsPPDirectives(const char *startBuf, const char *endBuf); void convertToUnqualifiedObjCType(QualType &T) { if (T->isObjCQualifiedIdType()) { @@ -562,6 +556,7 @@ namespace { } return false; } + bool PointerTypeTakesAnyBlockArguments(QualType QT); bool PointerTypeTakesAnyObjCQualifiedType(QualType QT); void GetExtentOfArgList(const char *Name, const char *&LParen, @@ -608,8 +603,7 @@ namespace { /*Pascal=*/false, StrType, SourceLocation()); } }; - -} +} // end anonymous namespace void RewriteModernObjC::RewriteBlocksInFunctionProtoType(QualType funcType, NamedDecl *D) { @@ -644,12 +638,13 @@ static bool IsHeaderFile(const std::string &Filename) { return Ext == "h" || Ext == "hh" || Ext == "H"; } -RewriteModernObjC::RewriteModernObjC(std::string inFile, raw_ostream* OS, - DiagnosticsEngine &D, const LangOptions &LOpts, - bool silenceMacroWarn, - bool LineInfo) - : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(OS), - SilenceRewriteMacroWarning(silenceMacroWarn), GenerateLineInfo(LineInfo) { +RewriteModernObjC::RewriteModernObjC(std::string inFile, + std::unique_ptr<raw_ostream> OS, + DiagnosticsEngine &D, + const LangOptions &LOpts, + bool silenceMacroWarn, bool LineInfo) + : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(std::move(OS)), + SilenceRewriteMacroWarning(silenceMacroWarn), GenerateLineInfo(LineInfo) { IsHeader = IsHeaderFile(inFile); RewriteFailedDiag = Diags.getCustomDiagID(DiagnosticsEngine::Warning, "rewriting sub-expression within a macro (may not be correct)"); @@ -665,10 +660,12 @@ RewriteModernObjC::RewriteModernObjC(std::string inFile, raw_ostream* OS, } std::unique_ptr<ASTConsumer> clang::CreateModernObjCRewriter( - const std::string &InFile, raw_ostream *OS, DiagnosticsEngine &Diags, - const LangOptions &LOpts, bool SilenceRewriteMacroWarning, bool LineInfo) { - return llvm::make_unique<RewriteModernObjC>( - InFile, OS, Diags, LOpts, SilenceRewriteMacroWarning, LineInfo); + const std::string &InFile, std::unique_ptr<raw_ostream> OS, + DiagnosticsEngine &Diags, const LangOptions &LOpts, + bool SilenceRewriteMacroWarning, bool LineInfo) { + return llvm::make_unique<RewriteModernObjC>(InFile, std::move(OS), Diags, + LOpts, SilenceRewriteMacroWarning, + LineInfo); } void RewriteModernObjC::InitializeCommon(ASTContext &context) { @@ -743,10 +740,6 @@ void RewriteModernObjC::HandleTopLevelSingleDecl(Decl *D) { if (PD->isThisDeclarationADefinition()) RewriteProtocolDecl(PD); } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) { - // FIXME. This will not work in all situations and leaving it out - // is harmless. - // RewriteLinkageSpec(LSD); - // Recurse into linkage specifications for (DeclContext::decl_iterator DI = LSD->decls_begin(), DIEnd = LSD->decls_end(); @@ -853,7 +846,6 @@ RewriteModernObjC::getIvarAccessString(ObjCIvarDecl *D) { else WriteInternalIvarName(ClassDecl, D, IvarOffsetName); - std::string S = "(*("; QualType IvarT = D->getType(); if (D->isBitField()) @@ -1068,11 +1060,11 @@ static void RewriteOneForwardClassDecl(ObjCInterfaceDecl *ForwardDecl, void RewriteModernObjC::RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl, const std::string &typedefString) { - SourceLocation startLoc = ClassDecl->getLocStart(); - const char *startBuf = SM->getCharacterData(startLoc); - const char *semiPtr = strchr(startBuf, ';'); - // Replace the @class with typedefs corresponding to the classes. - ReplaceText(startLoc, semiPtr-startBuf+1, typedefString); + SourceLocation startLoc = ClassDecl->getLocStart(); + const char *startBuf = SM->getCharacterData(startLoc); + const char *semiPtr = strchr(startBuf, ';'); + // Replace the @class with typedefs corresponding to the classes. + ReplaceText(startLoc, semiPtr-startBuf+1, typedefString); } void RewriteModernObjC::RewriteForwardClassDecl(DeclGroupRef D) { @@ -1147,7 +1139,7 @@ void RewriteModernObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) { ReplaceText(LocStart, 0, "// "); } - for (auto *I : CatDecl->properties()) + for (auto *I : CatDecl->instance_properties()) RewriteProperty(I); for (auto *I : CatDecl->instance_methods()) @@ -1171,7 +1163,7 @@ void RewriteModernObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { RewriteMethodDeclaration(I); for (auto *I : PDecl->class_methods()) RewriteMethodDeclaration(I); - for (auto *I : PDecl->properties()) + for (auto *I : PDecl->instance_properties()) RewriteProperty(I); // Lastly, comment out the @end. @@ -1212,22 +1204,6 @@ RewriteModernObjC::RewriteForwardProtocolDecl(const SmallVectorImpl<Decl *> &DG) ReplaceText(LocStart, 0, "// "); } -void -RewriteModernObjC::RewriteLinkageSpec(LinkageSpecDecl *LSD) { - SourceLocation LocStart = LSD->getExternLoc(); - if (LocStart.isInvalid()) - llvm_unreachable("Invalid extern SourceLocation"); - - ReplaceText(LocStart, 0, "// "); - if (!LSD->hasBraces()) - return; - // FIXME. We don't rewrite well if '{' is not on same line as 'extern'. - SourceLocation LocRBrace = LSD->getRBraceLoc(); - if (LocRBrace.isInvalid()) - llvm_unreachable("Invalid rbrace SourceLocation"); - ReplaceText(LocRBrace, 0, "// "); -} - void RewriteModernObjC::RewriteTypeIntoString(QualType T, std::string &ResultStr, const FunctionType *&FPRetType) { if (T->isObjCQualifiedIdType()) @@ -1313,7 +1289,7 @@ void RewriteModernObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl, ResultStr += " _cmd"; // Method arguments. - for (const auto *PDecl : OMD->params()) { + for (const auto *PDecl : OMD->parameters()) { ResultStr += ", "; if (PDecl->getType()->isObjCQualifiedIdType()) { ResultStr += "id "; @@ -1354,6 +1330,7 @@ void RewriteModernObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl, } } } + void RewriteModernObjC::RewriteImplementationDecl(Decl *OID) { ObjCImplementationDecl *IMD = dyn_cast<ObjCImplementationDecl>(OID); ObjCCategoryImplDecl *CID = dyn_cast<ObjCCategoryImplDecl>(OID); @@ -1417,7 +1394,7 @@ void RewriteModernObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) { // Mark this typedef as having been written into its c++ equivalent. ObjCWrittenInterfaces.insert(ClassDecl->getCanonicalDecl()); - for (auto *I : ClassDecl->properties()) + for (auto *I : ClassDecl->instance_properties()) RewriteProperty(I); for (auto *I : ClassDecl->instance_methods()) RewriteMethodDeclaration(I); @@ -1940,7 +1917,6 @@ void RewriteModernObjC::WarnAboutReturnGotoStmts(Stmt *S) Diags.Report(Context->getFullLoc(S->getLocStart()), TryFinallyContainsReturnDiag); } - return; } Stmt *RewriteModernObjC::RewriteObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) { @@ -2809,11 +2785,10 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { Context->UnsignedIntTy, SourceLocation()); MsgExprs.push_back(cnt); - SmallVector<QualType, 4> ArgTypes; ArgTypes.push_back(Context->getObjCClassType()); ArgTypes.push_back(Context->getObjCSelType()); - for (const auto *PI : ArrayMethod->params()) + for (const auto *PI : ArrayMethod->parameters()) ArgTypes.push_back(PI->getType()); QualType returnType = Exp->getType(); @@ -2921,8 +2896,6 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral CK_BitCast, DictLiteralKeyME); - - // Synthesize a call to objc_msgSend(). SmallVector<Expr*, 32> MsgExprs; SmallVector<Expr*, 4> ClsExprs; @@ -2959,11 +2932,10 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral Context->UnsignedIntTy, SourceLocation()); MsgExprs.push_back(cnt); - SmallVector<QualType, 8> ArgTypes; ArgTypes.push_back(Context->getObjCClassType()); ArgTypes.push_back(Context->getObjCSelType()); - for (const auto *PI : DictMethod->params()) { + for (const auto *PI : DictMethod->parameters()) { QualType T = PI->getType(); if (const PointerType* PT = T->getAs<PointerType>()) { QualType PointeeTy = PT->getPointeeType(); @@ -3176,7 +3148,6 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla str += "\t memset((void*)&s, 0, sizeof(s));\n"; str += "\t else\n"; - str += "\t s = (("; str += castType.getAsString(Context->getPrintingPolicy()); str += ")(void *)objc_msgSend_stret)(receiver, sel"; for (unsigned i = 2; i < ArgTypes.size(); i++) { @@ -3188,7 +3159,6 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla } str += ");\n"; - str += "\t}\n"; str += "\t"; str += returnType.getAsString(Context->getPrintingPolicy()); str += " s;\n"; @@ -3530,7 +3500,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ArgTypes.push_back(Context->getObjCSelType()); if (ObjCMethodDecl *OMD = Exp->getMethodDecl()) { // Push any user argument types. - for (const auto *PI : OMD->params()) { + for (const auto *PI : OMD->parameters()) { QualType t = PI->getType()->isObjCQualifiedIdType() ? Context->getObjCIdType() : PI->getType(); @@ -3635,33 +3605,6 @@ Stmt *RewriteModernObjC::RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp) { ProtocolExprDecls.insert(Exp->getProtocol()->getCanonicalDecl()); // delete Exp; leak for now, see RewritePropertyOrImplicitSetter() usage for more info. return castExpr; - -} - -bool RewriteModernObjC::BufferContainsPPDirectives(const char *startBuf, - const char *endBuf) { - while (startBuf < endBuf) { - if (*startBuf == '#') { - // Skip whitespace. - for (++startBuf; startBuf[0] == ' ' || startBuf[0] == '\t'; ++startBuf) - ; - if (!strncmp(startBuf, "if", strlen("if")) || - !strncmp(startBuf, "ifdef", strlen("ifdef")) || - !strncmp(startBuf, "ifndef", strlen("ifndef")) || - !strncmp(startBuf, "define", strlen("define")) || - !strncmp(startBuf, "undef", strlen("undef")) || - !strncmp(startBuf, "else", strlen("else")) || - !strncmp(startBuf, "elif", strlen("elif")) || - !strncmp(startBuf, "endif", strlen("endif")) || - !strncmp(startBuf, "pragma", strlen("pragma")) || - !strncmp(startBuf, "include", strlen("include")) || - !strncmp(startBuf, "import", strlen("import")) || - !strncmp(startBuf, "include_next", strlen("include_next"))) - return true; - } - startBuf++; - } - return false; } /// IsTagDefinedInsideClass - This routine checks that a named tagged type @@ -3688,7 +3631,6 @@ bool RewriteModernObjC::IsTagDefinedInsideClass(ObjCContainerDecl *IDecl, TagLocation = ED->getLocation(); return Context->getSourceManager().isBeforeInTranslationUnit( IDecl->getLocation(), TagLocation); - } return false; } @@ -3820,7 +3762,6 @@ void RewriteModernObjC::RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDec if (IsNamedDefinition) GlobalDefinedTags.insert(TD); } - } unsigned RewriteModernObjC::ObjCIvarBitfieldGroupNo(ObjCIvarDecl *IV) { @@ -3911,7 +3852,6 @@ void RewriteModernObjC::ObjCIvarBitfieldGroupDecl(ObjCIvarDecl *IV, Result += "__GRBF_"; unsigned GroupNo = ObjCIvarBitfieldGroupNo(IV); Result += utostr(GroupNo); - return; } /// ObjCIvarBitfieldGroupType - Names struct type for ivar bitfield group. @@ -3924,7 +3864,6 @@ void RewriteModernObjC::ObjCIvarBitfieldGroupType(ObjCIvarDecl *IV, Result += "__T_"; unsigned GroupNo = ObjCIvarBitfieldGroupNo(IV); Result += utostr(GroupNo); - return; } /// ObjCIvarBitfieldGroupOffset - Names symbol for ivar bitfield group field offset. @@ -4063,7 +4002,6 @@ void RewriteModernObjC::RewriteIvarOffsetSymbols(ObjCInterfaceDecl *CDecl, // Meta Data Emission //===----------------------------------------------------------------------===// - /// RewriteImplementations - This routine rewrites all method implementations /// and emits meta-data. @@ -4543,8 +4481,6 @@ void RewriteModernObjC::GetBlockDeclRefExprs(Stmt *S) { HasLocalVariableExternalStorage(DRE->getDecl())) // FIXME: Handle enums. BlockDeclRefs.push_back(DRE); - - return; } void RewriteModernObjC::GetInnerBlockDeclRefExprs(Stmt *S, @@ -4572,8 +4508,6 @@ void RewriteModernObjC::GetInnerBlockDeclRefExprs(Stmt *S, ImportedLocalExternalDecls.insert(Var); } } - - return; } /// convertObjCTypeToCStyleType - This routine converts such objc types @@ -4658,7 +4592,7 @@ Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp = dyn_cast<PseudoObjectExpr>(BlockExp)) { CPT = POE->getType()->castAs<BlockPointerType>(); } else { - assert(1 && "RewriteBlockClass: Bad type"); + assert(false && "RewriteBlockClass: Bad type"); } assert(CPT && "RewriteBlockClass: Bad type"); const FunctionType *FT = CPT->getPointeeType()->getAs<FunctionType>(); @@ -4828,7 +4762,6 @@ void RewriteModernObjC::RewriteCastExpr(CStyleCastExpr *CE) { break; } } - return; } void RewriteModernObjC::RewriteImplicitCastObjCExpr(CastExpr *IC) { @@ -4844,8 +4777,6 @@ void RewriteModernObjC::RewriteImplicitCastObjCExpr(CastExpr *IC) { Str += TypeString; Str += ")"; InsertText(IC->getSubExpr()->getLocStart(), Str); - - return; } void RewriteModernObjC::RewriteBlockPointerFunctionArgs(FunctionDecl *FD) { @@ -4880,7 +4811,6 @@ void RewriteModernObjC::RewriteBlockPointerFunctionArgs(FunctionDecl *FD) { break; } } - return; } bool RewriteModernObjC::PointerTypeTakesAnyBlockArguments(QualType QT) { @@ -5017,11 +4947,8 @@ void RewriteModernObjC::RewriteBlockPointerDecl(NamedDecl *ND) { OrigLength++; } ReplaceText(Start, OrigLength, buf); - - return; } - /// SynthesizeByrefCopyDestroyHelper - This routine synthesizes: /// void __Block_byref_id_object_copy(struct Block_byref_id_object *dst, /// struct Block_byref_id_object *src) { @@ -5242,7 +5169,6 @@ void RewriteModernObjC::RewriteByRefVar(VarDecl *ND, bool firstDecl, InsertText(separatorLoc, lastDecl ? "}" : "};\n"); } - return; } void RewriteModernObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) { @@ -5284,7 +5210,6 @@ FunctionDecl *RewriteModernObjC::SynthBlockInitFunctionDecl(StringRef name) { Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, const SmallVectorImpl<DeclRefExpr *> &InnerBlockDeclRefs) { - const BlockDecl *block = Exp->getBlockDecl(); Blocks.push_back(Exp); @@ -5292,7 +5217,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, CollectBlockDeclRefInfo(Exp); // Add inner imported variables now used in current block. - int countOfInnerDecls = 0; + int countOfInnerDecls = 0; if (!InnerBlockDeclRefs.empty()) { for (unsigned i = 0; i < InnerBlockDeclRefs.size(); i++) { DeclRefExpr *Exp = InnerBlockDeclRefs[i]; @@ -6995,7 +6920,8 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, PDecl->getNameAsString(), false); // Protocol's property metadata. - SmallVector<ObjCPropertyDecl *, 8> ProtocolProperties(PDecl->properties()); + SmallVector<ObjCPropertyDecl *, 8> ProtocolProperties( + PDecl->instance_properties()); Write_prop_list_t_initializer(*this, Context, Result, ProtocolProperties, /* Container */nullptr, "_OBJC_PROTOCOL_PROPERTIES_", @@ -7007,7 +6933,7 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, Result += "static "; Result += "struct _protocol_t _OBJC_PROTOCOL_"; Result += PDecl->getNameAsString(); - Result += " __attribute__ ((used, section (\"__DATA,__datacoal_nt,coalesced\"))) = {\n"; + Result += " __attribute__ ((used)) = {\n"; Result += "\t0,\n"; // id is; is null Result += "\t\""; Result += PDecl->getNameAsString(); Result += "\",\n"; if (SuperProtocols.size() > 0) { @@ -7072,52 +6998,6 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, // Mark this protocol as having been generated. if (!ObjCSynthesizedProtocols.insert(PDecl->getCanonicalDecl()).second) llvm_unreachable("protocol already synthesized"); - -} - -void RewriteModernObjC::RewriteObjCProtocolListMetaData( - const ObjCList<ObjCProtocolDecl> &Protocols, - StringRef prefix, StringRef ClassName, - std::string &Result) { - if (Protocols.empty()) return; - - for (unsigned i = 0; i != Protocols.size(); i++) - RewriteObjCProtocolMetaData(Protocols[i], Result); - - // Output the top lovel protocol meta-data for the class. - /* struct _objc_protocol_list { - struct _objc_protocol_list *next; - int protocol_count; - struct _objc_protocol *class_protocols[]; - } - */ - Result += "\n"; - if (LangOpts.MicrosoftExt) - Result += "__declspec(allocate(\".cat_cls_meth$B\")) "; - Result += "static struct {\n"; - Result += "\tstruct _objc_protocol_list *next;\n"; - Result += "\tint protocol_count;\n"; - Result += "\tstruct _objc_protocol *class_protocols["; - Result += utostr(Protocols.size()); - Result += "];\n} _OBJC_"; - Result += prefix; - Result += "_PROTOCOLS_"; - Result += ClassName; - Result += " __attribute__ ((used, section (\"__OBJC, __cat_cls_meth\")))= " - "{\n\t0, "; - Result += utostr(Protocols.size()); - Result += "\n"; - - Result += "\t,{&_OBJC_PROTOCOL_"; - Result += Protocols[0]->getNameAsString(); - Result += " \n"; - - for (unsigned i = 1; i != Protocols.size(); i++) { - Result += "\t ,&_OBJC_PROTOCOL_"; - Result += Protocols[i]->getNameAsString(); - Result += "\n"; - } - Result += "\t }\n};\n"; } /// hasObjCExceptionAttribute - Return true if this class or any super @@ -7208,19 +7088,18 @@ void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, IDecl->getNameAsString()); // Protocol's property metadata. - SmallVector<ObjCPropertyDecl *, 8> ClassProperties(CDecl->properties()); + SmallVector<ObjCPropertyDecl *, 8> ClassProperties( + CDecl->instance_properties()); Write_prop_list_t_initializer(*this, Context, Result, ClassProperties, /* Container */IDecl, "_OBJC_$_PROP_LIST_", CDecl->getNameAsString()); - // Data for initializing _class_ro_t metaclass meta-data uint32_t flags = CLS_META; std::string InstanceSize; std::string InstanceStart; - bool classIsHidden = CDecl->getVisibility() == HiddenVisibility; if (classIsHidden) flags |= OBJC2_CLS_HIDDEN; @@ -7288,7 +7167,6 @@ void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, if (ImplementationIsNonLazy(IDecl)) DefinedNonLazyClasses.push_back(CDecl); - } void RewriteModernObjC::RewriteClassSetupInitHook(std::string &Result) { @@ -7453,7 +7331,8 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, FullCategoryName); // Protocol's property metadata. - SmallVector<ObjCPropertyDecl *, 8> ClassProperties(CDecl->properties()); + SmallVector<ObjCPropertyDecl *, 8> ClassProperties( + CDecl->instance_properties()); Write_prop_list_t_initializer(*this, Context, Result, ClassProperties, /* Container */IDecl, "_OBJC_$_PROP_LIST_", @@ -7470,7 +7349,6 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, // Determine if this category is also "non-lazy". if (ImplementationIsNonLazy(IDecl)) DefinedNonLazyCategories.push_back(CDecl); - } void RewriteModernObjC::RewriteCategorySetupInitHook(std::string &Result) { @@ -7705,4 +7583,4 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { return Replacement; } -#endif +#endif // CLANG_ENABLE_OBJC_REWRITER diff --git a/gnu/llvm/tools/clang/lib/Frontend/Rewrite/RewriteObjC.cpp b/gnu/llvm/tools/clang/lib/Frontend/Rewrite/RewriteObjC.cpp index e0ddadb1230..5967e40bfed 100644 --- a/gnu/llvm/tools/clang/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/gnu/llvm/tools/clang/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -37,7 +37,6 @@ using llvm::utostr; namespace { class RewriteObjC : public ASTConsumer { protected: - enum { BLOCK_FIELD_IS_OBJECT = 3, /* id, NSObject, __attribute__((NSObject)), block, ... */ @@ -72,7 +71,7 @@ namespace { Stmt *CurrentBody; ParentMap *PropParentMap; // created lazily. std::string InFileName; - raw_ostream* OutFile; + std::unique_ptr<raw_ostream> OutFile; std::string Preamble; TypeDecl *ProtocolTypeDecl; @@ -158,14 +157,15 @@ namespace { : R(R), SavedValue(R.DisableReplaceStmt) { R.DisableReplaceStmt = true; } + ~DisableReplaceStmtScope() { R.DisableReplaceStmt = SavedValue; } }; + void InitializeCommon(ASTContext &context); public: - // Top Level Driver code. bool HandleTopLevelDecl(DeclGroupRef D) override { for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { @@ -187,9 +187,10 @@ namespace { } return true; } + void HandleTopLevelSingleDecl(Decl *D); void HandleDeclInMainFile(Decl *D); - RewriteObjC(std::string inFile, raw_ostream *OS, + RewriteObjC(std::string inFile, std::unique_ptr<raw_ostream> OS, DiagnosticsEngine &D, const LangOptions &LOpts, bool silenceMacroWarn); @@ -505,12 +506,10 @@ namespace { class RewriteObjCFragileABI : public RewriteObjC { public: - - RewriteObjCFragileABI(std::string inFile, raw_ostream *OS, - DiagnosticsEngine &D, const LangOptions &LOpts, - bool silenceMacroWarn) : RewriteObjC(inFile, OS, - D, LOpts, - silenceMacroWarn) {} + RewriteObjCFragileABI(std::string inFile, std::unique_ptr<raw_ostream> OS, + DiagnosticsEngine &D, const LangOptions &LOpts, + bool silenceMacroWarn) + : RewriteObjC(inFile, std::move(OS), D, LOpts, silenceMacroWarn) {} ~RewriteObjCFragileABI() override {} void Initialize(ASTContext &context) override; @@ -540,7 +539,7 @@ namespace { std::string &Result) override; Stmt *RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) override; }; -} +} // end anonymous namespace void RewriteObjC::RewriteBlocksInFunctionProtoType(QualType funcType, NamedDecl *D) { @@ -575,11 +574,11 @@ static bool IsHeaderFile(const std::string &Filename) { return Ext == "h" || Ext == "hh" || Ext == "H"; } -RewriteObjC::RewriteObjC(std::string inFile, raw_ostream* OS, +RewriteObjC::RewriteObjC(std::string inFile, std::unique_ptr<raw_ostream> OS, DiagnosticsEngine &D, const LangOptions &LOpts, bool silenceMacroWarn) - : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(OS), - SilenceRewriteMacroWarning(silenceMacroWarn) { + : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(std::move(OS)), + SilenceRewriteMacroWarning(silenceMacroWarn) { IsHeader = IsHeaderFile(inFile); RewriteFailedDiag = Diags.getCustomDiagID(DiagnosticsEngine::Warning, "rewriting sub-expression within a macro (may not be correct)"); @@ -590,11 +589,12 @@ RewriteObjC::RewriteObjC(std::string inFile, raw_ostream* OS, } std::unique_ptr<ASTConsumer> -clang::CreateObjCRewriter(const std::string &InFile, raw_ostream *OS, +clang::CreateObjCRewriter(const std::string &InFile, + std::unique_ptr<raw_ostream> OS, DiagnosticsEngine &Diags, const LangOptions &LOpts, bool SilenceRewriteMacroWarning) { - return llvm::make_unique<RewriteObjCFragileABI>(InFile, OS, Diags, LOpts, - SilenceRewriteMacroWarning); + return llvm::make_unique<RewriteObjCFragileABI>( + InFile, std::move(OS), Diags, LOpts, SilenceRewriteMacroWarning); } void RewriteObjC::InitializeCommon(ASTContext &context) { @@ -969,7 +969,7 @@ void RewriteObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) { // FIXME: handle category headers that are declared across multiple lines. ReplaceText(LocStart, 0, "// "); - for (auto *I : CatDecl->properties()) + for (auto *I : CatDecl->instance_properties()) RewriteProperty(I); for (auto *I : CatDecl->instance_methods()) RewriteMethodDeclaration(I); @@ -992,7 +992,7 @@ void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { RewriteMethodDeclaration(I); for (auto *I : PDecl->class_methods()) RewriteMethodDeclaration(I); - for (auto *I : PDecl->properties()) + for (auto *I : PDecl->instance_properties()) RewriteProperty(I); // Lastly, comment out the @end. @@ -1118,7 +1118,7 @@ void RewriteObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl, ResultStr += " _cmd"; // Method arguments. - for (const auto *PDecl : OMD->params()) { + for (const auto *PDecl : OMD->parameters()) { ResultStr += ", "; if (PDecl->getType()->isObjCQualifiedIdType()) { ResultStr += "id "; @@ -1159,6 +1159,7 @@ void RewriteObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl, } } } + void RewriteObjC::RewriteImplementationDecl(Decl *OID) { ObjCImplementationDecl *IMD = dyn_cast<ObjCImplementationDecl>(OID); ObjCCategoryImplDecl *CID = dyn_cast<ObjCCategoryImplDecl>(OID); @@ -1210,7 +1211,7 @@ void RewriteObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) { } RewriteObjCInternalStruct(ClassDecl, ResultStr); - for (auto *I : ClassDecl->properties()) + for (auto *I : ClassDecl->instance_properties()) RewriteProperty(I); for (auto *I : ClassDecl->instance_methods()) RewriteMethodDeclaration(I); @@ -1720,7 +1721,6 @@ void RewriteObjC::WarnAboutReturnGotoStmts(Stmt *S) Diags.Report(Context->getFullLoc(S->getLocStart()), TryFinallyContainsReturnDiag); } - return; } void RewriteObjC::HasReturnStmts(Stmt *S, bool &hasReturns) @@ -1730,32 +1730,29 @@ void RewriteObjC::HasReturnStmts(Stmt *S, bool &hasReturns) if (SubStmt) HasReturnStmts(SubStmt, hasReturns); - if (isa<ReturnStmt>(S)) - hasReturns = true; - return; + if (isa<ReturnStmt>(S)) + hasReturns = true; } void RewriteObjC::RewriteTryReturnStmts(Stmt *S) { - // Perform a bottom up traversal of all children. - for (Stmt *SubStmt : S->children()) - if (SubStmt) { - RewriteTryReturnStmts(SubStmt); - } - if (isa<ReturnStmt>(S)) { - SourceLocation startLoc = S->getLocStart(); - const char *startBuf = SM->getCharacterData(startLoc); - - const char *semiBuf = strchr(startBuf, ';'); - assert((*semiBuf == ';') && "RewriteTryReturnStmts: can't find ';'"); - SourceLocation onePastSemiLoc = startLoc.getLocWithOffset(semiBuf-startBuf+1); + // Perform a bottom up traversal of all children. + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + RewriteTryReturnStmts(SubStmt); + } + if (isa<ReturnStmt>(S)) { + SourceLocation startLoc = S->getLocStart(); + const char *startBuf = SM->getCharacterData(startLoc); + const char *semiBuf = strchr(startBuf, ';'); + assert((*semiBuf == ';') && "RewriteTryReturnStmts: can't find ';'"); + SourceLocation onePastSemiLoc = startLoc.getLocWithOffset(semiBuf-startBuf+1); - std::string buf; - buf = "{ objc_exception_try_exit(&_stack); return"; + std::string buf; + buf = "{ objc_exception_try_exit(&_stack); return"; - ReplaceText(startLoc, 6, buf); - InsertText(onePastSemiLoc, "}"); - } - return; + ReplaceText(startLoc, 6, buf); + InsertText(onePastSemiLoc, "}"); + } } void RewriteObjC::RewriteSyncReturnStmts(Stmt *S, std::string syncExitBuf) { @@ -1780,7 +1777,6 @@ void RewriteObjC::RewriteSyncReturnStmts(Stmt *S, std::string syncExitBuf) { ReplaceText(startLoc, 6, buf); InsertText(onePastSemiLoc, "}"); } - return; } Stmt *RewriteObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { @@ -2287,7 +2283,6 @@ void RewriteObjC::RewriteBlockPointerTypeVariable(std::string& Str, } } - void RewriteObjC::RewriteBlockLiteralFunctionDecl(FunctionDecl *FD) { SourceLocation FunLocStart = FD->getTypeSpecStartLoc(); const FunctionType *funcType = FD->getType()->getAs<FunctionType>(); @@ -2615,10 +2610,8 @@ CallExpr *RewriteObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavo CallExpr *STCE = new (Context) CallExpr( *Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, SourceLocation()); return STCE; - } - Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, SourceLocation StartLoc, SourceLocation EndLoc) { @@ -2924,7 +2917,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ArgTypes.push_back(Context->getObjCSelType()); if (ObjCMethodDecl *OMD = Exp->getMethodDecl()) { // Push any user argument types. - for (const auto *PI : OMD->params()) { + for (const auto *PI : OMD->parameters()) { QualType t = PI->getType()->isObjCQualifiedIdType() ? Context->getObjCIdType() : PI->getType(); @@ -3059,7 +3052,6 @@ Stmt *RewriteObjC::RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp) { ProtocolExprDecls.insert(Exp->getProtocol()->getCanonicalDecl()); // delete Exp; leak for now, see RewritePropertyOrImplicitSetter() usage for more info. return castExpr; - } bool RewriteObjC::BufferContainsPPDirectives(const char *startBuf, @@ -3224,7 +3216,6 @@ void RewriteObjC::RewriteObjCInternalStruct(ObjCInterfaceDecl *CDecl, // Meta Data Emission //===----------------------------------------------------------------------===// - /// RewriteImplementations - This routine rewrites all method implementations /// and emits meta-data. @@ -3665,8 +3656,6 @@ void RewriteObjC::GetBlockDeclRefExprs(Stmt *S) { HasLocalVariableExternalStorage(DRE->getDecl())) // FIXME: Handle enums. BlockDeclRefs.push_back(DRE); - - return; } void RewriteObjC::GetInnerBlockDeclRefExprs(Stmt *S, @@ -3694,8 +3683,6 @@ void RewriteObjC::GetInnerBlockDeclRefExprs(Stmt *S, ImportedLocalExternalDecls.insert(Var); } } - - return; } /// convertFunctionTypeOfBlocks - This routine converts a function type @@ -3761,7 +3748,7 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) { = dyn_cast<PseudoObjectExpr>(BlockExp)) { CPT = POE->getType()->castAs<BlockPointerType>(); } else { - assert(1 && "RewriteBlockClass: Bad type"); + assert(false && "RewriteBlockClass: Bad type"); } assert(CPT && "RewriteBlockClass: Bad type"); const FunctionType *FT = CPT->getPointeeType()->getAs<FunctionType>(); @@ -3931,7 +3918,6 @@ void RewriteObjC::RewriteCastExpr(CStyleCastExpr *CE) { break; } } - return; } void RewriteObjC::RewriteBlockPointerFunctionArgs(FunctionDecl *FD) { @@ -3966,7 +3952,6 @@ void RewriteObjC::RewriteBlockPointerFunctionArgs(FunctionDecl *FD) { break; } } - return; } bool RewriteObjC::PointerTypeTakesAnyBlockArguments(QualType QT) { @@ -4103,11 +4088,8 @@ void RewriteObjC::RewriteBlockPointerDecl(NamedDecl *ND) { OrigLength++; } ReplaceText(Start, OrigLength, buf); - - return; } - /// SynthesizeByrefCopyDestroyHelper - This routine synthesizes: /// void __Block_byref_id_object_copy(struct Block_byref_id_object *dst, /// struct Block_byref_id_object *src) { @@ -4328,7 +4310,6 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { InsertText(semiLoc, "}"); } - return; } void RewriteObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) { @@ -4494,7 +4475,6 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, Exp = new (Context) UnaryOperator(Exp, UO_AddrOf, QT, VK_RValue, OK_Ordinary, SourceLocation()); } - } InitExprs.push_back(Exp); } @@ -5241,7 +5221,6 @@ void RewriteObjCFragileABI::RewriteObjCProtocolMetaData( // Mark this protocol as having been generated. if (!ObjCSynthesizedProtocols.insert(PDecl->getCanonicalDecl()).second) llvm_unreachable("protocol already synthesized"); - } void RewriteObjCFragileABI::RewriteObjCProtocolListMetaData( @@ -5910,4 +5889,4 @@ Stmt *RewriteObjCFragileABI::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { return Replacement; } -#endif +#endif // CLANG_ENABLE_OBJC_REWRITER |
