def process_private_source_file(data, content, header_file, private_filename):
    replace_inclusion_directive('"' + header_file + '"',
                                '"' + get_private_name(data.interface_header_file, data.impl) + '"', content)

    replace_classname(data.classname, data.classname + data.impl, content)

    to_string.write_scope(content, private_filename)
    util.clang_format(private_filename)
示例#2
0
def write_file(data):
    processor = cpp_file_parser.CppFileParser()
    parser = file_parser.GenericFileParser(processor, data)
    parser.parse()
    scope = get_detail_file(data, processor.scope)
    cpp_file_parser.remove_duplicate_inclusion_directives(scope)
    if data.table:
        scope.visit(table_detail.SortTable())
    to_string.write_scope(scope, os.path.join(data.detail_folder,data.detail_file), to_string.Visitor(short_entries=[cpp.ALIAS]), not data.no_warning_header, True)
示例#3
0
def process_private_source_file(data, content, header_file, private_filename):
    replace_inclusion_directive(
        '"' + header_file + '"',
        '"' + get_private_name(data.interface_header_file, data.impl) + '"',
        content)

    replace_classname(data.classname, data.classname + data.impl, content)

    to_string.write_scope(content, private_filename)
    util.clang_format(private_filename)
def process_public_source_file(data, main_scope):
    main_scope.visit(PimplFunctions(data.classname, data.private_classname))
    cpp_file_parser.remove_inclusion_directives(main_scope)

    public_header_file = os.path.basename(data.interface_header_file)
    relative_include_files = [public_header_file, get_private_name(public_header_file,data.impl)]
    inclusion_directives = [cpp_file_parser.InclusionDirective('"' + include + '"') for include in relative_include_files]
    inclusion_directives.append(cpp_file_parser.InclusionDirective('<cassert>'))
    cpp_file_parser.prepend_inclusion_directives(main_scope, inclusion_directives)

    main_scope.visit(cpp_file_parser.SortClass())
    to_string.write_scope(main_scope, data.interface_source_file, to_string.VisitorForSourceFile())
    util.clang_format(data.interface_source_file)
示例#5
0
def process_header_file(data):
    private_filename = get_private_name(data.interface_header_file, data.impl)
    processor = cpp_file_parser.CppFileParser()
    parser = file_parser.GenericFileParser(processor, data)
    parser.parse()

    # write private header file
    main_scope = copy.deepcopy(processor.scope)
    remove_outside_class(data.classname, main_scope)
    remove_from_class([
        cpp_file_parser.ALIAS, cpp_file_parser.ENUM,
        cpp_file_parser.STATIC_VARIABLE
    ], data.classname, main_scope)
    replace_classname(data.classname, data.classname + data.impl, main_scope)

    comments = parser_addition.extract_comments(data.file)
    inclusion_directives = [
        cpp_file_parser.InclusionDirective(inclusion_directive)
        for inclusion_directive in
        util.get_inclusion_directives_for_forward_declarations(data, comments)
    ]
    cpp_file_parser.append_inclusion_directives(main_scope,
                                                inclusion_directives)

    main_scope.visit(cpp_file_parser.SortClass())
    to_string.write_scope(main_scope, private_filename)
    util.clang_format(private_filename)

    # write public header file
    main_scope = copy.deepcopy(processor.scope)
    remove_private_members(data.classname, main_scope)
    add_pimpl_section(data.classname, data.classname + data.impl, main_scope)
    main_scope.visit(RemoveConstructors(data.classname))
    main_scope.visit(AddConstructorsAndAssignments(data))
    cpp_file_parser.prepend_inclusion_directives(
        main_scope, [cpp_file_parser.InclusionDirective('<memory>')])

    visitor = to_string.VisitorForHeaderFile()
    main_scope.visit(cpp_file_parser.SortClass())
    comments = parser_addition.extract_comments(data.file)
    cpp_file_parser.add_comments(main_scope, comments)
    to_string.write_scope(main_scope, data.interface_header_file, visitor)
    util.clang_format(data.interface_header_file)
    return main_scope
def write_file(data):
    processor = cpp_file_parser.CppFileParser()
    parser = file_parser.GenericFileParser(processor, data)
    parser.parse()

    scope = get_interface_file(data, processor.scope)
    scope.visit(cpp_file_parser.SortClass())
    include_guard = parser_addition.extract_include_guard(data.file)
    scope.content.insert(0, cpp.IncludeGuard(include_guard))
    if not include_guard.startswith('#pragma once'):
        scope.content.append(cpp.ScopeEntry('Macro endif', '#endif\n'))

    cpp_file_parser.add_comments(scope,
                                 parser_addition.extract_comments(data.file))

    if data.header_only:
        to_string.write_scope(scope, data.interface_file, to_string.Visitor(),
                              not data.no_warning_header)
    else:
        to_string.write_scope(scope, data.interface_file,
                              to_string.VisitorForHeaderFile(),
                              not data.no_warning_header)
        source_filename = get_source_filename(data.interface_file)

        scope = get_interface_file(data,
                                   processor.scope,
                                   for_header_file=False)
        scope.visit(cpp_file_parser.SortClass())
        to_string.write_scope(scope, source_filename,
                              to_string.VisitorForSourceFile(),
                              not data.no_warning_header)
示例#7
0
def process_public_source_file(data, main_scope):
    main_scope.visit(PimplFunctions(data.classname, data.private_classname))
    cpp_file_parser.remove_inclusion_directives(main_scope)

    public_header_file = os.path.basename(data.interface_header_file)
    relative_include_files = [
        public_header_file,
        get_private_name(public_header_file, data.impl)
    ]
    inclusion_directives = [
        cpp_file_parser.InclusionDirective('"' + include + '"')
        for include in relative_include_files
    ]
    inclusion_directives.append(
        cpp_file_parser.InclusionDirective('<cassert>'))
    cpp_file_parser.prepend_inclusion_directives(main_scope,
                                                 inclusion_directives)

    main_scope.visit(cpp_file_parser.SortClass())
    to_string.write_scope(main_scope, data.interface_source_file,
                          to_string.VisitorForSourceFile())
    util.clang_format(data.interface_source_file)
def process_header_file(data):
    private_filename = get_private_name(data.interface_header_file, data.impl)
    processor = cpp_file_parser.CppFileParser()
    parser = file_parser.GenericFileParser(processor, data)
    parser.parse()

    # write private header file
    main_scope = copy.deepcopy(processor.scope)
    remove_outside_class(data.classname, main_scope)
    remove_from_class([cpp_file_parser.ALIAS, cpp_file_parser.ENUM, cpp_file_parser.STATIC_VARIABLE],
                      data.classname, main_scope)
    replace_classname(data.classname, data.classname + data.impl, main_scope)

    comments = parser_addition.extract_comments(data.file)
    inclusion_directives = [cpp_file_parser.InclusionDirective(inclusion_directive)
                            for inclusion_directive in
                            util.get_inclusion_directives_for_forward_declarations(data, comments)]
    cpp_file_parser.append_inclusion_directives(main_scope, inclusion_directives)

    main_scope.visit(cpp_file_parser.SortClass())
    to_string.write_scope(main_scope, private_filename)
    util.clang_format(private_filename)

    # write public header file
    main_scope = copy.deepcopy(processor.scope)
    remove_private_members(data.classname, main_scope)
    add_pimpl_section(data.classname, data.classname + data.impl, main_scope)
    main_scope.visit(RemoveConstructors(data.classname))
    main_scope.visit(AddConstructorsAndAssignments(data))
    cpp_file_parser.prepend_inclusion_directives(main_scope, [cpp_file_parser.InclusionDirective('<memory>')])

    visitor = to_string.VisitorForHeaderFile()
    main_scope.visit(cpp_file_parser.SortClass())
    comments = parser_addition.extract_comments(data.file)
    cpp_file_parser.add_comments(main_scope, comments)
    to_string.write_scope(main_scope, data.interface_header_file, visitor)
    util.clang_format(data.interface_header_file)
    return main_scope
def write_file(data):
    processor = cpp_file_parser.CppFileParser()
    parser = file_parser.GenericFileParser(processor, data)
    parser.parse()

    scope = get_interface_file(data, processor.scope)
    scope.visit(cpp_file_parser.SortClass())
    include_guard = parser_addition.extract_include_guard(data.file)
    scope.content.insert(0, cpp.IncludeGuard(include_guard))
    if not include_guard.startswith('#pragma once'):
        scope.content.append(cpp.ScopeEntry('Macro endif', '#endif\n'))

    cpp_file_parser.add_comments(scope, parser_addition.extract_comments(data.file))

    if data.header_only:
        to_string.write_scope(scope, data.interface_file, to_string.Visitor(), not data.no_warning_header)
    else:
        to_string.write_scope(scope, data.interface_file, to_string.VisitorForHeaderFile(), not data.no_warning_header)
        source_filename = get_source_filename(data.interface_file)

        scope = get_interface_file(data, processor.scope, for_header_file=False)
        scope.visit(cpp_file_parser.SortClass())
        to_string.write_scope(scope, source_filename, to_string.VisitorForSourceFile(), not data.no_warning_header)