1 | <?php |
||
15 | class Optimizer extends IRProcessor |
||
16 | { |
||
17 | /** |
||
18 | * Optimize an IR |
||
19 | * |
||
20 | * @param DOMDocument $ir |
||
21 | * @return void |
||
22 | */ |
||
23 | public function optimize(DOMDocument $ir) |
||
47 | |||
48 | /** |
||
49 | * Clone closeTag elements that follow a switch into said switch |
||
50 | * |
||
51 | * If there's a <closeTag/> right after a <switch/>, clone the <closeTag/> at the end of |
||
52 | * the every <case/> that does not end with a <closeTag/> |
||
53 | * |
||
54 | * @param DOMDocument $ir |
||
55 | * @return void |
||
56 | */ |
||
57 | protected function cloneCloseTagElementsIntoSwitch(DOMDocument $ir) |
||
72 | |||
73 | /** |
||
74 | * Clone closeTag elements from the head of a switch's cases before said switch |
||
75 | * |
||
76 | * If there's a <closeTag/> at the beginning of every <case/>, clone it and insert it |
||
77 | * right before the <switch/> unless there's already one |
||
78 | * |
||
79 | * @param DOMDocument $ir |
||
80 | * @return void |
||
81 | */ |
||
82 | protected function cloneCloseTagElementsOutOfSwitch(DOMDocument $ir) |
||
101 | |||
102 | /** |
||
103 | * Merge consecutive literal outputs |
||
104 | * |
||
105 | * @param DOMDocument $ir |
||
106 | * @return void |
||
107 | */ |
||
108 | protected function mergeConsecutiveLiteralOutputElements(DOMDocument $ir) |
||
123 | |||
124 | /** |
||
125 | * Optimize closeTags elements |
||
126 | * |
||
127 | * @param DOMDocument $ir |
||
128 | * @return void |
||
129 | */ |
||
130 | protected function optimizeCloseTagElements(DOMDocument $ir) |
||
137 | |||
138 | /** |
||
139 | * Remove redundant closeTag siblings after a switch |
||
140 | * |
||
141 | * If all branches of a switch have a closeTag we can remove any closeTag siblings of the switch |
||
142 | * |
||
143 | * @param DOMDocument $ir |
||
144 | * @return void |
||
145 | */ |
||
146 | protected function removeCloseTagSiblings(DOMDocument $ir) |
||
151 | |||
152 | /** |
||
153 | * Remove content from void elements |
||
154 | * |
||
155 | * For each void element, we find whichever <closeTag/> elements close it and remove everything |
||
156 | * after |
||
157 | * |
||
158 | * @param DOMDocument $ir |
||
159 | * @return void |
||
160 | */ |
||
161 | protected function removeContentFromVoidElements(DOMDocument $ir) |
||
171 | |||
172 | /** |
||
173 | * Remove empty default cases (no test and no descendants) |
||
174 | * |
||
175 | * @param DOMDocument $ir |
||
176 | * @return void |
||
177 | */ |
||
178 | protected function removeEmptyDefaultCases(DOMDocument $ir) |
||
183 | |||
184 | /** |
||
185 | * Remove all nodes that match given XPath query |
||
186 | * |
||
187 | * @param DOMDocument $ir |
||
188 | * @param string $query |
||
189 | * @param DOMNode $contextNode |
||
190 | * @return void |
||
191 | */ |
||
192 | protected function removeNodes(DOMDocument $ir, $query, DOMNode $contextNode = null) |
||
202 | |||
203 | /** |
||
204 | * Remove redundant closeTag elements from the tail of a switch's cases |
||
205 | * |
||
206 | * For each <closeTag/> remove duplicate <closeTag/> nodes that are either siblings or |
||
207 | * descendants of a sibling |
||
208 | * |
||
209 | * @param DOMDocument $ir |
||
210 | * @return void |
||
211 | */ |
||
212 | protected function removeRedundantCloseTagElements(DOMDocument $ir) |
||
222 | |||
223 | /** |
||
224 | * Remove redundant closeTag elements from the tail of a switch's cases |
||
225 | * |
||
226 | * If there's a <closeTag/> right after a <switch/>, remove all <closeTag/> nodes at the |
||
227 | * end of every <case/> |
||
228 | * |
||
229 | * @param DOMDocument $ir |
||
230 | * @return void |
||
231 | */ |
||
232 | protected function removeRedundantCloseTagElementsInSwitch(DOMDocument $ir) |
||
246 | } |