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 "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/Optional.h"
23 class CapturedDiagList {
24 typedef std::list<StoredDiagnostic> ListTy;
28 void push_back(const StoredDiagnostic &diag) { List.push_back(diag); }
30 bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
31 bool hasDiagnostic(ArrayRef<unsigned> IDs, SourceRange range) const;
33 void reportDiagnostics(DiagnosticsEngine &diags) const;
35 bool hasErrors() const;
37 typedef ListTy::const_iterator iterator;
38 iterator begin() const { return List.begin(); }
39 iterator end() const { return List.end(); }
42 void writeARCDiagsToPlist(const std::string &outPath,
43 ArrayRef<StoredDiagnostic> diags,
44 SourceManager &SM, const LangOptions &LangOpts);
46 class TransformActions {
47 DiagnosticsEngine &Diags;
48 CapturedDiagList &CapturedDiags;
50 void *Impl; // TransformActionsImpl.
53 TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags,
54 ASTContext &ctx, Preprocessor &PP);
57 void startTransaction();
58 bool commitTransaction();
59 void abortTransaction();
61 void insert(SourceLocation loc, StringRef text);
62 void insertAfterToken(SourceLocation loc, StringRef text);
63 void remove(SourceRange range);
64 void removeStmt(Stmt *S);
65 void replace(SourceRange range, StringRef text);
66 void replace(SourceRange range, SourceRange replacementRange);
67 void replaceStmt(Stmt *S, StringRef text);
68 void replaceText(SourceLocation loc, StringRef text,
69 StringRef replacementText);
70 void increaseIndentation(SourceRange range,
71 SourceLocation parentIndent);
73 bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
74 bool clearAllDiagnostics(SourceRange range) {
75 return clearDiagnostic(ArrayRef<unsigned>(), range);
77 bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
78 unsigned IDs[] = { ID1, ID2 };
79 return clearDiagnostic(IDs, range);
81 bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3,
83 unsigned IDs[] = { ID1, ID2, ID3 };
84 return clearDiagnostic(IDs, range);
87 bool hasDiagnostic(unsigned ID, SourceRange range) {
88 return CapturedDiags.hasDiagnostic(ID, range);
91 bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
92 unsigned IDs[] = { ID1, ID2 };
93 return CapturedDiags.hasDiagnostic(IDs, range);
96 void reportError(StringRef error, SourceLocation loc,
97 SourceRange range = SourceRange());
98 void reportWarning(StringRef warning, SourceLocation loc,
99 SourceRange range = SourceRange());
100 void reportNote(StringRef note, SourceLocation loc,
101 SourceRange range = SourceRange());
103 bool hasReportedErrors() const { return ReportedErrors; }
105 class RewriteReceiver {
107 virtual ~RewriteReceiver();
109 virtual void insert(SourceLocation loc, StringRef text) = 0;
110 virtual void remove(CharSourceRange range) = 0;
111 virtual void increaseIndentation(CharSourceRange range,
112 SourceLocation parentIndent) = 0;
115 void applyRewrites(RewriteReceiver &receiver);
119 TransformActions &TA;
123 Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
124 TA.startTransaction();
129 TA.commitTransaction();
133 TA.abortTransaction();
137 bool isAborted() const { return Aborted; }
140 class MigrationPass {
143 LangOptions::GCMode OrigGCMode;
144 MigratorOptions MigOptions;
146 TransformActions &TA;
147 std::vector<SourceLocation> &ARCMTMacroLocs;
148 llvm::Optional<bool> EnableCFBridgeFns;
150 MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode,
151 Sema &sema, TransformActions &TA,
152 std::vector<SourceLocation> &ARCMTMacroLocs)
153 : Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(),
154 SemaRef(sema), TA(TA),
155 ARCMTMacroLocs(ARCMTMacroLocs) { }
157 bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; }
158 bool noNSAllocReallocError() const { return MigOptions.NoNSAllocReallocError; }
159 void setNSAllocReallocError(bool val) { MigOptions.NoNSAllocReallocError = val; }
160 bool noFinalizeRemoval() const { return MigOptions.NoFinalizeRemoval; }
161 void setNoFinalizeRemoval(bool val) {MigOptions.NoFinalizeRemoval = val; }
163 bool CFBridgingFunctionsDefined();
166 static inline StringRef getARCMTMacroName() {
167 return "__IMPL_ARCMT_REMOVED_EXPR__";
170 } // end namespace arcmt
172 } // end namespace clang