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