Commit 5ea4b23c authored by Xavier Thompson's avatar Xavier Thompson

Introduce 'locked&' qualifier

parent 34a5e359
...@@ -782,6 +782,8 @@ class CFuncDeclaratorNode(CDeclaratorNode): ...@@ -782,6 +782,8 @@ class CFuncDeclaratorNode(CDeclaratorNode):
exc_check = self.exception_check exc_check = self.exception_check
if return_type.is_cfunction: if return_type.is_cfunction:
error(self.pos, "Function cannot return a function") error(self.pos, "Function cannot return a function")
if return_type.is_qualified_cyp_class and return_type.qualifier in ('locked&',):
error(self.pos, "Function cannot return a 'locked&' qualifier")
func_type = PyrexTypes.CFuncType( func_type = PyrexTypes.CFuncType(
return_type, func_type_args, self.has_varargs, return_type, func_type_args, self.has_varargs,
optional_arg_count=self.optional_arg_count, optional_arg_count=self.optional_arg_count,
...@@ -1370,6 +1372,9 @@ class QualifiedCypclassNode(CBaseTypeNode): ...@@ -1370,6 +1372,9 @@ class QualifiedCypclassNode(CBaseTypeNode):
if not base.is_cyp_class: if not base.is_cyp_class:
error(self.pos, "Qualifier '%s' can only apply to cypclass types" % self.qualifier) error(self.pos, "Qualifier '%s' can only apply to cypclass types" % self.qualifier)
return base return base
# if self.qualifier in ('locked&',) and env.return_type is None:
# error(self.pos, "Qualifier '%s' can only be used inside functions" % self.qualifier)
# return base
return PyrexTypes.cyp_class_qualified_type(base, self.qualifier) return PyrexTypes.cyp_class_qualified_type(base, self.qualifier)
...@@ -1502,6 +1507,9 @@ class CVarDefNode(StatNode): ...@@ -1502,6 +1507,9 @@ class CVarDefNode(StatNode):
else: else:
if self.directive_locals: if self.directive_locals:
error(self.pos, "Decorators can only be followed by functions") error(self.pos, "Decorators can only be followed by functions")
if base_type.is_qualified_cyp_class and base_type.qualifier in ('locked&', ) and env.return_type is None:
error(self.pos, "'locked&' variables are only allowed inside a function")
return error_type
self.entry = dest_scope.declare_var( self.entry = dest_scope.declare_var(
name, type, declarator.pos, name, type, declarator.pos,
cname=cname, visibility=visibility, in_pxd=self.in_pxd, cname=cname, visibility=visibility, in_pxd=self.in_pxd,
......
...@@ -2548,6 +2548,9 @@ def p_c_simple_base_type(s, self_flag, nonempty, templates = None): ...@@ -2548,6 +2548,9 @@ def p_c_simple_base_type(s, self_flag, nonempty, templates = None):
if s.sy == 'IDENT' and s.systring in ('active', 'iso', 'locked'): if s.sy == 'IDENT' and s.systring in ('active', 'iso', 'locked'):
qualifier = s.systring qualifier = s.systring
s.next() s.next()
if s.sy == '&' and qualifier in ('locked',):
qualifier = "%s&" % qualifier
s.next()
base_type = p_c_base_type(s, self_flag=self_flag, nonempty=nonempty, templates=templates) base_type = p_c_base_type(s, self_flag=self_flag, nonempty=nonempty, templates=templates)
return Nodes.QualifiedCypclassNode(pos, base_type=base_type, qualifier=qualifier) return Nodes.QualifiedCypclassNode(pos, base_type=base_type, qualifier=qualifier)
......
...@@ -4860,7 +4860,8 @@ class QualifiedCypclassType(BaseType): ...@@ -4860,7 +4860,8 @@ class QualifiedCypclassType(BaseType):
'iso': ('iso~',), 'iso': ('iso~',),
'iso~': (), 'iso~': (),
'iso->': ('iso~',), 'iso->': ('iso~',),
'locked': ('locked', 'iso~'), 'locked': ('locked', 'locked&', 'iso~'),
'locked&': ('locked&', 'iso~'),
} }
def __new__(cls, base_type, qualifier): def __new__(cls, base_type, qualifier):
......
...@@ -3318,8 +3318,8 @@ def qualified_cypclass_scope(base_type_scope, qualifier): ...@@ -3318,8 +3318,8 @@ def qualified_cypclass_scope(base_type_scope, qualifier):
return ActiveCypclassScope(base_type_scope) return ActiveCypclassScope(base_type_scope)
elif qualifier.startswith('iso'): elif qualifier.startswith('iso'):
return IsoCypclassScope(base_type_scope, qualifier) return IsoCypclassScope(base_type_scope, qualifier)
elif qualifier == 'locked': elif qualifier.startswith('locked'):
return IsoCypclassScope(base_type_scope, 'locked') return IsoCypclassScope(base_type_scope, qualifier)
else: else:
return QualifiedCypclassScope(base_type_scope, qualifier) return QualifiedCypclassScope(base_type_scope, qualifier)
...@@ -3346,6 +3346,8 @@ class IsoCypclassScope(QualifiedCypclassScope): ...@@ -3346,6 +3346,8 @@ class IsoCypclassScope(QualifiedCypclassScope):
if base_type.self_qualifier: if base_type.self_qualifier:
if self.qualifier in PyrexTypes.QualifiedCypclassType.assignable_to[base_type.self_qualifier]: if self.qualifier in PyrexTypes.QualifiedCypclassType.assignable_to[base_type.self_qualifier]:
return base_entry return base_entry
elif base_type.self_qualifier == 'locked&' and self.qualifier == 'locked':
return base_entry
else: else:
return None return None
iso_method_type = copy.copy(base_type) iso_method_type = copy.copy(base_type)
......
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