Commit 3d681d3e authored by Xavier Thompson's avatar Xavier Thompson

Fix viewpoint adaptation of the fields of and 'iso' cypclass

parent 8f14ad8c
...@@ -11379,8 +11379,8 @@ class ConsumeNode(ExprNode): ...@@ -11379,8 +11379,8 @@ class ConsumeNode(ExprNode):
self.type = PyrexTypes.error_type self.type = PyrexTypes.error_type
return self return self
if operand_type.is_qualified_cyp_class: if operand_type.is_qualified_cyp_class:
if operand_type.qualifier == 'iso!': if operand_type.qualifier == 'iso&':
error(self.pos, "Cannot consume iso!") error(self.pos, "Cannot consume iso&")
self.type = PyrexTypes.error_type self.type = PyrexTypes.error_type
return self return self
self.generate_runtime_check = operand_type.qualifier not in ('iso', 'iso~') self.generate_runtime_check = operand_type.qualifier not in ('iso', 'iso~')
......
...@@ -4802,7 +4802,7 @@ class ConstCypclassType(BaseType): ...@@ -4802,7 +4802,7 @@ class ConstCypclassType(BaseType):
class QualifiedCypclassType(BaseType): class QualifiedCypclassType(BaseType):
"A qualified cypclass reference" "A qualified cypclass reference"
# qualifier string the qualifier keyword: ('active' | 'iso' | 'iso~' | 'iso!' ) # qualifier string the qualifier keyword: ('active' | 'iso' | 'iso~' | 'iso&' )
subtypes = ['qual_base_type'] subtypes = ['qual_base_type']
...@@ -4813,7 +4813,7 @@ class QualifiedCypclassType(BaseType): ...@@ -4813,7 +4813,7 @@ class QualifiedCypclassType(BaseType):
'active': ('active', 'iso~'), 'active': ('active', 'iso~'),
'iso': ('iso~',), 'iso': ('iso~',),
'iso~': (), 'iso~': (),
'iso!': (), 'iso&': ('iso~',),
} }
def __init__(self, base_type, qualifier): def __init__(self, base_type, qualifier):
...@@ -5823,6 +5823,14 @@ def qualified_method_type(base_type, const, volatile): ...@@ -5823,6 +5823,14 @@ def qualified_method_type(base_type, const, volatile):
else: else:
return QualifiedMethodType(base_type, const, volatile) return QualifiedMethodType(base_type, const, volatile)
def viewpoint_adaptation(base_type, qualifier = 'iso&'):
# Perform viewpoint adaptation for cypclass types.
if base_type.is_qualified_cyp_class:
return base_type
if base_type.is_cyp_class:
return QualifiedCypclassType(base_type, qualifier)
return base_type
def same_type(type1, type2): def same_type(type1, type2):
return type1.same_as(type2) return type1.same_as(type2)
......
...@@ -17,7 +17,8 @@ from .Errors import warning, error, InternalError ...@@ -17,7 +17,8 @@ from .Errors import warning, error, InternalError
from .StringEncoding import EncodedString from .StringEncoding import EncodedString
from . import Options, Naming from . import Options, Naming
from . import PyrexTypes from . import PyrexTypes
from .PyrexTypes import py_object_type, cy_object_type, unspecified_type from .PyrexTypes import (
py_object_type, cy_object_type, unspecified_type, viewpoint_adaptation)
from .TypeSlots import ( from .TypeSlots import (
pyfunction_signature, pymethod_signature, richcmp_special_methods, pyfunction_signature, pymethod_signature, richcmp_special_methods,
get_special_method_signature, get_property_accessor_signature) get_special_method_signature, get_property_accessor_signature)
...@@ -3297,25 +3298,14 @@ class IsoCypclassScope(QualifiedCypclassScope): ...@@ -3297,25 +3298,14 @@ class IsoCypclassScope(QualifiedCypclassScope):
def __init__(self, base_type_scope): def __init__(self, base_type_scope):
QualifiedCypclassScope.__init__(self, base_type_scope, 'iso') QualifiedCypclassScope.__init__(self, base_type_scope, 'iso')
def adapt(self, fieldtype, qualifier='iso'):
if fieldtype.is_qualified_cyp_class:
# attribute is sendable (either 'iso' or 'active')
return fieldtype
elif fieldtype.is_cyp_class:
# viewpoint adaptation
return PyrexTypes.cyp_class_qualified_type(fieldtype, qualifier)
else:
return fieldtype
def adapt_arg_type(self, arg): def adapt_arg_type(self, arg):
arg = copy.copy(arg) arg = copy.copy(arg)
arg.type = self.adapt(arg.type) arg.type = viewpoint_adaptation(arg.type)
return arg return arg
def adapt_method_entry(self, base_entry): def adapt_method_entry(self, base_entry):
iso_method_type = copy.copy(base_entry.type) iso_method_type = copy.copy(base_entry.type)
# The return type should be treated as 'iso' but cannot be consumed return_type = viewpoint_adaptation(base_entry.type.return_type)
return_type = self.adapt(base_entry.type.return_type, qualifier='iso!')
iso_method_type.return_type = return_type iso_method_type.return_type = return_type
iso_method_type.args = [self.adapt_arg_type(arg) for arg in base_entry.type.args] iso_method_type.args = [self.adapt_arg_type(arg) for arg in base_entry.type.args]
if hasattr(base_entry.type, 'op_arg_struct'): if hasattr(base_entry.type, 'op_arg_struct'):
...@@ -3339,7 +3329,7 @@ class IsoCypclassScope(QualifiedCypclassScope): ...@@ -3339,7 +3329,7 @@ class IsoCypclassScope(QualifiedCypclassScope):
return iso_alternatives[0] return iso_alternatives[0]
else: else:
base_entry_type = base_entry.type base_entry_type = base_entry.type
adapted_type = self.adapt(base_entry_type) adapted_type = viewpoint_adaptation(base_entry_type)
if adapted_type is base_entry_type: if adapted_type is base_entry_type:
return base_entry return base_entry
else: else:
......
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