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
e2498419
Commit
e2498419
authored
13 years ago
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a asdl bytes type, so Bytes.s be properly typechecked
parent
18205baf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
7 deletions
+28
-7
Include/asdl.h
Include/asdl.h
+1
-0
Parser/Python.asdl
Parser/Python.asdl
+2
-2
Parser/asdl.py
Parser/asdl.py
+1
-1
Parser/asdl_c.py
Parser/asdl_c.py
+10
-0
Python/Python-ast.c
Python/Python-ast.c
+14
-4
No files found.
Include/asdl.h
View file @
e2498419
...
...
@@ -3,6 +3,7 @@
typedef
PyObject
*
identifier
;
typedef
PyObject
*
string
;
typedef
PyObject
*
bytes
;
typedef
PyObject
*
object
;
/* It would be nice if the code generated by asdl_c.py was completely
...
...
This diff is collapsed.
Click to expand it.
Parser/Python.asdl
View file @
e2498419
-- ASDL's f
our builtin types are identifier, int, string
, object
-- ASDL's f
ive builtin types are identifier, int, string, bytes
, object
module Python
{
...
...
@@ -67,7 +67,7 @@ module Python
expr? starargs, expr? kwargs)
| Num(object n) -- a number as a PyObject.
| Str(string s) -- need to specify raw, unicode, etc?
| Bytes(
string
s)
| Bytes(
bytes
s)
| Ellipsis
-- other literals? bools?
...
...
This diff is collapsed.
Click to expand it.
Parser/asdl.py
View file @
e2498419
...
...
@@ -228,7 +228,7 @@ class ASDLParser(spark.GenericParser, object):
" field ::= Id ? "
return
Field
(
type
[
0
],
opt
=
True
)
builtin_types
=
(
"identifier"
,
"string"
,
"int"
,
"bool"
,
"object"
)
builtin_types
=
(
"identifier"
,
"string"
,
"
bytes"
,
"
int"
,
"bool"
,
"object"
)
# below is a collection of classes to capture the AST of an AST :-)
# not sure if any of the methods are useful yet, but I'm adding them
...
...
This diff is collapsed.
Click to expand it.
Parser/asdl_c.py
View file @
e2498419
...
...
@@ -776,6 +776,7 @@ static PyObject* ast2obj_object(void *o)
}
#define ast2obj_identifier ast2obj_object
#define ast2obj_string ast2obj_object
#define ast2obj_bytes ast2obj_object
static PyObject* ast2obj_int(long b)
{
...
...
@@ -813,6 +814,15 @@ static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
return obj2ast_object(obj, out, arena);
}
static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena)
{
if (!PyBytes_CheckExact(obj)) {
PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes");
return 1;
}
return obj2ast_object(obj, out, arena);
}
static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
{
int i;
...
...
This diff is collapsed.
Click to expand it.
Python/Python-ast.c
View file @
e2498419
...
...
@@ -573,6 +573,7 @@ static PyObject* ast2obj_object(void *o)
}
#define ast2obj_identifier ast2obj_object
#define ast2obj_string ast2obj_object
#define ast2obj_bytes ast2obj_object
static
PyObject
*
ast2obj_int
(
long
b
)
{
...
...
@@ -610,6 +611,15 @@ static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
return
obj2ast_object
(
obj
,
out
,
arena
);
}
static
int
obj2ast_bytes
(
PyObject
*
obj
,
PyObject
**
out
,
PyArena
*
arena
)
{
if
(
!
PyBytes_CheckExact
(
obj
))
{
PyErr_SetString
(
PyExc_TypeError
,
"AST bytes must be of type bytes"
);
return
1
;
}
return
obj2ast_object
(
obj
,
out
,
arena
);
}
static
int
obj2ast_int
(
PyObject
*
obj
,
int
*
out
,
PyArena
*
arena
)
{
int
i
;
...
...
@@ -1773,7 +1783,7 @@ Str(string s, int lineno, int col_offset, PyArena *arena)
}
expr_ty
Bytes
(
string
s
,
int
lineno
,
int
col_offset
,
PyArena
*
arena
)
Bytes
(
bytes
s
,
int
lineno
,
int
col_offset
,
PyArena
*
arena
)
{
expr_ty
p
;
if
(
!
s
)
{
...
...
@@ -2804,7 +2814,7 @@ ast2obj_expr(void* _o)
case
Bytes_kind
:
result
=
PyType_GenericNew
(
Bytes_type
,
NULL
,
NULL
);
if
(
!
result
)
goto
failed
;
value
=
ast2obj_
string
(
o
->
v
.
Bytes
.
s
);
value
=
ast2obj_
bytes
(
o
->
v
.
Bytes
.
s
);
if
(
!
value
)
goto
failed
;
if
(
PyObject_SetAttrString
(
result
,
"s"
,
value
)
==
-
1
)
goto
failed
;
...
...
@@ -5509,13 +5519,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
return
1
;
}
if
(
isinstance
)
{
string
s
;
bytes
s
;
if
(
PyObject_HasAttrString
(
obj
,
"s"
))
{
int
res
;
tmp
=
PyObject_GetAttrString
(
obj
,
"s"
);
if
(
tmp
==
NULL
)
goto
failed
;
res
=
obj2ast_
string
(
tmp
,
&
s
,
arena
);
res
=
obj2ast_
bytes
(
tmp
,
&
s
,
arena
);
if
(
res
!=
0
)
goto
failed
;
Py_XDECREF
(
tmp
);
tmp
=
NULL
;
...
...
This diff is collapsed.
Click to expand it.
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