def contents_as_module_without_require(lib, other_imports, export=False, **kwargs): import_all_directories = not absolutize_has_all_constants( kwargs['absolutize']) if import_all_directories and not export: transform_base = lambda x: (escape_lib(x) + '.' + x if is_local_import(x, **kwargs) else x) else: transform_base = lambda x: x v_name = filename_of_lib(lib, ext='.v', **kwargs) contents = get_file(v_name, transform_base=transform_base, **kwargs) contents = strip_requires(contents) if kwargs['verbose'] > 2: kwargs['log'](contents) module_name = escape_lib(lib) # import the top-level wrappers if len(other_imports) > 0 and not export: # we need to import the contents in the correct order. Namely, if we have a module whose name is also the name of a directory (in the same folder), we want to import the file first. for imp in reversed( construct_import_list( other_imports, import_all_directories=import_all_directories)): contents = 'Import %s.\n%s' % (imp, contents) # wrap the contents in directory modules lib_parts = list(map(escape_lib, lib.split('.'))) maybe_export = 'Export ' if export else '' contents = 'Module %s.\n%s\nEnd %s.\n' % (lib_parts[-1], contents, lib_parts[-1]) for name in reversed(lib_parts[:-1]): contents = 'Module %s%s.\n%s\nEnd %s.\n' % ( maybe_export, name, contents, name) # or Module Export? contents = 'Module %s%s.\n%s\nEnd %s.\n' % (maybe_export, module_name, contents, module_name) return contents
def contents_without_imports(lib, **kwargs): v_file = filename_of_lib(lib, ext='.v', **kwargs) contents = get_file(v_file, **kwargs) if '(*' in ' '.join(IMPORT_LINE_REG.findall(contents)): print( 'Warning: There are comments in your Require/Import/Export lines in %s.' % v_file) return IMPORT_LINE_REG.sub('', contents)
def absolutize_imports(infile, **kwargs): filename = infile.name if kwargs['verbose']: kwargs['log']('Processing %s...' % filename) absolutized_contents = get_file(filename, update_globs=True, **kwargs) infile.close() if kwargs['inplace']: do_backup = kwargs['suffix'] is not None and len(kwargs['suffix']) > 0 write_to_file(filename, absolutized_contents, do_backup=do_backup, backup_ext=kwargs['suffix']) else: print(absolutized_contents)
def absolutize_imports(filename, **kwargs): if kwargs['verbose']: kwargs['log']('Processing %s...' % filename) absolutized_contents = get_file(filename, update_globs=True, **kwargs) if kwargs['inplace']: do_backup = kwargs['suffix'] is not None and len(kwargs['suffix']) > 0 write_to_file(filename, absolutized_contents, do_backup=do_backup, backup_ext=kwargs['suffix']) else: print(absolutized_contents)
def normalize_requires(filename, **kwargs): """Return the contents of filename, with all [Require]s split out and ordered at the top.""" if filename[-2:] != '.v': filename += '.v' kwargs = fill_kwargs(kwargs) lib = lib_of_filename(filename, libnames=tuple(kwargs['libnames'])) all_imports = run_recursively_get_imports(lib, **kwargs) v_name = filename_of_lib(lib, ext='.v', **kwargs) contents = get_file(v_name, **kwargs) contents = strip_requires(contents) contents = ''.join('Require %s.\n' % i for i in all_imports[:-1]) + '\n' + contents.strip() + '\n' return contents
def normalize_requires(filename, **kwargs): """Return the contents of filename, with all [Require]s split out and ordered at the top. Preserve any leading whitespace/comments. """ if filename[-2:] != '.v': filename += '.v' kwargs = fill_kwargs(kwargs) lib = lib_of_filename(filename, **kwargs) all_imports = run_recursively_get_imports(lib, **kwargs) v_name = filename_of_lib(lib, ext='.v', **kwargs) contents = get_file(v_name, **kwargs) header, contents = split_leading_comments_and_whitespace(contents) contents = strip_requires(contents) contents = ''.join('Require %s.\n' % i for i in all_imports[:-1]) + '\n' + contents.strip() + '\n' return header + contents
def contents_as_module_without_require(lib, other_imports, export=False, **kwargs): import_all_directories = not absolutize_has_all_constants(kwargs['absolutize']) if import_all_directories and not export: transform_base = lambda x: (escape_lib(x) + '.' + x if is_local_import(x, **kwargs) else x) else: transform_base = lambda x: x v_name = filename_of_lib(lib, ext='.v', **kwargs) contents = get_file(v_name, transform_base=transform_base, **kwargs) contents = strip_requires(contents) if kwargs['verbose'] > 2: kwargs['log'](contents) module_name = escape_lib(lib) # import the top-level wrappers if len(other_imports) > 0 and not export: # we need to import the contents in the correct order. Namely, if we have a module whose name is also the name of a directory (in the same folder), we want to import the file first. for imp in reversed(construct_import_list(other_imports, import_all_directories=import_all_directories)): contents = 'Import %s.\n%s' % (imp, contents) # wrap the contents in directory modules lib_parts = list(map(escape_lib, lib.split('.'))) maybe_export = 'Export ' if export else '' contents = 'Module %s.\n%s\nEnd %s.\n' % (lib_parts[-1], contents, lib_parts[-1]) for name in reversed(lib_parts[:-1]): contents = 'Module %s%s.\n%s\nEnd %s.\n' % (maybe_export, name, contents, name) # or Module Export? contents = 'Module %s%s.\n%s\nEnd %s.\n' % (maybe_export, module_name, contents, module_name) return contents
def contents_without_imports(lib, **kwargs): v_file = filename_of_lib(lib, ext='.v', **kwargs) contents = get_file(v_file, **kwargs) if '(*' in ' '.join(IMPORT_LINE_REG.findall(contents)): print('Warning: There are comments in your Require/Import/Export lines in %s.' % filename) return IMPORT_LINE_REG.sub('', contents)
list(env['coqc_args']) + ['-Q', dirname, libname]) for dirname in env['ocaml_dirnames']: env['coqc_args'] = tuple(list(env['coqc_args']) + ['-I', dirname]) env['input_files'] = sort_files_by_dependency(env['input_files'], update_globs=True, **env) try: failed = [] for name in env['input_files']: try: ranges = get_coq_statement_ranges(name, **env) contents = get_file( name, absolutize=(('lib', ) if args.absolutize else tuple()), update_globs=True, **env) refs = get_references_for(name, types=('lib', ), update_globs=True, **env) if refs is None: env['log']('ERROR: Failed to get references for %s' % name) failed.append((name, 'failed to get references')) if env['keep_going']: continue else: break annotated_contents = mark_exports( insert_references(contents, ranges, refs, **env),
for dirname, libname in env['libnames']: env['coqc_args'] = tuple(list(env['coqc_args']) + ['-R', dirname, libname]) for dirname, libname in env['non_recursive_libnames']: env['coqc_args'] = tuple(list(env['coqc_args']) + ['-Q', dirname, libname]) for dirname in env['ocaml_dirnames']: env['coqc_args'] = tuple(list(env['coqc_args']) + ['-I', dirname]) env['input_files'] = sort_files_by_dependency(env['input_files'], update_globs=True, **env) try: failed = [] for name in env['input_files']: try: ranges = get_coq_statement_ranges(name, **env) contents = get_file(name, absolutize=tuple(), update_globs=True, **env) refs = get_references_for(name, types=('lib',), update_globs=True, **env) if refs is None: env['log']('ERROR: Failed to get references for %s' % name) failed.append((name, 'failed to get references')) if env['keep_going']: continue else: break annotated_contents = mark_exports(insert_references(contents, ranges, refs, **env), env['keep_exports']) save_state = make_save_state(name, **env) check_state = make_check_state(contents, **env) verbose_check_state = make_check_state(contents, verbose_base=4-env['verbose'], **env) if env['verbose']: env['log']('Running coq on initial contents...') if not verbose_check_state(annotated_contents): env['log']('ERROR: Failed to update %s' % name)
'inplace': args.suffix != '', # it's None if they passed no argument, and '' if they didn't pass -i 'suffix': args.suffix, } update_env_with_libnames(env, args) for dirname, libname in env['libnames']: env['coqc_args'] = tuple(list(env['coqc_args']) + ['-R', dirname, libname]) try: failed = [] for input_file in args.input_files: name = input_file.name input_file.close() try: ranges = get_coq_statement_ranges(name, **env) contents = get_file(name, absolutize=tuple(), update_globs=True, **env) refs = get_references_for(name, types=('lib',), update_globs=True, **env) if refs is None: env['log']('ERROR: Failed to get references for %s' % name) failed.append((name, 'failed to get references')) if env['keep_going']: continue else: break annotated_contents = mark_exports(insert_references(contents, ranges, refs, **env), env['keep_exports']) save_state = make_save_state(name, **env) check_state = make_check_state(contents, **env) verbose_check_state = make_check_state(contents, verbose_base=4-env['verbose'], **env) if env['verbose']: env['log']('Running coq on initial contents...') if not verbose_check_state(annotated_contents): env['log']('ERROR: Failed to update %s' % name)