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