Book a Demo

Author Topic: EASL Code Generation  (Read 3501 times)

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
EASL Code Generation
« on: January 08, 2011, 01:49:33 am »
Hi All

I am having a little look at the EASL code generation in EA, specifically C# code from a sequence diagram. The User Guide is a little scant, but implies that a Loop combined fragment will generate an iteration, and indeed it does.

Below is an extract from the code generation script

$guard = %EASL_GET("Property", $guardedAction, "Guard")%
$expression = %EASL_GET("Property", $guard, "Expression")%
$upper = %EASL_GET("Property", $guard, "Upper")%
$lower = %EASL_GET("Property", $guard, "Lower")%


Now, the EASL Property "Expression" can be set by using the Properties of the Combined Fragment, and this setting comes out in the generated code. BUT, if we look a little further into the code generation script ...

%if $expression != ""%
while ($expression)\n
%elseIf $lower != ""%
for ($lower; $upper; ; )\n
%else%
while (true)\n
%endIf%

We find the $expression (if set) will always generate a while loop ... perfectly OK.

However, how do we get a for loop?

The above script implies, that if no expression is set AND EASL property "lower" is set then we get a for loop

Does anyone know how set a value for the EASL property lower ... what does this correspond to on the combined fragment. I can find no property, or tagged value

Cheers

Phil
Models are great!
Correct models are even greater!

Nizam Mohamed

  • EA User
  • **
  • Posts: 193
  • Karma: +1/-0
    • View Profile
Re: EASL Code Generation
« Reply #1 on: January 11, 2011, 09:36:16 am »
If the condition conforms to the following syntax, "("<minint> ["," <maxint>] ")", the upper and lower fields will be populated and a for loop will be generated

HTH

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: EASL Code Generation
« Reply #2 on: January 11, 2011, 08:45:47 pm »
Many thanks Nizam, that pointed me in the right direction. However the code generation script needs a slight modifcation. As its stands, if the condition contains a value a while will always be generated due to the statement

%if $expression !=""%

evaluates to true and the statement that generates the for loop is never reached.

I modifed the script as follows which also generates correct syntax for C#

$guard = %EASL_GET("Property", $guardedAction, "Guard")%
$expression = %EASL_GET("Property", $guard, "Expression")%
$upper = %EASL_GET("Property", $guard, "Upper")%
$lower = %EASL_GET("Property", $guard, "Lower")%

%if $expression != ""%
%if $lower !=""%
for (int i=$lower; i<$upper; i++)\n
%else%
while ($expression)\n
%endIf%
%else%
while (true)\n
%endIf%

Thanks again

Phil
Models are great!
Correct models are even greater!