Skip to content
Snippets Groups Projects
Commit e517870b authored by Andrea Enrici's avatar Andrea Enrici
Browse files

advanced in parsing SDs. missing more complete mathematical formulas for actions

parent 83ff91b5
No related branches found
No related tags found
No related merge requests found
...@@ -79,8 +79,8 @@ SKIP: ...@@ -79,8 +79,8 @@ SKIP:
/* Reserved keywords */ /* Reserved keywords */
TOKEN: TOKEN:
{ {
< BOOLTYPE: "BOOL" > < BOOL_TYPE: "bool" >
| < INTTYPE: "INT" > | < INT_TYPE: "int" >
| < START_KW: "START" > | < START_KW: "START" >
| < ENDBLOCK: "END" > | < ENDBLOCK: "END" >
| < MAINBLOCK: "MAIN" > | < MAINBLOCK: "MAIN" >
...@@ -88,8 +88,8 @@ TOKEN: ...@@ -88,8 +88,8 @@ TOKEN:
| < ACTIVITY_DIAGRAM: "ACTIVITY" > | < ACTIVITY_DIAGRAM: "ACTIVITY" >
| < SEQUENCE_DIAGRAM: "SEQUENCE" > | < SEQUENCE_DIAGRAM: "SEQUENCE" >
| < INCLUDE: "INCLUDE" > | < INCLUDE: "INCLUDE" >
| < TRUECONST: "TRUE" > | < TRUECONST: "TRUE" | "true" >
| < FALSECONST: "FALSE" > | < FALSECONST: "FALSE" | "false" >
| < STORAGE_KW: "STORAGE" > | < STORAGE_KW: "STORAGE" >
| < CONTROLLER_KW: "CONTROLLER" > | < CONTROLLER_KW: "CONTROLLER" >
| < TRANSFER_KW: "TRANSFER" > | < TRANSFER_KW: "TRANSFER" >
...@@ -164,23 +164,34 @@ ASTStartSymbol StartSymbol(): /* The left hand side of this production is called ...@@ -164,23 +164,34 @@ ASTStartSymbol StartSymbol(): /* The left hand side of this production is called
int i; int i;
String space = " "; String space = " ";
String undefinedDiagStringList = ""; String undefinedDiagStringList = "";
ArrayList<String> undefinedADList; TMLCP mainCP = new TMLCP();
ArrayList<String> undefinedSDList; TMLCPSequenceDiagram seqDiag;
ArrayList<TMLAttribute> attributeList;
} }
{ {
/*( IncludeFiles() )* attributeList = SequenceDiagramAttributesDeclaration()
( MappingList() )*
CommunicationPattern() { TraceManager.addDev( "#################" );
( ActivityDiagram() ( ActivityDiagram() )* ( SequenceDiagram() )+ | ( SequenceDiagram() )+ )*/ for( TMLAttribute attr: attributeList ) {
TraceManager.addDev( attr.toString() );
TraceManager.addDev( "#################" );
}
}
( seqDiag = SequenceDiagram( attributeList ) { mainCP.addCPSequenceDiagram( seqDiag ); } )+
// One or more attribute declaration followed by the declaration of the body of the Sequence Diagrams
( SequenceDiagramAttributeDeclaration() )+
( SequenceDiagram() )+ | ( SequenceDiagram() )+
<EOF> /* Force the parser to reach EOF */ <EOF> /* Force the parser to reach EOF */
{ {
//Must fill the Elements of each TMLCPActivityDiagram with the correct references to CPs and SDs that could not be done before //Must fill the Elements of each TMLCPActivityDiagram with the correct references to CPs and SDs that could not be done before
//encapsulate everything in one method as I do not know the type of the diagrams whose references where missing //encapsulate everything in one method as I do not know the type of the diagrams whose references where missing
topCP.correctReferences(); //topCP.correctReferences();
ArrayList<TMLCPSequenceDiagram> sdList = mainCP.getCPSequenceDiagrams();
TraceManager.addDev( "***************" );
for( TMLCPSequenceDiagram diag: sdList ) {
TraceManager.addDev( diag.toString() );
TraceManager.addDev( "***************" );
}
return jjtThis; return jjtThis;
} }
} }
...@@ -204,57 +215,110 @@ void MappingList(): ...@@ -204,57 +215,110 @@ void MappingList():
Sequence Diagram Section Sequence Diagram Section
********************************************************************************************************************************/ ********************************************************************************************************************************/
void SequenceDiagramAttributeDeclaration(): ArrayList<TMLAttribute> SequenceDiagramAttributesDeclaration():
{ {
String name; String instanceName, attributeName, attributeType;
Token t, t1;
ArrayList<TMLAttribute> attributeList = new ArrayList<TMLAttribute>();
} }
{ {
name = ID() ( instanceName = ID() "." attributeName = ID() ":" ( t = <BOOL_TYPE> | t = <INT_TYPE> )
<ASSIGNMENT> ( t1 = <IDENTIFIER> | t1 = <INTEGER_LITERAL> | t1 = <FALSECONST> | t1 = <TRUECONST> )
{
if( t.image.equals("int") ) {
attributeList.add( new TMLAttribute( attributeName, instanceName, new TMLType ( TMLType.NATURAL ), t1.image ) );
}
else if( t.image.equals("bool") ) {
attributeList.add ( new TMLAttribute( attributeName, instanceName, new TMLType( TMLType.BOOLEAN ), t1.image ) );
}
}
)*
{ return attributeList; }
} }
// A SD is a list of instances. Each Instance is composed of messages or actions. // A SD is a list of instances. Each Instance is composed of messages or actions.
void SequenceDiagram(): TMLCPSequenceDiagram SequenceDiagram( ArrayList<TMLAttribute> attributeList ):
{ {
String name; String diagramName;
ArrayList<TMLSDInstance> instancesList = new ArrayList<TMLSDInstance>(); TMLSDInstance instance;
} }
{ {
<SEQUENCE_DIAGRAM> name = ID() <SEQUENCE_DIAGRAM> diagramName = ID()
{ {
TMLCPSequenceDiagram currentSD = new TMLCPSequenceDiagram( name, new Object() ); TMLCPSequenceDiagram seqDiag = new TMLCPSequenceDiagram( diagramName );
} }
( SequenceDiagramInstance() )+ (
instance = SequenceDiagramInstance( attributeList )
{ seqDiag.addInstance( instance ); }
)+
<ENDBLOCK> <ENDBLOCK>
{ return seqDiag; }
} }
void SequenceDiagramInstance(): TMLSDInstance SequenceDiagramInstance( ArrayList<TMLAttribute> attributeList ):
{ {
String instanceName, type; String instanceName, type, senderName, receiverName, messageName;
Token t;
TMLSDAction action; TMLSDAction action;
TMLSDMessage message;
ArrayList<String> params = new ArrayList<String>();
} }
{ {
type = ID() instanceName = ID() ( t = <TRANSFER_KW> | t = <STORAGE_KW> | t = <CONTROLLER_KW> ) instanceName = ID()
( Message() | action = Action( instanceName ) )+ {
// addActionFromParser(), addMessageFromParser() TMLSDInstance instance = new TMLSDInstance( instanceName, t.image );
for( TMLAttribute attr: attributeList ) {
if( instanceName.equals( attr.getInstanceName() ) ) {
//TraceManager.addDev( "Adding attribute " attr.toString() + " to instance " + instanceName );
instance.addAttribute( attr );
}
}
}
( <RCV_MSG_KW> senderName = ID() ":" messageName = ID() params = MessageParameters()
{ message = new TMLSDMessage( messageName, senderName, instanceName, params );
instance.addMessageFromParser( message, TMLSDEvent.RECEIVE_MESSAGE_EVENT ); }
|
<SND_MSG_KW> receiverName = ID() ":" messageName = ID() params = MessageParameters()
{ message = new TMLSDMessage( messageName, instanceName, receiverName, params );
instance.addMessageFromParser( message, TMLSDEvent.SEND_MESSAGE_EVENT ); }
|
action = Action( instanceName )
{ instance.addActionFromParser( action ); }
)+
{ return instance; }
} }
void Message(): ArrayList<String> MessageParameters():
{ {
String name; String /*messageName, receiverName, senderName,*/ s;
ArrayList<String> params = new ArrayList<String>();
} }
{ {
( <RCV_MSG_KW> | <SND_MSG_KW> ) name = ID() "(" ( ID() )* ")" ( "()" | "(" s = ID() { params.add(s); } ( "," s = ID() { params.add(s); } )* ")" )
{
//TMLSDMessage message = new TMLSDMessage( messageName, "", instanceName, params );
return params;
}
/*|
<SND_MSG_KW> messageName = ID() "(" ( s = ID() { params.add(s); } )* ")"
{
TMLSDMessage message = new TMLSDMessage( messageName, instanceName, "", params );
return message;
}*/
} }
TMLSDAction Action( String instanceName ): TMLSDAction Action( String instanceName ):
{ {
String actionName; String s;
Token t;
} }
{ {
<ACTION_KW> actionName = ID() ID() <ASSIGNMENT> ( <INTEGER_LITERAL> | <FALSECONST> | <TRUECONST> ) <ACTION_KW> s = ID() <ASSIGNMENT> ( t = <INTEGER_LITERAL> | t = <FALSECONST> | t = <TRUECONST> )
{ {
TMLSDAction action = new TMLSDAction( actionName, instanceName ); TMLSDAction action = new TMLSDAction( s + " = " + t.image, instanceName );
return action; return action;
} }
} }
......
...@@ -65,6 +65,12 @@ public class TMLCPSequenceDiagram extends TMLElement { ...@@ -65,6 +65,12 @@ public class TMLCPSequenceDiagram extends TMLElement {
init(); init();
} }
// Constructor to be called from the parser, no reference object
public TMLCPSequenceDiagram( String _name ) {
super( _name, null );
init();
}
private void init() { private void init() {
//globalVariables = new ArrayList<TMLAttribute>(); //globalVariables = new ArrayList<TMLAttribute>();
instancesList = new ArrayList<TMLSDInstance>(); instancesList = new ArrayList<TMLSDInstance>();
......
...@@ -113,10 +113,10 @@ public class TMLSDEvent implements Comparable<TMLSDEvent> { ...@@ -113,10 +113,10 @@ public class TMLSDEvent implements Comparable<TMLSDEvent> {
switch( type ) { switch( type ) {
case 0: //send message case 0: //send message
msg = ( (TMLSDMessage) referenceObject ); msg = ( (TMLSDMessage) referenceObject );
return SEND_MESSAGE_LABEL + msg.toString(); return SEND_MESSAGE_LABEL + msg.getReceiverName() + ":" + msg.toString();
case 1: //receive message case 1: //receive message
msg = ( (TMLSDMessage) referenceObject ); msg = ( (TMLSDMessage) referenceObject );
return RECEIVE_MESSAGE_LABEL + msg.toString(); return RECEIVE_MESSAGE_LABEL + msg.getSenderName() + ":" + msg.toString();
case 2: //action case 2: //action
TMLSDAction action = ( (TMLSDAction) referenceObject ); TMLSDAction action = ( (TMLSDAction) referenceObject );
return ACTION_LABEL + action.toString(); return ACTION_LABEL + action.toString();
......
...@@ -70,6 +70,13 @@ public class TMLSDInstance extends TMLElement { ...@@ -70,6 +70,13 @@ public class TMLSDInstance extends TMLElement {
init(); init();
} }
//The constructor to be used from the parser. No reference to object
public TMLSDInstance( String _name, String _type ) {
super( _name, null );
this.type = _type;
init();
}
private void init() { private void init() {
globalVariables = new ArrayList<TMLAttribute>(); globalVariables = new ArrayList<TMLAttribute>();
...@@ -99,9 +106,9 @@ public class TMLSDInstance extends TMLElement { ...@@ -99,9 +106,9 @@ public class TMLSDInstance extends TMLElement {
events.add( _event ); events.add( _event );
}*/ }*/
public void addVariable( TMLAttribute _attr ) { /*public void addVariable( TMLAttribute _attr ) {
globalVariables.add( _attr ); globalVariables.add( _attr );
} }*/
public void addAttribute( TMLAttribute _attribute ) { //used by the graphical 2 TMLTxt compiler public void addAttribute( TMLAttribute _attribute ) { //used by the graphical 2 TMLTxt compiler
globalVariables.add( _attribute ); globalVariables.add( _attribute );
......
...@@ -88,7 +88,7 @@ public class TMLSDMessage extends TMLElement { ...@@ -88,7 +88,7 @@ public class TMLSDMessage extends TMLElement {
} }
// Constructor used for the TMLCPparser where in the TMLCP code there is no notion of yCoord and of referenceObject // Constructor used for the TMLCPparser where in the TMLCP code there is no notion of yCoord and of referenceObject
public TMLSDMessage( String _name, String _senderName, String _receiverName, Object _referenceObject, ArrayList<String> _params ) { public TMLSDMessage( String _name, String _senderName, String _receiverName, ArrayList<String> _params ) {
super( _name, null ); super( _name, null );
this.yCoord = -1; this.yCoord = -1;
this.senderName = _senderName; this.senderName = _senderName;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment