blob: d0d545ec517887431288d142bdb48ef6c08e3583 [file] [log] [blame]
John McCall8f0e8d22011-06-15 23:25:17 +00001//===-- Internals.h - Implementation Details---------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H
11#define LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H
12
13#include "clang/ARCMigrate/ARCMT.h"
14#include "llvm/ADT/ArrayRef.h"
15
16namespace clang {
17 class Sema;
18 class Stmt;
19
20namespace arcmt {
21
22class CapturedDiagList {
23 typedef std::list<StoredDiagnostic> ListTy;
24 ListTy List;
25
26public:
27 void push_back(const StoredDiagnostic &diag) { List.push_back(diag); }
28
29 bool clearDiagnostic(llvm::ArrayRef<unsigned> IDs, SourceRange range);
Argyrios Kyrtzidis60a5e3f2011-06-18 00:53:34 +000030 bool hasDiagnostic(llvm::ArrayRef<unsigned> IDs, SourceRange range) const;
John McCall8f0e8d22011-06-15 23:25:17 +000031
Argyrios Kyrtzidis60a5e3f2011-06-18 00:53:34 +000032 void reportDiagnostics(Diagnostic &diags) const;
John McCall8f0e8d22011-06-15 23:25:17 +000033};
34
35class TransformActions {
36 Diagnostic &Diags;
37 CapturedDiagList &CapturedDiags;
38 void *Impl; // TransformActionsImpl.
39
40public:
41 TransformActions(Diagnostic &diag, CapturedDiagList &capturedDiags,
42 ASTContext &ctx, Preprocessor &PP);
43 ~TransformActions();
44
45 void startTransaction();
46 bool commitTransaction();
47 void abortTransaction();
48
49 void insert(SourceLocation loc, llvm::StringRef text);
50 void insertAfterToken(SourceLocation loc, llvm::StringRef text);
51 void remove(SourceRange range);
52 void removeStmt(Stmt *S);
53 void replace(SourceRange range, llvm::StringRef text);
54 void replace(SourceRange range, SourceRange replacementRange);
55 void replaceStmt(Stmt *S, llvm::StringRef text);
56 void replaceText(SourceLocation loc, llvm::StringRef text,
57 llvm::StringRef replacementText);
58 void increaseIndentation(SourceRange range,
59 SourceLocation parentIndent);
60
61 bool clearDiagnostic(llvm::ArrayRef<unsigned> IDs, SourceRange range);
62 bool clearAllDiagnostics(SourceRange range) {
63 return clearDiagnostic(llvm::ArrayRef<unsigned>(), range);
64 }
65 bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
66 unsigned IDs[] = { ID1, ID2 };
67 return clearDiagnostic(IDs, range);
68 }
69 bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3,
70 SourceRange range) {
71 unsigned IDs[] = { ID1, ID2, ID3 };
72 return clearDiagnostic(IDs, range);
73 }
74
75 bool hasDiagnostic(unsigned ID, SourceRange range) {
76 return CapturedDiags.hasDiagnostic(ID, range);
77 }
78
79 bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
80 unsigned IDs[] = { ID1, ID2 };
81 return CapturedDiags.hasDiagnostic(IDs, range);
82 }
83
84 void reportError(llvm::StringRef error, SourceLocation loc,
85 SourceRange range = SourceRange());
86 void reportNote(llvm::StringRef note, SourceLocation loc,
87 SourceRange range = SourceRange());
88
89 class RewriteReceiver {
90 public:
91 virtual ~RewriteReceiver();
92
93 virtual void insert(SourceLocation loc, llvm::StringRef text) = 0;
94 virtual void remove(CharSourceRange range) = 0;
95 virtual void increaseIndentation(CharSourceRange range,
96 SourceLocation parentIndent) = 0;
97 };
98
99 void applyRewrites(RewriteReceiver &receiver);
100};
101
102class Transaction {
103 TransformActions &TA;
104 bool Aborted;
105
106public:
107 Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
108 TA.startTransaction();
109 }
110
111 ~Transaction() {
112 if (!isAborted())
113 TA.commitTransaction();
114 }
115
116 void abort() {
117 TA.abortTransaction();
118 Aborted = true;
119 }
120
121 bool isAborted() const { return Aborted; }
122};
123
124class MigrationPass {
125public:
126 ASTContext &Ctx;
127 Sema &SemaRef;
128 TransformActions &TA;
129 std::vector<SourceLocation> &ARCMTMacroLocs;
130
131 MigrationPass(ASTContext &Ctx, Sema &sema, TransformActions &TA,
132 std::vector<SourceLocation> &ARCMTMacroLocs)
133 : Ctx(Ctx), SemaRef(sema), TA(TA), ARCMTMacroLocs(ARCMTMacroLocs) { }
134};
135
136bool isARCDiagnostic(unsigned diagID, Diagnostic &Diag);
137
138static inline llvm::StringRef getARCMTMacroName() {
139 return "__IMPL_ARCMT_REMOVED_EXPR__";
140}
141
142} // end namespace arcmt
143
144} // end namespace clang
145
146#endif