arduino / arduino-preprocessor

Parses an Arduino Sketch and converts it into valid C++ source code
49 stars 13 forks source link

Including FastLED library breaks prototype generation #3

Open per1234 opened 6 years ago

per1234 commented 6 years ago

Using Arduino IDE Beta build 25 with Windows 7 64 bit

sketch_nov21a:5: error: 'foo' was not declared in this scope

void loop() {}

   ^


arduino-preprocessor `-debug` output:
https://gist.githubusercontent.com/per1234/e2e45e7b84de756ae1782178790c5830/raw/ecdd542f40c951ca8b93f9a585ee72366f6fcfaa/sketch_nov21a.ino.cpp

Examination of the generated .ino.cpp file shows that the `foo()` prototype was never generated, rather than being inserted in the wrong place.

The issue does not occur in Arduino IDE 1.8.5.

Originally reported at: http://forum.arduino.cc/index.php?topic=512898
facchinm commented 6 years ago

Hi @per1234 , thanks for spotting this; in fact, the libclang backend is failing to analyze a part of the library (it looks like it's the AVR specific macros, incidentally the ones making FastLed magic happen ) and thus it doesn't generate the prototypes. I can think about a couple of solutions (maybe @cmaglie has some other):

Anyway, comping on ARM works as expected, so we can use it as a reference. The error thrown (with --output-diagnostic) is

terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct null not valid
Aborted (core dumped)
LEKPHET-KUNSUE commented 7 months ago

in fact solve it with this code block

#include <FastLED.h>
void foo();
void setup() {
  foo();
}
void loop() {}
void foo() {}
LEKPHET-KUNSUE commented 7 months ago

try it.