Wiki source code of SCL Extensions
Version 12.1 by ssm on 2013/05/08 11:36
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
6.1 | 1 | |
| |
1.1 | 2 | |
| 3 | |||
| |
6.1 | 4 | |
| |
1.1 | 5 | {{toc/}} |
| 6 | |||
| 7 | There are several extensions implemented to ease the work with a scl model. (de.cau.cs.kieler.scl.extensions) | ||
| 8 | |||
| 9 | = SCL Factory Extensions = | ||
| 10 | |||
| |
3.1 | 11 | You need several Factories to handle all aspects of Yakindu (SGraph + SText) and the extended SCChart models. The SCL Factory Extension provides you with shortcuts for all factories. |
| |
1.1 | 12 | |
| |
3.1 | 13 | |=((( |
| 14 | Shortcut | ||
| 15 | )))|=((( | ||
| 16 | Factory | ||
| 17 | )))|=(% colspan="1" %)(% colspan="1" %) | ||
| 18 | ((( | ||
| 19 | Description | ||
| 20 | ))) | ||
| 21 | |((( | ||
| 22 | SGraph() | ||
| 23 | )))|((( | ||
| 24 | SGraphFactory::eINSTANCE | ||
| 25 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 26 | ((( | ||
| 27 | Factory for yakindu statechart models | ||
| 28 | ))) | ||
| 29 | |(% colspan="1" %)(% colspan="1" %) | ||
| 30 | ((( | ||
| 31 | SText() | ||
| 32 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 33 | ((( | ||
| 34 | StextFactory::eINSTANCE | ||
| 35 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 36 | ((( | ||
| 37 | Factory for yakindu expressions | ||
| 38 | ))) | ||
| 39 | |(% colspan="1" %)(% colspan="1" %) | ||
| 40 | ((( | ||
| 41 | SyncGraph() | ||
| 42 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 43 | ((( | ||
| 44 | SyncgraphFactory::eINSTANCE | ||
| 45 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 46 | ((( | ||
| 47 | Factory for sgraph extensions | ||
| 48 | ))) | ||
| 49 | |(% colspan="1" %)(% colspan="1" %) | ||
| 50 | ((( | ||
| 51 | SyncText() | ||
| 52 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 53 | ((( | ||
| 54 | SynctextFactory::eINSTANCE | ||
| 55 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 56 | ((( | ||
| 57 | Factory for stext extensions | ||
| 58 | ))) | ||
| 59 | |(% colspan="1" %)(% colspan="1" %) | ||
| 60 | ((( | ||
| 61 | SCCExp() | ||
| 62 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 63 | ((( | ||
| 64 | SCChartsExpFactory::eINSTANCE | ||
| 65 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 66 | ((( | ||
| 67 | Factory for SCCharts specific expression extensions | ||
| 68 | ))) | ||
| 69 | |(% colspan="1" %)(% colspan="1" %) | ||
| 70 | ((( | ||
| 71 | SCL() | ||
| 72 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 73 | ((( | ||
| 74 | SclFactory::eINSTANCE | ||
| 75 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 76 | ((( | ||
| 77 | Factory for SCL | ||
| 78 | ))) | ||
| 79 | |||
| |
1.1 | 80 | = SCL Create Extensions = |
| 81 | |||
| |
9.1 | 82 | coming soon... |
| 83 | |||
| 84 | = SCL Naming Extensions = | ||
| 85 | |||
| 86 | SCL Naming Extensions provide helper functions for ID & naming services. | ||
| 87 | |||
| |
8.1 | 88 | |=((( |
| 89 | Method | ||
| 90 | )))|=((( | ||
| 91 | Description | ||
| 92 | ))) | ||
| 93 | |((( | ||
| |
9.1 | 94 | def void distributeStateIDs(Statechart) |
| 95 | )))|((( | ||
| 96 | Since yakindu does not make use of the ID field, one can use this method to make every ID in a statechart unique. | ||
| 97 | ))) | ||
| 98 | |(% colspan="1" %)(% colspan="1" %) | ||
| 99 | ((( | ||
| 100 | def String getHierarchicalName(SyncState, String) | ||
| 101 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 102 | ((( | ||
| 103 | Generates a (most likely unique) name for a state. The name is generated from all parent states and regions, which are separated by an underscore. If a region or state has no name, the element's hash code is used instead. | ||
| 104 | ))) | ||
| 105 | |||
| 106 | = SCL Ordering Extensions = | ||
| 107 | |||
| 108 | The Ordering Extensions provide functions, which can be used in the //xtend sort// context. | ||
| 109 | |||
| 110 | |=((( | ||
| 111 | Method | ||
| 112 | )))|=((( | ||
| 113 | Description | ||
| 114 | ))) | ||
| 115 | |((( | ||
| 116 | def **int** compareSCLRegionStateOrder(SyncState, SyncState)(% style="font-size: small;" %) | ||
| 117 | )))|((( | ||
| 118 | Sorts states according to their type. Initial states come first, final states last. | ||
| 119 | ))) | ||
| 120 | |||
| 121 | = SCL Statement Extensions = | ||
| 122 | |||
| 123 | |=((( | ||
| 124 | Method | ||
| 125 | )))|=((( | ||
| 126 | Description | ||
| 127 | ))) | ||
| 128 | |((( | ||
| |
8.1 | 129 | def boolean isEmpty(Statement) |
| 130 | )))|((( | ||
| 131 | Returns true, if the statement is an EmptyStatement. | ||
| 132 | ))) | ||
| 133 | |(% colspan="1" %)(% colspan="1" %) | ||
| 134 | ((( | ||
| 135 | def boolean hasInstruction(Statement) | ||
| 136 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 137 | ((( | ||
| 138 | Returns true, if the statement is an InstructionStatement containing an instruction. | ||
| 139 | ))) | ||
| 140 | |(% colspan="1" %)(% colspan="1" %) | ||
| 141 | ((( | ||
| 142 | def boolean isGoto(Statement) | ||
| 143 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 144 | ((( | ||
| 145 | Returns true, if the statement is an InstructionStatement containing a goto instruction. | ||
| 146 | ))) | ||
| 147 | |(% colspan="1" %)(% colspan="1" %) | ||
| 148 | ((( | ||
| 149 | def EmptyStatement asEmptyStatement(Statement) | ||
| 150 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 151 | ((( | ||
| 152 | Convenently type-cast the statement to an EmptyStatement | ||
| 153 | ))) | ||
| 154 | |(% colspan="1" %)(% colspan="1" %) | ||
| 155 | ((( | ||
| 156 | def InstructionStatement asInstructionStatement(Statement) | ||
| 157 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 158 | ((( | ||
| 159 | Convenently type-cast the statement to an InstructionStatement | ||
| 160 | ))) | ||
| 161 | |(% colspan="1" %)(% colspan="1" %) | ||
| 162 | ((( | ||
| 163 | def getInstruction(Statement) | ||
| 164 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 165 | ((( | ||
| 166 | Type-cast the statement to an InstructionStatement an return its instruction. | ||
| 167 | ))) | ||
| 168 | |(% colspan="1" %)(% colspan="1" %) | ||
| 169 | ((( | ||
| 170 | def EmptyStatement removeInstruction(Statement) | ||
| 171 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 172 | ((( | ||
| 173 | Creates a new EmptyStatement and copies the label and comment information from the old statement. | ||
| 174 | ))) | ||
| 175 | |(% colspan="1" %)(% colspan="1" %) | ||
| 176 | ((( | ||
| 177 | def getStatement(Instruction) | ||
| 178 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 179 | ((( | ||
| 180 | Returns the parent statement of a given instruction. | ||
| 181 | ))) | ||
| |
1.1 | 182 | |
| 183 | = SCL Thread Extensions = | ||
| 184 | |||
| |
3.1 | 185 | The Thread Extensions provide functions to ease the handling of SCL threads and statements in the context of SCL threads. |
| |
1.1 | 186 | |
| |
3.1 | 187 | |=((( |
| 188 | Method | ||
| 189 | )))|=((( | ||
| 190 | Description | ||
| 191 | ))) | ||
| 192 | |((( | ||
| 193 | def AbstractThread getThread(Instruction) | ||
| 194 | |||
| 195 | def AbstractThread getThread(Statement)(% style="font-size: small;" %) | ||
| 196 | )))|((( | ||
| |
4.1 | 197 | Returns the SCL thread of a SCL statement or SCL instruction. |
| |
3.1 | 198 | ))) |
| 199 | |(% colspan="1" %)(% colspan="1" %) | ||
| 200 | ((( | ||
| 201 | def AbstractThread getMainThread(Instruction) | ||
| 202 | |||
| 203 | def AbstractThread getMainThread(Statement)(% style="font-size: small;" %) | ||
| 204 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 205 | ((( | ||
| |
4.1 | 206 | Returns the main thread of a SCL program. |
| |
3.1 | 207 | ))) |
| 208 | |(% colspan="1" %)(% colspan="1" %) | ||
| 209 | ((( | ||
| |
7.1 | 210 | def Statement[] getControlFlow(Instruction) |
| 211 | |||
| 212 | def Statement[] getControlFlow(Statement) | ||
| 213 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 214 | ((( | ||
| 215 | Returns the control flow of an instruction/statement up to the parent of this control flow. In contrast to a thread this also includes control flows of conditional instructions. | ||
| 216 | ))) | ||
| 217 | |(% colspan="1" %)(% colspan="1" %) | ||
| 218 | ((( | ||
| |
3.1 | 219 | def **boolean** isInSameThreadAs(Instruction, Instruction) |
| 220 | |||
| 221 | def **boolean** isInSameThreadAs(Statement, Statement) | ||
| 222 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 223 | ((( | ||
| |
4.1 | 224 | Returns true, if both instructions/statements are in the same thread. |
| |
3.1 | 225 | ))) |
| 226 | |(% colspan="1" %)(% colspan="1" %) | ||
| 227 | ((( | ||
| 228 | def **boolean** isInMainThread(Instruction) | ||
| 229 | |||
| 230 | def **boolean** isInMainThread(Statement) | ||
| 231 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 232 | ((( | ||
| |
4.1 | 233 | Returns true, if the instruction/statement runs in the main thread. |
| |
3.1 | 234 | ))) |
| 235 | |(% colspan="1" %)(% colspan="1" %) | ||
| 236 | ((( | ||
| |
4.1 | 237 | def **boolean** isInThread(Instruction, AbstractThread) |
| |
3.1 | 238 | |
| |
4.1 | 239 | def **boolean** isInThread(Statement, AbstractThread) |
| |
3.1 | 240 | )))|(% colspan="1" %)(% colspan="1" %) |
| 241 | ((( | ||
| |
4.1 | 242 | Returns true, if the instruction/statement runs in the given thread. |
| |
3.1 | 243 | ))) |
| 244 | |(% colspan="1" %)(% colspan="1" %) | ||
| 245 | ((( | ||
| |
4.1 | 246 | def **boolean** contains(AbstractThread, Instruction) |
| |
3.1 | 247 | |
| |
4.1 | 248 | def **boolean** contains(AbstractThread, Statements) |
| |
3.1 | 249 | )))|(% colspan="1" %)(% colspan="1" %) |
| 250 | ((( | ||
| |
4.1 | 251 | Returns true, if the thread contains the given instruction/statement. |
| |
3.1 | 252 | ))) |
| 253 | |(% colspan="1" %)(% colspan="1" %) | ||
| 254 | ((( | ||
| |
4.1 | 255 | def dropPrevious(AbstractThread, Statement) |
| |
3.1 | 256 | |
| 257 | def dropPrevious(List<Statement>, Statement)(% style="font-size: small;" %) | ||
| 258 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 259 | ((( | ||
| |
7.1 | 260 | Drops all preceding statements in a thread or a list of statements before the given statement. |
| |
3.1 | 261 | ))) |
| |
7.1 | 262 | |(% colspan="1" %)(% colspan="1" %) |
| 263 | ((( | ||
| 264 | def Statement getPreviousStatement(Statement) | ||
| 265 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 266 | ((( | ||
| 267 | Returns the preceding statement. | ||
| 268 | ))) | ||
| 269 | |(% colspan="1" %)(% colspan="1" %) | ||
| 270 | ((( | ||
| 271 | def Statement getPreviousStatementHierarchical(Statement) | ||
| 272 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 273 | ((( | ||
| 274 | Returns the preceding statement or the parent statement of that control flow, if no preceding statement is present. | ||
| 275 | ))) | ||
| 276 | |(% colspan="1" %)(% colspan="1" %) | ||
| 277 | ((( | ||
| 278 | def InstructionStatement getPreviousInstructionStatement(Statement) | ||
| 279 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 280 | ((( | ||
| 281 | Returns the preceding instruction statement. Empty statements are ignored. | ||
| 282 | ))) | ||
| 283 | |(% colspan="1" %)(% colspan="1" %) | ||
| 284 | ((( | ||
| 285 | def InstructionStatement getPreviousInstructionStatementHierarchical(Statement) | ||
| 286 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 287 | ((( | ||
| 288 | Returns the preceding instruction statement or the parent statement of that control flow, if no preceding statement is present. | ||
| 289 | ))) | ||
| |
3.1 | 290 | |
| |
1.1 | 291 | = SCL Goto Extensions = |
| 292 | |||
| |
4.1 | 293 | To help with the handling of the goto statement and its target instruction, use the SCL Goto Extensions. |
| |
1.1 | 294 | |
| |
4.1 | 295 | |=((( |
| 296 | Method | ||
| 297 | )))|=((( | ||
| 298 | Description | ||
| 299 | ))) | ||
| 300 | |((( | ||
| 301 | def Statement getTargetStatement(Goto) | ||
| 302 | |||
| 303 | def Statement getTargetStatement(Goto, AbstractThread) | ||
| 304 | )))|((( | ||
| 305 | Returns the target statement of a goto instruction (in the context of the (given) thread). | ||
| 306 | ))) | ||
| 307 | |(% colspan="1" %)(% colspan="1" %) | ||
| 308 | ((( | ||
| 309 | def boolean targetExists(Goto) | ||
| 310 | |||
| 311 | def boolean targetExists(Goto, AbstractThread) | ||
| 312 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 313 | ((( | ||
| 314 | Returns true, if the target of a goto instruction exists (in the context of the (given) thread). | ||
| 315 | ))) | ||
| 316 | |(% colspan="1" %)(% colspan="1" %) | ||
| 317 | ((( | ||
| 318 | def InstructionStatement getInstructionStatement(Statement)(% style="font-size: small;" %) | ||
| 319 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 320 | ((( | ||
| 321 | Returns the first valid InstructionStatement in a thread after the given statement. **May return null, if no further InstructionStatement exists.** | ||
| 322 | |||
| 323 | To get a valid instruction form a goto jump, one can write "goto.getTargetStatement?.getInstructionStatement?.instruction". The result value will be the instruction or null. | ||
| 324 | ))) | ||
| 325 | |(% colspan="1" %)(% colspan="1" %) | ||
| 326 | ((( | ||
| 327 | def getIncomingGotos(Statement) | ||
| 328 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 329 | ((( | ||
| 330 | Returns a list of all gotos that target the given statement. If you want to retrieve the count of incoming goto jumps, use "getIncomingGotos.size". | ||
| 331 | ))) | ||
| 332 | |||
| |
1.1 | 333 | = SCL Expression Extensions = |
| 334 | |||
| |
6.1 | 335 | The SCL Expression Extension holds methods to help with the manipulation and constructions of the SText (and extended) expressions. |
| |
1.1 | 336 | |
| |
6.1 | 337 | |=((( |
| 338 | Method | ||
| 339 | )))|=((( | ||
| 340 | Description | ||
| 341 | ))) | ||
| 342 | |((( | ||
| 343 | def Expression toExpression(RegularEventSpec) | ||
| 344 | )))|((( | ||
| 345 | Transforms a SGraph RegularEventSpec to a SText Expression. The resulting expression will be an ElementReferenceExpression. | ||
| 346 | ))) | ||
| 347 | |(% colspan="1" %)(% colspan="1" %) | ||
| 348 | ((( | ||
| 349 | def Expression negate(Expression) | ||
| 350 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 351 | ((( | ||
| 352 | Negates the given expression. If the Expression is an ElementReferenceExpression the result will be a LogicalNotExpression containing the expression. Otherwise the result will be a LogicalNotExpression containing a ParenthesizedExpression, which then holds the original expression. | ||
| 353 | ))) | ||
| 354 | |(% colspan="1" %)(% colspan="1" %) | ||
| 355 | ((( | ||
| 356 | def String correctSerialization(String) | ||
| 357 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 358 | ((( | ||
| 359 | Since the actual implementation of the SText parser may parse artefacts (like linebreaks) until matching a preceding delimeter, correctSerialization removes these artifacts, when serializing an expression. | ||
| 360 | ))) | ||
| 361 | |||
| |
1.1 | 362 | = SCL Dependency Extensions = |
| 363 | |||
| 364 | //coming soon...// | ||
| 365 | |||
| 366 | = SCL Basic Block Extensions = | ||
| 367 | |||
| |
10.1 | 368 | The Basic Block Extensions retrieve information about basic blocks in the SCL model. A basic block can be identified by any statement in the block. Usually the first statement (called basic block root statement) in the block is used. |
| 369 | |||
| 370 | |=((( | ||
| 371 | Method | ||
| 372 | )))|=((( | ||
| 373 | Description | ||
| 374 | ))) | ||
| 375 | |((( | ||
| 376 | def ArrayList<Statement> getBasicBlock(Statement) | ||
| 377 | |||
| 378 | def ArrayList<Statement> getBasicBlock(Statement, List<Statement>) | ||
| 379 | )))|((( | ||
| 380 | Retrieves all statements of the basic block in which the given statement is located. | ||
| 381 | ))) | ||
| 382 | |(% colspan="1" %)(% colspan="1" %) | ||
| 383 | ((( | ||
| 384 | def Statement getBasicBlockRoot(Statement) | ||
| 385 | |||
| 386 | def Statement getBasicBlockRoot(List<Statement>) | ||
| 387 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 388 | ((( | ||
| 389 | Returns the root statement of a basic block. | ||
| 390 | ))) | ||
| 391 | |(% colspan="1" %)(% colspan="1" %) | ||
| 392 | ((( | ||
| 393 | def boolean isInBasicBlock(Statement, Statement) | ||
| 394 | |||
| 395 | def boolean isInBasicBlock(Statement, List<Statement>) | ||
| 396 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 397 | ((( | ||
| 398 | Returns true, if the caller statement is contained in the given basic block. | ||
| 399 | ))) | ||
| 400 | |(% colspan="1" %)(% colspan="1" %) | ||
| 401 | ((( | ||
| 402 | def String getBasicBlockID(Statement) | ||
| 403 | |||
| 404 | def String getBasicBlockID(List<Statement>) | ||
| 405 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 406 | ((( | ||
| 407 | Returns an unique ID for the given basic block. To create this ID, the hash code of the root statement is used. | ||
| 408 | ))) | ||
| 409 | |(% colspan="1" %)(% colspan="1" %) | ||
| 410 | ((( | ||
| 411 | def ArrayList<Statement> getBasicBlockRoots(Statement) | ||
| 412 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 413 | ((( | ||
| 414 | Returns a list of all basic block root statements in the contorl flow of the calling statement. | ||
| 415 | ))) | ||
| 416 | |(% colspan="1" %)(% colspan="1" %) | ||
| 417 | ((( | ||
| 418 | def ArrayList<Statement> getAllBasicBlockRoots(Statement) | ||
| 419 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 420 | ((( | ||
| 421 | Returns a list of all basic block root statements in the program that contains the calling statement. | ||
| 422 | ))) | ||
| 423 | |(% colspan="1" %)(% colspan="1" %) | ||
| 424 | ((( | ||
| 425 | def int getBasicBlockIndex(Statement) | ||
| 426 | )))|(% colspan="1" %)(% colspan="1" %) | ||
| 427 | ((( | ||
| 428 | Returns the index of the given basic block. | ||
| 429 | ))) | ||
| 430 | |(% colspan="1" %)(% colspan="1" %) | ||
| 431 | ((( | ||
| |
12.1 | 432 | def ArrayList<Statement> getBasicBlockPredecessorsRoots(Statement) |
| |
10.1 | 433 | )))|(% colspan="1" %)(% colspan="1" %) |
| 434 | ((( | ||
| 435 | Returns a list of basic block root statements, that identify the predecessor basic blocks of the basic block identified by the given statement. | ||
| 436 | ))) | ||
| |
11.1 | 437 | |
| 438 | {{code title="SCL Basic Block Extensions Code Examples" language="java"}} | ||
| |
12.1 | 439 | for (predecessor : basicBlockData.BasicBlockRootStatement.getBasicBlockPredecessorsRoots) { |
| |
11.1 | 440 | goLabelText = goLabelText + 'P' + predecessor.getBasicBlockIndex + "\n" |
| 441 | } | ||
| 442 | {{/code}} |