Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d713b9ec
Commit
d713b9ec
authored
Jan 10, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some more changes related to the new except syntax and semantics,
by Collin Winter.
parent
f16bc2a2
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
47 additions
and
33 deletions
+47
-33
Grammar/Grammar
Grammar/Grammar
+1
-1
Include/Python-ast.h
Include/Python-ast.h
+3
-3
Lib/compiler/pycodegen.py
Lib/compiler/pycodegen.py
+25
-3
Lib/compiler/transformer.py
Lib/compiler/transformer.py
+6
-6
Parser/Python.asdl
Parser/Python.asdl
+1
-1
Python/Python-ast.c
Python/Python-ast.c
+2
-2
Python/ast.c
Python/ast.c
+1
-3
Python/compile.c
Python/compile.c
+5
-12
Python/graminit.c
Python/graminit.c
+1
-1
Python/symtable.c
Python/symtable.c
+2
-1
No files found.
Grammar/Grammar
View file @
d713b9ec
...
...
@@ -79,7 +79,7 @@ try_stmt: ('try' ':' suite
with_stmt: 'with' test [ with_var ] ':' suite
with_var: 'as' expr
# NB compile.c makes sure that the default except clause is last
except_clause: 'except' [test ['as'
test
]]
except_clause: 'except' [test ['as'
NAME
]]
suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
# Backward compatibility cruft to support:
...
...
Include/Python-ast.h
View file @
d713b9ec
...
...
@@ -322,7 +322,7 @@ struct _comprehension {
struct
_excepthandler
{
expr_ty
type
;
expr_ty
name
;
identifier
name
;
asdl_seq
*
body
;
int
lineno
;
int
col_offset
;
...
...
@@ -448,8 +448,8 @@ slice_ty ExtSlice(asdl_seq * dims, PyArena *arena);
slice_ty
Index
(
expr_ty
value
,
PyArena
*
arena
);
comprehension_ty
comprehension
(
expr_ty
target
,
expr_ty
iter
,
asdl_seq
*
ifs
,
PyArena
*
arena
);
excepthandler_ty
excepthandler
(
expr_ty
type
,
expr_ty
name
,
asdl_seq
*
body
,
int
lineno
,
int
col_offset
,
PyArena
*
arena
);
excepthandler_ty
excepthandler
(
expr_ty
type
,
identifier
name
,
asdl_seq
*
body
,
int
lineno
,
int
col_offset
,
PyArena
*
arena
);
arguments_ty
arguments
(
asdl_seq
*
args
,
identifier
vararg
,
expr_ty
varargannotation
,
asdl_seq
*
kwonlyargs
,
identifier
kwarg
,
expr_ty
kwargannotation
,
asdl_seq
*
defaults
,
...
...
Lib/compiler/pycodegen.py
View file @
d713b9ec
...
...
@@ -825,11 +825,33 @@ class CodeGenerator:
self
.
emit
(
'POP_TOP'
)
self
.
emit
(
'POP_TOP'
)
if
target
:
self
.
visit
(
target
)
cleanup_body
=
self
.
newBlock
()
cleanup_final
=
self
.
newBlock
()
target_name
=
target
[
1
]
self
.
storeName
(
target_name
)
self
.
emit
(
'POP_TOP'
)
self
.
emit
(
'SETUP_FINALLY'
,
cleanup_final
)
self
.
nextBlock
(
cleanup_body
)
self
.
setups
.
push
((
TRY_FINALLY
,
cleanup_body
))
self
.
visit
(
body
)
self
.
emit
(
'POP_BLOCK'
)
self
.
setups
.
pop
()
self
.
emit
(
'LOAD_CONST'
,
None
)
self
.
nextBlock
(
cleanup_final
)
self
.
setups
.
push
((
END_FINALLY
,
cleanup_final
))
self
.
emit
(
'LOAD_CONST'
,
None
)
self
.
storeName
(
target_name
)
self
.
_implicitNameOp
(
'DELETE'
,
target_name
)
self
.
emit
(
'END_FINALLY'
)
self
.
setups
.
pop
()
else
:
self
.
emit
(
'POP_TOP'
)
self
.
emit
(
'POP_TOP'
)
self
.
visit
(
body
)
self
.
emit
(
'POP_TOP'
)
self
.
visit
(
body
)
self
.
emit
(
'JUMP_FORWARD'
,
end
)
if
expr
:
self
.
nextBlock
(
next
)
...
...
Lib/compiler/transformer.py
View file @
d713b9ec
...
...
@@ -988,16 +988,16 @@ class Transformer:
for
i
in
range
(
3
,
len
(
nodelist
),
3
):
node
=
nodelist
[
i
]
if
node
[
0
]
==
symbol
.
except_clause
:
# except_clause: 'except' [expr ['
,' expr
]] */
# except_clause: 'except' [expr ['
as' NAME
]] */
if
len
(
node
)
>
2
:
expr
1
=
self
.
com_node
(
node
[
2
])
expr
=
self
.
com_node
(
node
[
2
])
if
len
(
node
)
>
4
:
expr
2
=
self
.
com_assign
(
node
[
4
],
OP_ASSIGN
)
expr
_name
=
node
[
4
]
else
:
expr
2
=
None
expr
_name
=
None
else
:
expr
1
=
expr2
=
None
clauses
.
append
((
expr
1
,
expr2
,
self
.
com_node
(
nodelist
[
i
+
2
])))
expr
=
expr_name
=
None
clauses
.
append
((
expr
,
expr_name
,
self
.
com_node
(
nodelist
[
i
+
2
])))
if
node
[
0
]
==
token
.
NAME
:
if
node
[
1
]
==
'else'
:
...
...
Parser/Python.asdl
View file @
d713b9ec
...
...
@@ -97,7 +97,7 @@ module Python version "$Revision$"
-- TODO(jhylton): Figure out if there is a better way to handle
-- lineno and col_offset fields, particularly when
-- ast is exposed to Python.
excepthandler = (expr? type,
exp
r? name, stmt* body, int lineno,
excepthandler = (expr? type,
identifie
r? name, stmt* body, int lineno,
int col_offset)
arguments = (arg* args, identifier? vararg, expr? varargannotation,
...
...
Python/Python-ast.c
View file @
d713b9ec
...
...
@@ -1836,7 +1836,7 @@ comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
}
excepthandler_ty
excepthandler
(
expr_ty
type
,
expr_ty
name
,
asdl_seq
*
body
,
int
lineno
,
int
excepthandler
(
expr_ty
type
,
identifier
name
,
asdl_seq
*
body
,
int
lineno
,
int
col_offset
,
PyArena
*
arena
)
{
excepthandler_ty
p
;
...
...
@@ -2928,7 +2928,7 @@ ast2obj_excepthandler(void* _o)
if
(
PyObject_SetAttrString
(
result
,
"type"
,
value
)
==
-
1
)
goto
failed
;
Py_DECREF
(
value
);
value
=
ast2obj_
exp
r
(
o
->
name
);
value
=
ast2obj_
identifie
r
(
o
->
name
);
if
(
!
value
)
goto
failed
;
if
(
PyObject_SetAttrString
(
result
,
"name"
,
value
)
==
-
1
)
goto
failed
;
...
...
Python/ast.c
View file @
d713b9ec
...
...
@@ -2899,11 +2899,9 @@ ast_for_except_clause(struct compiling *c, const node *exc, node *body)
else
if
(
NCH
(
exc
)
==
4
)
{
asdl_seq
*
suite_seq
;
expr_ty
expression
;
expr_ty
e
=
ast_for_expr
(
c
,
CHILD
(
exc
,
3
));
identifier
e
=
NEW_IDENTIFIER
(
CHILD
(
exc
,
3
));
if
(
!
e
)
return
NULL
;
if
(
!
set_context
(
e
,
Store
,
CHILD
(
exc
,
3
)))
return
NULL
;
expression
=
ast_for_expr
(
c
,
CHILD
(
exc
,
1
));
if
(
!
expression
)
return
NULL
;
...
...
Python/compile.c
View file @
d713b9ec
...
...
@@ -1956,16 +1956,13 @@ compiler_try_except(struct compiler *c, stmt_ty s)
ADDOP
(
c
,
POP_TOP
);
if
(
handler
->
name
)
{
basicblock
*
cleanup_end
,
*
cleanup_body
;
expr_context_ty
orig_ctx
;
assert
(
handler
->
name
->
kind
==
Name_kind
);
cleanup_end
=
compiler_new_block
(
c
);
cleanup_body
=
compiler_new_block
(
c
);
if
(
!
(
cleanup_end
||
cleanup_body
))
return
0
;
VISIT
(
c
,
expr
,
handler
->
nam
e
);
compiler_nameop
(
c
,
handler
->
name
,
Stor
e
);
ADDOP
(
c
,
POP_TOP
);
/*
...
...
@@ -1998,14 +1995,10 @@ compiler_try_except(struct compiler *c, stmt_ty s)
/* name = None */
ADDOP_O
(
c
,
LOAD_CONST
,
Py_None
,
consts
);
orig_ctx
=
handler
->
name
->
v
.
Name
.
ctx
;
handler
->
name
->
v
.
Name
.
ctx
=
Store
;
VISIT
(
c
,
expr
,
handler
->
name
);
/* del name */
handler
->
name
->
v
.
Name
.
ctx
=
Del
;
VISIT
(
c
,
expr
,
handler
->
name
);
handler
->
name
->
v
.
Name
.
ctx
=
orig_ctx
;
compiler_nameop
(
c
,
handler
->
name
,
Store
);
/* del name */
compiler_nameop
(
c
,
handler
->
name
,
Del
);
ADDOP
(
c
,
END_FINALLY
);
compiler_pop_fblock
(
c
,
FINALLY_END
,
cleanup_end
);
...
...
Python/graminit.c
View file @
d713b9ec
...
...
@@ -1053,7 +1053,7 @@ static arc arcs_46_2[2] = {
{
0
,
2
},
};
static
arc
arcs_46_3
[
1
]
=
{
{
22
,
4
},
{
19
,
4
},
};
static
arc
arcs_46_4
[
1
]
=
{
{
0
,
4
},
...
...
Python/symtable.c
View file @
d713b9ec
...
...
@@ -1335,7 +1335,8 @@ symtable_visit_excepthandler(struct symtable *st, excepthandler_ty eh)
if
(
eh
->
type
)
VISIT
(
st
,
expr
,
eh
->
type
);
if
(
eh
->
name
)
VISIT
(
st
,
expr
,
eh
->
name
);
if
(
!
symtable_add_def
(
st
,
eh
->
name
,
DEF_LOCAL
))
return
0
;
VISIT_SEQ
(
st
,
stmt
,
eh
->
body
);
return
1
;
}
...
...
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