clang  14.0.0git
Internals.h
Go to the documentation of this file.
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 
13 #include "clang/Basic/Diagnostic.h"
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/Optional.h"
17 #include <list>
18 
19 namespace clang {
20  class ASTContext;
21  class Sema;
22  class Stmt;
23 
24 namespace arcmt {
25 
27  typedef std::list<StoredDiagnostic> ListTy;
28  ListTy List;
29 
30 public:
31  void push_back(const StoredDiagnostic &diag) { List.push_back(diag); }
32 
35 
36  void reportDiagnostics(DiagnosticsEngine &diags) const;
37 
38  bool hasErrors() const;
39 
40  typedef ListTy::const_iterator iterator;
41  iterator begin() const { return List.begin(); }
42  iterator end() const { return List.end(); }
43 };
44 
45 void writeARCDiagsToPlist(const std::string &outPath,
47  SourceManager &SM, const LangOptions &LangOpts);
48 
50  DiagnosticsEngine &Diags;
51  CapturedDiagList &CapturedDiags;
52  void *Impl; // TransformActionsImpl.
53 
54 public:
56  ASTContext &ctx, Preprocessor &PP);
58 
59  void startTransaction();
60  bool commitTransaction();
61  void abortTransaction();
62 
63  void insert(SourceLocation loc, StringRef text);
64  void insertAfterToken(SourceLocation loc, StringRef text);
65  void remove(SourceRange range);
66  void removeStmt(Stmt *S);
67  void replace(SourceRange range, StringRef text);
68  void replace(SourceRange range, SourceRange replacementRange);
69  void replaceStmt(Stmt *S, StringRef text);
70  void replaceText(SourceLocation loc, StringRef text,
71  StringRef replacementText);
73  SourceLocation parentIndent);
74 
77  return clearDiagnostic(None, range);
78  }
79  bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
80  unsigned IDs[] = { ID1, ID2 };
81  return clearDiagnostic(IDs, range);
82  }
83  bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3,
85  unsigned IDs[] = { ID1, ID2, ID3 };
86  return clearDiagnostic(IDs, range);
87  }
88 
89  bool hasDiagnostic(unsigned ID, SourceRange range) {
90  return CapturedDiags.hasDiagnostic(ID, range);
91  }
92 
93  bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
94  unsigned IDs[] = { ID1, ID2 };
95  return CapturedDiags.hasDiagnostic(IDs, range);
96  }
97 
98  DiagnosticBuilder report(SourceLocation loc, unsigned diagId,
100  void reportError(StringRef error, SourceLocation loc,
102  void reportWarning(StringRef warning, SourceLocation loc,
104  void reportNote(StringRef note, SourceLocation loc,
106 
107  bool hasReportedErrors() const {
108  return Diags.hasUnrecoverableErrorOccurred();
109  }
110 
112  public:
113  virtual ~RewriteReceiver();
114 
115  virtual void insert(SourceLocation loc, StringRef text) = 0;
116  virtual void remove(CharSourceRange range) = 0;
118  SourceLocation parentIndent) = 0;
119  };
120 
121  void applyRewrites(RewriteReceiver &receiver);
122 };
123 
124 class Transaction {
125  TransformActions &TA;
126  bool Aborted;
127 
128 public:
129  Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
130  TA.startTransaction();
131  }
132 
134  if (!isAborted())
135  TA.commitTransaction();
136  }
137 
138  void abort() {
139  TA.abortTransaction();
140  Aborted = true;
141  }
142 
143  bool isAborted() const { return Aborted; }
144 };
145 
147 public:
154  std::vector<SourceLocation> &ARCMTMacroLocs;
156 
158  Sema &sema, TransformActions &TA,
159  const CapturedDiagList &capturedDiags,
160  std::vector<SourceLocation> &ARCMTMacroLocs)
162  SemaRef(sema), TA(TA), CapturedDiags(capturedDiags),
164 
165  const CapturedDiagList &getDiags() const { return CapturedDiags; }
166 
167  bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; }
170 
172 };
173 
174 static inline StringRef getARCMTMacroName() {
175  return "__IMPL_ARCMT_REMOVED_EXPR__";
176 }
177 
178 } // end namespace arcmt
179 
180 } // end namespace clang
181 
182 #endif
clang::comments::tok::text
@ text
Definition: CommentLexer.h:35
clang::arcmt::TransformActions::insertAfterToken
void insertAfterToken(SourceLocation loc, StringRef text)
Definition: TransformActions.cpp:633
clang::DiagnosticBuilder
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1264
clang::arcmt::TransformActions::clearDiagnostic
bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3, SourceRange range)
Definition: Internals.h:83
clang::arcmt::TransformActions::clearDiagnostic
bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range)
Definition: Internals.h:79
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::arcmt::TransformActions::TransformActions
TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags, ASTContext &ctx, Preprocessor &PP)
Definition: TransformActions.cpp:605
clang::arcmt::MigrationPass
Definition: Internals.h:146
clang::arcmt::TransformActions::clearAllDiagnostics
bool clearAllDiagnostics(SourceRange range)
Definition: Internals.h:76
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::arcmt::TransformActions
Definition: Internals.h:49
clang::arcmt::CapturedDiagList::iterator
ListTy::const_iterator iterator
Definition: Internals.h:40
clang::DiagnosticsEngine::hasUnrecoverableErrorOccurred
bool hasUnrecoverableErrorOccurred() const
Determine whether any kind of unrecoverable error has occurred.
Definition: Diagnostic.h:846
clang::arcmt::TransformActions::replaceStmt
void replaceStmt(Stmt *S, StringRef text)
Definition: TransformActions.cpp:655
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:191
clang::arcmt::TransformActions::increaseIndentation
void increaseIndentation(SourceRange range, SourceLocation parentIndent)
Definition: TransformActions.cpp:665
clang::arcmt::getARCMTMacroName
static StringRef getARCMTMacroName()
Definition: Internals.h:174
llvm::Optional< bool >
clang::arcmt::MigrationPass::MigrationPass
MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode, Sema &sema, TransformActions &TA, const CapturedDiagList &capturedDiags, std::vector< SourceLocation > &ARCMTMacroLocs)
Definition: Internals.h:157
clang::arcmt::CapturedDiagList::hasDiagnostic
bool hasDiagnostic(ArrayRef< unsigned > IDs, SourceRange range) const
Definition: ARCMT.cpp:59
clang::LangOptions::GCMode
GCMode
Definition: LangOptions.h:63
clang::arcmt::MigrationPass::TA
TransformActions & TA
Definition: Internals.h:152
clang::arcmt::MigrationPass::noFinalizeRemoval
bool noFinalizeRemoval() const
Definition: Internals.h:168
clang::arcmt::TransformActions::RewriteReceiver::increaseIndentation
virtual void increaseIndentation(CharSourceRange range, SourceLocation parentIndent)=0
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:626
clang::arcmt::MigrationPass::isGCMigration
bool isGCMigration() const
Definition: Internals.h:167
clang::arcmt::CapturedDiagList
Definition: Internals.h:26
clang::arcmt::TransformActions::removeStmt
void removeStmt(Stmt *S)
Definition: TransformActions.cpp:642
clang::arcmt::MigrationPass::CapturedDiags
const CapturedDiagList & CapturedDiags
Definition: Internals.h:153
clang::arcmt::TransformActions::replaceText
void replaceText(SourceLocation loc, StringRef text, StringRef replacementText)
Definition: TransformActions.cpp:659
clang::MigratorOptions::NoFinalizeRemoval
unsigned NoFinalizeRemoval
Definition: MigratorOptions.h:22
clang::arcmt::TransformActions::RewriteReceiver::remove
virtual void remove(CharSourceRange range)=0
clang::arcmt::Transaction
Definition: Internals.h:124
clang::arcmt::TransformActions::replace
void replace(SourceRange range, StringRef text)
Definition: TransformActions.cpp:646
clang::arcmt::TransformActions::remove
void remove(SourceRange range)
Definition: TransformActions.cpp:638
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
LangOptions.h
Diagnostic.h
clang::arcmt::MigrationPass::EnableCFBridgeFns
Optional< bool > EnableCFBridgeFns
Definition: Internals.h:155
clang::arcmt::CapturedDiagList::hasErrors
bool hasErrors() const
Definition: ARCMT.cpp:86
clang::arcmt::TransformActions::insert
void insert(SourceLocation loc, StringRef text)
Definition: TransformActions.cpp:629
clang::arcmt::CapturedDiagList::begin
iterator begin() const
Definition: Internals.h:41
clang::arcmt::CapturedDiagList::clearDiagnostic
bool clearDiagnostic(ArrayRef< unsigned > IDs, SourceRange range)
Definition: ARCMT.cpp:29
clang::arcmt::TransformActions::RewriteReceiver
Definition: Internals.h:111
clang::arcmt::MigrationPass::ARCMTMacroLocs
std::vector< SourceLocation > & ARCMTMacroLocs
Definition: Internals.h:154
clang::arcmt::CapturedDiagList::reportDiagnostics
void reportDiagnostics(DiagnosticsEngine &diags) const
Definition: ARCMT.cpp:81
clang::arcmt::MigrationPass::Ctx
ASTContext & Ctx
Definition: Internals.h:148
clang::arcmt::MigrationPass::MigOptions
MigratorOptions MigOptions
Definition: Internals.h:150
clang::arcmt::TransformActions::abortTransaction
void abortTransaction()
Definition: TransformActions.cpp:624
clang::StoredDiagnostic
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
Definition: Diagnostic.h:1671
clang::arcmt::TransformActions::hasDiagnostic
bool hasDiagnostic(unsigned ID, SourceRange range)
Definition: Internals.h:89
clang::arcmt::writeARCDiagsToPlist
void writeARCDiagsToPlist(const std::string &outPath, ArrayRef< StoredDiagnostic > diags, SourceManager &SM, const LangOptions &LangOpts)
Definition: PlistReporter.cpp:34
clang::arcmt::TransformActions::startTransaction
void startTransaction()
Definition: TransformActions.cpp:616
clang::arcmt::MigrationPass::SemaRef
Sema & SemaRef
Definition: Internals.h:151
clang::arcmt::TransformActions::RewriteReceiver::~RewriteReceiver
virtual ~RewriteReceiver()
Definition: TransformActions.cpp:603
clang::arcmt::TransformActions::reportNote
void reportNote(StringRef note, SourceLocation loc, SourceRange range=SourceRange())
Definition: TransformActions.cpp:697
false
#define false
Definition: stdbool.h:17
clang::arcmt::TransformActions::hasDiagnostic
bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range)
Definition: Internals.h:93
clang::LangOptions::NonGC
@ NonGC
Definition: LangOptions.h:63
clang::arcmt::Transaction::Transaction
Transaction(TransformActions &TA)
Definition: Internals.h:129
clang::arcmt::MigrationPass::getDiags
const CapturedDiagList & getDiags() const
Definition: Internals.h:165
llvm::ArrayRef< unsigned >
clang::MigratorOptions
Definition: MigratorOptions.h:19
clang::CharSourceRange
Represents a character-granular source range.
Definition: SourceLocation.h:253
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:354
clang::arcmt::TransformActions::applyRewrites
void applyRewrites(RewriteReceiver &receiver)
Definition: TransformActions.cpp:676
clang::arcmt::TransformActions::reportWarning
void reportWarning(StringRef warning, SourceLocation loc, SourceRange range=SourceRange())
Definition: TransformActions.cpp:692
clang::arcmt::TransformActions::report
DiagnosticBuilder report(SourceLocation loc, unsigned diagId, SourceRange range=SourceRange())
Definition: TransformActions.cpp:680
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
MigratorOptions.h
clang::Builtin::ID
ID
Definition: Builtins.h:48
clang::arcmt::TransformActions::reportError
void reportError(StringRef error, SourceLocation loc, SourceRange range=SourceRange())
Definition: TransformActions.cpp:687
clang
Definition: CalledOnceCheck.h:17
clang::arcmt::MigrationPass::OrigGCMode
LangOptions::GCMode OrigGCMode
Definition: Internals.h:149
clang::transformer::range
RangeSelector range(RangeSelector Begin, RangeSelector End)
DEPRECATED. Use enclose.
Definition: RangeSelector.h:41
clang::arcmt::Transaction::isAborted
bool isAborted() const
Definition: Internals.h:143
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
clang::arcmt::TransformActions::~TransformActions
~TransformActions()
Definition: TransformActions.cpp:612
clang::arcmt::MigrationPass::setNoFinalizeRemoval
void setNoFinalizeRemoval(bool val)
Definition: Internals.h:169
clang::arcmt::TransformActions::RewriteReceiver::insert
virtual void insert(SourceLocation loc, StringRef text)=0
clang::arcmt::Transaction::~Transaction
~Transaction()
Definition: Internals.h:133
clang::arcmt::Transaction::abort
void abort()
Definition: Internals.h:138
clang::arcmt::TransformActions::commitTransaction
bool commitTransaction()
Definition: TransformActions.cpp:620
clang::arcmt::TransformActions::clearDiagnostic
bool clearDiagnostic(ArrayRef< unsigned > IDs, SourceRange range)
Definition: TransformActions.cpp:671
clang::arcmt::CapturedDiagList::end
iterator end() const
Definition: Internals.h:42
clang::arcmt::TransformActions::hasReportedErrors
bool hasReportedErrors() const
Definition: Internals.h:107
clang::arcmt::MigrationPass::CFBridgingFunctionsDefined
bool CFBridgingFunctionsDefined()
Definition: Transforms.cpp:27
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:130
SM
#define SM(sm)
Definition: Cuda.cpp:81
clang::arcmt::CapturedDiagList::push_back
void push_back(const StoredDiagnostic &diag)
Definition: Internals.h:31