Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e66b042f0aaf2f35989b9f52e915001f6fd3b9eb (plain) (blame)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
package org.eclipse.etrice.generator.c.gen;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.HashSet;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.etrice.core.room.DataClass;
import org.eclipse.etrice.core.room.DataType;
import org.eclipse.etrice.core.room.DetailCode;
import org.eclipse.etrice.core.room.Message;
import org.eclipse.etrice.core.room.PrimitiveType;
import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.RefableType;
import org.eclipse.etrice.core.room.VarDecl;
import org.eclipse.etrice.generator.base.ILogger;
import org.eclipse.etrice.generator.c.gen.CExtensions;
import org.eclipse.etrice.generator.etricegen.Root;
import org.eclipse.etrice.generator.extensions.RoomExtensions;
import org.eclipse.etrice.generator.generic.GenericProtocolClassGenerator;
import org.eclipse.etrice.generator.generic.ProcedureHelpers;
import org.eclipse.etrice.generator.generic.TypeHelpers;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
import org.eclipse.xtext.xbase.lib.BooleanExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.eclipse.xtext.xtend2.lib.StringConcatenation;

@SuppressWarnings("all")
@Singleton
public class ProtocolClassGen extends GenericProtocolClassGenerator {
  @Inject
  private JavaIoFileSystemAccess fileAccess;
  
  @Inject
  private CExtensions stdExt;
  
  @Inject
  private RoomExtensions roomExt;
  
  @Inject
  private ProcedureHelpers helpers;
  
  @Inject
  private TypeHelpers _typeHelpers;
  
  @Inject
  private ILogger logger;
  
  public void doGenerate(final Root root) {
    EList<ProtocolClass> _usedProtocolClasses = root.getUsedProtocolClasses();
    for (final ProtocolClass pc : _usedProtocolClasses) {
      {
        String _generationTargetPath = this.roomExt.getGenerationTargetPath(pc);
        String _path = this.roomExt.getPath(pc);
        String _operator_plus = StringExtensions.operator_plus(_generationTargetPath, _path);
        String path = _operator_plus;
        String _cHeaderFileName = this.stdExt.getCHeaderFileName(pc);
        String _operator_plus_1 = StringExtensions.operator_plus("generating ProtocolClass header \'", _cHeaderFileName);
        String _operator_plus_2 = StringExtensions.operator_plus(_operator_plus_1, "\' in \'");
        String _operator_plus_3 = StringExtensions.operator_plus(_operator_plus_2, path);
        String _operator_plus_4 = StringExtensions.operator_plus(_operator_plus_3, "\'");
        this.logger.logInfo(_operator_plus_4);
        this.fileAccess.setOutputPath(path);
        String _cHeaderFileName_1 = this.stdExt.getCHeaderFileName(pc);
        StringConcatenation _generateHeaderFile = this.generateHeaderFile(root, pc);
        this.fileAccess.generateFile(_cHeaderFileName_1, _generateHeaderFile);
        String _cSourceFileName = this.stdExt.getCSourceFileName(pc);
        String _operator_plus_5 = StringExtensions.operator_plus("generating ProtocolClass source \'", _cSourceFileName);
        String _operator_plus_6 = StringExtensions.operator_plus(_operator_plus_5, "\' in \'");
        String _operator_plus_7 = StringExtensions.operator_plus(_operator_plus_6, path);
        String _operator_plus_8 = StringExtensions.operator_plus(_operator_plus_7, "\'");
        this.logger.logInfo(_operator_plus_8);
        this.fileAccess.setOutputPath(path);
        String _cSourceFileName_1 = this.stdExt.getCSourceFileName(pc);
        StringConcatenation _generateSourceFile = this.generateSourceFile(root, pc);
        this.fileAccess.generateFile(_cSourceFileName_1, _generateSourceFile);
      }
    }
  }
  
  public StringConcatenation generateHeaderFile(final Root root, final ProtocolClass pc) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @author generated by eTrice");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* Header File of ProtocolClass ");
    String _name = pc.getName();
    _builder.append(_name, " ");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("* ");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    _builder.newLine();
    String _name_1 = pc.getName();
    StringConcatenation _generateIncludeGuardBegin = this.stdExt.generateIncludeGuardBegin(_name_1);
    _builder.append(_generateIncludeGuardBegin, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("#include \"etDatatypes.h\"");
    _builder.newLine();
    _builder.append("#include \"modelbase/etPort.h\"");
    _builder.newLine();
    _builder.newLine();
    DetailCode _userCode1 = pc.getUserCode1();
    StringConcatenation _userCode = this.helpers.userCode(_userCode1);
    _builder.append(_userCode, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    {
      HashSet<DataClass> _referencedDataClasses = root.getReferencedDataClasses(pc);
      for(final DataClass dataClass : _referencedDataClasses) {
        _builder.append("#include \"");
        String _name_2 = dataClass.getName();
        _builder.append(_name_2, "");
        _builder.append(".h\"");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("/* message IDs */");
    _builder.newLine();
    String _genMessageIDs = this.genMessageIDs(pc);
    _builder.append(_genMessageIDs, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/*--------------------- port classes */");
    _builder.newLine();
    StringConcatenation _portClassHeader = this.portClassHeader(pc, ((Boolean)false));
    _builder.append(_portClassHeader, "");
    _builder.newLineIfNotEmpty();
    StringConcatenation _portClassHeader_1 = this.portClassHeader(pc, ((Boolean)true));
    _builder.append(_portClassHeader_1, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/*--------------------- debug helpers */");
    _builder.newLine();
    _builder.newLine();
    _builder.append("/* get message string for message id */");
    _builder.newLine();
    _builder.append("const char* ");
    String _name_3 = pc.getName();
    _builder.append(_name_3, "");
    _builder.append("_getMessageString(int msg_id);");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    DetailCode _userCode2 = pc.getUserCode2();
    StringConcatenation _userCode_1 = this.helpers.userCode(_userCode2);
    _builder.append(_userCode_1, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    String _name_4 = pc.getName();
    StringConcatenation _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(_name_4);
    _builder.append(_generateIncludeGuardEnd, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    return _builder;
  }
  
  public StringConcatenation generateSourceFile(final Root root, final ProtocolClass pc) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @author generated by eTrice");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* Source File of ProtocolClass ");
    String _name = pc.getName();
    _builder.append(_name, " ");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("* ");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    _builder.newLine();
    _builder.append("#include \"");
    String _cHeaderFileName = this.stdExt.getCHeaderFileName(pc);
    _builder.append(_cHeaderFileName, "");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("#include \"debugging/etMSCLogger.h\"");
    _builder.newLine();
    _builder.newLine();
    DetailCode _userCode3 = pc.getUserCode3();
    StringConcatenation _userCode = this.helpers.userCode(_userCode3);
    _builder.append(_userCode, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/*--------------------- port classes */");
    _builder.newLine();
    StringConcatenation _portClassSource = this.portClassSource(pc, ((Boolean)false));
    _builder.append(_portClassSource, "");
    _builder.newLineIfNotEmpty();
    StringConcatenation _portClassSource_1 = this.portClassSource(pc, ((Boolean)true));
    _builder.append(_portClassSource_1, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/*--------------------- debug helpers */");
    _builder.newLine();
    StringConcatenation _generateDebugHelpersImplementation = this.generateDebugHelpersImplementation(root, pc);
    _builder.append(_generateDebugHelpersImplementation, "");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  public StringConcatenation portClass(final ProtocolClass pc, final Boolean conj) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    return _builder;
  }
  
  public StringConcatenation portClassHeader(final ProtocolClass pc, final Boolean conj) {
    StringConcatenation _xblockexpression = null;
    {
      String _portClassName = this.roomExt.getPortClassName(pc, conj);
      String portClassName = _portClassName;
      String _portClassName_1 = this.roomExt.getPortClassName(pc, conj, true);
      String replPortClassName = _portClassName_1;
      List<Message> _xifexpression = null;
      if (conj) {
        List<Message> _allIncomingMessages = this.roomExt.getAllIncomingMessages(pc);
        _xifexpression = _allIncomingMessages;
      } else {
        List<Message> _allOutgoingMessages = this.roomExt.getAllOutgoingMessages(pc);
        _xifexpression = _allOutgoingMessages;
      }
      List<Message> messages = _xifexpression;
      StringConcatenation _builder = new StringConcatenation();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("typedef etPort ");
      _builder.append(portClassName, "	");
      _builder.append(";");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("typedef etReplPort ");
      _builder.append(replPortClassName, "	");
      _builder.append(";");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.newLine();
      {
        for(final Message message : messages) {
          _builder.append("\t");
          VarDecl _data = message.getData();
          boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_data, null);
          boolean hasData = _operator_notEquals;
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          String _xifexpression_1 = null;
          if (hasData) {
            VarDecl _data_1 = message.getData();
            RefableType _refType = _data_1.getRefType();
            DataType _type = _refType.getType();
            String _typeName = this._typeHelpers.typeName(_type);
            _xifexpression_1 = _typeName;
          } else {
            _xifexpression_1 = "";
          }
          String typeName = _xifexpression_1;
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          String _xifexpression_2 = null;
          boolean _operator_and = false;
          if (!hasData) {
            _operator_and = false;
          } else {
            VarDecl _data_2 = message.getData();
            RefableType _refType_1 = _data_2.getRefType();
            DataType _type_1 = _refType_1.getType();
            boolean _operator_not = BooleanExtensions.operator_not((_type_1 instanceof PrimitiveType));
            _operator_and = BooleanExtensions.operator_and(hasData, _operator_not);
          }
          if (_operator_and) {
            _xifexpression_2 = "*";
          } else {
            _xifexpression_2 = "";
          }
          String refp = _xifexpression_2;
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          String _xifexpression_3 = null;
          if (hasData) {
            String _operator_plus = StringExtensions.operator_plus(", ", typeName);
            String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, refp);
            String _operator_plus_2 = StringExtensions.operator_plus(_operator_plus_1, " data");
            _xifexpression_3 = _operator_plus_2;
          } else {
            _xifexpression_3 = "";
          }
          String data = _xifexpression_3;
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          String _name = message.getName();
          String _messageSignature = this.messageSignature(portClassName, _name, "", data);
          _builder.append(_messageSignature, "	");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          String _name_1 = message.getName();
          String _messageSignature_1 = this.messageSignature(replPortClassName, _name_1, "_broadcast", data);
          _builder.append(_messageSignature_1, "	");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          String _name_2 = message.getName();
          String _operator_plus_3 = StringExtensions.operator_plus(", int idx", data);
          String _messageSignature_2 = this.messageSignature(replPortClassName, _name_2, "", _operator_plus_3);
          _builder.append(_messageSignature_2, "	");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        }
      }
      _xblockexpression = (_builder);
    }
    return _xblockexpression;
  }
  
  public StringConcatenation portClassSource(final ProtocolClass pc, final Boolean conj) {
    StringConcatenation _xblockexpression = null;
    {
      String _portClassName = this.roomExt.getPortClassName(pc, conj);
      String portClassName = _portClassName;
      String _portClassName_1 = this.roomExt.getPortClassName(pc, conj, true);
      String replPortClassName = _portClassName_1;
      List<Message> _xifexpression = null;
      if (conj) {
        List<Message> _allIncomingMessages = this.roomExt.getAllIncomingMessages(pc);
        _xifexpression = _allIncomingMessages;
      } else {
        List<Message> _allOutgoingMessages = this.roomExt.getAllOutgoingMessages(pc);
        _xifexpression = _allOutgoingMessages;
      }
      List<Message> messages = _xifexpression;
      String _xifexpression_1 = null;
      if (conj) {
        _xifexpression_1 = "IN_";
      } else {
        _xifexpression_1 = "OUT_";
      }
      String dir = _xifexpression_1;
      StringConcatenation _builder = new StringConcatenation();
      {
        for(final Message message : messages) {
          VarDecl _data = message.getData();
          boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_data, null);
          boolean hasData = _operator_notEquals;
          _builder.newLineIfNotEmpty();
          String _xifexpression_2 = null;
          if (hasData) {
            VarDecl _data_1 = message.getData();
            RefableType _refType = _data_1.getRefType();
            DataType _type = _refType.getType();
            String _typeName = this._typeHelpers.typeName(_type);
            _xifexpression_2 = _typeName;
          } else {
            _xifexpression_2 = "";
          }
          String typeName = _xifexpression_2;
          _builder.newLineIfNotEmpty();
          String _xifexpression_3 = null;
          boolean _operator_and = false;
          if (!hasData) {
            _operator_and = false;
          } else {
            VarDecl _data_2 = message.getData();
            RefableType _refType_1 = _data_2.getRefType();
            DataType _type_1 = _refType_1.getType();
            boolean _operator_not = BooleanExtensions.operator_not((_type_1 instanceof PrimitiveType));
            _operator_and = BooleanExtensions.operator_and(hasData, _operator_not);
          }
          if (_operator_and) {
            _xifexpression_3 = "*";
          } else {
            _xifexpression_3 = "";
          }
          String refp = _xifexpression_3;
          _builder.newLineIfNotEmpty();
          String _xifexpression_4 = null;
          boolean _operator_and_1 = false;
          if (!hasData) {
            _operator_and_1 = false;
          } else {
            VarDecl _data_3 = message.getData();
            RefableType _refType_2 = _data_3.getRefType();
            DataType _type_2 = _refType_2.getType();
            _operator_and_1 = BooleanExtensions.operator_and(hasData, (_type_2 instanceof PrimitiveType));
          }
          if (_operator_and_1) {
            _xifexpression_4 = "&";
          } else {
            _xifexpression_4 = "";
          }
          String refa = _xifexpression_4;
          _builder.newLineIfNotEmpty();
          String _xifexpression_5 = null;
          if (hasData) {
            String _operator_plus = StringExtensions.operator_plus(", ", typeName);
            String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, refp);
            String _operator_plus_2 = StringExtensions.operator_plus(_operator_plus_1, " data");
            _xifexpression_5 = _operator_plus_2;
          } else {
            _xifexpression_5 = "";
          }
          String data = _xifexpression_5;
          _builder.newLineIfNotEmpty();
          _builder.newLine();
          String _name = message.getName();
          String _messageSignature = this.messageSignature(portClassName, _name, "", data);
          _builder.append(_messageSignature, "");
          _builder.append(" {");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"");
          _builder.append(portClassName, "	");
          _builder.append("\", \"");
          String _name_1 = message.getName();
          _builder.append(_name_1, "	");
          _builder.append("\")");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("if (self->receiveMessageFunc!=NULL) {");
          _builder.newLine();
          _builder.append("\t\t");
          String _name_2 = pc.getName();
          String _name_3 = message.getName();
          String _operator_plus_3 = StringExtensions.operator_plus(dir, _name_3);
          String _memberInUse = this.stdExt.memberInUse(_name_2, _operator_plus_3);
          String _operator_plus_4 = StringExtensions.operator_plus(refa, "data");
          String _sendMessageCall = this.sendMessageCall(hasData, "self", _memberInUse, typeName, _operator_plus_4);
          _builder.append(_sendMessageCall, "		");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("}");
          _builder.newLine();
          _builder.append("\t");
          _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
          String _name_4 = message.getName();
          String _messageSignature_1 = this.messageSignature(replPortClassName, _name_4, "_broadcast", data);
          _builder.append(_messageSignature_1, "");
          _builder.append(" {");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("int i;");
          _builder.newLine();
          _builder.append("\t");
          _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"");
          _builder.append(replPortClassName, "	");
          _builder.append("\", \"");
          String _name_5 = message.getName();
          _builder.append(_name_5, "	");
          _builder.append("\")");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("for (i=0; i<self->size; ++i) {");
          _builder.newLine();
          _builder.append("\t\t");
          String _name_6 = pc.getName();
          String _name_7 = message.getName();
          String _operator_plus_5 = StringExtensions.operator_plus(dir, _name_7);
          String _memberInUse_1 = this.stdExt.memberInUse(_name_6, _operator_plus_5);
          String _operator_plus_6 = StringExtensions.operator_plus(refa, "data");
          String _sendMessageCall_1 = this.sendMessageCall(hasData, "(etPort*)(&self->ports[i])", _memberInUse_1, typeName, _operator_plus_6);
          _builder.append(_sendMessageCall_1, "		");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("}");
          _builder.newLine();
          _builder.append("\t");
          _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
          String _name_8 = message.getName();
          String _operator_plus_7 = StringExtensions.operator_plus(", int idx", data);
          String _messageSignature_2 = this.messageSignature(replPortClassName, _name_8, "", _operator_plus_7);
          _builder.append(_messageSignature_2, "");
          _builder.append(" {");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"");
          _builder.append(replPortClassName, "	");
          _builder.append("\", \"");
          String _name_9 = message.getName();
          _builder.append(_name_9, "	");
          _builder.append("\")");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("if (0<=idx && idx<self->size) {");
          _builder.newLine();
          _builder.append("\t\t");
          String _name_10 = pc.getName();
          String _name_11 = message.getName();
          String _operator_plus_8 = StringExtensions.operator_plus(dir, _name_11);
          String _memberInUse_2 = this.stdExt.memberInUse(_name_10, _operator_plus_8);
          String _operator_plus_9 = StringExtensions.operator_plus(refa, "data");
          String _sendMessageCall_2 = this.sendMessageCall(hasData, "(etPort*)(&self->ports[idx])", _memberInUse_2, typeName, _operator_plus_9);
          _builder.append(_sendMessageCall_2, "		");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("}");
          _builder.newLine();
          _builder.append("\t");
          _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
        }
      }
      _xblockexpression = (_builder);
    }
    return _xblockexpression;
  }
  
  private String sendMessageCall(final boolean hasData, final String self, final String msg, final String typeName, final String data) {
    String _xifexpression = null;
    if (hasData) {
      String _operator_plus = StringExtensions.operator_plus("etPort_sendMessage(", self);
      String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, ", ");
      String _operator_plus_2 = StringExtensions.operator_plus(_operator_plus_1, msg);
      String _operator_plus_3 = StringExtensions.operator_plus(_operator_plus_2, ", sizeof(");
      String _operator_plus_4 = StringExtensions.operator_plus(_operator_plus_3, typeName);
      String _operator_plus_5 = StringExtensions.operator_plus(_operator_plus_4, "), ");
      String _operator_plus_6 = StringExtensions.operator_plus(_operator_plus_5, data);
      String _operator_plus_7 = StringExtensions.operator_plus(_operator_plus_6, ");");
      _xifexpression = _operator_plus_7;
    } else {
      String _operator_plus_8 = StringExtensions.operator_plus("etPort_sendMessage(", self);
      String _operator_plus_9 = StringExtensions.operator_plus(_operator_plus_8, ", ");
      String _operator_plus_10 = StringExtensions.operator_plus(_operator_plus_9, msg);
      String _operator_plus_11 = StringExtensions.operator_plus(_operator_plus_10, ", 0, NULL);");
      _xifexpression = _operator_plus_11;
    }
    return _xifexpression;
  }
  
  private String messageSignature(final String className, final String messageName, final String methodSuffix, final String data) {
    String _operator_plus = StringExtensions.operator_plus("void ", className);
    String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, "_");
    String _operator_plus_2 = StringExtensions.operator_plus(_operator_plus_1, messageName);
    String _operator_plus_3 = StringExtensions.operator_plus(_operator_plus_2, methodSuffix);
    String _operator_plus_4 = StringExtensions.operator_plus(_operator_plus_3, "(const ");
    String _operator_plus_5 = StringExtensions.operator_plus(_operator_plus_4, className);
    String _operator_plus_6 = StringExtensions.operator_plus(_operator_plus_5, "* self");
    String _operator_plus_7 = StringExtensions.operator_plus(_operator_plus_6, data);
    String _operator_plus_8 = StringExtensions.operator_plus(_operator_plus_7, ")");
    return _operator_plus_8;
  }
  
  private StringConcatenation messageCall(final Message m) {
    StringConcatenation _builder = new StringConcatenation();
    String _name = m.getName();
    _builder.append(_name, "");
    _builder.append("(");
    {
      VarDecl _data = m.getData();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_data, null);
      if (_operator_notEquals) {
        _builder.append(" ");
        VarDecl _data_1 = m.getData();
        String _name_1 = _data_1.getName();
        _builder.append(_name_1, "");
      }
    }
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  public StringConcatenation generateDebugHelpersImplementation(final Root root, final ProtocolClass pc) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("/* message names as strings for debugging (generate MSC) */");
    _builder.newLine();
    _builder.append("static const char* ");
    String _name = pc.getName();
    _builder.append(_name, "");
    _builder.append("_messageStrings[] = {\"MIN\", ");
    {
      List<Message> _allOutgoingMessages = this.roomExt.getAllOutgoingMessages(pc);
      for(final Message m : _allOutgoingMessages) {
        _builder.append("\"");
        String _name_1 = m.getName();
        _builder.append(_name_1, "");
        _builder.append("\",");
      }
    }
    {
      List<Message> _allIncomingMessages = this.roomExt.getAllIncomingMessages(pc);
      for(final Message m_1 : _allIncomingMessages) {
        _builder.append("\"");
        String _name_2 = m_1.getName();
        _builder.append(_name_2, "");
        _builder.append("\", ");
      }
    }
    _builder.append("\"MAX\"};");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("const char* ");
    String _name_3 = pc.getName();
    _builder.append(_name_3, "");
    _builder.append("_getMessageString(int msg_id) {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("if (msg_id<");
    String _name_4 = pc.getName();
    _builder.append(_name_4, "	");
    _builder.append("_MSG_MIN || msg_id>");
    String _name_5 = pc.getName();
    _builder.append(_name_5, "	");
    _builder.append("_MSG_MAX+1){");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("/* id out of range */");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return \"Message ID out of range\";");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("else{");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return ");
    String _name_6 = pc.getName();
    _builder.append(_name_6, "		");
    _builder.append("_messageStrings[msg_id];");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
}

Back to the top