blob: 4f153b1ad2f4f2f03de53a0ae57906b5db5deef9 [file] [log] [blame]
John McCalld70fb982011-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"
Douglas Gregor79591782012-10-23 23:11:23 +000014#include "clang/Basic/Diagnostic.h"
John McCalld70fb982011-06-15 23:25:17 +000015#include "llvm/ADT/ArrayRef.h"
Argyrios Kyrtzidis273c7c42012-06-01 00:10:47 +000016#include "llvm/ADT/Optional.h"
Douglas Gregor79591782012-10-23 23:11:23 +000017#include <list>
John McCalld70fb982011-06-15 23:25:17 +000018
19namespace clang {
20 class Sema;
21 class Stmt;
22
23namespace arcmt {
24
25class CapturedDiagList {
26 typedef std::list<StoredDiagnostic> ListTy;
27 ListTy List;
28
29public:
30 void push_back(const StoredDiagnostic &diag) { List.push_back(diag); }
31
Chris Lattner54b16772011-07-23 17:14:25 +000032 bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
33 bool hasDiagnostic(ArrayRef<unsigned> IDs, SourceRange range) const;
John McCalld70fb982011-06-15 23:25:17 +000034
David Blaikie9c902b52011-09-25 23:23:43 +000035 void reportDiagnostics(DiagnosticsEngine &diags) const;
Argyrios Kyrtzidis90b6a2a2011-06-18 00:53:41 +000036
37 bool hasErrors() const;
Argyrios Kyrtzidisd5713632011-07-19 17:20:03 +000038
39 typedef ListTy::const_iterator iterator;
40 iterator begin() const { return List.begin(); }
41 iterator end() const { return List.end(); }
John McCalld70fb982011-06-15 23:25:17 +000042};
43
Argyrios Kyrtzidisd5713632011-07-19 17:20:03 +000044void writeARCDiagsToPlist(const std::string &outPath,
Chris Lattner54b16772011-07-23 17:14:25 +000045 ArrayRef<StoredDiagnostic> diags,
Argyrios Kyrtzidisd5713632011-07-19 17:20:03 +000046 SourceManager &SM, const LangOptions &LangOpts);
47
John McCalld70fb982011-06-15 23:25:17 +000048class TransformActions {
David Blaikie9c902b52011-09-25 23:23:43 +000049 DiagnosticsEngine &Diags;
John McCalld70fb982011-06-15 23:25:17 +000050 CapturedDiagList &CapturedDiags;
51 void *Impl; // TransformActionsImpl.
52
53public:
David Blaikie9c902b52011-09-25 23:23:43 +000054 TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags,
John McCalld70fb982011-06-15 23:25:17 +000055 ASTContext &ctx, Preprocessor &PP);
56 ~TransformActions();
57
58 void startTransaction();
59 bool commitTransaction();
60 void abortTransaction();
61
Chris Lattner01cf8db2011-07-20 06:58:45 +000062 void insert(SourceLocation loc, StringRef text);
63 void insertAfterToken(SourceLocation loc, StringRef text);
John McCalld70fb982011-06-15 23:25:17 +000064 void remove(SourceRange range);
65 void removeStmt(Stmt *S);
Chris Lattner01cf8db2011-07-20 06:58:45 +000066 void replace(SourceRange range, StringRef text);
John McCalld70fb982011-06-15 23:25:17 +000067 void replace(SourceRange range, SourceRange replacementRange);
Chris Lattner01cf8db2011-07-20 06:58:45 +000068 void replaceStmt(Stmt *S, StringRef text);
69 void replaceText(SourceLocation loc, StringRef text,
70 StringRef replacementText);
John McCalld70fb982011-06-15 23:25:17 +000071 void increaseIndentation(SourceRange range,
72 SourceLocation parentIndent);
73
Chris Lattner54b16772011-07-23 17:14:25 +000074 bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
John McCalld70fb982011-06-15 23:25:17 +000075 bool clearAllDiagnostics(SourceRange range) {
Craig Topper5fc8fc22014-08-27 06:28:36 +000076 return clearDiagnostic(None, range);
John McCalld70fb982011-06-15 23:25:17 +000077 }
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 Toker42aa2122014-01-26 05:07:32 +000097 DiagnosticBuilder report(SourceLocation loc, unsigned diagId,
98 SourceRange range = SourceRange());
Chris Lattner01cf8db2011-07-20 06:58:45 +000099 void reportError(StringRef error, SourceLocation loc,
John McCalld70fb982011-06-15 23:25:17 +0000100 SourceRange range = SourceRange());
Fariborz Jahanianaa7b9aa2012-01-25 00:20:29 +0000101 void reportWarning(StringRef warning, SourceLocation loc,
102 SourceRange range = SourceRange());
Chris Lattner01cf8db2011-07-20 06:58:45 +0000103 void reportNote(StringRef note, SourceLocation loc,
John McCalld70fb982011-06-15 23:25:17 +0000104 SourceRange range = SourceRange());
105
Alp Toker379b97f2014-07-02 17:08:00 +0000106 bool hasReportedErrors() const {
107 return Diags.hasUnrecoverableErrorOccurred();
108 }
Argyrios Kyrtzidis73a0d322011-07-18 07:44:45 +0000109
John McCalld70fb982011-06-15 23:25:17 +0000110 class RewriteReceiver {
111 public:
112 virtual ~RewriteReceiver();
113
Chris Lattner01cf8db2011-07-20 06:58:45 +0000114 virtual void insert(SourceLocation loc, StringRef text) = 0;
John McCalld70fb982011-06-15 23:25:17 +0000115 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
123class Transaction {
124 TransformActions &TA;
125 bool Aborted;
126
127public:
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
145class MigrationPass {
146public:
147 ASTContext &Ctx;
Argyrios Kyrtzidisd208ef92011-11-04 15:58:08 +0000148 LangOptions::GCMode OrigGCMode;
Fariborz Jahanianaa7b9aa2012-01-25 00:20:29 +0000149 MigratorOptions MigOptions;
John McCalld70fb982011-06-15 23:25:17 +0000150 Sema &SemaRef;
151 TransformActions &TA;
Argyrios Kyrtzidis03fbe3e2013-01-04 18:30:08 +0000152 const CapturedDiagList &CapturedDiags;
John McCalld70fb982011-06-15 23:25:17 +0000153 std::vector<SourceLocation> &ARCMTMacroLocs;
David Blaikie05785d12013-02-20 22:23:23 +0000154 Optional<bool> EnableCFBridgeFns;
John McCalld70fb982011-06-15 23:25:17 +0000155
Argyrios Kyrtzidisd208ef92011-11-04 15:58:08 +0000156 MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode,
157 Sema &sema, TransformActions &TA,
Argyrios Kyrtzidis03fbe3e2013-01-04 18:30:08 +0000158 const CapturedDiagList &capturedDiags,
John McCalld70fb982011-06-15 23:25:17 +0000159 std::vector<SourceLocation> &ARCMTMacroLocs)
Fariborz Jahanianaa7b9aa2012-01-25 00:20:29 +0000160 : Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(),
Argyrios Kyrtzidis03fbe3e2013-01-04 18:30:08 +0000161 SemaRef(sema), TA(TA), CapturedDiags(capturedDiags),
Argyrios Kyrtzidisd208ef92011-11-04 15:58:08 +0000162 ARCMTMacroLocs(ARCMTMacroLocs) { }
163
Argyrios Kyrtzidis03fbe3e2013-01-04 18:30:08 +0000164 const CapturedDiagList &getDiags() const { return CapturedDiags; }
165
Argyrios Kyrtzidisd208ef92011-11-04 15:58:08 +0000166 bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; }
Fariborz Jahanian0c859d62012-01-26 00:08:04 +0000167 bool noFinalizeRemoval() const { return MigOptions.NoFinalizeRemoval; }
168 void setNoFinalizeRemoval(bool val) {MigOptions.NoFinalizeRemoval = val; }
Argyrios Kyrtzidis273c7c42012-06-01 00:10:47 +0000169
170 bool CFBridgingFunctionsDefined();
John McCalld70fb982011-06-15 23:25:17 +0000171};
172
Chris Lattner01cf8db2011-07-20 06:58:45 +0000173static inline StringRef getARCMTMacroName() {
John McCalld70fb982011-06-15 23:25:17 +0000174 return "__IMPL_ARCMT_REMOVED_EXPR__";
175}
176
177} // end namespace arcmt
178
179} // end namespace clang
180
181#endif