Skip to content

Commit

Permalink
Added implementation for active methods, traits, RTCPP generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Svetlana154 committed Aug 25, 2021
1 parent 7fa4725 commit 0e2ae92
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 5 deletions.
4 changes: 4 additions & 0 deletions UmpleToRTCpp/UmpleTLTemplates/Associations.ump
Expand Up @@ -93,10 +93,14 @@ class GenAssociation{
Boolean removeNullifyInternally= {_removeNullifyInternally()}

0..1 -- * GenComment comments sorted {priority};
0..1 -- * GenRequirement requirements sorted {priority};
depend java.util.stream.Collectors;
String emitComments(){
return this.getComments().stream().map(GenComment::getBody).collect(Collectors.joining(NL));
}
String emitRequirements(){
return this.getRequirements().stream().map(GenRequirement::getBody).collect(Collectors.joining(NL));
}

lazy String value;
lazy Boolean constant;
Expand Down
9 changes: 9 additions & 0 deletions UmpleToRTCpp/UmpleTLTemplates/Attributes.ump
Expand Up @@ -516,6 +516,7 @@ class GenField{
Boolean parameterized= false;
Boolean generatable= true;
0..1 -- * GenComment comments sorted {priority};
0..1 -- * GenRequirement requirements sorted {priority};

assignValueCallT <<!this-><<=name>>= <<=_value>>;!>>
emit assignValueCall(String _value)(assignValueCallT);
Expand Down Expand Up @@ -604,6 +605,10 @@ declarationT <<!<<#for(GenComment comment: getComments()){
String body= comment.getBody();
if(!body.isEmpty()){
#>><<=body>><<=NL>><<#}
}#>><<#for(GenRequirement requirement: getRequirements()){
String body= requirement.getBody();
if(!body.isEmpty()){
#>><<=body>><<=NL>><<#}
}#>><<#if(isStatic){#>>static <<#}#>><<#if(isConstant){#>>const <<#}#>><<=getNormalizedType()>> <<=name>><<=initializerString()>>;!>>

emit declaration()(declarationT);
Expand All @@ -612,6 +617,10 @@ implementationT <<!<<#for(GenComment comment: getComments()){
String body= comment.getBody();
if(!body.isEmpty()){
#>><<=body>><<=NL>><<#}
}#>><<#for(GenRequirement requirement: getRequirements()){
String body= requirement.getBody();
if(!body.isEmpty()){
#>><<=body>><<=NL>><<#}
}#>><<#if(isConstant){#>>const <<#}#>><<=getNormalizedType()>> <<=getGenClass().getName()>>::<<=name>>= <<=value>>;!>>

emit implementation()(implementationT);
Expand Down
2 changes: 1 addition & 1 deletion UmpleToRTCpp/UmpleTLTemplates/Content.ump
Expand Up @@ -130,7 +130,7 @@ class GenClass{
<<=headerIncludes>><<=libraryIncludes
>><<=incompleteDeclarations>><<=namespaceOpening()
>><<=enumerations>><<=selfIncompleteDeclarations
>><<=emitComments()>>class <<=getName()>><<#if(!classDeclarations.isEmpty())#>> : <<=classDeclarations>>{
>><<=emitComments()>><<=emitRequirements()>>class <<=getName()>><<#if(!classDeclarations.isEmpty())#>> : <<=classDeclarations>>{
<<=StringUtil.indent(visibilityBasedContents, 1)>>
};
<<=predefinitions>><<=namespaceClosing()>>
Expand Down
34 changes: 31 additions & 3 deletions UmpleToRTCpp/UmpleTLTemplates/Core.ump
Expand Up @@ -557,6 +557,7 @@ class GenClass{
0..1 -- * GenMethod methods sorted {priority};
0..1 -- * GenField fields sorted {priority};
0..1 -- * GenComment comments sorted {priority};
0..1 -- * GenRequirement requirements sorted {priority};
0..1 genDependClass -- * GenDepend dependencies sorted {priority};
0..1 genClassInterface -- * GenInterface interfaces sorted {priority};

Expand Down Expand Up @@ -721,6 +722,13 @@ class GenClass{
}
return results;
}
String emitRequirements(){
String results= getRequirements().stream().map(GenRequirement::getBody).collect(Collectors.joining(NL));
if(!results.isEmpty()){
results+= NL;
}
return results;
}

0..1 -- * MemberInitializer memberInitializers sorted {priority};
0..1 genHeaderDependClass -- * GenHeaderDepend headerDependencies sorted {priority};
Expand Down Expand Up @@ -836,6 +844,11 @@ introCommentT <<!//------------------------
//------------------------!>>
emit introComment(String comment)(introCommentT);

introRequirementT <<!//------------------------
//<<=requirement.toUpperCase()>>
//------------------------!>>
emit introRequirement(String requirement)(introRequirementT);


after constructor{
GenGroup globalGroup = new GenGroup(GenClass.GLOBAL_GROUP);
Expand Down Expand Up @@ -924,6 +937,7 @@ class GenMethod{
//0..1 -- * GenStereotype stereotypes;
* -- * GenMethodParameter parameters; //A parameter can be owned by multiple methods in order to allow for one update in all places
0..1 -- * GenComment comment sorted {priority};
0..1 -- * GenRequirement requirement sorted {priority};
* -- * GenField relatedFields;

0..1 -- * GenBody body sorted {priority};
Expand Down Expand Up @@ -1000,6 +1014,15 @@ class GenMethod{

return string+ NL;
}

String requirementString(){
String string= this.getRequirement().stream().map(GenRequirement::getBody).collect(Collectors.joining(NL));
if(string.isEmpty()){
return string;
}

return string+ NL;
}

String bodyString(List<String> bodies){
if (numberOfBody() == 1 && !hasConstraintConditions()) {
Expand Down Expand Up @@ -1097,13 +1120,13 @@ class GenMethod{
indentT <<!<<=content>>!>>
emit indent(String content)(indentT);

declarationT <<!<<=commentString()>><<#if(isInline){#>>inline <<#
declarationT <<!<<=commentString()>><<=requirementString()>><<#if(isInline){#>>inline <<#
}#>><<#if(isFriend){#>>friend <<#}#>><<#if(isStatic)#>>static <<#if(_isVirtual){#>>virtual <<#}#>><<#if(returnType!= null && !returnType.isEmpty()){#>><<=getNormalizedReturnType()>> <<#}#>><<=name>>(<<=parameters()>>)<<#if(getIsConstant()){#>> const<<#
}if(_isPure){#>> = 0;<<#
}else if(isHeader){#>>{
<<=_indent(2, new StringBuilder(), bodyString(new ArrayList<String>()))>>
}<<#}else{#>>;<<#}#>>!>>
implementationT <<!<<=commentString()>><<#if(isInline){#>>inline <<#}#>><<#if(returnType!= null && !returnType.isEmpty()){#>><<=getNormalizedReturnType()>> <<#}#>><<#
implementationT <<!<<=commentString()>><<=requirementString()>><<#if(isInline){#>>inline <<#}#>><<#if(returnType!= null && !returnType.isEmpty()){#>><<=getNormalizedReturnType()>> <<#}#>><<#
if(!Visibilities.GLOBAL.equals(getVisibility()) && owner!= null && !owner.isEmpty()){#>><<=owner>>::<<#}#>><<=name>>(<<=parameters()>>)<<#if(getIsConstant()){#>> const<<#}#>><<=getInitializerCall()>>{
<<=_indent(2, new StringBuilder(), bodyString(new ArrayList<String>()))>>
}!>>
Expand Down Expand Up @@ -1314,6 +1337,10 @@ class GenComment{
isA AbstractGenBody;
}

class GenRequirement{
isA AbstractGenBody;
}

class UniqueGenBody{
isA GenBody;
id;
Expand Down Expand Up @@ -1422,11 +1449,12 @@ class GenStruct{
Integer priority= 0;
0..1 -- * GenField fields;
0..1 -- * GenComment comments sorted {priority};
0..1 -- * GenRequirement requirements sorted {priority};

indentT <<!<<=content>>!>>
emit indent(String content)(indentT);

declarationT <<!<<#if(hasComments()){for(GenComment comment: getComments()){#>><<=comment.getBody()>><<=NL>><<#}}#>>struct <<=name>>{
declarationT <<!<<#if(hasComments()){for(GenComment comment: getComments()){#>><<=comment.getBody()>><<=NL>><<#}}#>><<#if(hasRequirements()){for(GenRequirement requirement: getRequirements()){#>><<=requirement.getBody()>><<=NL>><<#}}#>>struct <<=name>>{
<<#for(GenField field: getFields()){#>>
<<=_indent(2, new StringBuilder(), field.declaration())>>
<<#}#>>
Expand Down
Expand Up @@ -33,6 +33,7 @@
import cruise.umple.compiler.CodeBlock;
import cruise.umple.compiler.CodeInjection;
import cruise.umple.compiler.Comment;
import cruise.umple.compiler.Requirement;
import cruise.umple.compiler.ConstraintAssociation;
import cruise.umple.compiler.ConstraintAttribute;
import cruise.umple.compiler.ConstraintLiteral;
Expand Down
Expand Up @@ -34,6 +34,7 @@
import cruise.umple.compiler.BasicConstraint;
import cruise.umple.compiler.CodeBlock;
import cruise.umple.compiler.Comment;
import cruise.umple.compiler.Requirement;
import cruise.umple.compiler.ConstraintAttribute;
import cruise.umple.compiler.ConstraintOperator;
import cruise.umple.compiler.ConstraintPort;
Expand Down Expand Up @@ -551,6 +552,10 @@ public static List<Object> getActiveMthodCodeBody(@GenerationBaseElement ActiveM
if(comment!= null&& !visited.contains(comment)){
visited.add(comment);
}
Requirement requirement = activeDirectionHandlerBody.getRequirement();
if(requirement!= null&& !visited.contains(requirement)){
visited.add(requirement);
}

CodeBlock codeblock = activeDirectionHandlerBody.getCodeblock();
if(codeblock!= null&& !visited.contains(codeblock)){
Expand Down
Expand Up @@ -27,6 +27,7 @@
import cruise.umple.compiler.AssociationEnd;
import cruise.umple.compiler.AssociationVariable;
import cruise.umple.compiler.Comment;
import cruise.umple.compiler.Requirement;
import cruise.umple.compiler.UmpleClass;
import cruise.umple.compiler.UmpleElement;
import cruise.umple.compiler.UmpleModel;
Expand Down Expand Up @@ -117,5 +118,13 @@ public static List<String> getCommentStrings(List<Comment> comments){
}
return commentStrings;
}

public static List<String> getRequirementStrings(List<Requirement> reqs){
List<String> reqStrings= new ArrayList<String>(reqs.size());
for(Requirement r: reqs){
reqStrings.add(r.getStatement());
}
return reqStrings;
}

}
1 change: 1 addition & 0 deletions cruise.umple/src/class/Umple_CodeMethod.ump
Expand Up @@ -83,6 +83,7 @@ class Method
this.methodBody = another.getMethodBody();
}
this. comments = another.getComments();
this. requirements = another.getRequirements();
}

public boolean getExistsInLanguage(String lang)
Expand Down
4 changes: 3 additions & 1 deletion cruise.umple/src/strcture/Structure.ump
Expand Up @@ -143,6 +143,7 @@ class ActiveMethod
0..1 -> * Monitor watchList;
1 -> 0..* MethodParameter;
1 -> * Comment;
1 -> * Requirement;
ActiveDirectionHandler methodBody;
ActiveMethod inverseMethodBody;
}
Expand All @@ -162,9 +163,10 @@ class ActiveDirectionHandler
class ActiveDirectionHandlerBody {
depend cruise.umple.parser.Position;

bodyType { CODE{} TRIGGER{} COMMENT{} }
bodyType { CODE{} TRIGGER{} COMMENT{} REQUIREMENT{}}
lazy CodeBlock codeblock;
lazy Comment comment;
lazy Requirement requirement;
lazy Trigger trigger;

lazy Position position;
Expand Down
30 changes: 30 additions & 0 deletions cruise.umple/src/strcture/UmpleInternalParser_CodeStructure.ump
Expand Up @@ -68,6 +68,24 @@ class CompositeStructureTokenAnalyzer {

return cmtList;
}

public List<Requirement> analyzeImplementMethodReq(Token t){
System.out.println("analyzing impl3");
List<Requirement> reqList = new ArrayList<Requirement>();
int counter=0;

if (t.hasSubTokens()){
for (Token sub : t.getSubTokens()){
if (!sub.getValue().equals("STATIC") && parser.getModel().getAllRequirements().containsKey(sub.getValue())){
reqList.add(parser.getModel().getAllRequirements().get(sub.getValue()));
}
else counter++;
}
}

System.out.println(" ======= done with imple req3");
return reqList;
}

public void analyzePortClassDefinition(Token token){
if(token!=null) {
Expand Down Expand Up @@ -393,6 +411,18 @@ class CompositeStructureTokenAnalyzer {
}
}
}
else if (methodToken.is("reqImplementation")){
List<Requirement> reqList = analyzeImplementMethodReq(methodToken);
if(reqList!= null && reqList.size() > 0) {
for(Requirement req : reqList) {
ActiveDirectionHandlerBody abh = new ActiveDirectionHandlerBody();
abh.setBodyType(BodyType.REQUIREMENT);
abh.setRequirement(req);
aMethod.getMethodBody().addActiveDirectionHandlerBody(abh);
}
}

}
else if (methodToken.is("code"))
{
ActiveDirectionHandlerBody abh = new ActiveDirectionHandlerBody();
Expand Down
32 changes: 32 additions & 0 deletions cruise.umple/src/trait/UmpleInternalParser_CodeTrait.ump
Expand Up @@ -87,6 +87,12 @@ class UmpleInternalParser
regularCommentCountEnd++;
}

for (Requirement c : lastRequirements)
{
aTrait.addRequirementAt(c,regularCommentCountEnd);
regularCommentCountEnd++;
}

// Add special position comment at the end if @outputumplesource had been
// detected earlier in a comment
if(outputUmpleSource == true) {
Expand Down Expand Up @@ -205,6 +211,9 @@ class UmpleInternalParser

// Only need to clear comments if there actually was comments.
boolean shouldConsumeComment = lastComments.size() > 0;

// Only need to clear requirements if there actually was requirements.
boolean shouldConsumeRequirement = lastRequirements.size() > 0;

// Determine what the current token is primarily, and based on that the analysis procedure is determined.
if (token.isStatic("//") || token.isStatic("/*") || token.isStatic("*/"))
Expand Down Expand Up @@ -239,6 +248,11 @@ class UmpleInternalParser
analyzeMultilineComment(token);
shouldConsumeComment = false;
}
else if (token.is("reqImplementation"))
{
analyzeImplementReq(token);
shouldConsumeRequirement = isReqAddedToLast(token);
}
// TODO Under development

else if (token.is("traitDefinition"))
Expand Down Expand Up @@ -303,6 +317,10 @@ class UmpleInternalParser
{
lastComments.clear();
}
if (shouldConsumeRequirement)
{
lastRequirements.clear();
}
}

//---------------------------------end----------------------------------------
Expand Down Expand Up @@ -488,6 +506,11 @@ class UmpleInternalParser
attribute.addComment(c);
}

for (Requirement c : lastRequirements)
{
attribute.addRequirement(c);
}

// set the last attribute made to be attribute, clear lastassoc
lastattr = attribute;
lastassoc = null;
Expand Down Expand Up @@ -574,6 +597,11 @@ mixset Association {
{
yourAs.addComment(c);
}

for (Requirement c : lastRequirements)
{
yourAs.addRequirement(c);
}

// set last association made to be yourAs. clear lastattr.
lastassoc = yourAs;
Expand Down Expand Up @@ -1108,6 +1136,10 @@ mixset Association {
inClass.addComment(aComment);
}

for(Requirement aRequirement : inTrait.getRequirements()) {
inClass.addRequirement(aRequirement);
}

//set the dependens
for(Depend aDepend : inTrait.getDepends()) {
inClass.addDepend(aDepend);
Expand Down
1 change: 1 addition & 0 deletions cruise.umple/src/trait/Umple_Code_Trait.ump
Expand Up @@ -366,6 +366,7 @@ class Attribute {
codeblock = null;
isLazy = false;
comments = new ArrayList<Comment>();
requirements = new ArrayList<Requirement>();
boolean didAddUmpleTrait = setUmpleTrait(aUmpleTrait);
if (!didAddUmpleTrait)
{
Expand Down

0 comments on commit 0e2ae92

Please sign in to comment.