Martin =?utf-8?q?Bednár?= <[email protected]>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/[email protected]>


AaronBallman wrote:

> Thanks for taking a look.
> 
> > we'd want something more along the lines of 
> > clang_CXXMethod_isBinaryOperator()
> 
> non-member operators need to be supported too. `clang_Function_isOperator()` ?

Ah good call, though we probably don't want it to be `is` because this would 
return the kind rather than a bool, so probably more along the lines of 
`clang_Function_getBinaryOperatorKind()`.

> > That said, I'd like to understand the need a bit more before adding a new 
> > interface.
> 
> I have two needs :
> 
>     * know whether a CallExpr calls an operator (unary/binary doesn't 
> matter). This could be done by querying the referenced cursor 
> (`CXXMethod`/`FunctionDecl`) and asking whether it's an operator, or from the 
> Expr itself.  I'd prefer knowing whether the referenced declaration cursor is 
> an operator.

I think both are important because you can also call operators directly but 
they have a different AST form: https://godbolt.org/z/qKo3GqKEo -- the use of 
`+` as an operator forms a `CXXOperatorCallExpr` while the call to `operator+` 
forms a `CXXMemberCallExpr`. So I think it makes sense for 
`clang_getCursorBinaryOperatorKind()` to handle a `CXXOperatorCallExpr` because 
you can use this to catch times the user is actually using an operator, but 
without having to know about the oddity of calling the operator directly. But 
if you have a function declaration, it's still useful to know "is this for an 
operator and if so, which one?".

>     * Know when the called operator is `co_await`.

Makes sense.

> I actually don't like too much querying the `CallExpr` directly, but added it 
> for ease of use/consistency. I very much prefer querying the Declaration.

Thanks for the explanation! I'm okay with adding new declaration-based 
interfaces and I'm also okay with extending the expression-based interface to 
handle a `CXXOperatorCallExpr`; your call on whether you want to do both, or 
only add the declaration interfaces.

https://github.com/llvm/llvm-project/pull/216553
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to