11# Generate Julia composite types for ROS messages
22
3- using Compat
4- import Compat: String, Symbol
53using PyCall
64
75export @rosimport , rostypegen, rostypereset
86
97# Type definitions
108# Composite types for internal use. Keeps track of the imported types and helps
119# keep code generation orderly.
12- @compat abstract type ROSModule end
13- type ROSPackage
10+ abstract type ROSModule end
11+ mutable struct ROSPackage
1412 name:: String
1513 msg:: ROSModule
1614 srv:: ROSModule
@@ -21,13 +19,13 @@ type ROSPackage
2119 pkg
2220 end
2321end
24- type ROSMsgModule <: ROSModule
22+ struct ROSMsgModule <: ROSModule
2523 pkg:: ROSPackage
2624 members:: Vector{String}
2725 deps:: Set{String}
2826 ROSMsgModule (pkg) = new (pkg, String[], Set {String} ())
2927end
30- type ROSSrvModule <: ROSModule
28+ struct ROSSrvModule <: ROSModule
3129 pkg:: ROSPackage
3230 members:: Vector{String}
3331 deps:: Set{String}
@@ -62,9 +60,9 @@ const _ros_builtin_types = Dict{String, Symbol}(
6260 )
6361
6462# Abstract supertypes of all generated types
65- @compat abstract type AbstractMsg end
66- @compat abstract type AbstractSrv end
67- @compat abstract type AbstractService end
63+ abstract type AbstractMsg end
64+ abstract type AbstractSrv end
65+ abstract type AbstractService end
6866
6967"""
7068 @rosimport
103101
104102_get_quote_value (input:: QuoteNode ) = input. value
105103_get_quote_value (input:: Expr ) = (@assert input. head == :quote ; input. args[1 ])
104+
106105# Return the pkg and types strings for a single expression of form:
107106# pkg.[msg|srv].type or pkg.[msg|srv]:type
108107function _pkgtype_import (input:: Expr )
@@ -316,8 +315,6 @@ function modulecode(mod::ROSModule)
316315 # Common imports
317316 push! (modcode,
318317 quote
319- using Compat
320- import Compat: String, Symbol
321318 using PyCall
322319 import Base: convert, getindex
323320 import RobotOS
@@ -417,7 +414,7 @@ function buildtype(mod::ROSSrvModule, typename::String)
417414 reqsym = Symbol (string (typename," Request" ))
418415 respsym = Symbol (string (typename," Response" ))
419416 srvexprs = Expr[
420- :(immutable $ defsym <: AbstractService end ),
417+ :(struct $ defsym <: AbstractService end ),
421418 :(_typerepr (:: Type{$defsym} ) = $ (_rostypestr (mod,typename))),
422419 :(_srv_reqtype (:: Type{$defsym} ) = $ reqsym),
423420 :(_srv_resptype (:: Type{$defsym} ) = $ respsym),
@@ -447,7 +444,7 @@ function typecode(rosname::String, super::Symbol, members::Vector)
447444 # First the empty expressions
448445 # (1) Type declaration
449446 push! (exprs, :(
450- type $ jlsym <: $super
447+ mutable struct $ jlsym <: $super
451448 # Generated code here
452449 end
453450 ))
@@ -473,7 +470,7 @@ function typecode(rosname::String, super::Symbol, members::Vector)
473470 push! (exprs, :(
474471 function convert (jlt:: Type{$jlsym} , o:: PyObject )
475472 if convert (String, o[" _type" ]) != _typerepr (jlt)
476- throw (InexactError ())
473+ throw (InexactError (:convert , $ jlsym, o ))
477474 end
478475 jl = $ jlsym ()
479476 # Generated code here
557554
558555# Build a String => Iterable{String} object from the individual package
559556# dependencies.
560- function _collectdeps {S<:AbstractString} (pkgs:: Dict{S, ROSPackage} )
557+ function _collectdeps (pkgs:: Dict{S, ROSPackage} ) where S <: AbstractString
561558 deps = Dict {S, Set{S}} ()
562559 for pname in keys (pkgs)
563560 if ! haskey (deps, pname)
@@ -654,18 +651,18 @@ _jl_safe_name(name::AbstractString, suffix) = _nameconflicts(name) ?
654651_nameconflicts (typename:: String ) = isdefined (Base, Symbol (typename))
655652
656653# Get a default value for any builtin ROS type
657- _typedefault {T<:Real} (:: Type{T} ) = zero (T)
654+ _typedefault (:: Type{T} ) where {T <: Real } = zero (T)
658655_typedefault (:: Type{String} ) = " "
659656_typedefault (:: Type{Time} ) = Time (0 ,0 )
660657_typedefault (:: Type{Duration} ) = Duration (0 ,0 )
661658
662659# Default method to get the "pkg/type" string from a generated DataType.
663660# Extended by the generated modules.
664- _typerepr {T} (:: Type{T} ) = error (" Not a ROS type" )
661+ _typerepr (:: Type{T} ) where {T} = error (" Not a ROS type" )
665662
666663# Default method to get the request/response datatypes for a generated service
667- _srv_reqtype {T} ( :: Type{T} ) = error (" Not a ROS Service type" )
668- _srv_resptype {T} (:: Type{T} ) = error (" Not a ROS Service type" )
664+ _srv_reqtype ( :: Type{T} ) where {T} = error (" Not a ROS Service type" )
665+ _srv_resptype (:: Type{T} ) where {T} = error (" Not a ROS Service type" )
669666
670667# Accessors for the package name
671668_name (p:: ROSPackage ) = p. name
0 commit comments