blob: 5fdfca9ef8ec6d974f15e788caa7e91ed5871a40 [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;
Argyrios Kyrtzidise665d692011-06-18 00:53:41 +000033
34 bool hasErrors() const;
John McCall8f0e8d22011-06-15 23:25:17 +000035};
36
37class TransformActions {
38 Diagnostic &Diags;
39 CapturedDiagList &CapturedDiags;
Argyrios Kyrtzidisfd103982011-07-18 07:44:45 +000040 bool ReportedErrors;
John McCall8f0e8d22011-06-15 23:25:17 +000041 void *Impl; // TransformActionsImpl.
42
43public:
44 TransformActions(Diagnostic &diag, CapturedDiagList &capturedDiags,
45 ASTContext &ctx, Preprocessor &PP);
46 ~TransformActions();
47
48 void startTransaction();
49 bool commitTransaction();
50 void abortTransaction();
51
52 void insert(SourceLocation loc, llvm::StringRef text);
53 void insertAfterToken(SourceLocation loc, llvm::StringRef text);
54 void remove(SourceRange range);
55 void removeStmt(Stmt *S);
56 void replace(SourceRange range, llvm::StringRef text);
57 void replace(SourceRange range, SourceRange replacementRange);
58 void replaceStmt(Stmt *S, llvm::StringRef text);
59 void replaceText(SourceLocation loc, llvm::StringRef text,
60 llvm::StringRef replacementText);
61 void increaseIndentation(SourceRange range,
62 SourceLocation parentIndent);
63
64 bool clearDiagnostic(llvm::ArrayRef<unsigned> IDs, SourceRange range);
65 bool clearAllDiagnostics(SourceRange range) {
66 return clearDiagnostic(llvm::ArrayRef<unsigned>(), range);
67 }
68 bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
69 unsigned IDs[] = { ID1, ID2 };
70 return clearDiagnostic(IDs, range);
71 }
72 bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3,
73 SourceRange range) {
74 unsigned IDs[] = { ID1, ID2, ID3 };
75 return clearDiagnostic(IDs, range);
76 }
77
78 bool hasDiagnostic(unsigned ID, SourceRange range) {
79 return CapturedDiags.hasDiagnostic(ID, range);
80 }
81
82 bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
83 unsigned IDs[] = { ID1, ID2 };
84 return CapturedDiags.hasDiagnostic(IDs, range);
85 }
86
87 void reportError(llvm::StringRef error, SourceLocation loc,
88 SourceRange range = SourceRange());
89 void reportNote(llvm::StringRef note, SourceLocation loc,
90 SourceRange range = SourceRange());
91
Argyrios Kyrtzidisfd103982011-07-18 07:44:45 +000092 bool hasReportedErrors() const { return ReportedErrors; }
93
John McCall8f0e8d22011-06-15 23:25:17 +000094 class RewriteReceiver {
95 public:
96 virtual ~RewriteReceiver();
97
98 virtual void insert(SourceLocation loc, llvm::StringRef text) = 0;
99 virtual void remove(CharSourceRange range) = 0;
100 virtual void increaseIndentation(CharSourceRange range,
101 SourceLocation parentIndent) = 0;
102 };
103
104 void applyRewrites(RewriteReceiver &receiver);
105};
106
107class Transaction {
108 TransformActions &TA;
109 bool Aborted;
110
111public:
112 Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
113 TA.startTransaction();
114 }
115
116 ~Transaction() {
117 if (!isAborted())
118 TA.commitTransaction();
119 }
120
121 void abort() {
122 TA.abortTransaction();
123 Aborted = true;
124 }
125
126 bool isAborted() const { return Aborted; }
127};
128
129class MigrationPass {
130public:
131 ASTContext &Ctx;
132 Sema &SemaRef;
133 TransformActions &TA;
134 std::vector<SourceLocation> &ARCMTMacroLocs;
135
136 MigrationPass(ASTContext &Ctx, Sema &sema, TransformActions &TA,
137 std::vector<SourceLocation> &ARCMTMacroLocs)
138 : Ctx(Ctx), SemaRef(sema), TA(TA), ARCMTMacroLocs(ARCMTMacroLocs) { }
139};
140
141bool isARCDiagnostic(unsigned diagID, Diagnostic &Diag);
142
143static inline llvm::StringRef getARCMTMacroName() {
144 return "__IMPL_ARCMT_REMOVED_EXPR__";
145}
146
147} // end namespace arcmt
148
149} // end namespace clang
150
151#endif