mirror of
https://github.com/github/codeql.git
synced 2026-02-20 08:53:49 +01:00
Simplify representation of calls that use scope resolution operator.
Now, `Foo::bar` is a call where the receiver expr is `Foo`.
This commit is contained in:
@@ -11,12 +11,16 @@ class Call extends Expr {
|
||||
|
||||
/**
|
||||
* Gets the receiver of this call, if any. For example:
|
||||
*
|
||||
* ```rb
|
||||
* foo.bar
|
||||
* baz()
|
||||
* Baz::qux
|
||||
* corge()
|
||||
* ```
|
||||
* The result for the call to `bar` is the `Expr` for `foo`, while the call
|
||||
* to `baz` has no result.
|
||||
*
|
||||
* The result for the call to `bar` is the `Expr` for `foo`; the result for
|
||||
* the call to `qux` is the `Expr` for `Baz`; for the call to `corge` there
|
||||
* is no result.
|
||||
*/
|
||||
final Expr getReceiver() { result = range.getReceiver() }
|
||||
|
||||
@@ -26,47 +30,11 @@ class Call extends Expr {
|
||||
* ```rb
|
||||
* foo.bar x, y
|
||||
* ```
|
||||
*
|
||||
* the result is `"bar"`.
|
||||
*
|
||||
* N.B. in the following example, where the method name uses the scope
|
||||
* resolution operator, the result is the name being resolved, i.e. `"bar"`.
|
||||
* Use `getMethodNameScopeExpr` to get the expression for `Foo`.
|
||||
*
|
||||
* ```rb
|
||||
* Foo::bar x, y
|
||||
* ```
|
||||
*/
|
||||
final string getMethodName() { result = range.getMethodName() }
|
||||
|
||||
/**
|
||||
* Gets the scope expression used in the method name's scope resolution
|
||||
* operation, if any.
|
||||
*
|
||||
* In the following example, the result is the `Expr` for `Foo`.
|
||||
*
|
||||
* ```rb
|
||||
* Foo::bar()
|
||||
* ```
|
||||
*
|
||||
* However, there is no result for the following example, since there is no
|
||||
* scope resolution operation.
|
||||
*
|
||||
* ```rb
|
||||
* baz()
|
||||
* ```
|
||||
*/
|
||||
final Expr getMethodNameScopeExpr() { result = range.getMethodNameScopeExpr() }
|
||||
|
||||
/**
|
||||
* Holds if the method name uses the scope resolution operator to access the
|
||||
* global scope, as in this example:
|
||||
*
|
||||
* ```rb
|
||||
* ::foo
|
||||
* ```
|
||||
*/
|
||||
final predicate methodNameHasGlobalScope() { range.methodNameHasGlobalScope() }
|
||||
|
||||
/**
|
||||
* Gets the `n`th argument of this method call. In the following example, the
|
||||
* result for n=0 is the `IntegerLiteral` 0, while for n=1 the result is a
|
||||
|
||||
@@ -9,10 +9,6 @@ module Call {
|
||||
|
||||
abstract string getMethodName();
|
||||
|
||||
abstract Expr getMethodNameScopeExpr();
|
||||
|
||||
abstract predicate methodNameHasGlobalScope();
|
||||
|
||||
abstract Expr getArgument(int n);
|
||||
|
||||
abstract Block getBlock();
|
||||
@@ -29,10 +25,6 @@ module Call {
|
||||
|
||||
final override string getMethodName() { result = generated.getValue() }
|
||||
|
||||
final override Expr getMethodNameScopeExpr() { none() }
|
||||
|
||||
final override predicate methodNameHasGlobalScope() { none() }
|
||||
|
||||
final override Expr getArgument(int n) { none() }
|
||||
|
||||
final override Block getBlock() { none() }
|
||||
@@ -48,14 +40,10 @@ module Call {
|
||||
not access(identifier, _)
|
||||
}
|
||||
|
||||
final override Expr getReceiver() { none() }
|
||||
final override Expr getReceiver() { result = generated.getScope() }
|
||||
|
||||
final override string getMethodName() { result = identifier.getValue() }
|
||||
|
||||
final override Expr getMethodNameScopeExpr() { result = generated.getScope() }
|
||||
|
||||
final override predicate methodNameHasGlobalScope() { not exists(generated.getScope()) }
|
||||
|
||||
final override Expr getArgument(int n) { none() }
|
||||
|
||||
final override Block getBlock() { none() }
|
||||
@@ -64,7 +52,11 @@ module Call {
|
||||
private class RegularCallRange extends Call::Range, @call {
|
||||
final override Generated::Call generated;
|
||||
|
||||
final override Expr getReceiver() { result = generated.getReceiver() }
|
||||
final override Expr getReceiver() {
|
||||
if exists(generated.getReceiver())
|
||||
then result = generated.getReceiver()
|
||||
else result = generated.getMethod().(Generated::ScopeResolution).getScope()
|
||||
}
|
||||
|
||||
final override string getMethodName() {
|
||||
result = generated.getMethod().(Generated::Token).getValue() or
|
||||
@@ -72,17 +64,6 @@ module Call {
|
||||
generated.getMethod().(Generated::ScopeResolution).getName().(Generated::Token).getValue()
|
||||
}
|
||||
|
||||
final override Expr getMethodNameScopeExpr() {
|
||||
result = generated.getMethod().(Generated::ScopeResolution).getScope()
|
||||
}
|
||||
|
||||
final override predicate methodNameHasGlobalScope() {
|
||||
exists(Generated::ScopeResolution sr |
|
||||
sr = generated.getMethod() and
|
||||
not exists(sr.getScope())
|
||||
)
|
||||
}
|
||||
|
||||
final override Expr getArgument(int n) { result = generated.getArguments().getChild(n) }
|
||||
|
||||
final override Block getBlock() { result = generated.getBlock() }
|
||||
@@ -97,10 +78,6 @@ module YieldCall {
|
||||
|
||||
final override string getMethodName() { result = "yield" }
|
||||
|
||||
final override Expr getMethodNameScopeExpr() { none() }
|
||||
|
||||
final override predicate methodNameHasGlobalScope() { none() }
|
||||
|
||||
final override Expr getArgument(int n) { result = generated.getChild().getChild(n) }
|
||||
|
||||
final override Block getBlock() { none() }
|
||||
@@ -121,10 +98,6 @@ module SuperCall {
|
||||
|
||||
final override string getMethodName() { result = generated.getValue() }
|
||||
|
||||
final override Expr getMethodNameScopeExpr() { none() }
|
||||
|
||||
final override predicate methodNameHasGlobalScope() { none() }
|
||||
|
||||
final override Expr getArgument(int n) { none() }
|
||||
|
||||
final override Block getBlock() { none() }
|
||||
@@ -141,10 +114,6 @@ module SuperCall {
|
||||
result = generated.getMethod().(Generated::Super).getValue()
|
||||
}
|
||||
|
||||
final override Expr getMethodNameScopeExpr() { none() }
|
||||
|
||||
final override predicate methodNameHasGlobalScope() { none() }
|
||||
|
||||
final override Expr getArgument(int n) { result = generated.getArguments().getChild(n) }
|
||||
|
||||
final override Block getBlock() { result = generated.getBlock() }
|
||||
|
||||
Reference in New Issue
Block a user