From 825537bf29046dc5721f0c6b066a04017097e793 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Tue, 9 Jul 2024 14:27:45 +0800 Subject: [PATCH] cfg: Tweak formatting of cfg-text-loc to include both locations --- cfg/CFG.cc | 20 +++++++++++++------- cfg/CFG.h | 3 +++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cfg/CFG.cc b/cfg/CFG.cc index 18f986b12..8bea9d336 100644 --- a/cfg/CFG.cc +++ b/cfg/CFG.cc @@ -395,13 +395,7 @@ string BasicBlock::toTextualString(const core::GlobalState &gs, optionalouterLoops); } 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) { @@ -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 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 diff --git a/cfg/CFG.h b/cfg/CFG.h index 72fa0a674..b9b7ae188 100644 --- a/cfg/CFG.h +++ b/cfg/CFG.h @@ -7,6 +7,7 @@ #include "core/Types.h" #include #include +#include #include "cfg/Instructions.h" @@ -60,6 +61,8 @@ class Binding final { Binding() = default; Binding &operator=(Binding &&) = default; + + std::string toTextualString(const core::GlobalState &gs, std::optional file, const CFG &cfg) const; }; class BasicBlock final {