mirror of
https://github.com/github/codeql.git
synced 2026-04-22 23:35:14 +02:00
Rename (Hash)SplatArgument to (Hash)SplatExpr and make them UnaryOperations
This commit is contained in:
@@ -192,65 +192,3 @@ class BlockArgument extends Expr, TBlockArgument {
|
||||
pred = "getValue" and result = this.getValue()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A splat argument in a method call.
|
||||
* ```rb
|
||||
* foo(*args)
|
||||
* ```
|
||||
*/
|
||||
class SplatArgument extends Expr, TSplatArgument {
|
||||
private Generated::SplatArgument g;
|
||||
|
||||
SplatArgument() { this = TSplatArgument(g) }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "SplatArgument" }
|
||||
|
||||
/**
|
||||
* Gets the underlying expression. In the following example, the result is
|
||||
* the `Expr` for `bar`:
|
||||
* ```rb
|
||||
* foo(*bar)
|
||||
* ```
|
||||
*/
|
||||
final Expr getValue() { toGenerated(result) = g.getChild() }
|
||||
|
||||
final override string toString() { result = "*..." }
|
||||
|
||||
final override AstNode getAChild(string pred) {
|
||||
result = super.getAChild(pred)
|
||||
or
|
||||
pred = "getValue" and result = this.getValue()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A hash-splat (or 'double-splat') argument in a method call.
|
||||
* ```rb
|
||||
* foo(**options)
|
||||
* ```
|
||||
*/
|
||||
class HashSplatArgument extends Expr, THashSplatArgument {
|
||||
private Generated::HashSplatArgument g;
|
||||
|
||||
HashSplatArgument() { this = THashSplatArgument(g) }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "HashSplatArgument" }
|
||||
|
||||
/**
|
||||
* Gets the underlying expression. In the following example, the result is
|
||||
* the `Expr` for `bar`:
|
||||
* ```rb
|
||||
* foo(**bar)
|
||||
* ```
|
||||
*/
|
||||
final Expr getValue() { toGenerated(result) = g.getChild() }
|
||||
|
||||
final override string toString() { result = "**..." }
|
||||
|
||||
final override AstNode getAChild(string pred) {
|
||||
result = super.getAChild(pred)
|
||||
or
|
||||
pred = "getValue" and result = this.getValue()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -717,7 +717,7 @@ class HashLiteral extends Literal, THashLiteral {
|
||||
* Gets the `n`th element in this array literal.
|
||||
*
|
||||
* In the following example, the 0th element is a `Pair`, and the 1st element
|
||||
* is a `HashSplatArgument`.
|
||||
* is a `HashSplatExpr`.
|
||||
*
|
||||
* ```rb
|
||||
* { foo: 123, **bar }
|
||||
|
||||
@@ -24,14 +24,8 @@ class Operation extends Expr, TOperation {
|
||||
|
||||
/** A unary operation. */
|
||||
class UnaryOperation extends Operation, TUnaryOperation {
|
||||
private Generated::Unary g;
|
||||
|
||||
UnaryOperation() { g = toGenerated(this) }
|
||||
|
||||
/** Gets the operand of this unary operation. */
|
||||
final Expr getOperand() { toGenerated(result) = g.getOperand() }
|
||||
|
||||
final override string getOperator() { result = g.getOperator() }
|
||||
Expr getOperand() { none() }
|
||||
|
||||
final override Expr getAnOperand() { result = this.getOperand() }
|
||||
|
||||
@@ -44,8 +38,18 @@ class UnaryOperation extends Operation, TUnaryOperation {
|
||||
final override string toString() { result = this.getOperator() + " ..." }
|
||||
}
|
||||
|
||||
private class UnaryOperationGenerated extends UnaryOperation, TUnaryOperation {
|
||||
private Generated::Unary g;
|
||||
|
||||
UnaryOperationGenerated() { g = toGenerated(this) }
|
||||
|
||||
final override Expr getOperand() { toGenerated(result) = g.getOperand() }
|
||||
|
||||
final override string getOperator() { result = g.getOperator() }
|
||||
}
|
||||
|
||||
/** A unary logical operation. */
|
||||
class UnaryLogicalOperation extends UnaryOperation, TUnaryLogicalOperation { }
|
||||
class UnaryLogicalOperation extends UnaryOperationGenerated, TUnaryLogicalOperation { }
|
||||
|
||||
/**
|
||||
* A logical NOT operation, using either `!` or `not`.
|
||||
@@ -59,7 +63,7 @@ class NotExpr extends UnaryLogicalOperation, TNotExpr {
|
||||
}
|
||||
|
||||
/** A unary arithmetic operation. */
|
||||
class UnaryArithmeticOperation extends UnaryOperation, TUnaryArithmeticOperation { }
|
||||
class UnaryArithmeticOperation extends UnaryOperationGenerated, TUnaryArithmeticOperation { }
|
||||
|
||||
/**
|
||||
* A unary plus expression.
|
||||
@@ -81,6 +85,42 @@ class UnaryMinusExpr extends UnaryArithmeticOperation, TUnaryMinusExpr {
|
||||
final override string getAPrimaryQlClass() { result = "UnaryMinusExpr" }
|
||||
}
|
||||
|
||||
/**
|
||||
* A splat expression.
|
||||
* ```rb
|
||||
* foo(*args)
|
||||
* ```
|
||||
*/
|
||||
class SplatExpr extends UnaryOperation, TSplatArgument {
|
||||
private Generated::SplatArgument g;
|
||||
|
||||
SplatExpr() { this = TSplatArgument(g) }
|
||||
|
||||
final override Expr getOperand() { toGenerated(result) = g.getChild() }
|
||||
|
||||
final override string getOperator() { result = "*" }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "SplatExpr" }
|
||||
}
|
||||
|
||||
/**
|
||||
* A hash-splat (or 'double-splat') expression.
|
||||
* ```rb
|
||||
* foo(**options)
|
||||
* ```
|
||||
*/
|
||||
class HashSplatExpr extends UnaryOperation, THashSplatArgument {
|
||||
private Generated::HashSplatArgument g;
|
||||
|
||||
HashSplatExpr() { this = THashSplatArgument(g) }
|
||||
|
||||
final override Expr getOperand() { toGenerated(result) = g.getChild() }
|
||||
|
||||
final override string getOperator() { result = "**" }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "HashSplatExpr" }
|
||||
}
|
||||
|
||||
/** A unary bitwise operation. */
|
||||
class UnaryBitwiseOperation extends UnaryOperation, TUnaryBitwiseOperation { }
|
||||
|
||||
|
||||
@@ -585,7 +585,8 @@ class TNamespace = TClassDeclaration or TModuleDeclaration;
|
||||
class TOperation = TUnaryOperation or TBinaryOperation or TAssignment;
|
||||
|
||||
class TUnaryOperation =
|
||||
TUnaryLogicalOperation or TUnaryArithmeticOperation or TUnaryBitwiseOperation or TDefinedExpr;
|
||||
TUnaryLogicalOperation or TUnaryArithmeticOperation or TUnaryBitwiseOperation or TDefinedExpr or
|
||||
TSplatArgument or THashSplatArgument;
|
||||
|
||||
class TUnaryLogicalOperation = TNotExpr;
|
||||
|
||||
|
||||
@@ -853,10 +853,6 @@ module Trees {
|
||||
final override ControlFlowTree getChildNode(int i) { result = this.getElement(i) }
|
||||
}
|
||||
|
||||
private class HashSplatArgumentTree extends StandardPostOrderTree, HashSplatArgument {
|
||||
final override ControlFlowTree getChildNode(int i) { result = this.getValue() and i = 0 }
|
||||
}
|
||||
|
||||
private class HashSplatParameterTree extends NonDefaultValueParameterTree, HashSplatParameter { }
|
||||
|
||||
private class HereDocTree extends StandardPreOrderTree, HereDoc {
|
||||
@@ -1172,10 +1168,6 @@ module Trees {
|
||||
}
|
||||
}
|
||||
|
||||
private class SplatArgumentTree extends StandardPostOrderTree, SplatArgument {
|
||||
final override ControlFlowTree getChildNode(int i) { result = this.getValue() and i = 0 }
|
||||
}
|
||||
|
||||
private class SplatParameterTree extends NonDefaultValueParameterTree, SplatParameter { }
|
||||
|
||||
class StmtSequenceTree extends PostOrderTree, StmtSequence {
|
||||
|
||||
@@ -432,23 +432,23 @@ calls/calls.rb:
|
||||
# 267| getReceiver: [ConstantReadAccess] X
|
||||
# 270| getStmt: [MethodCall] call to foo
|
||||
# 270| getReceiver: [Self] self
|
||||
# 270| getArgument: [SplatArgument] *...
|
||||
# 270| getValue: [MethodCall] call to bar
|
||||
# 270| getArgument: [SplatExpr] * ...
|
||||
# 270| getAnOperand/getOperand: [MethodCall] call to bar
|
||||
# 270| getReceiver: [Self] self
|
||||
# 271| getStmt: [MethodCall] call to foo
|
||||
# 271| getReceiver: [Self] self
|
||||
# 271| getArgument: [SplatArgument] *...
|
||||
# 271| getValue: [MethodCall] call to bar
|
||||
# 271| getArgument: [SplatExpr] * ...
|
||||
# 271| getAnOperand/getOperand: [MethodCall] call to bar
|
||||
# 271| getReceiver: [ConstantReadAccess] X
|
||||
# 274| getStmt: [MethodCall] call to foo
|
||||
# 274| getReceiver: [Self] self
|
||||
# 274| getArgument: [HashSplatArgument] **...
|
||||
# 274| getValue: [MethodCall] call to bar
|
||||
# 274| getArgument: [HashSplatExpr] ** ...
|
||||
# 274| getAnOperand/getOperand: [MethodCall] call to bar
|
||||
# 274| getReceiver: [Self] self
|
||||
# 275| getStmt: [MethodCall] call to foo
|
||||
# 275| getReceiver: [Self] self
|
||||
# 275| getArgument: [HashSplatArgument] **...
|
||||
# 275| getValue: [MethodCall] call to bar
|
||||
# 275| getArgument: [HashSplatExpr] ** ...
|
||||
# 275| getAnOperand/getOperand: [MethodCall] call to bar
|
||||
# 275| getReceiver: [ConstantReadAccess] X
|
||||
# 278| getStmt: [MethodCall] call to foo
|
||||
# 278| getReceiver: [Self] self
|
||||
@@ -1102,8 +1102,8 @@ literals/literals.rb:
|
||||
# 114| getElement: [Pair] Pair
|
||||
# 114| getKey: [SymbolLiteral] :foo
|
||||
# 114| getValue: [IntegerLiteral] 7
|
||||
# 114| getElement: [HashSplatArgument] **...
|
||||
# 114| getValue: [MethodCall] call to bar
|
||||
# 114| getElement: [HashSplatExpr] ** ...
|
||||
# 114| getAnOperand/getOperand: [MethodCall] call to bar
|
||||
# 114| getReceiver: [Self] self
|
||||
# 117| getStmt: [ParenthesizedExpr] ( ... )
|
||||
# 117| getStmt: [RangeLiteral] _ .. _
|
||||
@@ -1621,14 +1621,14 @@ operations/operations.rb:
|
||||
# 29| getStmt: [ReturnStmt] return
|
||||
# 29| getValue: [ArgumentList] ..., ...
|
||||
# 29| getElement: [IntegerLiteral] 1
|
||||
# 29| getElement: [SplatArgument] *...
|
||||
# 29| getValue: [ArrayLiteral] [...]
|
||||
# 29| getElement: [SplatExpr] * ...
|
||||
# 29| getAnOperand/getOperand: [ArrayLiteral] [...]
|
||||
# 29| getElement: [IntegerLiteral] 2
|
||||
# 29| getElement: [Pair] Pair
|
||||
# 29| getKey: [SymbolLiteral] :a
|
||||
# 29| getValue: [IntegerLiteral] 3
|
||||
# 29| getElement: [HashSplatArgument] **...
|
||||
# 29| getValue: [HashLiteral] {...}
|
||||
# 29| getElement: [HashSplatExpr] ** ...
|
||||
# 29| getAnOperand/getOperand: [HashLiteral] {...}
|
||||
# 29| getElement: [Pair] Pair
|
||||
# 29| getKey: [SymbolLiteral] :b
|
||||
# 29| getValue: [IntegerLiteral] 4
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
blockArguments
|
||||
| calls.rb:266:5:266:8 | &... | calls.rb:266:6:266:8 | call to bar |
|
||||
| calls.rb:267:5:267:11 | &... | calls.rb:267:6:267:11 | call to bar |
|
||||
splatArguments
|
||||
| calls.rb:270:5:270:8 | *... | calls.rb:270:6:270:8 | call to bar |
|
||||
| calls.rb:271:5:271:11 | *... | calls.rb:271:6:271:11 | call to bar |
|
||||
hashSplatArguments
|
||||
| calls.rb:274:5:274:9 | **... | calls.rb:274:7:274:9 | call to bar |
|
||||
| calls.rb:275:5:275:12 | **... | calls.rb:275:7:275:12 | call to bar |
|
||||
splatExpr
|
||||
| calls.rb:270:5:270:8 | * ... | calls.rb:270:6:270:8 | call to bar |
|
||||
| calls.rb:271:5:271:11 | * ... | calls.rb:271:6:271:11 | call to bar |
|
||||
hashSplatExpr
|
||||
| calls.rb:274:5:274:9 | ** ... | calls.rb:274:7:274:9 | call to bar |
|
||||
| calls.rb:275:5:275:12 | ** ... | calls.rb:275:7:275:12 | call to bar |
|
||||
keywordArguments
|
||||
| calls.rb:278:5:278:13 | Pair | calls.rb:278:5:278:8 | :blah | calls.rb:278:11:278:13 | call to bar |
|
||||
| calls.rb:279:5:279:16 | Pair | calls.rb:279:5:279:8 | :blah | calls.rb:279:11:279:16 | call to bar |
|
||||
|
||||
@@ -2,9 +2,9 @@ import ruby
|
||||
|
||||
query predicate blockArguments(BlockArgument a, Expr e) { e = a.getValue() }
|
||||
|
||||
query predicate splatArguments(SplatArgument a, Expr e) { e = a.getValue() }
|
||||
query predicate splatExpr(SplatExpr a, Expr e) { e = a.getOperand() }
|
||||
|
||||
query predicate hashSplatArguments(HashSplatArgument a, Expr e) { e = a.getValue() }
|
||||
query predicate hashSplatExpr(HashSplatExpr a, Expr e) { e = a.getOperand() }
|
||||
|
||||
query predicate keywordArguments(Pair a, Expr key, Expr value) {
|
||||
exists(Call c | c.getAnArgument() = a and key = a.getKey() and value = a.getValue())
|
||||
|
||||
@@ -16,10 +16,10 @@ callsWithArguments
|
||||
| calls.rb:235:1:235:14 | ...[...] | [] | 0 | calls.rb:235:8:235:13 | call to bar |
|
||||
| calls.rb:266:1:266:9 | call to foo | foo | 0 | calls.rb:266:5:266:8 | &... |
|
||||
| calls.rb:267:1:267:12 | call to foo | foo | 0 | calls.rb:267:5:267:11 | &... |
|
||||
| calls.rb:270:1:270:9 | call to foo | foo | 0 | calls.rb:270:5:270:8 | *... |
|
||||
| calls.rb:271:1:271:12 | call to foo | foo | 0 | calls.rb:271:5:271:11 | *... |
|
||||
| calls.rb:274:1:274:10 | call to foo | foo | 0 | calls.rb:274:5:274:9 | **... |
|
||||
| calls.rb:275:1:275:13 | call to foo | foo | 0 | calls.rb:275:5:275:12 | **... |
|
||||
| calls.rb:270:1:270:9 | call to foo | foo | 0 | calls.rb:270:5:270:8 | * ... |
|
||||
| calls.rb:271:1:271:12 | call to foo | foo | 0 | calls.rb:271:5:271:11 | * ... |
|
||||
| calls.rb:274:1:274:10 | call to foo | foo | 0 | calls.rb:274:5:274:9 | ** ... |
|
||||
| calls.rb:275:1:275:13 | call to foo | foo | 0 | calls.rb:275:5:275:12 | ** ... |
|
||||
| calls.rb:278:1:278:14 | call to foo | foo | 0 | calls.rb:278:5:278:13 | Pair |
|
||||
| calls.rb:279:1:279:17 | call to foo | foo | 0 | calls.rb:279:5:279:16 | Pair |
|
||||
| calls.rb:288:5:288:16 | call to super | super | 0 | calls.rb:288:11:288:16 | "blah" |
|
||||
|
||||
@@ -622,7 +622,7 @@ hashLiteralElements
|
||||
| literals.rb:113:1:113:33 | {...} | 1 | literals.rb:113:11:113:19 | Pair | Pair |
|
||||
| literals.rb:113:1:113:33 | {...} | 2 | literals.rb:113:22:113:31 | Pair | Pair |
|
||||
| literals.rb:114:1:114:17 | {...} | 0 | literals.rb:114:3:114:8 | Pair | Pair |
|
||||
| literals.rb:114:1:114:17 | {...} | 1 | literals.rb:114:11:114:15 | **... | HashSplatArgument |
|
||||
| literals.rb:114:1:114:17 | {...} | 1 | literals.rb:114:11:114:15 | ** ... | HashSplatExpr |
|
||||
hashLiteralKeyValuePairs
|
||||
| literals.rb:84:1:84:14 | {...} | literals.rb:84:3:84:12 | Pair | literals.rb:84:3:84:5 | :foo | literals.rb:84:8:84:12 | "bar" |
|
||||
| literals.rb:113:1:113:33 | {...} | literals.rb:113:3:113:8 | Pair | literals.rb:113:3:113:5 | :foo | literals.rb:113:8:113:8 | 1 |
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
| operations.rb:26:1:26:2 | - ... | - | operations.rb:26:2:26:2 | 7 | UnaryMinusExpr |
|
||||
| operations.rb:27:1:27:2 | ~ ... | ~ | operations.rb:27:2:27:2 | x | ComplementExpr |
|
||||
| operations.rb:28:1:28:12 | defined? ... | defined? | operations.rb:28:10:28:12 | foo | DefinedExpr |
|
||||
| operations.rb:29:20:29:23 | * ... | * | operations.rb:29:21:29:23 | [...] | SplatExpr |
|
||||
| operations.rb:29:31:29:42 | ** ... | ** | operations.rb:29:33:29:42 | {...} | HashSplatExpr |
|
||||
| operations.rb:32:1:32:7 | ... + ... | + | operations.rb:32:1:32:1 | w | AddExpr |
|
||||
| operations.rb:32:1:32:7 | ... + ... | + | operations.rb:32:5:32:7 | 234 | AddExpr |
|
||||
| operations.rb:33:1:33:6 | ... - ... | - | operations.rb:33:1:33:1 | x | SubExpr |
|
||||
|
||||
@@ -5,6 +5,8 @@ unaryOperations
|
||||
| operations.rb:26:1:26:2 | - ... | - | operations.rb:26:2:26:2 | 7 | UnaryMinusExpr |
|
||||
| operations.rb:27:1:27:2 | ~ ... | ~ | operations.rb:27:2:27:2 | x | ComplementExpr |
|
||||
| operations.rb:28:1:28:12 | defined? ... | defined? | operations.rb:28:10:28:12 | foo | DefinedExpr |
|
||||
| operations.rb:29:20:29:23 | * ... | * | operations.rb:29:21:29:23 | [...] | SplatExpr |
|
||||
| operations.rb:29:31:29:42 | ** ... | ** | operations.rb:29:33:29:42 | {...} | HashSplatExpr |
|
||||
unaryLogicalOperations
|
||||
| operations.rb:23:1:23:2 | ! ... | ! | operations.rb:23:2:23:2 | a | NotExpr |
|
||||
| operations.rb:24:1:24:5 | not ... | not | operations.rb:24:5:24:5 | b | NotExpr |
|
||||
|
||||
@@ -1201,11 +1201,11 @@ cfg.rb:
|
||||
# 98| {...}
|
||||
#-----| -> ... = ...
|
||||
|
||||
# 98| **...
|
||||
# 98| ** ...
|
||||
#-----| -> "x"
|
||||
|
||||
# 98| map1
|
||||
#-----| -> **...
|
||||
#-----| -> ** ...
|
||||
|
||||
# 98| Pair
|
||||
#-----| -> map1
|
||||
@@ -1216,11 +1216,11 @@ cfg.rb:
|
||||
# 98| "y"
|
||||
#-----| -> Pair
|
||||
|
||||
# 98| **...
|
||||
# 98| ** ...
|
||||
#-----| -> {...}
|
||||
|
||||
# 98| map1
|
||||
#-----| -> **...
|
||||
#-----| -> ** ...
|
||||
|
||||
# 101| enter parameters
|
||||
#-----| -> value
|
||||
@@ -1676,11 +1676,11 @@ cfg.rb:
|
||||
# 158| self
|
||||
#-----| -> 1
|
||||
|
||||
# 158| *...
|
||||
# 158| * ...
|
||||
#-----| -> call to two_parameters
|
||||
|
||||
# 158| [...]
|
||||
#-----| -> *...
|
||||
#-----| -> * ...
|
||||
|
||||
# 158| 1
|
||||
#-----| -> 2
|
||||
|
||||
Reference in New Issue
Block a user