Commit 80e9ca42 authored by Robert Bradshaw's avatar Robert Bradshaw

Complex type parsing, very basic support if supported by C compiler

parent adcd8939
......@@ -674,6 +674,7 @@ class CSimpleBaseTypeNode(CBaseTypeNode):
# is_basic_c_type boolean
# signed boolean
# longness integer
# complex boolean
# is_self_arg boolean Is self argument of C method
child_attrs = []
......@@ -714,6 +715,8 @@ class CSimpleBaseTypeNode(CBaseTypeNode):
self.arg_name = self.name
else:
error(self.pos, "'%s' is not a type identifier" % self.name)
if self.complex:
type = PyrexTypes.CCompelxType(type)
if type:
return type
else:
......
......@@ -1692,6 +1692,7 @@ def p_c_simple_base_type(s, self_flag, nonempty):
is_basic = 0
signed = 1
longness = 0
complex = 0
module_path = []
pos = s.position()
if not s.sy == 'IDENT':
......@@ -1710,6 +1711,9 @@ def p_c_simple_base_type(s, self_flag, nonempty):
s.next()
else:
name = 'int'
if s.sy == 'IDENT' and s.systring == 'complex':
complex = 1
s.next()
elif looking_at_dotted_name(s):
#print "p_c_simple_base_type: looking_at_type_name at", s.position()
name = s.systring
......@@ -1738,7 +1742,8 @@ def p_c_simple_base_type(s, self_flag, nonempty):
type_node = Nodes.CSimpleBaseTypeNode(pos,
name = name, module_path = module_path,
is_basic_c_type = is_basic, signed = signed,
longness = longness, is_self_arg = self_flag)
complex = complex, longness = longness,
is_self_arg = self_flag)
# Treat trailing [] on type as buffer access if it appears in a context
......
......@@ -33,6 +33,7 @@ class PyrexType(BaseType):
# is_int boolean Is a C integer type
# is_longlong boolean Is a long long or unsigned long long.
# is_float boolean Is a C floating point type
# is_complex boolean Is a C complex type
# is_void boolean Is the C void type
# is_array boolean Is a C array type
# is_ptr boolean Is a C pointer type
......@@ -83,6 +84,7 @@ class PyrexType(BaseType):
is_int = 0
is_longlong = 0
is_float = 0
is_complex = 0
is_void = 0
is_array = 0
is_ptr = 0
......@@ -698,7 +700,24 @@ class CFloatType(CNumericType):
self.math_h_modifier = math_h_modifier
def assignable_from_resolved_type(self, src_type):
return src_type.is_numeric or src_type is error_type
return (src_type.is_numeric and not src_type.is_complex) or src_type is error_type
class CCompelxType(CNumericType):
is_complex = 1
def __init__(self, real_type):
self.real_type = real_type
CNumericType.__init__(self, real_type.rank + 0.5, real_type.signed)
def sign_and_name(self):
return self.real_type.sign_and_name() + " complex"
def assignable_from_resolved_type(self, src_type):
return (src_type.is_complex and self.real_type.assignable_from_resolved_type(src_type.real_type)
or src_type.is_numeric and self.real_type.assignable_from_resolved_type(src_type)
or src_type is error_type)
class CArrayType(CType):
......@@ -1615,3 +1634,5 @@ static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
}
""" + type_conversion_functions
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