Skip to main content
summaryrefslogtreecommitdiffstats
blob: 79d1a53e9ad89080435e241b660e54209f0e239a (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
package org.eclipse.papyrus.cpp.codegen.xtend;

import com.google.common.base.Objects;
import java.util.Collection;
import org.eclipse.emf.common.util.EList;
import org.eclipse.papyrus.C_Cpp.ConstInit;
import org.eclipse.papyrus.C_Cpp.Inline;
import org.eclipse.papyrus.C_Cpp.Virtual;
import org.eclipse.papyrus.codegen.base.GenUtils;
import org.eclipse.papyrus.cpp.codegen.Constants;
import org.eclipse.papyrus.cpp.codegen.utils.CppGenUtils;
import org.eclipse.papyrus.cpp.codegen.utils.Modifier;
import org.eclipse.papyrus.cpp.codegen.xtend.CppDocumentation;
import org.eclipse.papyrus.cpp.codegen.xtend.CppParameter;
import org.eclipse.papyrus.cpp.codegen.xtend.CppTemplates;
import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.BehavioredClassifier;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.DataType;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.OpaqueBehavior;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.Parameter;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.profile.standard.Create;
import org.eclipse.uml2.uml.profile.standard.Destroy;
import org.eclipse.uml2.uml.util.UMLUtil;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Conversions;

@SuppressWarnings("all")
public class CppOperations {
  public static CharSequence CppOperationImplementation(final Operation operation) {
    StringConcatenation _builder = new StringConcatenation();
    CharSequence _CppOperationDoc = CppDocumentation.CppOperationDoc(operation);
    _builder.append(_CppOperationDoc, "");
    _builder.newLineIfNotEmpty();
    {
      String _name = operation.getName();
      boolean _equals = Objects.equal(_name, "main");
      if (_equals) {
        String _CppReturnSpec = CppOperations.CppReturnSpec(operation);
        _builder.append(_CppReturnSpec, "");
        String _name_1 = operation.getName();
        _builder.append(_name_1, "");
        _builder.append("(");
        CharSequence _CppOperationParameters = CppParameter.CppOperationParameters(operation, false);
        _builder.append(_CppOperationParameters, "");
        _builder.append(") {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        String _body = GenUtils.getBody(operation, Constants.supportedLanguages);
        _builder.append(_body, "\t");
        _builder.newLineIfNotEmpty();
        _builder.append("} ");
        _builder.newLine();
      } else {
        CharSequence _templateSignature = CppTemplates.templateSignature(operation);
        _builder.append(_templateSignature, "");
        String _InlineTxt = CppOperations.InlineTxt(operation);
        _builder.append(_InlineTxt, "");
        String _CppReturnSpec_1 = CppOperations.CppReturnSpec(operation);
        _builder.append(_CppReturnSpec_1, "");
        EList<Classifier> _featuringClassifiers = operation.getFeaturingClassifiers();
        Classifier _get = _featuringClassifiers.get(0);
        String _name_2 = _get.getName();
        _builder.append(_name_2, "");
        CharSequence _templateShortSignature = CppTemplates.templateShortSignature(operation);
        _builder.append(_templateShortSignature, "");
        _builder.append("::");
        String _destructor = CppOperations.destructor(operation);
        _builder.append(_destructor, "");
        String _name_3 = operation.getName();
        _builder.append(_name_3, "");
        _builder.append("(");
        CharSequence _CppOperationParameters_1 = CppParameter.CppOperationParameters(operation, false);
        _builder.append(_CppOperationParameters_1, "");
        _builder.append(")");
        CharSequence _throwss = CppOperations.throwss(operation);
        _builder.append(_throwss, "");
        String _modCVQualifier = Modifier.modCVQualifier(operation);
        _builder.append(_modCVQualifier, "");
        String _CppConstInit = CppOperations.CppConstInit(operation);
        _builder.append(_CppConstInit, "");
        _builder.append(" {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        String _body_1 = GenUtils.getBody(operation, Constants.supportedLanguages);
        _builder.append(_body_1, "\t");
        _builder.newLineIfNotEmpty();
        _builder.append("}");
        _builder.newLine();
      }
    }
    return _builder;
  }
  
  public static String CppReturnSpec(final Operation operation) {
    String _xifexpression = null;
    boolean _or = false;
    Type _type = operation.getType();
    boolean _equals = Objects.equal(_type, null);
    if (_equals) {
      _or = true;
    } else {
      boolean _isConsOrDestructor = CppOperations.isConsOrDestructor(operation);
      _or = _isConsOrDestructor;
    }
    if (_or) {
      _xifexpression = CppOperations.ConsDestructorOrVoid(operation);
    } else {
      Parameter _returnResult = operation.getReturnResult();
      String _modCVQualifier = Modifier.modCVQualifier(_returnResult);
      String _plus = (_modCVQualifier + " ");
      Type _type_1 = operation.getType();
      String _cppQualifiedName = CppGenUtils.cppQualifiedName(_type_1);
      String _plus_1 = (_plus + _cppQualifiedName);
      Parameter _returnResult_1 = operation.getReturnResult();
      String _modPtr = Modifier.modPtr(_returnResult_1);
      String _plus_2 = (_plus_1 + _modPtr);
      Parameter _returnResult_2 = operation.getReturnResult();
      String _modRef = Modifier.modRef(_returnResult_2);
      String _plus_3 = (_plus_2 + _modRef);
      _xifexpression = (_plus_3 + " ");
    }
    return _xifexpression;
  }
  
  public static CharSequence CppReturnSpec(final Behavior behavior) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Parameter _returnResult = GenUtils.returnResult(behavior);
      boolean _equals = Objects.equal(_returnResult, null);
      if (_equals) {
        _builder.append("void ");
      } else {
        Parameter _returnResult_1 = GenUtils.returnResult(behavior);
        String _modCVQualifier = Modifier.modCVQualifier(_returnResult_1);
        _builder.append(_modCVQualifier, "");
        _builder.append(" ");
        Parameter _returnResult_2 = GenUtils.returnResult(behavior);
        Type _type = _returnResult_2.getType();
        String _cppQualifiedName = CppGenUtils.cppQualifiedName(_type);
        _builder.append(_cppQualifiedName, "");
        Parameter _returnResult_3 = GenUtils.returnResult(behavior);
        String _modPtr = Modifier.modPtr(_returnResult_3);
        _builder.append(_modPtr, "");
        Parameter _returnResult_4 = GenUtils.returnResult(behavior);
        String _modRef = Modifier.modRef(_returnResult_4);
        _builder.append(_modRef, "");
        _builder.append(" ");
      }
    }
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  public static CharSequence throwss(final Operation operation) {
    StringConcatenation _builder = new StringConcatenation();
    {
      EList<Type> _raisedExceptions = operation.getRaisedExceptions();
      int _length = ((Object[])Conversions.unwrapArray(_raisedExceptions, Object.class)).length;
      boolean _greaterThan = (_length > 0);
      if (_greaterThan) {
        _builder.append("throws ");
        {
          EList<Type> _raisedExceptions_1 = operation.getRaisedExceptions();
          boolean _hasElements = false;
          for(final Type re : _raisedExceptions_1) {
            if (!_hasElements) {
              _hasElements = true;
            } else {
              _builder.appendImmediate(",", "");
            }
            String _name = re.getName();
            _builder.append(_name, "");
          }
        }
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  public static String ConsDestructorOrVoid(final Operation operation) {
    String _xifexpression = null;
    boolean _isConsOrDestructor = CppOperations.isConsOrDestructor(operation);
    if (_isConsOrDestructor) {
      _xifexpression = null;
    } else {
      _xifexpression = "void ";
    }
    return _xifexpression;
  }
  
  public static boolean isConsOrDestructor(final Operation operation) {
    boolean _or = false;
    boolean _hasStereotype = GenUtils.hasStereotype(operation, Create.class);
    if (_hasStereotype) {
      _or = true;
    } else {
      boolean _hasStereotype_1 = GenUtils.hasStereotype(operation, Destroy.class);
      _or = _hasStereotype_1;
    }
    return _or;
  }
  
  public static String CppConstInit(final Operation operation) {
    String _xifexpression = null;
    boolean _and = false;
    boolean _hasStereotype = GenUtils.hasStereotype(operation, ConstInit.class);
    if (!_hasStereotype) {
      _and = false;
    } else {
      boolean _hasStereotype_1 = GenUtils.hasStereotype(operation, Create.class);
      _and = _hasStereotype_1;
    }
    if (_and) {
      ConstInit _stereotypeApplication = UMLUtil.<ConstInit>getStereotypeApplication(operation, ConstInit.class);
      _xifexpression = ((ConstInit) _stereotypeApplication).getInitialisation();
    }
    return _xifexpression;
  }
  
  public static Collection<Operation> getOwnedOperations(final Classifier cl) {
    Collection<Operation> _xblockexpression = null;
    {
      final EList<Operation> operations = CppOperations.getOwnedOperationsWNull(cl);
      Collection<Operation> _xifexpression = null;
      boolean _equals = Objects.equal(operations, null);
      if (_equals) {
        _xifexpression = CollectionLiterals.<Operation>emptySet();
      } else {
        _xifexpression = operations;
      }
      _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
  }
  
  public static EList<Operation> getOwnedOperationsWNull(final Classifier cl) {
    EList<Operation> _xifexpression = null;
    if ((cl instanceof org.eclipse.uml2.uml.Class)) {
      _xifexpression = ((org.eclipse.uml2.uml.Class) cl).getOwnedOperations();
    } else {
      EList<Operation> _xifexpression_1 = null;
      if ((cl instanceof DataType)) {
        _xifexpression_1 = ((DataType) cl).getOwnedOperations();
      } else {
        EList<Operation> _xifexpression_2 = null;
        if ((cl instanceof Interface)) {
          _xifexpression_2 = ((Interface) cl).getOwnedOperations();
        } else {
          _xifexpression_2 = null;
        }
        _xifexpression_1 = _xifexpression_2;
      }
      _xifexpression = _xifexpression_1;
    }
    return _xifexpression;
  }
  
  public static CharSequence CppBehaviorImplementation(final OpaqueBehavior behavior) {
    StringConcatenation _builder = new StringConcatenation();
    CharSequence _CppBehaviorDoc = CppDocumentation.CppBehaviorDoc(behavior);
    _builder.append(_CppBehaviorDoc, "");
    _builder.newLineIfNotEmpty();
    CharSequence _CppReturnSpec = CppOperations.CppReturnSpec(behavior);
    _builder.append(_CppReturnSpec, "");
    BehavioredClassifier _context = behavior.getContext();
    String _name = _context.getName();
    _builder.append(_name, "");
    _builder.append("::");
    String _name_1 = behavior.getName();
    _builder.append(_name_1, "");
    _builder.append("(");
    CharSequence _CppBehaviorParameters = CppParameter.CppBehaviorParameters(behavior, false);
    _builder.append(_CppBehaviorParameters, "");
    _builder.append(")");
    String _modCVQualifier = Modifier.modCVQualifier(behavior);
    _builder.append(_modCVQualifier, "");
    _builder.append(" {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    String _bodyFromOB = GenUtils.getBodyFromOB(behavior, Constants.supportedLanguages);
    _builder.append(_bodyFromOB, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
  
  public static CharSequence CppOperationDeclaration(final Operation operation) {
    StringConcatenation _builder = new StringConcatenation();
    CharSequence _CppOperationDoc = CppDocumentation.CppOperationDoc(operation);
    _builder.append(_CppOperationDoc, "");
    _builder.newLineIfNotEmpty();
    String _InlineTxt = CppOperations.InlineTxt(operation);
    _builder.append(_InlineTxt, "");
    String _virtualTxt = CppOperations.virtualTxt(operation);
    _builder.append(_virtualTxt, "");
    String _staticTxt = CppOperations.staticTxt(operation);
    _builder.append(_staticTxt, "");
    String _CppReturnSpec = CppOperations.CppReturnSpec(operation);
    _builder.append(_CppReturnSpec, "");
    String _destructor = CppOperations.destructor(operation);
    _builder.append(_destructor, "");
    String _name = operation.getName();
    _builder.append(_name, "");
    _builder.append("(");
    CharSequence _CppOperationParameters = CppParameter.CppOperationParameters(operation, true);
    _builder.append(_CppOperationParameters, "");
    _builder.append(")");
    String _modCVQualifier = Modifier.modCVQualifier(operation);
    _builder.append(_modCVQualifier, "");
    String _virtualSuffix = CppOperations.virtualSuffix(operation);
    _builder.append(_virtualSuffix, "");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  public static String InlineTxt(final Element element) {
    String _xifexpression = null;
    boolean _hasStereotype = GenUtils.hasStereotype(element, Inline.class);
    if (_hasStereotype) {
      _xifexpression = "inline ";
    }
    return _xifexpression;
  }
  
  public static String virtualTxt(final Operation operation) {
    String _xifexpression = null;
    boolean _or = false;
    boolean _or_1 = false;
    Interface _interface = operation.getInterface();
    boolean _notEquals = (!Objects.equal(_interface, null));
    if (_notEquals) {
      _or_1 = true;
    } else {
      boolean _isAbstract = operation.isAbstract();
      _or_1 = _isAbstract;
    }
    if (_or_1) {
      _or = true;
    } else {
      boolean _hasStereotype = GenUtils.hasStereotype(operation, Virtual.class);
      _or = _hasStereotype;
    }
    if (_or) {
      _xifexpression = "virtual ";
    }
    return _xifexpression;
  }
  
  public static String staticTxt(final Operation operation) {
    String _xifexpression = null;
    boolean _isStatic = operation.isStatic();
    if (_isStatic) {
      _xifexpression = "static ";
    }
    return _xifexpression;
  }
  
  public static String destructor(final Operation operation) {
    String _xifexpression = null;
    boolean _and = false;
    boolean _hasStereotype = GenUtils.hasStereotype(operation, Destroy.class);
    if (!_hasStereotype) {
      _and = false;
    } else {
      String _name = operation.getName();
      boolean _startsWith = _name.startsWith("~");
      boolean _not = (!_startsWith);
      _and = _not;
    }
    if (_and) {
      _xifexpression = "~";
    } else {
      _xifexpression = "";
    }
    return _xifexpression;
  }
  
  public static String virtualSuffix(final Operation operation) {
    String _xifexpression = null;
    boolean _or = false;
    Interface _interface = operation.getInterface();
    boolean _notEquals = (!Objects.equal(_interface, null));
    if (_notEquals) {
      _or = true;
    } else {
      boolean _isAbstract = operation.isAbstract();
      _or = _isAbstract;
    }
    if (_or) {
      _xifexpression = " = 0";
    }
    return _xifexpression;
  }
  
  public static CharSequence CppBehaviorDeclaration(final Behavior behavior) {
    StringConcatenation _builder = new StringConcatenation();
    CharSequence _CppBehaviorDoc = CppDocumentation.CppBehaviorDoc(behavior);
    _builder.append(_CppBehaviorDoc, "");
    _builder.newLineIfNotEmpty();
    String _InlineTxt = CppOperations.InlineTxt(behavior);
    _builder.append(_InlineTxt, "");
    CharSequence _CppReturnSpec = CppOperations.CppReturnSpec(behavior);
    _builder.append(_CppReturnSpec, "");
    String _name = behavior.getName();
    _builder.append(_name, "");
    _builder.append("(");
    CharSequence _CppBehaviorParameters = CppParameter.CppBehaviorParameters(behavior, true);
    _builder.append(_CppBehaviorParameters, "");
    _builder.append(")");
    String _modCVQualifier = Modifier.modCVQualifier(behavior);
    _builder.append(_modCVQualifier, "");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
}

Back to the top