root / trunk / compiler / ooasCompiler / src / org / momut / ooas / visitors / optimisation / OoaRemoveTrivialBlocksVisitor.java @ 7
1 |
/**
|
---|---|
2 |
*
|
3 |
* OOAS Compiler
|
4 |
*
|
5 |
* Copyright 2015, AIT Austrian Institute of Technology.
|
6 |
* This code is based on the C# Version of the OOAS Compiler, which is
|
7 |
* copyright 2015 by the Institute of Software Technology, Graz University
|
8 |
* of Technology with portions copyright by the AIT Austrian Institute of
|
9 |
* Technology. All rights reserved.
|
10 |
*
|
11 |
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
12 |
*
|
13 |
* If you modify the file please update the list of contributors below to in-
|
14 |
* clude your name. Please also stick to the coding convention of using TABs
|
15 |
* to do the basic (block-level) indentation and spaces for anything after
|
16 |
* that. (Enable the display of special chars and it should be pretty obvious
|
17 |
* what this means.) Also, remove all trailing whitespace.
|
18 |
*
|
19 |
* Contributors:
|
20 |
* Willibald Krenn (AIT)
|
21 |
* Stephan Zimmerer (AIT)
|
22 |
* Markus Demetz (AIT)
|
23 |
* Christoph Czurda (AIT)
|
24 |
*
|
25 |
*/
|
26 |
|
27 |
|
28 |
package org.momut.ooas.visitors.optimisation; |
29 |
|
30 |
import org.momut.ooas.ast.identifiers.MainModule; |
31 |
import org.momut.ooas.parser.ParserState; |
32 |
import org.momut.ooas.visitors.OoaEmptyVisitor; |
33 |
|
34 |
/**
|
35 |
* Iteratively applies the remove trivial Prioritized/Nondet/Seq visitors until
|
36 |
* we've reached a fixed point and no more changes can be done.
|
37 |
*
|
38 |
* @author willibald
|
39 |
*/
|
40 |
public final class OoaRemoveTrivialBlocksVisitor extends OoaEmptyVisitor { |
41 |
|
42 |
final ParserState m_state;
|
43 |
|
44 |
|
45 |
private boolean removePrio(MainModule m) { |
46 |
final OoaRemoveTrivialPrioritizedCompositionVisitor vis = new OoaRemoveTrivialPrioritizedCompositionVisitor(m_state); |
47 |
vis.visit(m); |
48 |
return vis.changedAst();
|
49 |
} |
50 |
|
51 |
private boolean removeNonDet(MainModule m) { |
52 |
final OoaRemoveTrivialNondetChoiceCompositionVisitor vis = new OoaRemoveTrivialNondetChoiceCompositionVisitor(m_state); |
53 |
vis.visit(m); |
54 |
return vis.changedAst();
|
55 |
} |
56 |
|
57 |
private boolean removeSeq(MainModule m) { |
58 |
final OoaRemoveTrivialSequentialCompositionVisitor vis = new OoaRemoveTrivialSequentialCompositionVisitor(m_state); |
59 |
vis.visit(m); |
60 |
return vis.changedAst();
|
61 |
} |
62 |
|
63 |
private boolean joinSeq(MainModule m) { |
64 |
final OoaJoinSequentialCompositionBlocksVisitor vis = new OoaJoinSequentialCompositionBlocksVisitor(m_state); |
65 |
vis.visit(m); |
66 |
return vis.changedAst();
|
67 |
} |
68 |
|
69 |
@Override
|
70 |
public void visit(MainModule mainModule) |
71 |
{ |
72 |
boolean changes = true; |
73 |
while (changes) {
|
74 |
changes = false;
|
75 |
changes |= removePrio(mainModule); |
76 |
changes |= removeNonDet(mainModule); |
77 |
changes |= removeSeq(mainModule); |
78 |
changes |= joinSeq(mainModule); |
79 |
} |
80 |
} |
81 |
|
82 |
|
83 |
public OoaRemoveTrivialBlocksVisitor(ParserState aState)
|
84 |
{ |
85 |
m_state = aState; |
86 |
} |
87 |
} |