diff options
author | ed <ed@FreeBSD.org> | 2009-07-04 13:58:54 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2009-07-04 13:58:54 +0000 |
commit | 4981926bf654fe5a2c3893f24ca44106b217e71e (patch) | |
tree | 8ddfe382e1c6d590dc240e76f7cd45cea5c78e24 /lib/Frontend | |
parent | c1ff020ff2d3e7ba86f7ab986ac7569c34f2ab1a (diff) | |
download | FreeBSD-src-4981926bf654fe5a2c3893f24ca44106b217e71e.zip FreeBSD-src-4981926bf654fe5a2c3893f24ca44106b217e71e.tar.gz |
Import Clang r74788.
Diffstat (limited to 'lib/Frontend')
-rw-r--r-- | lib/Frontend/ASTConsumers.cpp | 15 | ||||
-rw-r--r-- | lib/Frontend/AnalysisConsumer.cpp | 12 | ||||
-rw-r--r-- | lib/Frontend/Backend.cpp | 11 | ||||
-rw-r--r-- | lib/Frontend/DeclXML.cpp | 10 | ||||
-rw-r--r-- | lib/Frontend/InitHeaderSearch.cpp | 8 | ||||
-rw-r--r-- | lib/Frontend/InitPreprocessor.cpp | 9 | ||||
-rw-r--r-- | lib/Frontend/PCHReader.cpp | 14 | ||||
-rw-r--r-- | lib/Frontend/PCHReaderDecl.cpp | 2 | ||||
-rw-r--r-- | lib/Frontend/PCHReaderStmt.cpp | 1 | ||||
-rw-r--r-- | lib/Frontend/PCHWriter.cpp | 33 | ||||
-rw-r--r-- | lib/Frontend/PCHWriterDecl.cpp | 6 | ||||
-rw-r--r-- | lib/Frontend/PCHWriterStmt.cpp | 1 | ||||
-rw-r--r-- | lib/Frontend/ResolveLocation.cpp | 8 | ||||
-rw-r--r-- | lib/Frontend/RewriteBlocks.cpp | 33 | ||||
-rw-r--r-- | lib/Frontend/RewriteObjC.cpp | 131 |
15 files changed, 159 insertions, 135 deletions
diff --git a/lib/Frontend/ASTConsumers.cpp b/lib/Frontend/ASTConsumers.cpp index 5844be8..8f0ad13 100644 --- a/lib/Frontend/ASTConsumers.cpp +++ b/lib/Frontend/ASTConsumers.cpp @@ -44,7 +44,7 @@ namespace { virtual void HandleTranslationUnit(ASTContext &Context) { PrintingPolicy Policy = Context.PrintingPolicy; Policy.Dump = Dump; - Context.getTranslationUnitDecl()->print(Out, Context, Policy); + Context.getTranslationUnitDecl()->print(Out, Policy); } }; } // end anonymous namespace @@ -70,8 +70,8 @@ namespace { virtual void HandleTranslationUnit(ASTContext &Ctx) { Doc.addSubNode("TranslationUnit"); for (DeclContext::decl_iterator - D = Ctx.getTranslationUnitDecl()->decls_begin(Ctx), - DEnd = Ctx.getTranslationUnitDecl()->decls_end(Ctx); + D = Ctx.getTranslationUnitDecl()->decls_begin(), + DEnd = Ctx.getTranslationUnitDecl()->decls_end(); D != DEnd; ++D) { @@ -114,7 +114,7 @@ namespace { void ASTViewer::HandleTopLevelSingleDecl(Decl *D) { if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { - FD->print(llvm::errs(), *Context); + FD->print(llvm::errs()); if (FD->getBodyIfAvailable()) { llvm::cerr << '\n'; @@ -125,7 +125,7 @@ void ASTViewer::HandleTopLevelSingleDecl(Decl *D) { } if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { - MD->print(llvm::errs(), *Context); + MD->print(llvm::errs()); if (MD->getBody()) { llvm::cerr << '\n'; @@ -340,10 +340,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, Out << "\n"; // Print decls in the DeclContext. - // FIXME: Should not use a NULL DeclContext! - ASTContext *Context = 0; - for (DeclContext::decl_iterator I = DC->decls_begin(*Context), - E = DC->decls_end(*Context); + for (DeclContext::decl_iterator I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) { for (unsigned i = 0; i < Indentation; ++i) Out << " "; diff --git a/lib/Frontend/AnalysisConsumer.cpp b/lib/Frontend/AnalysisConsumer.cpp index d8fa141..06af2d9 100644 --- a/lib/Frontend/AnalysisConsumer.cpp +++ b/lib/Frontend/AnalysisConsumer.cpp @@ -307,7 +307,7 @@ void AnalysisConsumer::HandleTopLevelSingleDecl(Decl *D) { Opts.AnalyzeSpecificFunction != FD->getIdentifier()->getName()) break; - Stmt* Body = FD->getBody(*Ctx); + Stmt* Body = FD->getBody(); if (Body) HandleCode(FD, Body, FunctionActions); break; } @@ -341,8 +341,8 @@ void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) { if (!ObjCImplementationActions.empty()) { TranslationUnitDecl *TUD = C.getTranslationUnitDecl(); - for (DeclContext::decl_iterator I = TUD->decls_begin(C), - E = TUD->decls_end(C); + for (DeclContext::decl_iterator I = TUD->decls_begin(), + E = TUD->decls_end(); I != E; ++I) if (ObjCImplementationDecl* ID = dyn_cast<ObjCImplementationDecl>(*I)) HandleCode(ID, 0, ObjCImplementationActions); @@ -479,14 +479,16 @@ static void ActionDisplayLiveVariables(AnalysisManager& mgr) { static void ActionCFGDump(AnalysisManager& mgr) { if (CFG* c = mgr.getCFG()) { mgr.DisplayFunction(); - c->dump(); + LangOptions LO; // FIXME! + c->dump(LO); } } static void ActionCFGView(AnalysisManager& mgr) { if (CFG* c = mgr.getCFG()) { mgr.DisplayFunction(); - c->viewCFG(); + LangOptions LO; // FIXME! + c->viewCFG(LO); } } diff --git a/lib/Frontend/Backend.cpp b/lib/Frontend/Backend.cpp index d8f8625..1c536b0 100644 --- a/lib/Frontend/Backend.cpp +++ b/lib/Frontend/Backend.cpp @@ -75,13 +75,14 @@ namespace { public: BackendConsumer(BackendAction action, Diagnostic &Diags, const LangOptions &langopts, const CompileOptions &compopts, - const std::string &infile, llvm::raw_ostream* OS) : + const std::string &infile, llvm::raw_ostream* OS, + LLVMContext& C) : Action(action), CompileOpts(compopts), AsmOutStream(OS), LLVMIRGeneration("LLVM IR Generation Time"), CodeGenerationTime("Code Generation Time"), - Gen(CreateLLVMCodeGen(Diags, infile, compopts)), + Gen(CreateLLVMCodeGen(Diags, infile, compopts, C)), TheModule(0), TheTargetData(0), ModuleProvider(0), CodeGenPasses(0), PerModulePasses(0), PerFunctionPasses(0) { @@ -359,6 +360,8 @@ ASTConsumer *clang::CreateBackendConsumer(BackendAction Action, const LangOptions &LangOpts, const CompileOptions &CompileOpts, const std::string& InFile, - llvm::raw_ostream* OS) { - return new BackendConsumer(Action, Diags, LangOpts, CompileOpts, InFile, OS); + llvm::raw_ostream* OS, + LLVMContext& C) { + return new BackendConsumer(Action, Diags, LangOpts, CompileOpts, + InFile, OS, C); } diff --git a/lib/Frontend/DeclXML.cpp b/lib/Frontend/DeclXML.cpp index 5c21999..68f931f 100644 --- a/lib/Frontend/DeclXML.cpp +++ b/lib/Frontend/DeclXML.cpp @@ -34,8 +34,8 @@ class DocumentXML::DeclPrinter : public DeclVisitor<DocumentXML::DeclPrinter> void addSubNodes(RecordDecl* RD) { - for (RecordDecl::field_iterator i = RD->field_begin(*Doc.Ctx), e = RD->field_end(*Doc.Ctx); i != e; ++i) - { + for (RecordDecl::field_iterator i = RD->field_begin(), + e = RD->field_end(); i != e; ++i) { Visit(*i); Doc.toParent(); } @@ -43,8 +43,8 @@ class DocumentXML::DeclPrinter : public DeclVisitor<DocumentXML::DeclPrinter> void addSubNodes(EnumDecl* ED) { - for (EnumDecl::enumerator_iterator i = ED->enumerator_begin(*Doc.Ctx), e = ED->enumerator_end(*Doc.Ctx); i != e; ++i) - { + for (EnumDecl::enumerator_iterator i = ED->enumerator_begin(), + e = ED->enumerator_end(); i != e; ++i) { Visit(*i); Doc.toParent(); } @@ -147,7 +147,7 @@ void DocumentXML::writeDeclToXML(Decl *D) DeclPrinter(*this).Visit(D); if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { - if (Stmt *Body = FD->getBody(*Ctx)) { + if (Stmt *Body = FD->getBody()) { addSubNode("Body"); PrintStmt(Body); toParent(); diff --git a/lib/Frontend/InitHeaderSearch.cpp b/lib/Frontend/InitHeaderSearch.cpp index 7a2b3a7..8c80786 100644 --- a/lib/Frontend/InitHeaderSearch.cpp +++ b/lib/Frontend/InitHeaderSearch.cpp @@ -178,6 +178,14 @@ void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang) { AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/backward", System, true, false, false); + // Gentoo amd64 stable + AddPath("/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", System, + true, false, false); + AddPath("/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/" + "i686-pc-linux-gnu", System, true, false, false); + AddPath("/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/backward", + System, true, false, false); + // DragonFly AddPath("/usr/include/c++/4.1", System, true, false, false); diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 730414e..e41dfdd 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -383,7 +383,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI, // 16-bit targets doesn't necessarily have a 64-bit type. if (TI.getLongLongWidth() == 64) - DefineBuiltinMacro(Buf, "__INT64_TYPE__=long long"); + DefineType("__INT64_TYPE__", TI.getInt64Type(), Buf); // Add __builtin_va_list typedef. { @@ -423,7 +423,12 @@ static void InitializePredefinedMacros(const TargetInfo &TI, sprintf(MacroBuf, "__DECIMAL_DIG__=%d", PickFP(&TI.getLongDoubleFormat(), -1/*FIXME*/, 17, 21, 33, 36)); DefineBuiltinMacro(Buf, MacroBuf); - + + if (LangOpts.getStackProtectorMode() == LangOptions::SSPOn) + DefineBuiltinMacro(Buf, "__SSP__=1"); + else if (LangOpts.getStackProtectorMode() == LangOptions::SSPReq) + DefineBuiltinMacro(Buf, "__SSP_ALL__=2"); + // Get other target #defines. TI.getTargetDefines(LangOpts, Buf); } diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 765655b..95b1661 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -344,7 +344,8 @@ PCHReader::PCHReader(Preprocessor &PP, ASTContext *Context) IdentifierOffsets(0), MethodPoolLookupTable(0), MethodPoolLookupTableData(0), TotalSelectorsInMethodPool(0), SelectorOffsets(0), - TotalNumSelectors(0), NumStatHits(0), NumStatMisses(0), + TotalNumSelectors(0), Comments(0), NumComments(0), + NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), NumStatementsRead(0), NumMacrosRead(0), NumMethodPoolSelectorsRead(0), NumMethodPoolMisses(0), NumLexicalDeclContextsRead(0), NumVisibleDeclContextsRead(0) { } @@ -1350,6 +1351,11 @@ PCHReader::ReadPCHBlock() { case pch::ORIGINAL_FILE_NAME: OriginalFileName.assign(BlobStart, BlobLen); break; + + case pch::COMMENT_RANGES: + Comments = (SourceRange *)BlobStart; + NumComments = BlobLen / sizeof(SourceRange); + break; } } Error("premature end of bitstream in PCH file"); @@ -1664,6 +1670,12 @@ bool PCHReader::ParseLanguageOptions( return false; } +void PCHReader::ReadComments(std::vector<SourceRange> &Comments) { + Comments.resize(NumComments); + std::copy(this->Comments, this->Comments + NumComments, + Comments.begin()); +} + /// \brief Read and return the type at the given offset. /// /// This routine actually reads the record corresponding to the type diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp index 3f6ae35..15b54a2 100644 --- a/lib/Frontend/PCHReaderDecl.cpp +++ b/lib/Frontend/PCHReaderDecl.cpp @@ -80,7 +80,7 @@ void PCHDeclReader::VisitDecl(Decl *D) { D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); D->setInvalidDecl(Record[Idx++]); if (Record[Idx++]) - D->addAttr(*Reader.getContext(), Reader.ReadAttributes()); + D->addAttr(Reader.ReadAttributes()); D->setImplicit(Record[Idx++]); D->setUsed(Record[Idx++]); D->setAccess((AccessSpecifier)Record[Idx++]); diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp index d096388..eccb53b 100644 --- a/lib/Frontend/PCHReaderStmt.cpp +++ b/lib/Frontend/PCHReaderStmt.cpp @@ -1133,6 +1133,5 @@ Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) { StmtStack.push_back(S); } assert(StmtStack.size() == 1 && "Extra expressions on stack!"); - SwitchCaseStmts.clear(); return StmtStack.back(); } diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index e93219e..3bfc9e8 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -374,7 +374,8 @@ void PCHWriter::WriteBlockInfoBlock() { RECORD(STAT_CACHE); RECORD(EXT_VECTOR_DECLS); RECORD(OBJC_CATEGORY_IMPLEMENTATIONS); - + RECORD(COMMENT_RANGES); + // SourceManager Block. BLOCK(SOURCE_MANAGER_BLOCK); RECORD(SM_SLOC_FILE_ENTRY); @@ -989,6 +990,24 @@ void PCHWriter::WritePreprocessor(const Preprocessor &PP) { Stream.ExitBlock(); } +void PCHWriter::WriteComments(ASTContext &Context) { + using namespace llvm; + + if (Context.Comments.empty()) + return; + + BitCodeAbbrev *CommentAbbrev = new BitCodeAbbrev(); + CommentAbbrev->Add(BitCodeAbbrevOp(pch::COMMENT_RANGES)); + CommentAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); + unsigned CommentCode = Stream.EmitAbbrev(CommentAbbrev); + + RecordData Record; + Record.push_back(pch::COMMENT_RANGES); + Stream.EmitRecordWithBlob(CommentCode, Record, + (const char*)&Context.Comments[0], + Context.Comments.size() * sizeof(SourceRange)); +} + //===----------------------------------------------------------------------===// // Type Serialization //===----------------------------------------------------------------------===// @@ -1064,14 +1083,13 @@ void PCHWriter::WriteTypesBlock(ASTContext &Context) { /// bistream, or 0 if no block was written. uint64_t PCHWriter::WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC) { - if (DC->decls_empty(Context)) + if (DC->decls_empty()) return 0; uint64_t Offset = Stream.GetCurrentBitNo(); RecordData Record; - for (DeclContext::decl_iterator D = DC->decls_begin(Context), - DEnd = DC->decls_end(Context); - D != DEnd; ++D) + for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); + D != DEnd; ++D) AddDeclRef(*D, Record); ++NumLexicalDeclContexts; @@ -1097,7 +1115,7 @@ uint64_t PCHWriter::WriteDeclContextVisibleBlock(ASTContext &Context, return 0; // Force the DeclContext to build a its name-lookup table. - DC->lookup(Context, DeclarationName()); + DC->lookup(DeclarationName()); // Serialize the contents of the mapping used for lookup. Note that, // although we have two very different code paths, the serialized @@ -1747,7 +1765,8 @@ void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls) { WriteStatCache(*StatCalls); WriteSourceManagerBlock(Context.getSourceManager(), PP); WritePreprocessor(PP); - + WriteComments(Context); + // Keep writing types and declarations until all types and // declarations have been written. do { diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp index 44da4d7..a6843e1 100644 --- a/lib/Frontend/PCHWriterDecl.cpp +++ b/lib/Frontend/PCHWriterDecl.cpp @@ -146,7 +146,7 @@ void PCHDeclWriter::VisitFunctionDecl(FunctionDecl *D) { VisitValueDecl(D); Record.push_back(D->isThisDeclarationADefinition()); if (D->isThisDeclarationADefinition()) - Writer.AddStmt(D->getBody(Context)); + Writer.AddStmt(D->getBody()); Writer.AddDeclRef(D->getPreviousDeclaration(), Record); Record.push_back(D->getStorageClass()); // FIXME: stable encoding Record.push_back(D->isInline()); @@ -172,7 +172,7 @@ void PCHDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) { // Unlike C/C++, method bodies will never be in header files. Record.push_back(D->getBody() != 0); if (D->getBody() != 0) { - Writer.AddStmt(D->getBody(Context)); + Writer.AddStmt(D->getBody()); Writer.AddDeclRef(D->getSelfDecl(), Record); Writer.AddDeclRef(D->getCmdDecl(), Record); } @@ -520,7 +520,7 @@ void PCHWriter::WriteDeclsBlock(ASTContext &Context) { // If the declaration had any attributes, write them now. if (D->hasAttrs()) - WriteAttributeRecord(D->getAttrs(Context)); + WriteAttributeRecord(D->getAttrs()); // Flush any expressions that were written as part of this declaration. FlushStmts(); diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp index c63c03c..5235326 100644 --- a/lib/Frontend/PCHWriterStmt.cpp +++ b/lib/Frontend/PCHWriterStmt.cpp @@ -826,5 +826,4 @@ void PCHWriter::FlushStmts() { } StmtsToEmit.clear(); - SwitchCaseIDs.clear(); } diff --git a/lib/Frontend/ResolveLocation.cpp b/lib/Frontend/ResolveLocation.cpp index a5f0d1f..d7a9b48 100644 --- a/lib/Frontend/ResolveLocation.cpp +++ b/lib/Frontend/ResolveLocation.cpp @@ -163,7 +163,7 @@ void StmtLocResolver::VisitStmt(Stmt *Node) { void DeclLocResolver::VisitDeclContext(DeclContext *DC) { DeclLocResolver DLR(Ctx, Loc); for (DeclContext::decl_iterator - I = DC->decls_begin(Ctx), E = DC->decls_end(Ctx); I != E; ++I) { + I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) { DLR.Visit(*I); if (DLR.Finished()) { if (DLR.FoundIt()) @@ -211,7 +211,7 @@ void DeclLocResolver::VisitFunctionDecl(FunctionDecl *D) { // Finally, search through the body of the function. if (D->isThisDeclarationADefinition()) { StmtLocResolver SLR(Ctx, Loc); - SLR.Visit(D->getBody(Ctx)); + SLR.Visit(D->getBody()); if (SLR.FoundIt()) { llvm::tie(Dcl, Stm) = SLR.getResult(); // If we didn't find a more immediate 'parent' declaration for the @@ -287,7 +287,7 @@ void LocResolverBase::FixRange(SourceRange &Range) { void LocResolverBase::print(Decl *D) { llvm::raw_ostream &OS = llvm::outs(); OS << "#### DECL ####\n"; - D->print(OS, Ctx); + D->print(OS); OS << " <"; D->getLocStart().print(OS, Ctx.getSourceManager()); OS << " > - <"; @@ -299,7 +299,7 @@ void LocResolverBase::print(Decl *D) { void LocResolverBase::print(Stmt *Node) { llvm::raw_ostream &OS = llvm::outs(); OS << "#### STMT ####\n"; - Node->printPretty(OS, Ctx); + Node->printPretty(OS, Ctx, 0, PrintingPolicy(Ctx.getLangOptions())); OS << " <"; Node->getLocStart().print(OS, Ctx.getSourceManager()); OS << " > - <"; diff --git a/lib/Frontend/RewriteBlocks.cpp b/lib/Frontend/RewriteBlocks.cpp index d20d5cd..bc855fa 100644 --- a/lib/Frontend/RewriteBlocks.cpp +++ b/lib/Frontend/RewriteBlocks.cpp @@ -306,39 +306,33 @@ void RewriteBlocks::RewriteMethodDecl(ObjCMethodDecl *Method) { void RewriteBlocks::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) { for (ObjCInterfaceDecl::instmeth_iterator - I = ClassDecl->instmeth_begin(*Context), - E = ClassDecl->instmeth_end(*Context); + I = ClassDecl->instmeth_begin(), E = ClassDecl->instmeth_end(); I != E; ++I) RewriteMethodDecl(*I); for (ObjCInterfaceDecl::classmeth_iterator - I = ClassDecl->classmeth_begin(*Context), - E = ClassDecl->classmeth_end(*Context); + I = ClassDecl->classmeth_begin(), E = ClassDecl->classmeth_end(); I != E; ++I) RewriteMethodDecl(*I); } void RewriteBlocks::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) { for (ObjCCategoryDecl::instmeth_iterator - I = CatDecl->instmeth_begin(*Context), - E = CatDecl->instmeth_end(*Context); + I = CatDecl->instmeth_begin(), E = CatDecl->instmeth_end(); I != E; ++I) RewriteMethodDecl(*I); for (ObjCCategoryDecl::classmeth_iterator - I = CatDecl->classmeth_begin(*Context), - E = CatDecl->classmeth_end(*Context); + I = CatDecl->classmeth_begin(), E = CatDecl->classmeth_end(); I != E; ++I) RewriteMethodDecl(*I); } void RewriteBlocks::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { for (ObjCProtocolDecl::instmeth_iterator - I = PDecl->instmeth_begin(*Context), - E = PDecl->instmeth_end(*Context); + I = PDecl->instmeth_begin(), E = PDecl->instmeth_end(); I != E; ++I) RewriteMethodDecl(*I); for (ObjCProtocolDecl::classmeth_iterator - I = PDecl->classmeth_begin(*Context), - E = PDecl->classmeth_end(*Context); + I = PDecl->classmeth_begin(), E = PDecl->classmeth_end(); I != E; ++I) RewriteMethodDecl(*I); } @@ -724,7 +718,8 @@ std::string RewriteBlocks::SynthesizeBlockCall(CallExpr *Exp) { BlockCall += "((struct __block_impl *)"; std::string closureExprBufStr; llvm::raw_string_ostream closureExprBuf(closureExprBufStr); - Exp->getCallee()->printPretty(closureExprBuf, *Context); + Exp->getCallee()->printPretty(closureExprBuf, *Context, 0, + PrintingPolicy(LangOpts)); BlockCall += closureExprBuf.str(); BlockCall += ")->FuncPtr)"; @@ -735,7 +730,7 @@ std::string RewriteBlocks::SynthesizeBlockCall(CallExpr *Exp) { E = Exp->arg_end(); I != E; ++I) { std::string syncExprBufS; llvm::raw_string_ostream Buf(syncExprBufS); - (*I)->printPretty(Buf, *Context); + (*I)->printPretty(Buf, *Context, 0, PrintingPolicy(LangOpts)); BlockCall += ", " + Buf.str(); } return BlockCall; @@ -1088,7 +1083,7 @@ void RewriteBlocks::HandleDeclInMainFile(Decl *D) { RewriteFunctionProtoType(FD->getType(), FD); // FIXME: Handle CXXTryStmt - if (CompoundStmt *Body = FD->getCompoundBody(*Context)) { + if (CompoundStmt *Body = FD->getCompoundBody()) { CurFunctionDef = FD; FD->setBody(cast_or_null<CompoundStmt>(RewriteFunctionBody(Body))); // This synthesizes and inserts the block "impl" struct, invoke function, @@ -1100,7 +1095,7 @@ void RewriteBlocks::HandleDeclInMainFile(Decl *D) { } if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { RewriteMethodDecl(MD); - if (Stmt *Body = MD->getBody(*Context)) { + if (Stmt *Body = MD->getBody()) { CurMethodDef = MD; RewriteFunctionBody(Body); InsertBlockLiteralsWithinMethod(MD); @@ -1112,7 +1107,7 @@ void RewriteBlocks::HandleDeclInMainFile(Decl *D) { RewriteBlockPointerDecl(VD); if (VD->getInit()) { if (BlockExpr *CBE = dyn_cast<BlockExpr>(VD->getInit())) { - RewriteFunctionBody(CBE->getBody(*Context)); + RewriteFunctionBody(CBE->getBody()); // We've just rewritten the block body in place. // Now we snarf the rewritten text and stash it away for later use. @@ -1146,8 +1141,8 @@ void RewriteBlocks::HandleDeclInMainFile(Decl *D) { } if (RecordDecl *RD = dyn_cast<RecordDecl>(D)) { if (RD->isDefinition()) { - for (RecordDecl::field_iterator i = RD->field_begin(*Context), - e = RD->field_end(*Context); i != e; ++i) { + for (RecordDecl::field_iterator i = RD->field_begin(), + e = RD->field_end(); i != e; ++i) { FieldDecl *FD = *i; if (isBlockPointerType(FD->getType())) RewriteBlockPointerDecl(FD); diff --git a/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp index dce2710..cf31f2b 100644 --- a/lib/Frontend/RewriteObjC.cpp +++ b/lib/Frontend/RewriteObjC.cpp @@ -171,7 +171,7 @@ namespace { // Get the new text. std::string SStr; llvm::raw_string_ostream S(SStr); - New->printPretty(S, *Context); + New->printPretty(S, *Context, 0, PrintingPolicy(LangOpts)); const std::string &Str = S.str(); // If replacement succeeded or warning disabled return with no warning. @@ -597,8 +597,8 @@ void RewriteObjC::HandleTopLevelSingleDecl(Decl *D) { RewriteForwardProtocolDecl(FP); } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) { // Recurse into linkage specifications - for (DeclContext::decl_iterator DI = LSD->decls_begin(*Context), - DIEnd = LSD->decls_end(*Context); + for (DeclContext::decl_iterator DI = LSD->decls_begin(), + DIEnd = LSD->decls_end(); DI != DIEnd; ++DI) HandleTopLevelSingleDecl(*DI); } @@ -789,13 +789,11 @@ void RewriteObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) { ReplaceText(LocStart, 0, "// ", 3); for (ObjCCategoryDecl::instmeth_iterator - I = CatDecl->instmeth_begin(*Context), - E = CatDecl->instmeth_end(*Context); + I = CatDecl->instmeth_begin(), E = CatDecl->instmeth_end(); I != E; ++I) RewriteMethodDeclaration(*I); for (ObjCCategoryDecl::classmeth_iterator - I = CatDecl->classmeth_begin(*Context), - E = CatDecl->classmeth_end(*Context); + I = CatDecl->classmeth_begin(), E = CatDecl->classmeth_end(); I != E; ++I) RewriteMethodDeclaration(*I); @@ -812,13 +810,11 @@ void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { ReplaceText(LocStart, 0, "// ", 3); for (ObjCProtocolDecl::instmeth_iterator - I = PDecl->instmeth_begin(*Context), - E = PDecl->instmeth_end(*Context); + I = PDecl->instmeth_begin(), E = PDecl->instmeth_end(); I != E; ++I) RewriteMethodDeclaration(*I); for (ObjCProtocolDecl::classmeth_iterator - I = PDecl->classmeth_begin(*Context), - E = PDecl->classmeth_end(*Context); + I = PDecl->classmeth_begin(), E = PDecl->classmeth_end(); I != E; ++I) RewriteMethodDeclaration(*I); @@ -986,14 +982,14 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) { InsertText(CID->getLocStart(), "// ", 3); for (ObjCCategoryImplDecl::instmeth_iterator - I = IMD ? IMD->instmeth_begin(*Context) : CID->instmeth_begin(*Context), - E = IMD ? IMD->instmeth_end(*Context) : CID->instmeth_end(*Context); + I = IMD ? IMD->instmeth_begin() : CID->instmeth_begin(), + E = IMD ? IMD->instmeth_end() : CID->instmeth_end(); I != E; ++I) { std::string ResultStr; ObjCMethodDecl *OMD = *I; RewriteObjCMethodDecl(OMD, ResultStr); SourceLocation LocStart = OMD->getLocStart(); - SourceLocation LocEnd = OMD->getCompoundBody(*Context)->getLocStart(); + SourceLocation LocEnd = OMD->getCompoundBody()->getLocStart(); const char *startBuf = SM->getCharacterData(LocStart); const char *endBuf = SM->getCharacterData(LocEnd); @@ -1002,14 +998,14 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) { } for (ObjCCategoryImplDecl::classmeth_iterator - I = IMD ? IMD->classmeth_begin(*Context) : CID->classmeth_begin(*Context), - E = IMD ? IMD->classmeth_end(*Context) : CID->classmeth_end(*Context); + I = IMD ? IMD->classmeth_begin() : CID->classmeth_begin(), + E = IMD ? IMD->classmeth_end() : CID->classmeth_end(); I != E; ++I) { std::string ResultStr; ObjCMethodDecl *OMD = *I; RewriteObjCMethodDecl(OMD, ResultStr); SourceLocation LocStart = OMD->getLocStart(); - SourceLocation LocEnd = OMD->getCompoundBody(*Context)->getLocStart(); + SourceLocation LocEnd = OMD->getCompoundBody()->getLocStart(); const char *startBuf = SM->getCharacterData(LocStart); const char *endBuf = SM->getCharacterData(LocEnd); @@ -1017,8 +1013,8 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) { ResultStr.c_str(), ResultStr.size()); } for (ObjCCategoryImplDecl::propimpl_iterator - I = IMD ? IMD->propimpl_begin(*Context) : CID->propimpl_begin(*Context), - E = IMD ? IMD->propimpl_end(*Context) : CID->propimpl_end(*Context); + I = IMD ? IMD->propimpl_begin() : CID->propimpl_begin(), + E = IMD ? IMD->propimpl_end() : CID->propimpl_end(); I != E; ++I) { RewritePropertyImplDecl(*I, IMD, CID); } @@ -1047,17 +1043,15 @@ void RewriteObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) { } SynthesizeObjCInternalStruct(ClassDecl, ResultStr); - for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(*Context), - E = ClassDecl->prop_end(*Context); I != E; ++I) + for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(), + E = ClassDecl->prop_end(); I != E; ++I) RewriteProperty(*I); for (ObjCInterfaceDecl::instmeth_iterator - I = ClassDecl->instmeth_begin(*Context), - E = ClassDecl->instmeth_end(*Context); + I = ClassDecl->instmeth_begin(), E = ClassDecl->instmeth_end(); I != E; ++I) RewriteMethodDeclaration(*I); for (ObjCInterfaceDecl::classmeth_iterator - I = ClassDecl->classmeth_begin(*Context), - E = ClassDecl->classmeth_end(*Context); + I = ClassDecl->classmeth_begin(), E = ClassDecl->classmeth_end(); I != E; ++I) RewriteMethodDeclaration(*I); @@ -1149,8 +1143,7 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, dyn_cast<ObjCInterfaceType>(pType->getPointeeType()); // lookup which class implements the instance variable. ObjCInterfaceDecl *clsDeclared = 0; - iFaceDecl->getDecl()->lookupInstanceVariable(*Context, - D->getIdentifier(), + iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), clsDeclared); assert(clsDeclared && "RewriteObjCIvarRefExpr(): Can't find class"); @@ -1195,8 +1188,7 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, ObjCInterfaceType *iFaceDecl = dyn_cast<ObjCInterfaceType>(pType->getPointeeType()); // lookup which class implements the instance variable. ObjCInterfaceDecl *clsDeclared = 0; - iFaceDecl->getDecl()->lookupInstanceVariable(*Context, - D->getIdentifier(), + iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), clsDeclared); assert(clsDeclared && "RewriteObjCIvarRefExpr(): Can't find class"); @@ -1514,7 +1506,8 @@ Stmt *RewriteObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) { SourceLocation()); std::string syncExprBufS; llvm::raw_string_ostream syncExprBuf(syncExprBufS); - syncExpr->printPretty(syncExprBuf, *Context); + syncExpr->printPretty(syncExprBuf, *Context, 0, + PrintingPolicy(LangOpts)); buf += syncExprBuf.str(); buf += ");\n"; buf += " if (_rethrow) objc_exception_throw(_rethrow);\n"; @@ -2143,7 +2136,8 @@ Stmt *RewriteObjC::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) { // The pretty printer for StringLiteral handles escape characters properly. std::string prettyBufS; llvm::raw_string_ostream prettyBuf(prettyBufS); - Exp->getString()->printPretty(prettyBuf, *Context); + Exp->getString()->printPretty(prettyBuf, *Context, 0, + PrintingPolicy(LangOpts)); Preamble += prettyBuf.str(); Preamble += ","; // The minus 2 removes the begin/end double quotes. @@ -2192,8 +2186,7 @@ QualType RewriteObjC::getSuperStructType() { // Create fields for (unsigned i = 0; i < 2; ++i) { - SuperStructDecl->addDecl(*Context, - FieldDecl::Create(*Context, SuperStructDecl, + SuperStructDecl->addDecl(FieldDecl::Create(*Context, SuperStructDecl, SourceLocation(), 0, FieldTypes[i], /*BitWidth=*/0, /*Mutable=*/false)); @@ -2222,8 +2215,7 @@ QualType RewriteObjC::getConstantStringStructType() { // Create fields for (unsigned i = 0; i < 4; ++i) { - ConstantStringDecl->addDecl(*Context, - FieldDecl::Create(*Context, + ConstantStringDecl->addDecl(FieldDecl::Create(*Context, ConstantStringDecl, SourceLocation(), 0, FieldTypes[i], @@ -2889,9 +2881,9 @@ RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, const char *prefix, if (ObjCSynthesizedProtocols.count(PDecl)) return; - if (PDecl->instmeth_begin(*Context) != PDecl->instmeth_end(*Context)) { - unsigned NumMethods = std::distance(PDecl->instmeth_begin(*Context), - PDecl->instmeth_end(*Context)); + if (PDecl->instmeth_begin() != PDecl->instmeth_end()) { + unsigned NumMethods = std::distance(PDecl->instmeth_begin(), + PDecl->instmeth_end()); /* struct _objc_protocol_method_list { int protocol_method_count; struct protocol_methods protocols[]; @@ -2908,10 +2900,9 @@ RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, const char *prefix, // Output instance methods declared in this protocol. for (ObjCProtocolDecl::instmeth_iterator - I = PDecl->instmeth_begin(*Context), - E = PDecl->instmeth_end(*Context); + I = PDecl->instmeth_begin(), E = PDecl->instmeth_end(); I != E; ++I) { - if (I == PDecl->instmeth_begin(*Context)) + if (I == PDecl->instmeth_begin()) Result += "\t ,{{(struct objc_selector *)\""; else Result += "\t ,{(struct objc_selector *)\""; @@ -2926,8 +2917,8 @@ RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, const char *prefix, } // Output class methods declared in this protocol. - unsigned NumMethods = std::distance(PDecl->classmeth_begin(*Context), - PDecl->classmeth_end(*Context)); + unsigned NumMethods = std::distance(PDecl->classmeth_begin(), + PDecl->classmeth_end()); if (NumMethods > 0) { /* struct _objc_protocol_method_list { int protocol_method_count; @@ -2947,10 +2938,9 @@ RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, const char *prefix, // Output instance methods declared in this protocol. for (ObjCProtocolDecl::classmeth_iterator - I = PDecl->classmeth_begin(*Context), - E = PDecl->classmeth_end(*Context); + I = PDecl->classmeth_begin(), E = PDecl->classmeth_end(); I != E; ++I) { - if (I == PDecl->classmeth_begin(*Context)) + if (I == PDecl->classmeth_begin()) Result += "\t ,{{(struct objc_selector *)\""; else Result += "\t ,{(struct objc_selector *)\""; @@ -2993,14 +2983,14 @@ RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, const char *prefix, "{\n\t0, \""; Result += PDecl->getNameAsString(); Result += "\", 0, "; - if (PDecl->instmeth_begin(*Context) != PDecl->instmeth_end(*Context)) { + if (PDecl->instmeth_begin() != PDecl->instmeth_end()) { Result += "(struct _objc_protocol_method_list *)&_OBJC_PROTOCOL_INSTANCE_METHODS_"; Result += PDecl->getNameAsString(); Result += ", "; } else Result += "0, "; - if (PDecl->classmeth_begin(*Context) != PDecl->classmeth_end(*Context)) { + if (PDecl->classmeth_begin() != PDecl->classmeth_end()) { Result += "(struct _objc_protocol_method_list *)&_OBJC_PROTOCOL_CLASS_METHODS_"; Result += PDecl->getNameAsString(); Result += "\n"; @@ -3076,13 +3066,12 @@ void RewriteObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, // Build _objc_method_list for class's instance methods if needed llvm::SmallVector<ObjCMethodDecl *, 32> - InstanceMethods(IDecl->instmeth_begin(*Context), - IDecl->instmeth_end(*Context)); + InstanceMethods(IDecl->instmeth_begin(), IDecl->instmeth_end()); // If any of our property implementations have associated getters or // setters, produce metadata for them as well. - for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(*Context), - PropEnd = IDecl->propimpl_end(*Context); + for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(), + PropEnd = IDecl->propimpl_end(); Prop != PropEnd; ++Prop) { if ((*Prop)->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) continue; @@ -3103,8 +3092,7 @@ void RewriteObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, Result); // Build _objc_method_list for class's class methods if needed - RewriteObjCMethodsMetaData(IDecl->classmeth_begin(*Context), - IDecl->classmeth_end(*Context), + RewriteObjCMethodsMetaData(IDecl->classmeth_begin(), IDecl->classmeth_end(), false, "CATEGORY_", FullCategoryName.c_str(), Result); @@ -3147,7 +3135,7 @@ void RewriteObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, Result += ClassDecl->getNameAsString(); Result += "\"\n"; - if (IDecl->instmeth_begin(*Context) != IDecl->instmeth_end(*Context)) { + if (IDecl->instmeth_begin() != IDecl->instmeth_end()) { Result += "\t, (struct _objc_method_list *)" "&_OBJC_CATEGORY_INSTANCE_METHODS_"; Result += FullCategoryName; @@ -3155,7 +3143,7 @@ void RewriteObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, } else Result += "\t, 0\n"; - if (IDecl->classmeth_begin(*Context) != IDecl->classmeth_end(*Context)) { + if (IDecl->classmeth_begin() != IDecl->classmeth_end()) { Result += "\t, (struct _objc_method_list *)" "&_OBJC_CATEGORY_CLASS_METHODS_"; Result += FullCategoryName; @@ -3210,8 +3198,8 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, } // Build _objc_ivar_list metadata for classes ivars if needed - unsigned NumIvars = !IDecl->ivar_empty(*Context) - ? IDecl->ivar_size(*Context) + unsigned NumIvars = !IDecl->ivar_empty() + ? IDecl->ivar_size() : (CDecl ? CDecl->ivar_size() : 0); if (NumIvars > 0) { static bool objc_ivar = false; @@ -3249,10 +3237,9 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, ObjCInterfaceDecl::ivar_iterator IVI, IVE; llvm::SmallVector<ObjCIvarDecl *, 8> IVars; - if (!IDecl->ivar_empty(*Context)) { + if (!IDecl->ivar_empty()) { for (ObjCImplementationDecl::ivar_iterator - IV = IDecl->ivar_begin(*Context), - IVEnd = IDecl->ivar_end(*Context); + IV = IDecl->ivar_begin(), IVEnd = IDecl->ivar_end(); IV != IVEnd; ++IV) IVars.push_back(*IV); IVI = IVars.begin(); @@ -3289,13 +3276,12 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, // Build _objc_method_list for class's instance methods if needed llvm::SmallVector<ObjCMethodDecl *, 32> - InstanceMethods(IDecl->instmeth_begin(*Context), - IDecl->instmeth_end(*Context)); + InstanceMethods(IDecl->instmeth_begin(), IDecl->instmeth_end()); // If any of our property implementations have associated getters or // setters, produce metadata for them as well. - for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(*Context), - PropEnd = IDecl->propimpl_end(*Context); + for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(), + PropEnd = IDecl->propimpl_end(); Prop != PropEnd; ++Prop) { if ((*Prop)->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) continue; @@ -3315,8 +3301,7 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, true, "", IDecl->getNameAsCString(), Result); // Build _objc_method_list for class's class methods if needed - RewriteObjCMethodsMetaData(IDecl->classmeth_begin(*Context), - IDecl->classmeth_end(*Context), + RewriteObjCMethodsMetaData(IDecl->classmeth_begin(), IDecl->classmeth_end(), false, "", IDecl->getNameAsCString(), Result); // Protocols referenced in class declaration? @@ -3389,7 +3374,7 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, // Set 'ivars' field for root class to 0. ObjC1 runtime does not use it. // 'info' field is initialized to CLS_META(2) for metaclass Result += ", 0,2, sizeof(struct _objc_class), 0"; - if (IDecl->classmeth_begin(*Context) != IDecl->classmeth_end(*Context)) { + if (IDecl->classmeth_begin() != IDecl->classmeth_end()) { Result += "\n\t, (struct _objc_method_list *)&_OBJC_CLASS_METHODS_"; Result += IDecl->getNameAsString(); Result += "\n"; @@ -3442,7 +3427,7 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, } else Result += ",0"; - if (IDecl->instmeth_begin(*Context) != IDecl->instmeth_end(*Context)) { + if (IDecl->instmeth_begin() != IDecl->instmeth_end()) { Result += ", (struct _objc_method_list *)&_OBJC_INSTANCE_METHODS_"; Result += CDecl->getNameAsString(); Result += ", 0\n\t"; @@ -4552,7 +4537,7 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) { RewriteBlocksInFunctionProtoType(FD->getType(), FD); // FIXME: If this should support Obj-C++, support CXXTryStmt - if (CompoundStmt *Body = FD->getCompoundBody(*Context)) { + if (CompoundStmt *Body = FD->getCompoundBody()) { CurFunctionDef = FD; CollectPropertySetters(Body); CurrentBody = Body; @@ -4572,7 +4557,7 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) { return; } if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { - if (CompoundStmt *Body = MD->getBody()) { + if (CompoundStmt *Body = MD->getCompoundBody()) { CurMethodDef = MD; CollectPropertySetters(Body); CurrentBody = Body; @@ -4636,8 +4621,8 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) { } if (RecordDecl *RD = dyn_cast<RecordDecl>(D)) { if (RD->isDefinition()) { - for (RecordDecl::field_iterator i = RD->field_begin(*Context), - e = RD->field_end(*Context); i != e; ++i) { + for (RecordDecl::field_iterator i = RD->field_begin(), + e = RD->field_end(); i != e; ++i) { FieldDecl *FD = *i; if (isTopLevelBlockPointerType(FD->getType())) RewriteBlockPointerDecl(FD); |