|
2 | 2 | overlay[local] |
3 | 3 | module; |
4 | 4 |
|
| 5 | +import codeql.controlflow.SuccessorType |
5 | 6 | private import codeql.ruby.AST |
6 | 7 | private import codeql.ruby.controlflow.BasicBlocks |
7 | | -private import SuccessorTypes |
8 | 8 | private import internal.ControlFlowGraphImpl as CfgImpl |
9 | 9 | private import internal.Splitting as Splitting |
10 | 10 | private import internal.Completion |
@@ -59,241 +59,6 @@ class CfgNode extends CfgImpl::Node { |
59 | 59 | BasicBlock getBasicBlock() { result.getANode() = this } |
60 | 60 | } |
61 | 61 |
|
62 | | -/** The type of a control flow successor. */ |
63 | | -class SuccessorType extends CfgImpl::TSuccessorType { |
64 | | - /** Gets a textual representation of successor type. */ |
65 | | - string toString() { none() } |
66 | | -} |
67 | | - |
68 | | -/** Provides different types of control flow successor types. */ |
69 | | -module SuccessorTypes { |
70 | | - /** A normal control flow successor. */ |
71 | | - class NormalSuccessor extends SuccessorType, CfgImpl::TSuccessorSuccessor { |
72 | | - final override string toString() { result = "successor" } |
73 | | - } |
74 | | - |
75 | | - /** |
76 | | - * A conditional control flow successor. Either a Boolean successor (`BooleanSuccessor`) |
77 | | - * or a matching successor (`MatchingSuccessor`) |
78 | | - */ |
79 | | - class ConditionalSuccessor extends SuccessorType { |
80 | | - boolean value; |
81 | | - |
82 | | - ConditionalSuccessor() { |
83 | | - this = CfgImpl::TBooleanSuccessor(value) or |
84 | | - this = CfgImpl::TMatchingSuccessor(value) |
85 | | - } |
86 | | - |
87 | | - /** Gets the Boolean value of this successor. */ |
88 | | - final boolean getValue() { result = value } |
89 | | - |
90 | | - override string toString() { result = this.getValue().toString() } |
91 | | - } |
92 | | - |
93 | | - /** |
94 | | - * A Boolean control flow successor. |
95 | | - * |
96 | | - * For example, in |
97 | | - * |
98 | | - * ```rb |
99 | | - * if x >= 0 |
100 | | - * puts "positive" |
101 | | - * else |
102 | | - * puts "negative" |
103 | | - * end |
104 | | - * ``` |
105 | | - * |
106 | | - * `x >= 0` has both a `true` successor and a `false` successor. |
107 | | - */ |
108 | | - class BooleanSuccessor extends ConditionalSuccessor, CfgImpl::TBooleanSuccessor { } |
109 | | - |
110 | | - /** |
111 | | - * A matching control flow successor. |
112 | | - * |
113 | | - * For example, this program fragment: |
114 | | - * |
115 | | - * ```rb |
116 | | - * case x |
117 | | - * when 1 then puts "one" |
118 | | - * else puts "not one" |
119 | | - * end |
120 | | - * ``` |
121 | | - * |
122 | | - * has a control flow graph containing matching successors: |
123 | | - * |
124 | | - * ``` |
125 | | - * x |
126 | | - * | |
127 | | - * 1 |
128 | | - * / \ |
129 | | - * / \ |
130 | | - * / \ |
131 | | - * / \ |
132 | | - * match non-match |
133 | | - * | | |
134 | | - * puts "one" puts "not one" |
135 | | - * ``` |
136 | | - */ |
137 | | - class MatchingSuccessor extends ConditionalSuccessor, CfgImpl::TMatchingSuccessor { |
138 | | - override string toString() { if value = true then result = "match" else result = "no-match" } |
139 | | - } |
140 | | - |
141 | | - /** |
142 | | - * A `return` control flow successor. |
143 | | - * |
144 | | - * Example: |
145 | | - * |
146 | | - * ```rb |
147 | | - * def sum(x,y) |
148 | | - * return x + y |
149 | | - * end |
150 | | - * ``` |
151 | | - * |
152 | | - * The exit node of `sum` is a `return` successor of the `return x + y` |
153 | | - * statement. |
154 | | - */ |
155 | | - class ReturnSuccessor extends SuccessorType, CfgImpl::TReturnSuccessor { |
156 | | - final override string toString() { result = "return" } |
157 | | - } |
158 | | - |
159 | | - /** |
160 | | - * A `break` control flow successor. |
161 | | - * |
162 | | - * Example: |
163 | | - * |
164 | | - * ```rb |
165 | | - * def m |
166 | | - * while x >= 0 |
167 | | - * x -= 1 |
168 | | - * if num > 100 |
169 | | - * break |
170 | | - * end |
171 | | - * end |
172 | | - * puts "done" |
173 | | - * end |
174 | | - * ``` |
175 | | - * |
176 | | - * The node `puts "done"` is `break` successor of the node `break`. |
177 | | - */ |
178 | | - class BreakSuccessor extends SuccessorType, CfgImpl::TBreakSuccessor { |
179 | | - final override string toString() { result = "break" } |
180 | | - } |
181 | | - |
182 | | - /** |
183 | | - * A `next` control flow successor. |
184 | | - * |
185 | | - * Example: |
186 | | - * |
187 | | - * ```rb |
188 | | - * def m |
189 | | - * while x >= 0 |
190 | | - * x -= 1 |
191 | | - * if num > 100 |
192 | | - * next |
193 | | - * end |
194 | | - * end |
195 | | - * puts "done" |
196 | | - * end |
197 | | - * ``` |
198 | | - * |
199 | | - * The node `x >= 0` is `next` successor of the node `next`. |
200 | | - */ |
201 | | - class NextSuccessor extends SuccessorType, CfgImpl::TNextSuccessor { |
202 | | - final override string toString() { result = "next" } |
203 | | - } |
204 | | - |
205 | | - /** |
206 | | - * A `redo` control flow successor. |
207 | | - * |
208 | | - * Example: |
209 | | - * |
210 | | - * Example: |
211 | | - * |
212 | | - * ```rb |
213 | | - * def m |
214 | | - * while x >= 0 |
215 | | - * x -= 1 |
216 | | - * if num > 100 |
217 | | - * redo |
218 | | - * end |
219 | | - * end |
220 | | - * puts "done" |
221 | | - * end |
222 | | - * ``` |
223 | | - * |
224 | | - * The node `x -= 1` is `redo` successor of the node `redo`. |
225 | | - */ |
226 | | - class RedoSuccessor extends SuccessorType, CfgImpl::TRedoSuccessor { |
227 | | - final override string toString() { result = "redo" } |
228 | | - } |
229 | | - |
230 | | - /** |
231 | | - * A `retry` control flow successor. |
232 | | - * |
233 | | - * Example: |
234 | | - * |
235 | | - * Example: |
236 | | - * |
237 | | - * ```rb |
238 | | - * def m |
239 | | - * begin |
240 | | - * puts "Retry" |
241 | | - * raise |
242 | | - * rescue |
243 | | - * retry |
244 | | - * end |
245 | | - * end |
246 | | - * ``` |
247 | | - * |
248 | | - * The node `puts "Retry"` is `retry` successor of the node `retry`. |
249 | | - */ |
250 | | - class RetrySuccessor extends SuccessorType, CfgImpl::TRetrySuccessor { |
251 | | - final override string toString() { result = "retry" } |
252 | | - } |
253 | | - |
254 | | - /** |
255 | | - * An exceptional control flow successor. |
256 | | - * |
257 | | - * Example: |
258 | | - * |
259 | | - * ```rb |
260 | | - * def m x |
261 | | - * if x > 2 |
262 | | - * raise "x > 2" |
263 | | - * end |
264 | | - * puts "x <= 2" |
265 | | - * end |
266 | | - * ``` |
267 | | - * |
268 | | - * The exit node of `m` is an exceptional successor of the node |
269 | | - * `raise "x > 2"`. |
270 | | - */ |
271 | | - class RaiseSuccessor extends SuccessorType, CfgImpl::TRaiseSuccessor { |
272 | | - final override string toString() { result = "raise" } |
273 | | - } |
274 | | - |
275 | | - /** |
276 | | - * An exit control flow successor. |
277 | | - * |
278 | | - * Example: |
279 | | - * |
280 | | - * ```rb |
281 | | - * def m x |
282 | | - * if x > 2 |
283 | | - * exit 1 |
284 | | - * end |
285 | | - * puts "x <= 2" |
286 | | - * end |
287 | | - * ``` |
288 | | - * |
289 | | - * The exit node of `m` is an exit successor of the node |
290 | | - * `exit 1`. |
291 | | - */ |
292 | | - class ExitSuccessor extends SuccessorType, CfgImpl::TExitSuccessor { |
293 | | - final override string toString() { result = "exit" } |
294 | | - } |
295 | | -} |
296 | | - |
297 | 62 | class Split = Splitting::Split; |
298 | 63 |
|
299 | 64 | /** Provides different kinds of control flow graph splittings. */ |
|
0 commit comments