Exemplo n.º 1
0
 def visit_ArrayDecl(  # pylint: disable=invalid-name
         self, node) -> t.Tuple[str, typed_ast3.Subscript]:
     """Return tuple of: name, st.ndarray[..., ...] for given array type information."""
     name, type_ = self.visit(node.type)
     assert isinstance(name, str)
     assert isinstance(type_, typed_ast3.AST)
     dim = self.visit(node.dim)
     if dim is not None:
         raise NotImplementedError(_node_debug(node.dim), str(dim))
     dim_quals = [self.visit(subnode) for subnode in node.dim_quals]
     if dim_quals:
         raise NotImplementedError(_node_debug(node.dim_quals),
                                   str(dim_quals))
     _ = self.visit(node.coord)
     return name, typed_ast3.Subscript(
         value=typed_ast3.Attribute(value=typed_ast3.Name(
             id='st', ctx=typed_ast3.Load()),
                                    attr='ndarray',
                                    ctx=typed_ast3.Load()),
         slice=typed_ast3.ExtSlice(dims=[
             typed_ast3.Index(value=typed_ast3.Ellipsis()),
             typed_ast3.Index(value=type_)  # ,
             # typed_ast3.Index(value=typed_ast3.Tuple(n=-1))
         ]),
         ctx=typed_ast3.Load())
Exemplo n.º 2
0
def _transform_print_call(call):
    if not hasattr(call, 'fortran_metadata'):
        call.fortran_metadata = {}
    call.fortran_metadata['is_transformed'] = True
    if len(call.args) == 1:
        arg = call.args[0]
        if isinstance(arg, typed_ast3.Call) and isinstance(
                arg.func, typed_ast3.Attribute):
            label = int(arg.func.value.id.replace('format_label_', ''))
            call.args = [typed_ast3.Num(n=label)] + arg.args
            return call
    call.args.insert(0, typed_ast3.Ellipsis())
    return call
Exemplo n.º 3
0
    def _Function(self, node: ET.Element):  # pylint: disable=invalid-name
        if not self.types.is_relevant(node):
            raise ContinueIteration()
        name = node.attrib['name']
        arguments = typed_ast3.arguments(
            args=self.transform_all_subnodes(node),
            vararg=None,
            kwonlyargs=[],
            kwarg=None,
            defaults=[],
            kw_defaults=[])

        body = [typed_ast3.Expr(value=typed_ast3.Ellipsis())]
        returns = self.types.resolved_types[node.attrib['returns']]
        return typed_ast3.FunctionDef(name=name,
                                      args=arguments,
                                      body=body,
                                      decorator_list=[],
                                      returns=returns)
Exemplo n.º 4
0
 def visit_Ellipsis(self, n):
     # ellipses in Python 2 only exist as a slice index
     return ast3.Index(ast3.Ellipsis(lineno=-1, col_offset=-1))