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

Introduce 'locked&' qualifier

parent 34a5e359
......@@ -782,6 +782,8 @@ class CFuncDeclaratorNode(CDeclaratorNode):
exc_check = self.exception_check
if return_type.is_cfunction:
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(
return_type, func_type_args, self.has_varargs,
optional_arg_count=self.optional_arg_count,
......@@ -1370,6 +1372,9 @@ class QualifiedCypclassNode(CBaseTypeNode):
if not base.is_cyp_class:
error(self.pos, "Qualifier '%s' can only apply to cypclass types" % self.qualifier)
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)
......@@ -1502,6 +1507,9 @@ class CVarDefNode(StatNode):
else:
if self.directive_locals:
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(
name, type, declarator.pos,
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):
if s.sy == 'IDENT' and s.systring in ('active', 'iso', 'locked'):
qualifier = s.systring
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)
return Nodes.QualifiedCypclassNode(pos, base_type=base_type, qualifier=qualifier)
......
......@@ -4860,7 +4860,8 @@ class QualifiedCypclassType(BaseType):
'iso': ('iso~',),
'iso~': (),
'iso->': ('iso~',),
'locked': ('locked', 'iso~'),
'locked': ('locked', 'locked&', 'iso~'),
'locked&': ('locked&', 'iso~'),
}
def __new__(cls, base_type, qualifier):
......
......@@ -3318,8 +3318,8 @@ def qualified_cypclass_scope(base_type_scope, qualifier):
return ActiveCypclassScope(base_type_scope)
elif qualifier.startswith('iso'):
return IsoCypclassScope(base_type_scope, qualifier)
elif qualifier == 'locked':
return IsoCypclassScope(base_type_scope, 'locked')
elif qualifier.startswith('locked'):
return IsoCypclassScope(base_type_scope, qualifier)
else:
return QualifiedCypclassScope(base_type_scope, qualifier)
......@@ -3346,6 +3346,8 @@ class IsoCypclassScope(QualifiedCypclassScope):
if base_type.self_qualifier:
if self.qualifier in PyrexTypes.QualifiedCypclassType.assignable_to[base_type.self_qualifier]:
return base_entry
elif base_type.self_qualifier == 'locked&' and self.qualifier == 'locked':
return base_entry
else:
return None
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