clang  6.0.0svn
Internals.h
Go to the documentation of this file.
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 "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 Sema;
21  class Stmt;
22 
23 namespace arcmt {
24 
26  typedef std::list<StoredDiagnostic> ListTy;
27  ListTy List;
28 
29 public:
30  void push_back(const StoredDiagnostic &diag) { List.push_back(diag); }
31 
33  bool hasDiagnostic(ArrayRef<unsigned> IDs, SourceRange range) const;
34 
35  void reportDiagnostics(DiagnosticsEngine &diags) const;
36 
37  bool hasErrors() const;
38 
39  typedef ListTy::const_iterator iterator;
40  iterator begin() const { return List.begin(); }
41  iterator end() const { return List.end(); }
42 };
43 
44 void writeARCDiagsToPlist(const std::string &outPath,
46  SourceManager &SM, const LangOptions &LangOpts);
47 
49  DiagnosticsEngine &Diags;
50  CapturedDiagList &CapturedDiags;
51  void *Impl; // TransformActionsImpl.
52 
53 public:
55  ASTContext &ctx, Preprocessor &PP);
57 
58  void startTransaction();
59  bool commitTransaction();
60  void abortTransaction();
61 
62  void insert(SourceLocation loc, StringRef text);
63  void insertAfterToken(SourceLocation loc, StringRef text);
64  void remove(SourceRange range);
65  void removeStmt(Stmt *S);
66  void replace(SourceRange range, StringRef text);
67  void replace(SourceRange range, SourceRange replacementRange);
68  void replaceStmt(Stmt *S, StringRef text);
69  void replaceText(SourceLocation loc, StringRef text,
70  StringRef replacementText);
71  void increaseIndentation(SourceRange range,
72  SourceLocation parentIndent);
73 
76  return clearDiagnostic(None, range);
77  }
78  bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
79  unsigned IDs[] = { ID1, ID2 };
80  return clearDiagnostic(IDs, range);
81  }
82  bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3,
83  SourceRange range) {
84  unsigned IDs[] = { ID1, ID2, ID3 };
85  return clearDiagnostic(IDs, range);
86  }
87 
88  bool hasDiagnostic(unsigned ID, SourceRange range) {
89  return CapturedDiags.hasDiagnostic(ID, range);
90  }
91 
92  bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
93  unsigned IDs[] = { ID1, ID2 };
94  return CapturedDiags.hasDiagnostic(IDs, range);
95  }
96 
97  DiagnosticBuilder report(SourceLocation loc, unsigned diagId,
98  SourceRange range = SourceRange());
99  void reportError(StringRef error, SourceLocation loc,
100  SourceRange range = SourceRange());
101  void reportWarning(StringRef warning, SourceLocation loc,
102  SourceRange range = SourceRange());
103  void reportNote(StringRef note, SourceLocation loc,
104  SourceRange range = SourceRange());
105 
106  bool hasReportedErrors() const {
107  return Diags.hasUnrecoverableErrorOccurred();
108  }
109 
111  public:
112  virtual ~RewriteReceiver();
113 
114  virtual void insert(SourceLocation loc, StringRef text) = 0;
115  virtual void remove(CharSourceRange range) = 0;
116  virtual void increaseIndentation(CharSourceRange range,
117  SourceLocation parentIndent) = 0;
118  };
119 
120  void applyRewrites(RewriteReceiver &receiver);
121 };
122 
123 class Transaction {
124  TransformActions &TA;
125  bool Aborted;
126 
127 public:
128  Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
129  TA.startTransaction();
130  }
131 
133  if (!isAborted())
134  TA.commitTransaction();
135  }
136 
137  void abort() {
138  TA.abortTransaction();
139  Aborted = true;
140  }
141 
142  bool isAborted() const { return Aborted; }
143 };
144 
146 public:
153  std::vector<SourceLocation> &ARCMTMacroLocs;
155 
157  Sema &sema, TransformActions &TA,
158  const CapturedDiagList &capturedDiags,
159  std::vector<SourceLocation> &ARCMTMacroLocs)
160  : Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(),
161  SemaRef(sema), TA(TA), CapturedDiags(capturedDiags),
162  ARCMTMacroLocs(ARCMTMacroLocs) { }
163 
164  const CapturedDiagList &getDiags() const { return CapturedDiags; }
165 
166  bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; }
167  bool noFinalizeRemoval() const { return MigOptions.NoFinalizeRemoval; }
168  void setNoFinalizeRemoval(bool val) {MigOptions.NoFinalizeRemoval = val; }
169 
170  bool CFBridgingFunctionsDefined();
171 };
172 
173 static inline StringRef getARCMTMacroName() {
174  return "__IMPL_ARCMT_REMOVED_EXPR__";
175 }
176 
177 } // end namespace arcmt
178 
179 } // end namespace clang
180 
181 #endif
MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode, Sema &sema, TransformActions &TA, const CapturedDiagList &capturedDiags, std::vector< SourceLocation > &ARCMTMacroLocs)
Definition: Internals.h:156
Stmt - This represents one statement.
Definition: Stmt.h:60
ListTy::const_iterator iterator
Definition: Internals.h:39
static StringRef getARCMTMacroName()
Definition: Internals.h:173
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
Definition: Diagnostic.h:1346
void push_back(const StoredDiagnostic &diag)
Definition: Internals.h:30
bool hasDiagnostic(ArrayRef< unsigned > IDs, SourceRange range) const
Definition: ARCMT.cpp:59
void setNoFinalizeRemoval(bool val)
Definition: Internals.h:168
const CapturedDiagList & getDiags() const
Definition: Internals.h:164
bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range)
Definition: Internals.h:92
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:128
iterator begin() const
Definition: Internals.h:40
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
bool clearDiagnostic(ArrayRef< unsigned > IDs, SourceRange range)
Definition: ARCMT.cpp:29
void reportDiagnostics(DiagnosticsEngine &diags) const
Definition: ARCMT.cpp:81
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
bool hasUnrecoverableErrorOccurred() const
Determine whether any kind of unrecoverable error has occurred.
Definition: Diagnostic.h:670
Defines the Diagnostic-related interfaces.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:274
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:953
Represents a character-granular source range.
void writeARCDiagsToPlist(const std::string &outPath, ArrayRef< StoredDiagnostic > diags, SourceManager &SM, const LangOptions &LangOpts)
const SourceManager & SM
Definition: Format.cpp:1308
bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range)
Definition: Internals.h:78
#define false
Definition: stdbool.h:33
Encodes a location in the source.
bool noFinalizeRemoval() const
Definition: Internals.h:167
bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3, SourceRange range)
Definition: Internals.h:82
bool clearAllDiagnostics(SourceRange range)
Definition: Internals.h:75
Dataflow Directional Tag Classes.
const CapturedDiagList & CapturedDiags
Definition: Internals.h:152
Transaction(TransformActions &TA)
Definition: Internals.h:128
std::vector< SourceLocation > & ARCMTMacroLocs
Definition: Internals.h:153
Optional< bool > EnableCFBridgeFns
Definition: Internals.h:154
MigratorOptions MigOptions
Definition: Internals.h:149
TransformActions & TA
Definition: Internals.h:151
bool isAborted() const
Definition: Internals.h:142
bool isGCMigration() const
Definition: Internals.h:166
LangOptions::GCMode OrigGCMode
Definition: Internals.h:148
A trivial tuple used to represent a source range.
bool hasDiagnostic(unsigned ID, SourceRange range)
Definition: Internals.h:88
This class handles loading and caching of source files into memory.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:98