-
-
Notifications
You must be signed in to change notification settings - Fork 114
IDE 1.6.6 breaks sketches that use multiline function declarations. #80
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
Comments
Sorry, that's a known limitation, caused by ctags, a tool used by arduino-builder. Until @cmaglie comes up with a clang based replacement, please write your functions on one line only |
This is a new limitation that has been created that is different from the prior issues, so at a minimum it should be documented as a known issue and included in the release notes with work arounds from now on until it is fixed. And it isn't that all functions must be declared on a single line. i.e.
is just fine. Also, if a sketch has function declarations above an include that defines types used for other functions declared lower in the module, then the prototypes for those lower functions will end up being inserted prior to the include for the header that defines the types used within the prototype.
In the above case, the prototype for bar() will be inserted above foo() but the problem is it uses types that are not yet known since the libheader.h include will be included below the prototype. It also appears that if you have a prototype for the very first function in your sketch, that no additional prototypes will be generated. There can still be other prototypes in the module, just not a prototype for the first function. The problem is that the current behavior creates somewhat unpredictable errors whose cause is invisible to a user that is looking at his original sketch code that used to work in prior IDE versions. The only way to know what really happened is to go down and locate the .cpp file which the average Arduino will not know how to do. So while the real issue can be tagged as a "worn't fix", it needs to at least create a documentation issue that puts this limitation as a known issue in the release notes along with possible work arounds. Alternatively, the sketch can declare a dummy function as the fist function to "trick" the auduino-builder to behave properly.
This same kind of goofy stuff was necessary in the older IDEs (but it looked for a variable) to create a proper insertion point for the Arduino.h header. Without that it corrupted your code by missinserting the include for that. All the rules/limitations should be documented with work arounds so that it doesn't continue to crop up as a reported bug. |
bperrybap ha scritto il 07/12/2015 alle 19:22:
All functions must be on one line, otherwise prototypes won't be generated
That's why usually #include are put at the top of the sketch. If you
/cc @cmaglie
That's because all functions must be on one line
Arduino.h is now included at the top of the file, at its first line |
All function declarations do not not need to be on one line in order to get function prototypes. The issue is a regression of the prototype list insertion point. If there is no other better/smarter work around for handling the prototype list insertion point in the IDE/arduino-builder code, I did some additional testing to verify the actual limitations in 1.6.6 With the current parsing & insertion logic in 1.6.6, the only function that must have its return value on the same line as the function name is the first function of the sketch. Here is an example that shows how declarations do not need to be on one line but the first function must at least have its return value and function name on the same line.
If you look at the .cpp file generated by IDE 1.6.6, all the prototypes are correct and everything works. Interestingly, 1.6.6. creates a single line prototype while older IDEs will create the prototype the same way the function was declared. My view is that all s/w releases should have a list of "known issues", particularly for a project as large as Arduino. In this case it would be helpful because there is situation where code that used to work on the older IDEs no longer builds on 1.6.6 and it takes a bit of poking around to figure out why and how to work around the issue since the issue/error is unrelated to the actual users source code but is a case of the IDE silently misparsing the users source code. It is actually a bit surprising to me that a project as large as Arduino doesn't have a known issues section in the release notes. There seems to be hundreds of these types of little "gotchyas" in arduino and those that have been using it and playing with for quite some time are familiar with them. (There are many things that I have had to work around over the years and still continue to work around) |
Thank you @bperrybap for your detailed description. I'm sure @cmaglie will find a way to communicate these issues/gotchas better than we do now. The whole point of arduino-builder was to remove those gotchas (take a look at the number of closed issues related to preprocessing). However, it relies on ctags for listing functions and ctags fails to understand at which line a function starts when its return type is on a line of its own @cmaglie is working on a drop-in replacement of ctags. This will also help solving #68 |
Although I think I have a sense of what he is up to (clang lib I imagine), I hope for the community that there was a good planing of this solution. At the risk of sounding naive, despite plenty of time the simple java-regex-based Compiler.java could not be stabilized enough to address the long list of known issues, and the recent 2 months writing of what was going to be THE solution landed with this and other similarly still not addressed issues (this issue cannot be a surprise considering how long ctags has been around). In the meantime, a large number of issues are pilling up in the main tracker, some of them for years. This for a small example of mis-appreciation of the seriousness of the situation, and there are plenty of bigger ones. The team has plenty of courage to tackle problems, but is it possible that it might be beneficial to review how issues are evaluated and prioritized?! |
works around issue arduino/arduino-builder#80
I'm not convinced the problem is ctags. With this code - https://gist.github.com/focalintent/9cb049195962b677b375 - the hourly build from a few hours ago fails to compile and make prototypes. However, here's the end of the output from the ctags command (which I copied out of the ide and ran from the command line):
ctags is correctly pulling out the name, kind, signature, and return type for all the functions in the ino file. However, the arduino ide is failing to create prototypes for functions second and third. edited Ran arduino-builder with debug output - it's because the regex for the function and the given prototype aren't matching up (or the code responsible for deciding whether or not to skip a tag is too restrictive):
ctags is capable of parsing out all the parameters to the function, as evidenced by the signature coming out of ctags being correct. |
…at the code for a tag is multiline (that is, there's no closing paren), use the Filename/Line info in the tag to attempt to read a few lines from the original code to hopefully get a better block of code to look for the prototype in.
…at the code for a tag is multiline (that is, there's no closing paren), use the Filename/Line info in the tag to attempt to read a few lines from the original code to hopefully get a better block of code to look for the prototype in.
… file A somewhat heavy handed way to deal with #80 - if we detect that the code for a tag is multiline (that is, there's no closing paren), use the Filename/Line info in the tag to attempt to read a few lines from the original code to hopefully get a better block of code to look for the prototype in.
@per1234, is that update in 1.6.8? I just tried 1.6.8 with the example below and it still fails:
|
@bperrybap no it's in the hourly build but that code still doesn't compile. I had only tested your first example:
Which does compile now but I notice it started working in 1.6.7 so that's unrelated to fbfaa56, which I'm guessing is what fixed arduino/Arduino#4843. So I was wrong and this issue was not fixed by fbfaa56. Sorry about that. Per |
@bperrybap and @per1234 , I just checked with the provided sketch and indeed the issue is not solved in nightly. |
Had to flip whole structure upside down because this piece of ****: arduino/arduino-builder#68 arduino/arduino-builder#80 arduino/arduino-builder#85 and countless other issue tickets, arduino builder preprocessor fails to do prototype and can't reorder functions so everything must be just in the right order (and also breaks many libraries and other third party boards). Code may not compile properly as long as arduino developpers can't get their **** together. Wifi part won't work until underlying issue in arduino-builder gets fixed or old version of arduino ide is used or something is gludged to overcome these issues.
Will be fixed by merging #182 |
From @bperrybap on December 6, 2015 23:43
The latest 1.6.6 IDE breaks sketches that use to and still should compile.
The issue is that the IDE is incorrectly inserting its prototypes when it converts the sketch to a .cpp file.
It appears that it is looking for first line of the first function and then attempting to insert the prototypes on the line just above it.
When the function declaration is not all on a single line, because the return type is on a line above the reset of the declaration, the IDE inserts the sketch function prototypes below the return type of the function declaration which causes the code to no longer compile.
This has broken many of my sketches and has broken some of my openGLCD library example sketches.
While the code in my sketches and library are much more complex and do not involved the setup() or loop() functions, here is a minimal example that demonstrates the problem.
If you go look at the .cpp file generated, you can see the problem:
Notice that the prototypes were inserted below the return type of the first function.
Curiously, it does manage to locate the and generate the correct prototype even if there are multiple whitespace lines between the return type and the reset of the function declaration or even if the rest of the declaration is on multiple lines like say the function name, parens, or arguments are on different/multiple lines.
The issue seems to be it is inserting the prototypes just above the line that contains the function name rather than just above the line that contains the return type.
Copied from original issue: arduino/Arduino#4265
The text was updated successfully, but these errors were encountered: