Commit b05b8fd8 authored by gsamain's avatar gsamain

Introduce 'activable' keyword

parent 4112265c
...@@ -820,10 +820,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -820,10 +820,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def generate_cyp_class_deferred_definitions(self, type_entries, code): def generate_cyp_class_deferred_definitions(self, type_entries, code):
for entry in type_entries: for entry in type_entries:
if entry.type.is_cyp_class: if entry.type.is_cyp_class:
# Generate acthon-specific classes if entry.type.activable:
self.generate_cyp_class_reifying_entries(entry, code) # Generate acthon-specific classes
self.generate_cyp_class_activated_class(entry, code) self.generate_cyp_class_reifying_entries(entry, code)
self.generate_cyp_class_activate_function(entry, code) self.generate_cyp_class_activated_class(entry, code)
self.generate_cyp_class_activate_function(entry, code)
# Generate cypclass attr destructor # Generate cypclass attr destructor
self.generate_cyp_class_attrs_destructor_definition(entry, code) self.generate_cyp_class_attrs_destructor_definition(entry, code)
# Generate wrapper constructor # Generate wrapper constructor
......
...@@ -1522,7 +1522,7 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode): ...@@ -1522,7 +1522,7 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
error(self.pos, "Required template parameters must precede optional template parameters.") error(self.pos, "Required template parameters must precede optional template parameters.")
self.entry = env.declare_cpp_class( self.entry = env.declare_cpp_class(
self.name, None, self.pos, self.cname, self.name, None, self.pos, self.cname,
base_classes=[], visibility=self.visibility, templates=template_types, cypclass=self.cypclass, lock_mode=self.lock_mode) base_classes=[], visibility=self.visibility, templates=template_types, cypclass=self.cypclass, lock_mode=self.lock_mode, activable=self.activable)
def analyse_declarations(self, env): def analyse_declarations(self, env):
if self.templates is None: if self.templates is None:
...@@ -1549,7 +1549,8 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode): ...@@ -1549,7 +1549,8 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
base_class_types = filter(base_ok, base_types_list) base_class_types = filter(base_ok, base_types_list)
self.entry = env.declare_cpp_class( self.entry = env.declare_cpp_class(
self.name, scope, self.pos, self.name, scope, self.pos,
self.cname, base_class_types, visibility=self.visibility, templates=template_types, cypclass=self.cypclass, lock_mode=self.lock_mode) self.cname, base_class_types, visibility=self.visibility, templates=template_types,
cypclass=self.cypclass, lock_mode=self.lock_mode, activable=self.activable)
if self.entry is None: if self.entry is None:
return return
self.entry.is_cpp_class = 1 self.entry.is_cpp_class = 1
......
...@@ -3798,8 +3798,10 @@ def p_cpp_class_definition(s, pos, ctx): ...@@ -3798,8 +3798,10 @@ def p_cpp_class_definition(s, pos, ctx):
error(s.position(), "Name options not allowed for C++ class") error(s.position(), "Name options not allowed for C++ class")
nogil = p_nogil(s) or cypclass nogil = p_nogil(s) or cypclass
lock_mode = None lock_mode = None
activable = False
if cypclass: if cypclass:
lock_mode = p_cypclass_lock_mode(s) lock_mode = p_cypclass_lock_mode(s)
activable = p_cypclass_activable(s)
if s.sy == ':': if s.sy == ':':
s.next() s.next()
s.expect('NEWLINE') s.expect('NEWLINE')
...@@ -3825,7 +3827,7 @@ def p_cpp_class_definition(s, pos, ctx): ...@@ -3825,7 +3827,7 @@ def p_cpp_class_definition(s, pos, ctx):
visibility = ctx.visibility, visibility = ctx.visibility,
in_pxd = ctx.level == 'module_pxd', in_pxd = ctx.level == 'module_pxd',
attributes = attributes, attributes = attributes,
templates = templates, cypclass=cypclass, lock_mode=lock_mode) templates = templates, cypclass=cypclass, lock_mode=lock_mode, activable=activable)
def p_cpp_class_attribute(s, ctx): def p_cpp_class_attribute(s, ctx):
decorators = None decorators = None
...@@ -3859,6 +3861,12 @@ def p_cypclass_lock_mode(s): ...@@ -3859,6 +3861,12 @@ def p_cypclass_lock_mode(s):
else: else:
return None return None
def p_cypclass_activable(s):
if s.sy == 'IDENT' and s.systring == 'activable':
s.next()
return True
else:
return False
#---------------------------------------------- #----------------------------------------------
# #
......
...@@ -3900,9 +3900,10 @@ class CypClassType(CppClassType): ...@@ -3900,9 +3900,10 @@ class CypClassType(CppClassType):
is_cyp_class = 1 is_cyp_class = 1
def __init__(self, name, scope, cname, base_classes, templates=None, template_type=None, nogil=0, lock_mode=None): def __init__(self, name, scope, cname, base_classes, templates=None, template_type=None, nogil=0, lock_mode=None, activable=False):
CppClassType.__init__(self, name, scope, cname, base_classes, templates, template_type, nogil) CppClassType.__init__(self, name, scope, cname, base_classes, templates, template_type, nogil)
self.lock_mode = lock_mode if lock_mode else "autolock" self.lock_mode = lock_mode if lock_mode else "autolock"
self.activable = activable
def empty_declaration_code(self): def empty_declaration_code(self):
if self._empty_declaration is None: if self._empty_declaration is None:
......
...@@ -628,7 +628,7 @@ class Scope(object): ...@@ -628,7 +628,7 @@ class Scope(object):
def declare_cpp_class(self, name, scope, def declare_cpp_class(self, name, scope,
pos, cname = None, base_classes = (), pos, cname = None, base_classes = (),
visibility = 'extern', templates = None, cypclass=0, lock_mode=None): visibility = 'extern', templates = None, cypclass=0, lock_mode=None, activable=False):
if cname is None: if cname is None:
if self.in_cinclude or (visibility != 'private'): if self.in_cinclude or (visibility != 'private'):
cname = name cname = name
...@@ -639,7 +639,7 @@ class Scope(object): ...@@ -639,7 +639,7 @@ class Scope(object):
if not entry: if not entry:
if cypclass: if cypclass:
type = PyrexTypes.CypClassType( type = PyrexTypes.CypClassType(
name, scope, cname, base_classes, templates = templates, lock_mode=lock_mode) name, scope, cname, base_classes, templates = templates, lock_mode=lock_mode, activable=activable)
else: else:
type = PyrexTypes.CppClassType( type = PyrexTypes.CppClassType(
name, scope, cname, base_classes, templates = templates) name, scope, cname, base_classes, templates = templates)
...@@ -707,20 +707,21 @@ class Scope(object): ...@@ -707,20 +707,21 @@ class Scope(object):
alloc_entry.is_builtin_cmethod = 1 alloc_entry.is_builtin_cmethod = 1
alloc_entry.func_cname = "%s::%s" % (entry.type.empty_declaration_code(), alloc_cname) alloc_entry.func_cname = "%s::%s" % (entry.type.empty_declaration_code(), alloc_cname)
# === Acthon === if entry.type.activable:
# Declare activated class # === Acthon ===
act_scope = CppClassScope("Activated", scope) # Declare activated class
act_type = PyrexTypes.CypClassType( act_scope = CppClassScope("Activated", scope)
"Activated", act_scope, "Activated", None, templates = templates, lock_mode="nolock") act_type = PyrexTypes.CypClassType(
act_type.set_scope(act_scope) "Activated", act_scope, "Activated", None, templates = templates, lock_mode="nolock")
act_type.namespace = entry.type act_type.set_scope(act_scope)
#scope.declare_cpp_class("Activated", act_scope, pos) act_type.namespace = entry.type
scope.declare("Activated", "Activated", act_type, pos, visibility) #scope.declare_cpp_class("Activated", act_scope, pos)
# Declaring active_self member and activate function (its definition is generated automatically) scope.declare("Activated", "Activated", act_type, pos, visibility)
act_attr_name = Naming.builtin_prefix + "_active_self" # Declaring active_self member and activate function (its definition is generated automatically)
scope.declare_var("<active_self>", act_type, pos, cname=act_attr_name) act_attr_name = Naming.builtin_prefix + "_active_self"
activate_type = PyrexTypes.CFuncType(act_type, []) scope.declare_var("<active_self>", act_type, pos, cname=act_attr_name)
scope.declare_var("__activate__", activate_type, pos, cname="__activate__", defining = 1) activate_type = PyrexTypes.CFuncType(act_type, [])
scope.declare_var("__activate__", activate_type, pos, cname="__activate__", defining = 1)
if self.is_cpp_class_scope: if self.is_cpp_class_scope:
entry.type.namespace = self.outer_scope.lookup(self.name).type entry.type.namespace = self.outer_scope.lookup(self.name).type
...@@ -2579,7 +2580,7 @@ class CppClassScope(Scope): ...@@ -2579,7 +2580,7 @@ class CppClassScope(Scope):
def declare_cfunction(self, name, type, pos, def declare_cfunction(self, name, type, pos,
cname=None, visibility='extern', api=0, in_pxd=0, cname=None, visibility='extern', api=0, in_pxd=0,
defining=0, modifiers=(), utility_code=None, overridable=False): defining=0, modifiers=(), utility_code=None, overridable=False):
reify = self.type.is_cyp_class reify = self.type.is_cyp_class and self.type.activable
class_name = self.name.split('::')[-1] class_name = self.name.split('::')[-1]
if name in (class_name, '__init__') and cname is None: if name in (class_name, '__init__') and cname is None:
reify = False reify = False
......
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