Files
codeql/ql/src/codeql_ruby/ast/Constant.qll
2021-02-11 12:29:25 +00:00

97 lines
2.3 KiB
Plaintext

private import codeql_ruby.AST
private import internal.Constant
/** An access to a constant. */
class ConstantAccess extends Expr {
override ConstantAccess::Range range;
/** Gets the name of the constant being accessed. */
string getName() { result = range.getName() }
/**
* Gets the expression used in the access's scope resolution operation, if
* any. In the following example, the result is the `Call` expression for
* `foo()`.
*
* ```rb
* foo()::MESSAGE
* ```
*
* However, there is no result for the following example, since there is no
* scope resolution operation.
*
* ```rb
* MESSAGE
* ```
*/
Expr getScopeExpr() { result = range.getScopeExpr() }
/**
* Holds if the access uses the scope resolution operator to refer to the
* global scope, as in this example:
*
* ```rb
* ::MESSAGE
* ```
*/
predicate hasGlobalScope() { range.hasGlobalScope() }
}
/**
* A use (read) of a constant.
*
* For example, the right-hand side of the assignment in:
*
* ```rb
* x = Foo
* ```
*
* Or the superclass `Bar` in this example:
*
* ```rb
* class Foo < Bar
* end
* ```
*/
class ConstantReadAccess extends ConstantAccess {
final override ConstantReadAccess::Range range;
final override string getAPrimaryQlClass() { result = "ConstantReadAccess" }
}
/**
* A definition of a constant.
*
* Examples:
*
* ```rb
* Foo = 1 # defines constant Foo as an integer
* M::Foo = 1 # defines constant Foo as an integer in module M
*
* class Bar; end # defines constant Bar as a class
* class M::Bar; end # defines constant Bar as a class in module M
*
* module Baz; end # defines constant Baz as a module
* module M::Baz; end # defines constant Baz as a module in module M
* ```
*/
class ConstantWriteAccess extends ConstantAccess {
override ConstantWriteAccess::Range range;
override string getAPrimaryQlClass() { result = "ConstantWriteAccess" }
}
/**
* A definition of a constant via assignment. For example, the left-hand
* operand in the following example:
*
* ```rb
* MAX_SIZE = 100
* ```
*/
class ConstantAssignment extends ConstantWriteAccess {
override ConstantAssignment::Range range;
override string getAPrimaryQlClass() { result = "ConstantAssignment" }
}