Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8abd27aafda4cba7d6885c9aa88c7ab33d76ea3c (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
/**
 * Copyright (c) 2014 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     CEA LIST - initial API and implementation
 */
package org.eclipse.papyrus.cpp.codegen.xtend;

import com.google.common.base.Objects;
import java.util.Collection;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.papyrus.C_Cpp.Union;
import org.eclipse.papyrus.codegen.base.GenUtils;
import org.eclipse.papyrus.cpp.codegen.preferences.CppCodeGenUtils;
import org.eclipse.papyrus.cpp.codegen.utils.CppGenUtils;
import org.eclipse.papyrus.cpp.codegen.xtend.CppAttribute;
import org.eclipse.papyrus.cpp.codegen.xtend.CppClassAttributesDeclaration;
import org.eclipse.papyrus.cpp.codegen.xtend.CppClassFriendDeclaration;
import org.eclipse.papyrus.cpp.codegen.xtend.CppClassIncludeClassDeclaration;
import org.eclipse.papyrus.cpp.codegen.xtend.CppClassInheritedDeclarations;
import org.eclipse.papyrus.cpp.codegen.xtend.CppClassOperationsDeclaration;
import org.eclipse.papyrus.cpp.codegen.xtend.CppClassOperationsImplementation;
import org.eclipse.papyrus.cpp.codegen.xtend.CppClassTypeAndEnum;
import org.eclipse.papyrus.cpp.codegen.xtend.CppDocumentation;
import org.eclipse.papyrus.cpp.codegen.xtend.CppIncludeUtil;
import org.eclipse.papyrus.cpp.codegen.xtend.CppOperations;
import org.eclipse.papyrus.cpp.codegen.xtend.CppTemplates;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.DataType;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.TemplateBinding;
import org.eclipse.uml2.uml.TemplateParameterSubstitution;
import org.eclipse.uml2.uml.ValueSpecification;
import org.eclipse.uml2.uml.VisibilityKind;
import org.eclipse.uml2.uml.profile.standard.Create;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;

/**
 * @author Ansgar Radermacher (ansgar.radermacher@cea.fr)
 */
@SuppressWarnings("all")
public class CppClassifierGenerator {
  public static CharSequence generateHeaderCode(final Classifier classifier, final String commentHeader) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append(commentHeader, "");
    _builder.newLineIfNotEmpty();
    _builder.append("AcceleoDriver.evaluate(cppInclude.getHeader(), classifier, null);");
    _builder.newLine();
    return _builder;
  }
  
  public static CharSequence generateBindHeaderCode(final Classifier classifier) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#ifndef ");
    String _fullNameUC = GenUtils.getFullNameUC(classifier);
    _builder.append(_fullNameUC, "");
    _builder.append("_H");
    _builder.newLineIfNotEmpty();
    _builder.append("#define ");
    String _fullNameUC_1 = GenUtils.getFullNameUC(classifier);
    _builder.append(_fullNameUC_1, "");
    _builder.append("_H");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/************************************************************");
    _builder.newLine();
    _builder.append("              ");
    String _name = classifier.getName();
    _builder.append(_name, "              ");
    _builder.append(" template binding header");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("************************************************************/");
    _builder.newLine();
    _builder.newLine();
    org.eclipse.uml2.uml.Package _package = classifier.getPackage();
    String _cppOwnerPackageIncludePath = CppClassIncludeClassDeclaration.cppOwnerPackageIncludePath(_package);
    String _includeDirective = CppIncludeUtil.includeDirective(_cppOwnerPackageIncludePath);
    _builder.append(_includeDirective, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    {
      List<String> _sortedIncludePathList = CppClassifierGenerator.getSortedIncludePathList(classifier);
      for(final String path : _sortedIncludePathList) {
        String _includeDirective_1 = CppIncludeUtil.includeDirective(path);
        _builder.append(_includeDirective_1, "");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    String _CppIncludeHeader = CppIncludeUtil.CppIncludeHeader(classifier);
    _builder.append(_CppIncludeHeader, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    TemplateBinding tb = GenUtils.getTemplateBinding(classifier);
    _builder.newLineIfNotEmpty();
    EList<Element> _targets = tb.getTargets();
    Element templateElement = _targets.get(0);
    _builder.newLineIfNotEmpty();
    org.eclipse.uml2.uml.Package _package_1 = classifier.getPackage();
    String _fullPath = GenUtils.getFullPath(_package_1);
    String _plus = (_fullPath + "/");
    Element _owner = templateElement.getOwner();
    String _name_1 = ((NamedElement) _owner).getName();
    String _plus_1 = (_plus + _name_1);
    String _plus_2 = (_plus_1 + ".");
    String _headerSuffix = CppCodeGenUtils.getHeaderSuffix();
    String _plus_3 = (_plus_2 + _headerSuffix);
    String _includeDirective_2 = CppIncludeUtil.includeDirective(_plus_3);
    _builder.append(_includeDirective_2, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    String _openNS = CppGenUtils.openNS(classifier);
    _builder.append(_openNS, "");
    _builder.newLineIfNotEmpty();
    _builder.append("/************************************************************/");
    _builder.newLine();
    _builder.append("typedef ");
    Element _owner_1 = templateElement.getOwner();
    String _name_2 = ((NamedElement) _owner_1).getName();
    _builder.append(_name_2, "");
    _builder.append("<");
    {
      EList<TemplateParameterSubstitution> _parameterSubstitutions = tb.getParameterSubstitutions();
      boolean _hasElements = false;
      for(final TemplateParameterSubstitution ps : _parameterSubstitutions) {
        if (!_hasElements) {
          _hasElements = true;
        } else {
          _builder.appendImmediate(", ", "");
        }
        Object _CppTemplateBindingParameter = CppTemplates.CppTemplateBindingParameter(ps);
        _builder.append(_CppTemplateBindingParameter, "");
      }
    }
    _builder.append("> ");
    String _name_3 = classifier.getName();
    _builder.append(_name_3, "");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    String _closeNS = CppGenUtils.closeNS(classifier);
    _builder.append(_closeNS, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/************************************************************");
    _builder.newLine();
    _builder.append("              ");
    _builder.append("End of ");
    String _name_4 = classifier.getName();
    _builder.append(_name_4, "              ");
    _builder.append(" template binding header");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("************************************************************/");
    _builder.newLine();
    _builder.newLine();
    _builder.append("#endif");
    _builder.newLine();
    return _builder;
  }
  
  public static List<String> getSortedIncludePathList(final Classifier classifier) {
    Iterable<String> _CppClassAllIncludes = CppClassIncludeClassDeclaration.CppClassAllIncludes(classifier);
    List<String> includePathList = IterableExtensions.<String>sort(_CppClassAllIncludes);
    return includePathList;
  }
  
  public static CharSequence generateBindBodyCode(final Classifier classifier) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#define ");
    String _fullNameUC = GenUtils.getFullNameUC(classifier);
    _builder.append(_fullNameUC, "");
    _builder.append("_BODY");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/************************************************************");
    _builder.newLine();
    _builder.append("              ");
    String _name = classifier.getName();
    _builder.append(_name, "              ");
    _builder.append(" template binding body");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("************************************************************/");
    _builder.newLine();
    _builder.newLine();
    String _CppIncludePreBody = CppIncludeUtil.CppIncludePreBody(classifier);
    _builder.append(_CppIncludePreBody, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("// include associated header file");
    _builder.newLine();
    org.eclipse.uml2.uml.Package _package = classifier.getPackage();
    String _fullPath = GenUtils.getFullPath(_package);
    String _plus = (_fullPath + "/");
    String _name_1 = classifier.getName();
    String _plus_1 = (_plus + _name_1);
    String _plus_2 = (_plus_1 + ".");
    String _headerSuffix = CppCodeGenUtils.getHeaderSuffix();
    String _plus_3 = (_plus_2 + _headerSuffix);
    String _includeDirective = CppIncludeUtil.includeDirective(_plus_3);
    _builder.append(_includeDirective, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    String _CppIncludeBody = CppIncludeUtil.CppIncludeBody(classifier);
    _builder.append(_CppIncludeBody, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    String _openNS = CppGenUtils.openNS(classifier);
    _builder.append(_openNS, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("// Derived includes directives");
    _builder.newLine();
    {
      Iterable<String> _CppClassAllIncludes = CppClassIncludeClassDeclaration.CppClassAllIncludes(classifier);
      List<String> _sort = IterableExtensions.<String>sort(_CppClassAllIncludes);
      for(final String path : _sort) {
        String _includeDirective_1 = CppIncludeUtil.includeDirective(path);
        _builder.append(_includeDirective_1, "");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("/************************************************************/");
    _builder.newLine();
    TemplateBinding tb = GenUtils.getTemplateBinding(classifier);
    _builder.newLineIfNotEmpty();
    EList<Element> _targets = tb.getTargets();
    Element templateElement = _targets.get(0);
    _builder.newLineIfNotEmpty();
    _builder.append("template class ");
    Element _owner = templateElement.getOwner();
    String _name_2 = ((NamedElement) _owner).getName();
    _builder.append(_name_2, "");
    _builder.append("<");
    {
      EList<TemplateParameterSubstitution> _parameterSubstitutions = tb.getParameterSubstitutions();
      boolean _hasElements = false;
      for(final TemplateParameterSubstitution ps : _parameterSubstitutions) {
        if (!_hasElements) {
          _hasElements = true;
        } else {
          _builder.appendImmediate(", ", "");
        }
        Object _CppTemplateBindingParameter = CppTemplates.CppTemplateBindingParameter(ps);
        _builder.append(_CppTemplateBindingParameter, "");
      }
    }
    _builder.append(">;");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    String _closeNS = CppGenUtils.closeNS(classifier);
    _builder.append(_closeNS, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/************************************************************");
    _builder.newLine();
    _builder.append("              ");
    _builder.append("End of ");
    String _name_3 = classifier.getName();
    _builder.append(_name_3, "              ");
    _builder.append(" template binding body");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("************************************************************/");
    _builder.newLine();
    return _builder;
  }
  
  public static CharSequence generateClassHeaderCode(final Classifier classifier) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#ifndef ");
    String _fullNameUC = GenUtils.getFullNameUC(classifier);
    _builder.append(_fullNameUC, "");
    _builder.append("_H");
    _builder.newLineIfNotEmpty();
    _builder.append("#define ");
    String _fullNameUC_1 = GenUtils.getFullNameUC(classifier);
    _builder.append(_fullNameUC_1, "");
    _builder.append("_H");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/************************************************************");
    _builder.newLine();
    _builder.append("              ");
    String _name = classifier.getName();
    _builder.append(_name, "              ");
    _builder.append(" class header");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("************************************************************/");
    _builder.newLine();
    _builder.newLine();
    org.eclipse.uml2.uml.Package _package = classifier.getPackage();
    String _cppOwnerPackageIncludePath = CppClassIncludeClassDeclaration.cppOwnerPackageIncludePath(_package);
    String _includeDirective = CppIncludeUtil.includeDirective(_cppOwnerPackageIncludePath);
    _builder.append(_includeDirective, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    {
      List<String> _sortedIncludePathList = CppClassifierGenerator.getSortedIncludePathList(classifier);
      for(final String path : _sortedIncludePathList) {
        String _includeDirective_1 = CppIncludeUtil.includeDirective(path);
        _builder.append(_includeDirective_1, "");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    String _CppIncludeHeader = CppIncludeUtil.CppIncludeHeader(classifier);
    _builder.append(_CppIncludeHeader, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    String _openNS = CppGenUtils.openNS(classifier);
    _builder.append(_openNS, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/************************************************************/");
    _builder.newLine();
    CharSequence _CppElementDoc = CppDocumentation.CppElementDoc(classifier);
    _builder.append(_CppElementDoc, "");
    _builder.newLineIfNotEmpty();
    CharSequence _templateSignature = CppTemplates.templateSignature(classifier);
    _builder.append(_templateSignature, "");
    String _classUnionOrStruct = CppClassifierGenerator.classUnionOrStruct(classifier);
    _builder.append(_classUnionOrStruct, "");
    _builder.append(" ");
    String _name_1 = classifier.getName();
    _builder.append(_name_1, "");
    CharSequence _CppClassInheritedDeclarations = CppClassInheritedDeclarations.CppClassInheritedDeclarations(classifier);
    _builder.append(_CppClassInheritedDeclarations, "");
    _builder.append(" {");
    _builder.newLineIfNotEmpty();
    CppClassFriendDeclaration.CppClassIncludeFriendDeclaration(classifier);
    CharSequence _CppClassTypeAndEnum = CppClassTypeAndEnum.CppClassTypeAndEnum(classifier);
    _builder.append(_CppClassTypeAndEnum, "");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    VisibilityKind publicVisibility = VisibilityKind.PUBLIC_LITERAL;
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    String _defaultInitializer = CppClassifierGenerator.defaultInitializer(classifier);
    String _section = CppGenUtils.getSection(publicVisibility, _defaultInitializer);
    _builder.append(_section, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    CharSequence _CppClassAttributesDeclaration = CppClassAttributesDeclaration.CppClassAttributesDeclaration(classifier, publicVisibility);
    String _string = _CppClassAttributesDeclaration.toString();
    String _section_1 = CppGenUtils.getSection(publicVisibility, _string);
    _builder.append(_section_1, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    CharSequence _CppClassOperationsDeclaration = CppClassOperationsDeclaration.CppClassOperationsDeclaration(classifier, publicVisibility);
    String _string_1 = _CppClassOperationsDeclaration.toString();
    String _section_2 = CppGenUtils.getSection(publicVisibility, _string_1);
    _builder.append(_section_2, "\t");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    VisibilityKind protectedVisibility = VisibilityKind.PROTECTED_LITERAL;
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    CharSequence _CppClassAttributesDeclaration_1 = CppClassAttributesDeclaration.CppClassAttributesDeclaration(classifier, protectedVisibility);
    String _string_2 = _CppClassAttributesDeclaration_1.toString();
    String _section_3 = CppGenUtils.getSection(protectedVisibility, _string_2);
    _builder.append(_section_3, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    CharSequence _CppClassOperationsDeclaration_1 = CppClassOperationsDeclaration.CppClassOperationsDeclaration(classifier, protectedVisibility);
    String _string_3 = _CppClassOperationsDeclaration_1.toString();
    String _section_4 = CppGenUtils.getSection(protectedVisibility, _string_3);
    _builder.append(_section_4, "\t");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    VisibilityKind privateVisibility = VisibilityKind.PRIVATE_LITERAL;
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    CharSequence _CppClassAttributesDeclaration_2 = CppClassAttributesDeclaration.CppClassAttributesDeclaration(classifier, privateVisibility);
    String _string_4 = _CppClassAttributesDeclaration_2.toString();
    String _section_5 = CppGenUtils.getSection(privateVisibility, _string_4);
    _builder.append(_section_5, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    CharSequence _CppClassOperationsDeclaration_2 = CppClassOperationsDeclaration.CppClassOperationsDeclaration(classifier, privateVisibility);
    String _string_5 = _CppClassOperationsDeclaration_2.toString();
    String _section_6 = CppGenUtils.getSection(privateVisibility, _string_5);
    _builder.append(_section_6, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("};");
    _builder.newLine();
    _builder.append("/************************************************************/");
    _builder.newLine();
    _builder.append("/* External declarations (package visibility)               */");
    _builder.newLine();
    VisibilityKind packageVisibility = VisibilityKind.PACKAGE_LITERAL;
    _builder.newLineIfNotEmpty();
    CharSequence _CppClassAttributesDeclaration_3 = CppClassAttributesDeclaration.CppClassAttributesDeclaration(classifier, packageVisibility);
    _builder.append(_CppClassAttributesDeclaration_3, "");
    _builder.newLineIfNotEmpty();
    CharSequence _CppClassOperationsDeclaration_3 = CppClassOperationsDeclaration.CppClassOperationsDeclaration(classifier, packageVisibility);
    _builder.append(_CppClassOperationsDeclaration_3, "");
    _builder.newLineIfNotEmpty();
    _builder.append("/************************************************************/");
    _builder.newLine();
    _builder.newLine();
    {
      boolean _isTemplate = CppTemplates.isTemplate(classifier);
      if (_isTemplate) {
        _builder.append("/************************************************************/");
        _builder.newLine();
        _builder.append("/* Template functions                                       */");
        _builder.newLine();
        CharSequence _CppClassOperationsImplementation = CppClassOperationsImplementation.CppClassOperationsImplementation(classifier, false);
        _builder.append(_CppClassOperationsImplementation, "");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("/* Inline functions                                         */");
    _builder.newLine();
    CharSequence _CppClassOperationsImplementation_1 = CppClassOperationsImplementation.CppClassOperationsImplementation(classifier, true);
    _builder.append(_CppClassOperationsImplementation_1, "");
    _builder.newLineIfNotEmpty();
    String _closeNS = CppGenUtils.closeNS(classifier);
    _builder.append(_closeNS, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/************************************************************");
    _builder.newLine();
    _builder.append("              ");
    _builder.append("End of ");
    String _name_2 = classifier.getName();
    _builder.append(_name_2, "              ");
    _builder.append(" class header");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("************************************************************/");
    _builder.newLine();
    _builder.newLine();
    _builder.append("#endif");
    _builder.newLine();
    return _builder;
  }
  
  public static String classUnionOrStruct(final Classifier classifier) {
    boolean _hasStereotype = GenUtils.hasStereotype(classifier, Union.class);
    if (_hasStereotype) {
      return "union";
    } else {
      if ((classifier instanceof DataType)) {
        CppGenUtils.resetVisibility(VisibilityKind.PUBLIC_LITERAL);
        return "struct";
      } else {
        CppGenUtils.resetVisibility(VisibilityKind.PRIVATE_LITERAL);
        return "class";
      }
    }
  }
  
  /**
   * default initializer for non-static attributes with a default value TODO: should be disabled by default, since non-static members can be initialized directly in C++ 011
   */
  public static String defaultInitializer(final Classifier classifier) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Collection<Operation> _ownedOperations = CppOperations.getOwnedOperations(classifier);
      final Function1<Operation, Boolean> _function = new Function1<Operation, Boolean>() {
        public Boolean apply(final Operation it) {
          return Boolean.valueOf(GenUtils.hasStereotype(it, Create.class));
        }
      };
      Iterable<Operation> _filter = IterableExtensions.<Operation>filter(_ownedOperations, _function);
      boolean _isEmpty = IterableExtensions.isEmpty(_filter);
      if (_isEmpty) {
        EList<Property> _attributes = classifier.getAttributes();
        final Function1<Property, Boolean> _function_1 = new Function1<Property, Boolean>() {
          public Boolean apply(final Property it) {
            boolean _and = false;
            boolean _and_1 = false;
            boolean _isStatic = it.isStatic();
            boolean _equals = (_isStatic == false);
            if (!_equals) {
              _and_1 = false;
            } else {
              ValueSpecification _defaultValue = it.getDefaultValue();
              boolean _notEquals = (!Objects.equal(_defaultValue, null));
              _and_1 = _notEquals;
            }
            if (!_and_1) {
              _and = false;
            } else {
              ValueSpecification _defaultValue_1 = it.getDefaultValue();
              String _stringValue = _defaultValue_1.stringValue();
              boolean _notEquals_1 = (!Objects.equal(_stringValue, null));
              _and = _notEquals_1;
            }
            return Boolean.valueOf(_and);
          }
        };
        Iterable<Property> attributeList = IterableExtensions.<Property>filter(_attributes, _function_1);
        _builder.newLineIfNotEmpty();
        {
          boolean _isEmpty_1 = IterableExtensions.isEmpty(attributeList);
          boolean _not = (!_isEmpty_1);
          if (_not) {
            String _name = classifier.getName();
            _builder.append(_name, "");
            _builder.append("() : ");
            {
              boolean _hasElements = false;
              for(final Property a : attributeList) {
                if (!_hasElements) {
                  _hasElements = true;
                } else {
                  _builder.appendImmediate(", ", "");
                }
                String _name_1 = a.getName();
                _builder.append(_name_1, "");
                _builder.append("(");
                ValueSpecification _defaultValue = a.getDefaultValue();
                String _stringValue = _defaultValue.stringValue();
                _builder.append(_stringValue, "");
                _builder.append(")");
              }
            }
            _builder.append(" {}");
            _builder.newLineIfNotEmpty();
          }
        }
        _builder.append("\t\t");
      }
    }
    String code = _builder.toString();
    return code.trim();
  }
  
  public static CharSequence generateClassBodyCode(final Classifier classifier) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#define ");
    String _fullName = GenUtils.getFullName(classifier);
    _builder.append(_fullName, "");
    _builder.append("_BODY");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/************************************************************");
    _builder.newLine();
    _builder.append("              ");
    String _name = classifier.getName();
    _builder.append(_name, "              ");
    _builder.append(" class body");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("************************************************************/");
    _builder.newLine();
    _builder.newLine();
    String _CppIncludePreBody = CppIncludeUtil.CppIncludePreBody(classifier);
    _builder.append(_CppIncludePreBody, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("// include associated header file");
    _builder.newLine();
    org.eclipse.uml2.uml.Package _nearestPackage = classifier.getNearestPackage();
    String _fullPath = GenUtils.getFullPath(_nearestPackage);
    String _plus = (_fullPath + "/");
    String _name_1 = classifier.getName();
    String _plus_1 = (_plus + _name_1);
    String _plus_2 = (_plus_1 + ".");
    String _headerSuffix = CppCodeGenUtils.getHeaderSuffix();
    String _plus_3 = (_plus_2 + _headerSuffix);
    String _includeDirective = CppIncludeUtil.includeDirective(_plus_3);
    _builder.append(_includeDirective, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("// Derived includes directives");
    _builder.newLine();
    {
      Iterable<String> _CppClassAllIncludesDeclarationBody = CppClassIncludeClassDeclaration.CppClassAllIncludesDeclarationBody(classifier);
      List<String> _sort = IterableExtensions.<String>sort(_CppClassAllIncludesDeclarationBody);
      for(final String path : _sort) {
        String _includeDirective_1 = CppIncludeUtil.includeDirective(path);
        _builder.append(_includeDirective_1, "");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    String _CppIncludeBody = CppIncludeUtil.CppIncludeBody(classifier);
    _builder.append(_CppIncludeBody, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    String _openNS = CppGenUtils.openNS(classifier);
    _builder.append(_openNS, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    String _CppStaticAttributes = CppAttribute.CppStaticAttributes(classifier);
    _builder.append(_CppStaticAttributes, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    {
      boolean _isTemplate = classifier.isTemplate();
      boolean _not = (!_isTemplate);
      if (_not) {
        CharSequence _CppClassOperationsImplementation = CppClassOperationsImplementation.CppClassOperationsImplementation(classifier, false);
        _builder.append(_CppClassOperationsImplementation, "");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    String _closeNS = CppGenUtils.closeNS(classifier);
    _builder.append(_closeNS, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/************************************************************");
    _builder.newLine();
    _builder.append("              ");
    _builder.append("End of ");
    String _name_2 = classifier.getName();
    _builder.append(_name_2, "              ");
    _builder.append(" class body");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("************************************************************/");
    _builder.newLine();
    return _builder;
  }
}

Back to the top