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)
def add_handle(data, scope, class_scope):
    classname = 'Handle'
    handle = 'template < class T, class Interface '
    if data.small_buffer_optimization:
        handle += ', class Buffer, bool HeapAllocated > struct Handle : HandleBase < Interface , Buffer >'
    else:
        handle += ' > struct Handle : HandleBase < Interface >'
    scope.add(cpp.get_template_struct_from_text(classname, handle))

    add_handle_constructors(scope)
    add_overriding_functions(data, scope, classname)

    class_scope.visit(OverridingFunctionExtractor(data, scope))
    scope.add(cpp.ScopeEntry('variable', 'T value_;'))

    scope.close()

    # template specialization for std::reference_wrapper
    scope.add(
        cpp.ScopeEntry('code fragment', code.get_handle_specialization(data)))
Example #3
0
def get_detail_file(data, interface_scope):
    main_scope = cpp.Namespace('global')
    main_scope.add(cpp.ScopeEntry(cpp.INCLUDE_GUARD, '#pragma once\n'))
    for entry in interface_scope.content:
        if cpp.is_inclusion_directive(entry):
            main_scope.add(entry)
    main_scope.add( cpp.InclusionDirective('<functional>') )
    if data.copy_on_write:
        main_scope.add(cpp.InclusionDirective('<memory>'))
    if not data.table:
        main_scope.add( cpp.InclusionDirective('<type_traits>') )
        main_scope.add( cpp.InclusionDirective('<utility>') )
        main_scope.add( cpp.InclusionDirective('<' + os.path.join(data.util_include_path,'util.hh') + '>') )
    else:
        main_scope.add( cpp.InclusionDirective('<' + os.path.join(data.util_include_path,'table_util.hh') + '>') )

    comments = parser_addition.extract_comments(data.file)
    inclusion_directives_for_forward_decl = util.get_inclusion_directives_for_forward_declarations(data, comments)
    for inclusion_directive in inclusion_directives_for_forward_decl:
        main_scope.add(cpp.InclusionDirective(inclusion_directive))

    get_detail_file_impl(data, main_scope, interface_scope)
    return main_scope
 def process_enum(self,data,cursor):
     self.scope.add(cpp.ScopeEntry('enum', clang_util.get_enum_definition(data.tu, cursor)))
 def process_headers(self, headers):
     self.scope.add(cpp.ScopeEntry('headers', headers))
 def process_open_include_guard(self, filename):
     self.scope.add(cpp.ScopeEntry('include_guard', parser_addition.extract_include_guard(filename)))