mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Improve INO to CPP converter // Issue #639
This commit is contained in:
@ -53,14 +53,18 @@ class InoToCPPConverter(object):
|
|||||||
prototypes.append({"path": file_path, "match": match})
|
prototypes.append({"path": file_path, "match": match})
|
||||||
return prototypes
|
return prototypes
|
||||||
|
|
||||||
def append_prototypes(self, contents, prototypes):
|
def append_prototypes(self, file_path, contents, prototypes):
|
||||||
result = []
|
result = []
|
||||||
if not prototypes:
|
if not prototypes:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
split_pos = prototypes[0]['match'].start()
|
|
||||||
prototype_names = set(
|
prototype_names = set(
|
||||||
[p['match'].group(3).strip() for p in prototypes])
|
[p['match'].group(3).strip() for p in prototypes])
|
||||||
|
split_pos = prototypes[0]['match'].start()
|
||||||
|
for item in prototypes:
|
||||||
|
if item['path'] == file_path:
|
||||||
|
split_pos = item['match'].start()
|
||||||
|
break
|
||||||
|
|
||||||
match_ptrs = re.search(
|
match_ptrs = re.search(
|
||||||
self.PROTOPTRS_TPLRE % ("|".join(prototype_names)),
|
self.PROTOPTRS_TPLRE % ("|".join(prototype_names)),
|
||||||
@ -74,8 +78,7 @@ class InoToCPPConverter(object):
|
|||||||
result.append("%s;" %
|
result.append("%s;" %
|
||||||
";\n".join([p['match'].group(1) for p in prototypes]))
|
";\n".join([p['match'].group(1) for p in prototypes]))
|
||||||
result.append('#line %d "%s"' % (
|
result.append('#line %d "%s"' % (
|
||||||
contents.count("\n", 0, split_pos) + 2,
|
contents.count("\n", 0, split_pos) + 2, file_path))
|
||||||
prototypes[0]['path'].replace("\\", "/")))
|
|
||||||
result.append(contents[split_pos:].strip())
|
result.append(contents[split_pos:].strip())
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@ -102,7 +105,8 @@ class InoToCPPConverter(object):
|
|||||||
result.append('#line 1 "%s"' % file_path.replace("\\", "/"))
|
result.append('#line 1 "%s"' % file_path.replace("\\", "/"))
|
||||||
|
|
||||||
if is_first and prototypes:
|
if is_first and prototypes:
|
||||||
result += self.append_prototypes(contents, prototypes)
|
result += self.append_prototypes(
|
||||||
|
file_path, contents, prototypes)
|
||||||
else:
|
else:
|
||||||
result.append(contents)
|
result.append(contents)
|
||||||
is_first = False
|
is_first = False
|
||||||
|
Reference in New Issue
Block a user