Common interface for BlockDecl, FunctionDecl, ObjCMethodDecl?

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

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(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