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(llvm::ArrayRef<unsigned> IDs, SourceRange range);
30 bool hasDiagnostic(llvm::ArrayRef<unsigned> IDs, SourceRange range) const;
32 void reportDiagnostics(Diagnostic &diags) const;
34 bool hasErrors() const;
37 class TransformActions {
39 CapturedDiagList &CapturedDiags;
40 void *Impl; // TransformActionsImpl.
43 TransformActions(Diagnostic &diag, CapturedDiagList &capturedDiags,
44 ASTContext &ctx, Preprocessor &PP);
47 void startTransaction();
48 bool commitTransaction();
49 void abortTransaction();
51 void insert(SourceLocation loc, llvm::StringRef text);
52 void insertAfterToken(SourceLocation loc, llvm::StringRef text);
53 void remove(SourceRange range);
54 void removeStmt(Stmt *S);
55 void replace(SourceRange range, llvm::StringRef text);
56 void replace(SourceRange range, SourceRange replacementRange);
57 void replaceStmt(Stmt *S, llvm::StringRef text);
58 void replaceText(SourceLocation loc, llvm::StringRef text,
59 llvm::StringRef replacementText);
60 void increaseIndentation(SourceRange range,
61 SourceLocation parentIndent);
63 bool clearDiagnostic(llvm::ArrayRef<unsigned> IDs, SourceRange range);
64 bool clearAllDiagnostics(SourceRange range) {
65 return clearDiagnostic(llvm::ArrayRef<unsigned>(), range);
67 bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
68 unsigned IDs[] = { ID1, ID2 };
69 return clearDiagnostic(IDs, range);
71 bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3,
73 unsigned IDs[] = { ID1, ID2, ID3 };
74 return clearDiagnostic(IDs, range);
77 bool hasDiagnostic(unsigned ID, SourceRange range) {
78 return CapturedDiags.hasDiagnostic(ID, range);
81 bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
82 unsigned IDs[] = { ID1, ID2 };
83 return CapturedDiags.hasDiagnostic(IDs, range);
86 void reportError(llvm::StringRef error, SourceLocation loc,
87 SourceRange range = SourceRange());
88 void reportNote(llvm::StringRef note, SourceLocation loc,
89 SourceRange range = SourceRange());
91 class RewriteReceiver {
93 virtual ~RewriteReceiver();
95 virtual void insert(SourceLocation loc, llvm::StringRef text) = 0;
96 virtual void remove(CharSourceRange range) = 0;
97 virtual void increaseIndentation(CharSourceRange range,
98 SourceLocation parentIndent) = 0;
101 void applyRewrites(RewriteReceiver &receiver);
105 TransformActions &TA;
109 Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
110 TA.startTransaction();
115 TA.commitTransaction();
119 TA.abortTransaction();
123 bool isAborted() const { return Aborted; }
126 class MigrationPass {
130 TransformActions &TA;
131 std::vector<SourceLocation> &ARCMTMacroLocs;
133 MigrationPass(ASTContext &Ctx, Sema &sema, TransformActions &TA,
134 std::vector<SourceLocation> &ARCMTMacroLocs)
135 : Ctx(Ctx), SemaRef(sema), TA(TA), ARCMTMacroLocs(ARCMTMacroLocs) { }
138 bool isARCDiagnostic(unsigned diagID, Diagnostic &Diag);
140 static inline llvm::StringRef getARCMTMacroName() {
141 return "__IMPL_ARCMT_REMOVED_EXPR__";
144 } // end namespace arcmt
146 } // end namespace clang