semantic_checks.c 8.43 KB
Newer Older
Maxime Perrotin's avatar
Maxime Perrotin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* Buildsupport is (c) 2008-2015 European Space Agency
 * contact: maxime.perrotin@esa.int
 * License is LGPL, check LICENSE file */
/* semantic_checks.c

  this backend verifies some semantic properties on the interface and deployment views
 
*/
#define ID "$Id: semantic_checks.c 400 2009-11-24 13:28:24Z maxime1008 $"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>

#include "my_types.h"
#include "practical_functions.h"

/* Various semantic checks on an interface */
void Interface_Semantic_Check(Interface * i)
{
    int count_param = 0;

    /* Check that Cyclic PIs are not connected. */
    if (PI == i->direction && cyclic == i->rcm && NULL != i->distant_fv) {

        ERROR
28
            ("[ERROR] In Function \"%s\", interface \"%s\" is cyclic and should not be connected. \n",
Maxime Perrotin's avatar
Maxime Perrotin committed
29
30
31
32
33
34
35
36
37
38
             i->parent_fv->name, i->name);
        add_error();

    }

    /* Check if Cyclic PIs have parameters, which is forbidden */
    if (PI == i->direction && cyclic == i->rcm
        && (NULL != i->in || NULL != i->out)) {

        ERROR
39
            ("[ERROR] In Function \"%s\", interface \"%s\" is cyclic and should not have parameters. \n",
Maxime Perrotin's avatar
Maxime Perrotin committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
             i->parent_fv->name, i->name);
        add_error();

    }

    if (PI == i->direction && (sporadic == i->rcm || variator == i->rcm)) {


        /* Check that SPO interfaces only have ONE input parameter */
        FOREACH(p, Parameter, i->in, {
                (void) p;
                count_param++;
                });

        if (count_param > 1) {
            ERROR
56
                ("[ERROR] In Function \"%s\", sporadic interface \"%s\" cannot have more than 1 IN param.\n",
Maxime Perrotin's avatar
Maxime Perrotin committed
57
58
59
60
61
62
63
                 i->parent_fv->name, i->name);
            add_error();
        }

        /* Check that SPO interfaces don't have any OUT parameters */
        if (NULL != i->out) {
            ERROR
64
                ("[ERROR]  In Function \"%s\", sporadic interface \"%s\" cannot have OUT parameters.\n",
Maxime Perrotin's avatar
Maxime Perrotin committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
                 i->parent_fv->name, i->name);
            add_error();
        }

    }

}


/* External interface (the one and unique) */
void Function_Semantic_Check(FV * fv)
{
    if (fv->system_ast->context->glue && NULL == fv->process) {
        ERROR
79
            ("[ERROR] Function \"%s\" is not bound to any partition.\n",
Maxime Perrotin's avatar
Maxime Perrotin committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
             fv->name);
        add_error();
    }

    if (fv->system_ast->context->onlycv) {
        return;
    }

    /*
     * A function must have at least ONE PI - otherwise it is dead code
     * (with the exception of blackbox devices which may be connected to
     * an interrupt in the future, and GUIs that may have only TCs)
     */
    if (blackbox_device != fv->language && gui != fv->language) {
        int count_pi = 0;
        FOREACH(i, Interface, fv->interfaces, {
                if (PI == i->direction) count_pi++;}
        );
        if (0 == count_pi) {
            ERROR
100
                ("[ERROR] Function \"%s\" shall contain at least one provided interface.\n",
Maxime Perrotin's avatar
Maxime Perrotin committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
                 fv->name);
            add_error();
        }
    }

    /* 
     * SCADE/Simulink specific checks: exactly ONE PI and *NO* RI 
     */
    if (scade == fv->language || simulink == fv->language) {
        int count_pi = 0, count_ri = 0;

        FOREACH(i, Interface, fv->interfaces, {
                if (RI == i->direction) {
                count_ri++;}
                else {
                count_pi++;}
                }
        );

        if (1 != count_pi) {
            ERROR
122
                ("[ERROR] %s function \"%s\" must contain ONE provided interface\n",
Maxime Perrotin's avatar
Maxime Perrotin committed
123
124
125
126
127
128
129
130
                 scade == fv->language ? "SCADE" : "Simulink", fv->name);
            ERROR
                ("** (but possibly several input and output parameters).\n");
            add_error();
        }

        if (0 != count_ri) {
            ERROR
131
                ("[ERROR] %s function \"%s\" must NOT contain any required interface\n",
Maxime Perrotin's avatar
Maxime Perrotin committed
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
                 scade == fv->language ? "SCADE" : "Simulink", fv->name);
            ERROR
                ("** (use OUT parameters in the interface specification).\n");
            add_error();
        }
    }

    /* 
     * QGenC/QGenAda specific checks: *NO* RI
     */
    if (qgenc == fv->language || qgenada == fv->language) {
        int count_ri = 0;

        FOREACH(i, Interface, fv->interfaces, {
            if (RI == i->direction) {
                count_ri++;}
            else {
                if (asynch == i->synchronism) {
                    ERROR
151
                    ("[ERROR] Required interface %s of function %s should be PROTECTED or UNPROTECTED\n",
Maxime Perrotin's avatar
Maxime Perrotin committed
152
153
154
155
156
157
158
159
160
161
162
163
                     i->name, fv->name);
                    ERROR
                    ("   because it is connected to a function that is using QGen as a source language\n");
                    ERROR
                    ("   (remote calls cannot be made to QGen functions).\n");
                    add_error();
                }
            }
        });

        if (0 != count_ri) {
            ERROR
164
                ("[ERROR] %s function \"%s\" must NOT contain any required interface\n",
Maxime Perrotin's avatar
Maxime Perrotin committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
                 qgenc == fv->language ? "QGenC" : "QGenAda", fv->name);
            ERROR
                ("** (use OUT parameters in the interface specification).\n");
            add_error();
        }
    }

    /* 
     * SCADE specific check: function name and PI name must match
     */
    if (scade == fv->language) {
        Interface *i = NULL;

        if (NULL != fv->interfaces) {
            i = fv->interfaces->value;
        }

        if (strcmp(i->name, fv->name)) {
            ERROR
184
            ("[ERROR] PI \"%s\" should have the same name as SCADE function \"%s\"\n",
Maxime Perrotin's avatar
Maxime Perrotin committed
185
186
187
188
189
190
191
192
193
194
195
196
197
198
             i->name, fv->name);
            add_error();
        }
    }

    /* 
     * GUI-specific checks : 
     * (1) RIs must have a parameter
     * (2) All PI/RIs of GUIs must be sporadic
     */
    if (gui == fv->language) {
        FOREACH(i, Interface, fv->interfaces, {
            if (RI == i->direction) {
                if (NULL == i->in) {
199
                    ERROR("[ERROR] in GUI function \"%s\",\n"
Maxime Perrotin's avatar
Maxime Perrotin committed
200
201
202
203
204
205
206
                           "**    interface \"%s\" must contain a parameter.\n",
                           fv->name,
                           i->name); 
                    add_error();}
                }
                /* Undefined RCM corresponds to "any type" (=inherited from PI) */ 
                if (undefined != i->rcm && sporadic != i->rcm && variator != i->rcm) {
207
                    ERROR("[ERROR] All interfaces of GUI \"%s\"\n"
Maxime Perrotin's avatar
Maxime Perrotin committed
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
                           "**       must be SPORADIC (e.g. %s is not).\n",
                           fv->name,
                           i->name);
                    add_error();
                }
            }
        );
    }

    /*
     * Pro/Unpro checks: Passive functions must be bound to the same process
     * as all their calling threads (to handle possible static data).
     */
    FOREACH(i, Interface, fv->interfaces, {
            if (RI == i->direction && synch == i->synchronism
                && NULL != i->distant_fv) {
            FOREACH(function, FV, get_system_ast()->functions, {
                    if (!strcmp(function->name, i->distant_fv)
                        && function->process != fv->process) {
                    ERROR
228
                    ("[ERROR] Required interface %s of function %s should be SPORADIC\n",
Maxime Perrotin's avatar
Maxime Perrotin committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
                     i->name, fv->name);
                    ERROR
                    ("   because it is connected to a function that is bound to a different\n");
                    ERROR
                    ("   partition in your deployment view (remote calls cannot be synchronous)\n");
                    add_error();}
                    }
            );}
            }
    );

    FOREACH(i, Interface, fv->interfaces, {
            Interface_Semantic_Check(i);
            }
    );
}

/* External interface */
void Semantic_Checks()
{
    FOREACH(fv, FV, get_system_ast()->functions, {
            Function_Semantic_Check(fv);
    });

    /*
     * VHDL-specific check: there can be only ONE VHDL subsystem per node
     */
    FOREACH(process, Process, get_system_ast()->processes, {
            int count = 0;
            FOREACH(binding, Aplc_binding, process->bindings, {
                    if (vhdl == binding->fv->language) count++;}
            ); if (count > 1) {
            ERROR
262
            ("[ERROR] in a distributed system, a partition can contain only ONE\n");
Maxime Perrotin's avatar
Maxime Perrotin committed
263
264
265
266
267
            ERROR("   VHDL component. Partition \"%s\" has %d.\n",
                   process->name, count); add_error();}

    });
}