SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 388 | Next

Steven Kelly and Juha-Pekka Tolvanen

"Domain-Specific Modeling"

The generator, shown in Listing 9.5, is signi?¬?cantly shorter than that for
Java and follows a completely different approach. The application??™s States and
Buttons are turned into enums, and the state machine is generated as two-level nested
switch??“case statements. The outer level has a case for each state the application is in,
and the inner level for that state speci?¬?es the actions and transition for each button that
may be pressed in that state.
Listing 9.5 The C generator for Watch Applications.
subreport '_C_Enums' run
'int state = Start;
int button = None; /* pseudo-button for buttonless transitions */
'subreport '_C_RunWatch' run;
'void handleEvent()
{
int oldState = state;
switch (state)
{
'foreach .(State | Start)
{ ' case ' id ':' newline
' switch (button)' newline
' {' newline
{ ' ' subreport '_C_' type run
}
}
do ~To.(State | Stop)
{ if not oid = oid;2 then
' state = ' id ';' newline
endif
}
do ~From>Transition;
{ ' case '
if ~Event; then
do ~Event.Button { id }
else
'None'
endif
':' newline
do ~Action.Action
{ do ~ActionBody>()
218 DIGITAL WRISTWATCH
This generator produces the familiar nested switch??“cases used in much embedded
software. The results for Stopwatch are shown in Listing 9.6.
Listing 9.6 The generated C code for the Stopwatch application.


Pages:
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6