[PATCH] D83172: [Attributor] Create getter function for the ID of the abstract attribute

Luofan Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 5 02:40:15 PDT 2020


bbn added a comment.

In D83172#2131745 <https://reviews.llvm.org/D83172#2131745>, @kuter wrote:

> This seems like too much code duplication.
>  I think we can have a macro to declare `getIdAddr` and the `getName` function.
>  I am curious what other people think about this.


@kuter Do you mean we can use macro inside the header file? for example, we create such macro and use it inside the declaration of the class, but I still think it is not clean.

  #define AA_FUNC_GET_ID(CLASS) \
   const char *getIdAddr() const override { return &ID; }

As far as I know we the `getIdAddr()` function has to be declared for every AbstractAttributes, so we cannot avoid this. However, maybe we can create a macro for the actual definition of the function (like the `createForPosition` function)

- In header file:

  struct AA {
    const char *getIdAddr() const override;



- in source file

  #define AA_FUNC_GET_ID(CLASS) \
    const char *CLASS::getIdAddr() { return &ID; }

But I think such getter is short and small, and this way does not seem to reduce the code duplication...

Do you have any other ideas for this? Thanks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83172/new/

https://reviews.llvm.org/D83172





More information about the llvm-commits mailing list