mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Handle pointer to the prototypes while converting "*.ino" to ".cpp" // Resolve #639
This commit is contained in:
@ -4,6 +4,12 @@ Release Notes
|
|||||||
PlatformIO 2.0
|
PlatformIO 2.0
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
2.9.1 (2016-04-??)
|
||||||
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
* Handle pointer to the prototypes while converting ``*.ino`` to ``.cpp``
|
||||||
|
(`issue #639 <https://github.com/platformio/platformio/issues/639>`_)
|
||||||
|
|
||||||
2.9.0 (2016-04-28)
|
2.9.0 (2016-04-28)
|
||||||
~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ class InoToCPPConverter(object):
|
|||||||
""",
|
""",
|
||||||
re.X | re.M | re.I
|
re.X | re.M | re.I
|
||||||
)
|
)
|
||||||
|
|
||||||
DETECTMAIN_RE = re.compile(r"void\s+(setup|loop)\s*\(", re.M | re.I)
|
DETECTMAIN_RE = re.compile(r"void\s+(setup|loop)\s*\(", re.M | re.I)
|
||||||
|
PROTOPTRS_TPLRE = r"\([^&\(]*&(%s)[^\)]*\)"
|
||||||
|
|
||||||
def __init__(self, nodes):
|
def __init__(self, nodes):
|
||||||
self.nodes = nodes
|
self.nodes = nodes
|
||||||
@ -50,22 +50,33 @@ class InoToCPPConverter(object):
|
|||||||
if (set([match.group(2).strip(), match.group(3).strip()]) &
|
if (set([match.group(2).strip(), match.group(3).strip()]) &
|
||||||
reserved_keywords):
|
reserved_keywords):
|
||||||
continue
|
continue
|
||||||
prototypes.append((file_path, match.start(), match.group(1)))
|
prototypes.append({"path": file_path, "match": match})
|
||||||
return prototypes
|
return prototypes
|
||||||
|
|
||||||
@staticmethod
|
def append_prototypes(self, contents, prototypes):
|
||||||
def append_prototypes(contents, prototypes):
|
|
||||||
result = []
|
result = []
|
||||||
if not prototypes:
|
if not prototypes:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
first_pos = prototypes[0][1]
|
split_pos = prototypes[0]['match'].start()
|
||||||
result.append(contents[:first_pos].strip())
|
prototype_names = set(
|
||||||
result.append("%s;" % ";\n".join([p[2] for p in prototypes]))
|
[p['match'].group(3).strip() for p in prototypes])
|
||||||
|
|
||||||
|
match_ptrs = re.search(
|
||||||
|
self.PROTOPTRS_TPLRE % ("|".join(prototype_names)),
|
||||||
|
contents[:split_pos],
|
||||||
|
re.M
|
||||||
|
)
|
||||||
|
if match_ptrs:
|
||||||
|
split_pos = contents.rfind("\n", 0, match_ptrs.start())
|
||||||
|
|
||||||
|
result.append(contents[:split_pos].strip())
|
||||||
|
result.append("%s;" %
|
||||||
|
";\n".join([p['match'].group(1) for p in prototypes]))
|
||||||
result.append('#line %d "%s"' % (
|
result.append('#line %d "%s"' % (
|
||||||
contents.count("\n", 0, first_pos + len(prototypes[0][2])) + 1,
|
contents.count("\n", 0, split_pos) + 2,
|
||||||
prototypes[0][0].replace("\\", "/")))
|
prototypes[0]['path'].replace("\\", "/")))
|
||||||
result.append(contents[first_pos:].strip())
|
result.append(contents[split_pos:].strip())
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user