blob: 935fc9b52535601925f2a104be5674b68e2fca44 [file] [log] [blame]
John McCall8f0e8d22011-06-15 23:25:17 +00001//===-- 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"
Argyrios Kyrtzidis684190b2012-06-01 00:10:47 +000015#include "llvm/ADT/Optional.h"
John McCall8f0e8d22011-06-15 23:25:17 +000016
17namespace clang {
18 class Sema;
19 class Stmt;
20
21namespace arcmt {
22
23class CapturedDiagList {
24 typedef std::list<StoredDiagnostic> ListTy;
25 ListTy List;
26
27public:
28 void push_back(const StoredDiagnostic &diag) { List.push_back(diag); }
29
Chris Lattner2d3ba4f2011-07-23 17:14:25 +000030 bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
31 bool hasDiagnostic(ArrayRef<unsigned> IDs, SourceRange range) const;
John McCall8f0e8d22011-06-15 23:25:17 +000032
David Blaikied6471f72011-09-25 23:23:43 +000033 void reportDiagnostics(DiagnosticsEngine &diags) const;
Argyrios Kyrtzidise665d692011-06-18 00:53:41 +000034
35 bool hasErrors() const;
Argyrios Kyrtzidis7ee20492011-07-19 17:20:03 +000036
37 typedef ListTy::const_iterator iterator;
38 iterator begin() const { return List.begin(); }
39 iterator end() const { return List.end(); }
John McCall8f0e8d22011-06-15 23:25:17 +000040};
41
Argyrios Kyrtzidis7ee20492011-07-19 17:20:03 +000042void writeARCDiagsToPlist(const std::string &outPath,
Chris Lattner2d3ba4f2011-07-23 17:14:25 +000043 ArrayRef<StoredDiagnostic> diags,
Argyrios Kyrtzidis7ee20492011-07-19 17:20:03 +000044 SourceManager &SM, const LangOptions &LangOpts);
45
John McCall8f0e8d22011-06-15 23:25:17 +000046class TransformActions {
David Blaikied6471f72011-09-25 23:23:43 +000047 DiagnosticsEngine &Diags;
John McCall8f0e8d22011-06-15 23:25:17 +000048 CapturedDiagList &CapturedDiags;
Argyrios Kyrtzidisfd103982011-07-18 07:44:45 +000049 bool ReportedErrors;
John McCall8f0e8d22011-06-15 23:25:17 +000050 void *Impl; // TransformActionsImpl.
51
52public:
David Blaikied6471f72011-09-25 23:23:43 +000053 TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags,
John McCall8f0e8d22011-06-15 23:25:17 +000054 ASTContext &ctx, Preprocessor &PP);
55 ~TransformActions();
56
57 void startTransaction();
58 bool commitTransaction();
59 void abortTransaction();
60
Chris Lattner686775d2011-07-20 06:58:45 +000061 void insert(SourceLocation loc, StringRef text);
62 void insertAfterToken(SourceLocation loc, StringRef text);
John McCall8f0e8d22011-06-15 23:25:17 +000063 void remove(SourceRange range);
64 void removeStmt(Stmt *S);
Chris Lattner686775d2011-07-20 06:58:45 +000065 void replace(SourceRange range, StringRef text);
John McCall8f0e8d22011-06-15 23:25:17 +000066 void replace(SourceRange range, SourceRange replacementRange);
Chris Lattner686775d2011-07-20 06:58:45 +000067 void replaceStmt(Stmt *S, StringRef text);
68 void replaceText(SourceLocation loc, StringRef text,
69 StringRef replacementText);
John McCall8f0e8d22011-06-15 23:25:17 +000070 void increaseIndentation(SourceRange range,
71 SourceLocation parentIndent);
72
Chris Lattner2d3ba4f2011-07-23 17:14:25 +000073 bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
John McCall8f0e8d22011-06-15 23:25:17 +000074 bool clearAllDiagnostics(SourceRange range) {
Chris Lattner2d3ba4f2011-07-23 17:14:25 +000075 return clearDiagnostic(ArrayRef<unsigned>(), range);
John McCall8f0e8d22011-06-15 23:25:17 +000076 }
77 bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
78 unsigned IDs[] = { ID1, ID2 };
79 return clearDiagnostic(IDs, range);
80 }
81 bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3,
82 SourceRange range) {
83 unsigned IDs[] = { ID1, ID2, ID3 };
84 return clearDiagnostic(IDs, range);
85 }
86
87 bool hasDiagnostic(unsigned ID, SourceRange range) {
88 return CapturedDiags.hasDiagnostic(ID, range);
89 }
90
91 bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
92 unsigned IDs[] = { ID1, ID2 };
93 return CapturedDiags.hasDiagnostic(IDs, range);
94 }
95
Chris Lattner686775d2011-07-20 06:58:45 +000096 void reportError(StringRef error, SourceLocation loc,
John McCall8f0e8d22011-06-15 23:25:17 +000097 SourceRange range = SourceRange());
Fariborz Jahanianb5c6bab2012-01-25 00:20:29 +000098 void reportWarning(StringRef warning, SourceLocation loc,
99 SourceRange range = SourceRange());
Chris Lattner686775d2011-07-20 06:58:45 +0000100 void reportNote(StringRef note, SourceLocation loc,
John McCall8f0e8d22011-06-15 23:25:17 +0000101 SourceRange range = SourceRange());
102
Argyrios Kyrtzidisfd103982011-07-18 07:44:45 +0000103 bool hasReportedErrors() const { return ReportedErrors; }
104
John McCall8f0e8d22011-06-15 23:25:17 +0000105 class RewriteReceiver {
106 public:
107 virtual ~RewriteReceiver();
108
Chris Lattner686775d2011-07-20 06:58:45 +0000109 virtual void insert(SourceLocation loc, StringRef text) = 0;
John McCall8f0e8d22011-06-15 23:25:17 +0000110 virtual void remove(CharSourceRange range) = 0;
111 virtual void increaseIndentation(CharSourceRange range,
112 SourceLocation parentIndent) = 0;
113 };
114
115 void applyRewrites(RewriteReceiver &receiver);
116};
117
118class Transaction {
119 TransformActions &TA;
120 bool Aborted;
121
122public:
123 Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
124 TA.startTransaction();
125 }
126
127 ~Transaction() {
128 if (!isAborted())
129 TA.commitTransaction();
130 }
131
132 void abort() {
133 TA.abortTransaction();
134 Aborted = true;
135 }
136
137 bool isAborted() const { return Aborted; }
138};
139
140class MigrationPass {
141public:
142 ASTContext &Ctx;
Argyrios Kyrtzidise0ac7452011-11-04 15:58:08 +0000143 LangOptions::GCMode OrigGCMode;
Fariborz Jahanianb5c6bab2012-01-25 00:20:29 +0000144 MigratorOptions MigOptions;
John McCall8f0e8d22011-06-15 23:25:17 +0000145 Sema &SemaRef;
146 TransformActions &TA;
147 std::vector<SourceLocation> &ARCMTMacroLocs;
Argyrios Kyrtzidis684190b2012-06-01 00:10:47 +0000148 llvm::Optional<bool> EnableCFBridgeFns;
John McCall8f0e8d22011-06-15 23:25:17 +0000149
Argyrios Kyrtzidise0ac7452011-11-04 15:58:08 +0000150 MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode,
151 Sema &sema, TransformActions &TA,
John McCall8f0e8d22011-06-15 23:25:17 +0000152 std::vector<SourceLocation> &ARCMTMacroLocs)
Fariborz Jahanianb5c6bab2012-01-25 00:20:29 +0000153 : Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(),
154 SemaRef(sema), TA(TA),
Argyrios Kyrtzidise0ac7452011-11-04 15:58:08 +0000155 ARCMTMacroLocs(ARCMTMacroLocs) { }
156
157 bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; }
Fariborz Jahanianb5c6bab2012-01-25 00:20:29 +0000158 bool noNSAllocReallocError() const { return MigOptions.NoNSAllocReallocError; }
159 void setNSAllocReallocError(bool val) { MigOptions.NoNSAllocReallocError = val; }
Fariborz Jahanian26f0e4e2012-01-26 00:08:04 +0000160 bool noFinalizeRemoval() const { return MigOptions.NoFinalizeRemoval; }
161 void setNoFinalizeRemoval(bool val) {MigOptions.NoFinalizeRemoval = val; }
Argyrios Kyrtzidis684190b2012-06-01 00:10:47 +0000162
163 bool CFBridgingFunctionsDefined();
John McCall8f0e8d22011-06-15 23:25:17 +0000164};
165
Chris Lattner686775d2011-07-20 06:58:45 +0000166static inline StringRef getARCMTMacroName() {
John McCall8f0e8d22011-06-15 23:25:17 +0000167 return "__IMPL_ARCMT_REMOVED_EXPR__";
168}
169
170} // end namespace arcmt
171
172} // end namespace clang
173
174#endif