-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowing all binary C++ operators in WebIDL #22770
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me. @kripken WDYT?
Hmm, I think the reason we focused on the But maybe that risk is very small? Anyhow, if there is real-world use case I'm not opposed to it. Out of curiosity @jrouwe can you explain a bit about the use case you have in mind for this? I guess the library has only |
The use case is for a quaternion or matrix class. These classes look like:
In this example the operation Obviously I could define a function like Matrix matrix = ...;
Vector vector = ...;
Vector result = matrix * vector; B.t.w. the real class lives here: The IDL lives here: |
Thanks for the info @jrouwe , yeah, that makes sense. I agree we should support this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm with an update to the docs:
https://emscripten.org/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html#operators
File is at site/source/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.rst
.
Documentation updated. |
tools/webidl_binder.py
Outdated
call = '((*%s)[%s%s])' % (cast_self, maybe_deref, args[0]) | ||
else: | ||
raise Exception('unfamiliar operator ' + operator) | ||
call = '(*%s %s %s%s)' % (cast_self, operator, maybe_deref, args[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we error somehow if this is not one of the allowed operators? For example if it is a unary operator. Before this PR we'd error on unsupported things, and it would be good to keep doing so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the list explicit (based on https://en.cppreference.com/w/cpp/language/operators). Note that previously operators would be allowed as long as they contained a '=', so 'x=' would have been a valid operator (but doesn't compile obviously). Those will be caught now as well.
864ba41
to
76d4830
Compare
tools/webidl_binder.py
Outdated
if any(x == operator for x in ["+", "-", "*", "/", "%", "^", "&", "|", "=", | ||
"<", ">", "+=", "-=", "*=", "/=", "%=", "^=", "&=", "|=", "<<", ">>", ">>=", | ||
"<<=", "==", "!=", "<=", ">=", "<=>", "&&", "||"]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if any(x == operator for x in ["+", "-", "*", "/", "%", "^", "&", "|", "=", | |
"<", ">", "+=", "-=", "*=", "/=", "%=", "^=", "&=", "|=", "<<", ">>", ">>=", | |
"<<=", "==", "!=", "<=", ">=", "<=>", "&&", "||"]): | |
if operator in ["+", "-", "*", "/", "%", "^", "&", "|", "=", | |
"<", ">", "+=", "-=", "*=", "/=", "%=", "^=", "&=", "|=", "<<", ">>", ">>=", | |
"<<=", "==", "!=", "<=", ">=", "<=>", "&&", "||"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't use python very often... I've merged your suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, looks good!
Also erroring on previously allowed, but non-existing operators like 'x='.
This expands the list of supported operators by the 'Operator' WebIDL attribute to all binary operators that are supported by C++.
Fixes #9415