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

Vedant Kumar via cfe-dev cfe-dev at lists.llvm.org
Thu Jan 18 19:16:07 PST 2018


> On Jan 18, 2018, at 6:57 PM, George Karpenkov via cfe-dev <cfe-dev at lists.llvm.org> 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 <https://reviews.llvm.org/D40727>.

vedant

> 
> Regards,
> George
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180118/af1bea6c/attachment.html>


More information about the cfe-dev mailing list