Common interface for BlockDecl, FunctionDecl, ObjCMethodDecl?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Common interface for BlockDecl, FunctionDecl, ObjCMethodDecl?

Artem Dergachev via cfe-dev
Hi,

Declarations for callable objects: BlockDecl, FunctionDecl, ObjCMethodDecl share quite a few methods:

 - parameters()
 - getSourceRange()
 - getBody()

and some others.
Despite that, they don’t have any super-interface (CallableDecl?).

As a result, I often find myself writing duplicating code. Clang static analyzer has a CallEvent struct which partially mitigates the issue, but
1) In some cases, it’s not suitable
2) CallEvent itself has duplication

Would anyone be against  introducing a common interface for those classes?
It could be as tiny change as just adding an inheritance, and then users would be able to do

if (auto *CD = dyn_cast<CallableDecl>(D))
    D->parameters() // …

instead of duplicating code

Regards,
George
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Common interface for BlockDecl, FunctionDecl, ObjCMethodDecl?

Artem Dergachev via cfe-dev

On Jan 18, 2018, at 6:57 PM, George Karpenkov via cfe-dev <[hidden email]> wrote:

Hi,

Declarations for callable objects: BlockDecl, FunctionDecl, ObjCMethodDecl share quite a few methods:

- parameters()
- getSourceRange()
- getBody()

and some others.
Despite that, they don’t have any super-interface (CallableDecl?).

CodeGenFunction has AbstractCallee. Maybe that could be extended to suit your needs?


As a result, I often find myself writing duplicating code. Clang static analyzer has a CallEvent struct which partially mitigates the issue, but
1) In some cases, it’s not suitable
2) CallEvent itself has duplication

Would anyone be against  introducing a common interface for those classes?
It could be as tiny change as just adding an inheritance, and then users would be able to do

if (auto *CD = dyn_cast<CallableDecl>(D))
   D->parameters() // …

instead of duplicating code

+ 1, I'd be happy to review that.

If anyone else is interested, there's a similar patch for llvm under review: https://reviews.llvm.org/D40727.

vedant


Regards,
George
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev