Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Cpp
Commits
cf4214c0
Commit
cf4214c0
authored
Jan 16, 2021
by
Malte Heithoff
Browse files
Constructor Support
parent
ed087875
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/generator/cpp/EMAMBluePrintCPP.java
View file @
cf4214c0
...
...
@@ -154,4 +154,12 @@ public class EMAMBluePrintCPP extends EMAMBluePrint {
public
void
addInstructionToMethod
(
Instruction
instruction
,
String
methodName
)
{
getMethod
(
methodName
).
get
().
addInstruction
(
instruction
);
}
public
void
setConstructor
(
Method
constructor
)
{
this
.
constructor
=
constructor
;
}
public
Method
getConstructor
()
{
return
constructor
;
}
}
src/main/java/de/monticore/lang/monticar/generator/cpp/LanguageUnitCPP.java
View file @
cf4214c0
...
...
@@ -185,6 +185,9 @@ public class LanguageUnitCPP extends LanguageUnit {
resultString
+=
generateHeaderGenerateVariable
(
v
);
}
if
(
bluePrint
.
getConstructor
()
!=
null
)
resultString
+=
generateConstructor
(
bluePrint
.
getConstructor
(),
bluePrint
);
//generate methods
for
(
Method
method
:
bluePrint
.
getMethods
())
{
if
(!
method
.
isPublic
()){
...
...
@@ -204,6 +207,29 @@ public class LanguageUnitCPP extends LanguageUnit {
return
resultString
;
}
private
String
generateConstructor
(
Method
constructor
,
EMAMBluePrintCPP
bluePrint
)
{
int
counter
=
0
;
String
resultString
=
constructor
.
getName
()
+
"("
;
for
(
Variable
param
:
constructor
.
getParameters
())
{
if
(
counter
==
0
)
{
++
counter
;
resultString
+=
param
.
getVariableType
().
getTypeNameTargetLanguage
()
+
" "
+
param
.
getNameTargetLanguageFormat
();
}
else
{
resultString
+=
", "
+
param
.
getVariableType
().
getTypeNameTargetLanguage
()
+
" "
+
param
.
getNameTargetLanguageFormat
();
}
if
(
param
.
isArray
())
resultString
+=
"["
+
param
.
getArraySize
()
+
"]"
;
}
resultString
+=
") :\n"
;
//TODO add semicolon when using source files
for
(
Instruction
instruction
:
constructor
.
getInstructions
())
resultString
+=
instruction
.
getTargetLanguageInstruction
();
resultString
+=
"{}\n"
;
return
resultString
;
}
protected
String
generateHeaderGenerateVariable
(
Variable
v
){
if
(
v
instanceof
VariablePortValueChecker
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment