Giter VIP home page Giter VIP logo

Comments (17)

ffissore avatar ffissore commented on June 2, 2024

Thank you! I'll take a look at it in the next weeks. Can you tell if adding the prototype yourself works around the issues?

from arduino-builder.

ffissore avatar ffissore commented on June 2, 2024

Also, what would be the correct prototypes?

from arduino-builder.

Chris--A avatar Chris--A commented on June 2, 2024

Yes adding a prototype does prevent the incorrect generation. But without it, the errors are very confusing if you aren't expecting it.

Here is an example of the errors for 2 (simple function returning a function pointer)


sketch_oct08c:3: error: void value not ignored as it ought to be

   func()();

        ^

C:\Users\Chris\AppData\Local\Temp\arduino_cdba69ab332f1f472a84ede0e3d7b376\sketch_oct08c.ino: In function 'void (* func())()':

sketch_oct08c:8: error: new declaration 'void (* func())()'

 void (*func())(){

                ^

sketch_oct08c:4: error: ambiguates old declaration 'void func()'

 }

      ^

exit status 1
void value not ignored as it ought to be

from arduino-builder.

Chris--A avatar Chris--A commented on June 2, 2024

The prototypes are an exact copy, the functions are correct as written, just without the { & }

from arduino-builder.

matthijskooijman avatar matthijskooijman commented on June 2, 2024

Yes adding a prototype does prevent the incorrect generation. But without it, the errors are very confusing if you aren't expecting it.

I suspect that this is mostly because the line numbers are completely screwed up? I previously discussed an approach with Federico to generate a #line directive for every generated prototype, pointing to the original function definition, which should at least improve this.

from arduino-builder.

ffissore avatar ffissore commented on June 2, 2024

These are the outputs of ctags for 2, 3 and 4 https://gist.github.com/ffissore/625f6743e8f643311ad8
While it correctly identifies the function declaration, like in /^void (*func())(){$/;", it also tell that the function name is func. I use the function name for composing the prototype.
How much safe it is to say something like: if function declaration contains more than 1 nested parenthesis, use function declaration as prototype?

from arduino-builder.

ffissore avatar ffissore commented on June 2, 2024

note: func is not correct, it should be (*func())

from arduino-builder.

matthijskooijman avatar matthijskooijman commented on June 2, 2024

it also tell that the function name is func

That is ok, the function name is func. However, the return type is wrong - it's not void. And even if the return type was correctly parsed by ctags, the current "return type" + "name" + "signature" way of generating a prototype is not sufficient for the complicated types shown here.

How much safe it is to say something like: if function declaration contains more than 1 nested parenthesis, use function declaration as prototype?

I would not go there - AFAICS the function "declaration" is just the entire line, which might even contain a full function body (like loop(){} in these examples) or other stuff. At best, I would try to detect if a function is too complex for generating a prototype and then skip it.

One generic way would be to see if the original declaration matches the generated prototype. If so, you're probably good, if not, skip generating the prototype?

from arduino-builder.

ffissore avatar ffissore commented on June 2, 2024

I would not go there - AFAICS the function "declaration" is just the
entire line, which might even contain a full function body (like
|loop(){}| in these examples) or other stuff.

yes, indeed. I think it's best when limitations are known and an easy
workaround is available. like "don't put your function body on the same
line" or "provide the prototype yourself"

One generic way would be to see if the original declaration matches the
generated prototype. If so, you're probably good, if not, skip
generating the prototype?

if the prototype ALWAYS equal to its related function?

from arduino-builder.

matthijskooijman avatar matthijskooijman commented on June 2, 2024

if the prototype ALWAYS equal to its related function?

Note sure what you mean there?

What I mean is that for example, for:

setup ctags_target.cpp /^void setup(){$/;" kind:function line:2 signature:() returntype:void

the generated prototype (based on returntype, name and signature) is void setup();. If you take the actual function definition line (void setup(){) up to the first { (if any) and that matches (equals) the generated prototype, the prototype is likely ok and it should be output.

Looking at:

func ctags_target.cpp /^void (*func())(){$/;" kind:function line:8 signature:() returntype:void

the generated prototype is void func(), which does not match the actual line void (*func())(){, so no prototype should be output.

from arduino-builder.

ffissore avatar ffissore commented on June 2, 2024

This is what I came up with: https://github.com/arduino/arduino-builder/commits/functionpointer

from arduino-builder.

Chris--A avatar Chris--A commented on June 2, 2024

Also, this next one relates to #27 / arduino/ctags#1

The space is removed between typename and the nested name specifier.

I have added a PR here: arduino/ctags#3

template< typename T >
  struct Foo{
    typedef T Bar;
};

void setup() {
  func();
}

void loop() {}

typename Foo<char>::Bar func(){

}

from arduino-builder.

Chris--A avatar Chris--A commented on June 2, 2024

However the issue above is still not solved completely. The space should be fixed by the PR, however the template parameters are removed.

#include <Arduino.h>
#line 1
#line 1 "C:\\Users\\Chris\\AppData\\Local\\Temp\\arduino_38f0e5c3a68a41fc40766eb5fba8fc90\\sketch_oct08a.ino"

template< typename T >
  struct Foo{
    typedef T Bar;
};

void setup();
void loop();
typenameFoo::Bar func();
#line 7
void setup() {
  func();
}

void loop() {}

typename Foo<char>::Bar func(){

}

from arduino-builder.

matthijskooijman avatar matthijskooijman commented on June 2, 2024

I found another case that is still broken with the functionpointer branch:

static void function () {}

Which generates:

sketch_oct30a:6: error: 'void function()' was declared 'extern' and later 'static' [-fpermissive]

Because the new code does a "substring" test, the prototype (void function ()) is deemed ok (it's a substring of the code line), and the (erronous) prototype is generated. I'll have a look at fixing this in the way I think it should be in a minute.

from arduino-builder.

matthijskooijman avatar matthijskooijman commented on June 2, 2024

I added a commit to https://github.com/arduino/arduino-builder/commits/functionpointer that changes the matching to prefix matching instead of substring matching, which fixes the static function prototype. I tried doing full exact matching, by taking the code line up to the first {, if any, but that failed when a function definition was followed by a comment before the {. To prevent having to parse comments as well, I switched to prefix matching instead. Since, AFAICS, only function attribute can appear after a function's argument list (and it's not needed to specify those on both the definition and the prototype), I don't think this will generated any broken prototypes.

from arduino-builder.

ffissore avatar ffissore commented on June 2, 2024

Let's recap. @Chris--A all your cases are now handled and no wrong prototype is added. The IDE won't cast its magic on these sketches, not on all function at least, so the only way to compile them is to add prototypes yourself
As for static, it's been solved
Thank you all for your time and patience

from arduino-builder.

Chris--A avatar Chris--A commented on June 2, 2024

Nice, will pull & rebuild.

from arduino-builder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.