bindings/python/ns3modulescan-modular.py
author Tom Henderson <tomh@tomh.org>
Mon, 28 Sep 2015 20:27:25 -0700
changeset 11676 05ea1489e509
parent 7051 ca85ee4e00f8
permissions -rw-r--r--
bug 2184: Integer overflow in MacLow
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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:
6921
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
    38
        new_head, tail = os.path.split(head)
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
    39
        if new_head == head:
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
    40
            raise ValueError
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
    41
        head = new_head
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    42
        if tail == 'ns3':
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    43
            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
    44
        l.insert(0, tail)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    45
    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
    46
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    47
class PreScanHook:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    48
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    49
    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
    50
        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
    51
        self.module = module
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    52
6889
3a137dbf9789 Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6880
diff changeset
    53
    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
    54
                 pygccxml_definition,
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    55
                 global_annotations,
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    56
                 parameter_annotations):
6921
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
    57
        try:
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
    58
            ns3_header = get_ns3_relative_path(pygccxml_definition.location.file_name)
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
    59
        except ValueError: # the header is not from ns3
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
    60
            return # ignore the definition, it's not ns-3 def.
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
    61
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    62
        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
    63
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    64
        ## 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
    65
        ## 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
    66
        ## 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
    67
        ## kept under version control.
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    69
        #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
    70
        #    (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
    71
        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
    72
            (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
    73
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    74
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    75
        ## 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
    76
        ## 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
    77
        ## argument type name).
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    78
        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
    79
                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
    80
                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
    81
            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
    82
            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
    83
                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
    84
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
        ## 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
    86
        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
    87
                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
    88
                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
    89
            global_annotations['ignore'] = None
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    90
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    91
        # manually wrapped
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    92
        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
    93
                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
    94
                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
    95
            global_annotations['ignore'] = True
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    96
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    97
        ## 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
    98
        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
    99
            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
   100
                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
   101
                    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
   102
                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
   103
                    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
   104
                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
   105
                    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
   106
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   107
        ## classes
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   108
        if isinstance(pygccxml_definition, class_t):
6921
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
   109
            print >> sys.stderr, pygccxml_definition
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   110
            # 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
   111
            #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
   112
            #    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
   113
6889
3a137dbf9789 Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6880
diff changeset
   114
            #
3a137dbf9789 Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6880
diff changeset
   115
            # 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
   116
            # 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
   117
            # 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
   118
            # 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
   119
            # 
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 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
   121
                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
   122
                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
   123
                                             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
   124
                #print >> sys.stderr, "********************", cls_name, repr(template_parameters_decls)
6921
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
   125
                
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
   126
                template_parameters_modules = []
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
   127
                for templ in template_parameters_decls:
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
   128
                    if not hasattr(templ, 'location'):
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
   129
                        continue
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
   130
                    try:
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
   131
                        h = get_ns3_relative_path(templ.location.file_name)
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
   132
                    except ValueError:
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
   133
                        continue
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
   134
                    template_parameters_modules.append(self.headers_map[h])
f4aa5d190c7b Modular bindings: bug fixes, more verbose scanning
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6902
diff changeset
   135
6889
3a137dbf9789 Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6880
diff changeset
   136
                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
   137
                    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
   138
                        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
   139
                        break
3a137dbf9789 Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6880
diff changeset
   140
                #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
   141
3a137dbf9789 Modular python scan: fix module detection of template class instantiation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6880
diff changeset
   142
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   143
            if definition_module != self.module:
6935
7d5937fd65db Modular bindings: fix 'import_from_module' with module names with dashes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6921
diff changeset
   144
                global_annotations['import_from_module'] = 'ns.%s' % (definition_module.replace('-', '_'),)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   145
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   146
            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
   147
                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
   148
                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
   149
                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
   150
                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
   151
                return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   152
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   153
            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
   154
                # 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
   155
                global_annotations['ignore'] = None
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   156
                return
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
            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
   159
                global_annotations['ignore'] = None
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   160
                return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   161
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   162
            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
   163
                # 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
   164
                global_annotations['ignore'] = None
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   165
                return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   166
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   167
            # table driven class customization
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   168
            try:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   169
                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
   170
            except KeyError:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   171
                pass
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   172
            else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   173
                global_annotations.update(annotations)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   174
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   175
        ## enums
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   176
        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
   177
            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
   178
                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
   179
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   180
        ## free functions
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   181
        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
   182
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   183
            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
   184
                global_annotations['ignore'] = None
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   185
                return
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
            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
   188
                global_annotations['ignore'] = None
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   189
                return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   190
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   191
        ## 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
   192
        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
   193
            try:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   194
                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
   195
            except KeyError:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   196
                pass
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   197
            else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   198
                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
   199
                    if key == 'params':
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   200
                        parameter_annotations.update (value)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   201
                        del annotations['params']
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   202
                global_annotations.update(annotations)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   203
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   204
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   205
# 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
   206
#     ## classes
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   207
#     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
   208
#         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
   209
#             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
   210
#             #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
   211
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
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
   214
    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
   215
    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
   216
                                                      recursive=False):
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   217
        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
   218
            continue
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   219
        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
   220
        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
   221
        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
   222
    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
   223
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   224
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   225
def ns3_module_scan(top_builddir, module_name, headers_map, output_file_name, cflags):
6902
3aa6e43dfe41 Modular bindings: handle module names with hyphens
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6896
diff changeset
   226
    module_parser = ModuleParser('ns.%s' % module_name.replace('-', '_'), 'ns3')
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   227
    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
   228
    #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
   229
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   230
    gccxml_options = dict(
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   231
        include_paths=[top_builddir],
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   232
         define_symbols={
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   233
            #'NS3_ASSERT_ENABLE': None,
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   234
            #'NS3_LOG_ENABLE': None,
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   235
            },
7051
ca85ee4e00f8 define PYTHON_SCAN
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6935
diff changeset
   236
        cflags=('--gccxml-cxxflags "%s -DPYTHON_SCAN"' % cflags)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   237
        )
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   238
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   239
    try:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   240
        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
   241
    except OSError:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   242
        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
   243
    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
   244
        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
   245
    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
   246
        pass
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   247
    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
   248
    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
   249
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6889
diff changeset
   250
    # 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
   251
    # 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
   252
    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
   253
    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
   254
        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
   255
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6889
diff changeset
   256
    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
   257
                             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
   258
                             #includes=['"ns3/everything.h"'],
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   259
                             pygen_sink=output_sink,
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   260
                             gccxml_options=gccxml_options)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   261
    module_parser.scan_types()
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   262
6896
fb47685b1dad Modular bindings: add the Callback<...> type handlers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   263
    callback_classes_file = open(os.path.join(os.path.dirname(output_file_name), "callbacks_list.py"), "wt")
fb47685b1dad Modular bindings: add the Callback<...> type handlers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   264
    scan_callback_classes(module_parser, callback_classes_file)
fb47685b1dad Modular bindings: add the Callback<...> type handlers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   265
    callback_classes_file.close()
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   266
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   267
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   268
    module_parser.scan_methods()
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   269
    module_parser.scan_functions()
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   270
    module_parser.parse_finalize()
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   271
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   272
    output_file.close()
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   273
    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
   274
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   275
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   276
if __name__ == '__main__':
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   277
    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
   278
        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
   279
        sys.exit(1)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   280
    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
   281
    sys.exit(0)