John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 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 | |
| 16 | namespace clang { |
| 17 | class Sema; |
| 18 | class Stmt; |
| 19 | |
| 20 | namespace arcmt { |
| 21 | |
| 22 | class CapturedDiagList { |
| 23 | typedef std::list<StoredDiagnostic> ListTy; |
| 24 | ListTy List; |
| 25 | |
| 26 | public: |
| 27 | void push_back(const StoredDiagnostic &diag) { List.push_back(diag); } |
| 28 | |
Chris Lattner | 2d3ba4f | 2011-07-23 17:14:25 +0000 | [diff] [blame] | 29 | bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range); |
| 30 | bool hasDiagnostic(ArrayRef<unsigned> IDs, SourceRange range) const; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 31 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame^] | 32 | void reportDiagnostics(DiagnosticsEngine &diags) const; |
Argyrios Kyrtzidis | e665d69 | 2011-06-18 00:53:41 +0000 | [diff] [blame] | 33 | |
| 34 | bool hasErrors() const; |
Argyrios Kyrtzidis | 7ee2049 | 2011-07-19 17:20:03 +0000 | [diff] [blame] | 35 | |
| 36 | typedef ListTy::const_iterator iterator; |
| 37 | iterator begin() const { return List.begin(); } |
| 38 | iterator end() const { return List.end(); } |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
Argyrios Kyrtzidis | 7ee2049 | 2011-07-19 17:20:03 +0000 | [diff] [blame] | 41 | void writeARCDiagsToPlist(const std::string &outPath, |
Chris Lattner | 2d3ba4f | 2011-07-23 17:14:25 +0000 | [diff] [blame] | 42 | ArrayRef<StoredDiagnostic> diags, |
Argyrios Kyrtzidis | 7ee2049 | 2011-07-19 17:20:03 +0000 | [diff] [blame] | 43 | SourceManager &SM, const LangOptions &LangOpts); |
| 44 | |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 45 | class TransformActions { |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame^] | 46 | DiagnosticsEngine &Diags; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 47 | CapturedDiagList &CapturedDiags; |
Argyrios Kyrtzidis | fd10398 | 2011-07-18 07:44:45 +0000 | [diff] [blame] | 48 | bool ReportedErrors; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 49 | void *Impl; // TransformActionsImpl. |
| 50 | |
| 51 | public: |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame^] | 52 | TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags, |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 53 | ASTContext &ctx, Preprocessor &PP); |
| 54 | ~TransformActions(); |
| 55 | |
| 56 | void startTransaction(); |
| 57 | bool commitTransaction(); |
| 58 | void abortTransaction(); |
| 59 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 60 | void insert(SourceLocation loc, StringRef text); |
| 61 | void insertAfterToken(SourceLocation loc, StringRef text); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 62 | void remove(SourceRange range); |
| 63 | void removeStmt(Stmt *S); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 64 | void replace(SourceRange range, StringRef text); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 65 | void replace(SourceRange range, SourceRange replacementRange); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 66 | void replaceStmt(Stmt *S, StringRef text); |
| 67 | void replaceText(SourceLocation loc, StringRef text, |
| 68 | StringRef replacementText); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 69 | void increaseIndentation(SourceRange range, |
| 70 | SourceLocation parentIndent); |
| 71 | |
Chris Lattner | 2d3ba4f | 2011-07-23 17:14:25 +0000 | [diff] [blame] | 72 | bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 73 | bool clearAllDiagnostics(SourceRange range) { |
Chris Lattner | 2d3ba4f | 2011-07-23 17:14:25 +0000 | [diff] [blame] | 74 | return clearDiagnostic(ArrayRef<unsigned>(), range); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 75 | } |
| 76 | bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) { |
| 77 | unsigned IDs[] = { ID1, ID2 }; |
| 78 | return clearDiagnostic(IDs, range); |
| 79 | } |
| 80 | bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3, |
| 81 | SourceRange range) { |
| 82 | unsigned IDs[] = { ID1, ID2, ID3 }; |
| 83 | return clearDiagnostic(IDs, range); |
| 84 | } |
| 85 | |
| 86 | bool hasDiagnostic(unsigned ID, SourceRange range) { |
| 87 | return CapturedDiags.hasDiagnostic(ID, range); |
| 88 | } |
| 89 | |
| 90 | bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) { |
| 91 | unsigned IDs[] = { ID1, ID2 }; |
| 92 | return CapturedDiags.hasDiagnostic(IDs, range); |
| 93 | } |
| 94 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 95 | void reportError(StringRef error, SourceLocation loc, |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 96 | SourceRange range = SourceRange()); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 97 | void reportNote(StringRef note, SourceLocation loc, |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 98 | SourceRange range = SourceRange()); |
| 99 | |
Argyrios Kyrtzidis | fd10398 | 2011-07-18 07:44:45 +0000 | [diff] [blame] | 100 | bool hasReportedErrors() const { return ReportedErrors; } |
| 101 | |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 102 | class RewriteReceiver { |
| 103 | public: |
| 104 | virtual ~RewriteReceiver(); |
| 105 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 106 | virtual void insert(SourceLocation loc, StringRef text) = 0; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 107 | virtual void remove(CharSourceRange range) = 0; |
| 108 | virtual void increaseIndentation(CharSourceRange range, |
| 109 | SourceLocation parentIndent) = 0; |
| 110 | }; |
| 111 | |
| 112 | void applyRewrites(RewriteReceiver &receiver); |
| 113 | }; |
| 114 | |
| 115 | class Transaction { |
| 116 | TransformActions &TA; |
| 117 | bool Aborted; |
| 118 | |
| 119 | public: |
| 120 | Transaction(TransformActions &TA) : TA(TA), Aborted(false) { |
| 121 | TA.startTransaction(); |
| 122 | } |
| 123 | |
| 124 | ~Transaction() { |
| 125 | if (!isAborted()) |
| 126 | TA.commitTransaction(); |
| 127 | } |
| 128 | |
| 129 | void abort() { |
| 130 | TA.abortTransaction(); |
| 131 | Aborted = true; |
| 132 | } |
| 133 | |
| 134 | bool isAborted() const { return Aborted; } |
| 135 | }; |
| 136 | |
| 137 | class MigrationPass { |
| 138 | public: |
| 139 | ASTContext &Ctx; |
| 140 | Sema &SemaRef; |
| 141 | TransformActions &TA; |
| 142 | std::vector<SourceLocation> &ARCMTMacroLocs; |
| 143 | |
| 144 | MigrationPass(ASTContext &Ctx, Sema &sema, TransformActions &TA, |
| 145 | std::vector<SourceLocation> &ARCMTMacroLocs) |
| 146 | : Ctx(Ctx), SemaRef(sema), TA(TA), ARCMTMacroLocs(ARCMTMacroLocs) { } |
| 147 | }; |
| 148 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame^] | 149 | bool isARCDiagnostic(unsigned diagID, DiagnosticsEngine &Diag); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 150 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 151 | static inline StringRef getARCMTMacroName() { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 152 | return "__IMPL_ARCMT_REMOVED_EXPR__"; |
| 153 | } |
| 154 | |
| 155 | } // end namespace arcmt |
| 156 | |
| 157 | } // end namespace clang |
| 158 | |
| 159 | #endif |