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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
dc54ee46
Commit
dc54ee46
authored
Dec 02, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up evil import collisions in ParseTreeTransforms.py
parent
3ccc783a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
77 deletions
+84
-77
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+84
-77
No files found.
Cython/Compiler/ParseTreeTransforms.py
View file @
dc54ee46
import
cython
import
cython
cython
.
declare
(
copy
=
object
,
ModuleNode
=
object
,
TreeFragment
=
object
,
TemplateTransform
=
object
,
cython
.
declare
(
PyrexTypes
=
object
,
Naming
=
object
,
ExprNodes
=
object
,
Nodes
=
object
,
EncodedString
=
object
,
error
=
object
,
warning
=
object
,
PyrexTypes
=
object
,
Naming
=
object
)
Options
=
object
,
UtilNodes
=
object
,
ModuleNode
=
object
,
LetNode
=
object
,
LetRefNode
=
object
,
TreeFragment
=
object
,
TemplateTransform
=
object
,
EncodedString
=
object
,
error
=
object
,
warning
=
object
,
copy
=
object
)
import
PyrexTypes
import
Naming
import
ExprNodes
import
Nodes
import
Options
from
Cython.Compiler.Visitor
import
VisitorTransform
,
TreeVisitor
from
Cython.Compiler.Visitor
import
VisitorTransform
,
TreeVisitor
from
Cython.Compiler.Visitor
import
CythonTransform
,
EnvTransform
,
ScopeTrackingTransform
from
Cython.Compiler.Visitor
import
CythonTransform
,
EnvTransform
,
ScopeTrackingTransform
from
Cython.Compiler.ModuleNode
import
ModuleNode
from
Cython.Compiler.ModuleNode
import
ModuleNode
from
Cython.Compiler.Nodes
import
*
from
Cython.Compiler.UtilNodes
import
LetNode
,
LetRefNode
from
Cython.Compiler.ExprNodes
import
*
from
Cython.Compiler.UtilNodes
import
*
from
Cython.Compiler.TreeFragment
import
TreeFragment
,
TemplateTransform
from
Cython.Compiler.TreeFragment
import
TreeFragment
,
TemplateTransform
from
Cython.Compiler.StringEncoding
import
EncodedString
from
Cython.Compiler.StringEncoding
import
EncodedString
from
Cython.Compiler.Errors
import
error
,
warning
,
CompileError
from
Cython.Compiler.Errors
import
error
,
warning
,
CompileError
,
InternalError
from
Cython.Compiler
import
PyrexTypes
,
Naming
import
copy
import
copy
...
@@ -98,7 +104,7 @@ class NormalizeTree(CythonTransform):
...
@@ -98,7 +104,7 @@ class NormalizeTree(CythonTransform):
self
.
visitchildren
(
node
)
self
.
visitchildren
(
node
)
self
.
is_in_statlist
=
stacktmp
self
.
is_in_statlist
=
stacktmp
if
not
self
.
is_in_statlist
and
not
self
.
is_in_expr
:
if
not
self
.
is_in_statlist
and
not
self
.
is_in_expr
:
return
StatListNode
(
pos
=
node
.
pos
,
stats
=
[
node
])
return
Nodes
.
StatListNode
(
pos
=
node
.
pos
,
stats
=
[
node
])
else
:
else
:
return
node
return
node
...
@@ -120,7 +126,7 @@ class NormalizeTree(CythonTransform):
...
@@ -120,7 +126,7 @@ class NormalizeTree(CythonTransform):
# Eliminate PassStatNode
# Eliminate PassStatNode
def
visit_PassStatNode
(
self
,
node
):
def
visit_PassStatNode
(
self
,
node
):
if
not
self
.
is_in_statlist
:
if
not
self
.
is_in_statlist
:
return
StatListNode
(
pos
=
node
.
pos
,
stats
=
[])
return
Nodes
.
StatListNode
(
pos
=
node
.
pos
,
stats
=
[])
else
:
else
:
return
[]
return
[]
...
@@ -197,7 +203,7 @@ class PostParse(ScopeTrackingTransform):
...
@@ -197,7 +203,7 @@ class PostParse(ScopeTrackingTransform):
# cdef variables
# cdef variables
def
handle_bufferdefaults
(
self
,
decl
):
def
handle_bufferdefaults
(
self
,
decl
):
if
not
isinstance
(
decl
.
default
,
DictNode
):
if
not
isinstance
(
decl
.
default
,
ExprNodes
.
DictNode
):
raise
PostParseError
(
decl
.
pos
,
ERR_BUF_DEFAULTS
)
raise
PostParseError
(
decl
.
pos
,
ERR_BUF_DEFAULTS
)
self
.
scope_node
.
buffer_defaults_node
=
decl
.
default
self
.
scope_node
.
buffer_defaults_node
=
decl
.
default
self
.
scope_node
.
buffer_defaults_pos
=
decl
.
pos
self
.
scope_node
.
buffer_defaults_pos
=
decl
.
pos
...
@@ -213,12 +219,12 @@ class PostParse(ScopeTrackingTransform):
...
@@ -213,12 +219,12 @@ class PostParse(ScopeTrackingTransform):
newdecls
=
[]
newdecls
=
[]
for
decl
in
node
.
declarators
:
for
decl
in
node
.
declarators
:
declbase
=
decl
declbase
=
decl
while
isinstance
(
declbase
,
CPtrDeclaratorNode
):
while
isinstance
(
declbase
,
Nodes
.
CPtrDeclaratorNode
):
declbase
=
declbase
.
base
declbase
=
declbase
.
base
if
isinstance
(
declbase
,
CNameDeclaratorNode
):
if
isinstance
(
declbase
,
Nodes
.
CNameDeclaratorNode
):
if
declbase
.
default
is
not
None
:
if
declbase
.
default
is
not
None
:
if
self
.
scope_type
in
(
'cclass'
,
'pyclass'
,
'struct'
):
if
self
.
scope_type
in
(
'cclass'
,
'pyclass'
,
'struct'
):
if
isinstance
(
self
.
scope_node
,
CClassDefNode
):
if
isinstance
(
self
.
scope_node
,
Nodes
.
CClassDefNode
):
handler
=
self
.
specialattribute_handlers
.
get
(
decl
.
name
)
handler
=
self
.
specialattribute_handlers
.
get
(
decl
.
name
)
if
handler
:
if
handler
:
if
decl
is
not
declbase
:
if
decl
is
not
declbase
:
...
@@ -227,8 +233,8 @@ class PostParse(ScopeTrackingTransform):
...
@@ -227,8 +233,8 @@ class PostParse(ScopeTrackingTransform):
continue
# Remove declaration
continue
# Remove declaration
raise
PostParseError
(
decl
.
pos
,
ERR_CDEF_INCLASS
)
raise
PostParseError
(
decl
.
pos
,
ERR_CDEF_INCLASS
)
first_assignment
=
self
.
scope_type
!=
'module'
first_assignment
=
self
.
scope_type
!=
'module'
stats
.
append
(
SingleAssignmentNode
(
node
.
pos
,
stats
.
append
(
Nodes
.
SingleAssignmentNode
(
node
.
pos
,
lhs
=
NameNode
(
node
.
pos
,
name
=
declbase
.
name
),
lhs
=
ExprNodes
.
NameNode
(
node
.
pos
,
name
=
declbase
.
name
),
rhs
=
declbase
.
default
,
first
=
first_assignment
))
rhs
=
declbase
.
default
,
first
=
first_assignment
))
declbase
.
default
=
None
declbase
.
default
=
None
newdecls
.
append
(
decl
)
newdecls
.
append
(
decl
)
...
@@ -505,11 +511,11 @@ class PxdPostParse(CythonTransform, SkipDeclarations):
...
@@ -505,11 +511,11 @@ class PxdPostParse(CythonTransform, SkipDeclarations):
# an imp they are CVarDefNodes..)
# an imp they are CVarDefNodes..)
err
=
self
.
ERR_INLINE_ONLY
err
=
self
.
ERR_INLINE_ONLY
if
(
isinstance
(
node
,
DefNode
)
and
self
.
scope_type
==
'cclass'
if
(
isinstance
(
node
,
Nodes
.
DefNode
)
and
self
.
scope_type
==
'cclass'
and
node
.
name
in
(
'__getbuffer__'
,
'__releasebuffer__'
)):
and
node
.
name
in
(
'__getbuffer__'
,
'__releasebuffer__'
)):
err
=
None
# allow these slots
err
=
None
# allow these slots
if
isinstance
(
node
,
CFuncDefNode
):
if
isinstance
(
node
,
Nodes
.
CFuncDefNode
):
if
u'inline'
in
node
.
modifiers
and
self
.
scope_type
==
'pxd'
:
if
u'inline'
in
node
.
modifiers
and
self
.
scope_type
==
'pxd'
:
node
.
inline_in_pxd
=
True
node
.
inline_in_pxd
=
True
if
node
.
visibility
!=
'private'
:
if
node
.
visibility
!=
'private'
:
...
@@ -554,21 +560,21 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -554,21 +560,21 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
and which names the "cython" module may have been imported to.
and which names the "cython" module may have been imported to.
"""
"""
unop_method_nodes
=
{
unop_method_nodes
=
{
'typeof'
:
TypeofNode
,
'typeof'
:
ExprNodes
.
TypeofNode
,
'operator.address'
:
AmpersandNode
,
'operator.address'
:
ExprNodes
.
AmpersandNode
,
'operator.dereference'
:
DereferenceNode
,
'operator.dereference'
:
ExprNodes
.
DereferenceNode
,
'operator.preincrement'
:
inc_dec_constructor
(
True
,
'++'
),
'operator.preincrement'
:
ExprNodes
.
inc_dec_constructor
(
True
,
'++'
),
'operator.predecrement'
:
inc_dec_constructor
(
True
,
'--'
),
'operator.predecrement'
:
ExprNodes
.
inc_dec_constructor
(
True
,
'--'
),
'operator.postincrement'
:
inc_dec_constructor
(
False
,
'++'
),
'operator.postincrement'
:
ExprNodes
.
inc_dec_constructor
(
False
,
'++'
),
'operator.postdecrement'
:
inc_dec_constructor
(
False
,
'--'
),
'operator.postdecrement'
:
ExprNodes
.
inc_dec_constructor
(
False
,
'--'
),
# For backwards compatability.
# For backwards compatability.
'address'
:
AmpersandNode
,
'address'
:
ExprNodes
.
AmpersandNode
,
}
}
binop_method_nodes
=
{
binop_method_nodes
=
{
'operator.comma'
:
c_binop_constructor
(
','
),
'operator.comma'
:
ExprNodes
.
c_binop_constructor
(
','
),
}
}
special_methods
=
cython
.
set
([
'declare'
,
'union'
,
'struct'
,
'typedef'
,
'sizeof'
,
special_methods
=
cython
.
set
([
'declare'
,
'union'
,
'struct'
,
'typedef'
,
'sizeof'
,
...
@@ -666,11 +672,11 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -666,11 +672,11 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
return
node
return
node
def
visit_SingleAssignmentNode
(
self
,
node
):
def
visit_SingleAssignmentNode
(
self
,
node
):
if
(
isinstance
(
node
.
rhs
,
ImportNode
)
and
if
(
isinstance
(
node
.
rhs
,
ExprNodes
.
ImportNode
)
and
node
.
rhs
.
module_name
.
value
==
u'cython'
):
node
.
rhs
.
module_name
.
value
==
u'cython'
):
node
=
CImportStatNode
(
node
.
pos
,
node
=
Nodes
.
CImportStatNode
(
node
.
pos
,
module_name
=
u'cython'
,
module_name
=
u'cython'
,
as_name
=
node
.
lhs
.
name
)
as_name
=
node
.
lhs
.
name
)
self
.
visit_CImportStatNode
(
node
)
self
.
visit_CImportStatNode
(
node
)
else
:
else
:
self
.
visitchildren
(
node
)
self
.
visitchildren
(
node
)
...
@@ -687,7 +693,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -687,7 +693,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
# If node is the contents of an directive (in a with statement or
# If node is the contents of an directive (in a with statement or
# decorator), returns a list of (directivename, value) pairs.
# decorator), returns a list of (directivename, value) pairs.
# Otherwise, returns None
# Otherwise, returns None
if
isinstance
(
node
,
CallNode
):
if
isinstance
(
node
,
ExprNodes
.
CallNode
):
self
.
visit
(
node
.
function
)
self
.
visit
(
node
.
function
)
optname
=
node
.
function
.
as_cython_attribute
()
optname
=
node
.
function
.
as_cython_attribute
()
if
optname
:
if
optname
:
...
@@ -712,7 +718,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -712,7 +718,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
return
directives
return
directives
directives
.
append
(
self
.
try_to_parse_directive
(
optname
,
args
,
kwds
,
node
.
function
.
pos
))
directives
.
append
(
self
.
try_to_parse_directive
(
optname
,
args
,
kwds
,
node
.
function
.
pos
))
return
directives
return
directives
elif
isinstance
(
node
,
(
AttributeNode
,
NameNode
)):
elif
isinstance
(
node
,
(
ExprNodes
.
AttributeNode
,
ExprNodes
.
NameNode
)):
self
.
visit
(
node
)
self
.
visit
(
node
)
optname
=
node
.
as_cython_attribute
()
optname
=
node
.
as_cython_attribute
()
if
optname
:
if
optname
:
...
@@ -728,15 +734,16 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -728,15 +734,16 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
def
try_to_parse_directive
(
self
,
optname
,
args
,
kwds
,
pos
):
def
try_to_parse_directive
(
self
,
optname
,
args
,
kwds
,
pos
):
directivetype
=
Options
.
directive_types
.
get
(
optname
)
directivetype
=
Options
.
directive_types
.
get
(
optname
)
if
len
(
args
)
==
1
and
isinstance
(
args
[
0
],
NoneNode
):
if
len
(
args
)
==
1
and
isinstance
(
args
[
0
],
ExprNodes
.
NoneNode
):
return
optname
,
Options
.
directive_defaults
[
optname
]
return
optname
,
Options
.
directive_defaults
[
optname
]
elif
directivetype
is
bool
:
elif
directivetype
is
bool
:
if
kwds
is
not
None
or
len
(
args
)
!=
1
or
not
isinstance
(
args
[
0
],
BoolNode
):
if
kwds
is
not
None
or
len
(
args
)
!=
1
or
not
isinstance
(
args
[
0
],
ExprNodes
.
BoolNode
):
raise
PostParseError
(
pos
,
raise
PostParseError
(
pos
,
'The %s directive takes one compile-time boolean argument'
%
optname
)
'The %s directive takes one compile-time boolean argument'
%
optname
)
return
(
optname
,
args
[
0
].
value
)
return
(
optname
,
args
[
0
].
value
)
elif
directivetype
is
str
:
elif
directivetype
is
str
:
if
kwds
is
not
None
or
len
(
args
)
!=
1
or
not
isinstance
(
args
[
0
],
(
StringNode
,
UnicodeNode
)):
if
kwds
is
not
None
or
len
(
args
)
!=
1
or
not
isinstance
(
args
[
0
],
(
ExprNodes
.
StringNode
,
ExprNodes
.
UnicodeNode
)):
raise
PostParseError
(
pos
,
raise
PostParseError
(
pos
,
'The %s directive takes one compile-time string argument'
%
optname
)
'The %s directive takes one compile-time string argument'
%
optname
)
return
(
optname
,
str
(
args
[
0
].
value
))
return
(
optname
,
str
(
args
[
0
].
value
))
...
@@ -758,10 +765,10 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -758,10 +765,10 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
newdirectives
=
copy
.
copy
(
olddirectives
)
newdirectives
=
copy
.
copy
(
olddirectives
)
newdirectives
.
update
(
directives
)
newdirectives
.
update
(
directives
)
self
.
directives
=
newdirectives
self
.
directives
=
newdirectives
assert
isinstance
(
body
,
StatListNode
),
body
assert
isinstance
(
body
,
Nodes
.
StatListNode
),
body
retbody
=
self
.
visit_Node
(
body
)
retbody
=
self
.
visit_Node
(
body
)
directive
=
CompilerDirectivesNode
(
pos
=
retbody
.
pos
,
body
=
retbody
,
directive
=
Nodes
.
CompilerDirectivesNode
(
pos
=
retbody
.
pos
,
body
=
retbody
,
directives
=
newdirectives
)
directives
=
newdirectives
)
self
.
directives
=
olddirectives
self
.
directives
=
olddirectives
return
directive
return
directive
...
@@ -770,7 +777,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -770,7 +777,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
directives
=
self
.
_extract_directives
(
node
,
'function'
)
directives
=
self
.
_extract_directives
(
node
,
'function'
)
if
not
directives
:
if
not
directives
:
return
self
.
visit_Node
(
node
)
return
self
.
visit_Node
(
node
)
body
=
StatListNode
(
node
.
pos
,
stats
=
[
node
])
body
=
Nodes
.
StatListNode
(
node
.
pos
,
stats
=
[
node
])
return
self
.
visit_with_directives
(
body
,
directives
)
return
self
.
visit_with_directives
(
body
,
directives
)
def
visit_CVarDefNode
(
self
,
node
):
def
visit_CVarDefNode
(
self
,
node
):
...
@@ -789,14 +796,14 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -789,14 +796,14 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
directives
=
self
.
_extract_directives
(
node
,
'cclass'
)
directives
=
self
.
_extract_directives
(
node
,
'cclass'
)
if
not
directives
:
if
not
directives
:
return
self
.
visit_Node
(
node
)
return
self
.
visit_Node
(
node
)
body
=
StatListNode
(
node
.
pos
,
stats
=
[
node
])
body
=
Nodes
.
StatListNode
(
node
.
pos
,
stats
=
[
node
])
return
self
.
visit_with_directives
(
body
,
directives
)
return
self
.
visit_with_directives
(
body
,
directives
)
def
visit_PyClassDefNode
(
self
,
node
):
def
visit_PyClassDefNode
(
self
,
node
):
directives
=
self
.
_extract_directives
(
node
,
'class'
)
directives
=
self
.
_extract_directives
(
node
,
'class'
)
if
not
directives
:
if
not
directives
:
return
self
.
visit_Node
(
node
)
return
self
.
visit_Node
(
node
)
body
=
StatListNode
(
node
.
pos
,
stats
=
[
node
])
body
=
Nodes
.
StatListNode
(
node
.
pos
,
stats
=
[
node
])
return
self
.
visit_with_directives
(
body
,
directives
)
return
self
.
visit_with_directives
(
body
,
directives
)
def
_extract_directives
(
self
,
node
,
scope_name
):
def
_extract_directives
(
self
,
node
,
scope_name
):
...
@@ -813,7 +820,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -813,7 +820,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
directives
.
append
(
directive
)
directives
.
append
(
directive
)
else
:
else
:
realdecs
.
append
(
dec
)
realdecs
.
append
(
dec
)
if
realdecs
and
isinstance
(
node
,
(
CFuncDefNode
,
CClassDefNode
)):
if
realdecs
and
isinstance
(
node
,
(
Nodes
.
CFuncDefNode
,
Nodes
.
CClassDefNode
)):
raise
PostParseError
(
realdecs
[
0
].
pos
,
"Cdef functions/classes cannot take arbitrary decorators."
)
raise
PostParseError
(
realdecs
[
0
].
pos
,
"Cdef functions/classes cannot take arbitrary decorators."
)
else
:
else
:
node
.
decorators
=
realdecs
node
.
decorators
=
realdecs
...
@@ -848,7 +855,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -848,7 +855,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
name
,
value
=
directive
name
,
value
=
directive
if
name
==
'nogil'
:
if
name
==
'nogil'
:
# special case: in pure mode, "with nogil" spells "with cython.nogil"
# special case: in pure mode, "with nogil" spells "with cython.nogil"
node
=
GILStatNode
(
node
.
pos
,
state
=
"nogil"
,
body
=
node
.
body
)
node
=
Nodes
.
GILStatNode
(
node
.
pos
,
state
=
"nogil"
,
body
=
node
.
body
)
return
self
.
visit_Node
(
node
)
return
self
.
visit_Node
(
node
)
if
self
.
check_directive_scope
(
node
.
pos
,
name
,
'with statement'
):
if
self
.
check_directive_scope
(
node
.
pos
,
name
,
'with statement'
):
directive_dict
[
name
]
=
value
directive_dict
[
name
]
=
value
...
@@ -908,7 +915,7 @@ class WithTransform(CythonTransform, SkipDeclarations):
...
@@ -908,7 +915,7 @@ class WithTransform(CythonTransform, SkipDeclarations):
handle
=
"__tmpvar_%d"
%
TemplateTransform
.
temp_name_counter
handle
=
"__tmpvar_%d"
%
TemplateTransform
.
temp_name_counter
self
.
visitchildren
(
node
,
[
'body'
])
self
.
visitchildren
(
node
,
[
'body'
])
excinfo_temp
=
NameNode
(
node
.
pos
,
name
=
handle
)
#TempHandle(Builtin.tuple_type)
excinfo_temp
=
ExprNodes
.
NameNode
(
node
.
pos
,
name
=
handle
)
#TempHandle(Builtin.tuple_type)
if
node
.
target
is
not
None
:
if
node
.
target
is
not
None
:
result
=
self
.
template_with_target
.
substitute
({
result
=
self
.
template_with_target
.
substitute
({
u'EXPR'
:
node
.
manager
,
u'EXPR'
:
node
.
manager
,
...
@@ -925,7 +932,7 @@ class WithTransform(CythonTransform, SkipDeclarations):
...
@@ -925,7 +932,7 @@ class WithTransform(CythonTransform, SkipDeclarations):
# Set except excinfo target to EXCINFO
# Set except excinfo target to EXCINFO
try_except
=
result
.
stats
[
-
1
].
body
.
stats
[
-
1
]
try_except
=
result
.
stats
[
-
1
].
body
.
stats
[
-
1
]
try_except
.
except_clauses
[
0
].
excinfo_target
=
NameNode
(
node
.
pos
,
name
=
handle
)
try_except
.
except_clauses
[
0
].
excinfo_target
=
ExprNodes
.
NameNode
(
node
.
pos
,
name
=
handle
)
# excinfo_temp.ref(node.pos))
# excinfo_temp.ref(node.pos))
# result.stats[-1].body.stats[-1] = TempsBlockNode(
# result.stats[-1].body.stats[-1] = TempsBlockNode(
...
@@ -972,15 +979,15 @@ class DecoratorTransform(CythonTransform, SkipDeclarations):
...
@@ -972,15 +979,15 @@ class DecoratorTransform(CythonTransform, SkipDeclarations):
class_node
,
class_node
.
name
)
class_node
,
class_node
.
name
)
def
_handle_decorators
(
self
,
node
,
name
):
def
_handle_decorators
(
self
,
node
,
name
):
decorator_result
=
NameNode
(
node
.
pos
,
name
=
name
)
decorator_result
=
ExprNodes
.
NameNode
(
node
.
pos
,
name
=
name
)
for
decorator
in
node
.
decorators
[::
-
1
]:
for
decorator
in
node
.
decorators
[::
-
1
]:
decorator_result
=
SimpleCallNode
(
decorator_result
=
ExprNodes
.
SimpleCallNode
(
decorator
.
pos
,
decorator
.
pos
,
function
=
decorator
.
decorator
,
function
=
decorator
.
decorator
,
args
=
[
decorator_result
])
args
=
[
decorator_result
])
name_node
=
NameNode
(
node
.
pos
,
name
=
name
)
name_node
=
ExprNodes
.
NameNode
(
node
.
pos
,
name
=
name
)
reassignment
=
SingleAssignmentNode
(
reassignment
=
Nodes
.
SingleAssignmentNode
(
node
.
pos
,
node
.
pos
,
lhs
=
name_node
,
lhs
=
name_node
,
rhs
=
decorator_result
)
rhs
=
decorator_result
)
...
@@ -1139,9 +1146,9 @@ property NAME:
...
@@ -1139,9 +1146,9 @@ property NAME:
elif
entry
.
visibility
==
'readonly'
:
elif
entry
.
visibility
==
'readonly'
:
template
=
self
.
basic_property_ro
template
=
self
.
basic_property_ro
property
=
template
.
substitute
({
property
=
template
.
substitute
({
u"ATTR"
:
AttributeNode
(
pos
=
entry
.
pos
,
u"ATTR"
:
ExprNodes
.
AttributeNode
(
pos
=
entry
.
pos
,
obj
=
NameNode
(
pos
=
entry
.
pos
,
name
=
"self"
),
obj
=
ExprNodes
.
NameNode
(
pos
=
entry
.
pos
,
name
=
"self"
),
attribute
=
entry
.
name
),
attribute
=
entry
.
name
),
},
pos
=
entry
.
pos
).
stats
[
0
]
},
pos
=
entry
.
pos
).
stats
[
0
]
property
.
name
=
entry
.
name
property
.
name
=
entry
.
name
# ---------------------------------------
# ---------------------------------------
...
@@ -1194,26 +1201,26 @@ class ExpandInplaceOperators(EnvTransform):
...
@@ -1194,26 +1201,26 @@ class ExpandInplaceOperators(EnvTransform):
if
lhs
.
type
.
is_cpp_class
:
if
lhs
.
type
.
is_cpp_class
:
# No getting around this exact operator here.
# No getting around this exact operator here.
return
node
return
node
if
isinstance
(
lhs
,
IndexNode
)
and
lhs
.
is_buffer_access
:
if
isinstance
(
lhs
,
ExprNodes
.
IndexNode
)
and
lhs
.
is_buffer_access
:
# There is code to handle this case.
# There is code to handle this case.
return
node
return
node
env
=
self
.
current_env
()
env
=
self
.
current_env
()
def
side_effect_free_reference
(
node
,
setting
=
False
):
def
side_effect_free_reference
(
node
,
setting
=
False
):
if
isinstance
(
node
,
NameNode
):
if
isinstance
(
node
,
ExprNodes
.
NameNode
):
return
node
,
[]
return
node
,
[]
elif
node
.
type
.
is_pyobject
and
not
setting
:
elif
node
.
type
.
is_pyobject
and
not
setting
:
node
=
LetRefNode
(
node
)
node
=
LetRefNode
(
node
)
return
node
,
[
node
]
return
node
,
[
node
]
elif
isinstance
(
node
,
IndexNode
):
elif
isinstance
(
node
,
ExprNodes
.
IndexNode
):
if
node
.
is_buffer_access
:
if
node
.
is_buffer_access
:
raise
ValueError
,
"Buffer access"
raise
ValueError
,
"Buffer access"
base
,
temps
=
side_effect_free_reference
(
node
.
base
)
base
,
temps
=
side_effect_free_reference
(
node
.
base
)
index
=
LetRefNode
(
node
.
index
)
index
=
LetRefNode
(
node
.
index
)
return
IndexNode
(
node
.
pos
,
base
=
base
,
index
=
index
),
temps
+
[
index
]
return
ExprNodes
.
IndexNode
(
node
.
pos
,
base
=
base
,
index
=
index
),
temps
+
[
index
]
elif
isinstance
(
node
,
AttributeNode
):
elif
isinstance
(
node
,
ExprNodes
.
AttributeNode
):
obj
,
temps
=
side_effect_free_reference
(
node
.
obj
)
obj
,
temps
=
side_effect_free_reference
(
node
.
obj
)
return
AttributeNode
(
node
.
pos
,
obj
=
obj
,
attribute
=
node
.
attribute
),
temps
return
ExprNodes
.
AttributeNode
(
node
.
pos
,
obj
=
obj
,
attribute
=
node
.
attribute
),
temps
else
:
else
:
node
=
LetRefNode
(
node
)
node
=
LetRefNode
(
node
)
return
node
,
[
node
]
return
node
,
[
node
]
...
@@ -1222,19 +1229,19 @@ class ExpandInplaceOperators(EnvTransform):
...
@@ -1222,19 +1229,19 @@ class ExpandInplaceOperators(EnvTransform):
except
ValueError
:
except
ValueError
:
return
node
return
node
dup
=
lhs
.
__class__
(
**
lhs
.
__dict__
)
dup
=
lhs
.
__class__
(
**
lhs
.
__dict__
)
binop
=
binop_node
(
node
.
pos
,
binop
=
ExprNodes
.
binop_node
(
node
.
pos
,
operator
=
node
.
operator
,
operator
=
node
.
operator
,
operand1
=
dup
,
operand1
=
dup
,
operand2
=
rhs
,
operand2
=
rhs
,
inplace
=
True
)
inplace
=
True
)
# Manually analyse types for new node.
# Manually analyse types for new node.
lhs
.
analyse_target_types
(
env
)
lhs
.
analyse_target_types
(
env
)
dup
.
analyse_types
(
env
)
dup
.
analyse_types
(
env
)
binop
.
analyse_operation
(
env
)
binop
.
analyse_operation
(
env
)
node
=
SingleAssignmentNode
(
node
=
Nodes
.
SingleAssignmentNode
(
node
.
pos
,
node
.
pos
,
lhs
=
lhs
,
lhs
=
lhs
,
rhs
=
binop
.
coerce_to
(
lhs
.
type
,
env
))
rhs
=
binop
.
coerce_to
(
lhs
.
type
,
env
))
# Use LetRefNode to avoid side effects.
# Use LetRefNode to avoid side effects.
let_ref_nodes
.
reverse
()
let_ref_nodes
.
reverse
()
for
t
in
let_ref_nodes
:
for
t
in
let_ref_nodes
:
...
@@ -1487,12 +1494,12 @@ class TransformBuiltinMethods(EnvTransform):
...
@@ -1487,12 +1494,12 @@ class TransformBuiltinMethods(EnvTransform):
attribute
=
node
.
as_cython_attribute
()
attribute
=
node
.
as_cython_attribute
()
if
attribute
:
if
attribute
:
if
attribute
==
u'compiled'
:
if
attribute
==
u'compiled'
:
node
=
BoolNode
(
node
.
pos
,
value
=
True
)
node
=
ExprNodes
.
BoolNode
(
node
.
pos
,
value
=
True
)
elif
attribute
==
u'NULL'
:
elif
attribute
==
u'NULL'
:
node
=
NullNode
(
node
.
pos
)
node
=
ExprNodes
.
NullNode
(
node
.
pos
)
elif
attribute
in
(
u'set'
,
u'frozenset'
):
elif
attribute
in
(
u'set'
,
u'frozenset'
):
node
=
NameNode
(
node
.
pos
,
name
=
EncodedString
(
attribute
),
node
=
ExprNodes
.
NameNode
(
node
.
pos
,
name
=
EncodedString
(
attribute
),
entry
=
self
.
current_env
().
builtin_scope
().
lookup_here
(
attribute
))
entry
=
self
.
current_env
().
builtin_scope
().
lookup_here
(
attribute
))
elif
not
PyrexTypes
.
parse_basic_type
(
attribute
):
elif
not
PyrexTypes
.
parse_basic_type
(
attribute
):
error
(
node
.
pos
,
u"'%s' not a valid cython attribute or is being used incorrectly"
%
attribute
)
error
(
node
.
pos
,
u"'%s' not a valid cython attribute or is being used incorrectly"
%
attribute
)
return
node
return
node
...
@@ -1536,7 +1543,7 @@ class TransformBuiltinMethods(EnvTransform):
...
@@ -1536,7 +1543,7 @@ class TransformBuiltinMethods(EnvTransform):
else
:
else
:
type
=
node
.
args
[
0
].
analyse_as_type
(
self
.
current_env
())
type
=
node
.
args
[
0
].
analyse_as_type
(
self
.
current_env
())
if
type
:
if
type
:
node
=
TypecastNode
(
node
.
function
.
pos
,
type
=
type
,
operand
=
node
.
args
[
1
])
node
=
ExprNodes
.
TypecastNode
(
node
.
function
.
pos
,
type
=
type
,
operand
=
node
.
args
[
1
])
else
:
else
:
error
(
node
.
args
[
0
].
pos
,
"Not a type"
)
error
(
node
.
args
[
0
].
pos
,
"Not a type"
)
elif
function
==
u'sizeof'
:
elif
function
==
u'sizeof'
:
...
@@ -1545,23 +1552,23 @@ class TransformBuiltinMethods(EnvTransform):
...
@@ -1545,23 +1552,23 @@ class TransformBuiltinMethods(EnvTransform):
else
:
else
:
type
=
node
.
args
[
0
].
analyse_as_type
(
self
.
current_env
())
type
=
node
.
args
[
0
].
analyse_as_type
(
self
.
current_env
())
if
type
:
if
type
:
node
=
SizeofTypeNode
(
node
.
function
.
pos
,
arg_type
=
type
)
node
=
ExprNodes
.
SizeofTypeNode
(
node
.
function
.
pos
,
arg_type
=
type
)
else
:
else
:
node
=
SizeofVarNode
(
node
.
function
.
pos
,
operand
=
node
.
args
[
0
])
node
=
ExprNodes
.
SizeofVarNode
(
node
.
function
.
pos
,
operand
=
node
.
args
[
0
])
elif
function
==
'cmod'
:
elif
function
==
'cmod'
:
if
len
(
node
.
args
)
!=
2
:
if
len
(
node
.
args
)
!=
2
:
error
(
node
.
function
.
pos
,
u"cmod() takes exactly two arguments"
)
error
(
node
.
function
.
pos
,
u"cmod() takes exactly two arguments"
)
else
:
else
:
node
=
binop_node
(
node
.
function
.
pos
,
'%'
,
node
.
args
[
0
],
node
.
args
[
1
])
node
=
ExprNodes
.
binop_node
(
node
.
function
.
pos
,
'%'
,
node
.
args
[
0
],
node
.
args
[
1
])
node
.
cdivision
=
True
node
.
cdivision
=
True
elif
function
==
'cdiv'
:
elif
function
==
'cdiv'
:
if
len
(
node
.
args
)
!=
2
:
if
len
(
node
.
args
)
!=
2
:
error
(
node
.
function
.
pos
,
u"cdiv() takes exactly two arguments"
)
error
(
node
.
function
.
pos
,
u"cdiv() takes exactly two arguments"
)
else
:
else
:
node
=
binop_node
(
node
.
function
.
pos
,
'/'
,
node
.
args
[
0
],
node
.
args
[
1
])
node
=
ExprNodes
.
binop_node
(
node
.
function
.
pos
,
'/'
,
node
.
args
[
0
],
node
.
args
[
1
])
node
.
cdivision
=
True
node
.
cdivision
=
True
elif
function
==
u'set'
:
elif
function
==
u'set'
:
node
.
function
=
NameNode
(
node
.
pos
,
name
=
EncodedString
(
'set'
))
node
.
function
=
ExprNodes
.
NameNode
(
node
.
pos
,
name
=
EncodedString
(
'set'
))
else
:
else
:
error
(
node
.
function
.
pos
,
u"'%s' not a valid cython language construct"
%
function
)
error
(
node
.
function
.
pos
,
u"'%s' not a valid cython language construct"
%
function
)
...
...
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