From d7e2d05f60fb2c10770eb6d0c364d84c3d5cc5d4 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 20 Mar 2019 18:49:20 +0200 Subject: [PATCH] Fix error with conflicting declaration of a prototype (Arduino sketch preprocessor) --- HISTORY.rst | 1 + platformio/builder/tools/piomisc.py | 13 ++++++++++--- tests/ino2cpp/basic/basic.ino | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 32e2aa8d..f59d36aa 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,6 +7,7 @@ PlatformIO 3.0 3.6.6 (2019-??-??) ~~~~~~~~~~~~~~~~~~ +* Fixed error with conflicting declaration of a prototype (Arduino sketch preprocessor) * Fixed "FileExistsError" when `platformio ci `__ command is used in pair with ``--keep-build-dir`` option 3.6.5 (2019-03-07) diff --git a/platformio/builder/tools/piomisc.py b/platformio/builder/tools/piomisc.py index be030f39..c2173bd2 100644 --- a/platformio/builder/tools/piomisc.py +++ b/platformio/builder/tools/piomisc.py @@ -33,10 +33,10 @@ class InoToCPPConverter(object): PROTOTYPE_RE = re.compile( r"""^( (?:template\<.*\>\s*)? # template - ([a-z_\d\&]+\*?\s+){1,2} # return type + ([a-z_\d\&]+\*?\s+){1,2} # return type ([a-z_\d]+\s*) # name of prototype \([a-z_,\.\*\&\[\]\s\d]*\) # arguments - )\s*\{ # must end with { + )\s*(\{|;) # must end with `{` or `;` """, re.X | re.M | re.I) DETECTMAIN_RE = re.compile(r"void\s+(setup|loop)\s*\(", re.M | re.I) PROTOPTRS_TPLRE = r"\([^&\(]*&(%s)[^\)]*\)" @@ -162,7 +162,14 @@ class InoToCPPConverter(object): if not prototypes: return contents - prototype_names = set([m.group(3).strip() for m in prototypes]) + # skip already declared prototypes + declared = set( + m.group(1).strip() for m in prototypes if m.group(4) == ";") + prototypes = [ + m for m in prototypes if m.group(1).strip() not in declared + ] + + prototype_names = set(m.group(3).strip() for m in prototypes) split_pos = prototypes[0].start() match_ptrs = re.search( self.PROTOPTRS_TPLRE % ("|".join(prototype_names)), diff --git a/tests/ino2cpp/basic/basic.ino b/tests/ino2cpp/basic/basic.ino index 0c5d7511..fcec8edd 100644 --- a/tests/ino2cpp/basic/basic.ino +++ b/tests/ino2cpp/basic/basic.ino @@ -49,4 +49,12 @@ void fooCallback(){ } +extern "C" { +void some_extern(const char *fmt, ...); +}; + +void some_extern(const char *fmt, ...) { + +} + // юнікод