aboutsummaryrefslogtreecommitdiff
path: root/scripts/stripdecls.py
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2019-07-30 07:32:47 +0200
committerGitHub <noreply@github.com>2019-07-30 07:32:47 +0200
commit35ec60f73a5d9f1ad9393bb1f645c624e67fdb26 (patch)
treecdab39bdae9398dab95927303b179250d644dd03 /scripts/stripdecls.py
parentbae02eb3968be1c9677283d030fbbe6dd02cb180 (diff)
parentd651710de1e5627d602d9ca05a902e198d031571 (diff)
downloadrneovim-35ec60f73a5d9f1ad9393bb1f645c624e67fdb26.tar.gz
rneovim-35ec60f73a5d9f1ad9393bb1f645c624e67fdb26.tar.bz2
rneovim-35ec60f73a5d9f1ad9393bb1f645c624e67fdb26.zip
Merge pull request #10648 from blueyed/autopep8
ci: py: flake8 fixes
Diffstat (limited to 'scripts/stripdecls.py')
-rwxr-xr-xscripts/stripdecls.py233
1 files changed, 117 insertions, 116 deletions
diff --git a/scripts/stripdecls.py b/scripts/stripdecls.py
index a73b1980cb..b4ac34dcfe 100755
--- a/scripts/stripdecls.py
+++ b/scripts/stripdecls.py
@@ -10,7 +10,7 @@ import os
DECL_KINDS = {
- CursorKind.FUNCTION_DECL,
+ CursorKind.FUNCTION_DECL,
}
@@ -18,122 +18,123 @@ Strip = namedtuple('Strip', 'start_line start_column end_line end_column')
def main(progname, cfname, only_static, move_all):
- cfname = os.path.abspath(os.path.normpath(cfname))
-
- hfname1 = os.path.splitext(cfname)[0] + os.extsep + 'h'
- hfname2 = os.path.splitext(cfname)[0] + '_defs' + os.extsep + 'h'
-
- files_to_modify = (cfname, hfname1, hfname2)
-
- index = Index.create()
- src_dirname = os.path.join(os.path.dirname(__file__), '..', 'src')
- src_dirname = os.path.abspath(os.path.normpath(src_dirname))
- relname = os.path.join(src_dirname, 'nvim')
- unit = index.parse(cfname, args=('-I' + src_dirname,
- '-DUNIX',
- '-DEXITFREE',
- '-DFEAT_USR_CMDS',
- '-DFEAT_CMDL_COMPL',
- '-DFEAT_COMPL_FUNC',
- '-DPROTO',
- '-DUSE_MCH_ERRMSG'))
- cursor = unit.cursor
-
- tostrip = defaultdict(OrderedDict)
- definitions = set()
-
- for child in cursor.get_children():
- if not (child.location and child.location.file):
- continue
- fname = os.path.abspath(os.path.normpath(child.location.file.name))
- if fname not in files_to_modify:
- continue
- if child.kind not in DECL_KINDS:
- continue
- if only_static and next(child.get_tokens()).spelling == 'static':
- continue
-
- if child.is_definition() and fname == cfname:
- definitions.add(child.spelling)
- else:
- stripdict = tostrip[fname]
- assert(child.spelling not in stripdict)
- stripdict[child.spelling] = Strip(
- child.extent.start.line,
- child.extent.start.column,
- child.extent.end.line,
- child.extent.end.column,
- )
-
- for (fname, stripdict) in tostrip.items():
- if not move_all:
- for name in set(stripdict) - definitions:
- stripdict.pop(name)
-
- if not stripdict:
- continue
-
- if fname.endswith('.h'):
- is_h_file = True
- include_line = next(reversed(stripdict.values())).start_line + 1
- else:
- is_h_file = False
- include_line = next(iter(stripdict.values())).start_line
-
- lines = None
- generated_existed = os.path.exists(fname + '.generated.h')
- with open(fname, 'rb') as F:
- lines = list(F)
-
- stripped = []
-
- for name, position in reversed(stripdict.items()):
- sl = slice(position.start_line - 1, position.end_line)
- if is_h_file:
- include_line -= sl.stop - sl.start
- stripped += lines[sl]
- lines[sl] = ()
+ cfname = os.path.abspath(os.path.normpath(cfname))
+
+ hfname1 = os.path.splitext(cfname)[0] + os.extsep + 'h'
+ hfname2 = os.path.splitext(cfname)[0] + '_defs' + os.extsep + 'h'
+
+ files_to_modify = (cfname, hfname1, hfname2)
+
+ index = Index.create()
+ src_dirname = os.path.join(os.path.dirname(__file__), '..', 'src')
+ src_dirname = os.path.abspath(os.path.normpath(src_dirname))
+ relname = os.path.join(src_dirname, 'nvim')
+ unit = index.parse(cfname, args=('-I' + src_dirname,
+ '-DUNIX',
+ '-DEXITFREE',
+ '-DFEAT_USR_CMDS',
+ '-DFEAT_CMDL_COMPL',
+ '-DFEAT_COMPL_FUNC',
+ '-DPROTO',
+ '-DUSE_MCH_ERRMSG'))
+ cursor = unit.cursor
+
+ tostrip = defaultdict(OrderedDict)
+ definitions = set()
+
+ for child in cursor.get_children():
+ if not (child.location and child.location.file):
+ continue
+ fname = os.path.abspath(os.path.normpath(child.location.file.name))
+ if fname not in files_to_modify:
+ continue
+ if child.kind not in DECL_KINDS:
+ continue
+ if only_static and next(child.get_tokens()).spelling == 'static':
+ continue
+
+ if child.is_definition() and fname == cfname:
+ definitions.add(child.spelling)
+ else:
+ stripdict = tostrip[fname]
+ assert(child.spelling not in stripdict)
+ stripdict[child.spelling] = Strip(
+ child.extent.start.line,
+ child.extent.start.column,
+ child.extent.end.line,
+ child.extent.end.column,
+ )
+
+ for (fname, stripdict) in tostrip.items():
+ if not move_all:
+ for name in set(stripdict) - definitions:
+ stripdict.pop(name)
+
+ if not stripdict:
+ continue
+
+ if fname.endswith('.h'):
+ is_h_file = True
+ include_line = next(reversed(stripdict.values())).start_line + 1
+ else:
+ is_h_file = False
+ include_line = next(iter(stripdict.values())).start_line
+
+ lines = None
+ generated_existed = os.path.exists(fname + '.generated.h')
+ with open(fname, 'rb') as F:
+ lines = list(F)
+
+ stripped = []
+
+ for name, position in reversed(stripdict.items()):
+ sl = slice(position.start_line - 1, position.end_line)
+ if is_h_file:
+ include_line -= sl.stop - sl.start
+ stripped += lines[sl]
+ lines[sl] = ()
+
+ if not generated_existed:
+ lines[include_line:include_line] = [
+ '#ifdef INCLUDE_GENERATED_DECLARATIONS\n',
+ '# include "{0}.generated.h"\n'.format(
+ os.path.relpath(fname, relname)),
+ '#endif\n',
+ ]
+
+ with open(fname, 'wb') as F:
+ F.writelines(lines)
- if not generated_existed:
- lines[include_line:include_line] = [
- '#ifdef INCLUDE_GENERATED_DECLARATIONS\n',
- '# include "{0}.generated.h"\n'.format(os.path.relpath(fname, relname)),
- '#endif\n',
- ]
- with open(fname, 'wb') as F:
- F.writelines(lines)
+if __name__ == '__main__':
+ progname = sys.argv[0]
+ args = sys.argv[1:]
+ if not args or '--help' in args:
+ print('Usage:')
+ print('')
+ print(' {0} [--static [--all]] file.c...'.format(progname))
+ print('')
+ print('Stripts all declarations from file.c, file.h and file_defs.h.')
+ print('If --static argument is given then only static declarations are')
+ print('stripped. Declarations are stripped only if corresponding')
+ print('definition is found unless --all argument was given.')
+ print('')
+ print('Note: it is assumed that static declarations starts with "static"')
+ print(' keyword.')
+ sys.exit(0 if args else 1)
+
+ if args[0] == '--static':
+ only_static = True
+ args = args[1:]
+ else:
+ only_static = False
+ if args[0] == '--all':
+ move_all = True
+ args = args[1:]
+ else:
+ move_all = False
-if __name__ == '__main__':
- progname = sys.argv[0]
- args = sys.argv[1:]
- if not args or '--help' in args:
- print('Usage:')
- print('')
- print(' {0} [--static [--all]] file.c...'.format(progname))
- print('')
- print('Stripts all declarations from file.c, file.h and file_defs.h.')
- print('If --static argument is given then only static declarations are')
- print('stripped. Declarations are stripped only if corresponding')
- print('definition is found unless --all argument was given.')
- print('')
- print('Note: it is assumed that static declarations starts with "static"')
- print(' keyword.')
- sys.exit(0 if args else 1)
-
- if args[0] == '--static':
- only_static = True
- args = args[1:]
- else:
- only_static = False
-
- if args[0] == '--all':
- move_all = True
- args = args[1:]
- else:
- move_all = False
-
- for cfname in args:
- print('Processing {0}'.format(cfname))
- main(progname, cfname, only_static, move_all)
+ for cfname in args:
+ print('Processing {0}'.format(cfname))
+ main(progname, cfname, only_static, move_all)