Internals.h revision 224145
1//===-- Internals.h - Implementation Details---------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H 11#define LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H 12 13#include "clang/ARCMigrate/ARCMT.h" 14#include "llvm/ADT/ArrayRef.h" 15 16namespace clang { 17 class Sema; 18 class Stmt; 19 20namespace arcmt { 21 22class CapturedDiagList { 23 typedef std::list<StoredDiagnostic> ListTy; 24 ListTy List; 25 26public: 27 void push_back(const StoredDiagnostic &diag) { List.push_back(diag); } 28 29 bool clearDiagnostic(llvm::ArrayRef<unsigned> IDs, SourceRange range); 30 bool hasDiagnostic(llvm::ArrayRef<unsigned> IDs, SourceRange range) const; 31 32 void reportDiagnostics(Diagnostic &diags) const; 33 34 bool hasErrors() const; 35}; 36 37class TransformActions { 38 Diagnostic &Diags; 39 CapturedDiagList &CapturedDiags; 40 void *Impl; // TransformActionsImpl. 41 42public: 43 TransformActions(Diagnostic &diag, CapturedDiagList &capturedDiags, 44 ASTContext &ctx, Preprocessor &PP); 45 ~TransformActions(); 46 47 void startTransaction(); 48 bool commitTransaction(); 49 void abortTransaction(); 50 51 void insert(SourceLocation loc, llvm::StringRef text); 52 void insertAfterToken(SourceLocation loc, llvm::StringRef text); 53 void remove(SourceRange range); 54 void removeStmt(Stmt *S); 55 void replace(SourceRange range, llvm::StringRef text); 56 void replace(SourceRange range, SourceRange replacementRange); 57 void replaceStmt(Stmt *S, llvm::StringRef text); 58 void replaceText(SourceLocation loc, llvm::StringRef text, 59 llvm::StringRef replacementText); 60 void increaseIndentation(SourceRange range, 61 SourceLocation parentIndent); 62 63 bool clearDiagnostic(llvm::ArrayRef<unsigned> IDs, SourceRange range); 64 bool clearAllDiagnostics(SourceRange range) { 65 return clearDiagnostic(llvm::ArrayRef<unsigned>(), range); 66 } 67 bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) { 68 unsigned IDs[] = { ID1, ID2 }; 69 return clearDiagnostic(IDs, range); 70 } 71 bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3, 72 SourceRange range) { 73 unsigned IDs[] = { ID1, ID2, ID3 }; 74 return clearDiagnostic(IDs, range); 75 } 76 77 bool hasDiagnostic(unsigned ID, SourceRange range) { 78 return CapturedDiags.hasDiagnostic(ID, range); 79 } 80 81 bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) { 82 unsigned IDs[] = { ID1, ID2 }; 83 return CapturedDiags.hasDiagnostic(IDs, range); 84 } 85 86 void reportError(llvm::StringRef error, SourceLocation loc, 87 SourceRange range = SourceRange()); 88 void reportNote(llvm::StringRef note, SourceLocation loc, 89 SourceRange range = SourceRange()); 90 91 class RewriteReceiver { 92 public: 93 virtual ~RewriteReceiver(); 94 95 virtual void insert(SourceLocation loc, llvm::StringRef text) = 0; 96 virtual void remove(CharSourceRange range) = 0; 97 virtual void increaseIndentation(CharSourceRange range, 98 SourceLocation parentIndent) = 0; 99 }; 100 101 void applyRewrites(RewriteReceiver &receiver); 102}; 103 104class Transaction { 105 TransformActions &TA; 106 bool Aborted; 107 108public: 109 Transaction(TransformActions &TA) : TA(TA), Aborted(false) { 110 TA.startTransaction(); 111 } 112 113 ~Transaction() { 114 if (!isAborted()) 115 TA.commitTransaction(); 116 } 117 118 void abort() { 119 TA.abortTransaction(); 120 Aborted = true; 121 } 122 123 bool isAborted() const { return Aborted; } 124}; 125 126class MigrationPass { 127public: 128 ASTContext &Ctx; 129 Sema &SemaRef; 130 TransformActions &TA; 131 std::vector<SourceLocation> &ARCMTMacroLocs; 132 133 MigrationPass(ASTContext &Ctx, Sema &sema, TransformActions &TA, 134 std::vector<SourceLocation> &ARCMTMacroLocs) 135 : Ctx(Ctx), SemaRef(sema), TA(TA), ARCMTMacroLocs(ARCMTMacroLocs) { } 136}; 137 138bool isARCDiagnostic(unsigned diagID, Diagnostic &Diag); 139 140static inline llvm::StringRef getARCMTMacroName() { 141 return "__IMPL_ARCMT_REMOVED_EXPR__"; 142} 143 144} // end namespace arcmt 145 146} // end namespace clang 147 148#endif 149