Exemple #1
0
 def _st(visitor, node, s):
     """ s is a mapping between names and filepath of messages to generate.
     """
     if node._kind == 'topic': #special treatment to add private fields
         t = struct_of_topic(types.of(node))
     else:
         t = types.of(node)
     ext_rd = node['EXTERNAL_ROS_DEF']
     if ext_rd: #External def to be used
         name = ext_rd['FULLNAME']._val
         header = ext_rd['HEADER']._val
     else:
         reg_name = infos.ros_type_of_struct.get(t, None)
         if not reg_name: #Msg name and file to create
             msgname = qn.rosmsg(node)
             s[t] = msg_msg_file(package_folder, msgname)
             msgpkg = package_name
             infos.ros_type_of_struct[t] = (msgpkg, msgname)
         else: #Msg file already created
             (msgpkg, msgname) = reg_name
         header = msg_cpp_header(msgpkg, msgname)
         #keep only the actual string to identify the type and header file
         name = msg_cpp_qname(msgpkg, msgname)
     #Store our findings in the node for future retrieval
     node._ros_msgtype_name = name
     node._ros_msgtype_header = header
     return visitor.node_red(node, s) #recursive call
Exemple #2
0
 def _st(visitor, node, s):
     """ s is a mapping between names and filepath of messages to generate.
     """
     if node._kind == 'topic':  #special treatment to add private fields
         t = struct_of_topic(types.of(node))
     else:
         t = types.of(node)
     ext_rd = node['EXTERNAL_ROS_DEF']
     if ext_rd:  #External def to be used
         name = ext_rd['FULLNAME']._val
         header = ext_rd['HEADER']._val
     else:
         reg_name = infos.ros_type_of_struct.get(t, None)
         if not reg_name:  #Msg name and file to create
             name = ast._namespace.generate('radl__msg')
             #note: the .msg file is different from the header linked to it
             s[t] = filepath(qn_msgfile(name, suffix='.msg'))
             infos.ros_type_of_struct[t] = name
         else:  #Msg file already created
             name = reg_name
         header = qn_file(name, suffix='.h')
         #keep only the actual string to identify the type and header file
         name = qn_cpp(name)
     #Store our findings in the node for future retrieval
     node._ros_msgtype_name = name
     node._ros_msgtype_header = header
     return visitor.node_mapacc(node, s)  #recursive call
Exemple #3
0
def collect_leaf(visitor, leaf, acc):
    if isinstance(leaf, Alias) and _is_current_module(leaf):
        target = leaf._is_alias_of
        name_dag, decls, defs, d = collect_leaf(visitor, target, acc)
        #assign the value
        t = types.of(target)
        if isinstance(t, ArrayType):  #TODO: 5 strange things here..
            node_assgn = "\n    ".join(
                copy_to(qn.c_varname(leaf), target, False, init=True))
            d['assgns'] += '\n    ' + node_assgn if d['assgns'] else node_assgn
        else:
            d['assgns'] += '\n    ' + qn.c_varname(
                leaf) + ' = ' + qn.c_varname(target) + ';'
        #leaf will have a type already set (._type field of its node)
        #We will do like in col_types_node for nodes with already defined type
        t = types.of(leaf)
        decl_tname = typedeclof(t)
        tname = qn.c_typename(leaf)
        decls[tname] = "typedef {} {};\n".format(decl_tname, tname)
        name_dag[tname] = [decl_tname]
        vd = "{} {};\n\n".format(tname, qn.c_varname(leaf))
        d['vdecls'] += vd
        defs[tname] = "extern " + vd
        return name_dag, decls, defs, d

    elif isinstance(leaf, Ident) and _is_current_module(leaf._node):
        #We only have to generate things for the current module.
        #We are assuming types to not be circular, so easy:
        return collect_node(visitor, leaf._node, acc)
        #RMQ: since we are doing that (depth first), we don't need the name_dag and tarjan.
    else:
        #We have nothing to do, other leafs are basic types
        return acc
Exemple #4
0
 def _st(visitor, node, s):
     """ s is a mapping between names and filepath of messages to generate.
     """
     if node._kind == 'topic': #special treatment to add private fields
         t = struct_of_topic(types.of(node))
     else:
         t = types.of(node)
     ext_rd = node['EXTERNAL_ROS_DEF']
     if ext_rd: #External def to be used
         name = ext_rd['FULLNAME']._val
         header = ext_rd['HEADER']._val
     else:
         reg_name = infos.ros_type_of_struct.get(t, None)
         if not reg_name: #Msg name and file to create
             name = ast._namespace.generate('radl__msg')
             #note: the .msg file is different from the header linked to it
             s[t] = filepath(qn_msgfile(name, suffix='.msg'))
             infos.ros_type_of_struct[t] = name
         else: #Msg file already created
             name = reg_name
         header = qn_file(name, suffix='.h')
         #keep only the actual string to identify the type and header file
         name = qn_cpp(name)
     #Store our findings in the node for future retrieval
     node._ros_msgtype_name = name
     node._ros_msgtype_header = header
     return visitor.node_mapacc(node, s) #recursive call
Exemple #5
0
 def default(visitor, n, _):
     t = types.of(n)
     if isinstance(t, str):  # Basic value
         return language.interpret_value(t, n._val), _
     else:
         return (str(n._qname), visitor.visit(filter_pred(n._children),
                                              _)[0]), _
Exemple #6
0
def collect_node(visitor, node, acc):
    """ We are doing solution 2: forget about class fields,
    the output struct fields are the object variable names.
    This is done depth first to enable sharing of types (CSE of types).
    """
    t = types.of(node)
    name_dag, decls, defs, d = visitor.node_red(node, acc)
    #generate types and declarations
    decl_tname = typedeclof(t)
    tname = qn.c_typename(node)
    if decl_tname is None:  #We need to define a type
        tdecl, tdef, decl_deps, def_deps = decl_and_def_type(t, tname)
        decls[tname] = tdecl
        vd = "{} {};\n\n".format(tname, qn.c_varname(node))
        d['vdecls'] += vd
        defs[tname] = tdef + "extern " + vd
        name_dag[tname] = chain(def_deps, decl_deps)

    elif name_dag.get(tname, None) is None and _is_current_module(node):
        #The type is already defined, only declare it.
        decls[tname] = "typedef {} {};\n".format(decl_tname, tname)
        name_dag[tname] = [decl_tname]
        vd = "{} {};\n\n".format(tname, qn.c_varname(node))
        d['vdecls'] += vd
        defs[tname] = "extern " + vd
    else:
        #The type is defined and declared -> nothing to be done
        return name_dag, decls, defs, d
    #assign the value
    node_assgn = "\n    ".join(copy_to(qn.c_varname(node), node, init=True))
    d['assgns'] += '\n    ' + node_assgn if d['assgns'] else node_assgn
    return name_dag, decls, defs, d
Exemple #7
0
def copy_to(var, node, shallow=True, init=False):
    """ Used to copy the value of node in var.
    Require a node with actual access to its values (._val).
    The var is expected to be allocated and of the correct type.
    @param deep: if True the copy will be deep (recursively). If shallow (False)
    it requires cvarname(node) to already be defined so it can be referenced.
    @param init: if True, it assumes that the value of cvarname(node) isn't
    initialized. The init flag is turned off for any internal copy, thus if
    shallow, any internal variable used by node is assumed to be initialized.
    """
    t = types.of(node)
    if shallow and not init:
        yield var + ' = &' + qn.c_varname(node) + ';'
    else:  #Deep copy of this level
        if isinstance(t, str):  #Basic types, always do deep copy.
            v = language.value_mapping[t]['C'](node._val)
            yield var + ' = ' + v + ';'
        elif isinstance(t, StructType):
            for (f_name, _) in t.elems_t:
                v = getattr(node, f_name)
                yield from copy_to(var + '.' + f_name, v, shallow
                                   and t.shallow, False)
        elif isinstance(t, ArrayType):
            vs = node['VALUES']
            for i, v in enumerate(vs):
                yield from copy_to(var + '[' + str(i) + ']', v, False, False)
        elif isinstance(t, EmptyType):
            yield var + ' = 0;'
        else:
            internal_error("Type unsupported.")
Exemple #8
0
 def __init__(self, sub, pub, maxlatency, each, topic, plantinfo):
     """
     incoming may be True or False for outgoing channels.
     Channels expect to be created from the sub side.
     """
     self.id = channel.gen_id()
     self.sub = sub
     self.pub = pub
     self.maxlatency = maxlatency
     self.each = each
     self.topic = topic
     self.incoming = True
     self.kind = chan_kind(pub, sub, topic, self.incoming, plantinfo)
     # The data type and value of the topic are coming from the ast dump
     self.data_typename = qn.c_typename(topic)
     self.data_init_valname = qn.c_ast_val(topic)
     #The actual message encapsulate the data and adds radl fields:
     fields = [('radl__flags', 'uint8'), ('radl__data', types.of(topic))]
     if infos.instrument_msg_timings:
         fields += instrumentation.msg_timings.msg_field_decl()
     self.msg_type = StructType(False, fields)
Exemple #9
0
def _tc_arrays(visitor, array, _):
    """Type Check arrays, simply call types.of() """
    types.of(array)
    return (), _
Exemple #10
0
def _tc_arrays(visitor, array, _):
    """Type Check arrays, simply call types.of() """
    types.of(array)
    return _