Last active
July 30, 2020 10:22
-
-
Save l2m2/3b11b342490d3a72f7d0de49dcf7aa2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, glob, re | |
module = 'xxx' | |
fixup = r""" | |
/*! | |
* \class {cls} | |
* \inmodule {module} | |
*/ | |
""" | |
def gen(path): | |
cpps = [y for x in os.walk(path) for y in glob.glob(os.path.join(x[0], '*.cpp'))] | |
for cpp in cpps: | |
with open(cpp, 'r+', encoding = 'utf-8-sig') as fd: | |
code = fd.read() | |
if re.search("thread.cpp$", cpp): continue | |
if not r"\class" in code: | |
lines = code.splitlines() | |
pos = next(i for i,v in enumerate(lines) if v != '' and not re.search("^#include", v)) | |
classes = set([ re.match(r'^(\w+)::(\1)', line).group(1) for line in lines if re.search(r'^(\w+)::(\1)', line) ]) | |
if len(classes) == 0: continue | |
print(cpp, classes) | |
for cls in classes: | |
temp = fixup.format(cls=cls, module=module) | |
lines[pos:pos] = temp.splitlines() | |
fd.seek(0) | |
fd.truncate() | |
fd.write('\n'.join(lines)) | |
if __name__ == "__main__": | |
gen(r"F:\workspace\xxx\src") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment