diff --git a/flang/lib/parser/message.cc b/flang/lib/parser/message.cc index a4a13ec8391e..296dae608f03 100644 --- a/flang/lib/parser/message.cc +++ b/flang/lib/parser/message.cc @@ -134,6 +134,18 @@ std::string Message::ToString() const { text_); } +void Message::ResolveProvenances(const CookedSource &cooked) { + if (CharBlock * cb{std::get_if(&location_)}) { + if (std::optional resolved{ + cooked.GetProvenanceRange(*cb)}) { + location_ = *resolved; + } + } + if (Message * attachment{attachment_.get()}) { + attachment->ResolveProvenances(cooked); + } +} + std::optional Message::GetProvenanceRange( const CookedSource &cooked) const { return std::visit(common::visitors{[&](const CharBlock &cb) { @@ -221,6 +233,12 @@ void Messages::Copy(const Messages &that) { } } +void Messages::ResolveProvenances(const CookedSource &cooked) { + for (Message &m : messages_) { + m.ResolveProvenances(cooked); + } +} + void Messages::Emit( std::ostream &o, const CookedSource &cooked, bool echoSourceLines) const { std::vector sorted; diff --git a/flang/lib/parser/message.h b/flang/lib/parser/message.h index 373d933ca65d..ca23a25efae7 100644 --- a/flang/lib/parser/message.h +++ b/flang/lib/parser/message.h @@ -144,6 +144,7 @@ public: bool SortBefore(const Message &that) const; bool IsFatal() const; std::string ToString() const; + void ResolveProvenances(const CookedSource &); std::optional GetProvenanceRange(const CookedSource &) const; void Emit( std::ostream &, const CookedSource &, bool echoSourceLine = true) const; @@ -207,6 +208,7 @@ public: void Incorporate(Messages &); void Copy(const Messages &); + void ResolveProvenances(const CookedSource &); void Emit(std::ostream &, const CookedSource &cooked, bool echoSourceLines = true) const;