Beispiel #1
0
def ns3_module_scan(top_builddir, module_name, headers_map, output_file_name,
                    cflags):
    module_parser = ModuleParser('ns.%s' % module_name.replace('-', '_'),
                                 'ns3')
    module_parser.add_pre_scan_hook(PreScanHook(headers_map, module_name))
    #module_parser.add_post_scan_hook(post_scan_hook)

    castxml_options = dict(
        include_paths=[top_builddir,
                       os.path.join(top_builddir, "include")],
        define_symbols={
            #'NS3_ASSERT_ENABLE': None,
            #'NS3_LOG_ENABLE': None,
        },
        cflags=('-std=c++17 %s' % cflags))

    try:
        os.unlink(output_file_name)
    except OSError:
        pass
    try:
        os.makedirs(os.path.dirname(output_file_name))
    except OSError:
        pass
    output_file = open(output_file_name, "wt")
    output_sink = FileCodeSink(output_file)

    # if there exists a scan-header.h file in src/<module>/bindings or contrib/<module>/bindings,
    # scan it, otherwise scan ns3/xxxx-module.h.
    scan_header = os.path.join(os.path.dirname(output_file_name),
                               "scan-header.h")
    if not os.path.exists(scan_header):
        scan_header = os.path.join(top_builddir, "ns3",
                                   "%s-module.h" % module_name)
    if not os.path.exists(scan_header):
        scan_header = os.path.join(top_builddir, "include", "ns3",
                                   "%s-module.h" % module_name)

    module_parser.parse_init([scan_header],
                             None,
                             whitelist_paths=[top_builddir],
                             pygen_sink=output_sink,
                             castxml_options=castxml_options)
    module_parser.scan_types()

    callback_classes_file = open(
        os.path.join(os.path.dirname(output_file_name), "callbacks_list.py"),
        "wt")
    scan_callback_classes(module_parser, callback_classes_file)
    callback_classes_file.close()

    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    output_file.close()
    os.chmod(output_file_name, 0o400)
Beispiel #2
0
def ns3_module_scan(top_builddir, module_name, headers_map, output_file_name,
                    cflags):
    module_parser = ModuleParser('ns.%s' % module_name.replace('-', '_'),
                                 'ns3')
    module_parser.add_pre_scan_hook(PreScanHook(headers_map, module_name))

    gccxml_options = dict(include_paths=[top_builddir],
                          define_symbols={},
                          cflags=('--gccxml-cxxflags "%s -DPYTHON_SCAN"' %
                                  cflags))

    try:
        os.unlink(output_file_name)
    except OSError:
        pass
    try:
        os.makedirs(os.path.dirname(output_file_name))
    except OSError:
        pass
    output_file = open(output_file_name, "wt")
    output_sink = FileCodeSink(output_file)

    scan_header = os.path.join(os.path.dirname(output_file_name),
                               "scan-header.h")
    if not os.path.exists(scan_header):
        scan_header = os.path.join(top_builddir, "ns3",
                                   "%s-module.h" % module_name)

    module_parser.parse_init([scan_header],
                             None,
                             whitelist_paths=[top_builddir],
                             pygen_sink=output_sink,
                             gccxml_options=gccxml_options)
    module_parser.scan_types()

    callback_classes_file = open(
        os.path.join(os.path.dirname(output_file_name), "callbacks_list.py"),
        "wt")
    scan_callback_classes(module_parser, callback_classes_file)
    callback_classes_file.close()

    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    output_file.close()
    os.chmod(output_file_name, 0400)
Beispiel #3
0
    def generate(self, out, module_file_base_name=None):
        """Generates the module

        :type out: a file object, L{FileCodeSink}, or L{MultiSectionFactory}

        :param module_file_base_name: base name of the module file.
        This is useful when we want to produce a _foo module that will
        be imported into a foo module, to avoid making all types
        docstrings contain _foo.Xpto instead of foo.Xpto.
        """
        if hasattr(out, 'write'):
            out = FileCodeSink(out)
        if isinstance(out, CodeSink):
            sink_manager = _MonolithicSinkManager(out)
        elif isinstance(out, MultiSectionFactory):
            sink_manager = _MultiSectionSinkManager(out)
        else:
            raise TypeError
        self.do_generate(sink_manager, module_file_base_name)
        sink_manager.close()
Beispiel #4
0
def ns3_module_scan(top_builddir, pygen_file_name, everything_h, cflags):

    ns3_modules = eval(sys.stdin.read())

    ## do a topological sort on the modules graph
    from topsort import topsort
    graph = []
    module_names = ns3_modules.keys()
    module_names.sort()
    for ns3_module_name in module_names:
        ns3_module_deps = list(ns3_modules[ns3_module_name][0])
        ns3_module_deps.sort()
        for dep in ns3_module_deps:
            graph.append((dep, ns3_module_name))
    sorted_ns3_modules = topsort(graph)
    #print >> sys.stderr, "******* topological sort: ", sorted_ns3_modules

    sections = [
        PygenSection('__main__', FileCodeSink(open(pygen_file_name, "wt")))
    ]
    headers_map = {}  # header_name -> section_name
    section_precendences = {}  # section_name -> precedence
    for prec, ns3_module in enumerate(sorted_ns3_modules):
        section_name = "ns3_module_%s" % ns3_module.replace('-', '_')
        file_name = os.path.join(os.path.dirname(pygen_file_name),
                                 "%s.py" % section_name)
        sections.append(
            PygenSection(section_name, FileCodeSink(open(file_name, "wt")),
                         section_name + "__local"))
        for header in ns3_modules[ns3_module][1]:
            headers_map[header] = section_name
        section_precendences[section_name] = prec

    module_parser = ModuleParser('ns3', 'ns3')

    module_parser.add_pre_scan_hook(pre_scan_hook)
    #module_parser.add_post_scan_hook(post_scan_hook)

    gccxml_options = dict(
        include_paths=[top_builddir],
        define_symbols={
            #'NS3_ASSERT_ENABLE': None,
            #'NS3_LOG_ENABLE': None,
        },
        cflags=('--gccxml-cxxflags %r' % (cflags, )))

    module_parser.parse_init(
        [everything_h],
        None,
        whitelist_paths=[top_builddir,
                         os.path.dirname(everything_h)],
        #includes=['"ns3/everything.h"'],
        pygen_sink=sections,
        pygen_classifier=MyPygenClassifier(headers_map, section_precendences),
        gccxml_options=gccxml_options)
    module_parser.scan_types()

    callback_classes_file = open(
        os.path.join(os.path.dirname(pygen_file_name), "callbacks_list.py"),
        "wt")
    scan_callback_classes(module_parser, callback_classes_file)
    callback_classes_file.close()

    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    for section in sections:
        section.code_sink.file.close()
Beispiel #5
0
def ns3_module_scan(top_builddir, pygen_file_name, everything_h, cflags):

    ns3_modules = eval(sys.stdin.readline())

    
    from topsort import topsort
    graph = []
    module_names = ns3_modules.keys()
    module_names.sort()
    for ns3_module_name in module_names:
        ns3_module_deps = list(ns3_modules[ns3_module_name][0])
        ns3_module_deps.sort()
        for dep in ns3_module_deps:
            graph.append((dep, ns3_module_name))
    sorted_ns3_modules = topsort(graph)
    

    sections = [PygenSection('__main__', FileCodeSink(open(pygen_file_name, "wt")))]
    headers_map = {} 
    section_precendences = {} 
    for prec, ns3_module in enumerate(sorted_ns3_modules):
        section_name = "ns3_module_%s" % ns3_module.replace('-', '_')
        file_name = os.path.join(os.path.dirname(pygen_file_name), "%s.py" % section_name)
        sections.append(PygenSection(section_name, FileCodeSink(open(file_name, "wt")),
                                     section_name + "__local"))
        for header in ns3_modules[ns3_module][1]:
            headers_map[header] = section_name
        section_precendences[section_name] = prec

    module_parser = ModuleParser('ns3', 'ns3')

    module_parser.add_pre_scan_hook(pre_scan_hook)
    

    gccxml_options = dict(
        include_paths=[top_builddir],
         define_symbols={
            
            
            },
        cflags=('--gccxml-cxxflags "%s -DPYTHON_SCAN"' % cflags)
        )

    module_parser.parse_init([everything_h],
                             None, whitelist_paths=[top_builddir, os.path.dirname(everything_h)],
                             
                             pygen_sink=sections,
                             pygen_classifier=MyPygenClassifier(headers_map, section_precendences),
                             gccxml_options=gccxml_options)
    module_parser.scan_types()

    callback_classes_file = open(os.path.join(os.path.dirname(pygen_file_name), "callbacks_list.py"), "wt")
    scan_callback_classes(module_parser, callback_classes_file)
    callback_classes_file.close()


    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    for section in sections:
        section.code_sink.file.close()