[cfe-dev] Common interface for BlockDecl, FunctionDecl, ObjCMethodDecl?

George Karpenkov via cfe-dev cfe-dev at lists.llvm.org
Thu Jan 18 18:57:18 PST 2018


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


More information about the cfe-dev mailing list