-
-
Notifications
You must be signed in to change notification settings - Fork 114
Auto prototype generation with function as argument to class instantiation #50
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
The prototype for the ctags output:
Preprocessed file:
|
Yes indeed that's the source of the problem. I'm working on it. I've chatted with @facchinm and he told me that I can look at ctags "code" section and if it contains a "&" + one of the collected function names I can consider that a function pointer and use that line instead of "setup" one |
I kind of thought that might be the case, the user will just have to declare the prototype but I decided I'd at least report it so that you can put it on the list.
I probably don't understand correctly but just in case this is any help, here's another sketch that was reported as being broken by 1.6.6, in this case they didn't use & before the function argument: #include <TimedAction.h>
TimedAction timedAction = TimedAction(1000, blink);
void setup(){
timedAction.enable();
}
void loop(){
timedAction.check();
}
void blink(){
// do stuff
} That is using http://playground.arduino.cc/Code/TimedAction |
Thank you @per1234 indeed that one won't work with that hack |
…ototypes are written above that line. Mitigates #50 Signed-off-by: Federico Fissore <[email protected]>
First type of function used as callback now works. Fix available with hourly builds. Second type however will NOT work. The only way to make it work is understanding that "blink" is a function pointer, which means having an Abstract Syntax Tree and/or C++ parser, which we don't have |
- added --line-directives to ctags command line: makes "line" fields aware of #line directives (thanks @matthijskooijman for the hint) - prototypes get generated after ctags are produced for both gcc -E output and original sketch. This allows to consider functions used in callbacks. See #50 - each prototype is preceded by #line directives that points to its function. This allows error in function declarations themselves to be properly reported to the IDE - split ctags target files (added "ctags_target_for_gcc_minus_e.cpp") for easier debugging Signed-off-by: Federico Fissore <[email protected]>
Using Arduino IDE 1.6.7 2015/11/10 12:55
CallbackBug.h
Error:
This causes example sketches in the TaskScheduler library to not compile. |
I think you need to remove the |
@NicoHood, that's not the case, the problem here is wrong ordering of prototypes, not the code itself. For functions, |
@ffissore I just wanted to make sure the issue I reported in my last comment didn't slip through the cracks. Is it a wontfix? |
@matthijskooijman I never managed to get an answer regarding the issue I reported in my previous comment. Is it wontfix/invalid, should this issue be reopened, or should I create a new issue for it? PS: I apologize if you're the wrong person to tag on this. I don't know who is responsible for it now that ffissore is gone and you are already somewhat familiar with the issue. |
@per1234 No problem tagging me. I probably won't fix it, but I can at least have a look :-) It seems that using The latter case probably has an empty For now, I'd say it's a wontfix, but hopefully we can improve the prototype generation at some point by doing proper parsing of the source (e.g. using clang) and cases like this one can be properly handled. @cmaglie, I wonder if it would make sense to add a collection of testcases like these (and probably also testcases that do compile) to the arduino-builder test-suite? The tester could then just verify that each testcase does or does not compile, without having to check the exact output of the compilation (which makes it easier to maintain the testcases. |
Yes, I've exactly this testcase almost ready in my local repo, I've to refine some details. |
@per1234 @ffissore Please reopen this issue. If I'm reading correctly, it's not fixed and any library that uses functions either as callbacks or protothreads (the popular pubsub MQTT library and TimedAction.h protothreading library are two examples), now requires their function definitions be in the proper order as to not have the prototypes created out-of-order and thus cause scope issues. I believe the previous commenters have provided good test cases for this and they were not all fixed correctly. If you need further details I can provide them, but without this fixed, (a) code prior to 1.6.6 will not compile in these instances due to undeclared functions / scope issues, Really surprised this has continued this long without being reopened and fixed properly after breaking sketches and causing hassle for tons of libraries. |
C is most important to me personally, as this quickly becomes both messy and a nightmare:
|
@ReanimationXP Sorry you missed the news, but I no longer work for arduino https://groups.google.com/a/arduino.cc/forum/#!msg/developers/RTdVlpcUTSo/KqCHTgZRCAAJ |
@ReanimationXP, it's not that we disagree that this is a problem, but it is pretty much impossible to fix with the current ctags-based approach. If we switch to full parsing (e.g. using clang, which is something that is being explored), this usecase will certainly be fixed. However, to reduce clutter in the list of open issues, I'd rather leave this issue closed. |
I'm confused as to what would take priority over something that is effectively a code-breaking compiler change It's been a year and change already. |
I'm not sure if I can explain this properly quickly, but I believe that this particular change is caused by changes to the preprocessing, which improves compilation for a lot of sketches, but makes it worse for a few, such as this one. So it's not a matter of fixing a bug that was introduced, there's some tradeoffs involved because the current preprocessing isn't ideal. |
It seems like there are a lot of what ifs and the issue isn't being reopened. It'd be nice to at least have the discussion and weigh the pros and cons, particularly what were we fixing/improving before by moving to a different compilation method, what did we gain, and if it wasn't significant enough to warrant breaking code, is reversing this change possible? The benefits the change brought about may not justify the means. I believe this is causing an issue for enough people that it should at least be open. |
Using Arduino IDE 1.6.7 2015/11/07 12:42 with Windows 7 64 bit
I apologize if my terminology is off on the issue title, this is what I'm referring to:
CallbackBug.h:
Compiling gives the error:
If I declare the function prototype for t1Callback() it compiles fine.
The code compiles fine with Arduino IDE 1.6.5r5
Example of a library where this breaks the examples: https://github.com/arkhipenko/TaskScheduler
Originally reported at: http://forum.arduino.cc/index.php?topic=357312.msg2468586#msg2468586
The text was updated successfully, but these errors were encountered: