13
13
#include " swift/extractor/infra/SwiftLocationExtractor.h"
14
14
#include " swift/extractor/infra/SwiftBodyEmissionStrategy.h"
15
15
#include " swift/extractor/config/SwiftExtractorState.h"
16
- #include " swift/extractor/infra/log/SwiftLogging .h"
16
+ #include " swift/extractor/infra/log/SwiftAssert .h"
17
17
18
18
namespace codeql {
19
19
@@ -67,21 +67,20 @@ class SwiftDispatcher {
67
67
entry.forEachLabel ([&valid, &entry, this ](const char * field, int index, auto & label) {
68
68
using Label = std::remove_reference_t <decltype (label)>;
69
69
if (!label.valid ()) {
70
- std::cerr << entry.NAME << " has undefined " << field;
71
- if (index >= 0 ) {
72
- std::cerr << ' [' << index << ' ]' ;
73
- }
70
+ const char * action;
74
71
if constexpr (std::is_base_of_v<typename Label::Tag, UnspecifiedElementTag>) {
75
- std::cerr << " , replacing with unspecified element\n " ;
72
+ action = " replacing with unspecified element" ;
76
73
label = emitUnspecified (idOf (entry), field, index);
77
74
} else {
78
- std::cerr << " , skipping emission\n " ;
75
+ action = " skipping emission" ;
79
76
valid = false ;
80
77
}
78
+ LOG_ERROR (" {} has undefined field {}{}, {}" , entry.NAME , field,
79
+ index >= 0 ? (' [' + std::to_string (index) + ' ]' ) : " " , action);
81
80
}
82
81
});
83
82
if (valid) {
84
- trap.emit (entry);
83
+ trap.emit (entry, /* check */ false );
85
84
}
86
85
}
87
86
@@ -146,8 +145,8 @@ class SwiftDispatcher {
146
145
// this is required so we avoid any recursive loop: a `fetchLabel` during the visit of `e` might
147
146
// end up calling `fetchLabel` on `e` itself, so we want the visit of `e` to call `fetchLabel`
148
147
// only after having called `assignNewLabel` on `e`.
149
- assert (std::holds_alternative<std::monostate>(waitingForNewLabel) &&
150
- " fetchLabel called before assignNewLabel" );
148
+ CODEQL_ASSERT (std::holds_alternative<std::monostate>(waitingForNewLabel),
149
+ " fetchLabel called before assignNewLabel" );
151
150
if (auto l = store.get (e)) {
152
151
return *l;
153
152
}
@@ -162,8 +161,8 @@ class SwiftDispatcher {
162
161
}
163
162
return *l;
164
163
}
165
- assert (! " assignNewLabel not called during visit" );
166
- return {} ;
164
+ LOG_CRITICAL ( " assignNewLabel not called during visit" );
165
+ abort () ;
167
166
}
168
167
169
168
// convenience `fetchLabel` overload for `swift::Type` (which is just a wrapper for
@@ -184,7 +183,7 @@ class SwiftDispatcher {
184
183
// declarations
185
184
template <typename E, typename ... Args, std::enable_if_t <IsStorable<E>>* = nullptr >
186
185
TrapLabel<ConcreteTrapTagOf<E>> assignNewLabel (const E& e, Args&&... args) {
187
- assert (waitingForNewLabel == Store::Handle{e} && " assignNewLabel called on wrong entity" );
186
+ CODEQL_ASSERT (waitingForNewLabel == Store::Handle{e}, " assignNewLabel called on wrong entity" );
188
187
auto label = trap.createLabel <ConcreteTrapTagOf<E>>(std::forward<Args>(args)...);
189
188
store.insert (e, label);
190
189
waitingForNewLabel = std::monostate{};
@@ -332,7 +331,10 @@ class SwiftDispatcher {
332
331
SwiftBodyEmissionStrategy& bodyEmissionStrategy;
333
332
Store::Handle waitingForNewLabel{std::monostate{}};
334
333
std::unordered_set<swift::ModuleDecl*> encounteredModules;
335
- Logger logger{" dispatcher" };
334
+ Logger& logger () {
335
+ static Logger ret{" dispatcher" };
336
+ return ret;
337
+ }
336
338
};
337
339
338
340
} // namespace codeql
0 commit comments