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 reportNote(StringRef note, SourceLocation loc,
98 SourceRange range = SourceRange());
100 bool hasReportedErrors() const { return ReportedErrors; }
102 class RewriteReceiver {
104 virtual ~RewriteReceiver();
106 virtual void insert(SourceLocation loc, StringRef text) = 0;
107 virtual void remove(CharSourceRange range) = 0;
108 virtual void increaseIndentation(CharSourceRange range,
109 SourceLocation parentIndent) = 0;
112 void applyRewrites(RewriteReceiver &receiver);
116 TransformActions &TA;
120 Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
121 TA.startTransaction();
126 TA.commitTransaction();
130 TA.abortTransaction();
134 bool isAborted() const { return Aborted; }
137 class MigrationPass {
141 TransformActions &TA;
142 std::vector<SourceLocation> &ARCMTMacroLocs;
144 MigrationPass(ASTContext &Ctx, Sema &sema, TransformActions &TA,
145 std::vector<SourceLocation> &ARCMTMacroLocs)
146 : Ctx(Ctx), SemaRef(sema), TA(TA), ARCMTMacroLocs(ARCMTMacroLocs) { }
149 bool isARCDiagnostic(unsigned diagID, DiagnosticsEngine &Diag);
151 static inline StringRef getARCMTMacroName() {
152 return "__IMPL_ARCMT_REMOVED_EXPR__";
155 } // end namespace arcmt
157 } // end namespace clang