summaryrefslogtreecommitdiff
path: root/Cython/Compiler/ParseTreeTransforms.py
diff options
context:
space:
mode:
authorRobert Bradshaw <robertwb@gmail.com>2015-10-27 22:26:49 -0700
committerRobert Bradshaw <robertwb@gmail.com>2015-10-27 22:26:49 -0700
commit7d18de21583854823f7decad8640282d5695894f (patch)
treeb6c1b59eb478380008865c2cc661b3cdd0208e23 /Cython/Compiler/ParseTreeTransforms.py
parent92f5779244a6cbbc7228fa9f8f6956f827fae48e (diff)
parent6d55fd189f6ee9d4374d00b8c9c320bd04332bab (diff)
downloadcython-7d18de21583854823f7decad8640282d5695894f.tar.gz
Merge branch 'feat/casts' of git://github.com/memeplex/cython
Diffstat (limited to 'Cython/Compiler/ParseTreeTransforms.py')
-rw-r--r--Cython/Compiler/ParseTreeTransforms.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py
index 59bbd5f5a..1d1f38a50 100644
--- a/Cython/Compiler/ParseTreeTransforms.py
+++ b/Cython/Compiler/ParseTreeTransforms.py
@@ -2703,11 +2703,13 @@ class TransformBuiltinMethods(EnvTransform):
node.function.pos, operand1=node.args[0], operand2=node.args[1])
elif function == u'cast':
if len(node.args) != 2:
- error(node.function.pos, u"cast() takes exactly two arguments")
+ error(node.function.pos,
+ u"cast() takes exactly two arguments and an optional typecheck keyword")
else:
type = node.args[0].analyse_as_type(self.current_env())
if type:
- node = ExprNodes.TypecastNode(node.function.pos, type=type, operand=node.args[1])
+ node = ExprNodes.TypecastNode(
+ node.function.pos, type=type, operand=node.args[1], typecheck=False)
else:
error(node.args[0].pos, "Not a type")
elif function == u'sizeof':
@@ -2753,6 +2755,26 @@ class TransformBuiltinMethods(EnvTransform):
return self._inject_super(node, func_name)
return node
+ def visit_GeneralCallNode(self, node):
+ function = node.function.as_cython_attribute()
+ if function:
+ args = node.positional_args.args
+ kwargs = node.keyword_args.compile_time_value(None)
+ if function == u'cast':
+ if (len(args) != 2 or len(kwargs) > 1 or
+ (len(kwargs) == 1 and 'typecheck' not in kwargs)):
+ error(node.function.pos,
+ u"cast() takes exactly two arguments and an optional typecheck keyword")
+ else:
+ type = args[0].analyse_as_type(self.current_env())
+ if type:
+ typecheck = kwargs.get('typecheck', False)
+ node = ExprNodes.TypecastNode(
+ node.function.pos, type=type, operand=args[1], typecheck=typecheck)
+ else:
+ error(args[0].pos, "Not a type")
+ return node
+
class ReplaceFusedTypeChecks(VisitorTransform):
"""