/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/ARCMigrate/Internals.h
Line | Count | Source (jump to first uncovered line) |
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/Basic/LangOptions.h" |
13 | | #include "clang/Basic/Diagnostic.h" |
14 | | #include "clang/Frontend/MigratorOptions.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 | | |
26 | | class CapturedDiagList { |
27 | | typedef std::list<StoredDiagnostic> ListTy; |
28 | | ListTy List; |
29 | | |
30 | | public: |
31 | 1.18k | void push_back(const StoredDiagnostic &diag) { List.push_back(diag); } |
32 | | |
33 | | bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range); |
34 | | bool hasDiagnostic(ArrayRef<unsigned> IDs, SourceRange range) const; |
35 | | |
36 | | void reportDiagnostics(DiagnosticsEngine &diags) const; |
37 | | |
38 | | bool hasErrors() const; |
39 | | |
40 | | typedef ListTy::const_iterator iterator; |
41 | 404 | iterator begin() const { return List.begin(); } |
42 | 404 | iterator end() const { return List.end(); } |
43 | | }; |
44 | | |
45 | | void writeARCDiagsToPlist(const std::string &outPath, |
46 | | ArrayRef<StoredDiagnostic> diags, |
47 | | SourceManager &SM, const LangOptions &LangOpts); |
48 | | |
49 | | class TransformActions { |
50 | | DiagnosticsEngine &Diags; |
51 | | CapturedDiagList &CapturedDiags; |
52 | | void *Impl; // TransformActionsImpl. |
53 | | |
54 | | public: |
55 | | TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags, |
56 | | ASTContext &ctx, Preprocessor &PP); |
57 | | ~TransformActions(); |
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); |
72 | | void increaseIndentation(SourceRange range, |
73 | | SourceLocation parentIndent); |
74 | | |
75 | | bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range); |
76 | 0 | bool clearAllDiagnostics(SourceRange range) { |
77 | 0 | return clearDiagnostic(None, range); |
78 | 0 | } |
79 | 198 | bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) { |
80 | 198 | unsigned IDs[] = { ID1, ID2 }; |
81 | 198 | return clearDiagnostic(IDs, range); |
82 | 198 | } |
83 | | bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3, |
84 | 297 | SourceRange range) { |
85 | 297 | unsigned IDs[] = { ID1, ID2, ID3 }; |
86 | 297 | return clearDiagnostic(IDs, range); |
87 | 297 | } |
88 | | |
89 | 4 | bool hasDiagnostic(unsigned ID, SourceRange range) { |
90 | 4 | return CapturedDiags.hasDiagnostic(ID, range); |
91 | 4 | } |
92 | | |
93 | 69 | bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) { |
94 | 69 | unsigned IDs[] = { ID1, ID2 }; |
95 | 69 | return CapturedDiags.hasDiagnostic(IDs, range); |
96 | 69 | } |
97 | | |
98 | | DiagnosticBuilder report(SourceLocation loc, unsigned diagId, |
99 | | SourceRange range = SourceRange()); |
100 | | void reportError(StringRef error, SourceLocation loc, |
101 | | SourceRange range = SourceRange()); |
102 | | void reportWarning(StringRef warning, SourceLocation loc, |
103 | | SourceRange range = SourceRange()); |
104 | | void reportNote(StringRef note, SourceLocation loc, |
105 | | SourceRange range = SourceRange()); |
106 | | |
107 | 39 | bool hasReportedErrors() const { |
108 | 39 | return Diags.hasUnrecoverableErrorOccurred(); |
109 | 39 | } |
110 | | |
111 | | class RewriteReceiver { |
112 | | public: |
113 | | virtual ~RewriteReceiver(); |
114 | | |
115 | | virtual void insert(SourceLocation loc, StringRef text) = 0; |
116 | | virtual void remove(CharSourceRange range) = 0; |
117 | | virtual void increaseIndentation(CharSourceRange range, |
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 | 885 | Transaction(TransformActions &TA) : TA(TA), Aborted(false) { |
130 | 885 | TA.startTransaction(); |
131 | 885 | } |
132 | | |
133 | 885 | ~Transaction() { |
134 | 885 | if (!isAborted()) |
135 | 877 | TA.commitTransaction(); |
136 | 885 | } |
137 | | |
138 | 8 | void abort() { |
139 | 8 | TA.abortTransaction(); |
140 | 8 | Aborted = true; |
141 | 8 | } |
142 | | |
143 | 885 | bool isAborted() const { return Aborted; } |
144 | | }; |
145 | | |
146 | | class MigrationPass { |
147 | | public: |
148 | | ASTContext &Ctx; |
149 | | LangOptions::GCMode OrigGCMode; |
150 | | MigratorOptions MigOptions; |
151 | | Sema &SemaRef; |
152 | | TransformActions &TA; |
153 | | const CapturedDiagList &CapturedDiags; |
154 | | std::vector<SourceLocation> &ARCMTMacroLocs; |
155 | | Optional<bool> EnableCFBridgeFns; |
156 | | |
157 | | MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode, |
158 | | Sema &sema, TransformActions &TA, |
159 | | const CapturedDiagList &capturedDiags, |
160 | | std::vector<SourceLocation> &ARCMTMacroLocs) |
161 | | : Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(), |
162 | | SemaRef(sema), TA(TA), CapturedDiags(capturedDiags), |
163 | 122 | ARCMTMacroLocs(ARCMTMacroLocs) { } |
164 | | |
165 | 403 | const CapturedDiagList &getDiags() const { return CapturedDiags; } |
166 | | |
167 | 613 | bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; } |
168 | 0 | bool noFinalizeRemoval() const { return MigOptions.NoFinalizeRemoval; } |
169 | 50 | void setNoFinalizeRemoval(bool val) {MigOptions.NoFinalizeRemoval = val; } |
170 | | |
171 | | bool CFBridgingFunctionsDefined(); |
172 | | }; |
173 | | |
174 | 1.41k | static inline StringRef getARCMTMacroName() { |
175 | 1.41k | return "__IMPL_ARCMT_REMOVED_EXPR__"; |
176 | 1.41k | } ARCMT.cpp:clang::arcmt::getARCMTMacroName() Line | Count | Source | 174 | 1.08k | static inline StringRef getARCMTMacroName() { | 175 | 1.08k | return "__IMPL_ARCMT_REMOVED_EXPR__"; | 176 | 1.08k | } |
Unexecuted instantiation: PlistReporter.cpp:clang::arcmt::getARCMTMacroName() Unexecuted instantiation: TransAPIUses.cpp:clang::arcmt::getARCMTMacroName() Unexecuted instantiation: TransARCAssign.cpp:clang::arcmt::getARCMTMacroName() Unexecuted instantiation: TransAutoreleasePool.cpp:clang::arcmt::getARCMTMacroName() Unexecuted instantiation: TransBlockObjCVariable.cpp:clang::arcmt::getARCMTMacroName() TransEmptyStatementsAndDealloc.cpp:clang::arcmt::getARCMTMacroName() Line | Count | Source | 174 | 128 | static inline StringRef getARCMTMacroName() { | 175 | 128 | return "__IMPL_ARCMT_REMOVED_EXPR__"; | 176 | 128 | } |
Unexecuted instantiation: TransGCAttrs.cpp:clang::arcmt::getARCMTMacroName() Unexecuted instantiation: TransGCCalls.cpp:clang::arcmt::getARCMTMacroName() Unexecuted instantiation: TransProperties.cpp:clang::arcmt::getARCMTMacroName() Unexecuted instantiation: TransProtectedScope.cpp:clang::arcmt::getARCMTMacroName() Unexecuted instantiation: TransRetainReleaseDealloc.cpp:clang::arcmt::getARCMTMacroName() Unexecuted instantiation: TransUnbridgedCasts.cpp:clang::arcmt::getARCMTMacroName() Unexecuted instantiation: TransUnusedInitDelegate.cpp:clang::arcmt::getARCMTMacroName() Unexecuted instantiation: TransZeroOutPropsInDealloc.cpp:clang::arcmt::getARCMTMacroName() TransformActions.cpp:clang::arcmt::getARCMTMacroName() Line | Count | Source | 174 | 198 | static inline StringRef getARCMTMacroName() { | 175 | 198 | return "__IMPL_ARCMT_REMOVED_EXPR__"; | 176 | 198 | } |
Unexecuted instantiation: Transforms.cpp:clang::arcmt::getARCMTMacroName() |
177 | | |
178 | | } // end namespace arcmt |
179 | | |
180 | | } // end namespace clang |
181 | | |
182 | | #endif |