1 //===-- Internals.h - Implementation Details---------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H
11 #define LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H
13 #include "clang/ARCMigrate/ARCMT.h"
14 #include "clang/Basic/Diagnostic.h"
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/Optional.h"
25 class CapturedDiagList {
26 typedef std::list<StoredDiagnostic> ListTy;
30 void push_back(const StoredDiagnostic &diag) { List.push_back(diag); }
32 bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
33 bool hasDiagnostic(ArrayRef<unsigned> IDs, SourceRange range) const;
35 void reportDiagnostics(DiagnosticsEngine &diags) const;
37 bool hasErrors() const;
39 typedef ListTy::const_iterator iterator;
40 iterator begin() const { return List.begin(); }
41 iterator end() const { return List.end(); }
44 void writeARCDiagsToPlist(const std::string &outPath,
45 ArrayRef<StoredDiagnostic> diags,
46 SourceManager &SM, const LangOptions &LangOpts);
48 class TransformActions {
49 DiagnosticsEngine &Diags;
50 CapturedDiagList &CapturedDiags;
51 void *Impl; // TransformActionsImpl.
54 TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags,
55 ASTContext &ctx, Preprocessor &PP);
58 void startTransaction();
59 bool commitTransaction();
60 void abortTransaction();
62 void insert(SourceLocation loc, StringRef text);
63 void insertAfterToken(SourceLocation loc, StringRef text);
64 void remove(SourceRange range);
65 void removeStmt(Stmt *S);
66 void replace(SourceRange range, StringRef text);
67 void replace(SourceRange range, SourceRange replacementRange);
68 void replaceStmt(Stmt *S, StringRef text);
69 void replaceText(SourceLocation loc, StringRef text,
70 StringRef replacementText);
71 void increaseIndentation(SourceRange range,
72 SourceLocation parentIndent);
74 bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
75 bool clearAllDiagnostics(SourceRange range) {
76 return clearDiagnostic(None, range);
78 bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
79 unsigned IDs[] = { ID1, ID2 };
80 return clearDiagnostic(IDs, range);
82 bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3,
84 unsigned IDs[] = { ID1, ID2, ID3 };
85 return clearDiagnostic(IDs, range);
88 bool hasDiagnostic(unsigned ID, SourceRange range) {
89 return CapturedDiags.hasDiagnostic(ID, range);
92 bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
93 unsigned IDs[] = { ID1, ID2 };
94 return CapturedDiags.hasDiagnostic(IDs, range);
97 DiagnosticBuilder report(SourceLocation loc, unsigned diagId,
98 SourceRange range = SourceRange());
99 void reportError(StringRef error, SourceLocation loc,
100 SourceRange range = SourceRange());
101 void reportWarning(StringRef warning, SourceLocation loc,
102 SourceRange range = SourceRange());
103 void reportNote(StringRef note, SourceLocation loc,
104 SourceRange range = SourceRange());
106 bool hasReportedErrors() const {
107 return Diags.hasUnrecoverableErrorOccurred();
110 class RewriteReceiver {
112 virtual ~RewriteReceiver();
114 virtual void insert(SourceLocation loc, StringRef text) = 0;
115 virtual void remove(CharSourceRange range) = 0;
116 virtual void increaseIndentation(CharSourceRange range,
117 SourceLocation parentIndent) = 0;
120 void applyRewrites(RewriteReceiver &receiver);
124 TransformActions &TA;
128 Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
129 TA.startTransaction();
134 TA.commitTransaction();
138 TA.abortTransaction();
142 bool isAborted() const { return Aborted; }
145 class MigrationPass {
148 LangOptions::GCMode OrigGCMode;
149 MigratorOptions MigOptions;
151 TransformActions &TA;
152 const CapturedDiagList &CapturedDiags;
153 std::vector<SourceLocation> &ARCMTMacroLocs;
154 Optional<bool> EnableCFBridgeFns;
156 MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode,
157 Sema &sema, TransformActions &TA,
158 const CapturedDiagList &capturedDiags,
159 std::vector<SourceLocation> &ARCMTMacroLocs)
160 : Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(),
161 SemaRef(sema), TA(TA), CapturedDiags(capturedDiags),
162 ARCMTMacroLocs(ARCMTMacroLocs) { }
164 const CapturedDiagList &getDiags() const { return CapturedDiags; }
166 bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; }
167 bool noFinalizeRemoval() const { return MigOptions.NoFinalizeRemoval; }
168 void setNoFinalizeRemoval(bool val) {MigOptions.NoFinalizeRemoval = val; }
170 bool CFBridgingFunctionsDefined();
173 static inline StringRef getARCMTMacroName() {
174 return "__IMPL_ARCMT_REMOVED_EXPR__";
177 } // end namespace arcmt
179 } // end namespace clang