public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-3769] analyzer: introduce succeed_or_fail_call_info
Date: Tue,  8 Nov 2022 02:53:58 +0000 (GMT)	[thread overview]
Message-ID: <20221108025359.24B0F385840A@sourceware.org> (raw)

https://gcc.gnu.org/g:be9fdbda1cbcd6a35b05424679c6c059605b61cb

commit r13-3769-gbe9fdbda1cbcd6a35b05424679c6c059605b61cb
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Mon Nov 7 21:52:40 2022 -0500

    analyzer: introduce succeed_or_fail_call_info
    
    This makes some followup code much cleaner.
    
    gcc/analyzer/ChangeLog:
            * call-info.cc (success_call_info::get_desc): Delete.
            (failed_call_info::get_desc): Likewise.
            (succeed_or_fail_call_info::get_desc): New.
            * call-info.h (class succeed_or_fail_call_info): New.
            (class success_call_info): Convert to a subclass of
            succeed_or_fail_call_info.
            (class failed_call_info): Likewise.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/call-info.cc | 21 ++++++---------------
 gcc/analyzer/call-info.h  | 34 ++++++++++++++++++++++++++--------
 2 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/gcc/analyzer/call-info.cc b/gcc/analyzer/call-info.cc
index ffdab73b165..7a1c4edfcae 100644
--- a/gcc/analyzer/call-info.cc
+++ b/gcc/analyzer/call-info.cc
@@ -141,24 +141,15 @@ call_info::call_info (const call_details &cd)
   gcc_assert (m_fndecl);
 }
 
-/* class success_call_info : public call_info.  */
-
-/* Implementation of call_info::get_desc vfunc for success_call_info.  */
-
-label_text
-success_call_info::get_desc (bool can_colorize) const
-{
-  return make_label_text (can_colorize, "when %qE succeeds", get_fndecl ());
-}
-
-/* class failed_call_info : public call_info.  */
-
-/* Implementation of call_info::get_desc vfunc for failed_call_info.  */
+/* class succeed_or_fail_call_info : public call_info.  */
 
 label_text
-failed_call_info::get_desc (bool can_colorize) const
+succeed_or_fail_call_info::get_desc (bool can_colorize) const
 {
-  return make_label_text (can_colorize, "when %qE fails", get_fndecl ());
+  if (m_success)
+    return make_label_text (can_colorize, "when %qE succeeds", get_fndecl ());
+  else
+    return make_label_text (can_colorize, "when %qE fails", get_fndecl ());
 }
 
 } // namespace ana
diff --git a/gcc/analyzer/call-info.h b/gcc/analyzer/call-info.h
index 4bb7dd7e198..2fd50776f0a 100644
--- a/gcc/analyzer/call-info.h
+++ b/gcc/analyzer/call-info.h
@@ -51,17 +51,36 @@ private:
 };
 
 /* Subclass of call_info for a "success" outcome of a call,
-   adding a "when `FNDECL' succeeds" message.
+   adding either a
+     "when `FNDECL' succeeds" message (when 'success' is true)
+   or a
+     "when `FNDECL' fails" message    (when 'success' is false).
    This is still abstract: the custom_edge_info::update_model vfunc
    must be implemented.  */
 
-class success_call_info : public call_info
+class succeed_or_fail_call_info : public call_info
 {
 public:
   label_text get_desc (bool can_colorize) const final override;
 
 protected:
-  success_call_info (const call_details &cd) : call_info (cd) {}
+  succeed_or_fail_call_info (const call_details &cd, bool success)
+   : call_info (cd), m_success (success) {}
+
+  bool m_success;
+};
+
+/* Subclass of call_info for a "success" outcome of a call,
+   adding a "when `FNDECL' succeeds" message.
+   This is still abstract: the custom_edge_info::update_model vfunc
+   must be implemented.  */
+
+class success_call_info : public succeed_or_fail_call_info
+{
+protected:
+  success_call_info (const call_details &cd)
+  : succeed_or_fail_call_info (cd, true)
+  {}
 };
 
 /* Subclass of call_info for a "failure" outcome of a call,
@@ -69,13 +88,12 @@ protected:
    This is still abstract: the custom_edge_info::update_model vfunc
    must be implemented.  */
 
-class failed_call_info : public call_info
+class failed_call_info : public succeed_or_fail_call_info
 {
-public:
-  label_text get_desc (bool can_colorize) const final override;
-
 protected:
-  failed_call_info (const call_details &cd) : call_info (cd) {}
+  failed_call_info (const call_details &cd)
+  : succeed_or_fail_call_info (cd, false)
+  {}
 };
 
 } // namespace ana

                 reply	other threads:[~2022-11-08  2:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221108025359.24B0F385840A@sourceware.org \
    --to=dmalcolm@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).