@@ -61,7 +61,7 @@ function changetype(ex::Expr)
61
61
elseif isa (ex, Integer)
62
62
return Int === Int64 ? SafeInt64 (ex) : SafeInt32 (ex)
63
63
elseif (Meta. isexpr (ex, :call , 2 ) && isa (ex. args[2 ], Integer))
64
- return changetype_of_cast_int (ex)
64
+ return changetype_of_cast_int (ex)
65
65
elseif (Meta. isexpr (ex, :(= ), 2 ) && isa (ex. args[2 ], Integer) && isa (ex. args[1 ], Symbol))
66
66
ex. args[2 ] = Int === Int64 ? SafeInt64 (ex. args[2 ]) : SafeInt32 (ex. args[2 ])
67
67
return ex
@@ -76,10 +76,25 @@ function changetype(ex::Expr)
76
76
end
77
77
end
78
78
79
+ if VERSION < v " 1.5"
80
+ # calls to include(f) are changed to include_mapexpr_compat(modul, f) so that
81
+ # @changetype can apply recursively to included files.
82
+ function include_mapexpr_compat (modul, filename:: AbstractString )
83
+ # use the undocumented parse_input_line function so that we preserve
84
+ # the filename and line-number information.
85
+ s = string (" begin; " , read (filename, String), " \n end\n " )
86
+ expr = Base. parse_input_line (s, filename= filename)
87
+ Core. eval (modul, changetype (expr))
88
+ end
89
+ end
79
90
80
91
function changetypes (ex:: Expr )
81
92
if Meta. isexpr (ex, :call , 2 ) && ex. args[1 ] == :include
82
- return :($ include (@__MODULE__ , $ (ex. args[2 ])))
93
+ if VERSION < v " 1.5"
94
+ return Expr (:call , include_mapexpr_compat, :(@__MODULE__ ), ex. args[2 : end ]. .. )
95
+ else
96
+ return Expr (ex. head, ex. args[1 ], changetype, ex. args[2 : end ]. .. )
97
+ end
83
98
elseif Meta. isexpr (ex, :call ) && ex. args[1 ] in changefuncs
84
99
return Expr (:call , Core. eval (SaferIntTypes, ex. args[1 ]), changetype .(ex. args[2 : end ])... )
85
100
elseif Meta. isexpr (ex, :., 2 ) && ex. args[1 ] in changefuncs && Meta. isexpr (ex. args[2 ], :tuple )
@@ -90,7 +105,7 @@ function changetypes(ex::Expr)
90
105
end
91
106
end
92
107
93
- function changetype_of_cast_int (ex:: Expr )
108
+ function changetype_of_cast_int (ex:: Expr )
94
109
if @capture (ex, Int64 (_))
95
110
ex. args[1 ] = :SafeInt64
96
111
elseif @capture (ex, Int32 (_))
@@ -115,7 +130,7 @@ function changetype_of_cast_int(ex::Expr)
115
130
return ex
116
131
end
117
132
118
- function changetype_of_assigned_cast_int (ex:: Expr )
133
+ function changetype_of_assigned_cast_int (ex:: Expr )
119
134
if @capture (ex, _= Int64 (_))
120
135
ex. args[2 ]. args[1 ] = :SafeInt64
121
136
elseif @capture (ex, _= Int32 (_))
@@ -140,16 +155,6 @@ function changetype_of_assigned_cast_int(ex::Expr)
140
155
return ex
141
156
end
142
157
143
- # calls to include(f) are changed to include(T, modul, f) so that
144
- # @changetype can apply recursively to included files.
145
- function include (modul, filename:: AbstractString )
146
- # use the undocumented parse_input_line function so that we preserve
147
- # the filename and line-number information.
148
- s = string (" begin; " , read (filename, String), " \n end\n " )
149
- expr = Base. parse_input_line (s, filename= filename)
150
- Core. eval (modul, changetype (expr))
151
- end
152
-
153
158
for F in binaryfuncs
154
159
# @eval $F(T, args...) = Base.$F(changetype.(T, args...)...,)
155
160
@eval Base.$ F (:: Type{S} , :: Type{I} , n) where {S<: SFInt , I<: HWInt } = $ F (S, n)
0 commit comments