Commit 0bb6f98b authored by Xavier Thompson's avatar Xavier Thompson

Disallow 'const' qualifier for cypclass types

parent 608c29a9
......@@ -431,7 +431,6 @@ def inject_acthon_interfaces(self):
result_scope.var_entries.append(result_pushVoidStar_entry)
result_getVoidStar_type = PyrexTypes.CFuncType(PyrexTypes.c_void_ptr_type, [], nogil = 1)
result_getVoidStar_type.is_const_method = 1
result_getVoidStar_entry = result_scope.declare("getVoidStarResult", "getVoidStarResult",
result_getVoidStar_type, None, "extern")
result_getVoidStar_entry.is_cfunction = 1
......@@ -447,7 +446,6 @@ def inject_acthon_interfaces(self):
result_scope.var_entries.append(result_pushInt_entry)
result_getInt_type = PyrexTypes.CFuncType(PyrexTypes.c_int_type, [], nogil = 1)
result_getInt_type.is_const_method = 1
result_getInt_entry = result_scope.declare("getIntResult", "getIntResult",
result_getInt_type, None, "extern")
result_getInt_entry.is_cfunction = 1
......@@ -495,7 +493,6 @@ def inject_acthon_interfaces(self):
sync_entry.is_type = 1
sync_isActivable_type = PyrexTypes.CFuncType(PyrexTypes.c_bint_type, [], nogil = 1)
sync_isActivable_type.is_const_method = 1
sync_isActivable_entry = sync_scope.declare("isActivable", "isActivable",
sync_isActivable_type, None, "extern")
sync_isActivable_entry.is_cfunction = 1
......@@ -503,7 +500,6 @@ def inject_acthon_interfaces(self):
sync_scope.var_entries.append(sync_isActivable_entry)
sync_isCompleted_type = PyrexTypes.CFuncType(PyrexTypes.c_bint_type, [], nogil = 1)
sync_isCompleted_type.is_const_method = 1
sync_isCompleted_entry = sync_scope.declare("isCompleted", "isCompleted",
sync_isCompleted_type, None, "extern")
sync_isCompleted_entry.is_cfunction = 1
......@@ -578,7 +574,6 @@ def inject_acthon_interfaces(self):
queue_scope.var_entries.append(queue_activate_entry)
queue_is_empty_type = PyrexTypes.CFuncType(PyrexTypes.c_bint_type, [], nogil = 1)
queue_is_empty_type.is_const_method = 1
queue_is_empty_entry = queue_scope.declare("is_empty", "is_empty",
queue_is_empty_type, None, "extern")
queue_is_empty_entry.is_cfunction = 1
......@@ -654,21 +649,21 @@ def inject_cypclass_refcount_macros():
incref_type = PyrexTypes.CFuncType(
PyrexTypes.c_void_type,
[
PyrexTypes.CFuncTypeArg("obj", PyrexTypes.const_cy_object_type, None)
PyrexTypes.CFuncTypeArg("obj", PyrexTypes.cy_object_type, None)
],
nogil = 1)
decref_type = PyrexTypes.CFuncType(
PyrexTypes.c_void_type,
[
PyrexTypes.CFuncTypeArg("obj", PyrexTypes.CReferenceType(PyrexTypes.const_cy_object_type), None)
PyrexTypes.CFuncTypeArg("obj", PyrexTypes.CReferenceType(PyrexTypes.cy_object_type), None)
],
nogil = 1)
getref_type = PyrexTypes.CFuncType(
PyrexTypes.c_int_type,
[
PyrexTypes.CFuncTypeArg("obj", PyrexTypes.const_cy_object_type, None)
PyrexTypes.CFuncTypeArg("obj", PyrexTypes.cy_object_type, None)
],
nogil = 1)
......@@ -679,7 +674,7 @@ def inject_cypclass_lock_macros():
blocking_macro_type = PyrexTypes.CFuncType(
PyrexTypes.c_void_type,
[
PyrexTypes.CFuncTypeArg("obj", PyrexTypes.const_cy_object_type, None)
PyrexTypes.CFuncTypeArg("obj", PyrexTypes.cy_object_type, None)
],
nogil = 1)
for macro in ("Cy_RLOCK", "Cy_WLOCK", "Cy_UNWLOCK", "Cy_UNRLOCK"):
......@@ -687,7 +682,7 @@ def inject_cypclass_lock_macros():
nonblocking_macro_type = PyrexTypes.CFuncType(PyrexTypes.c_int_type,
[
PyrexTypes.CFuncTypeArg("obj", PyrexTypes.const_cy_object_type, None)
PyrexTypes.CFuncTypeArg("obj", PyrexTypes.cy_object_type, None)
],
nogil = 1)
for macro in ("Cy_TRYRLOCK", "Cy_TRYWLOCK"):
......@@ -698,7 +693,7 @@ def inject_cypclass_typecheck_functions():
isinstanceof_type = PyrexTypes.CFuncType(
PyrexTypes.c_int_type,
[
PyrexTypes.CFuncTypeArg("obj", PyrexTypes.const_cy_object_type, None),
PyrexTypes.CFuncTypeArg("obj", PyrexTypes.cy_object_type, None),
PyrexTypes.CFuncTypeArg("type", template_placeholder_type, None)
],
nogil = 1,
......
......@@ -2894,7 +2894,7 @@ class CppIteratorNode(ExprNode):
sequence_type = self.sequence.type
if sequence_type.is_ptr:
sequence_type = sequence_type.base_type
if sequence_type.is_const or sequence_type.is_const_cyp_class:
if sequence_type.is_const:
begin = sequence_type.scope.lookup("const_begin")
end = sequence_type.scope.lookup("const_end")
if not begin or begin.cname != "begin":
......@@ -13429,9 +13429,6 @@ class PrimaryCmpNode(ExprNode, CmpNode):
common_type = PyrexTypes.independent_spanning_type(type1, type2)
if common_type.is_error:
common_type = PyrexTypes.cy_object_type
if type1.is_const_cyp_class or type2.is_const_cyp_class:
if not common_type.is_const_cyp_class:
common_type = PyrexTypes.cyp_class_const_type(common_type)
# do not analyse the TypecastNode
# to ensure a simple pointer cast is used and not a user-defined conversion method
self.operand1 = TypecastNode(self.operand1.pos, operand=self.operand1, type=common_type)
......
......@@ -653,8 +653,6 @@ class CFuncDeclaratorNode(CDeclaratorNode):
directive_locals = {}
if nonempty:
nonempty -= 1
if self.is_const_method and env.is_cyp_class_scope:
error(self.pos, "The form 'f(self, ...) const' is not allowed for cypclass methods. Use 'f(const self, ...)' instead")
func_type_args = []
for i, arg_node in enumerate(self.args):
name_declarator, type = arg_node.analyse(
......@@ -682,12 +680,8 @@ class CFuncDeclaratorNode(CDeclaratorNode):
type = env.parent_type
elif i == 0 and env.is_cyp_class_scope and 'staticmethod' not in env.directives and self.declared_name() != "alloc":
if self.declared_name() != "__new__":
# Accept 'f(const self, ...)' syntax as equivalent to 'f(self, ...) const'
unqualified_type = type
if type.is_const_cyp_class:
self.is_const_method = True
unqualified_type = type.const_base_type
# Accept 'f(<qualifier> self, ...) syntax'
unqualified_type = type
if type.is_qualified_cyp_class:
self.self_qualifier = type.qualifier
unqualified_type = type.qual_base_type
......@@ -1355,10 +1349,11 @@ class CConstOrVolatileTypeNode(CBaseTypeNode):
error(self.pos,
"Const/volatile base type cannot be a Python object")
if base.is_cyp_class:
if not self.is_const or self.is_volatile:
error(self.pos, "Cypclass doesn't support 'volatile' yet")
if self.is_const:
error(self.pos, "Cypclass reference cannot be 'const'")
elif self.is_volatile:
error(self.pos, "Cypclass reference cannot be 'volatile'")
return base
return PyrexTypes.cyp_class_const_type(base)
return PyrexTypes.c_const_or_volatile_type(base, self.is_const, self.is_volatile)
......
......@@ -3383,7 +3383,7 @@ def p_c_func_or_var_declaration(s, pos, ctx):
s.next()
p_test(s) # Keep going, but ignore result.
if s.sy == ':':
if ctx.level not in ('module', 'c_class', 'module_pxd', 'c_class_pxd', 'cpp_class') and not ctx.templates:
if ctx.level not in ('module', 'c_class', 'module_pxd', 'c_class_pxd', 'cpp_class', 'cyp_class') and not ctx.templates:
s.error("C function definition not allowed here")
doc, suite = p_suite_with_docstring(s, Ctx(level='function'))
if 'mutable' in modifiers:
......@@ -3877,7 +3877,8 @@ def p_cpp_class_definition(s, pos, ctx):
# so why not on the cppclass itself ?
p_doc_string(s)
attributes = []
body_ctx = Ctx(visibility = ctx.visibility, level='cpp_class', nogil=nogil or ctx.nogil)
body_level = 'cyp_class' if cypclass else 'cpp_class'
body_ctx = Ctx(visibility = ctx.visibility, level=body_level, nogil=nogil or ctx.nogil)
body_ctx.templates = template_names
while s.sy != 'DEDENT':
if s.sy != 'pass':
......
......@@ -258,7 +258,6 @@ class PyrexType(BaseType):
is_struct_or_union = 0
is_cpp_class = 0
is_cyp_class = 0
is_const_cyp_class = 0
is_qualified_cyp_class = 0
is_cpp_string = 0
is_struct = 0
......@@ -4671,13 +4670,11 @@ class CypClassType(CppClassType):
return "dynamic_cast<%s>(%s)" % (self.declaration_code(''), expr_code)
def same_as_resolved_type(self, other_type):
if other_type.is_const_cyp_class:
if other_type.is_qualified_cyp_class:
return 0
return super(CypClassType, self).same_as_resolved_type(other_type)
def assignable_from_resolved_type(self, other_type):
if other_type.is_const_cyp_class:
return 0
if other_type.is_qualified_cyp_class and other_type.qualifier != 'iso~':
return 0
if other_type.is_ptr and other_type.base_type.is_cpp_class and other_type.base_type.is_subclass(self) or other_type.is_null_ptr:
......@@ -4685,16 +4682,12 @@ class CypClassType(CppClassType):
return super(CypClassType, self).assignable_from_resolved_type(other_type)
def is_subclass(self, other_type):
if other_type.is_const_cyp_class:
other_type = other_type.const_base_type
elif other_type.is_qualified_cyp_class:
if other_type.is_qualified_cyp_class:
other_type = other_type.qual_base_type
return super(CypClassType, self).is_subclass(other_type)
def subclass_dist(self, super_type):
if super_type.is_const_cyp_class:
super_type = super_type.const_base_type
elif super_type.is_qualified_cyp_class:
if super_type.is_qualified_cyp_class:
super_type = super_type.qual_base_type
return super(CypClassType, self).subclass_dist(super_type)
......@@ -4753,94 +4746,6 @@ class CypClassType(CppClassType):
raise NotImplementedError("Cy_XDECREF_SET is not defined for decrementing a group of cyobjects")
class ConstCypclassType(BaseType):
"A const cypclass"
subtypes = ['const_base_type']
is_const_cyp_class = 1
def __init__(self, base_type):
assert base_type.is_cyp_class
self.const_base_type = base_type
if base_type.has_attributes and base_type.scope is not None:
from .Symtab import CConstOrVolatileScope
self.scope = CConstOrVolatileScope(base_type.scope, is_const = 1, is_volatile = 0)
def __repr__(self):
return "<ConstCypclassType %s%r>" % self.const_base_type
def __str__(self):
return self.declaration_code("", for_display=1)
def declaration_code(self, entity_code, for_display = 0, dll_linkage = None, pyrex = 0, template_params = None, deref = 0):
return "const %s" % self.const_base_type.declaration_code(entity_code, for_display, dll_linkage, pyrex, template_params, deref)
def empty_declaration_code(self):
if self._empty_declaration is None:
self._empty_declaration = "const %s" % self.const_base_type.empty_declaration_code()
return self._empty_declaration
def cast_code(self, expr_code):
return "((%s)%s)" % (self.declaration_code(''), expr_code)
def dynamic_cast_code(self, expr_code):
return "dynamic_cast<%s>(%s)" % (self.declaration_code(''), expr_code)
def resolve(self):
base_type = self.const_base_type.resolve()
if base_type == self.const_base_type:
return self
return ConstCypclassType(base_type)
def specialize(self, values):
base_type = self.const_base_type.specialize(values)
if base_type == self.const_base_type:
return self
return ConstCypclassType(base_type)
def as_argument_type(self):
return self
def as_returned_type(self):
return self
def deduce_template_params(self, actual):
return self.const_base_type.deduce_template_params(actual)
def can_coerce_to_pyobject(self, env):
return self.const_base_type.can_coerce_to_pyobject(env)
def can_coerce_from_pyobject(self, env):
return self.const_base_type.can_coerce_from_pyobject(env)
def create_to_py_utility_code(self, env):
if self.const_base_type.create_to_py_utility_code(env):
self.to_py_function = self.const_base_type.to_py_function
return True
def assignable_from(self, src_type):
return self.assignable_from_resolved_type(src_type.resolve())
def assignable_from_resolved_type(self, src_type):
if src_type.is_const_cyp_class:
src_type = src_type.const_base_type
return self.const_base_type.assignable_from_resolved_type(src_type)
def same_as(self, other_type):
if not other_type.is_const_cyp_class:
return 0
return self.same_as_resolved_type(other_type.resolve())
def same_as_resolved_type(self, other_type):
if other_type.is_const_cyp_class:
return self.const_base_type.same_as_resolved_type(other_type.const_base_type)
return 0
def __getattr__(self, name):
return getattr(self.const_base_type, name)
class QualifiedCypclassType(BaseType):
"A qualified cypclass reference"
......@@ -5252,7 +5157,6 @@ unspecified_type = UnspecifiedType()
py_object_type = PyObjectType()
cy_object_type = CypClassType('cyobject', None, "CyObject", None)
const_cy_object_type = ConstCypclassType(cy_object_type)
c_void_type = CVoidType()
......@@ -5881,13 +5785,6 @@ def c_const_or_volatile_type(base_type, is_const, is_volatile):
else:
return CConstOrVolatileType(base_type, is_const, is_volatile)
def cyp_class_const_type(base_type):
# Construct a Cypclass const type.
if base_type is error_type:
return error_type
else:
return ConstCypclassType(base_type)
def cyp_class_qualified_type(base_type, qualifier):
# Construct a qualified cypclass type.
if base_type is error_type:
......@@ -5929,10 +5826,6 @@ def ptr_to_subtype_of(type1, type2):
def ptr_to_same_without_cv(type1, type2):
if type1.is_cyp_class and type2.is_cyp_class:
if type1.is_const_cyp_class:
type1 = type1.const_base_type
if type2.is_const_cyp_class:
type2 = type2.const_base_type
return same_type(type1, type2)
elif type1.is_ptr and type2.is_ptr:
type1 = type1.base_type
......
......@@ -564,12 +564,6 @@ class Scope(object):
cpp_override_allowed = True
continue
# allow const overloads
if alt_type.is_const_method != type.is_const_method:
error(pos, "Cypclass method const-overloads another method: not supported yet")
cpp_override_allowed = True
continue
elif alt_entry.is_inherited:
# if the arguments are compatible, then the signatures need to actually be the
......
......@@ -125,26 +125,26 @@ cdef cypclass cypdict[K, V]:
ctypedef V value_type
ctypedef pair[key_type, value_type] item_type
ctypedef vector[item_type].size_type size_type
ctypedef dict_key_iterator_t[const cypdict[K, V], vector[item_type].const_iterator, key_type] iterator
ctypedef dict_keys_view_t[const cypdict[K, V], vector[item_type].const_iterator, key_type] keys_view
ctypedef dict_values_view_t[const cypdict[K, V], vector[item_type].const_iterator, value_type] values_view
ctypedef dict_items_view_t[const cypdict[K, V], vector[item_type].const_iterator, item_type] items_view
ctypedef dict_key_iterator_t[cypdict[K, V], vector[item_type].const_iterator, key_type] iterator
ctypedef dict_keys_view_t[cypdict[K, V], vector[item_type].const_iterator, key_type] keys_view
ctypedef dict_values_view_t[cypdict[K, V], vector[item_type].const_iterator, value_type] values_view
ctypedef dict_items_view_t[cypdict[K, V], vector[item_type].const_iterator, item_type] items_view
vector[item_type] _items
unordered_map[key_type, size_type] _indices
mutable atomic[int] _active_iterators
atomic[int] _active_iterators
__init__(self):
self._active_iterators.store(0)
V __getitem__(const self, const key_type key) except ~:
V __getitem__(self, key_type key) except ~:
it = self._indices.const_find(key)
if it != self._indices.end():
return self._items[dereference(it).second].second
with gil:
raise KeyError("Getting nonexistent item")
void __setitem__(self, const key_type key, const value_type value) except ~:
void __setitem__(self, key_type key, value_type value) except ~:
it = self._indices.find(key)
if it != self._indices.end():
index = dereference(it).second
......@@ -156,7 +156,7 @@ cdef cypclass cypdict[K, V]:
with gil:
raise RuntimeError("Modifying a dictionary with active iterators")
void __delitem__(self, const key_type key) except ~:
void __delitem__(self, key_type key) except ~:
it = self._indices.find(key)
if it == self._indices.end():
with gil:
......@@ -170,7 +170,7 @@ cdef cypclass cypdict[K, V]:
self._items[index] = self._items[self._indices.size() - 1]
self._items.pop_back()
void update(self, const cypdict[K, V] other) except ~:
void update(self, cypdict[K, V] other) except ~:
for item in other.items():
self[item.first] = item.second
......@@ -182,23 +182,23 @@ cdef cypclass cypdict[K, V]:
with gil:
raise RuntimeError("Modifying a dictionary with active iterators")
iterator begin(const self):
iterator begin(self):
return iterator(self._items.const_begin(), self)
vector[item_type].const_iterator end(const self):
vector[item_type].const_iterator end(self):
return self._items.const_end()
size_type __len__(const self):
size_type __len__(self):
return self._items.size()
bint __contains__(const self, const key_type key):
bint __contains__(self, key_type key):
return self._indices.count(key)
keys_view keys(const self):
keys_view keys(self):
return keys_view(self)
values_view values(const self):
values_view values(self):
return values_view(self)
items_view items(const self):
items_view items(self):
return items_view(self)
......@@ -18,7 +18,7 @@ cdef extern from * nogil:
cdef cppclass list_iterator_t[list_t, base_iterator_t, reference_t]:
list_iterator_t()
list_iterator_t(base_iterator_t)
list_iterator_t(base_iterator_t, const list_t)
list_iterator_t(base_iterator_t, list_t)
reference_t operator*()
list_iterator_t operator++()
bint operator!=(base_iterator_t)
......@@ -26,22 +26,22 @@ cdef extern from * nogil:
cdef cypclass cyplist[V]:
ctypedef V value_type
ctypedef vector[value_type].size_type size_type
ctypedef list_iterator_t[const cyplist[V], vector[value_type].const_iterator, value_type] iterator
ctypedef list_iterator_t[cyplist[V], vector[value_type].const_iterator, value_type] iterator
vector[value_type] _elements
mutable atomic[int] _active_iterators
atomic[int] _active_iterators
__init__(self):
self._active_iterators.store(0)
V __getitem__(const self, const size_type index) except ~:
V __getitem__(self, size_type index) except ~:
if index < self._elements.size():
return self._elements[index]
else:
with gil:
raise IndexError("Getting list index out of range")
void __setitem__(self, size_type index, const value_type value) except ~:
void __setitem__(self, size_type index, value_type value) except ~:
if index < self._elements.size():
self._elements[index] = value
else:
......@@ -60,14 +60,14 @@ cdef cypclass cyplist[V]:
with gil:
raise IndexError("Deleting list index out of range")
void append(self, const value_type value) except ~:
void append(self, value_type value) except ~:
if self._active_iterators == 0:
self._elements.push_back(value)
else:
with gil:
raise RuntimeError("Modifying a list with active iterators")
void insert(self, size_type index, const value_type value) except ~:
void insert(self, size_type index, value_type value) except ~:
if self._active_iterators == 0:
if index <= self._elements.size():
it = self._elements.begin() + index
......@@ -86,14 +86,14 @@ cdef cypclass cyplist[V]:
with gil:
raise RuntimeError("Modifying a list with active iterators")
cyplist[V] __add__(const self, const cyplist[V] other):
cyplist[V] __add__(self, cyplist[V] other):
result = cyplist[V]()
result._elements.reserve(self._elements.size() + other._elements.size())
result._elements.insert(result._elements.end(), self._elements.const_begin(), self._elements.const_end())
result._elements.insert(result._elements.end(), other._elements.const_begin(), other._elements.const_end())
return result
cyplist[V] __iadd__(self, const cyplist[V] other):
cyplist[V] __iadd__(self, cyplist[V] other):
if self._active_iterators == 0:
self._elements.insert(self._elements.end(), other._elements.const_begin(), other._elements.const_end())
return self
......@@ -101,7 +101,7 @@ cdef cypclass cyplist[V]:
with gil:
raise RuntimeError("Modifying a list with active iterators")
cyplist[V] __mul__(const self, size_type n):
cyplist[V] __mul__(self, size_type n):
result = cyplist[V]()
result._elements.reserve(self._elements.size() * n)
for i in range(n):
......@@ -125,16 +125,16 @@ cdef cypclass cyplist[V]:
with gil:
raise RuntimeError("Modifying a list with active iterators")
iterator begin(const self):
iterator begin(self):
return iterator(self._elements.const_begin(), self)
vector[value_type].const_iterator end(const self):
vector[value_type].const_iterator end(self):
return self._elements.const_end()
size_type __len__(const self):
size_type __len__(self):
return self._elements.size()
bint __contains__(const self, const value_type value):
bint __contains__(self, value_type value):
for v in self._elements:
if value is v:
return 1
......
......@@ -19,7 +19,7 @@ cdef extern from * nogil:
cdef cppclass set_iterator_t[set_t, base_iterator_t, reference_t]:
set_iterator_t()
set_iterator_t(base_iterator_t)
set_iterator_t(base_iterator_t, const set_t)
set_iterator_t(base_iterator_t, set_t)
reference_t operator*()
set_iterator_t operator++()
bint operator!=(base_iterator_t)
......@@ -27,24 +27,24 @@ cdef extern from * nogil:
cdef cypclass cypset[V]:
ctypedef V value_type
ctypedef size_t size_type
ctypedef set_iterator_t[const cypset[V], unordered_set[value_type].const_iterator, value_type] iterator
ctypedef set_iterator_t[cypset[V], unordered_set[value_type].const_iterator, value_type] iterator
unordered_set[value_type] _elements
mutable atomic[int] _active_iterators
atomic[int] _active_iterators
__init__(self):
self._active_iterators.store(0)
# set elementary operations
void add(self, const value_type value) except ~:
void add(self, value_type value) except ~:
if self._active_iterators == 0:
self._elements.insert(value)
else:
with gil:
raise RuntimeError("Modifying a set with active iterators")
void remove(self, const value_type value) except ~:
void remove(self, value_type value) except ~:
if self._active_iterators == 0:
if self._elements.erase(value) == 0:
with gil:
......@@ -53,7 +53,7 @@ cdef cypclass cypset[V]:
with gil:
raise RuntimeError("Modifying a set with active iterators")
void discard(self, const value_type value) except ~:
void discard(self, value_type value) except ~:
if self._active_iterators == 0:
self._elements.erase(value)
else:
......@@ -79,15 +79,15 @@ cdef cypclass cypset[V]:
# inspection operations
size_type __len__(const self):
size_type __len__(self):
return self._elements.size()
bint __contains__(const self, const value_type value):
bint __contains__(self, value_type value):
return self._elements.count(value)
bint isdisjoint(const self, const cypset[V] other):
cdef const cypset[V] smallest
cdef const cypset[V] greatest
bint isdisjoint(self, cypset[V] other):
cdef cypset[V] smallest
cdef cypset[V] greatest
if self._elements.size() < other._elements.size():
smallest = self
greatest = other
......@@ -101,7 +101,7 @@ cdef cypclass cypset[V]:
# set comparisons
bint __eq__(const self, const cypset[V] other):
bint __eq__(self, cypset[V] other):
if self._elements.size() != other._elements.size():
return 0
for value in self._elements:
......@@ -109,7 +109,7 @@ cdef cypclass cypset[V]:
return 0
return 1
bint __ne__(const self, const cypset[V] other):
bint __ne__(self, cypset[V] other):
if self._elements.size() != other._elements.size():
return 1
for value in self._elements:
......@@ -117,7 +117,7 @@ cdef cypclass cypset[V]:
return 1
return 0
bint __le__(const self, const cypset[V] other):
bint __le__(self, cypset[V] other):
if self._elements.size() > other._elements.size():
return 0
for value in self._elements:
......@@ -125,13 +125,13 @@ cdef cypclass cypset[V]:
return 0
return 1
bint __lt__(const self, const cypset[V] other):
bint __lt__(self, cypset[V] other):
return self <= other and self._elements.size() < other._elements.size()
bint issubset(const self, const cypset[V] other):
bint issubset(self, cypset[V] other):
return self <= other
bint __ge__(const self, const cypset[V] other):
bint __ge__(self, cypset[V] other):
if self._elements.size() < other._elements.size():
return 0
for value in other._elements:
......@@ -139,27 +139,27 @@ cdef cypclass cypset[V]:
return 0
return 1
bint __gt__(const self, const cypset[V] other):
bint __gt__(self, cypset[V] other):
return self >= other and self._elements.size() > other._elements.size()
bint issuperset(const self, const cypset[V] other):
bint issuperset(self, cypset[V] other):
return self >= other
# set non-modifying operations
cypset[V] __or__(const self, const cypset[V] other):
cypset[V] __or__(self, cypset[V] other):
result = cypset[V]()
result._elements.insert(self._elements.const_begin(), self._elements.const_end())
result._elements.insert(other._elements.const_begin(), other._elements.const_end())
return result
cypset[V] union "set_union"(const self, const cypset[V] other):
cypset[V] union "set_union"(self, cypset[V] other):
return self | other
cypset[V] __and__(const self, const cypset[V] other):
cdef const cypset[V] smallest
cdef const cypset[V] greatest
cypset[V] __and__(self, cypset[V] other):
cdef cypset[V] smallest
cdef cypset[V] greatest
if self._elements.size() < other._elements.size():
smallest = self
greatest = other
......@@ -172,20 +172,20 @@ cdef cypclass cypset[V]:
result._elements.insert(value)
return result
cypset[V] intersection(const self, const cypset[V] other):
cypset[V] intersection(self, cypset[V] other):
return self & other
cypset[V] __sub__(const self, const cypset[V] other):
cypset[V] __sub__(self, cypset[V] other):
result = cypset[V]()
for value in self._elements:
if other._elements.count(value) == 0:
result._elements.insert(value)
return result
cypset[V] difference(const self, const cypset[V] other):
cypset[V] difference(self, cypset[V] other):
return self - other
cypset[V] __xor__(const self, const cypset[V] other):
cypset[V] __xor__(self, cypset[V] other):
result = cypset[V]()
result._elements = other._elements
for value in self._elements:
......@@ -196,13 +196,13 @@ cdef cypclass cypset[V]:
result._elements.insert(value)
return result
cypset[V] symmetric_difference(const self, const cypset[V] other):
cypset[V] symmetric_difference(self, cypset[V] other):
return self ^ other
# set in-place (modifying) operations
cypset[V] __ior__(self, const cypset[V] other) except ~:
cypset[V] __ior__(self, cypset[V] other) except ~:
if self._active_iterators == 0:
self._elements.insert(other._elements.const_begin(), other._elements.end())
return self
......@@ -210,11 +210,11 @@ cdef cypclass cypset[V]:
with gil:
raise RuntimeError("Modifying a set with active iterators")
cypset[V] update(self, const cypset[V] other) except ~:
cypset[V] update(self, cypset[V] other) except ~:
self |= other
return self
cypset[V] __iand__(self, const cypset[V] other) except ~:
cypset[V] __iand__(self, cypset[V] other) except ~:
if self._active_iterators == 0:
it = self._elements.begin()
end = self._elements.end()
......@@ -229,11 +229,11 @@ cdef cypclass cypset[V]:
with gil:
raise RuntimeError("Modifying a set with active iterators")
cypset[V] intersection_update(self, const cypset[V] other) except ~:
cypset[V] intersection_update(self, cypset[V] other) except ~:
self &= other
return self
cypset[V] __isub__(self, const cypset[V] other) except ~:
cypset[V] __isub__(self, cypset[V] other) except ~:
if self._active_iterators == 0:
for value in other._elements:
self._elements.erase(value)
......@@ -242,11 +242,11 @@ cdef cypclass cypset[V]:
with gil:
raise RuntimeError("Modifying a set with active iterators")
cypset[V] difference_update(self, const cypset[V] other) except ~:
cypset[V] difference_update(self, cypset[V] other) except ~:
self -= other
return self
cypset[V] __ixor__(self, const cypset[V] other) except ~:
cypset[V] __ixor__(self, cypset[V] other) except ~:
if self._active_iterators == 0:
for value in other._elements:
if self._elements.erase(value) == 0:
......@@ -255,14 +255,14 @@ cdef cypclass cypset[V]:
with gil:
raise RuntimeError("Modifying a set with active iterators")
cypset[V] symmetric_difference_update(self, const cypset[V] other) except ~:
cypset[V] symmetric_difference_update(self, cypset[V] other) except ~:
self ^= other
return self
# iterators
iterator begin(const self):
iterator begin(self):
return iterator(self._elements.const_begin(), self)
unordered_set[value_type].const_iterator end(const self):
unordered_set[value_type].const_iterator end(self):
return self._elements.const_end()
......@@ -364,9 +364,9 @@
struct ActhonResultInterface : public CyObject {
virtual void pushVoidStarResult(void* result) = 0;
virtual void* getVoidStarResult() const = 0;
virtual void* getVoidStarResult() = 0;
virtual void pushIntResult(int result) = 0;
virtual int getIntResult() const = 0;
virtual int getIntResult() = 0;
operator int() { return this->getIntResult(); }
operator void*() { return this->getVoidStarResult(); }
};
......@@ -374,8 +374,8 @@
struct ActhonMessageInterface;
struct ActhonSyncInterface : public CyObject {
virtual int isActivable() const = 0;
virtual int isCompleted() const = 0;
virtual int isActivable() = 0;
virtual int isCompleted() = 0;
virtual void insertActivity() = 0;
virtual void removeActivity() = 0;
};
......@@ -391,7 +391,7 @@
struct ActhonQueueInterface : public CyObject {
virtual void push(ActhonMessageInterface* message) = 0;
virtual int activate() = 0;
virtual int is_empty() const = 0;
virtual int is_empty() = 0;
};
struct ActhonActivableClass : public CyObject {
......
......@@ -23,7 +23,7 @@ cdef cypclass BasicQueue(ActhonQueueInterface):
__dealloc__(self):
del self._queue
bint is_empty(const self):
bint is_empty(self):
return self._queue.empty()
void push(locked self, ActhonMessageInterface message):
......@@ -58,9 +58,9 @@ cdef cypclass NoneResult(ActhonResultInterface):
pass
void pushIntResult(self, int result):
pass
void* getVoidStarResult(const self):
void* getVoidStarResult(self):
return NULL
int getIntResult(const self):
int getIntResult(self):
return 0
cdef cypclass WaitResult(ActhonResultInterface):
......@@ -89,18 +89,17 @@ cdef cypclass WaitResult(ActhonResultInterface):
self.result.int_val = result
sem_post(&self.semaphore)
result_t _getRawResult(const self):
result_t _getRawResult(self):
# We must ensure a result exists, but we can let others access it immediately
# The cast here is a way of const-casting (we're modifying the semaphore in a const method)
sem_wait(<sem_t*> &self.semaphore)
sem_post(<sem_t*> &self.semaphore)
sem_wait(&self.semaphore)
sem_post(&self.semaphore)
return self.result
void* getVoidStarResult(const self):
void* getVoidStarResult(self):
res = self._getRawResult()
return res.ptr
int getIntResult(const self):
int getIntResult(self):
res = self._getRawResult()
return res.int_val
......@@ -118,10 +117,10 @@ cdef cypclass ActivityCounterSync(ActhonSyncInterface):
void removeActivity(self):
self.count -= 1
bint isCompleted(const self):
bint isCompleted(self):
return self.count == 0
bint isActivable(const self):
bint isActivable(self):
cdef bint res = True
if self.previous_sync is not NULL:
prev_sync = self.previous_sync
......@@ -135,7 +134,7 @@ cdef cypclass A activable:
self.a = 0
self._active_result_class = WaitResult.construct
self._active_queue_class = consume BasicQueue()
int getter(const self):
int getter(self):
return self.a
void setter(self, int a):
self.a = a
......
......@@ -21,14 +21,3 @@ def test_is_cypclass():
r = <RightBase> d
return d is d, l is d, r is d, l is r
def test_is_cypclass_const():
"""
>>> test_is_cypclass_const()
(True, True, True, True)
"""
cdef const Derived d = Derived()
cdef const LeftBase l = <LeftBase> d
cdef const RightBase r = <RightBase> d
return d is d, l is d, r is d, l is r
......@@ -26,22 +26,3 @@ def test_insinstanceof():
cdef int r6 = isinstanceof[Derived](derived)
print(r1, r2, r3, r4, r5, r6)
def test_const_insinstanceof():
"""
>>> test_const_insinstanceof()
(1, 1, 1, 0, 1, 1)
"""
cdef const Base base = Base()
cdef const Base derived_as_base = Derived()
cdef const Derived derived = Derived()
cdef int r1 = isinstanceof[Base](base)
cdef int r2 = isinstanceof[Base](derived_as_base)
cdef int r3 = isinstanceof[Base](derived)
cdef int r4 = isinstanceof[Derived](base)
cdef int r5 = isinstanceof[Derived](derived_as_base)
cdef int r6 = isinstanceof[Derived](derived)
print(r1, r2, r3, r4, r5, r6)
......@@ -105,7 +105,7 @@ cdef cypclass Subscript:
self.value = NULL
self.index = NULL
Value __getitem__(const self, Index index):
Value __getitem__(self, Index index):
if self.index is index:
return value
return NULL
......
......@@ -175,7 +175,7 @@ cdef cypclass Subscript:
self.value = NULL
self.index = NULL
Value __getitem__(const self, Index index):
Value __getitem__(self, Index index):
if self.index is index:
return value
return NULL
......
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