Address review comments

This commit is contained in:
Tom Hvitved
2020-11-19 14:31:08 +01:00
parent 4626168969
commit 06a6a3feb0
10 changed files with 66 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
/** Provides classes representing basic blocks. */
import codeql_ruby.ast
private import codeql_ruby.ast
private import codeql_ruby.controlflow.ControlFlowGraph
private import internal.ControlFlowGraphImpl
private import SuccessorTypes

View File

@@ -1,24 +1,26 @@
/** Provides classes representing the control flow graph. */
import codeql_ruby.ast
private import codeql_ruby.ast
private import codeql_ruby.controlflow.BasicBlocks
private import SuccessorTypes
private import internal.ControlFlowGraphImpl
private import internal.Splitting
private import internal.Completion
private class CfgScopeRange = @method or @block or @do_block;
/** An AST node with an associated control-flow graph. */
class CfgScope extends AstNode {
private string name;
CfgScope() {
name = this.(Method).getName().toString()
or
this = any(MethodCall mc | name = "block for " + mc.getMethod()).getBlock()
}
class CfgScope extends AstNode, CfgScopeRange {
/** Gets the name of this scope. */
string getName() { result = name }
string getName() {
result = this.(Method).getName().toString()
or
this instanceof Block and
result = "block"
or
this instanceof DoBlock and
result = "do block"
}
}
/**
@@ -276,6 +278,30 @@ module SuccessorTypes {
final override string toString() { result = "redo" }
}
/**
* A `retry` control flow successor.
*
* Example:
*
* Example:
*
* ```rb
* def m
* begin
* puts "Retry"
* raise
* rescue
* retry
* end
* end
* ```
*
* The node `puts "Retry"` is `retry` successor of the node `retry`.
*/
class RetrySuccessor extends SuccessorType, TRetrySuccessor {
final override string toString() { result = "retry" }
}
/**
* An exceptional control flow successor.
*

View File

@@ -3,7 +3,7 @@
* will likely be part of the hand-written user-facing AST layer.
*/
import codeql_ruby.ast
private import codeql_ruby.ast
class LogicalNotAstNode extends Unary {
AstNode operand;

View File

@@ -4,7 +4,7 @@
* A completion represents how a statement or expression terminates.
*/
import codeql_ruby.ast
private import codeql_ruby.ast
private import codeql_ruby.controlflow.ControlFlowGraph
private import AstNodes
private import NonReturning
@@ -17,6 +17,7 @@ private newtype TCompletion =
TBreakCompletion() or
TNextCompletion() or
TRedoCompletion() or
TRetryCompletion() or
TRaiseCompletion() or // TODO: Add exception type?
TExitCompletion() or
TNestedCompletion(Completion inner, Completion outer) {
@@ -220,6 +221,16 @@ class RedoCompletion extends Completion, TRedoCompletion {
override string toString() { result = "redo" }
}
/**
* A completion that represents evaluation of a statement or an
* expression resulting in a retry.
*/
class RetryCompletion extends Completion, TRetryCompletion {
override RetrySuccessor getAMatchingSuccessorType() { any() }
override string toString() { result = "retry" }
}
/**
* A completion that represents evaluation of a statement or an
* expression resulting in a thrown exception.

View File

@@ -1,7 +1,7 @@
import codeql_ruby.ast
import codeql_ruby.controlflow.ControlFlowGraph
import Completion
import Splitting
private import codeql_ruby.ast
private import codeql_ruby.controlflow.ControlFlowGraph
private import Completion
private import Splitting
query predicate nonUniqueSetRepresentation(Splits s1, Splits s2) {
forex(Split s | s = s1.getASplit() | s = s2.getASplit()) and

View File

@@ -31,7 +31,7 @@
* caught up by its surrounding loop and turned into a `NormalCompletion`.
*/
import codeql_ruby.ast
private import codeql_ruby.ast
private import AstNodes
private import codeql_ruby.controlflow.ControlFlowGraph
private import Completion
@@ -501,6 +501,7 @@ private module Cached {
TBreakSuccessor() or
TNextSuccessor() or
TRedoSuccessor() or
TRetrySuccessor() or
TRaiseSuccessor() or // TODO: Add exception type?
TExitSuccessor()

View File

@@ -1,6 +1,6 @@
/** Provides a simple analysis for identifying calls that will not return. */
import codeql_ruby.ast
private import codeql_ruby.ast
private import Completion
/** A call that definitely does not return (conservative analysis). */

View File

@@ -2,7 +2,7 @@
* Provides classes and predicates relevant for splitting the control flow graph.
*/
import codeql_ruby.ast
private import codeql_ruby.ast
private import AstNodes
private import Completion
private import ControlFlowGraphImpl

View File

@@ -6,7 +6,7 @@
* to hold for only the AST nodes you wish to view.
*/
import codeql_ruby.ast
private import codeql_ruby.ast
/**
* The query can extend this class to control which nodes are printed.