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