]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/ARCMigrate/Internals.h
Merge bmake-20120831 from vendor/NetBSD/bmake/dist.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / ARCMigrate / Internals.h
1 //===-- 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 #include "llvm/ADT/Optional.h"
16
17 namespace clang {
18   class Sema;
19   class Stmt;
20
21 namespace arcmt {
22
23 class CapturedDiagList {
24   typedef std::list<StoredDiagnostic> ListTy;
25   ListTy List;
26   
27 public:
28   void push_back(const StoredDiagnostic &diag) { List.push_back(diag); }
29
30   bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
31   bool hasDiagnostic(ArrayRef<unsigned> IDs, SourceRange range) const;
32
33   void reportDiagnostics(DiagnosticsEngine &diags) const;
34
35   bool hasErrors() const;
36
37   typedef ListTy::const_iterator iterator;
38   iterator begin() const { return List.begin(); }
39   iterator end()   const { return List.end();   }
40 };
41
42 void writeARCDiagsToPlist(const std::string &outPath,
43                           ArrayRef<StoredDiagnostic> diags,
44                           SourceManager &SM, const LangOptions &LangOpts);
45
46 class TransformActions {
47   DiagnosticsEngine &Diags;
48   CapturedDiagList &CapturedDiags;
49   bool ReportedErrors;
50   void *Impl; // TransformActionsImpl.
51
52 public:
53   TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags,
54                    ASTContext &ctx, Preprocessor &PP);
55   ~TransformActions();
56
57   void startTransaction();
58   bool commitTransaction();
59   void abortTransaction();
60
61   void insert(SourceLocation loc, StringRef text);
62   void insertAfterToken(SourceLocation loc, StringRef text);
63   void remove(SourceRange range);
64   void removeStmt(Stmt *S);
65   void replace(SourceRange range, StringRef text);
66   void replace(SourceRange range, SourceRange replacementRange);
67   void replaceStmt(Stmt *S, StringRef text);
68   void replaceText(SourceLocation loc, StringRef text,
69                    StringRef replacementText);
70   void increaseIndentation(SourceRange range,
71                            SourceLocation parentIndent);
72
73   bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
74   bool clearAllDiagnostics(SourceRange range) {
75     return clearDiagnostic(ArrayRef<unsigned>(), range);
76   }
77   bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
78     unsigned IDs[] = { ID1, ID2 };
79     return clearDiagnostic(IDs, range);
80   }
81   bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3,
82                        SourceRange range) {
83     unsigned IDs[] = { ID1, ID2, ID3 };
84     return clearDiagnostic(IDs, range);
85   }
86
87   bool hasDiagnostic(unsigned ID, SourceRange range) {
88     return CapturedDiags.hasDiagnostic(ID, range);
89   }
90
91   bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
92     unsigned IDs[] = { ID1, ID2 };
93     return CapturedDiags.hasDiagnostic(IDs, range);
94   }
95
96   void reportError(StringRef error, SourceLocation loc,
97                    SourceRange range = SourceRange());
98   void reportWarning(StringRef warning, SourceLocation loc,
99                    SourceRange range = SourceRange());
100   void reportNote(StringRef note, SourceLocation loc,
101                   SourceRange range = SourceRange());
102
103   bool hasReportedErrors() const { return ReportedErrors; }
104
105   class RewriteReceiver {
106   public:
107     virtual ~RewriteReceiver();
108
109     virtual void insert(SourceLocation loc, StringRef text) = 0;
110     virtual void remove(CharSourceRange range) = 0;
111     virtual void increaseIndentation(CharSourceRange range,
112                                      SourceLocation parentIndent) = 0;
113   };
114
115   void applyRewrites(RewriteReceiver &receiver);
116 };
117
118 class Transaction {
119   TransformActions &TA;
120   bool Aborted;
121
122 public:
123   Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
124     TA.startTransaction();
125   }
126
127   ~Transaction() {
128     if (!isAborted())
129       TA.commitTransaction();
130   }
131
132   void abort() {
133     TA.abortTransaction();
134     Aborted = true;
135   }
136
137   bool isAborted() const { return Aborted; }
138 };
139
140 class MigrationPass {
141 public:
142   ASTContext &Ctx;
143   LangOptions::GCMode OrigGCMode;
144   MigratorOptions MigOptions;
145   Sema &SemaRef;
146   TransformActions &TA;
147   std::vector<SourceLocation> &ARCMTMacroLocs;
148   llvm::Optional<bool> EnableCFBridgeFns;
149
150   MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode,
151                 Sema &sema, TransformActions &TA,
152                 std::vector<SourceLocation> &ARCMTMacroLocs)
153     : Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(),
154       SemaRef(sema), TA(TA),
155       ARCMTMacroLocs(ARCMTMacroLocs) { }
156
157   bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; }
158   bool noNSAllocReallocError() const { return MigOptions.NoNSAllocReallocError; }
159   void setNSAllocReallocError(bool val) { MigOptions.NoNSAllocReallocError = val; }
160   bool noFinalizeRemoval() const { return MigOptions.NoFinalizeRemoval; }
161   void setNoFinalizeRemoval(bool val) {MigOptions.NoFinalizeRemoval = val; }
162
163   bool CFBridgingFunctionsDefined();
164 };
165
166 static inline StringRef getARCMTMacroName() {
167   return "__IMPL_ARCMT_REMOVED_EXPR__";
168 }
169
170 } // end namespace arcmt
171
172 } // end namespace clang
173
174 #endif