author | Gustavo J. A. M. Carneiro <gjc@inescporto.pt> |
Sat, 12 Mar 2011 18:34:30 +0000 | |
changeset 6893 | 5dccd86f90cf |
parent 6889 | 3a137dbf9789 |
child 6896 | fb47685b1dad |
permissions | -rw-r--r-- |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
1 |
#! /usr/bin/env python |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
2 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
3 |
import sys |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
4 |
import os.path |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
5 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
6 |
import pybindgen.settings |
6889
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
7 |
from pybindgen.gccxmlparser import ModuleParser, PygenClassifier, PygenSection, WrapperWarning, find_declaration_from_name |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
8 |
from pybindgen.typehandlers.codesink import FileCodeSink |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
9 |
from pygccxml.declarations import templates |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
10 |
from pygccxml.declarations.enumeration import enumeration_t |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
11 |
from pygccxml.declarations.class_declaration import class_t |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
12 |
from pygccxml.declarations.calldef import free_function_t, member_function_t, constructor_t, calldef_t |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
13 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
14 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
15 |
## we need the smart pointer type transformation to be active even |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
16 |
## during gccxml scanning. |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
17 |
import ns3modulegen_core_customizations |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
18 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
19 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
20 |
## silence gccxmlparser errors; we only want error handling in the |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
21 |
## generated python script, not while scanning. |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
22 |
class ErrorHandler(pybindgen.settings.ErrorHandler): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
23 |
def handle_error(self, dummy_wrapper, dummy_exception, dummy_traceback_): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
24 |
return True |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
25 |
pybindgen.settings.error_handler = ErrorHandler() |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
26 |
import warnings |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
27 |
warnings.filterwarnings(category=WrapperWarning, action='ignore') |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
28 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
29 |
|
6878
11a009e0c08e
Import type_annotations from ns3modulescan.py into ns3modulescan-modular.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6877
diff
changeset
|
30 |
import ns3modulescan |
11a009e0c08e
Import type_annotations from ns3modulescan.py into ns3modulescan-modular.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6877
diff
changeset
|
31 |
type_annotations = ns3modulescan.type_annotations |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
32 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
33 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
34 |
def get_ns3_relative_path(path): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
35 |
l = [] |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
36 |
head = path |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
37 |
while head: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
38 |
head, tail = os.path.split(head) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
39 |
if tail == 'ns3': |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
40 |
return os.path.join(*l) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
41 |
l.insert(0, tail) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
42 |
raise AssertionError("is the path %r inside ns3?!" % path) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
43 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
44 |
class PreScanHook: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
45 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
46 |
def __init__(self, headers_map, module): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
47 |
self.headers_map = headers_map |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
48 |
self.module = module |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
49 |
|
6889
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
50 |
def __call__(self, module_parser, |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
51 |
pygccxml_definition, |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
52 |
global_annotations, |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
53 |
parameter_annotations): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
54 |
ns3_header = get_ns3_relative_path(pygccxml_definition.location.file_name) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
55 |
definition_module = self.headers_map[ns3_header] |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
56 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
57 |
## Note: we don't include line numbers in the comments because |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
58 |
## those numbers are very likely to change frequently, which would |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
59 |
## cause needless changes, since the generated python files are |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
60 |
## kept under version control. |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
61 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
62 |
#global_annotations['pygen_comment'] = "%s:%i: %s" % \ |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
63 |
# (ns3_header, pygccxml_definition.location.line, pygccxml_definition) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
64 |
global_annotations['pygen_comment'] = "%s (module %r): %s" % \ |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
65 |
(ns3_header, definition_module, pygccxml_definition) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
66 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
67 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
68 |
## handle ns3::Object::GetObject (left to its own devices, |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
69 |
## pybindgen will generate a mangled name containing the template |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
70 |
## argument type name). |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
71 |
if isinstance(pygccxml_definition, member_function_t) \ |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
72 |
and pygccxml_definition.parent.name == 'Object' \ |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
73 |
and pygccxml_definition.name == 'GetObject': |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
74 |
template_args = templates.args(pygccxml_definition.demangled_name) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
75 |
if template_args == ['ns3::Object']: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
76 |
global_annotations['template_instance_names'] = 'ns3::Object=>GetObject' |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
77 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
78 |
## Don't wrap Simulator::Schedule* (manually wrapped) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
79 |
if isinstance(pygccxml_definition, member_function_t) \ |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
80 |
and pygccxml_definition.parent.name == 'Simulator' \ |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
81 |
and pygccxml_definition.name.startswith('Schedule'): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
82 |
global_annotations['ignore'] = None |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
83 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
84 |
# manually wrapped |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
85 |
if isinstance(pygccxml_definition, member_function_t) \ |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
86 |
and pygccxml_definition.parent.name == 'Simulator' \ |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
87 |
and pygccxml_definition.name == 'Run': |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
88 |
global_annotations['ignore'] = True |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
89 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
90 |
## http://www.gccxml.org/Bug/view.php?id=9915 |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
91 |
if isinstance(pygccxml_definition, calldef_t): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
92 |
for arg in pygccxml_definition.arguments: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
93 |
if arg.default_value is None: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
94 |
continue |
6880
4ea22fe9e5ee
Copy a bug fix from ns3modulescan.py into ns3modulescan-modular.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6878
diff
changeset
|
95 |
elif arg.default_value == "ns3::MilliSeconds( )": |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
96 |
arg.default_value = "ns3::MilliSeconds(0)" |
6880
4ea22fe9e5ee
Copy a bug fix from ns3modulescan.py into ns3modulescan-modular.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6878
diff
changeset
|
97 |
elif arg.default_value == "ns3::Seconds( )": |
4ea22fe9e5ee
Copy a bug fix from ns3modulescan.py into ns3modulescan-modular.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6878
diff
changeset
|
98 |
arg.default_value = "ns3::Seconds(0)" |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
99 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
100 |
## classes |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
101 |
if isinstance(pygccxml_definition, class_t): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
102 |
# no need for helper classes to allow subclassing in Python, I think... |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
103 |
#if pygccxml_definition.name.endswith('Helper'): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
104 |
# global_annotations['allow_subclassing'] = 'false' |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
105 |
|
6889
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
106 |
# |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
107 |
# If a class is template instantiation, even if the |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
108 |
# template was defined in some other module, if a template |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
109 |
# argument belongs to this module then the template |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
110 |
# instantiation will belong to this module. |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
111 |
# |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
112 |
if templates.is_instantiation(pygccxml_definition.decl_string): |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
113 |
cls_name, template_parameters = templates.split(pygccxml_definition.name) |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
114 |
template_parameters_decls = [find_declaration_from_name(module_parser.global_ns, templ_param) |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
115 |
for templ_param in template_parameters] |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
116 |
#print >> sys.stderr, "********************", cls_name, repr(template_parameters_decls) |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
117 |
template_parameters_modules = [self.headers_map[get_ns3_relative_path(templ.location.file_name)] |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
118 |
for templ in template_parameters_decls if hasattr(templ, 'location')] |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
119 |
for templ_mod in template_parameters_modules: |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
120 |
if templ_mod == self.module: |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
121 |
definition_module = templ_mod |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
122 |
break |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
123 |
#print >> sys.stderr, "********************", cls_name, repr(template_parameters_modules) |
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
124 |
|
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
125 |
|
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
126 |
if definition_module != self.module: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
127 |
global_annotations['import_from_module'] = 'ns.%s' % definition_module |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
128 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
129 |
if pygccxml_definition.decl_string.startswith('::ns3::SimpleRefCount<'): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
130 |
global_annotations['incref_method'] = 'Ref' |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
131 |
global_annotations['decref_method'] = 'Unref' |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
132 |
global_annotations['peekref_method'] = 'GetReferenceCount' |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
133 |
global_annotations['automatic_type_narrowing'] = 'true' |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
134 |
return |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
135 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
136 |
if pygccxml_definition.decl_string.startswith('::ns3::Callback<'): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
137 |
# manually handled in ns3modulegen_core_customizations.py |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
138 |
global_annotations['ignore'] = None |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
139 |
return |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
140 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
141 |
if pygccxml_definition.decl_string.startswith('::ns3::TracedCallback<'): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
142 |
global_annotations['ignore'] = None |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
143 |
return |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
144 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
145 |
if pygccxml_definition.decl_string.startswith('::ns3::Ptr<'): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
146 |
# handled by pybindgen "type transformation" |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
147 |
global_annotations['ignore'] = None |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
148 |
return |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
149 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
150 |
# table driven class customization |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
151 |
try: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
152 |
annotations = type_annotations[pygccxml_definition.decl_string] |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
153 |
except KeyError: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
154 |
pass |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
155 |
else: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
156 |
global_annotations.update(annotations) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
157 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
158 |
## enums |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
159 |
if isinstance(pygccxml_definition, enumeration_t): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
160 |
if definition_module != self.module: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
161 |
global_annotations['import_from_module'] = 'ns.%s' % definition_module |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
162 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
163 |
## free functions |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
164 |
if isinstance(pygccxml_definition, free_function_t): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
165 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
166 |
if definition_module != self.module: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
167 |
global_annotations['ignore'] = None |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
168 |
return |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
169 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
170 |
if pygccxml_definition.name == 'PeekPointer': |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
171 |
global_annotations['ignore'] = None |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
172 |
return |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
173 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
174 |
## table driven methods/constructors/functions customization |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
175 |
if isinstance(pygccxml_definition, (free_function_t, member_function_t, constructor_t)): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
176 |
try: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
177 |
annotations = type_annotations[str(pygccxml_definition)] |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
178 |
except KeyError: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
179 |
pass |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
180 |
else: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
181 |
for key,value in annotations.items(): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
182 |
if key == 'params': |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
183 |
parameter_annotations.update (value) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
184 |
del annotations['params'] |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
185 |
global_annotations.update(annotations) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
186 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
187 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
188 |
# def post_scan_hook(dummy_module_parser, dummy_pygccxml_definition, pybindgen_wrapper): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
189 |
# ## classes |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
190 |
# if isinstance(pybindgen_wrapper, CppClass): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
191 |
# if pybindgen_wrapper.name.endswith('Checker'): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
192 |
# print >> sys.stderr, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", pybindgen_wrapper |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
193 |
# #pybindgen_wrapper.set_instance_creation_function(AttributeChecker_instance_creation_function) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
194 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
195 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
196 |
def scan_callback_classes(module_parser, callback_classes_file): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
197 |
callback_classes_file.write("callback_classes = [\n") |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
198 |
for cls in module_parser.module_namespace.classes(function=module_parser.location_filter, |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
199 |
recursive=False): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
200 |
if not cls.name.startswith("Callback<"): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
201 |
continue |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
202 |
assert templates.is_instantiation(cls.decl_string), "%s is not a template instantiation" % cls |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
203 |
dummy_cls_name, template_parameters = templates.split(cls.decl_string) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
204 |
callback_classes_file.write(" %r,\n" % template_parameters) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
205 |
callback_classes_file.write("]\n") |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
206 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
207 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
208 |
def ns3_module_scan(top_builddir, module_name, headers_map, output_file_name, cflags): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
209 |
module_parser = ModuleParser('ns.%s' % module_name, 'ns3') |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
210 |
module_parser.add_pre_scan_hook(PreScanHook(headers_map, module_name)) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
211 |
#module_parser.add_post_scan_hook(post_scan_hook) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
212 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
213 |
gccxml_options = dict( |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
214 |
include_paths=[top_builddir], |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
215 |
define_symbols={ |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
216 |
#'NS3_ASSERT_ENABLE': None, |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
217 |
#'NS3_LOG_ENABLE': None, |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
218 |
}, |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
219 |
cflags=('--gccxml-cxxflags %r' % (cflags,)) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
220 |
) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
221 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
222 |
try: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
223 |
os.unlink(output_file_name) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
224 |
except OSError: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
225 |
pass |
6877
826f20022032
./waf --apiscan creates the bindings dir if it doesn't exist
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6874
diff
changeset
|
226 |
try: |
826f20022032
./waf --apiscan creates the bindings dir if it doesn't exist
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6874
diff
changeset
|
227 |
os.makedirs(os.path.dirname(output_file_name)) |
826f20022032
./waf --apiscan creates the bindings dir if it doesn't exist
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6874
diff
changeset
|
228 |
except OSError: |
826f20022032
./waf --apiscan creates the bindings dir if it doesn't exist
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6874
diff
changeset
|
229 |
pass |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
230 |
output_file = open(output_file_name, "wt") |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
231 |
output_sink = FileCodeSink(output_file) |
6893
5dccd86f90cf
Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6889
diff
changeset
|
232 |
|
5dccd86f90cf
Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6889
diff
changeset
|
233 |
# if there exists a scan-header.h file in src/<module>/bindings, |
5dccd86f90cf
Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6889
diff
changeset
|
234 |
# scan it, otherwise scan ns3/xxxx-module.h. |
5dccd86f90cf
Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6889
diff
changeset
|
235 |
scan_header = os.path.join(os.path.dirname(output_file_name), "scan-header.h") |
5dccd86f90cf
Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6889
diff
changeset
|
236 |
if not os.path.exists(scan_header): |
5dccd86f90cf
Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6889
diff
changeset
|
237 |
scan_header = os.path.join(top_builddir, "ns3", "%s-module.h" % module_name) |
5dccd86f90cf
Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6889
diff
changeset
|
238 |
|
5dccd86f90cf
Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6889
diff
changeset
|
239 |
module_parser.parse_init([scan_header], |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
240 |
None, whitelist_paths=[top_builddir], |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
241 |
#includes=['"ns3/everything.h"'], |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
242 |
pygen_sink=output_sink, |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
243 |
gccxml_options=gccxml_options) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
244 |
module_parser.scan_types() |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
245 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
246 |
#callback_classes_file = open(os.path.join(os.path.dirname(pygen_file_name), "callbacks_list.py"), "wt") |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
247 |
#scan_callback_classes(module_parser, callback_classes_file) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
248 |
#callback_classes_file.close() |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
249 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
250 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
251 |
module_parser.scan_methods() |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
252 |
module_parser.scan_functions() |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
253 |
module_parser.parse_finalize() |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
254 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
255 |
output_file.close() |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
256 |
os.chmod(output_file_name, 0400) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
257 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
258 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
259 |
if __name__ == '__main__': |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
260 |
if len(sys.argv) != 6: |
6889
3a137dbf9789
Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6880
diff
changeset
|
261 |
print "ns3modulescan-modular.py top_builddir module_path module_headers output_file_name cflags" |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
262 |
sys.exit(1) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
263 |
ns3_module_scan(sys.argv[1], sys.argv[2], eval(sys.argv[3]), sys.argv[4], sys.argv[5]) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
264 |
sys.exit(0) |