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"
22 class CapturedDiagList {
23 typedef std::list<StoredDiagnostic> ListTy;
27 void push_back(const StoredDiagnostic &diag) { List.push_back(diag); }
29 bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
30 bool hasDiagnostic(ArrayRef<unsigned> IDs, SourceRange range) const;
32 void reportDiagnostics(DiagnosticsEngine &diags) const;
34 bool hasErrors() const;
36 typedef ListTy::const_iterator iterator;
37 iterator begin() const { return List.begin(); }
38 iterator end() const { return List.end(); }
41 void writeARCDiagsToPlist(const std::string &outPath,
42 ArrayRef<StoredDiagnostic> diags,
43 SourceManager &SM, const LangOptions &LangOpts);
45 class TransformActions {
46 DiagnosticsEngine &Diags;
47 CapturedDiagList &CapturedDiags;
49 void *Impl; // TransformActionsImpl.
52 TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags,
53 ASTContext &ctx, Preprocessor &PP);
56 void startTransaction();
57 bool commitTransaction();
58 void abortTransaction();
60 void insert(SourceLocation loc, StringRef text);
61 void insertAfterToken(SourceLocation loc, StringRef text);
62 void remove(SourceRange range);
63 void removeStmt(Stmt *S);
64 void replace(SourceRange range, StringRef text);
65 void replace(SourceRange range, SourceRange replacementRange);
66 void replaceStmt(Stmt *S, StringRef text);
67 void replaceText(SourceLocation loc, StringRef text,
68 StringRef replacementText);
69 void increaseIndentation(SourceRange range,
70 SourceLocation parentIndent);
72 bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
73 bool clearAllDiagnostics(SourceRange range) {
74 return clearDiagnostic(ArrayRef<unsigned>(), range);
76 bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
77 unsigned IDs[] = { ID1, ID2 };
78 return clearDiagnostic(IDs, range);
80 bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3,
82 unsigned IDs[] = { ID1, ID2, ID3 };
83 return clearDiagnostic(IDs, range);
86 bool hasDiagnostic(unsigned ID, SourceRange range) {
87 return CapturedDiags.hasDiagnostic(ID, range);
90 bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
91 unsigned IDs[] = { ID1, ID2 };
92 return CapturedDiags.hasDiagnostic(IDs, range);
95 void reportError(StringRef error, SourceLocation loc,
96 SourceRange range = SourceRange());
97 void reportWarning(StringRef warning, SourceLocation loc,
98 SourceRange range = SourceRange());
99 void reportNote(StringRef note, SourceLocation loc,
100 SourceRange range = SourceRange());
102 bool hasReportedErrors() const { return ReportedErrors; }
104 class RewriteReceiver {
106 virtual ~RewriteReceiver();
108 virtual void insert(SourceLocation loc, StringRef text) = 0;
109 virtual void remove(CharSourceRange range) = 0;
110 virtual void increaseIndentation(CharSourceRange range,
111 SourceLocation parentIndent) = 0;
114 void applyRewrites(RewriteReceiver &receiver);
118 TransformActions &TA;
122 Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
123 TA.startTransaction();
128 TA.commitTransaction();
132 TA.abortTransaction();
136 bool isAborted() const { return Aborted; }
139 class MigrationPass {
142 LangOptions::GCMode OrigGCMode;
143 MigratorOptions MigOptions;
145 TransformActions &TA;
146 std::vector<SourceLocation> &ARCMTMacroLocs;
148 MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode,
149 Sema &sema, TransformActions &TA,
150 std::vector<SourceLocation> &ARCMTMacroLocs)
151 : Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(),
152 SemaRef(sema), TA(TA),
153 ARCMTMacroLocs(ARCMTMacroLocs) { }
155 bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; }
156 bool noNSAllocReallocError() const { return MigOptions.NoNSAllocReallocError; }
157 void setNSAllocReallocError(bool val) { MigOptions.NoNSAllocReallocError = val; }
158 bool noFinalizeRemoval() const { return MigOptions.NoFinalizeRemoval; }
159 void setNoFinalizeRemoval(bool val) {MigOptions.NoFinalizeRemoval = val; }
162 static inline StringRef getARCMTMacroName() {
163 return "__IMPL_ARCMT_REMOVED_EXPR__";
166 } // end namespace arcmt
168 } // end namespace clang