Commit f58cc9a8 authored by mattip's avatar mattip

MAINT: refactor: is_cgetter now lives on the entry, use find_decorator

parent 03c53946
...@@ -7146,7 +7146,7 @@ class AttributeNode(ExprNode): ...@@ -7146,7 +7146,7 @@ class AttributeNode(ExprNode):
obj_code = obj.result_as(obj.type) obj_code = obj.result_as(obj.type)
#print "...obj_code =", obj_code ### #print "...obj_code =", obj_code ###
if self.entry and self.entry.is_cmethod: if self.entry and self.entry.is_cmethod:
if getattr(self.entry.type, 'is_cgetter', False): if self.entry.is_cgetter:
return "%s(%s)" %(self.entry.func_cname, obj_code) return "%s(%s)" %(self.entry.func_cname, obj_code)
if obj.type.is_extension_type and not self.entry.is_builtin_cmethod: if obj.type.is_extension_type and not self.entry.is_builtin_cmethod:
if self.entry.final_func_cname: if self.entry.final_func_cname:
...@@ -11225,9 +11225,9 @@ class NumBinopNode(BinopNode): ...@@ -11225,9 +11225,9 @@ class NumBinopNode(BinopNode):
self.operand2 = self.operand2.coerce_to(self.type, env) self.operand2 = self.operand2.coerce_to(self.type, env)
def compute_c_result_type(self, type1, type2): def compute_c_result_type(self, type1, type2):
if type1.is_cfunction and type1.is_cgetter: if type1.is_cfunction and type1.entry.is_cgetter:
type1 = type1.return_type type1 = type1.return_type
if type2.is_cfunction and type2.is_cgetter: if type2.is_cfunction and type2.entry.is_cgetter:
type2 = type2.return_type type2 = type2.return_type
if self.c_types_okay(type1, type2): if self.c_types_okay(type1, type2):
widest_type = PyrexTypes.widest_numeric_type(type1, type2) widest_type = PyrexTypes.widest_numeric_type(type1, type2)
......
...@@ -2245,23 +2245,21 @@ class ReplacePropertyNode(CythonTransform): ...@@ -2245,23 +2245,21 @@ class ReplacePropertyNode(CythonTransform):
return node return node
# transform @property decorators on ctypedef class functions # transform @property decorators on ctypedef class functions
for decorator_node in node.decorators[::-1]: for decorator_node in node.decorators[::-1]:
_node = self.analyse_decorator(node, decorator_node.decorator) if self.find_decorator(decorator_node.decorator, 'property'):
if _node:
node.decorators.remove(decorator_node)
node = _node
break
return node
def analyse_decorator(self, node, decorator):
if decorator.is_name and decorator.name == 'property':
if len(node.decorators) > 1: if len(node.decorators) > 1:
return self._reject_decorated_property(node, decorator_node) # raises
# Mark the node as a cgetter self._reject_decorated_property(node, decorator_node)
node.type.is_cgetter = True node.entry.is_cgetter = True
# Add a func_cname to be output instead of the attribute # Add a func_cname to be output instead of the attribute
node.entry.func_cname = node.body.stats[0].value.function.name node.entry.func_cname = node.body.stats[0].value.function.name
node.decorators.remove(decorator_node)
break
return node return node
return None
def find_decorator(self, decorator, name):
if decorator.is_name and decorator.name == name:
return True
return False
class FindInvalidUseOfFusedTypes(CythonTransform): class FindInvalidUseOfFusedTypes(CythonTransform):
......
...@@ -134,6 +134,7 @@ class Entry(object): ...@@ -134,6 +134,7 @@ class Entry(object):
# cf_used boolean Entry is used # cf_used boolean Entry is used
# is_fused_specialized boolean Whether this entry of a cdef or def function # is_fused_specialized boolean Whether this entry of a cdef or def function
# is a specialization # is a specialization
# is_cgetter boolean Is a c-level getter function
# TODO: utility_code and utility_code_definition serves the same purpose... # TODO: utility_code and utility_code_definition serves the same purpose...
...@@ -203,6 +204,7 @@ class Entry(object): ...@@ -203,6 +204,7 @@ class Entry(object):
error_on_uninitialized = False error_on_uninitialized = False
cf_used = True cf_used = True
outer_entry = None outer_entry = None
is_cgetter = False
def __init__(self, name, cname, type, pos = None, init = None): def __init__(self, name, cname, type, pos = None, init = None):
self.name = name self.name = name
......
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