Beispiel #1
0
def my_module_gen():
    pygen = [
        PygenSection('__main__', FileCodeSink(open(sys.argv[3], "wt"))),
        PygenSection('foomodulegen_module1', FileCodeSink(open(sys.argv[4], "wt")),
                     'foomodulegen_module1_local'),
        PygenSection('foomodulegen_module2', FileCodeSink(open(sys.argv[5], "wt")),
                     'foomodulegen_module2_local'),
        ]
    module_parser = ModuleParser('foo4', '::')
    module_parser.enable_anonymous_containers = True

    gccxml_options = dict(
        include_paths=eval(sys.argv[2]),
        )

    module_parser.parse_init([sys.argv[1]], includes=['"foo.h"'], pygen_sink=pygen, pygen_classifier=MyPygenClassifier(),
                             gccxml_options=gccxml_options)
    module = module_parser.module
    module.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()')
    module_parser.scan_types()
    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    for sect in pygen:
        sect.code_sink.file.close()
Beispiel #2
0
def my_module_gen():
    out = FileCodeSink(sys.stdout)
    pygen_file = open(sys.argv[3], "wt")
    module_parser = ModuleParser('foo2', '::')
    module_parser.enable_anonymous_containers = True

    print >> sys.stderr, "PYTHON_INCLUDES:", repr(sys.argv[2])
    gccxml_options = dict(
        include_paths=eval(sys.argv[2]),
        )

    module_parser.parse_init([sys.argv[1]], includes=['"foo.h"'], pygen_sink=FileCodeSink(pygen_file),
                             gccxml_options=gccxml_options)
    module = module_parser.module
    module.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()')
    module_parser.scan_types()
    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    pygen_file.close()

    foomodulegen_common.customize_module(module)

    module.generate(out)
Beispiel #3
0
def my_module_gen():
    out = FileCodeSink(sys.stdout)
    pygen_file = open(sys.argv[3], "wt")
    module_parser = ModuleParser('foo2', '::')
    module_parser.enable_anonymous_containers = True

    print("PYTHON_INCLUDES:", repr(sys.argv[2]), file=sys.stderr)
    gccxml_options = dict(
        include_paths=eval(sys.argv[2]),
        )

    module_parser.parse_init([sys.argv[1]], includes=['"foo.h"'], pygen_sink=FileCodeSink(pygen_file),
                             gccxml_options=gccxml_options)
    module = module_parser.module
    foomodulegen_common.customize_module_pre(module)

    module.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()')
    module_parser.scan_types()
    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    pygen_file.close()

    foomodulegen_common.customize_module(module)

    module.generate(out)
Beispiel #4
0
def dcepy_module_gen(binddir, ns3path, dcepath):
    DCE_INCLUDE_PATH = dcepath
    '''
    print "************************* dcepy_module_gen"
    print "* binddir = " + binddir
    print "* ns3path = " + ns3path
    print "* dcepath = " + dcepath
    print "******************************************"
    '''

    cflags = ''

    bldpath = 'bindings/python'
    try:
        os.makedirs(bldpath)
    except OSError as exc:
        if exc.errno == errno.EEXIST and os.path.isdir(bldpath):
            pass
        else:
            raise

    ref_header_dir = binddir + "/refh"
    gccxml_options = dict(
        #include_paths=[ns3path, dcepath+"/model", dcepath + "/helper"],
        include_paths=[ref_header_dir, ns3path],
        define_symbols={
            #'NS3_ASSERT_ENABLE': None,
            #'NS3_LOG_ENABLE': None,
        },
        cflags=('--gccxml-cxxflags "%s -DPYTHON_SCAN"' % cflags))

    inclfiles = []
    for hf in includes_dce:
        inclfiles.append(ref_header_dir + "/" + hf)
        #inclfiles.append( dcepath+"/model/"+hf  )

    #whitelist_paths=[ dcepath+"/model", dcepath + "/helper", ns3path  ]
    whitelist_paths = [ref_header_dir]

    module_parser = ModuleParser('dce', 'ns3')
    module_parser.enable_anonymous_containers = True
    module_parser.add_pre_scan_hook(pre_scan_hook)

    generatepyintermediate = True
    if generatepyintermediate:
        # Test with intermediate file
        fname = bldpath + '/temp_dce_bindings.py'
        print "Generating python pygendbind intermediate file: " + str(fname)
        py_file = open(fname, "wt")
        includes = [
            '"ns3/dce-module.h"', '"ns3/dce-manager-helper.h"',
            '"ns3/dce-application.h"', '"ns3/ipv4-dce-routing-helper.h"'
        ]
        pysink = FileCodeSink(py_file)
        module_parser.parse_init(inclfiles,
                                 whitelist_paths=whitelist_paths,
                                 pygen_sink=pysink,
                                 gccxml_options=gccxml_options,
                                 includes=includes)
        module_parser.scan_types()
        module_parser.scan_methods()
        module_parser.scan_functions()
        module_parser.parse_finalize()

    else:
        # Test with cpp
        fname = bldpath + '/temp_dce_bindings.cpp'
        #fname = 'dce_bindings.cpp'
        print "Generating python bindings c++ file: " + str(fname)
        pygen_file = open(fname, "wt")
        module_parser.parse_init(inclfiles,
                                 whitelist_paths=whitelist_paths,
                                 gccxml_options=gccxml_options)

        module_parser.scan_types()
        module_parser.scan_methods()
        module_parser.scan_functions()
        module_parser.parse_finalize()
        module_parser.module.add_include('<ns3/dce-module.h>')
        module_parser.module.add_include('<ns3/dce-manager-helper.h>')
        module_parser.module.add_include('<ns3/dce-application.h>')
        module_parser.module.add_include('<ns3/ipv4-dce-routing-helper.h>')
        module_parser.module.add_include('<ns3/linux-stack-helper.h>')
        pybindgen.write_preamble(FileCodeSink(pygen_file))
        module_parser.module.generate(FileCodeSink(pygen_file))