Commit 8bcb7184 authored by Xavier Thompson's avatar Xavier Thompson

Disallow the form 'f(self, ...) const' for cypclass methods

parent bd25a02e
...@@ -651,6 +651,8 @@ class CFuncDeclaratorNode(CDeclaratorNode): ...@@ -651,6 +651,8 @@ class CFuncDeclaratorNode(CDeclaratorNode):
directive_locals = {} directive_locals = {}
if nonempty: if nonempty:
nonempty -= 1 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 = [] func_type_args = []
for i, arg_node in enumerate(self.args): for i, arg_node in enumerate(self.args):
name_declarator, type = arg_node.analyse( name_declarator, type = arg_node.analyse(
...@@ -683,8 +685,6 @@ class CFuncDeclaratorNode(CDeclaratorNode): ...@@ -683,8 +685,6 @@ class CFuncDeclaratorNode(CDeclaratorNode):
if type.is_const_cyp_class: if type.is_const_cyp_class:
self.is_const_method = True self.is_const_method = True
unqualified_type = type.const_base_type unqualified_type = type.const_base_type
elif self.is_const_method:
type = PyrexTypes.cyp_class_const_type(type)
# check that the type of self is correct: # check that the type of self is correct:
if not unqualified_type.same_as(env.parent_type): if not unqualified_type.same_as(env.parent_type):
error(self.pos, "Wrong type for self argument - expected %s, got %s" % (env.parent_type, type)) error(self.pos, "Wrong type for self argument - expected %s, got %s" % (env.parent_type, type))
......
...@@ -137,7 +137,7 @@ cdef cypclass cypdict[K, V]: ...@@ -137,7 +137,7 @@ cdef cypclass cypdict[K, V]:
__init__(self): __init__(self):
self._active_iterators.store(0) self._active_iterators.store(0)
V __getitem__(self, const key_type key) except ~ const: V __getitem__(const self, const key_type key) except ~:
it = self._indices.const_find(key) it = self._indices.const_find(key)
if it != self._indices.end(): if it != self._indices.end():
return self._items[dereference(it).second].second return self._items[dereference(it).second].second
...@@ -182,23 +182,23 @@ cdef cypclass cypdict[K, V]: ...@@ -182,23 +182,23 @@ cdef cypclass cypdict[K, V]:
with gil: with gil:
raise RuntimeError("Modifying a dictionary with active iterators") raise RuntimeError("Modifying a dictionary with active iterators")
iterator begin(self) const: iterator begin(const self):
return iterator(self._items.const_begin(), self) return iterator(self._items.const_begin(), self)
vector[item_type].const_iterator end(self) const: vector[item_type].const_iterator end(const self):
return self._items.const_end() return self._items.const_end()
size_type __len__(self) const: size_type __len__(const self):
return self._items.size() return self._items.size()
bint __contains__(self, const key_type key) const: bint __contains__(const self, const key_type key):
return self._indices.count(key) return self._indices.count(key)
keys_view keys(self) const: keys_view keys(const self):
return keys_view(self) return keys_view(self)
values_view values(self) const: values_view values(const self):
return values_view(self) return values_view(self)
items_view items(self) const: items_view items(const self):
return items_view(self) return items_view(self)
...@@ -34,7 +34,7 @@ cdef cypclass cyplist[V]: ...@@ -34,7 +34,7 @@ cdef cypclass cyplist[V]:
__init__(self): __init__(self):
self._active_iterators.store(0) self._active_iterators.store(0)
V __getitem__(self, const size_type index) except ~ const: V __getitem__(const self, const size_type index) except ~:
if index < self._elements.size(): if index < self._elements.size():
return self._elements[index] return self._elements[index]
else: else:
...@@ -86,7 +86,7 @@ cdef cypclass cyplist[V]: ...@@ -86,7 +86,7 @@ cdef cypclass cyplist[V]:
with gil: with gil:
raise RuntimeError("Modifying a list with active iterators") raise RuntimeError("Modifying a list with active iterators")
cyplist[V] __add__(self, const cyplist[V] other) const: cyplist[V] __add__(const self, const cyplist[V] other):
result = cyplist[V]() result = cyplist[V]()
result._elements.reserve(self._elements.size() + other._elements.size()) 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(), self._elements.const_begin(), self._elements.const_end())
...@@ -101,7 +101,7 @@ cdef cypclass cyplist[V]: ...@@ -101,7 +101,7 @@ cdef cypclass cyplist[V]:
with gil: with gil:
raise RuntimeError("Modifying a list with active iterators") raise RuntimeError("Modifying a list with active iterators")
cyplist[V] __mul__(self, size_type n) const: cyplist[V] __mul__(const self, size_type n):
result = cyplist[V]() result = cyplist[V]()
result._elements.reserve(self._elements.size() * n) result._elements.reserve(self._elements.size() * n)
for i in range(n): for i in range(n):
...@@ -125,13 +125,13 @@ cdef cypclass cyplist[V]: ...@@ -125,13 +125,13 @@ cdef cypclass cyplist[V]:
with gil: with gil:
raise RuntimeError("Modifying a list with active iterators") raise RuntimeError("Modifying a list with active iterators")
iterator begin(self) const: iterator begin(const self):
return iterator(self._elements.const_begin(), self) return iterator(self._elements.const_begin(), self)
vector[value_type].const_iterator end(self) const: vector[value_type].const_iterator end(const self):
return self._elements.const_end() return self._elements.const_end()
size_type __len__(self) const: size_type __len__(const self):
return self._elements.size() return self._elements.size()
bint __contains__(self, const value_type value): bint __contains__(self, const value_type value):
......
...@@ -79,13 +79,13 @@ cdef cypclass cypset[V]: ...@@ -79,13 +79,13 @@ cdef cypclass cypset[V]:
# inspection operations # inspection operations
size_type __len__(self) const: size_type __len__(const self):
return self._elements.size() return self._elements.size()
bint __contains__(self, const value_type value): bint __contains__(self, const value_type value):
return self._elements.count(value) return self._elements.count(value)
bint isdisjoint(self, const cypset[V] other) const: bint isdisjoint(const self, const cypset[V] other):
cdef const cypset[V] smallest cdef const cypset[V] smallest
cdef const cypset[V] greatest cdef const cypset[V] greatest
if self._elements.size() < other._elements.size(): if self._elements.size() < other._elements.size():
...@@ -101,7 +101,7 @@ cdef cypclass cypset[V]: ...@@ -101,7 +101,7 @@ cdef cypclass cypset[V]:
# set comparisons # set comparisons
bint __eq__(self, const cypset[V] other) const: bint __eq__(const self, const cypset[V] other):
if self._elements.size() != other._elements.size(): if self._elements.size() != other._elements.size():
return 0 return 0
for value in self._elements: for value in self._elements:
...@@ -109,7 +109,7 @@ cdef cypclass cypset[V]: ...@@ -109,7 +109,7 @@ cdef cypclass cypset[V]:
return 0 return 0
return 1 return 1
bint __ne__(self, const cypset[V] other) const: bint __ne__(const self, const cypset[V] other):
if self._elements.size() != other._elements.size(): if self._elements.size() != other._elements.size():
return 1 return 1
for value in self._elements: for value in self._elements:
...@@ -117,7 +117,7 @@ cdef cypclass cypset[V]: ...@@ -117,7 +117,7 @@ cdef cypclass cypset[V]:
return 1 return 1
return 0 return 0
bint __le__(self, const cypset[V] other) const: bint __le__(const self, const cypset[V] other):
if self._elements.size() > other._elements.size(): if self._elements.size() > other._elements.size():
return 0 return 0
for value in self._elements: for value in self._elements:
...@@ -125,13 +125,13 @@ cdef cypclass cypset[V]: ...@@ -125,13 +125,13 @@ cdef cypclass cypset[V]:
return 0 return 0
return 1 return 1
bint __lt__(self, const cypset[V] other) const: bint __lt__(const self, const cypset[V] other):
return self <= other and self._elements.size() < other._elements.size() return self <= other and self._elements.size() < other._elements.size()
bint issubset(self, const cypset[V] other) const: bint issubset(const self, const cypset[V] other):
return self <= other return self <= other
bint __ge__(self, const cypset[V] other) const: bint __ge__(const self, const cypset[V] other):
if self._elements.size() < other._elements.size(): if self._elements.size() < other._elements.size():
return 0 return 0
for value in other._elements: for value in other._elements:
...@@ -139,25 +139,25 @@ cdef cypclass cypset[V]: ...@@ -139,25 +139,25 @@ cdef cypclass cypset[V]:
return 0 return 0
return 1 return 1
bint __gt__(self, const cypset[V] other) const: bint __gt__(const self, const cypset[V] other):
return self >= other and self._elements.size() > other._elements.size() return self >= other and self._elements.size() > other._elements.size()
bint issuperset(self, const cypset[V] other) const: bint issuperset(const self, const cypset[V] other):
return self >= other return self >= other
# set non-modifying operations # set non-modifying operations
cypset[V] __or__(self, const cypset[V] other) const: cypset[V] __or__(const self, const cypset[V] other):
result = cypset[V]() result = cypset[V]()
result._elements.insert(self._elements.const_begin(), self._elements.const_end()) result._elements.insert(self._elements.const_begin(), self._elements.const_end())
result._elements.insert(other._elements.const_begin(), other._elements.const_end()) result._elements.insert(other._elements.const_begin(), other._elements.const_end())
return result return result
cypset[V] union "set_union"(self, const cypset[V] other) const: cypset[V] union "set_union"(const self, const cypset[V] other):
return self | other return self | other
cypset[V] __and__(self, const cypset[V] other) const: cypset[V] __and__(const self, const cypset[V] other):
cdef const cypset[V] smallest cdef const cypset[V] smallest
cdef const cypset[V] greatest cdef const cypset[V] greatest
if self._elements.size() < other._elements.size(): if self._elements.size() < other._elements.size():
...@@ -172,20 +172,20 @@ cdef cypclass cypset[V]: ...@@ -172,20 +172,20 @@ cdef cypclass cypset[V]:
result._elements.insert(value) result._elements.insert(value)
return result return result
cypset[V] intersection(self, const cypset[V] other) const: cypset[V] intersection(const self, const cypset[V] other):
return self & other return self & other
cypset[V] __sub__(self, const cypset[V] other) const: cypset[V] __sub__(const self, const cypset[V] other):
result = cypset[V]() result = cypset[V]()
for value in self._elements: for value in self._elements:
if other._elements.count(value) == 0: if other._elements.count(value) == 0:
result._elements.insert(value) result._elements.insert(value)
return result return result
cypset[V] difference(self, const cypset[V] other) const: cypset[V] difference(const self, const cypset[V] other):
return self - other return self - other
cypset[V] __xor__(self, const cypset[V] other) const: cypset[V] __xor__(const self, const cypset[V] other):
result = cypset[V]() result = cypset[V]()
result._elements = other._elements result._elements = other._elements
for value in self._elements: for value in self._elements:
...@@ -196,7 +196,7 @@ cdef cypclass cypset[V]: ...@@ -196,7 +196,7 @@ cdef cypclass cypset[V]:
result._elements.insert(value) result._elements.insert(value)
return result return result
cypset[V] symmetric_difference(self, const cypset[V] other) const: cypset[V] symmetric_difference(const self, const cypset[V] other):
return self ^ other return self ^ other
...@@ -261,8 +261,8 @@ cdef cypclass cypset[V]: ...@@ -261,8 +261,8 @@ cdef cypclass cypset[V]:
# iterators # iterators
iterator begin(self) const: iterator begin(const self):
return iterator(self._elements.const_begin(), self) return iterator(self._elements.const_begin(), self)
unordered_set[value_type].const_iterator end(self) const: unordered_set[value_type].const_iterator end(const self):
return self._elements.const_end() return self._elements.const_end()
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
cdef cypclass A checklock: cdef cypclass A checklock:
int a int a
int getter(self) const: int getter(const self):
return self.a return self.a
void setter(self, int a): void setter(self, int a):
self.a = a self.a = a
......
...@@ -23,7 +23,7 @@ cdef cypclass BasicQueue(ActhonQueueInterface) checklock: ...@@ -23,7 +23,7 @@ cdef cypclass BasicQueue(ActhonQueueInterface) checklock:
__dealloc__(self): __dealloc__(self):
del self._queue del self._queue
bint is_empty(self) const: bint is_empty(const self):
return self._queue.empty() return self._queue.empty()
void push(self, ActhonMessageInterface message): void push(self, ActhonMessageInterface message):
...@@ -58,9 +58,9 @@ cdef cypclass NoneResult(ActhonResultInterface) checklock: ...@@ -58,9 +58,9 @@ cdef cypclass NoneResult(ActhonResultInterface) checklock:
pass pass
void pushIntResult(self, int result): void pushIntResult(self, int result):
pass pass
void* getVoidStarResult(self) const: void* getVoidStarResult(const self):
return NULL return NULL
int getIntResult(self) const: int getIntResult(const self):
return 0 return 0
cdef cypclass WaitResult(ActhonResultInterface) checklock: cdef cypclass WaitResult(ActhonResultInterface) checklock:
...@@ -89,18 +89,18 @@ cdef cypclass WaitResult(ActhonResultInterface) checklock: ...@@ -89,18 +89,18 @@ cdef cypclass WaitResult(ActhonResultInterface) checklock:
self.result.int_val = result self.result.int_val = result
sem_post(&self.semaphore) sem_post(&self.semaphore)
result_t _getRawResult(self) const: result_t _getRawResult(const self):
# We must ensure a result exists, but we can let others access it immediately # 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) # 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_wait(<sem_t*> &self.semaphore)
sem_post(<sem_t*> &self.semaphore) sem_post(<sem_t*> &self.semaphore)
return self.result return self.result
void* getVoidStarResult(self) const: void* getVoidStarResult(const self):
res = self._getRawResult() res = self._getRawResult()
return res.ptr return res.ptr
int getIntResult(self) const: int getIntResult(const self):
res = self._getRawResult() res = self._getRawResult()
return res.int_val return res.int_val
...@@ -118,10 +118,10 @@ cdef cypclass ActivityCounterSync(ActhonSyncInterface) checklock: ...@@ -118,10 +118,10 @@ cdef cypclass ActivityCounterSync(ActhonSyncInterface) checklock:
void removeActivity(self, ActhonMessageInterface msg): void removeActivity(self, ActhonMessageInterface msg):
self.count -= 1 self.count -= 1
bint isCompleted(self) const: bint isCompleted(const self):
return self.count == 0 return self.count == 0
bint isActivable(self) const: bint isActivable(const self):
cdef bint res = True cdef bint res = True
if self.previous_sync is not NULL: if self.previous_sync is not NULL:
prev_sync = self.previous_sync prev_sync = self.previous_sync
...@@ -135,7 +135,7 @@ cdef cypclass A checklock activable: ...@@ -135,7 +135,7 @@ cdef cypclass A checklock activable:
self.a = 0 self.a = 0
self._active_result_class = WaitResult.construct self._active_result_class = WaitResult.construct
self._active_queue_class = BasicQueue() self._active_queue_class = BasicQueue()
int getter(self) const: int getter(const self):
return self.a return self.a
void setter(self, int a): void setter(self, int a):
self.a = a self.a = a
......
...@@ -6,7 +6,7 @@ cdef cypclass A checklock: ...@@ -6,7 +6,7 @@ cdef cypclass A checklock:
int a int a
__init__(self): __init__(self):
self.a = 0 self.a = 0
int getter(self) const: int getter(const self):
return self.a return self.a
void setter(self, int a): void setter(self, int a):
self.a = a self.a = a
......
...@@ -175,7 +175,7 @@ cdef cypclass Subscript: ...@@ -175,7 +175,7 @@ cdef cypclass Subscript:
self.value = NULL self.value = NULL
self.index = NULL self.index = NULL
Value __getitem__(self, Index index) const: Value __getitem__(const self, Index index):
if self.index is index: if self.index is index:
return value return value
return NULL 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