sync/gen_codec.ysl2
author Edouard Tisserant
Sat, 14 May 2016 12:01:50 +0200
changeset 622 ed6f7d40e6a7
parent 618 32fe7c8bee51
permissions -rw-r--r--
gen_codec : typeOfActionParam : parm node instead of parm node name text
Edouard@613
     1
// generate encoder and decoders for protocol messages
Edouard@613
     2
Edouard@613
     3
// Copyleft (c) 2016, p≡p foundation
Edouard@613
     4
Edouard@613
     5
include yslt.yml2
Edouard@613
     6
Edouard@613
     7
tstylesheet {
Edouard@613
     8
Edouard@613
     9
    key "ActionByNames", "/protocol/fsm/state/event//action", "@name";
Edouard@613
    10
    variable "UniqueActions", "/protocol/fsm/state/event//action[generate-id()=generate-id(key('ActionByNames',@name)[1])]";
Edouard@613
    11
    variable "UniqueSendActions", "$UniqueActions[starts-with(@name,'send')]";
Edouard@613
    12
Edouard@615
    13
    template "/protocol" {
Edouard@615
    14
        ||
Edouard@615
    15
        // encoders and decoders state for «@name» protocol
Edouard@613
    16
vb@618
    17
        #include "sync_fsm.h"
Edouard@613
    18
Edouard@615
    19
        // decoders
Edouard@613
    20
Edouard@615
    21
        ||
Edouard@615
    22
        apply "$UniqueSendActions",0 mode="proto" {
Edouard@615
    23
            with "pfx", "'read'";
Edouard@615
    24
            with "baseParms" > const char *buf, size_t size
Edouard@615
    25
        }
Edouard@615
    26
        ||
Edouard@613
    27
Edouard@615
    28
        // encoders 
Edouard@613
    29
Edouard@615
    30
        ||
Edouard@615
    31
        apply "$UniqueSendActions",0 mode="proto" {
Edouard@615
    32
            with "pfx", "'create'";
Edouard@615
    33
            with "baseParms" > const char **bufp, size_t *sizep
Edouard@615
    34
        }
vb@618
    35
        ||
vb@618
    36
vb@618
    37
        ||
Edouard@615
    38
    }
Edouard@613
    39
Edouard@613
    40
    def "xsl:typeOfActionParam" {
Edouard@613
    41
        param "n", "name(.)";
Edouard@622
    42
        result "ancestor::event/child::parm[child::*[position()=2 and name(.)=$n]]/child::*[position()=1]";
Edouard@613
    43
    }
Edouard@613
    44
    
Edouard@613
    45
    function "interfaces_params" {
Edouard@613
    46
        param "ifaceName";
Edouard@613
    47
        // variable "ifaceCommons", "/protocol/interface[@name = 'commons']/*";
Edouard@613
    48
        variable "ifaceParams", "$UniqueActions[@name = concat('send',$ifaceName)]/parm/*";
Edouard@613
    49
        variable "ifaceAdditions", "/protocol/interface[@name = $ifaceName]/*";
Edouard@613
    50
Edouard@613
    51
        // if "count($ifaceCommons) != 0" > , 
Edouard@613
    52
        // for "$ifaceCommons" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
Edouard@613
    53
Edouard@613
    54
        if "count($ifaceParams) != 0" > , 
Edouard@613
    55
        for "set:distinct($ifaceParams)" {
Edouard@622
    56
            > «name(xsl:typeOfActionParam())» «name(.)»
Edouard@613
    57
            if "position() != last()" > ,
Edouard@613
    58
        }
Edouard@613
    59
Edouard@613
    60
        if "count($ifaceAdditions) != 0" > , 
Edouard@613
    61
        for "$ifaceAdditions" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
Edouard@613
    62
    }
Edouard@613
    63
Edouard@613
    64
    template "action", mode="func_header" {
Edouard@613
    65
        param "pfx";
Edouard@615
    66
        param "baseParms";
Edouard@613
    67
        variable "ifaceName", "substring-after(@name, 'send')";
Edouard@613
    68
Edouard@615
    69
        > void «$pfx»«$ifaceName»(«$baseParms»
Edouard@613
    70
        call("interfaces_params") with "ifaceName", "$ifaceName";
Edouard@613
    71
        > )
Edouard@613
    72
    }
Edouard@613
    73
Edouard@613
    74
    template "action", mode="proto" {
Edouard@613
    75
        param "pfx";
Edouard@615
    76
        param "baseParms";
Edouard@615
    77
        apply ".",0 mode="func_header" {
Edouard@615
    78
            with "pfx", "$pfx" ;
Edouard@615
    79
            with "baseParms", "$baseParms" ;
Edouard@615
    80
        }
Edouard@613
    81
        | ;
Edouard@613
    82
    }
Edouard@613
    83
}
Edouard@613
    84