#pragma once #include #include "swift/extractor/trap/TrapLabel.h" namespace codeql { // Sink for trap emissions and label assignments. This abstracts away `ofstream` operations // like `ofstream`, an explicit bool operator is provided, that return false if something // went wrong // TODO better error handling class TrapOutput { std::ostream& out_; public: explicit TrapOutput(std::ostream& out) : out_{out} {} template void assignStar(TrapLabel label) { print(label, "=*"); } template void assignKey(TrapLabel label, const std::string& key) { // prefix the key with the id to guarantee the same key is not used wrongly with different tags auto prefixed = std::string(Tag::prefix) + '_' + key; print(label, "=@", trapQuoted(prefixed)); } template void assignKey(TrapLabel label, const Args&... keyParts) { std::ostringstream oss; (oss << ... << keyParts); assignKey(label, oss.str()); } template void emit(const Entry& e) { print(e); } private: template void print(const Args&... args) { (out_ << ... << args) << '\n'; } }; } // namespace codeql