Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
b2ee75d3
Commit
b2ee75d3
authored
Jul 25, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Warn more thoroughly about long->int and unicode->str literal conversion
parent
b56ac190
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
8 deletions
+38
-8
src/analysis/type_analysis.cpp
src/analysis/type_analysis.cpp
+2
-0
src/codegen/parse_ast.py
src/codegen/parse_ast.py
+9
-4
src/codegen/parser.cpp
src/codegen/parser.cpp
+19
-2
src/core/ast.h
src/core/ast.h
+8
-2
No files found.
src/analysis/type_analysis.cpp
View file @
b2ee75d3
...
...
@@ -407,6 +407,8 @@ private:
return
INT
;
case
AST_Num
:
:
FLOAT
:
return
FLOAT
;
case
AST_Num
:
:
LONG
:
RELEASE_ASSERT
(
0
,
""
);
}
abort
();
}
...
...
src/codegen/parse_ast.py
View file @
b2ee75d3
...
...
@@ -115,12 +115,20 @@ def convert(n, f):
f
.
write
(
'
\
x10
'
)
elif
isinstance
(
n
.
n
,
long
):
assert
(
-
1L
<<
60
)
<
n
.
n
<
(
1L
<<
60
)
f
.
write
(
'
\
x
1
0
'
)
f
.
write
(
'
\
x
3
0
'
)
elif
isinstance
(
n
.
n
,
float
):
f
.
write
(
'
\
x20
'
)
else
:
raise
Exception
(
type
(
n
.
n
))
if
isinstance
(
n
,
_ast
.
Str
):
if
isinstance
(
n
.
s
,
str
):
f
.
write
(
'
\
x10
'
)
elif
isinstance
(
n
.
s
,
unicode
):
f
.
write
(
'
\
x20
'
)
else
:
raise
Exception
(
type
(
n
.
s
))
# print >>sys.stderr, n, sorted(n.__dict__.items())
for
k
,
v
in
sorted
(
n
.
__dict__
.
items
()):
if
k
.
startswith
(
'_'
):
...
...
@@ -144,8 +152,6 @@ def convert(n, f):
elif
isinstance
(
v
,
str
):
_print_str
(
v
,
f
)
elif
isinstance
(
v
,
unicode
):
print
>>
sys
.
stderr
,
"Warning, converting unicode string to str!"
sys
.
stderr
.
flush
()
_print_str
(
v
.
encode
(
"ascii"
),
f
)
elif
isinstance
(
v
,
bool
):
f
.
write
(
struct
.
pack
(
"B"
,
v
))
...
...
@@ -153,7 +159,6 @@ def convert(n, f):
f
.
write
(
struct
.
pack
(
">q"
,
v
))
elif
isinstance
(
v
,
long
):
assert
(
-
1L
<<
60
)
<
v
<
(
1L
<<
60
)
print
>>
sys
.
stderr
,
"Warning, converting long to int!"
f
.
write
(
struct
.
pack
(
">q"
,
v
))
elif
isinstance
(
v
,
float
):
f
.
write
(
struct
.
pack
(
">d"
,
v
))
...
...
src/codegen/parser.cpp
View file @
b2ee75d3
...
...
@@ -518,6 +518,11 @@ AST_Num* read_num(BufferedReader* reader) {
if
(
rtn
->
num_type
==
AST_Num
::
INT
)
{
rtn
->
n_int
=
reader
->
readULL
();
// automatic conversion to signed
}
else
if
(
rtn
->
num_type
==
AST_Num
::
LONG
)
{
// Don't really support longs for now...
printf
(
"Warning: converting long literal to int
\n
"
);
rtn
->
num_type
=
AST_Num
::
INT
;
rtn
->
n_int
=
reader
->
readULL
();
// automatic conversion to signed
}
else
if
(
rtn
->
num_type
==
AST_Num
::
FLOAT
)
{
rtn
->
n_float
=
reader
->
readDouble
();
}
else
{
...
...
@@ -591,9 +596,21 @@ AST_Slice* read_slice(BufferedReader* reader) {
AST_Str
*
read_str
(
BufferedReader
*
reader
)
{
AST_Str
*
rtn
=
new
AST_Str
();
rtn
->
str_type
=
(
AST_Str
::
StrType
)
reader
->
readByte
();
rtn
->
col_offset
=
readColOffset
(
reader
);
rtn
->
lineno
=
reader
->
readULL
();
rtn
->
s
=
readString
(
reader
);
if
(
rtn
->
str_type
==
AST_Str
::
STR
)
{
rtn
->
s
=
readString
(
reader
);
}
else
if
(
rtn
->
str_type
==
AST_Str
::
UNICODE
)
{
// Don't really support unicode for now...
printf
(
"Warning: converting unicode literal to str
\n
"
);
rtn
->
str_type
=
AST_Str
::
STR
;
rtn
->
s
=
readString
(
reader
);
}
else
{
RELEASE_ASSERT
(
0
,
"%d"
,
rtn
->
str_type
);
}
return
rtn
;
}
...
...
@@ -879,7 +896,7 @@ AST_Module* parse(const char* fn) {
return
ast_cast
<
AST_Module
>
(
rtn
);
}
#define MAGIC_STRING "a\nc
h
"
#define MAGIC_STRING "a\nc
i
"
#define MAGIC_STRING_LENGTH 4
#define CHECKSUM_LENGTH 4
...
...
src/core/ast.h
View file @
b2ee75d3
...
...
@@ -602,6 +602,7 @@ public:
// These values must correspond to the values in parse_ast.py
INT
=
0x10
,
FLOAT
=
0x20
,
LONG
=
0x30
,
}
num_type
;
union
{
...
...
@@ -695,14 +696,19 @@ public:
class
AST_Str
:
public
AST_expr
{
public:
enum
StrType
{
STR
=
0x10
,
UNICODE
=
0x20
,
}
str_type
;
std
::
string
s
;
virtual
void
accept
(
ASTVisitor
*
v
);
virtual
void
*
accept_expr
(
ExprVisitor
*
v
);
AST_Str
()
:
AST_expr
(
AST_TYPE
::
Str
)
{}
AST_Str
(
const
std
::
string
&
s
)
:
AST_expr
(
AST_TYPE
::
Str
),
s
(
s
)
{}
AST_Str
(
const
std
::
string
&&
s
)
:
AST_expr
(
AST_TYPE
::
Str
),
s
(
std
::
move
(
s
))
{}
AST_Str
(
const
std
::
string
&
s
)
:
AST_expr
(
AST_TYPE
::
Str
),
s
tr_type
(
STR
),
s
(
s
)
{}
AST_Str
(
const
std
::
string
&&
s
)
:
AST_expr
(
AST_TYPE
::
Str
),
s
tr_type
(
STR
),
s
(
std
::
move
(
s
))
{}
static
const
AST_TYPE
::
AST_TYPE
TYPE
=
AST_TYPE
::
Str
;
};
...
...
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