public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Gavin Ray <ray.gavin97@gmail.com>
To: gcc@gcc.gnu.org
Subject: Difficulty in implementing a GCC plugin for [[invariant]] contract functions in classes/structs without prior experience?
Date: Thu, 29 Dec 2022 10:37:40 -0500	[thread overview]
Message-ID: <CAFtvWZPaaDYjvcevpnbZg5QAtaNr-0dUpD_mfbGDsH-LMQo2iw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1368 bytes --]

Hey all,

The feature I appreciate most about the D programming language is its
"Design by Contract" feature.
Contract programming - Dlang Tour
<https://tour.dlang.org/tour/en/gems/contract-programming>

With the recent merge of Contracts to GCC master, C++ comes close to this,
with support for function-based contracts.
The most powerful contract though, is the "invariant" contract:

*invariant() is a special member function of struct and class types that
> allows sanity checking an object's state during its whole lifetime:*


>
> *- invariant() is called after the constructor has run and before the
> destructor is called.*
> *- invariant() is called before entering a member function*
> *- invariant() is called after exiting a member function.**- Class
> invariants are inherited. That means that a derived class invariant will
> implicitly call the base class invariant.*


I'm very interested in prototyping a GCC plugin to implement support for
transforming all member function calls in class/struct types
such that a call to the [[invariant]]-annotated function (if any) is placed
at the beginning and end of method bodies.

Does anyone have any idea whether something like this would be suitable for
a first plugin,
or if there would be roadblocks/technical challenges to implementing such a
thing?

I'd be grateful for any advice.

Thank you,
Gavin =)

             reply	other threads:[~2022-12-29 15:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-29 15:37 Gavin Ray [this message]
2022-12-29 18:33 ` Gavin Ray
2022-12-30 17:29   ` Gavin Ray

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=CAFtvWZPaaDYjvcevpnbZg5QAtaNr-0dUpD_mfbGDsH-LMQo2iw@mail.gmail.com \
    --to=ray.gavin97@gmail.com \
    --cc=gcc@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).