Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions cfg/CFG.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,7 @@ string BasicBlock::toTextualString(const core::GlobalState &gs, optional<core::F
fmt::format_to(std::back_inserter(buf), " # outerLoops: {}\n", this->outerLoops);
}
for (const Binding &exp : this->exprs) {
string positionText = "";
if (file) {
positionText = fmt::format(" @ {}", core::Loc(file.value(), exp.loc).showRawLineColumn(gs));
}

fmt::format_to(std::back_inserter(buf), " {}{} = {}\n", exp.bind.toString(gs, cfg), positionText,
exp.value.toString(gs, cfg));
fmt::format_to(std::back_inserter(buf), " {}\n", exp.toTextualString(gs, file, cfg));
}

if (this->bexit.thenb == this->bexit.elseb) {
Expand Down Expand Up @@ -442,4 +436,16 @@ string BasicBlock::showRaw(const core::GlobalState &gs, const CFG &cfg) const {
Binding::Binding(LocalOccurrence bind, core::LocOffsets loc, InstructionPtr value)
: bind(bind.variable, bind.loc), loc(loc), value(std::move(value)) {}

std::string Binding::toTextualString(const core::GlobalState &gs, std::optional<core::FileRef> file,
const CFG &cfg) const {
string lhsPositionText = "";
string rhsPositionText = "";
if (file) {
lhsPositionText = fmt::format(" @ {}", core::Loc(file.value(), this->bind.loc).showRawLineColumn(gs));
rhsPositionText = fmt::format(" (@ {})", core::Loc(file.value(), this->loc).showRawLineColumn(gs));
}
return fmt::format("{}{} = {}{}", this->bind.toString(gs, cfg), lhsPositionText, this->value.toString(gs, cfg),
rhsPositionText);
}

} // namespace sorbet::cfg
3 changes: 3 additions & 0 deletions cfg/CFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "core/Types.h"
#include <climits>
#include <memory>
#include <optional>

#include "cfg/Instructions.h"

Expand Down Expand Up @@ -60,6 +61,8 @@ class Binding final {
Binding() = default;

Binding &operator=(Binding &&) = default;

std::string toTextualString(const core::GlobalState &gs, std::optional<core::FileRef> file, const CFG &cfg) const;
};

class BasicBlock final {
Expand Down