Example #1
0
    def visit_Argument(self, node):
        if not hasattr(node, 'attributes'):
            return self.generic_visit(node)

        if not 'optional' in node.attributes:
            return self.generic_visit(node)

        # remove optional allocatable/pointer arguments
        if 'allocatable' in node.attributes or 'pointer' in node.attributes:
            logging.debug('removing optional argument %s due to allocatable/pointer attributes' %
                          node.name)
            return None

        dims = [attrib for attrib in node.attributes if attrib.startswith('dimension')]

        # remove optional complex scalar arguments
        if node.type.startswith('complex') and len(dims) == 0:
            logging.debug('removing optional argument %s as it is a complex scalar' % node.name)
            return None

        # remove optional derived types not in self.types
        if node.type.startswith('type') and ft.split_type(node.type) not in self.types:
            logging.debug('removing optional argument %s due to unsupported derived type %s' %
                          (node.name, node.type))
            return None

        # remove arrays of derived types
        if node.type.startswith('type') and len(dims) != 0:
            logging.debug('removing optional argument %s due to unsupported derived type array %s' %
                          (node.name, node.type))
            return None

        return self.generic_visit(node)
Example #2
0
    def visit_Procedure(self, node):
        # special case: keep all constructors and destructors, although
        # they may have pointer arguments
        for suff in self.constructors + self.destructors:
            if node.name.endswith(suff):
                return self.generic_visit(node)

        # don't wrap operator overloading routines
        if node.name.startswith('operator('):
            return None

        # FIXME don't wrap callback arguments
        if 'callback' in node.attributes:
            return None

        args = node.arguments[:]
        if isinstance(node, ft.Function):
            args.append(node.ret_val)

        for arg in args:
            # only callback functions in self.callbacks
            if 'callback' in arg.attributes:
                if node.name not in self.callbacks:
                    logging.debug('removing callback routine %s' % node.name)
                    return None
                else:
                    continue

            if 'optional' in arg.attributes:
                # we can remove the argument instead of the whole routine
                return self.generic_visit(node)
            else:
                # no allocatables or pointers
                if 'allocatable' in arg.attributes or 'pointer' in arg.attributes:
                    logging.debug('removing routine %s due to allocatable/pointer arguments' % node.name)
                    return None

                dims = [attrib for attrib in arg.attributes if attrib.startswith('dimension')]

                # # no complex scalars (arrays are OK)
                # if arg.type.startswith('complex') and len(dims) == 0:
                #    logging.debug('removing routine %s due to complex scalar arguments' % node.name)
                #    return None

                # no derived types apart from those in self.types
                if arg.type.startswith('type') and ft.split_type(arg.type) not in self.types:
                    logging.debug('removing routine %s due to unsupported derived type %s' %
                                  (node.name, arg.type))
                    return None

                # no arrays of derived types
                if arg.type.startswith('type') and len(dims) != 0:
                    logging.debug('removing routine %s due to unsupported derived type array %s' %
                                  (node.name, arg.type))
                    return None

        return self.generic_visit(node)
Example #3
0
    def visit_Argument(self, node):
        if not hasattr(node, 'attributes'):
            return self.generic_visit(node)

        if not 'optional' in node.attributes:
            return self.generic_visit(node)

        # remove optional allocatable/pointer arguments
        if 'allocatable' in node.attributes or 'pointer' in node.attributes:
            warnings.warn(
                'removing optional argument %s due to allocatable/pointer attributes'
                % node.name)
            return None

        dims = [
            attrib for attrib in node.attributes
            if attrib.startswith('dimension')
        ]

        # remove optional complex scalar arguments
        if node.type.startswith('complex') and len(dims) == 0:
            warnings.warn(
                'removing optional argument %s as it is a complex scalar' %
                node.name)
            return None

        # remove optional derived types not in self.types
        if node.type.startswith('type') and ft.split_type(
                node.type) not in self.types:
            warnings.warn(
                'removing optional argument %s due to unsupported derived type %s'
                % (node.name, node.type))
            return None

        # remove arrays of derived types
        # EXPERIMENTAL !
        if node.type.startswith('type') and len(dims) != 0:
            if len(dims) > 1:
                raise ValueError(
                    'more than one dimension attribute found for arg %s' %
                    node.name)
            if len(ArrayDimensionConverter.split_dimensions(dims[0])) > 1:
                warnings.warn(
                    'test removing optional argument %s as only one dimensional fixed-length arrays are currently supported for derived type %s array'
                    % (node.name, node.type))
                return None

        return self.generic_visit(node)
Example #4
0
    def visit_Argument(self, node):
        if not hasattr(node, 'attributes'):
            return self.generic_visit(node)

        if not 'optional' in node.attributes:
            return self.generic_visit(node)

        # remove optional allocatable/pointer arguments
        if 'allocatable' in node.attributes or 'pointer' in node.attributes:
            warnings.warn('removing optional argument %s due to allocatable/pointer attributes' %
                          node.name)
            return None

        dims = [attrib for attrib in node.attributes if attrib.startswith('dimension')]

        # remove optional complex scalar arguments
        if node.type.startswith('complex') and len(dims) == 0:
            warnings.warn('removing optional argument %s as it is a complex scalar' % node.name)
            return None

        # remove optional derived types not in self.types
        if node.type.startswith('type') and ft.split_type(node.type) not in self.types:
            warnings.warn('removing optional argument %s due to unsupported derived type %s' %
                          (node.name, node.type))
            return None

        # remove optional arrays of derived types
        # EXPERIMENTAL !
        if node.type.startswith('type') and len(dims) != 0:
            if len(dims) > 1:
                raise ValueError('more than one dimension attribute found for arg %s' % node.name)
            dimensions_list = ArrayDimensionConverter.split_dimensions(dims[0])
            if len(dimensions_list) > 1 or ':' in dimensions_list:
                warnings.warn(
                    'test removing optional argument %s as only one dimensional fixed-length arrays are currently supported for derived type %s array' %
                    (node.name, node.type))
                return None

        return self.generic_visit(node)
Example #5
0
    def visit_Procedure(self, node):
        # special case: keep all constructors and destructors, although
        # they may have pointer arguments
        for suff in self.constructors + self.destructors:
            if node.name.endswith(suff):
                return self.generic_visit(node)

        # don't wrap operator overloading routines
        if node.name.startswith('operator('):
            return None

        # FIXME don't wrap callback arguments
        if 'callback' in node.attributes:
            return None

        args = node.arguments[:]
        if isinstance(node, ft.Function):
            args.append(node.ret_val)

        for arg in args:
            # only callback functions in self.callbacks
            if 'callback' in arg.attributes:
                if node.name not in self.callbacks:
                    warnings.warn('removing callback routine %s' % node.name)
                    return None
                else:
                    continue

            if 'optional' in arg.attributes:
                # we can remove the argument instead of the whole routine
                return self.generic_visit(node)
            else:
                # no allocatables or pointers
                if 'allocatable' in arg.attributes or 'pointer' in arg.attributes:
                    warnings.warn(
                        'removing routine %s due to allocatable/pointer arguments'
                        % node.name)
                    return None

                dims = [
                    attrib for attrib in arg.attributes
                    if attrib.startswith('dimension')
                ]

                # # no complex scalars (arrays are OK)
                # if arg.type.startswith('complex') and len(dims) == 0:
                #    logging.debug('removing routine %s due to complex scalar arguments' % node.name)
                #    return None

                # no derived types apart from those in self.types
                if arg.type.startswith('type') and ft.split_type(
                        arg.type) not in self.types:
                    warnings.warn(
                        'removing routine %s due to unsupported derived type %s'
                        % (node.name, arg.type))
                    return None

                # no arrays of derived types of assumed shape, or more than one dimension
                # Yann - EXPERIMENTAL !!
                if arg.type.startswith('type') and len(dims) != 0:
                    # warnings.warn('removing routine %s due to unsupported arrays of derived types %s' %
                    #               (node.name, arg.type))
                    # return none
                    if len(dims) > 1:
                        raise ValueError(
                            'more than one dimension attribute found for arg %s'
                            % arg.name)
                    dimensions_list = ArrayDimensionConverter.split_dimensions(
                        dims[0])
                    if len(dimensions_list) > 1 or ':' in dimensions_list:
                        warnings.warn(
                            'removing routine %s due to derived type array %s -- currently, only '
                            'fixed-lengh one-dimensional arrays of derived type are supported'
                            % (arg.name, arg.type))
                        return None

        return self.generic_visit(node)
Example #6
0
    def visit_Procedure(self, node):
        # special case: keep all constructors and destructors, although
        # they may have pointer arguments
        for suff in self.constructors + self.destructors:
            if node.name.endswith(suff):
                return self.generic_visit(node)

        # don't wrap operator overloading routines
        if node.name.startswith('operator('):
            return None

        # FIXME don't wrap callback arguments
        if 'callback' in node.attributes:
            return None

        args = node.arguments[:]
        if isinstance(node, ft.Function):
            args.append(node.ret_val)

        for arg in args:
            # only callback functions in self.callbacks
            if 'callback' in arg.attributes:
                if node.name not in self.callbacks:
                    warnings.warn('removing callback routine %s' % node.name)
                    return None
                else:
                    continue

            if 'optional' in arg.attributes:
                # we can remove the argument instead of the whole routine
                return self.generic_visit(node)
            else:
                # no allocatables or pointers
                if 'allocatable' in arg.attributes or 'pointer' in arg.attributes:
                    warnings.warn('removing routine %s due to allocatable/pointer arguments' % node.name)
                    return None

                dims = [attrib for attrib in arg.attributes if attrib.startswith('dimension')]

                # # no complex scalars (arrays are OK)
                # if arg.type.startswith('complex') and len(dims) == 0:
                #    logging.debug('removing routine %s due to complex scalar arguments' % node.name)
                #    return None

                # no derived types apart from those in self.types
                if arg.type.startswith('type') and ft.split_type(arg.type) not in self.types:
                    warnings.warn('removing routine %s due to unsupported derived type %s' %
                                  (node.name, arg.type))
                    return None

                # no arrays of derived types of assumed shape, or more than one dimension
                # Yann - EXPERIMENTAL !!
                if arg.type.startswith('type') and len(dims) != 0:
                    # warnings.warn('removing routine %s due to unsupported arrays of derived types %s' %
                    #               (node.name, arg.type))
                    # return none
                    if len(dims) > 1:
                        raise ValueError('more than one dimension attribute found for arg %s' % arg.name)
                    dimensions_list = ArrayDimensionConverter.split_dimensions(dims[0])
                    if len(dimensions_list) > 1 or ':' in dimensions_list:
                        warnings.warn('removing routine %s due to derived type array argument : %s -- currently, only '
                                      'fixed-lengh one-dimensional arrays of derived type are supported'
                                      % (node.name, arg.name))
                        return None

        return self.generic_visit(node)