Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
01e9ff88
Commit
01e9ff88
authored
Oct 14, 2017
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow typeof(...) to be used in a type context.
parent
6501e274
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
2 deletions
+26
-2
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+9
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+4
-2
tests/run/cpp_templates.pyx
tests/run/cpp_templates.pyx
+13
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
01e9ff88
...
...
@@ -5267,6 +5267,11 @@ class SimpleCallNode(CallNode):
error
(
self
.
args
[
0
].
pos
,
"Unknown type"
)
else
:
return
PyrexTypes
.
CPtrType
(
type
)
elif
attr
==
'typeof'
:
if
len
(
self
.
args
)
!=
1
:
error
(
self
.
args
.
pos
,
"only one type allowed."
)
operand
=
self
.
args
[
0
].
analyse_types
(
env
)
return
operand
.
type
def
explicit_args_kwds
(
self
):
return
self
.
args
,
None
...
...
@@ -10683,6 +10688,10 @@ class TypeofNode(ExprNode):
self
.
literal
=
literal
.
coerce_to_pyobject
(
env
)
return
self
def
analyse_as_type
(
env
):
self
.
operand
=
self
.
operand
.
analyse_types
(
env
)
return
self
.
operand
.
type
def
may_be_none
(
self
):
return
False
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
01e9ff88
...
...
@@ -15,6 +15,7 @@ from . import ExprNodes
from
.
import
Nodes
from
.
import
Options
from
.
import
Builtin
from
.
import
Errors
from
.Visitor
import
VisitorTransform
,
TreeVisitor
from
.Visitor
import
CythonTransform
,
EnvTransform
,
ScopeTrackingTransform
...
...
@@ -3157,8 +3158,9 @@ class ReplaceFusedTypeChecks(VisitorTransform):
return
self
.
transform
(
node
)
def
visit_PrimaryCmpNode
(
self
,
node
):
type1
=
node
.
operand1
.
analyse_as_type
(
self
.
local_scope
)
type2
=
node
.
operand2
.
analyse_as_type
(
self
.
local_scope
)
with
Errors
.
local_errors
(
ignore
=
True
):
type1
=
node
.
operand1
.
analyse_as_type
(
self
.
local_scope
)
type2
=
node
.
operand2
.
analyse_as_type
(
self
.
local_scope
)
if
type1
and
type2
:
false_node
=
ExprNodes
.
BoolNode
(
node
.
pos
,
value
=
False
)
...
...
tests/run/cpp_templates.pyx
View file @
01e9ff88
...
...
@@ -131,6 +131,19 @@ def test_func_ptr(double x):
finally
:
del
w
def
test_typeof
(
double
x
):
"""
>>> test_func_ptr(3)
9.0
>>> test_func_ptr(-1.5)
2.25
"""
try
:
w
=
new
Wrap
[
cython
.
typeof
(
&
f
)](
&
f
)
return
w
.
get
()(
x
)
finally
:
del
w
def
test_cast_template_pointer
():
"""
>>> test_cast_template_pointer()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment