clang  19.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 <list>
17 #include <optional>
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(std::nullopt, 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;
155  std::optional<bool> EnableCFBridgeFns;
156 
158  TransformActions &TA, const CapturedDiagList &capturedDiags,
159  std::vector<SourceLocation> &ARCMTMacroLocs)
160  : Ctx(Ctx), OrigGCMode(OrigGCMode), SemaRef(sema), TA(TA),
161  CapturedDiags(capturedDiags), ARCMTMacroLocs(ARCMTMacroLocs) {}
162 
163  const CapturedDiagList &getDiags() const { return CapturedDiags; }
164 
165  bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; }
168 
170 };
171 
172 static inline StringRef getARCMTMacroName() {
173  return "__IMPL_ARCMT_REMOVED_EXPR__";
174 }
175 
176 } // end namespace arcmt
177 
178 } // end namespace clang
179 
180 #endif
static char ID
Definition: Arena.cpp:183
#define SM(sm)
Definition: Cuda.cpp:83
Defines the Diagnostic-related interfaces.
Defines the clang::LangOptions interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:185
Represents a character-granular source range.
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1277
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:193
bool hasUnrecoverableErrorOccurred() const
Determine whether any kind of unrecoverable error has occurred.
Definition: Diagnostic.h:859
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:482
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:128
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:462
Encodes a location in the source.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition: Stmt.h:84
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
Definition: Diagnostic.h:1701
bool clearDiagnostic(ArrayRef< unsigned > IDs, SourceRange range)
Definition: ARCMT.cpp:29
void push_back(const StoredDiagnostic &diag)
Definition: Internals.h:31
bool hasDiagnostic(ArrayRef< unsigned > IDs, SourceRange range) const
Definition: ARCMT.cpp:59
iterator begin() const
Definition: Internals.h:41
ListTy::const_iterator iterator
Definition: Internals.h:40
void reportDiagnostics(DiagnosticsEngine &diags) const
Definition: ARCMT.cpp:81
std::vector< SourceLocation > & ARCMTMacroLocs
Definition: Internals.h:154
bool isGCMigration() const
Definition: Internals.h:165
MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode, Sema &sema, TransformActions &TA, const CapturedDiagList &capturedDiags, std::vector< SourceLocation > &ARCMTMacroLocs)
Definition: Internals.h:157
bool noFinalizeRemoval() const
Definition: Internals.h:166
const CapturedDiagList & CapturedDiags
Definition: Internals.h:153
const CapturedDiagList & getDiags() const
Definition: Internals.h:163
MigratorOptions MigOptions
Definition: Internals.h:150
LangOptions::GCMode OrigGCMode
Definition: Internals.h:149
std::optional< bool > EnableCFBridgeFns
Definition: Internals.h:155
TransformActions & TA
Definition: Internals.h:152
void setNoFinalizeRemoval(bool val)
Definition: Internals.h:167
bool isAborted() const
Definition: Internals.h:143
Transaction(TransformActions &TA)
Definition: Internals.h:129
virtual void insert(SourceLocation loc, StringRef text)=0
virtual void remove(CharSourceRange range)=0
virtual void increaseIndentation(CharSourceRange range, SourceLocation parentIndent)=0
void increaseIndentation(SourceRange range, SourceLocation parentIndent)
DiagnosticBuilder report(SourceLocation loc, unsigned diagId, SourceRange range=SourceRange())
void replaceStmt(Stmt *S, StringRef text)
void insertAfterToken(SourceLocation loc, StringRef text)
void insert(SourceLocation loc, StringRef text)
bool clearDiagnostic(ArrayRef< unsigned > IDs, SourceRange range)
void remove(SourceRange range)
void applyRewrites(RewriteReceiver &receiver)
void reportNote(StringRef note, SourceLocation loc, SourceRange range=SourceRange())
bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range)
Definition: Internals.h:93
void reportWarning(StringRef warning, SourceLocation loc, SourceRange range=SourceRange())
void reportError(StringRef error, SourceLocation loc, SourceRange range=SourceRange())
bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3, SourceRange range)
Definition: Internals.h:83
void replace(SourceRange range, StringRef text)
bool hasDiagnostic(unsigned ID, SourceRange range)
Definition: Internals.h:89
void replaceText(SourceLocation loc, StringRef text, StringRef replacementText)
TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags, ASTContext &ctx, Preprocessor &PP)
bool clearAllDiagnostics(SourceRange range)
Definition: Internals.h:76
bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range)
Definition: Internals.h:79
static StringRef getARCMTMacroName()
Definition: Internals.h:172
void writeARCDiagsToPlist(const std::string &outPath, ArrayRef< StoredDiagnostic > diags, SourceManager &SM, const LangOptions &LangOpts)
ASTEdit note(RangeSelector Anchor, TextGenerator Note)
Generates a single, no-op edit with the associated note anchored at the start location of the specifi...
RangeSelector range(RangeSelector Begin, RangeSelector End)
DEPRECATED. Use enclose.
Definition: RangeSelector.h:41
The JSON file list parser is used to communicate input to InstallAPI.
#define false
Definition: stdbool.h:26