Address comments

This commit is contained in:
Arthur Baars
2022-02-03 13:44:42 +01:00
parent a22868ba27
commit 6525035f0a
5 changed files with 29 additions and 16 deletions

View File

@@ -423,17 +423,17 @@ class ReferencePattern extends CasePattern, TReferencePattern {
any(Ruby::ExpressionReferencePattern g | this = TExpressionReferencePattern(g)).getValue()
}
/** Gets the value this reference pattern matches against. */
final Expr getValue() { toGenerated(result) = value }
/** Gets the value this reference pattern matches against. For example `2 * x` in `^(2 * x)` */
final Expr getExpr() { toGenerated(result) = value }
final override string getAPrimaryQlClass() { result = "ReferencePattern" }
final override string toString() { result = "^..." }
override AstNode getAChild(string pred) {
final override AstNode getAChild(string pred) {
result = super.getAChild(pred)
or
pred = "getValue" and result = this.getValue()
pred = "getExpr" and result = this.getExpr()
}
}
@@ -450,5 +450,5 @@ class ReferencePattern extends CasePattern, TReferencePattern {
*/
deprecated class VariableReferencePattern extends ReferencePattern, TVariableReferencePattern {
/** Gets the variable access corresponding to this variable reference pattern. */
final VariableReadAccess getVariableAccess() { result = this.getValue() }
final VariableReadAccess getVariableAccess() { result = this.getExpr() }
}

View File

@@ -1033,6 +1033,19 @@ private module ImplicitHashValueSynthesis {
}
}
/**
* ```rb
* def foo(&)
* bar(&)
* end
* ```
* desugars to,
* ```rb
* def foo(&__synth_0)
* bar(&__synth_0)
* end
* ```
*/
private module AnonymousBlockParameterSynth {
private BlockParameter anonymousBlockParameter() {
exists(Ruby::BlockParameter p | not exists(p.getName()) and toGenerated(result) = p)

View File

@@ -235,7 +235,7 @@ private predicate inMatchingContext(AstNode n) {
or
n instanceof CasePattern
or
n = any(ReferencePattern p).getValue()
n = any(ReferencePattern p).getExpr()
or
n.(Trees::DefaultValueParameterTree).hasDefaultValue()
}

View File

@@ -732,7 +732,7 @@ module Trees {
}
private class ReferencePatternTree extends StandardPreOrderTree, ReferencePattern {
override ControlFlowTree getChildElement(int i) { result = this.getValue() and i = 0 }
override ControlFlowTree getChildElement(int i) { result = this.getExpr() and i = 0 }
}
private class InClauseTree extends PreOrderTree, InClause {

View File

@@ -952,7 +952,7 @@ control/cases.rb:
# 87| getPattern: [IntegerLiteral] 5
# 88| getBranch: [InClause] in ... then ...
# 88| getPattern: [ReferencePattern] ^...
# 88| getValue: [LocalVariableAccess] foo
# 88| getExpr: [LocalVariableAccess] foo
# 89| getBranch: [InClause] in ... then ...
# 89| getPattern: [StringLiteral] "string"
# 89| getComponent: [StringTextComponent] string
@@ -1050,7 +1050,7 @@ control/cases.rb:
# 111| getPattern: [AlternativePattern] ... | ...
# 111| getAlternative: [IntegerLiteral] 5
# 111| getAlternative: [ReferencePattern] ^...
# 111| getValue: [LocalVariableAccess] foo
# 111| getExpr: [LocalVariableAccess] foo
# 111| getAlternative: [StringLiteral] "string"
# 111| getComponent: [StringTextComponent] string
# 111| getAlternative: [LocalVariableAccess] var
@@ -1146,28 +1146,28 @@ control/cases.rb:
# 147| getReceiver: [Self, SelfVariableAccess] self
# 148| getBranch: [InClause] in ... then ...
# 148| getPattern: [ReferencePattern] ^...
# 148| getValue: [LocalVariableAccess] foo
# 148| getExpr: [LocalVariableAccess] foo
# 149| getBranch: [InClause] in ... then ...
# 149| getPattern: [ReferencePattern] ^...
# 149| getValue: [GlobalVariableAccess] $foo
# 149| getExpr: [GlobalVariableAccess] $foo
# 150| getBranch: [InClause] in ... then ...
# 150| getPattern: [ReferencePattern] ^...
# 150| getValue: [InstanceVariableAccess] @foo
# 150| getExpr: [InstanceVariableAccess] @foo
# 151| getBranch: [InClause] in ... then ...
# 151| getPattern: [ReferencePattern] ^...
# 151| getValue: [ClassVariableAccess] @@foo
# 151| getExpr: [ClassVariableAccess] @@foo
# 154| getStmt: [CaseExpr] case ...
# 154| getValue: [MethodCall] call to expr
# 154| getReceiver: [Self, SelfVariableAccess] self
# 155| getBranch: [InClause] in ... then ...
# 155| getPattern: [ReferencePattern] ^...
# 155| getValue: [LocalVariableAccess] foo
# 155| getExpr: [LocalVariableAccess] foo
# 156| getBranch: [InClause] in ... then ...
# 156| getPattern: [ReferencePattern] ^...
# 156| getValue: [InstanceVariableAccess] @foo
# 156| getExpr: [InstanceVariableAccess] @foo
# 157| getBranch: [InClause] in ... then ...
# 157| getPattern: [ReferencePattern] ^...
# 157| getValue: [AddExpr] ... + ...
# 157| getExpr: [AddExpr] ... + ...
# 157| getAnOperand/getLeftOperand/getReceiver: [IntegerLiteral] 1
# 157| getAnOperand/getArgument/getRightOperand: [IntegerLiteral] 1
modules/classes.rb: