-
Notifications
You must be signed in to change notification settings - Fork 64
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
Equals initializer syntax #1580
Conversation
because warnings do not prevent the file from being formatted, and after formatting the positions of the warnings are wrong which can cause errors
Some of them cannot really be fixed yet, like test/C/concurrent/ScheduleAt.lf
379ed01
to
1485833
Compare
760b27e
to
b94501d
Compare
b94501d
to
753ec48
Compare
Only 654 files changed? 🤣 |
this is to replace the old C syntax
This looks good to me, though it would be great to get some more 👀 on this. My main concern is that this does not only affect our tests, but also our examples. We should probably set up CI in https://github.com/lf-lang/examples-lingua-franca first, and prepare a PR that makes all the required adjustments... |
Just to clarify, does using braces now trigger a warning or an error? |
This also requires an update of all the examples and text on the website. |
Using parentheses triggers a warning (except in C++), braces is still an error in all targets except C++. Also in all targets including C++, writing
I've been working on this and will submit a PR today. |
Looks like all the tests pass now. This should be ready to be merged. Should we go ahead or does anyone else want to review the code? |
I do not object to merging this right away even though I have not reviewed the code. If other people think that more review is important and can wait for a few days for me to do it, I can, but I also do not mind trusting you and Clement so that this big PR does not linger any longer. |
The one failing test, In C, I am not aware of any use cases for zero-length arrays except in the case when you are code-generating C, using macros, etc., and the array of length zero is the continuation of some pattern. I am not sure I can envision such situations cropping up in LF programs. For sure it is awkward and weird that C does not permit initializers of length zero before 2023, but maybe that is C's fault, not ours. We have the ability to patch it up in LF, but I am not sure that that is our responsibility. |
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, I have no important comments. Looking forward to seeing this get merged soon!
Co-authored-by: Peter Donovan <[email protected]>
Co-authored-by: Peter Donovan <[email protected]>
=
initializer syntax to replace the parens syntax in all targets except C++. This works exactly like parentheses do, except in C++ it calls the assignment operator.Updated 2023-03-02 This does in fact add a syntax for C array initializers (which can be used also for struct initializers). Summary:
a: int(0)
ora: int(0,0)
produces a warning (except in C++). they can be replaced witha: int = 0
resp.a: int = {0, 0}
(the latter only in C/C++).a(1,2)
, you can convert it toa = {= [1, 2] =}
to remove the warning, or just wait until we allow writinga = [1, 2]
directly.new R(a = 1)
instead ofnew R(a (1))
.new R(a = {= std::vector<int>(1,2) =}
or so (whereas you don't need to repeat the type when you write a default parameter value or a state var initializer). This is so because we would get problems with generic type parameters otherwise (and C++ itself has the same behavior).new R(a(1,2))
ornew R(a = (1,2))
to mean an array, then usenew R(a = {1, 2})
Remaining action items:
{}
needs to be escaped to not be omitted.Fixes #1650 and #1651