18f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall//===--- ARCMT.cpp - Migration to ARC mode --------------------------------===// 28f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// 38f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// The LLVM Compiler Infrastructure 48f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// 58f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// This file is distributed under the University of Illinois Open Source 68f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// License. See LICENSE.TXT for details. 78f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// 88f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall//===----------------------------------------------------------------------===// 98f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 108f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#include "Internals.h" 11478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer#include "clang/AST/ASTContext.h" 128f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#include "clang/AST/Expr.h" 138f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#include "clang/Basic/SourceManager.h" 1455fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Lex/Preprocessor.h" 158f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#include "llvm/ADT/DenseSet.h" 168f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#include <map> 178f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallusing namespace clang; 188f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallusing namespace arcmt; 198f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 208f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallnamespace { 218f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 228f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// \brief Collects transformations and merges them before applying them with 238f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// with applyRewrites(). E.g. if the same source range 248f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// is requested to be removed twice, only one rewriter remove will be invoked. 258f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// Rewrites happen in "transactions"; if one rewrite in the transaction cannot 268f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// be done (e.g. it resides in a macro) all rewrites in the transaction are 278f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// aborted. 288f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// FIXME: "Transactional" rewrites support should be baked in the Rewriter. 298f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallclass TransformActionsImpl { 308f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CapturedDiagList &CapturedDiags; 318f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ASTContext &Ctx; 328f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Preprocessor &PP; 338f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 348f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall bool IsInTransaction; 358f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 368f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall enum ActionKind { 378f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Act_Insert, Act_InsertAfterToken, 388f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Act_Remove, Act_RemoveStmt, 398f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Act_Replace, Act_ReplaceText, 408f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Act_IncreaseIndentation, 418f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Act_ClearDiagnostic 428f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall }; 438f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 448f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall struct ActionData { 458f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ActionKind Kind; 468f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceLocation Loc; 478f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceRange R1, R2; 485f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Text1, Text2; 498f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Stmt *S; 505f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<unsigned, 2> DiagIDs; 518f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall }; 528f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 538f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall std::vector<ActionData> CachedActions; 548f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 558f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall enum RangeComparison { 568f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Range_Before, 578f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Range_After, 588f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Range_Contains, 598f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Range_Contained, 608f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Range_ExtendsBegin, 618f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Range_ExtendsEnd 628f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall }; 638f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 648f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall /// \brief A range to remove. It is a character range. 658f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall struct CharRange { 668f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall FullSourceLoc Begin, End; 678f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 688f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CharRange(CharSourceRange range, SourceManager &srcMgr, Preprocessor &PP) { 698f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceLocation beginLoc = range.getBegin(), endLoc = range.getEnd(); 708f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(beginLoc.isValid() && endLoc.isValid()); 718f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (range.isTokenRange()) { 72402785357ab053dd53f4fdd858b9630a5e0f8badChandler Carruth Begin = FullSourceLoc(srcMgr.getExpansionLoc(beginLoc), srcMgr); 738f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall End = FullSourceLoc(getLocForEndOfToken(endLoc, srcMgr, PP), srcMgr); 748f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } else { 75402785357ab053dd53f4fdd858b9630a5e0f8badChandler Carruth Begin = FullSourceLoc(srcMgr.getExpansionLoc(beginLoc), srcMgr); 76402785357ab053dd53f4fdd858b9630a5e0f8badChandler Carruth End = FullSourceLoc(srcMgr.getExpansionLoc(endLoc), srcMgr); 778f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 788f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(Begin.isValid() && End.isValid()); 798f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 808f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 818f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall RangeComparison compareWith(const CharRange &RHS) const { 828f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (End.isBeforeInTranslationUnitThan(RHS.Begin)) 838f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return Range_Before; 848f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (RHS.End.isBeforeInTranslationUnitThan(Begin)) 858f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return Range_After; 868f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (!Begin.isBeforeInTranslationUnitThan(RHS.Begin) && 878f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall !RHS.End.isBeforeInTranslationUnitThan(End)) 888f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return Range_Contained; 898f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (Begin.isBeforeInTranslationUnitThan(RHS.Begin) && 908f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall RHS.End.isBeforeInTranslationUnitThan(End)) 918f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return Range_Contains; 928f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (Begin.isBeforeInTranslationUnitThan(RHS.Begin)) 938f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return Range_ExtendsBegin; 948f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall else 958f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return Range_ExtendsEnd; 968f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 978f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 988f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static RangeComparison compare(SourceRange LHS, SourceRange RHS, 998f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceManager &SrcMgr, Preprocessor &PP) { 1008f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return CharRange(CharSourceRange::getTokenRange(LHS), SrcMgr, PP) 1018f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall .compareWith(CharRange(CharSourceRange::getTokenRange(RHS), 1028f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SrcMgr, PP)); 1038f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 1048f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall }; 1058f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1065f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner typedef SmallVector<StringRef, 2> TextsVec; 1078f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall typedef std::map<FullSourceLoc, TextsVec, FullSourceLoc::BeforeThanCompare> 1088f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall InsertsMap; 1098f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall InsertsMap Inserts; 1108f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall /// \brief A list of ranges to remove. They are always sorted and they never 1118f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall /// intersect with each other. 1128f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall std::list<CharRange> Removals; 1138f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1148f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall llvm::DenseSet<Stmt *> StmtRemovals; 1158f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1168f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall std::vector<std::pair<CharRange, SourceLocation> > IndentationRanges; 1178f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1188f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall /// \brief Keeps text passed to transformation methods. 1198f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall llvm::StringMap<bool> UniqueText; 1208f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1218f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallpublic: 1228f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall TransformActionsImpl(CapturedDiagList &capturedDiags, 1238f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ASTContext &ctx, Preprocessor &PP) 1248f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall : CapturedDiags(capturedDiags), Ctx(ctx), PP(PP), IsInTransaction(false) { } 1258f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1261fe4203ca05d0a3283efc8a2e8c01ecdf78fbf2eArgyrios Kyrtzidis ASTContext &getASTContext() { return Ctx; } 1271fe4203ca05d0a3283efc8a2e8c01ecdf78fbf2eArgyrios Kyrtzidis 1288f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void startTransaction(); 1298f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall bool commitTransaction(); 1308f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void abortTransaction(); 1318f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1328f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall bool isInTransaction() const { return IsInTransaction; } 1338f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1345f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void insert(SourceLocation loc, StringRef text); 1355f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void insertAfterToken(SourceLocation loc, StringRef text); 1368f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void remove(SourceRange range); 1378f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void removeStmt(Stmt *S); 1385f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void replace(SourceRange range, StringRef text); 1398f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void replace(SourceRange range, SourceRange replacementRange); 1405f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void replaceStmt(Stmt *S, StringRef text); 1415f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void replaceText(SourceLocation loc, StringRef text, 1425f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef replacementText); 1438f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void increaseIndentation(SourceRange range, 1448f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceLocation parentIndent); 1458f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1462d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range); 1478f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1488f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void applyRewrites(TransformActions::RewriteReceiver &receiver); 1498f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1508f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallprivate: 1518f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall bool canInsert(SourceLocation loc); 1528f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall bool canInsertAfterToken(SourceLocation loc); 1538f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall bool canRemoveRange(SourceRange range); 1548f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall bool canReplaceRange(SourceRange range, SourceRange replacementRange); 1555f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner bool canReplaceText(SourceLocation loc, StringRef text); 1568f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1578f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void commitInsert(SourceLocation loc, StringRef text); 1588f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void commitInsertAfterToken(SourceLocation loc, StringRef text); 1598f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void commitRemove(SourceRange range); 1608f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void commitRemoveStmt(Stmt *S); 1618f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void commitReplace(SourceRange range, SourceRange replacementRange); 1625f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void commitReplaceText(SourceLocation loc, StringRef text, 1635f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef replacementText); 1648f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void commitIncreaseIndentation(SourceRange range,SourceLocation parentIndent); 1652d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner void commitClearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range); 1668f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1678f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void addRemoval(CharSourceRange range); 1688f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall void addInsertion(SourceLocation loc, StringRef text); 1698f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1708f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall /// \brief Stores text passed to the transformation methods to keep the string 1718f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall /// "alive". Since the vast majority of text will be the same, we also unique 1728f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall /// the strings using a StringMap. 1738f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall StringRef getUniqueText(StringRef text); 1748f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1758f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall /// \brief Computes the source location just past the end of the token at 1768f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall /// the given source location. If the location points at a macro, the whole 177711474a6c68a805e7c984415e9dc80c2e4167671Chandler Carruth /// macro expansion is skipped. 1788f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static SourceLocation getLocForEndOfToken(SourceLocation loc, 1798f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceManager &SM,Preprocessor &PP); 1808f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall}; 1818f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1828f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} // anonymous namespace 1838f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1848f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::startTransaction() { 1858f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(!IsInTransaction && 1868f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall "Cannot start a transaction in the middle of another one"); 1878f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall IsInTransaction = true; 1888f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 1898f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1908f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallbool TransformActionsImpl::commitTransaction() { 1918f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(IsInTransaction && "No transaction started"); 1928f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1938f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (CachedActions.empty()) { 1948f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall IsInTransaction = false; 1958f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return false; 1968f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 1978f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1988f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall // Verify that all actions are possible otherwise abort the whole transaction. 1998f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall bool AllActionsPossible = true; 2008f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall for (unsigned i = 0, e = CachedActions.size(); i != e; ++i) { 2018f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ActionData &act = CachedActions[i]; 2028f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall switch (act.Kind) { 2038f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_Insert: 2048f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (!canInsert(act.Loc)) 2058f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall AllActionsPossible = false; 2068f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2078f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_InsertAfterToken: 2088f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (!canInsertAfterToken(act.Loc)) 2098f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall AllActionsPossible = false; 2108f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2118f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_Remove: 2128f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (!canRemoveRange(act.R1)) 2138f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall AllActionsPossible = false; 2148f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2158f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_RemoveStmt: 2168f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(act.S); 2178f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (!canRemoveRange(act.S->getSourceRange())) 2188f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall AllActionsPossible = false; 2198f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2208f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_Replace: 2218f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (!canReplaceRange(act.R1, act.R2)) 2228f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall AllActionsPossible = false; 2238f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2248f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_ReplaceText: 2258f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (!canReplaceText(act.Loc, act.Text1)) 2268f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall AllActionsPossible = false; 2278f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2288f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_IncreaseIndentation: 2298f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall // This is not important, we don't care if it will fail. 2308f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2318f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_ClearDiagnostic: 2328f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall // We are just checking source rewrites. 2338f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2348f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 2358f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (!AllActionsPossible) 2368f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2378f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 2388f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 2398f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (!AllActionsPossible) { 2408f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall abortTransaction(); 2418f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return true; 2428f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 2438f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 2448f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall for (unsigned i = 0, e = CachedActions.size(); i != e; ++i) { 2458f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ActionData &act = CachedActions[i]; 2468f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall switch (act.Kind) { 2478f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_Insert: 2488f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall commitInsert(act.Loc, act.Text1); 2498f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2508f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_InsertAfterToken: 2518f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall commitInsertAfterToken(act.Loc, act.Text1); 2528f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2538f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_Remove: 2548f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall commitRemove(act.R1); 2558f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2568f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_RemoveStmt: 2578f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall commitRemoveStmt(act.S); 2588f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2598f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_Replace: 2608f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall commitReplace(act.R1, act.R2); 2618f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2628f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_ReplaceText: 2638f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall commitReplaceText(act.Loc, act.Text1, act.Text2); 2648f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2658f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_IncreaseIndentation: 2668f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall commitIncreaseIndentation(act.R1, act.Loc); 2678f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2688f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Act_ClearDiagnostic: 2698f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall commitClearDiagnostic(act.DiagIDs, act.R1); 2708f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 2718f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 2728f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 2738f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 2748f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CachedActions.clear(); 2758f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall IsInTransaction = false; 2768f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return false; 2778f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 2788f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 2798f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::abortTransaction() { 2808f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(IsInTransaction && "No transaction started"); 2818f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CachedActions.clear(); 2828f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall IsInTransaction = false; 2838f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 2848f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 2858f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::insert(SourceLocation loc, StringRef text) { 2868f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(IsInTransaction && "Actions only allowed during a transaction"); 2878f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall text = getUniqueText(text); 2888f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ActionData data; 2898f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Kind = Act_Insert; 2908f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Loc = loc; 2918f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Text1 = text; 2928f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CachedActions.push_back(data); 2938f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 2948f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 2958f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::insertAfterToken(SourceLocation loc, StringRef text) { 2968f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(IsInTransaction && "Actions only allowed during a transaction"); 2978f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall text = getUniqueText(text); 2988f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ActionData data; 2998f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Kind = Act_InsertAfterToken; 3008f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Loc = loc; 3018f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Text1 = text; 3028f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CachedActions.push_back(data); 3038f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 3048f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3058f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::remove(SourceRange range) { 3068f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(IsInTransaction && "Actions only allowed during a transaction"); 3078f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ActionData data; 3088f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Kind = Act_Remove; 3098f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.R1 = range; 3108f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CachedActions.push_back(data); 3118f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 3128f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3138f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::removeStmt(Stmt *S) { 3148f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(IsInTransaction && "Actions only allowed during a transaction"); 3158f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ActionData data; 3168f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Kind = Act_RemoveStmt; 3177e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall data.S = S->IgnoreImplicit(); // important for uniquing 3188f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CachedActions.push_back(data); 3198f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 3208f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3218f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::replace(SourceRange range, StringRef text) { 3228f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(IsInTransaction && "Actions only allowed during a transaction"); 3238f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall text = getUniqueText(text); 3248f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall remove(range); 3258f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall insert(range.getBegin(), text); 3268f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 3278f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3288f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::replace(SourceRange range, 3298f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceRange replacementRange) { 3308f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(IsInTransaction && "Actions only allowed during a transaction"); 3318f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ActionData data; 3328f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Kind = Act_Replace; 3338f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.R1 = range; 3348f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.R2 = replacementRange; 3358f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CachedActions.push_back(data); 3368f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 3378f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3388f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::replaceText(SourceLocation loc, StringRef text, 3398f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall StringRef replacementText) { 3408f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall text = getUniqueText(text); 3418f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall replacementText = getUniqueText(replacementText); 3428f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ActionData data; 3438f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Kind = Act_ReplaceText; 3448f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Loc = loc; 3458f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Text1 = text; 3468f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Text2 = replacementText; 3478f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CachedActions.push_back(data); 3488f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 3498f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3508f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::replaceStmt(Stmt *S, StringRef text) { 3518f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(IsInTransaction && "Actions only allowed during a transaction"); 3528f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall text = getUniqueText(text); 3538f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall insert(S->getLocStart(), text); 3548f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall removeStmt(S); 3558f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 3568f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3578f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::increaseIndentation(SourceRange range, 3588f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceLocation parentIndent) { 3598f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (range.isInvalid()) return; 3608f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(IsInTransaction && "Actions only allowed during a transaction"); 3618f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ActionData data; 3628f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Kind = Act_IncreaseIndentation; 3638f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.R1 = range; 3648f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Loc = parentIndent; 3658f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CachedActions.push_back(data); 3668f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 3678f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3682d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattnerbool TransformActionsImpl::clearDiagnostic(ArrayRef<unsigned> IDs, 3698f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceRange range) { 3708f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(IsInTransaction && "Actions only allowed during a transaction"); 3718f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (!CapturedDiags.hasDiagnostic(IDs, range)) 3728f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return false; 3738f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3748f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ActionData data; 3758f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.Kind = Act_ClearDiagnostic; 3768f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.R1 = range; 3778f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall data.DiagIDs.append(IDs.begin(), IDs.end()); 3788f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CachedActions.push_back(data); 3798f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return true; 3808f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 3818f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3828f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallbool TransformActionsImpl::canInsert(SourceLocation loc) { 3838f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (loc.isInvalid()) 3848f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return false; 3858f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3868f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceManager &SM = Ctx.getSourceManager(); 387402785357ab053dd53f4fdd858b9630a5e0f8badChandler Carruth if (SM.isInSystemHeader(SM.getExpansionLoc(loc))) 3888f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return false; 3898f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3908f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (loc.isFileID()) 3918f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return true; 392433db06b614f26dc6829e86d6ff469e2cca7d4f9Chandler Carruth return PP.isAtStartOfMacroExpansion(loc); 3938f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 3948f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3958f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallbool TransformActionsImpl::canInsertAfterToken(SourceLocation loc) { 3968f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (loc.isInvalid()) 3978f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return false; 3988f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 3998f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceManager &SM = Ctx.getSourceManager(); 400402785357ab053dd53f4fdd858b9630a5e0f8badChandler Carruth if (SM.isInSystemHeader(SM.getExpansionLoc(loc))) 4018f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return false; 4028f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4038f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (loc.isFileID()) 4048f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return true; 405433db06b614f26dc6829e86d6ff469e2cca7d4f9Chandler Carruth return PP.isAtEndOfMacroExpansion(loc); 4068f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 4078f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4088f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallbool TransformActionsImpl::canRemoveRange(SourceRange range) { 4098f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return canInsert(range.getBegin()) && canInsertAfterToken(range.getEnd()); 4108f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 4118f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4128f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallbool TransformActionsImpl::canReplaceRange(SourceRange range, 4138f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceRange replacementRange) { 4148f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return canRemoveRange(range) && canRemoveRange(replacementRange); 4158f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 4168f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4178f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallbool TransformActionsImpl::canReplaceText(SourceLocation loc, StringRef text) { 4188f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (!canInsert(loc)) 4198f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return false; 4208f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4218f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceManager &SM = Ctx.getSourceManager(); 422402785357ab053dd53f4fdd858b9630a5e0f8badChandler Carruth loc = SM.getExpansionLoc(loc); 4238f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4248f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall // Break down the source location. 4258f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(loc); 4268f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4278f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall // Try to load the file buffer. 4288f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall bool invalidTemp = false; 4295f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef file = SM.getBufferData(locInfo.first, &invalidTemp); 4308f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (invalidTemp) 4318f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return false; 4328f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4338f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return file.substr(locInfo.second).startswith(text); 4348f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 4358f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4368f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::commitInsert(SourceLocation loc, StringRef text) { 4378f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall addInsertion(loc, text); 4388f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 4398f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4408f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::commitInsertAfterToken(SourceLocation loc, 4418f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall StringRef text) { 4428f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall addInsertion(getLocForEndOfToken(loc, Ctx.getSourceManager(), PP), text); 4438f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 4448f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4458f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::commitRemove(SourceRange range) { 4468f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall addRemoval(CharSourceRange::getTokenRange(range)); 4478f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 4488f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4498f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::commitRemoveStmt(Stmt *S) { 4508f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(S); 4518f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (StmtRemovals.count(S)) 4528f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return; // already removed. 4538f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4548f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (Expr *E = dyn_cast<Expr>(S)) { 4558f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall commitRemove(E->getSourceRange()); 4568f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall commitInsert(E->getSourceRange().getBegin(), getARCMTMacroName()); 4578f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } else 4588f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall commitRemove(S->getSourceRange()); 4598f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4608f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall StmtRemovals.insert(S); 4618f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 4628f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4638f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::commitReplace(SourceRange range, 4648f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceRange replacementRange) { 4658f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall RangeComparison comp = CharRange::compare(replacementRange, range, 4668f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Ctx.getSourceManager(), PP); 4678f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall assert(comp == Range_Contained); 4688f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (comp != Range_Contained) 4698f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return; // Although we asserted, be extra safe for release build. 4708f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (range.getBegin() != replacementRange.getBegin()) 4718f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall addRemoval(CharSourceRange::getCharRange(range.getBegin(), 4728f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall replacementRange.getBegin())); 4738f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (replacementRange.getEnd() != range.getEnd()) 4748f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall addRemoval(CharSourceRange::getTokenRange( 4758f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall getLocForEndOfToken(replacementRange.getEnd(), 4768f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Ctx.getSourceManager(), PP), 4778f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall range.getEnd())); 4788f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 4798f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::commitReplaceText(SourceLocation loc, 4808f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall StringRef text, 4818f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall StringRef replacementText) { 4828f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceManager &SM = Ctx.getSourceManager(); 483402785357ab053dd53f4fdd858b9630a5e0f8badChandler Carruth loc = SM.getExpansionLoc(loc); 4848f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall // canReplaceText already checked if loc points at text. 485a64ccefdf0ea4e03ec88805d71b0af74950c7472Argyrios Kyrtzidis SourceLocation afterText = loc.getLocWithOffset(text.size()); 4868f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4878f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall addRemoval(CharSourceRange::getCharRange(loc, afterText)); 4888f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall commitInsert(loc, replacementText); 4898f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 4908f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 4918f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::commitIncreaseIndentation(SourceRange range, 4928f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceLocation parentIndent) { 4938f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceManager &SM = Ctx.getSourceManager(); 4948f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall IndentationRanges.push_back( 4958f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall std::make_pair(CharRange(CharSourceRange::getTokenRange(range), 4968f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SM, PP), 497402785357ab053dd53f4fdd858b9630a5e0f8badChandler Carruth SM.getExpansionLoc(parentIndent))); 4988f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 4998f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5002d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattnervoid TransformActionsImpl::commitClearDiagnostic(ArrayRef<unsigned> IDs, 5018f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceRange range) { 5028f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CapturedDiags.clearDiagnostic(IDs, range); 5038f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 5048f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5058f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::addInsertion(SourceLocation loc, StringRef text) { 5068f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceManager &SM = Ctx.getSourceManager(); 507402785357ab053dd53f4fdd858b9630a5e0f8badChandler Carruth loc = SM.getExpansionLoc(loc); 5088f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall for (std::list<CharRange>::reverse_iterator 5098f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall I = Removals.rbegin(), E = Removals.rend(); I != E; ++I) { 5108f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (!SM.isBeforeInTranslationUnit(loc, I->End)) 5118f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 5128f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (I->Begin.isBeforeInTranslationUnitThan(loc)) 5138f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return; 5148f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 5158f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5168f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Inserts[FullSourceLoc(loc, SM)].push_back(text); 5178f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 5188f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5198f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::addRemoval(CharSourceRange range) { 5208f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CharRange newRange(range, Ctx.getSourceManager(), PP); 5218f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (newRange.Begin == newRange.End) 5228f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return; 5238f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5248f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Inserts.erase(Inserts.upper_bound(newRange.Begin), 5258f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Inserts.lower_bound(newRange.End)); 5268f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5278f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall std::list<CharRange>::iterator I = Removals.end(); 5288f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall while (I != Removals.begin()) { 5298f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall std::list<CharRange>::iterator RI = I; 5308f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall --RI; 5318f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall RangeComparison comp = newRange.compareWith(*RI); 5328f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall switch (comp) { 5338f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Range_Before: 5348f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall --I; 5358f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 5368f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Range_After: 5378f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Removals.insert(I, newRange); 5388f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return; 5398f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Range_Contained: 5408f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return; 5418f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Range_Contains: 5428f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall RI->End = newRange.End; 5438f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Range_ExtendsBegin: 5448f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall newRange.End = RI->End; 5458f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Removals.erase(RI); 5468f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall break; 5478f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall case Range_ExtendsEnd: 5488f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall RI->End = newRange.End; 5498f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return; 5508f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 5518f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 5528f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5538f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Removals.insert(Removals.begin(), newRange); 5548f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 5558f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5568f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActionsImpl::applyRewrites( 5578f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall TransformActions::RewriteReceiver &receiver) { 5588f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall for (InsertsMap::iterator I = Inserts.begin(), E = Inserts.end(); I!=E; ++I) { 5598f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceLocation loc = I->first; 5608f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall for (TextsVec::iterator 5618f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall TI = I->second.begin(), TE = I->second.end(); TI != TE; ++TI) { 5628f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall receiver.insert(loc, *TI); 5638f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 5648f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 5658f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5668f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall for (std::vector<std::pair<CharRange, SourceLocation> >::iterator 5678f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall I = IndentationRanges.begin(), E = IndentationRanges.end(); I!=E; ++I) { 5688f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CharSourceRange range = CharSourceRange::getCharRange(I->first.Begin, 5698f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall I->first.End); 5708f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall receiver.increaseIndentation(range, I->second); 5718f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 5728f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5738f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall for (std::list<CharRange>::iterator 5748f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall I = Removals.begin(), E = Removals.end(); I != E; ++I) { 5758f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CharSourceRange range = CharSourceRange::getCharRange(I->Begin, I->End); 5768f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall receiver.remove(range); 5778f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall } 5788f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 5798f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5808f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// \brief Stores text passed to the transformation methods to keep the string 5818f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// "alive". Since the vast majority of text will be the same, we also unique 5828f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// the strings using a StringMap. 5838f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallStringRef TransformActionsImpl::getUniqueText(StringRef text) { 584176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return UniqueText.insert(std::make_pair(text, false)).first->first(); 5858f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 5868f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5878f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// \brief Computes the source location just past the end of the token at 5888f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// the given source location. If the location points at a macro, the whole 589711474a6c68a805e7c984415e9dc80c2e4167671Chandler Carruth/// macro expansion is skipped. 5908f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallSourceLocation TransformActionsImpl::getLocForEndOfToken(SourceLocation loc, 5918f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceManager &SM, 5928f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Preprocessor &PP) { 5938f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall if (loc.isMacroID()) 594edc3dccece244a584f8ebdb81da6c962c08e79beChandler Carruth loc = SM.getExpansionRange(loc).second; 5958f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return PP.getLocForEndOfToken(loc); 5968f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 5978f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5988f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallTransformActions::RewriteReceiver::~RewriteReceiver() { } 5998f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 600d6471f7c1921c7802804ce3ff6fe9768310f72b9David BlaikieTransformActions::TransformActions(DiagnosticsEngine &diag, 6018f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CapturedDiagList &capturedDiags, 6028f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall ASTContext &ctx, Preprocessor &PP) 603c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines : Diags(diag), CapturedDiags(capturedDiags) { 6048f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall Impl = new TransformActionsImpl(capturedDiags, ctx, PP); 6058f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6068f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6078f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallTransformActions::~TransformActions() { 6088f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall delete static_cast<TransformActionsImpl*>(Impl); 6098f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6108f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6118f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActions::startTransaction() { 6128f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static_cast<TransformActionsImpl*>(Impl)->startTransaction(); 6138f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6148f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6158f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallbool TransformActions::commitTransaction() { 6168f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return static_cast<TransformActionsImpl*>(Impl)->commitTransaction(); 6178f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6188f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6198f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActions::abortTransaction() { 6208f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static_cast<TransformActionsImpl*>(Impl)->abortTransaction(); 6218f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6228f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6238f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6245f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid TransformActions::insert(SourceLocation loc, StringRef text) { 6258f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static_cast<TransformActionsImpl*>(Impl)->insert(loc, text); 6268f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6278f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6288f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActions::insertAfterToken(SourceLocation loc, 6295f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef text) { 6308f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static_cast<TransformActionsImpl*>(Impl)->insertAfterToken(loc, text); 6318f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6328f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6338f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActions::remove(SourceRange range) { 6348f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static_cast<TransformActionsImpl*>(Impl)->remove(range); 6358f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6368f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6378f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActions::removeStmt(Stmt *S) { 6388f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static_cast<TransformActionsImpl*>(Impl)->removeStmt(S); 6398f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6408f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6415f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid TransformActions::replace(SourceRange range, StringRef text) { 6428f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static_cast<TransformActionsImpl*>(Impl)->replace(range, text); 6438f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6448f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6458f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActions::replace(SourceRange range, 6468f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceRange replacementRange) { 6478f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static_cast<TransformActionsImpl*>(Impl)->replace(range, replacementRange); 6488f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6498f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6505f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid TransformActions::replaceStmt(Stmt *S, StringRef text) { 6518f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static_cast<TransformActionsImpl*>(Impl)->replaceStmt(S, text); 6528f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6538f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6545f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid TransformActions::replaceText(SourceLocation loc, StringRef text, 6555f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef replacementText) { 6568f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static_cast<TransformActionsImpl*>(Impl)->replaceText(loc, text, 6578f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall replacementText); 6588f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6598f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6608f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActions::increaseIndentation(SourceRange range, 6618f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceLocation parentIndent) { 6628f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static_cast<TransformActionsImpl*>(Impl)->increaseIndentation(range, 6638f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall parentIndent); 6648f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6658f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6662d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattnerbool TransformActions::clearDiagnostic(ArrayRef<unsigned> IDs, 6678f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall SourceRange range) { 6688f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall return static_cast<TransformActionsImpl*>(Impl)->clearDiagnostic(IDs, range); 6698f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6708f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 6718f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallvoid TransformActions::applyRewrites(RewriteReceiver &receiver) { 6728f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall static_cast<TransformActionsImpl*>(Impl)->applyRewrites(receiver); 6738f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6748f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 675651f13cea278ec967336033dd032faef0e9fc2ecStephen HinesDiagnosticBuilder TransformActions::report(SourceLocation loc, unsigned diagId, 676651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SourceRange range) { 677651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines assert(!static_cast<TransformActionsImpl *>(Impl)->isInTransaction() && 6788f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall "Errors should be emitted out of a transaction"); 679651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return Diags.Report(loc, diagId) << range; 6808f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 6818f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 682651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid TransformActions::reportError(StringRef message, SourceLocation loc, 683b5c6babd3d8e0233b8ea5a4eb1e2700e30c0d396Fariborz Jahanian SourceRange range) { 684651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines report(loc, diag::err_mt_message, range) << message; 685b5c6babd3d8e0233b8ea5a4eb1e2700e30c0d396Fariborz Jahanian} 686b5c6babd3d8e0233b8ea5a4eb1e2700e30c0d396Fariborz Jahanian 687651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid TransformActions::reportWarning(StringRef message, SourceLocation loc, 688651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SourceRange range) { 689651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines report(loc, diag::warn_mt_message, range) << message; 690651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 6911fe4203ca05d0a3283efc8a2e8c01ecdf78fbf2eArgyrios Kyrtzidis 692651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid TransformActions::reportNote(StringRef message, SourceLocation loc, 693651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SourceRange range) { 694651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines report(loc, diag::note_mt_message, range) << message; 6958f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} 696