Skip to content

Commit 387495b

Browse files
cleanup: Clean up Debug.h + add helper function. (#117)
1 parent d8be16f commit 387495b

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

scip_indexer/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ cc_library(
5252
"//sorbet_version",
5353
"@com_google_absl//absl/status",
5454
"@com_google_absl//absl/status:statusor",
55+
"@com_google_absl//absl/strings",
5556
"@com_google_absl//absl/synchronization",
5657
"@cxxopts",
5758
"@spdlog",

scip_indexer/Debug.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace sorbet::scip_indexer {
1010

11+
constexpr sorbet::core::ErrorClass SCIPRubyDebug{400, sorbet::core::StrictLevel::False};
12+
1113
void _log_debug(const sorbet::core::GlobalState &gs, sorbet::core::Loc loc, std::string s) {
1214
if (auto e = gs.beginError(loc, SCIPRubyDebug)) {
1315
auto lines = absl::StrSplit(s, '\n');

scip_indexer/Debug.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include "common/common.h"
1111
#include "core/Error.h"
1212

13-
template <typename K, typename V, typename Fn> std::string map_to_string(const sorbet::UnorderedMap<K, V> m, Fn f) {
13+
namespace sorbet::scip_indexer {
14+
15+
template <typename K, typename V, typename Fn> std::string showMap(const sorbet::UnorderedMap<K, V> &m, Fn f) {
1416
std::ostringstream out;
1517
out << "{";
1618
auto i = -1;
@@ -25,7 +27,7 @@ template <typename K, typename V, typename Fn> std::string map_to_string(const s
2527
return out.str();
2628
}
2729

28-
template <typename T, typename Fn> std::string set_to_string(const sorbet::UnorderedSet<T> s, Fn f) {
30+
template <typename T, typename Fn> std::string showSet(const sorbet::UnorderedSet<T> &s, Fn f) {
2931
std::ostringstream out;
3032
out << "{";
3133
auto i = -1;
@@ -40,7 +42,7 @@ template <typename T, typename Fn> std::string set_to_string(const sorbet::Unord
4042
return out.str();
4143
}
4244

43-
template <typename T, typename Fn> std::string vec_to_string(const std::vector<T> v, Fn f) {
45+
template <typename T, typename Fn> std::string showVec(const std::vector<T> &v, Fn f) {
4446
std::ostringstream out;
4547
out << "[";
4648
for (auto i = 0; i < v.size(); ++i) {
@@ -53,10 +55,6 @@ template <typename T, typename Fn> std::string vec_to_string(const std::vector<T
5355
return out.str();
5456
}
5557

56-
namespace sorbet::scip_indexer {
57-
58-
constexpr sorbet::core::ErrorClass SCIPRubyDebug{400, sorbet::core::StrictLevel::False};
59-
6058
void _log_debug(const sorbet::core::GlobalState &gs, sorbet::core::Loc loc, std::string s);
6159
} // namespace sorbet::scip_indexer
6260

scip_indexer/SCIPIndexer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ class AliasMap final {
616616
}
617617

618618
string showRaw(const core::GlobalState &gs, core::FileRef file, const cfg::CFG &cfg) const {
619-
return map_to_string(this->map, [&](const cfg::LocalRef &local, auto &data) -> string {
619+
return showMap(this->map, [&](const cfg::LocalRef &local, const auto &data) -> string {
620620
auto symRef = get<0>(data);
621621
auto offsets = get<1>(data);
622622
auto emitted = get<2>(data);

scip_indexer/SCIPSymbolRef.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ absl::Status UntypedGenericSymbolRef::symbolForExpr(const core::GlobalState &gs,
8181
return absl::OkStatus();
8282
}
8383

84+
string UntypedGenericSymbolRef::showRaw(const core::GlobalState &gs) const {
85+
if (this->name.exists()) {
86+
return fmt::format("UGSR(owner: {}, name: {})", this->selfOrOwner.showFullName(gs), this->name.toString(gs));
87+
}
88+
return fmt::format("UGSR(symbol: {})", this->selfOrOwner.showFullName(gs));
89+
}
90+
8491
string GenericSymbolRef::showRaw(const core::GlobalState &gs) const {
8592
switch (this->kind()) {
8693
case Kind::UndeclaredField:

scip_indexer/SCIPSymbolRef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class UntypedGenericSymbolRef final {
8383
// Try to compute a scip::Symbol for this value.
8484
absl::Status symbolForExpr(const core::GlobalState &gs, const GemMetadata &metadata, std::optional<core::Loc> loc,
8585
scip::Symbol &symbol) const;
86+
87+
std::string showRaw(const core::GlobalState &gs) const;
8688
};
8789

8890
// A wrapper type to handle both top-level symbols (like classes) as well as

0 commit comments

Comments
 (0)