sync/gen_actions.ysl2
author Volker Birk <vb@pep.foundation>
Tue, 07 Aug 2018 17:16:03 +0200
branchsync
changeset 2829 e444c3c960bb
parent 2287 026ab4dae779
child 2830 d6f044e43e1a
permissions -rw-r--r--
cut things in
krista@2271
     1
// This file is under GNU General Public License 3.0
krista@2271
     2
// see LICENSE.txt
krista@2271
     3
vb@2829
     4
// generate conditions and actions
krista@2271
     5
vb@2829
     6
// Copyleft (c) 2017, p≡p foundation
krista@2271
     7
krista@2271
     8
// Written by Volker Birk
krista@2271
     9
krista@2271
    10
include yslt.yml2
krista@2271
    11
vb@2829
    12
decl _func *name (*type) alias - {
vb@2829
    13
    template %name=*name, %type=*type, "%type[@name='%name']"
vb@2829
    14
        call *type with "content" content;
vb@2829
    15
};
vb@2829
    16
vb@2829
    17
decl condition is _func (*type="condition");
vb@2829
    18
decl action is _func (*type="action");
vb@2829
    19
krista@2271
    20
tstylesheet {
krista@2271
    21
    include standardlib.ysl2
krista@2271
    22
    include ./functions.ysl2
krista@2271
    23
vb@2829
    24
    include ./cond_act.yml2
vb@2829
    25
krista@2271
    26
    template "/protocol" {
vb@2829
    27
        document "generated/{@name}_actions.c", "text" {
vb@2829
    28
            ||
vb@2829
    29
            // This file is under GNU General Public License 3.0
vb@2829
    30
            // see LICENSE.txt
krista@2271
    31
vb@2829
    32
            #include "«@name»_impl.h"
vb@2829
    33
            `` for "fsm" | #include "«@name»_fsm.h"
krista@2271
    34
krista@2271
    35
            ||
vb@2829
    36
            apply "func:distinctName(//condition)", 0;
vb@2829
    37
            apply "func:distinctName(//action[not(starts-with(@name, 'send'))])", 0;
krista@2271
    38
        }
krista@2271
    39
    }
krista@2271
    40
vb@2829
    41
    template "condition" | #error condition «@name» not implemented\n
vb@2829
    42
    template "action" | #error action «@name» not implemented\n
vb@2829
    43
vb@2829
    44
    function "condition" {
vb@2829
    45
        param "content";
vb@2829
    46
        ||
vb@2829
    47
        PEP_STATUS «@name»(PEP_SESSION session, bool *result)
vb@2829
    48
        {
vb@2829
    49
            assert(session && result);
vb@2829
    50
            if (!(session && result))
vb@2829
    51
                return PEP_ILLEGAL_VALUE;
krista@2271
    52
krista@2271
    53
        ||
vb@2829
    54
        copy "$content";
vb@2829
    55
        ||
krista@2271
    56
vb@2829
    57
            return PEP_STATUS_OK;
krista@2271
    58
        }
krista@2271
    59
krista@2271
    60
        ||
krista@2271
    61
    }
krista@2271
    62
vb@2829
    63
    function "action" {
vb@2829
    64
        param "content";
vb@2829
    65
        ||
vb@2829
    66
        PEP_STATUS «@name»(PEP_SESSION session)
vb@2829
    67
        {
vb@2829
    68
            assert(session);
vb@2829
    69
            if (!session)
vb@2829
    70
                return PEP_ILLEGAL_VALUE;
krista@2271
    71
krista@2271
    72
        ||
vb@2829
    73
        copy "$content";
krista@2271
    74
        ||
krista@2271
    75
krista@2271
    76
            return PEP_STATUS_OK;
krista@2271
    77
        }
krista@2271
    78
krista@2271
    79
        ||
krista@2271
    80
    }
krista@2271
    81
}
krista@2271
    82