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