diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Rewrite')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Core/CMakeLists.txt | 24 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Core/DeltaTree.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/DeltaTree.cpp) | 5 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Core/HTMLRewrite.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/HTMLRewrite.cpp) | 5 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Core/Makefile | 18 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Core/RewriteRope.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/RewriteRope.cpp) | 6 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Core/Rewriter.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp) | 2 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Core/TokenRewriter.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/TokenRewriter.cpp) | 2 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Frontend/CMakeLists.txt | 28 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Frontend/FixItRewriter.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/FixItRewriter.cpp) | 2 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Frontend/FrontendActions.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/FrontendActions.cpp) | 8 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Frontend/HTMLPrint.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/HTMLPrint.cpp) | 6 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/InclusionRewriter.cpp) | 12 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Frontend/Makefile | 18 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Frontend/RewriteMacros.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/RewriteMacros.cpp) | 4 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/RewriteModernObjC.cpp) | 156 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Frontend/RewriteObjC.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/RewriteObjC.cpp) | 38 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Rewrite/Frontend/RewriteTest.cpp (renamed from contrib/llvm/tools/clang/lib/Rewrite/RewriteTest.cpp) | 4 |
17 files changed, 240 insertions, 98 deletions
diff --git a/contrib/llvm/tools/clang/lib/Rewrite/Core/CMakeLists.txt b/contrib/llvm/tools/clang/lib/Rewrite/Core/CMakeLists.txt new file mode 100644 index 0000000..0797818 --- /dev/null +++ b/contrib/llvm/tools/clang/lib/Rewrite/Core/CMakeLists.txt @@ -0,0 +1,24 @@ +add_clang_library(clangRewriteCore + DeltaTree.cpp + HTMLRewrite.cpp + RewriteRope.cpp + Rewriter.cpp + TokenRewriter.cpp + ) + +add_dependencies(clangRewriteCore + ClangAttrClasses + ClangAttrList + ClangAttrParsedAttrList + ClangCommentNodes + ClangDeclNodes + ClangDiagnosticCommon + ClangDiagnosticFrontend + ClangStmtNodes + ) + +target_link_libraries(clangRewriteCore + clangBasic + clangAST + clangParse + ) diff --git a/contrib/llvm/tools/clang/lib/Rewrite/DeltaTree.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Core/DeltaTree.cpp index 4297dc8..4692277 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/DeltaTree.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Core/DeltaTree.cpp @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/DeltaTree.h" +#include "clang/Rewrite/Core/DeltaTree.h" #include "clang/Basic/LLVM.h" #include <cstring> #include <cstdio> @@ -113,8 +113,6 @@ namespace { void RecomputeFullDeltaLocally(); void Destroy(); - - //static inline bool classof(const DeltaTreeNode *) { return true; } }; } // end anonymous namespace @@ -149,7 +147,6 @@ namespace { return Children[i]; } - //static inline bool classof(const DeltaTreeInteriorNode *) { return true; } static inline bool classof(const DeltaTreeNode *N) { return !N->isLeaf(); } }; } diff --git a/contrib/llvm/tools/clang/lib/Rewrite/HTMLRewrite.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Core/HTMLRewrite.cpp index 236b98f..0e8e4fe 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/HTMLRewrite.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Core/HTMLRewrite.cpp @@ -13,8 +13,8 @@ //===----------------------------------------------------------------------===// #include "clang/Lex/Preprocessor.h" -#include "clang/Rewrite/Rewriter.h" -#include "clang/Rewrite/HTMLRewrite.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include "clang/Rewrite/Core/HTMLRewrite.h" #include "clang/Lex/TokenConcatenation.h" #include "clang/Lex/Preprocessor.h" #include "clang/Basic/SourceManager.h" @@ -484,6 +484,7 @@ void html::HighlightMacros(Rewriter &R, FileID FID, const Preprocessor& PP) { // Temporarily change the diagnostics object so that we ignore any generated // diagnostics from this pass. DiagnosticsEngine TmpDiags(PP.getDiagnostics().getDiagnosticIDs(), + &PP.getDiagnostics().getDiagnosticOptions(), new IgnoringDiagConsumer); // FIXME: This is a huge hack; we reuse the input preprocessor because we want diff --git a/contrib/llvm/tools/clang/lib/Rewrite/Core/Makefile b/contrib/llvm/tools/clang/lib/Rewrite/Core/Makefile new file mode 100644 index 0000000..8c8d2e4 --- /dev/null +++ b/contrib/llvm/tools/clang/lib/Rewrite/Core/Makefile @@ -0,0 +1,18 @@ +##===- clang/lib/Rewrite/Makefile --------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +# +# This implements code transformation / rewriting facilities. +# +##===----------------------------------------------------------------------===## + +CLANG_LEVEL := ../../.. +LIBRARYNAME := clangRewriteCore + +include $(CLANG_LEVEL)/Makefile + diff --git a/contrib/llvm/tools/clang/lib/Rewrite/RewriteRope.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Core/RewriteRope.cpp index cc8de1b..fe7aa2d 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/RewriteRope.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Core/RewriteRope.cpp @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/RewriteRope.h" +#include "clang/Rewrite/Core/RewriteRope.h" #include "clang/Basic/LLVM.h" #include <algorithm> using namespace clang; @@ -117,8 +117,6 @@ namespace { /// guaranteed that there is a split at Offset. void erase(unsigned Offset, unsigned NumBytes); - //static inline bool classof(const RopePieceBTreeNode *) { return true; } - }; } // end anonymous namespace @@ -221,7 +219,6 @@ namespace { /// guaranteed that there is a split at Offset. void erase(unsigned Offset, unsigned NumBytes); - //static inline bool classof(const RopePieceBTreeLeaf *) { return true; } static inline bool classof(const RopePieceBTreeNode *N) { return N->isLeaf(); } @@ -458,7 +455,6 @@ namespace { /// guaranteed that there is a split at Offset. void erase(unsigned Offset, unsigned NumBytes); - //static inline bool classof(const RopePieceBTreeInterior *) { return true; } static inline bool classof(const RopePieceBTreeNode *N) { return !N->isLeaf(); } diff --git a/contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Core/Rewriter.cpp index 7c27114..4df967f 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Core/Rewriter.cpp @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/Rewriter.h" +#include "clang/Rewrite/Core/Rewriter.h" #include "clang/AST/Stmt.h" #include "clang/AST/Decl.h" #include "clang/Basic/DiagnosticIDs.h" diff --git a/contrib/llvm/tools/clang/lib/Rewrite/TokenRewriter.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Core/TokenRewriter.cpp index 03ce63e..940ece2 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/TokenRewriter.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Core/TokenRewriter.cpp @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/TokenRewriter.h" +#include "clang/Rewrite/Core/TokenRewriter.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/ScratchBuffer.h" #include "clang/Basic/SourceManager.h" diff --git a/contrib/llvm/tools/clang/lib/Rewrite/Frontend/CMakeLists.txt b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/CMakeLists.txt new file mode 100644 index 0000000..9017e47 --- /dev/null +++ b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/CMakeLists.txt @@ -0,0 +1,28 @@ +add_clang_library(clangRewriteFrontend + FixItRewriter.cpp + FrontendActions.cpp + HTMLPrint.cpp + InclusionRewriter.cpp + RewriteMacros.cpp + RewriteModernObjC.cpp + RewriteObjC.cpp + RewriteTest.cpp + ) + +add_dependencies(clangRewriteFrontend + ClangAttrClasses + ClangAttrList + ClangAttrParsedAttrList + ClangCommentNodes + ClangDeclNodes + ClangDiagnosticCommon + ClangDiagnosticFrontend + ClangStmtNodes + ) + +target_link_libraries(clangRewriteFrontend + clangBasic + clangAST + clangParse + clangFrontend + ) diff --git a/contrib/llvm/tools/clang/lib/Rewrite/FixItRewriter.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/FixItRewriter.cpp index 3863adb..43a1ab1 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/FixItRewriter.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/FixItRewriter.cpp @@ -13,7 +13,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/FixItRewriter.h" +#include "clang/Rewrite/Frontend/FixItRewriter.h" #include "clang/Edit/Commit.h" #include "clang/Edit/EditsReceiver.h" #include "clang/Basic/FileManager.h" diff --git a/contrib/llvm/tools/clang/lib/Rewrite/FrontendActions.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/FrontendActions.cpp index 9bc218e..7d29b6d 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/FrontendActions.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/FrontendActions.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/FrontendActions.h" +#include "clang/Rewrite/Frontend/FrontendActions.h" #include "clang/AST/ASTConsumer.h" #include "clang/Lex/Preprocessor.h" #include "clang/Parse/Parser.h" @@ -16,9 +16,9 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/Utils.h" -#include "clang/Rewrite/ASTConsumers.h" -#include "clang/Rewrite/FixItRewriter.h" -#include "clang/Rewrite/Rewriters.h" +#include "clang/Rewrite/Frontend/ASTConsumers.h" +#include "clang/Rewrite/Frontend/FixItRewriter.h" +#include "clang/Rewrite/Frontend/Rewriters.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/Path.h" diff --git a/contrib/llvm/tools/clang/lib/Rewrite/HTMLPrint.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/HTMLPrint.cpp index 3d190ab..79e4447 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/HTMLPrint.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/HTMLPrint.cpp @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/ASTConsumers.h" +#include "clang/Rewrite/Frontend/ASTConsumers.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" @@ -19,8 +19,8 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/Preprocessor.h" -#include "clang/Rewrite/HTMLRewrite.h" -#include "clang/Rewrite/Rewriter.h" +#include "clang/Rewrite/Core/HTMLRewrite.h" +#include "clang/Rewrite/Core/Rewriter.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" using namespace clang; diff --git a/contrib/llvm/tools/clang/lib/Rewrite/InclusionRewriter.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp index 3dfc3b0..9d1bec9 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/InclusionRewriter.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/Rewriters.h" +#include "clang/Rewrite/Frontend/Rewriters.h" #include "clang/Lex/Preprocessor.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/PreprocessorOutputOptions.h" @@ -57,10 +57,11 @@ private: const Token &IncludeTok, StringRef FileName, bool IsAngled, + CharSourceRange FilenameRange, const FileEntry *File, - SourceLocation EndLoc, StringRef SearchPath, - StringRef RelativePath); + StringRef RelativePath, + const Module *Imported); void WriteLineInfo(const char *Filename, int Line, SrcMgr::CharacteristicKind FileType, StringRef EOL, StringRef Extra = StringRef()); @@ -152,10 +153,11 @@ void InclusionRewriter::InclusionDirective(SourceLocation HashLoc, const Token &/*IncludeTok*/, StringRef /*FileName*/, bool /*IsAngled*/, + CharSourceRange /*FilenameRange*/, const FileEntry * /*File*/, - SourceLocation /*EndLoc*/, StringRef /*SearchPath*/, - StringRef /*RelativePath*/) { + StringRef /*RelativePath*/, + const Module * /*Imported*/) { assert(LastInsertedFileChange == FileChanges.end() && "Another inclusion " "directive was found before the previous one was processed"); std::pair<FileChangeMap::iterator, bool> p = FileChanges.insert( diff --git a/contrib/llvm/tools/clang/lib/Rewrite/Frontend/Makefile b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/Makefile new file mode 100644 index 0000000..ac97d40 --- /dev/null +++ b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/Makefile @@ -0,0 +1,18 @@ +##===- clang/lib/Rewrite/Makefile --------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +# +# This implements code transformation / rewriting facilities. +# +##===----------------------------------------------------------------------===## + +CLANG_LEVEL := ../../.. +LIBRARYNAME := clangRewriteFrontend + +include $(CLANG_LEVEL)/Makefile + diff --git a/contrib/llvm/tools/clang/lib/Rewrite/RewriteMacros.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/RewriteMacros.cpp index 3fa0bdb..f399dd5 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/RewriteMacros.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/RewriteMacros.cpp @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/Rewriters.h" -#include "clang/Rewrite/Rewriter.h" +#include "clang/Rewrite/Frontend/Rewriters.h" +#include "clang/Rewrite/Core/Rewriter.h" #include "clang/Lex/Preprocessor.h" #include "clang/Basic/SourceManager.h" #include "llvm/Support/raw_ostream.h" diff --git a/contrib/llvm/tools/clang/lib/Rewrite/RewriteModernObjC.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp index dcd003f..4b56b37 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/RewriteModernObjC.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/ASTConsumers.h" -#include "clang/Rewrite/Rewriter.h" +#include "clang/Rewrite/Frontend/ASTConsumers.h" +#include "clang/Rewrite/Core/Rewriter.h" #include "clang/AST/AST.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ParentMap.h" @@ -278,6 +278,9 @@ namespace { // Syntactic Rewriting. void RewriteRecordBody(RecordDecl *RD); void RewriteInclude(); + void RewriteLineDirective(const Decl *D); + void ConvertSourceLocationToLineDirective(SourceLocation Loc, + std::string &LineString); void RewriteForwardClassDecl(DeclGroupRef D); void RewriteForwardClassDecl(const llvm::SmallVector<Decl*, 8> &DG); void RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl, @@ -1602,6 +1605,19 @@ Stmt *RewriteModernObjC::RewriteBreakStmt(BreakStmt *S) { return 0; } +void RewriteModernObjC::ConvertSourceLocationToLineDirective( + SourceLocation Loc, + std::string &LineString) { + if (Loc.isFileID()) { + LineString += "\n#line "; + PresumedLoc PLoc = SM->getPresumedLoc(Loc); + LineString += utostr(PLoc.getLine()); + LineString += " \""; + LineString += Lexer::Stringify(PLoc.getFilename()); + LineString += "\"\n"; + } +} + /// RewriteContinueStmt - Rewrite for a continue-stmt inside an ObjC2's foreach /// statement to continue with its inner synthesized loop. /// @@ -1664,7 +1680,10 @@ Stmt *RewriteModernObjC::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S, StringRef elementName; std::string elementTypeAsString; std::string buf; - buf = "\n{\n\t"; + // line directive first. + SourceLocation ForEachLoc = S->getForLoc(); + ConvertSourceLocationToLineDirective(ForEachLoc, buf); + buf += "{\n\t"; if (DeclStmt *DS = dyn_cast<DeclStmt>(S->getElement())) { // type elem; NamedDecl* D = cast<NamedDecl>(DS->getSingleDecl()); @@ -1836,7 +1855,9 @@ Stmt *RewriteModernObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) assert((*startBuf == '@') && "bogus @synchronized location"); std::string buf; - buf = "{ id _rethrow = 0; id _sync_obj = "; + SourceLocation SynchLoc = S->getAtSynchronizedLoc(); + ConvertSourceLocationToLineDirective(SynchLoc, buf); + buf += "{ id _rethrow = 0; id _sync_obj = "; const char *lparenBuf = startBuf; while (*lparenBuf != '(') lparenBuf++; @@ -1902,12 +1923,14 @@ Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { ObjCAtFinallyStmt *finalStmt = S->getFinallyStmt(); bool noCatch = S->getNumCatchStmts() == 0; std::string buf; + SourceLocation TryLocation = S->getAtTryLoc(); + ConvertSourceLocationToLineDirective(TryLocation, buf); if (finalStmt) { if (noCatch) - buf = "{ id volatile _rethrow = 0;\n"; + buf += "{ id volatile _rethrow = 0;\n"; else { - buf = "{ id volatile _rethrow = 0;\ntry {\n"; + buf += "{ id volatile _rethrow = 0;\ntry {\n"; } } // Get the start location and compute the semi location. @@ -1934,13 +1957,15 @@ Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { ObjCInterfaceDecl *IDecl = Ptr->getObjectType()->getInterface(); if (IDecl) { std::string Result; + ConvertSourceLocationToLineDirective(Catch->getLocStart(), Result); + startBuf = SM->getCharacterData(startLoc); assert((*startBuf == '@') && "bogus @catch location"); SourceLocation rParenLoc = Catch->getRParenLoc(); const char *rParenBuf = SM->getCharacterData(rParenLoc); // _objc_exc_Foo *_e as argument to catch. - Result = "catch (_objc_exc_"; Result += IDecl->getNameAsString(); + Result += "catch (_objc_exc_"; Result += IDecl->getNameAsString(); Result += " *_"; Result += catchDecl->getNameAsString(); Result += ")"; ReplaceText(startLoc, rParenBuf-startBuf+1, Result); @@ -1966,11 +1991,18 @@ Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { } if (finalStmt) { buf.clear(); - if (noCatch) - buf = "catch (id e) {_rethrow = e;}\n"; - else - buf = "}\ncatch (id e) {_rethrow = e;}\n"; - + SourceLocation FinallyLoc = finalStmt->getLocStart(); + + if (noCatch) { + ConvertSourceLocationToLineDirective(FinallyLoc, buf); + buf += "catch (id e) {_rethrow = e;}\n"; + } + else { + buf += "}\n"; + ConvertSourceLocationToLineDirective(FinallyLoc, buf); + buf += "catch (id e) {_rethrow = e;}\n"; + } + SourceLocation startFinalLoc = finalStmt->getLocStart(); ReplaceText(startFinalLoc, 8, buf); Stmt *body = finalStmt->getFinallyBody(); @@ -2070,7 +2102,7 @@ CallExpr *RewriteModernObjC::SynthesizeCallToFunctionDecl( const FunctionType *FT = msgSendType->getAs<FunctionType>(); CallExpr *Exp = - new (Context) CallExpr(*Context, ICE, args, nargs, + new (Context) CallExpr(*Context, ICE, llvm::makeArrayRef(args, nargs), FT->getCallResultType(*Context), VK_RValue, EndLoc); return Exp; @@ -2675,8 +2707,7 @@ Stmt *RewriteModernObjC::RewriteObjCBoxedExpr(ObjCBoxedExpr *Exp) { ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs<FunctionType>(); - CallExpr *CE = new (Context) CallExpr(*Context, PE, &MsgExprs[0], - MsgExprs.size(), + CallExpr *CE = new (Context) CallExpr(*Context, PE, MsgExprs, FT->getResultType(), VK_RValue, EndLoc); ReplaceStmt(Exp, CE); @@ -2718,7 +2749,7 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { for (unsigned i = 0; i < NumElements; i++) InitExprs.push_back(Exp->getElement(i)); Expr *NSArrayCallExpr = - new (Context) CallExpr(*Context, NSArrayDRE, &InitExprs[0], InitExprs.size(), + new (Context) CallExpr(*Context, NSArrayDRE, InitExprs, NSArrayFType, VK_LValue, SourceLocation()); FieldDecl *ARRFD = FieldDecl::Create(*Context, 0, SourceLocation(), @@ -2814,8 +2845,7 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs<FunctionType>(); - CallExpr *CE = new (Context) CallExpr(*Context, PE, &MsgExprs[0], - MsgExprs.size(), + CallExpr *CE = new (Context) CallExpr(*Context, PE, MsgExprs, FT->getResultType(), VK_RValue, EndLoc); ReplaceStmt(Exp, CE); @@ -2865,7 +2895,7 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral // (const id [])objects Expr *NSValueCallExpr = - new (Context) CallExpr(*Context, NSDictDRE, &ValueExprs[0], ValueExprs.size(), + new (Context) CallExpr(*Context, NSDictDRE, ValueExprs, NSDictFType, VK_LValue, SourceLocation()); FieldDecl *ARRFD = FieldDecl::Create(*Context, 0, SourceLocation(), @@ -2887,7 +2917,7 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral DictLiteralValueME); // (const id <NSCopying> [])keys Expr *NSKeyCallExpr = - new (Context) CallExpr(*Context, NSDictDRE, &KeyExprs[0], KeyExprs.size(), + new (Context) CallExpr(*Context, NSDictDRE, KeyExprs, NSDictFType, VK_LValue, SourceLocation()); MemberExpr *DictLiteralKeyME = @@ -2989,8 +3019,7 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs<FunctionType>(); - CallExpr *CE = new (Context) CallExpr(*Context, PE, &MsgExprs[0], - MsgExprs.size(), + CallExpr *CE = new (Context) CallExpr(*Context, PE, MsgExprs, FT->getResultType(), VK_RValue, EndLoc); ReplaceStmt(Exp, CE); @@ -3078,6 +3107,34 @@ static SourceLocation getFunctionSourceLocation (RewriteModernObjC &R, return FD->getTypeSpecStartLoc(); } +void RewriteModernObjC::RewriteLineDirective(const Decl *D) { + + SourceLocation Location = D->getLocation(); + + if (Location.isFileID()) { + std::string LineString("\n#line "); + PresumedLoc PLoc = SM->getPresumedLoc(Location); + LineString += utostr(PLoc.getLine()); + LineString += " \""; + LineString += Lexer::Stringify(PLoc.getFilename()); + if (isa<ObjCMethodDecl>(D)) + LineString += "\""; + else LineString += "\"\n"; + + Location = D->getLocStart(); + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { + if (FD->isExternC() && !FD->isMain()) { + const DeclContext *DC = FD->getDeclContext(); + if (const LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(DC)) + // if it is extern "C" {...}, return function decl's own location. + if (!LSD->getRBraceLoc().isValid()) + Location = LSD->getExternLoc(); + } + } + InsertText(Location, LineString); + } +} + /// SynthMsgSendStretCallExpr - This routine translates message expression /// into a call to objc_msgSend_stret() entry point. Tricky part is that /// nil check on receiver must be performed before calling objc_msgSend_stret. @@ -3140,7 +3197,14 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla str += "\t"; str += returnType.getAsString(Context->getPrintingPolicy()); str += " s;\n"; str += "};\n\n"; - SourceLocation FunLocStart = getFunctionSourceLocation(*this, CurFunctionDef); + SourceLocation FunLocStart; + if (CurFunctionDef) + FunLocStart = getFunctionSourceLocation(*this, CurFunctionDef); + else { + assert(CurMethodDef && "SynthMsgSendStretCallExpr - CurMethodDef is null"); + FunLocStart = CurMethodDef->getLocStart(); + } + InsertText(FunLocStart, str); ++stretCount; @@ -3151,7 +3215,7 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla SC_None, false, false); DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, false, castType, VK_RValue, SourceLocation()); - CallExpr *STCE = new (Context) CallExpr(*Context, DRE, &MsgExprs[0], MsgExprs.size(), + CallExpr *STCE = new (Context) CallExpr(*Context, DRE, MsgExprs, castType, VK_LValue, SourceLocation()); FieldDecl *FieldD = FieldDecl::Create(*Context, 0, SourceLocation(), @@ -3260,8 +3324,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, false, superType, VK_LValue, SourceLocation()); - SuperRep = new (Context) CallExpr(*Context, DRE, &InitExprs[0], - InitExprs.size(), + SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, superType, VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with @@ -3280,8 +3343,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, } else { // (struct __rw_objc_super) { <exprs from above> } InitListExpr *ILE = - new (Context) InitListExpr(*Context, SourceLocation(), - &InitExprs[0], InitExprs.size(), + new (Context) InitListExpr(*Context, SourceLocation(), InitExprs, SourceLocation()); TypeSourceInfo *superTInfo = Context->getTrivialTypeSourceInfo(superType); @@ -3370,8 +3432,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, false, superType, VK_LValue, SourceLocation()); - SuperRep = new (Context) CallExpr(*Context, DRE, &InitExprs[0], - InitExprs.size(), + SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, superType, VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with // the structure definition in the header. The rewriter has it's own @@ -3389,8 +3450,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, } else { // (struct __rw_objc_super) { <exprs from above> } InitListExpr *ILE = - new (Context) InitListExpr(*Context, SourceLocation(), - &InitExprs[0], InitExprs.size(), + new (Context) InitListExpr(*Context, SourceLocation(), InitExprs, SourceLocation()); TypeSourceInfo *superTInfo = Context->getTrivialTypeSourceInfo(superType); @@ -3544,10 +3604,8 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs<FunctionType>(); - CallExpr *CE = new (Context) CallExpr(*Context, PE, &MsgExprs[0], - MsgExprs.size(), - FT->getResultType(), VK_RValue, - EndLoc); + CallExpr *CE = new (Context) CallExpr(*Context, PE, MsgExprs, + FT->getResultType(), VK_RValue, EndLoc); Stmt *ReplacingStmt = CE; if (MsgSendStretFlavor) { // We have the method which returns a struct/union. Must also generate @@ -3578,7 +3636,8 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, SourceLocation()); BinaryOperator *lessThanExpr = new (Context) BinaryOperator(sizeofExpr, limit, BO_LE, Context->IntTy, - VK_RValue, OK_Ordinary, SourceLocation()); + VK_RValue, OK_Ordinary, SourceLocation(), + false); // (sizeof(returnType) <= 8 ? objc_msgSend(...) : objc_msgSend_stret(...)) ConditionalOperator *CondExpr = new (Context) ConditionalOperator(lessThanExpr, @@ -3968,8 +4027,12 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, const FunctionType *AFT = CE->getFunctionType(); QualType RT = AFT->getResultType(); std::string StructRef = "struct " + Tag; - std::string S = "static " + RT.getAsString(Context->getPrintingPolicy()) + " __" + - funcName.str() + "_block_func_" + utostr(i); + SourceLocation BlockLoc = CE->getExprLoc(); + std::string S; + ConvertSourceLocationToLineDirective(BlockLoc, S); + + S += "static " + RT.getAsString(Context->getPrintingPolicy()) + " __" + + funcName.str() + "_block_func_" + utostr(i); BlockDecl *BD = CE->getBlockDecl(); @@ -4585,8 +4648,7 @@ Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp E = Exp->arg_end(); I != E; ++I) { BlkExprs.push_back(*I); } - CallExpr *CE = new (Context) CallExpr(*Context, PE, &BlkExprs[0], - BlkExprs.size(), + CallExpr *CE = new (Context) CallExpr(*Context, PE, BlkExprs, Exp->getType(), VK_RValue, SourceLocation()); return CE; @@ -4869,7 +4931,7 @@ void RewriteModernObjC::RewriteBlockPointerDecl(NamedDecl *ND) { else if (*argListBegin == '<') { buf += "/*"; buf += *argListBegin++; - OrigLength++;; + OrigLength++; while (*argListBegin != '>') { buf += *argListBegin++; OrigLength++; @@ -5347,7 +5409,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, Context->IntTy, SourceLocation()); InitExprs.push_back(FlagExp); } - NewRep = new (Context) CallExpr(*Context, DRE, &InitExprs[0], InitExprs.size(), + NewRep = new (Context) CallExpr(*Context, DRE, InitExprs, FType, VK_LValue, SourceLocation()); if (GlobalBlockExpr) { @@ -5666,6 +5728,7 @@ void RewriteModernObjC::HandleDeclInMainFile(Decl *D) { // This synthesizes and inserts the block "impl" struct, invoke function, // and any copy/dispose helper functions. InsertBlockLiteralsWithinFunction(FD); + RewriteLineDirective(D); CurFunctionDef = 0; } break; @@ -5684,6 +5747,7 @@ void RewriteModernObjC::HandleDeclInMainFile(Decl *D) { PropParentMap = 0; } InsertBlockLiteralsWithinMethod(MD); + RewriteLineDirective(D); CurMethodDef = 0; } break; @@ -5894,8 +5958,8 @@ void RewriteModernObjC::Initialize(ASTContext &context) { Preamble += "(const char *);\n"; Preamble += "__OBJC_RW_DLLIMPORT void objc_exception_throw( struct objc_object *);\n"; // @synchronized hooks. - Preamble += "__OBJC_RW_DLLIMPORT void objc_sync_enter( struct objc_object *);\n"; - Preamble += "__OBJC_RW_DLLIMPORT void objc_sync_exit( struct objc_object *);\n"; + Preamble += "__OBJC_RW_DLLIMPORT int objc_sync_enter( struct objc_object *);\n"; + Preamble += "__OBJC_RW_DLLIMPORT int objc_sync_exit( struct objc_object *);\n"; Preamble += "__OBJC_RW_DLLIMPORT Protocol *objc_getProtocol(const char *);\n"; Preamble += "#ifndef __FASTENUMERATIONSTATE\n"; Preamble += "struct __objcFastEnumerationState {\n\t"; @@ -7476,7 +7540,7 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { BinaryOperator *addExpr = new (Context) BinaryOperator(castExpr, DRE, BO_Add, Context->getPointerType(Context->CharTy), - VK_RValue, OK_Ordinary, SourceLocation()); + VK_RValue, OK_Ordinary, SourceLocation(), false); // Don't forget the parens to enforce the proper binding. ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), diff --git a/contrib/llvm/tools/clang/lib/Rewrite/RewriteObjC.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/RewriteObjC.cpp index 37c17e6..a6dcc6b 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/RewriteObjC.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/RewriteObjC.cpp @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/ASTConsumers.h" -#include "clang/Rewrite/Rewriter.h" +#include "clang/Rewrite/Frontend/ASTConsumers.h" +#include "clang/Rewrite/Core/Rewriter.h" #include "clang/AST/AST.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ParentMap.h" @@ -2059,7 +2059,7 @@ CallExpr *RewriteObjC::SynthesizeCallToFunctionDecl( const FunctionType *FT = msgSendType->getAs<FunctionType>(); CallExpr *Exp = - new (Context) CallExpr(*Context, ICE, args, nargs, + new (Context) CallExpr(*Context, ICE, llvm::makeArrayRef(args, nargs), FT->getCallResultType(*Context), VK_RValue, EndLoc); return Exp; @@ -2661,8 +2661,7 @@ CallExpr *RewriteObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavo ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), cast); const FunctionType *FT = msgSendType->getAs<FunctionType>(); - CallExpr *STCE = new (Context) CallExpr(*Context, PE, &MsgExprs[0], - MsgExprs.size(), + CallExpr *STCE = new (Context) CallExpr(*Context, PE, MsgExprs, FT->getResultType(), VK_RValue, SourceLocation()); return STCE; @@ -2766,8 +2765,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, false, superType, VK_LValue, SourceLocation()); - SuperRep = new (Context) CallExpr(*Context, DRE, &InitExprs[0], - InitExprs.size(), + SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, superType, VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with @@ -2786,8 +2784,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, } else { // (struct objc_super) { <exprs from above> } InitListExpr *ILE = - new (Context) InitListExpr(*Context, SourceLocation(), - &InitExprs[0], InitExprs.size(), + new (Context) InitListExpr(*Context, SourceLocation(), InitExprs, SourceLocation()); TypeSourceInfo *superTInfo = Context->getTrivialTypeSourceInfo(superType); @@ -2876,8 +2873,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, false, superType, VK_LValue, SourceLocation()); - SuperRep = new (Context) CallExpr(*Context, DRE, &InitExprs[0], - InitExprs.size(), + SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, superType, VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with // the structure definition in the header. The rewriter has it's own @@ -2895,8 +2891,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, } else { // (struct objc_super) { <exprs from above> } InitListExpr *ILE = - new (Context) InitListExpr(*Context, SourceLocation(), - &InitExprs[0], InitExprs.size(), + new (Context) InitListExpr(*Context, SourceLocation(), InitExprs, SourceLocation()); TypeSourceInfo *superTInfo = Context->getTrivialTypeSourceInfo(superType); @@ -3050,8 +3045,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs<FunctionType>(); - CallExpr *CE = new (Context) CallExpr(*Context, PE, &MsgExprs[0], - MsgExprs.size(), + CallExpr *CE = new (Context) CallExpr(*Context, PE, MsgExprs, FT->getResultType(), VK_RValue, EndLoc); Stmt *ReplacingStmt = CE; @@ -3084,7 +3078,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, SourceLocation()); BinaryOperator *lessThanExpr = new (Context) BinaryOperator(sizeofExpr, limit, BO_LE, Context->IntTy, - VK_RValue, OK_Ordinary, SourceLocation()); + VK_RValue, OK_Ordinary, SourceLocation(), + false); // (sizeof(returnType) <= 8 ? objc_msgSend(...) : objc_msgSend_stret(...)) ConditionalOperator *CondExpr = new (Context) ConditionalOperator(lessThanExpr, @@ -3923,8 +3918,7 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) { E = Exp->arg_end(); I != E; ++I) { BlkExprs.push_back(*I); } - CallExpr *CE = new (Context) CallExpr(*Context, PE, &BlkExprs[0], - BlkExprs.size(), + CallExpr *CE = new (Context) CallExpr(*Context, PE, BlkExprs, Exp->getType(), VK_RValue, SourceLocation()); return CE; @@ -4190,7 +4184,7 @@ void RewriteObjC::RewriteBlockPointerDecl(NamedDecl *ND) { else if (*argListBegin == '<') { buf += "/*"; buf += *argListBegin++; - OrigLength++;; + OrigLength++; while (*argListBegin != '>') { buf += *argListBegin++; OrigLength++; @@ -4651,7 +4645,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, Context->IntTy, SourceLocation()); InitExprs.push_back(FlagExp); } - NewRep = new (Context) CallExpr(*Context, DRE, &InitExprs[0], InitExprs.size(), + NewRep = new (Context) CallExpr(*Context, DRE, InitExprs, FType, VK_LValue, SourceLocation()); NewRep = new (Context) UnaryOperator(NewRep, UO_AddrOf, Context->getPointerType(NewRep->getType()), @@ -5119,8 +5113,8 @@ void RewriteObjCFragileABI::Initialize(ASTContext &context) { Preamble += "__OBJC_RW_DLLIMPORT int objc_exception_match"; Preamble += "(struct objc_class *, struct objc_object *);\n"; // @synchronized hooks. - Preamble += "__OBJC_RW_DLLIMPORT void objc_sync_enter(struct objc_object *);\n"; - Preamble += "__OBJC_RW_DLLIMPORT void objc_sync_exit(struct objc_object *);\n"; + Preamble += "__OBJC_RW_DLLIMPORT int objc_sync_enter(struct objc_object *);\n"; + Preamble += "__OBJC_RW_DLLIMPORT int objc_sync_exit(struct objc_object *);\n"; Preamble += "__OBJC_RW_DLLIMPORT Protocol *objc_getProtocol(const char *);\n"; Preamble += "#ifndef __FASTENUMERATIONSTATE\n"; Preamble += "struct __objcFastEnumerationState {\n\t"; diff --git a/contrib/llvm/tools/clang/lib/Rewrite/RewriteTest.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/RewriteTest.cpp index 019e5e7..722c5e8 100644 --- a/contrib/llvm/tools/clang/lib/Rewrite/RewriteTest.cpp +++ b/contrib/llvm/tools/clang/lib/Rewrite/Frontend/RewriteTest.cpp @@ -11,9 +11,9 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/Rewriters.h" +#include "clang/Rewrite/Frontend/Rewriters.h" #include "clang/Lex/Preprocessor.h" -#include "clang/Rewrite/TokenRewriter.h" +#include "clang/Rewrite/Core/TokenRewriter.h" #include "llvm/Support/raw_ostream.h" void clang::DoRewriteTest(Preprocessor &PP, raw_ostream* OS) { |