Пример #1
0
def add_missing_destructors(tree):
    for node in ft.walk(tree):
        if not isinstance(node, ft.Type):
            continue
        for child in ft.iter_child_nodes(node):
            if isinstance(child, ft.Procedure):
                if 'destructor' in child.attributes:
                    logging.info('found destructor %s' % child.name)
                    break
        else:

            logging.info('adding missing destructor for %s' % node.name)
            new_node = ft.Subroutine('%s_finalise' % node.name,
                                 node.filename,
                                 ['Automatically generated destructor for %s' % node.name],
                                 node.lineno,
                                 [ft.Argument(name='this',
                                           filename=node.filename,
                                           doc=['Object to be destructed'],
                                           lineno=node.lineno,
                                           attributes=['intent(inout)'],
                                           type='type(%s)' % node.name)],
                                 node.uses,
                                 ['destructor', 'skip_call'],
                                 mod_name=node.mod_name,
                                 type_name=node.name)
            new_node.method_name = '__del__'
            node.procedures.append(new_node)
    return tree
Пример #2
0
def add_missing_destructors(tree):
    for node in ft.walk(tree):
        if not isinstance(node, ft.Type):
            continue
        for child in ft.iter_child_nodes(node):
            if isinstance(child, ft.Procedure):
                if 'destructor' in child.attributes:
                    logging.info('found destructor %s' % child.name)
                    break
        else:

            logging.info('adding missing destructor for %s' % node.name)
            new_node = ft.Subroutine(
                '%s_finalise' % node.name,
                node.filename,
                ['Automatically generated destructor for %s' % node.name],
                node.lineno, [
                    ft.Argument(name='this',
                                filename=node.filename,
                                doc=['Object to be destructed'],
                                lineno=node.lineno,
                                attributes=['intent(inout)'],
                                type='type(%s)' % node.name)
                ],
                node.uses, ['destructor', 'skip_call'],
                mod_name=node.mod_name,
                type_name=node.name)
            new_node.method_name = '__del__'
            node.procedures.append(new_node)
    return tree
Пример #3
0
        def visit_Type(self, node):
            logging.debug('visiting %r' % node)
            interfaces = []
            procedures = []
            for child in ft.iter_child_nodes(node):
                if isinstance(child, ft.Interface):
                    interfaces.append(child)
                elif isinstance(child, ft.Procedure):
                    procedures.append(child)
                else:
                    # other child nodes should be left where they are
                    pass

            node.interfaces = interfaces
            node.procedures = procedures
            return self.generic_visit(node)
Пример #4
0
        def visit_Type(self, node):
            logging.debug('visiting %r' % node)
            interfaces = []
            procedures = []
            for child in ft.iter_child_nodes(node):
                if isinstance(child, ft.Interface):
                    interfaces.append(child)
                elif isinstance(child, ft.Procedure):
                    procedures.append(child)
                else:
                    # other child nodes should be left where they are
                    pass

            node.interfaces = interfaces
            node.procedures = procedures
            return self.generic_visit(node)