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
Boxiang Sun
cython
Commits
0869f9d4
Commit
0869f9d4
authored
Oct 07, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more flexable declare
parent
80d9a6ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
8 deletions
+32
-8
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+23
-2
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+2
-2
Cython/Shadow.py
Cython/Shadow.py
+7
-4
No files found.
Cython/Compiler/Nodes.py
View file @
0869f9d4
...
...
@@ -2549,6 +2549,22 @@ class ExprStatNode(StatNode):
child_attrs
=
[
"expr"
]
def
analyse_declarations
(
self
,
env
):
import
ExprNodes
if
isinstance
(
self
.
expr
,
ExprNodes
.
GeneralCallNode
):
func
=
self
.
expr
.
function
.
as_cython_attribute
()
if
func
==
u'declare'
:
args
,
kwds
=
self
.
expr
.
explicit_args_kwds
()
if
len
(
args
):
error
(
self
.
expr
.
pos
,
"Variable names must be specified."
)
for
var
,
type_node
in
kwds
.
key_value_pairs
:
type
=
type_node
.
analyse_as_type
(
env
)
if
type
is
None
:
error
(
type_node
.
pos
,
"Unknown type"
)
else
:
env
.
declare_var
(
var
.
value
,
type
,
var
.
pos
,
is_cdef
=
True
)
self
.
__class__
=
PassStatNode
def
analyse_expressions
(
self
,
env
):
self
.
expr
.
analyse_expressions
(
env
)
self
.
expr
.
release_temp
(
env
)
...
...
@@ -2609,8 +2625,7 @@ class SingleAssignmentNode(AssignmentNode):
args
,
kwds
=
self
.
rhs
.
explicit_args_kwds
()
if
func_name
in
[
'declare'
,
'typedef'
]:
self
.
declaration_only
=
True
if
len
(
args
)
!=
1
or
kwds
is
not
None
:
if
len
(
args
)
>
2
or
kwds
is
not
None
:
error
(
rhs
.
pos
,
"Can only declare one type at a time."
)
return
type
=
args
[
0
].
analyse_as_type
(
env
)
...
...
@@ -2628,7 +2643,13 @@ class SingleAssignmentNode(AssignmentNode):
return
for
var
,
pos
in
vars
:
env
.
declare_var
(
var
,
type
,
pos
,
is_cdef
=
True
)
if
len
(
args
)
==
2
:
# we have a value
self
.
rhs
=
args
[
1
]
else
:
self
.
declaration_only
=
True
else
:
self
.
declaration_only
=
True
if
not
isinstance
(
lhs
,
ExprNodes
.
NameNode
):
error
(
lhs
.
pos
,
"Invalid declaration."
)
env
.
declare_typedef
(
lhs
.
name
,
type
,
self
.
pos
,
'private'
)
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
0869f9d4
...
...
@@ -719,12 +719,12 @@ class TransformBuiltinMethods(EnvTransform):
if
attribute
==
u'compiled'
:
node
=
BoolNode
(
node
.
pos
,
value
=
True
)
else
:
error
(
node
.
pos
,
u"'%s' not a valid cython attribute"
%
attribute
)
error
(
node
.
pos
,
u"'%s' not a valid cython attribute
or is being used incorrectly
"
%
attribute
)
return
node
def
visit_SimpleCallNode
(
self
,
node
):
# locals
# locals
builtin
if
isinstance
(
node
.
function
,
ExprNodes
.
NameNode
):
if
node
.
function
.
name
==
'locals'
:
pos
=
node
.
pos
...
...
Cython/Shadow.py
View file @
0869f9d4
...
...
@@ -21,11 +21,14 @@ def sizeof(arg):
def
address
(
arg
):
return
pointer
(
type
(
arg
))([
arg
])
def
declare
(
type
):
if
callable
(
type
):
return
type
()
def
declare
(
type
=
None
,
value
=
None
,
**
kwds
):
if
type
and
callable
(
type
):
if
value
:
return
type
(
value
)
else
:
return
type
()
else
:
return
Non
e
return
valu
e
# Emulated types
...
...
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