Commit d48da4fd authored by Stefan Behnel's avatar Stefan Behnel

clean up some code

parent b47fb4d0
from Visitor import CythonTransform from Cython.Compiler.Visitor import CythonTransform
from ModuleNode import ModuleNode from Cython.Compiler.ModuleNode import ModuleNode
from ExprNodes import * from Cython.Compiler.Errors import CompileError
from Errors import CompileError from Cython.Compiler.UtilityCode import CythonUtilityCode
from UtilityCode import CythonUtilityCode from Cython.Compiler.Code import UtilityCode, TempitaUtilityCode
from Code import UtilityCode, TempitaUtilityCode
import Interpreter from Cython.Compiler import Options
import PyrexTypes from Cython.Compiler import Interpreter
import Naming from Cython.Compiler import PyrexTypes
import Symtab from Cython.Compiler import Naming
from Cython.Compiler import Symtab
def dedent(text, reindent=0): def dedent(text, reindent=0):
......
This diff is collapsed.
This diff is collapsed.
...@@ -447,7 +447,7 @@ class MemoryViewSliceType(PyrexType): ...@@ -447,7 +447,7 @@ class MemoryViewSliceType(PyrexType):
has_attributes = 1 has_attributes = 1
scope = None scope = None
# These are specialcased in Defnode # These are special cased in Defnode
from_py_function = None from_py_function = None
to_py_function = None to_py_function = None
...@@ -457,7 +457,7 @@ class MemoryViewSliceType(PyrexType): ...@@ -457,7 +457,7 @@ class MemoryViewSliceType(PyrexType):
subtypes = ['dtype'] subtypes = ['dtype']
def __init__(self, base_dtype, axes): def __init__(self, base_dtype, axes):
''' """
MemoryViewSliceType(base, axes) MemoryViewSliceType(base, axes)
Base is the C base type; axes is a list of (access, packing) strings, Base is the C base type; axes is a list of (access, packing) strings,
...@@ -489,7 +489,7 @@ class MemoryViewSliceType(PyrexType): ...@@ -489,7 +489,7 @@ class MemoryViewSliceType(PyrexType):
Fortran-contiguous memory has 'direct' as the access spec, 'contig' as Fortran-contiguous memory has 'direct' as the access spec, 'contig' as
the *first* axis' packing spec and 'follow' for all other packing the *first* axis' packing spec and 'follow' for all other packing
specs. specs.
''' """
import MemoryView import MemoryView
self.dtype = base_dtype self.dtype = base_dtype
...@@ -684,8 +684,6 @@ class MemoryViewSliceType(PyrexType): ...@@ -684,8 +684,6 @@ class MemoryViewSliceType(PyrexType):
return "__pyx_memoryview_fromslice(%s, %s, %s, %s, %d);" % tup return "__pyx_memoryview_fromslice(%s, %s, %s, %s, %d);" % tup
def dtype_object_conversion_funcs(self, env): def dtype_object_conversion_funcs(self, env):
import MemoryView, Code
get_function = "__pyx_memview_get_%s" % self.dtype_name get_function = "__pyx_memview_get_%s" % self.dtype_name
set_function = "__pyx_memview_set_%s" % self.dtype_name set_function = "__pyx_memview_set_%s" % self.dtype_name
...@@ -724,13 +722,13 @@ class MemoryViewSliceType(PyrexType): ...@@ -724,13 +722,13 @@ class MemoryViewSliceType(PyrexType):
return get_function, set_function return get_function, set_function
def axes_to_code(self): def axes_to_code(self):
"Return a list of code constants for each axis" """Return a list of code constants for each axis"""
import MemoryView import MemoryView
d = MemoryView._spec_to_const d = MemoryView._spec_to_const
return ["(%s | %s)" % (d[a], d[p]) for a, p in self.axes] return ["(%s | %s)" % (d[a], d[p]) for a, p in self.axes]
def axes_to_name(self): def axes_to_name(self):
"Return an abbreviated name for our axes" """Return an abbreviated name for our axes"""
import MemoryView import MemoryView
d = MemoryView._spec_to_abbrev d = MemoryView._spec_to_abbrev
return "".join(["%s%s" % (d[a], d[p]) for a, p in self.axes]) return "".join(["%s%s" % (d[a], d[p]) for a, p in self.axes])
...@@ -763,7 +761,7 @@ class MemoryViewSliceType(PyrexType): ...@@ -763,7 +761,7 @@ class MemoryViewSliceType(PyrexType):
return "%s[%s]" % (dtype_name, ", ".join(axes_code_list)) return "%s[%s]" % (dtype_name, ", ".join(axes_code_list))
def specialize(self, values): def specialize(self, values):
"This does not validate the base type!!" """This does not validate the base type!!"""
dtype = self.dtype.specialize(values) dtype = self.dtype.specialize(values)
if dtype is not self.dtype: if dtype is not self.dtype:
return MemoryViewSliceType(dtype, self.axes) return MemoryViewSliceType(dtype, self.axes)
...@@ -868,7 +866,7 @@ class PyObjectType(PyrexType): ...@@ -868,7 +866,7 @@ class PyObjectType(PyrexType):
return True return True
def default_coerced_ctype(self): def default_coerced_ctype(self):
"The default C type that this Python type coerces to, or None." """The default C type that this Python type coerces to, or None."""
return None return None
def assignable_from(self, src_type): def assignable_from(self, src_type):
...@@ -990,7 +988,7 @@ class BuiltinObjectType(PyObjectType): ...@@ -990,7 +988,7 @@ class BuiltinObjectType(PyObjectType):
type_check = self.type_check_function(exact=True) type_check = self.type_check_function(exact=True)
check = 'likely(%s(%s))' % (type_check, arg) check = 'likely(%s(%s))' % (type_check, arg)
if not notnone: if not notnone:
check = check + ('||((%s) == Py_None)' % arg) check += '||((%s) == Py_None)' % arg
error = '(PyErr_Format(PyExc_TypeError, "Expected %s, got %%.200s", Py_TYPE(%s)->tp_name), 0)' % (self.name, arg) error = '(PyErr_Format(PyExc_TypeError, "Expected %s, got %%.200s", Py_TYPE(%s)->tp_name), 0)' % (self.name, arg)
return check + '||' + error return check + '||' + error
...@@ -1198,7 +1196,7 @@ class CConstType(BaseType): ...@@ -1198,7 +1196,7 @@ class CConstType(BaseType):
if base_type == self.const_base_type: if base_type == self.const_base_type:
return self return self
else: else:
return ConstType(base_type) return CConstType(base_type)
def create_to_py_utility_code(self, env): def create_to_py_utility_code(self, env):
if self.const_base_type.create_to_py_utility_code(env): if self.const_base_type.create_to_py_utility_code(env):
...@@ -1330,7 +1328,7 @@ class CNumericType(CType): ...@@ -1330,7 +1328,7 @@ class CNumericType(CType):
visibility="extern") visibility="extern")
scope.parent_type = self scope.parent_type = self
scope.directives = {} scope.directives = {}
entry = scope.declare_cfunction( scope.declare_cfunction(
"conjugate", "conjugate",
CFuncType(self, [CFuncTypeArg("self", self, None)], nogil=True), CFuncType(self, [CFuncTypeArg("self", self, None)], nogil=True),
pos=None, pos=None,
...@@ -1339,7 +1337,7 @@ class CNumericType(CType): ...@@ -1339,7 +1337,7 @@ class CNumericType(CType):
return True return True
def __lt__(self, other): def __lt__(self, other):
"Sort based on rank, preferring signed over unsigned" """Sort based on rank, preferring signed over unsigned"""
if other.is_numeric: if other.is_numeric:
return self.rank > other.rank and self.signed >= other.signed return self.rank > other.rank and self.signed >= other.signed
...@@ -1928,7 +1926,7 @@ class CComplexType(CNumericType): ...@@ -1928,7 +1926,7 @@ class CComplexType(CNumericType):
scope.directives = {} scope.directives = {}
scope.declare_var("real", self.real_type, None, cname="real", is_cdef=True) scope.declare_var("real", self.real_type, None, cname="real", is_cdef=True)
scope.declare_var("imag", self.real_type, None, cname="imag", is_cdef=True) scope.declare_var("imag", self.real_type, None, cname="imag", is_cdef=True)
entry = scope.declare_cfunction( scope.declare_cfunction(
"conjugate", "conjugate",
CFuncType(self, [CFuncTypeArg("self", self, None)], nogil=True), CFuncType(self, [CFuncTypeArg("self", self, None)], nogil=True),
pos=None, pos=None,
...@@ -2790,7 +2788,7 @@ class CFuncType(CType): ...@@ -2790,7 +2788,7 @@ class CFuncType(CType):
return result return result
def get_fused_types(self, result=None, seen=None, subtypes=None): def get_fused_types(self, result=None, seen=None, subtypes=None):
"Return fused types in the order they appear as parameter types" """Return fused types in the order they appear as parameter types"""
return super(CFuncType, self).get_fused_types(result, seen, return super(CFuncType, self).get_fused_types(result, seen,
subtypes=['args']) subtypes=['args'])
...@@ -3223,8 +3221,8 @@ class CppClassType(CType): ...@@ -3223,8 +3221,8 @@ class CppClassType(CType):
def specialize_here(self, pos, template_values = None): def specialize_here(self, pos, template_values = None):
if self.templates is None: if self.templates is None:
error(pos, "'%s' type is not a template" % self); error(pos, "'%s' type is not a template" % self)
return PyrexTypes.error_type return error_type
if len(self.templates) != len(template_values): if len(self.templates) != len(template_values):
error(pos, "%s templated type receives %d arguments, got %d" % error(pos, "%s templated type receives %d arguments, got %d" %
(self.name, len(self.templates), len(template_values))) (self.name, len(self.templates), len(template_values)))
...@@ -3625,8 +3623,6 @@ def best_match(args, functions, pos=None, env=None): ...@@ -3625,8 +3623,6 @@ def best_match(args, functions, pos=None, env=None):
the same weight, we return None (as there is no best match). If pos the same weight, we return None (as there is no best match). If pos
is not None, we also generate an error. is not None, we also generate an error.
""" """
from Cython import Utils
# TODO: args should be a list of types, not a list of Nodes. # TODO: args should be a list of types, not a list of Nodes.
actual_nargs = len(args) actual_nargs = len(args)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment