Skip to content

Commit 8fa85da

Browse files
committed
0.5 deprecations: ASCIIString -> String and symbol -> Symbol
1 parent 9761277 commit 8fa85da

File tree

2 files changed

+49
-50
lines changed

2 files changed

+49
-50
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
julia 0.4
22
PyCall
3-
Compat
3+
Compat 0.8.0

src/gentypes.jl

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#Generate Julia composite types for ROS messages
22

3+
using Compat
4+
import Compat: String, Symbol
5+
36
export @rosimport, rostypegen, rostypereset, gentypes, cleartypes
47

58
#Type definitions
69
#Composite types for internal use. Keeps track of the imported types and helps
710
#keep code generation orderly.
811
abstract ROSModule
912
type ROSPackage
10-
name::ASCIIString
13+
name::String
1114
msg::ROSModule
1215
srv::ROSModule
13-
function ROSPackage(pkgname::ASCIIString)
16+
function ROSPackage(pkgname::String)
1417
pkg = new(pkgname)
1518
pkg.msg = ROSMsgModule(pkg)
1619
pkg.srv = ROSSrvModule(pkg)
@@ -19,25 +22,25 @@ type ROSPackage
1922
end
2023
type ROSMsgModule <: ROSModule
2124
pkg::ROSPackage
22-
members::Vector{ASCIIString}
23-
deps::Set{ASCIIString}
24-
ROSMsgModule(pkg) = new(pkg, ASCIIString[], Set{ASCIIString}())
25+
members::Vector{String}
26+
deps::Set{String}
27+
ROSMsgModule(pkg) = new(pkg, String[], Set{String}())
2528
end
2629
type ROSSrvModule <: ROSModule
2730
pkg::ROSPackage
28-
members::Vector{ASCIIString}
29-
deps::Set{ASCIIString}
30-
ROSSrvModule(pkg) = new(pkg, ASCIIString[], Set{ASCIIString}())
31+
members::Vector{String}
32+
deps::Set{String}
33+
ROSSrvModule(pkg) = new(pkg, String[], Set{String}())
3134
end
3235

3336
#These two global objects maintain the hierarchy from multiple calls to
3437
#`@rosimport` and keep the link to the Python objects whenever communication
3538
#goes between RobotOS and rospy.
36-
const _rospy_imports = Dict{ASCIIString,ROSPackage}()
37-
const _rospy_objects = Dict{ASCIIString,PyObject}()
38-
const _rospy_modules = Dict{ASCIIString,PyObject}()
39+
const _rospy_imports = Dict{String,ROSPackage}()
40+
const _rospy_objects = Dict{String,PyObject}()
41+
const _rospy_modules = Dict{String,PyObject}()
3942

40-
const _ros_builtin_types = Dict{ASCIIString, Symbol}(
43+
const _ros_builtin_types = Dict{String, Symbol}(
4144
"bool" => :Bool,
4245
"int8" => :Int8,
4346
"int16" => :Int16,
@@ -49,7 +52,7 @@ const _ros_builtin_types = Dict{ASCIIString, Symbol}(
4952
"uint64" => :UInt64,
5053
"float32" => :Float32,
5154
"float64" => :Float64,
52-
"string" => :ASCIIString,
55+
"string" => :String,
5356
"time" => :Time,
5457
"duration"=> :Duration,
5558
#Deprecated but supported
@@ -71,7 +74,7 @@ macro rosimport(input)
7174
if input.head == :tuple
7275
@assert isa(input.args[1], Expr) "Improper @rosimport input"
7376
@assert input.args[1].head == :(:) "First argument needs ':' following"
74-
types = ASCIIString[]
77+
types = String[]
7578
pkg, ismsg, typ = _pkgtype_import(input.args[1])
7679
push!(types, typ)
7780
for t in input.args[2:end]
@@ -109,7 +112,7 @@ function _pkgtype_import(input::Expr)
109112
return ps,msb,ts
110113
end
111114
#Import a set of types from a single package
112-
function _rosimport(package::ASCIIString, ismsg::Bool, names::ASCIIString...)
115+
function _rosimport(package::String, ismsg::Bool, names::String...)
113116
global _rospy_imports
114117
if ! haskey(_rospy_imports, package)
115118
@debug("Importing new package: ",package,".", ismsg ? "msg" : "srv")
@@ -145,7 +148,7 @@ end
145148

146149
#Populate the module with a new message type. Import and add dependencies first
147150
#so they will appear first in the generated code.
148-
function addtype!(mod::ROSMsgModule, typ::ASCIIString)
151+
function addtype!(mod::ROSMsgModule, typ::String)
149152
global _rospy_objects
150153
if !(typ in mod.members)
151154
@debug("Message type import: ", _fullname(mod), ".", typ)
@@ -165,7 +168,7 @@ end
165168

166169
#Populate the module with a new service type. Import and add dependencies
167170
#first.
168-
function addtype!(mod::ROSSrvModule, typ::ASCIIString)
171+
function addtype!(mod::ROSSrvModule, typ::String)
169172
global _rospy_objects
170173
if !(typ in mod.members)
171174
@debug("Service type import: ", _fullname(mod), ".", typ)
@@ -191,7 +194,7 @@ function addtype!(mod::ROSSrvModule, typ::ASCIIString)
191194
end
192195

193196
#Return the python module and python object for a particular type
194-
function _pyvars(modname::ASCIIString, typ::ASCIIString)
197+
function _pyvars(modname::String, typ::String)
195198
pymod = _import_rospy_pkg(modname)
196199
pyobj =
197200
try pymod[typ]
@@ -233,7 +236,7 @@ function _importdeps!(mod::ROSModule, deps::Vector)
233236
end
234237

235238
#Bring in the python modules as needed
236-
function _import_rospy_pkg(package::ASCIIString)
239+
function _import_rospy_pkg(package::String)
237240
global _rospy_modules
238241
if ! haskey(_rospy_modules, package)
239242
@debug("Importing python package: ", package)
@@ -252,7 +255,7 @@ function buildpackage(pkg::ROSPackage)
252255
@debug("Building package: ", _name(pkg))
253256

254257
#Create the top-level module for the package in Main
255-
pkgsym = symbol(_name(pkg))
258+
pkgsym = Symbol(_name(pkg))
256259
pkgcode = Expr(:toplevel, :(module ($pkgsym) end))
257260
Main.eval(pkgcode)
258261
pkgmod = Main.eval(pkgsym)
@@ -284,14 +287,10 @@ function modulecode(mod::ROSModule)
284287
modcode = Expr[]
285288

286289
#Common imports
287-
if VERSION < v"0.4-"
288-
push!(modcode,
289-
quote
290-
using Compat
291-
end)
292-
end
293290
push!(modcode,
294291
quote
292+
using Compat
293+
import Compat: String, Symbol
295294
using PyCall
296295
import Base: convert, getindex
297296
import RobotOS
@@ -320,7 +319,7 @@ end
320319
function _importexprs(mod::ROSMsgModule)
321320
imports = Expr[Expr(:import, :RobotOS, :MsgT)]
322321
othermods = filter(d -> d != _name(mod), mod.deps)
323-
append!(imports, [Expr(:using,symbol(m),:msg) for m in othermods])
322+
append!(imports, [Expr(:using,Symbol(m),:msg) for m in othermods])
324323
imports
325324
end
326325
function _importexprs(mod::ROSSrvModule)
@@ -330,32 +329,32 @@ function _importexprs(mod::ROSSrvModule)
330329
Expr(:import, :RobotOS, :_srv_reqtype),
331330
Expr(:import, :RobotOS, :_srv_resptype),
332331
]
333-
append!(imports, [Expr(:using,symbol(m),:msg) for m in mod.deps])
332+
append!(imports, [Expr(:using,Symbol(m),:msg) for m in mod.deps])
334333
imports
335334
end
336335

337336
#The exported names for each module
338337
function _exportexpr(mod::ROSMsgModule)
339338
exportexpr = Expr(:export)
340339
for m in mod.members
341-
push!(exportexpr.args, symbol(_jl_safe_name(m,"Msg")))
340+
push!(exportexpr.args, Symbol(_jl_safe_name(m,"Msg")))
342341
end
343342
exportexpr
344343
end
345344
function _exportexpr(mod::ROSSrvModule)
346345
exportexpr = Expr(:export)
347346
for typ in mod.members
348347
push!(exportexpr.args,
349-
symbol(typ),
350-
symbol(string(typ,"Request")),
351-
symbol(string(typ,"Response"))
348+
Symbol(typ),
349+
Symbol(string(typ,"Request")),
350+
Symbol(string(typ,"Response"))
352351
)
353352
end
354353
exportexpr
355354
end
356355

357356
#All the generated code for a generated message type
358-
function buildtype(mod::ROSMsgModule, typename::ASCIIString)
357+
function buildtype(mod::ROSMsgModule, typename::String)
359358
global _rospy_objects
360359
fulltypestr = _rostypestr(mod, typename)
361360
pyobj = _rospy_objects[fulltypestr]
@@ -368,7 +367,7 @@ end
368367

369368
#All the generated code for a generated service type
370369
#Will create 3 different composite types.
371-
function buildtype(mod::ROSSrvModule, typename::ASCIIString)
370+
function buildtype(mod::ROSSrvModule, typename::String)
372371
global _rospy_objects
373372

374373
req_typestr = _rostypestr(mod, string(typename,"Request"))
@@ -387,9 +386,9 @@ function buildtype(mod::ROSSrvModule, typename::ASCIIString)
387386
pyresp = :(RobotOS._rospy_objects[$resp_typestr])
388387
respexprs = typecode(resp_typestr, :SrvT, respmems)
389388

390-
defsym = symbol(typename)
391-
reqsym = symbol(string(typename,"Request"))
392-
respsym = symbol(string(typename,"Response"))
389+
defsym = Symbol(typename)
390+
reqsym = Symbol(string(typename,"Request"))
391+
respsym = Symbol(string(typename,"Response"))
393392
srvexprs = Expr[
394393
:(immutable $defsym <: ServiceDefinition end),
395394
:(_typerepr(::Type{$defsym}) = $(_rostypestr(mod,typename))),
@@ -406,7 +405,7 @@ end
406405
# (3) convert(PyObject, ...)
407406
# (4) convert(..., o::PyObject)
408407
# (5) getindex for accessing member constants
409-
function typecode(rosname::ASCIIString, super::Symbol, members::Vector)
408+
function typecode(rosname::String, super::Symbol, members::Vector)
410409
tname = _splittypestr(rosname)[2]
411410
@debug("Type: ", tname)
412411

@@ -415,7 +414,7 @@ function typecode(rosname::ASCIIString, super::Symbol, members::Vector)
415414
suffix = if super == :MsgT; "Msg"
416415
elseif super == :SrvT; "Srv"
417416
else; "ROS" end
418-
jlsym = symbol(_jl_safe_name(tname,suffix))
417+
jlsym = Symbol(_jl_safe_name(tname,suffix))
419418

420419
exprs = Expr[]
421420
#First the empty expressions
@@ -446,7 +445,7 @@ function typecode(rosname::ASCIIString, super::Symbol, members::Vector)
446445
#(4) Convert from PyObject
447446
push!(exprs, :(
448447
function convert(jlt::Type{$jlsym}, o::PyObject)
449-
if convert(ASCIIString, o["_type"]) != _typerepr(jlt)
448+
if convert(String, o["_type"]) != _typerepr(jlt)
450449
throw(InexactError())
451450
end
452451
jl = $jlsym()
@@ -487,7 +486,7 @@ function _addtypemember!(exprs, namestr, typestr)
487486

488487
typestr, arraylen = _check_array_type(typestr)
489488
if _isrostype(typestr)
490-
j_typ = symbol(_splittypestr(typestr)[2])
489+
j_typ = Symbol(_splittypestr(typestr)[2])
491490
#Default has to be deferred until the types exist
492491
j_def = Expr(:call, j_typ)
493492
else
@@ -499,7 +498,7 @@ function _addtypemember!(exprs, namestr, typestr)
499498
j_def = @eval _typedefault($j_typ)
500499
end
501500

502-
namesym = symbol(namestr)
501+
namesym = Symbol(namestr)
503502
if arraylen >= 0
504503
memexpr = :($namesym::Array{$j_typ,1})
505504
defexpr = :([$j_def for i = 1:$arraylen])
@@ -559,15 +558,15 @@ function _order(d::Dict)
559558
end
560559
end
561560
end
562-
tlist = ASCIIString[]
561+
tlist = String[]
563562
for t in keys(d)
564563
trecurse!(tlist, d, t)
565564
end
566565
tlist
567566
end
568567

569-
_rostypestr(mod::ROSModule, name::ASCIIString) = string(_name(mod),"/",name)
570-
function _splittypestr(typestr::ASCIIString)
568+
_rostypestr(mod::ROSModule, name::String) = string(_name(mod),"/",name)
569+
function _splittypestr(typestr::String)
571570
if ! _isrostype(typestr)
572571
error(string("Invalid message type '$typestr', ",
573572
"use 'package_name/type_name'"))
@@ -577,12 +576,12 @@ function _splittypestr(typestr::ASCIIString)
577576
end
578577
#Valid ROS type string is all word chars split by a single forward slash, with
579578
#optional square brackets for array types
580-
_isrostype(s::ASCIIString) = ismatch(r"^\w+/\w+(?:\[\d*\])?$", s)
579+
_isrostype(s::String) = ismatch(r"^\w+/\w+(?:\[\d*\])?$", s)
581580

582581
#Sanitize a string by checking for and removing brackets if they are present
583582
#Return the sanitized type and the number inside the brackets if it is a fixed
584583
#size type. Returns 0 if variable size (no number), -1 if no brackets
585-
function _check_array_type(typ::ASCIIString)
584+
function _check_array_type(typ::String)
586585
arraylen = -1
587586
m = match(r"^([\w/]+)\[(\d*)\]$", typ)
588587
if m != nothing
@@ -620,11 +619,11 @@ _jl_safe_name(name::AbstractString, suffix) = _nameconflicts(name) ?
620619

621620
#Check if the type name conflicts with a Julia builtin. Currently this is only
622621
#some of the messages from the std_msgs.msg package
623-
_nameconflicts(typename::ASCIIString) = isdefined(Base, symbol(typename))
622+
_nameconflicts(typename::String) = isdefined(Base, Symbol(typename))
624623

625624
#Get a default value for any builtin ROS type
626625
_typedefault{T<:Real}(::Type{T}) = zero(T)
627-
_typedefault(::Type{ASCIIString}) = ""
626+
_typedefault(::Type{String}) = ""
628627
_typedefault(::Type{Time}) = Time(0,0)
629628
_typedefault(::Type{Duration}) = Duration(0,0)
630629

0 commit comments

Comments
 (0)