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