blob: b7761341a777c963b37f5f2ebc44d1ae20b4c541 (
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
|
<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
skeleton = "../../generator.skeleton"
imports = "org.eclipse.uml2.uml.* org.eclipse.papyrus.cpp.codegen.jet.doc.* Cpp.* org.eclipse.papyrus.cpp.codegen.StdStereo org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
class = "CppOperationImplementation"
%>
<%
//////////////////////////////////////////////////////////////////////////////////////////
// Java preparation
//////////////////////////////////////////////////////////////////////////////////////////
// Retrieve the Operation
Operation currentOperation = (Operation) argument;
String body = "";
String className = "";
String operationName = currentOperation.getName();
String opParameters = "";
String returnTypeName = "void";
String isInline = "";
String isConst = "";
String constInit = "";
String opDoc = "";
// Doc for the template
CppOperationDoc jDoc = new CppOperationDoc();
opDoc = jDoc.generate(currentOperation);
// Retrieve class name. Operation may belong to a class or datatype, thus use
// generic getOwner function
Element opOwner = currentOperation.getOwner();
className = (opOwner instanceof NamedElement) ? ((NamedElement) opOwner).getName() : "";
// Retrieve body content
body = GenUtils.getBody (currentOperation, "C/C++");
// Prepare return type
CppOperationReturnType jetRT = new CppOperationReturnType();
returnTypeName = jetRT.generate(currentOperation);
// Creator / Destructor: use function within StdStereo
if (StdStereo.isApplied(currentOperation, StdStereo.create)) {
returnTypeName = "";
}
if (StdStereo.isApplied(currentOperation, StdStereo.destroy)) {
returnTypeName = "";
operationName = "~"+operationName;
}
// If is inline operation
if (GenUtils.hasStereotype(currentOperation, CppInline.class)) {
isInline = "inline ";
}
// Const op
if (GenUtils.hasStereotype(currentOperation, CppConst.class)) {
isConst = " const";
}
// Constructor init list
CppConstInit cppConstInit = GenUtils.getApplication(currentOperation, CppConstInit.class);
if ((cppConstInit != null)
&& StdStereo.isApplied(currentOperation, StdStereo.create)) {
constInit = " : " + cppConstInit.getInitialisation();
}
// Prepare parameters
CppOperationParametersWithoutDefaultValue jetParams = new CppOperationParametersWithoutDefaultValue();
opParameters = jetParams.generate(currentOperation);
//////////////////////////////////////////////////////////////////////////////////////////
// The following part contains the template two cases main operation or classical
//////////////////////////////////////////////////////////////////////////////////////////
// main
if (operationName.equals("main")) {
//////////////////////////////////////////////////////////////////////////////////////////%>
<%= opDoc %>
<%= returnTypeName %> <%= operationName %> (<%= opParameters %>) {
<%= body %>
}
<%//////////////////////////////////////////////////////////////////////////////////////////
}
else {
//////////////////////////////////////////////////////////////////////////////////////////%>
<%= opDoc %>
<%= isInline %><%= returnTypeName %> <%= className %>::<%= operationName %>(<%= opParameters %>)<%= isConst %><%= constInit %> {
<%= body %>
}
<%//////////////////////////////////////////////////////////////////////////////////////////
}
//////////////////////////////////////////////////////////////////////////////////////////%>
|