Clang Project

clang_source_code/lib/ARCMigrate/Internals.h
1//===-- Internals.h - Implementation Details---------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H
10#define LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H
11
12#include "clang/ARCMigrate/ARCMT.h"
13#include "clang/Basic/Diagnostic.h"
14#include "llvm/ADT/ArrayRef.h"
15#include "llvm/ADT/Optional.h"
16#include <list>
17
18namespace clang {
19  class Sema;
20  class Stmt;
21
22namespace arcmt {
23
24class CapturedDiagList {
25  typedef std::list<StoredDiagnosticListTy;
26  ListTy List;
27
28public:
29  void push_back(const StoredDiagnostic &diag) { List.push_back(diag); }
30
31  bool clearDiagnostic(ArrayRef<unsignedIDsSourceRange range);
32  bool hasDiagnostic(ArrayRef<unsignedIDsSourceRange rangeconst;
33
34  void reportDiagnostics(DiagnosticsEngine &diagsconst;
35
36  bool hasErrors() const;
37
38  typedef ListTy::const_iterator iterator;
39  iterator begin() const { return List.begin(); }
40  iterator end()   const { return List.end();   }
41};
42
43void writeARCDiagsToPlist(const std::string &outPath,
44                          ArrayRef<StoredDiagnosticdiags,
45                          SourceManager &SMconst LangOptions &LangOpts);
46
47class TransformActions {
48  DiagnosticsEngine &Diags;
49  CapturedDiagList &CapturedDiags;
50  void *Impl// TransformActionsImpl.
51
52public:
53  TransformActions(DiagnosticsEngine &diagCapturedDiagList &capturedDiags,
54                   ASTContext &ctxPreprocessor &PP);
55  ~TransformActions();
56
57  void startTransaction();
58  bool commitTransaction();
59  void abortTransaction();
60
61  void insert(SourceLocation locStringRef text);
62  void insertAfterToken(SourceLocation locStringRef text);
63  void remove(SourceRange range);
64  void removeStmt(Stmt *S);
65  void replace(SourceRange rangeStringRef text);
66  void replace(SourceRange rangeSourceRange replacementRange);
67  void replaceStmt(Stmt *SStringRef text);
68  void replaceText(SourceLocation locStringRef text,
69                   StringRef replacementText);
70  void increaseIndentation(SourceRange range,
71                           SourceLocation parentIndent);
72
73  bool clearDiagnostic(ArrayRef<unsignedIDsSourceRange range);
74  bool clearAllDiagnostics(SourceRange range) {
75    return clearDiagnostic(None, range);
76  }
77  bool clearDiagnostic(unsigned ID1unsigned ID2SourceRange range) {
78    unsigned IDs[] = { ID1ID2 };
79    return clearDiagnostic(IDsrange);
80  }
81  bool clearDiagnostic(unsigned ID1unsigned ID2unsigned ID3,
82                       SourceRange range) {
83    unsigned IDs[] = { ID1ID2ID3 };
84    return clearDiagnostic(IDsrange);
85  }
86
87  bool hasDiagnostic(unsigned IDSourceRange range) {
88    return CapturedDiags.hasDiagnostic(IDrange);
89  }
90
91  bool hasDiagnostic(unsigned ID1unsigned ID2SourceRange range) {
92    unsigned IDs[] = { ID1ID2 };
93    return CapturedDiags.hasDiagnostic(IDsrange);
94  }
95
96  DiagnosticBuilder report(SourceLocation locunsigned diagId,
97                           SourceRange range = SourceRange());
98  void reportError(StringRef errorSourceLocation loc,
99                   SourceRange range = SourceRange());
100  void reportWarning(StringRef warningSourceLocation loc,
101                   SourceRange range = SourceRange());
102  void reportNote(StringRef noteSourceLocation loc,
103                  SourceRange range = SourceRange());
104
105  bool hasReportedErrors() const {
106    return Diags.hasUnrecoverableErrorOccurred();
107  }
108
109  class RewriteReceiver {
110  public:
111    virtual ~RewriteReceiver();
112
113    virtual void insert(SourceLocation locStringRef text) = 0;
114    virtual void remove(CharSourceRange range) = 0;
115    virtual void increaseIndentation(CharSourceRange range,
116                                     SourceLocation parentIndent) = 0;
117  };
118
119  void applyRewrites(RewriteReceiver &receiver);
120};
121
122class Transaction {
123  TransformActions &TA;
124  bool Aborted;
125
126public:
127  Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
128    TA.startTransaction();
129  }
130
131  ~Transaction() {
132    if (!isAborted())
133      TA.commitTransaction();
134  }
135
136  void abort() {
137    TA.abortTransaction();
138    Aborted = true;
139  }
140
141  bool isAborted() const { return Aborted; }
142};
143
144class MigrationPass {
145public:
146  ASTContext &Ctx;
147  LangOptions::GCMode OrigGCMode;
148  MigratorOptions MigOptions;
149  Sema &SemaRef;
150  TransformActions &TA;
151  const CapturedDiagList &CapturedDiags;
152  std::vector<SourceLocation> &ARCMTMacroLocs;
153  Optional<boolEnableCFBridgeFns;
154
155  MigrationPass(ASTContext &CtxLangOptions::GCMode OrigGCMode,
156                Sema &semaTransformActions &TA,
157                const CapturedDiagList &capturedDiags,
158                std::vector<SourceLocation> &ARCMTMacroLocs)
159    : Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(),
160      SemaRef(sema), TA(TA), CapturedDiags(capturedDiags),
161      ARCMTMacroLocs(ARCMTMacroLocs) { }
162
163  const CapturedDiagList &getDiags() const { return CapturedDiags; }
164
165  bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; }
166  bool noFinalizeRemoval() const { return MigOptions.NoFinalizeRemoval; }
167  void setNoFinalizeRemoval(bool val) {MigOptions.NoFinalizeRemoval = val; }
168
169  bool CFBridgingFunctionsDefined();
170};
171
172static inline StringRef getARCMTMacroName() {
173  return "__IMPL_ARCMT_REMOVED_EXPR__";
174}
175
176// end namespace arcmt
177
178// end namespace clang
179
180#endif
181
clang::arcmt::CapturedDiagList::List
clang::arcmt::CapturedDiagList::push_back
clang::arcmt::CapturedDiagList::clearDiagnostic
clang::arcmt::CapturedDiagList::hasDiagnostic
clang::arcmt::CapturedDiagList::reportDiagnostics
clang::arcmt::CapturedDiagList::hasErrors
clang::arcmt::CapturedDiagList::begin
clang::arcmt::CapturedDiagList::end
clang::arcmt::TransformActions::Diags
clang::arcmt::TransformActions::CapturedDiags
clang::arcmt::TransformActions::Impl
clang::arcmt::TransformActions::startTransaction
clang::arcmt::TransformActions::commitTransaction
clang::arcmt::TransformActions::abortTransaction
clang::arcmt::TransformActions::insert
clang::arcmt::TransformActions::insertAfterToken
clang::arcmt::TransformActions::remove
clang::arcmt::TransformActions::removeStmt
clang::arcmt::TransformActions::replace
clang::arcmt::TransformActions::replace
clang::arcmt::TransformActions::replaceStmt
clang::arcmt::TransformActions::replaceText
clang::arcmt::TransformActions::increaseIndentation
clang::arcmt::TransformActions::clearDiagnostic
clang::arcmt::TransformActions::clearAllDiagnostics
clang::arcmt::TransformActions::clearDiagnostic
clang::arcmt::TransformActions::clearDiagnostic
clang::arcmt::TransformActions::hasDiagnostic
clang::arcmt::TransformActions::hasDiagnostic
clang::arcmt::TransformActions::report
clang::arcmt::TransformActions::reportError
clang::arcmt::TransformActions::reportWarning
clang::arcmt::TransformActions::reportNote
clang::arcmt::TransformActions::hasReportedErrors
clang::arcmt::TransformActions::RewriteReceiver
clang::arcmt::TransformActions::RewriteReceiver::insert
clang::arcmt::TransformActions::RewriteReceiver::remove
clang::arcmt::TransformActions::RewriteReceiver::increaseIndentation
clang::arcmt::TransformActions::applyRewrites
clang::arcmt::Transaction::TA
clang::arcmt::Transaction::Aborted
clang::arcmt::Transaction::abort
clang::arcmt::Transaction::isAborted
clang::arcmt::MigrationPass::Ctx
clang::arcmt::MigrationPass::OrigGCMode
clang::arcmt::MigrationPass::MigOptions
clang::arcmt::MigrationPass::SemaRef
clang::arcmt::MigrationPass::TA
clang::arcmt::MigrationPass::CapturedDiags
clang::arcmt::MigrationPass::ARCMTMacroLocs
clang::arcmt::MigrationPass::EnableCFBridgeFns
clang::arcmt::MigrationPass::getDiags
clang::arcmt::MigrationPass::isGCMigration
clang::arcmt::MigrationPass::noFinalizeRemoval
clang::arcmt::MigrationPass::setNoFinalizeRemoval
clang::arcmt::MigrationPass::CFBridgingFunctionsDefined