From: peter klausler Date: Fri, 16 Feb 2018 23:47:30 +0000 (-0800) Subject: [flang] Define MessageText and "..."_msg. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5e83ea521c604cc7b77e5e8b11a32cede5e16eff;p=platform%2Fupstream%2Fllvm.git [flang] Define MessageText and "..."_msg. Original-commit: flang-compiler/f18@6e9e16431c3de9b48bfa50dc489f7ddf73d783e4 Reviewed-on: https://github.com/flang-compiler/f18/pull/14 Tree-same-pre-rewrite: false --- diff --git a/flang/lib/parser/message.cc b/flang/lib/parser/message.cc index 9ee48de..e9a6c5e 100644 --- a/flang/lib/parser/message.cc +++ b/flang/lib/parser/message.cc @@ -3,12 +3,19 @@ namespace Fortran { namespace parser { +std::ostream &operator<<(std::ostream &o, const MessageText &t) { + for (size_t j{0}; j < t.size(); ++j) { + o << t.str()[j]; + } + return o; +} + Provenance Message::Emit( std::ostream &o, const AllSources &sources, bool echoSourceLine) const { if (!context_ || context_->Emit(o, sources, false) != provenance_) { sources.Identify(o, provenance_, "", echoSourceLine); } - o << " " << message_ << '\n'; + o << " " << text_ << message_ << '\n'; return provenance_; } diff --git a/flang/lib/parser/message.h b/flang/lib/parser/message.h index 0abf5d4..4dcae4b 100644 --- a/flang/lib/parser/message.h +++ b/flang/lib/parser/message.h @@ -18,12 +18,38 @@ namespace parser { class Message; using MessageContext = std::shared_ptr; +class MessageText { +public: + MessageText() {} + constexpr MessageText(const char str[], size_t n) : str_{str}, bytes_{n} {} + constexpr MessageText(const MessageText &) = default; + MessageText(MessageText &&) = default; + constexpr MessageText &operator=(const MessageText &) = default; + MessageText &operator=(MessageText &&) = default; + + const char *str() const { return str_; } + size_t size() const { return bytes_; } + + std::string ToString() const { return std::string(str_, bytes_); } + +private: + const char *str_{nullptr}; + size_t bytes_{0}; +}; + +constexpr MessageText operator""_msg(const char str[], size_t n) { + return MessageText{str, n}; +} + +std::ostream &operator<<(std::ostream &, const MessageText &); + class Message { public: Message() {} Message(const Message &) = default; Message(Message &&) = default; + Message(Provenance at, MessageText t, MessageContext ctx = nullptr); Message(Provenance at, const std::string &msg, MessageContext ctx = nullptr) : provenance_{at}, message_{msg}, context_{ctx} {} Message(Provenance at, std::string &&msg, MessageContext ctx = nullptr) @@ -39,6 +65,7 @@ public: } Provenance provenance() const { return provenance_; } + MessageText text() const { return text_; } std::string message() const { return message_; } MessageContext context() const { return context_; } @@ -47,6 +74,7 @@ public: private: Provenance provenance_; + MessageText text_; std::string message_; MessageContext context_; };