forked from platformio/platformio-core
Fix INO to CPP converter when #define is used
This commit is contained in:
@@ -53,6 +53,7 @@ class InoToCPPConverter(object):
|
|||||||
return self.process(contents)
|
return self.process(contents)
|
||||||
|
|
||||||
def merge(self, nodes):
|
def merge(self, nodes):
|
||||||
|
assert nodes
|
||||||
lines = []
|
lines = []
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
contents = node.get_text_contents()
|
contents = node.get_text_contents()
|
||||||
@@ -65,6 +66,9 @@ class InoToCPPConverter(object):
|
|||||||
else:
|
else:
|
||||||
lines.extend(_lines)
|
lines.extend(_lines)
|
||||||
|
|
||||||
|
if not self._main_ino:
|
||||||
|
self._main_ino = nodes[0].get_path()
|
||||||
|
|
||||||
return "\n".join(["#include <Arduino.h>"] + lines) if lines else None
|
return "\n".join(["#include <Arduino.h>"] + lines) if lines else None
|
||||||
|
|
||||||
def process(self, contents):
|
def process(self, contents):
|
||||||
@@ -104,17 +108,20 @@ class InoToCPPConverter(object):
|
|||||||
|
|
||||||
if line.endswith("\\"):
|
if line.endswith("\\"):
|
||||||
if line.startswith('"'):
|
if line.startswith('"'):
|
||||||
newlines.append(line[:-1])
|
|
||||||
stropen = True
|
stropen = True
|
||||||
|
newlines.append(line[:-1])
|
||||||
|
continue
|
||||||
elif stropen:
|
elif stropen:
|
||||||
newlines[len(newlines) - 1] += line[:-1]
|
newlines[len(newlines) - 1] += line[:-1]
|
||||||
|
continue
|
||||||
elif stropen and line.endswith('";'):
|
elif stropen and line.endswith('";'):
|
||||||
newlines[len(newlines) - 1] += line
|
newlines[len(newlines) - 1] += line
|
||||||
stropen = False
|
stropen = False
|
||||||
newlines.append('#line %d "%s"' %
|
newlines.append('#line %d "%s"' %
|
||||||
(linenum, self._main_ino.replace("\\", "/")))
|
(linenum, self._main_ino.replace("\\", "/")))
|
||||||
else:
|
continue
|
||||||
newlines.append(line)
|
|
||||||
|
newlines.append(line)
|
||||||
|
|
||||||
return "\n".join(newlines)
|
return "\n".join(newlines)
|
||||||
|
|
||||||
|
@@ -1,3 +1,6 @@
|
|||||||
|
#define SQR(a) \
|
||||||
|
( a * a )
|
||||||
|
|
||||||
typedef struct Item item;
|
typedef struct Item item;
|
||||||
struct Item {
|
struct Item {
|
||||||
byte foo[50];
|
byte foo[50];
|
||||||
@@ -10,7 +13,7 @@ class Foo {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Foo(void (*function)()) {
|
Foo(void (*function)()) {
|
||||||
#warning "Line number is 13"
|
#warning "Line number is 16"
|
||||||
}
|
}
|
||||||
|
|
||||||
bool childFunc() {
|
bool childFunc() {
|
||||||
|
@@ -40,7 +40,7 @@ def test_warning_line(clirunner, validate_cliresult):
|
|||||||
result = clirunner.invoke(cmd_ci,
|
result = clirunner.invoke(cmd_ci,
|
||||||
[join(INOTEST_DIR, "basic"), "-b", "uno"])
|
[join(INOTEST_DIR, "basic"), "-b", "uno"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert ('basic.ino:13:14: warning: #warning "Line number is 13"' in
|
assert ('basic.ino:16:14: warning: #warning "Line number is 16"' in
|
||||||
result.output)
|
result.output)
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_ci, [join(INOTEST_DIR, "strmultilines"), "-b", "uno"])
|
cmd_ci, [join(INOTEST_DIR, "strmultilines"), "-b", "uno"])
|
||||||
|
Reference in New Issue
Block a user