CodeQL library for Ruby
codeql/ruby-all 0.8.15-dev (changelog, source)
Search

Module AST

Import path

import codeql.ruby.AST

Imports

Locations

Provides classes for working with locations.

Classes

AddExpr

An add expression. rb x + 1

AddExprRoot

A series of add expressions, e.g. 1 + 2 + 3. This class is used to represent the root of such a series, and the getALeaf predicate can be used to get the leaf nodes.

AliasStmt

An alias statement. For example: rb - alias alias_name method_name - alias foo :method_name - alias bar :"method_#{ name }"

AlternativePattern

A composite pattern matching one of the given sub-patterns, for example: rb in 1 | 2 | 3

ArgumentList

A sequence of expressions in the right-hand side of an assignment or a return, break or next statement. rb x = 1, *items, 3, *more return 1, 2 next *list break **map return 1, 2, *items, k: 5, **map

ArrayLiteral

An array literal.

ArrayPattern

An array pattern, for example: rb in [] in ["first", Integer => x, "last"] in ["a", Integer => x, *] in ["a", Integer => x, ] in [1, 2, *x, 7, 8] in [*init, 7, 8] in List["a", Integer => x, *tail]

AsPattern

A pattern match that binds to the specified local variable, for example Integer => a in the following: rb case 1 in Integer => a then puts "#{a} is an integer value" end

AssignAddExpr

A += assignment expression. rb x += 1

AssignArithmeticOperation

An arithmetic assignment operation: +=, -=, *=, /=, **=, and %=.

AssignBitwiseAndExpr

A bitwise AND assignment operation. rb x &= 0xff

AssignBitwiseOperation

A bitwise assignment operation: <<=, >>=, &=, |= and ^=.

AssignBitwiseOrExpr

A bitwise OR assignment operation. rb x |= 0x01

AssignBitwiseXorExpr

An XOR (exclusive OR) assignment operation. rb x ^= y

AssignDivExpr

A /= assignment expression. rb x /= y

AssignExponentExpr

A **= assignment expression. rb x **= 2

AssignExpr

An assignment operation with the operator =. rb x = 123

AssignLShiftExpr

A left-shift assignment operation. rb x <<= 3

AssignLogicalAndExpr

A logical AND assignment operation. rb x &&= y.even?

AssignLogicalOperation

A logical assignment operation: &&= and ||=.

AssignLogicalOrExpr

A logical OR assignment operation. rb x ||= y

AssignModuloExpr

A %= assignment expression. rb x %= 4

AssignMulExpr

A *= assignment expression. rb x *= 10

AssignOperation

A binary assignment operation other than =.

AssignRShiftExpr

A right-shift assignment operation. rb x >>= 3

AssignSubExpr

A -= assignment expression. rb x -= 3

Assignment

A binary assignment operation, including =, +=, &=, etc.

AstNode

A node in the abstract syntax tree. This class is the base class for all Ruby program elements.

BeginBlock

A BEGIN block. rb BEGIN { puts "starting ..." }

BeginExpr

A begin statement. rb begin puts "hello world" end

BinaryArithmeticOperation

A binary arithmetic operation.

BinaryBitwiseOperation

A binary bitwise operation.

BinaryLogicalOperation

A binary logical operation.

BinaryOperation

A binary operation.

BitwiseAndExpr

A bitwise AND operation. rb x & 0xff

BitwiseOrExpr

A bitwise OR operation. rb x | 0x01

BitwiseXorExpr

An XOR (exclusive OR) operation. rb x ^ y

Block

A block.

BlockArgument

A block argument in a method call. rb foo(&block)

BlockParameter

A parameter that is a block. For example, &bar in the following code: rb def foo(&bar) bar.call if block_given? end

BodyStmt

A sequence of statements representing the body of a method, class, module, or do-block. That is, any body that may also include rescue/ensure/else statements.

BooleanLiteral

A Boolean literal. rb true false TRUE FALSE

BraceBlock

A block defined using curly braces, e.g. in the following code: rb names.each { |name| puts name }

BreakStmt

A break statement. rb break break value

Call

A call.

Callable

A callable.

CaseEqExpr

A case-equality (or ‘threequals’) expression. rb String === "foo"

CaseExpr

A case statement. There are three forms of case statements:

CasePattern

A pattern used in a case-in expression. For example rb case expr in [ x ] then ... in Point(a:, b:) then ... in Integer => x then ... end

CharacterLiteral

A character literal.

ClassDeclaration

A class definition.

ClassVariable

A class variable.

ClassVariableAccess

An access to a class variable.

ClassVariableReadAccess

An access to a class variable where the value is read.

ClassVariableWriteAccess

An access to a class variable where the value is updated.

ComparisonOperation

A comparison operation. That is, either an equality operation or a relational operation.

ComplementExpr

A complement (bitwise NOT) expression. rb ~x

ComplexLiteral

A complex literal.

ConditionalExpr

A conditional expression: if/unless (including expression-modifier variants), and ternary-if (?:) expressions.

ConditionalLoop

A loop using a condition expression. That is, a while or until loop, or their expression-modifier variants.

ConstantAccess

An access to a constant.

ConstantAssignment

A definition of a constant via assignment. For example, the left-hand operand in the following example:

ConstantReadAccess

A use (read) of a constant.

ConstantValue

A constant value.

ConstantWriteAccess

A definition of a constant.

ControlExpr

A control expression that can be any of the following: - case - if/unless (including expression-modifier variants) - ternary-if (?:) - while/until (including expression-modifier variants) - for

DefinedExpr

A call to the special defined? operator. rb defined? some_method

DestructuredLhsExpr

A “left-hand-side” (LHS) expression of a destructured assignment.

DestructuredParameter

A parameter defined using destructuring. For example

DivExpr

A divide expression. rb x / y

DoBlock

A block enclosed within do and end.

ElementReference

An element reference; a call to the [] method. rb a[0]

EmptyStmt

An empty statement (;).

EncodingLiteral

An __ENCODING__ literal.

EndBlock

An END block. rb END { puts "shutting down" }

EqExpr

An equals expression. rb x == y

EqualityOperation

An equality operation.

ErbAstNode

A node in the ERB abstract syntax tree. This class is the base class for all ERB elements.

ErbCode

An ERB token appearing within a code directive. This will typically be interpreted as Ruby code or a GraphQL query, depending on context.

ErbComment

An ERB token appearing within a comment directive.

ErbCommentDirective

A comment directive in an ERB template. erb <%#= 2 + 2 %> <%# for x in xs do %>

ErbDirective

A directive in an ERB template.

ErbExecutionDirective

An execution directive in an ERB template. This code will be executed as Ruby, but not rendered. erb <% books = author.books for book in books do %>

ErbFile

A File containing an Embedded Ruby template. This is typically a file containing snippets of Ruby code that can be evaluated to create a compiled version of the file.

ErbGraphqlDirective

A GraphQL directive in an ERB template. erb <%graphql fragment Foo on Bar { some { queryText moreProperties } } %>

ErbOutputDirective

An output directive in an ERB template. erb <%= fragment Foo on Bar { some { queryText moreProperties } } %>

ErbTemplate

An ERB template. This can contain multiple directives to be executed when the template is compiled.

ErbToken

An ERB token. This could be embedded code, a comment, or arbitrary text.

ExponentExpr

An exponent expression. rb x ** 2

Expr

An expression.

FileLiteral

A __FILE__ literal.

FindPattern

A find pattern, for example: rb in [*, "a", Integer => x, *] in List[*init, "a", Integer => x, *tail] in List[*, "a", Integer => x, *]

FloatLiteral

A floating-point literal.

ForExpr

A for loop. rb for val in 1..n sum += val end

ForwardParameter

A special ... parameter that forwards positional/keyword/block arguments: rb def foo(...) end

ForwardedArguments

A ... expression that contains forwarded arguments. rb foo(...)

GEExpr

A greater-than-or-equal expression. rb x >= 0

GTExpr

A greater-than expression. rb x > 0

GlobalVariable

A global variable.

GlobalVariableAccess

An access to a global variable.

GlobalVariableReadAccess

An access to a global variable where the value is read.

GlobalVariableWriteAccess

An access to a global variable where the value is updated.

HashLiteral

A hash literal.

HashPattern

A hash pattern, for example: rb in {} in { a: 1 } in { a: 1, **rest } in { a: 1, **nil } in Node{ label: , children: [] }

HashSplatExpr

A hash-splat (or ‘double-splat’) expression. rb foo(**options)

HashSplatNilParameter

A nil hash splat (**nil) indicating that there are no keyword parameters or keyword patterns. For example: rb def foo(bar, **nil) case bar in { x:, **nil } then puts x end end

HashSplatParameter

A hash-splat (or double-splat) parameter. For example, **options in the following code: rb def foo(bar, **options) ... end

HereDoc

A “here document”. For example: rb query = <<SQL SELECT * FROM person WHERE age > 21 SQL

IfExpr

An if or elsif expression. rb if x a += 1 elsif y a += 2 end

IfModifierExpr

An expression modified using if. rb foo if bar

InClause

An in clause of a case expression. rb case foo in [ a ] then a end

InstanceVariable

An instance variable.

InstanceVariableAccess

An access to an instance variable.

InstanceVariableReadAccess

An access to an instance variable where the value is read.

InstanceVariableWriteAccess

An access to an instance variable where the value is updated.

IntegerLiteral

An integer literal.

KeywordParameter

A keyword parameter, including a default value if the parameter is optional. For example, in the following example, foo is a keyword parameter with a default value of 0, and bar is a mandatory keyword parameter with no default value mandatory parameter). rb def f(foo: 0, bar:) foo * 10 + bar end

LEExpr

A less-than-or-equal expression. rb x <= 10

LShiftExpr

A left-shift operation. rb x << n

LTExpr

A less-than expression. rb x < 10

Lambda

A lambda (anonymous method). For example: rb -> (x) { x + 1 }

LhsExpr

A “left-hand-side” (LHS) expression. An LhsExpr can occur on the left-hand side of operator assignments (AssignOperation), on the left-hand side of assignments (AssignExpr), as patterns in for loops (ForExpr), and as exception variables in rescue clauses (RescueClause).

LineLiteral

A __LINE__ literal.

Literal

A literal.

LocalVariable

A local variable.

LocalVariableAccess

An access to a local variable.

LocalVariableReadAccess

An access to a local variable where the value is read.

LocalVariableWriteAccess

An access to a local variable where the value is updated.

LogicalAndExpr

A logical AND operation, using either and or &&. rb x and y a && b

LogicalOrExpr

A logical OR operation, using either or or ||. rb x or y a || b

Loop

A loop. That is, a for loop, a while or until loop, or their expression-modifier variants.

MatchPattern

A one-line pattern match using the => operator. For example: rb foo => Point{ x:, y: }

Method

A normal method.

MethodBase

A method.

MethodCall

A method call.

MethodName

A method name literal. For example: rb method_name # a normal name + # an operator :method_name # a symbol :"eval_#{name}" # a complex symbol

Module

A representation of a run-time module or class value.

ModuleBase

The base class for classes, singleton classes, and modules.

ModuleDeclaration

A module definition.

ModuloExpr

A modulo expression. rb x % 2

MulExpr

A multiply expression. rb x * 10

NEExpr

A not-equals expression. rb x != y

NamedParameter

A named parameter.

Namespace

A class or module definition.

NextStmt

A next statement. rb next next value

NilLiteral

A nil literal.

NoRegExpMatchExpr

A regexp-doesn’t-match expression. rb input !~ /\d/

NotExpr

A logical NOT operation, using either ! or not. rb !x.nil? not params.empty?

NumericLiteral

A numeric literal, i.e. an integer, floating-point, rational, or complex value.

Operation

An operation.

OptionalParameter

An optional parameter. For example, the parameter name in the following code: rb def say_hello(name = 'Anon') puts "hello #{name}" end

Pair

A pair expression. For example, in a hash: rb { foo: bar } Or a keyword argument: rb baz(qux: 1)

Parameter

A parameter.

ParenthesizedExpr

A parenthesized expression sequence, typically containing a single expression: rb (x + 1) However, they can also contain multiple expressions (the value of the parenthesized expression is the last expression): rb (foo; bar) or even an empty sequence (value is nil): rb ()

ParenthesizedPattern

A parenthesized pattern: rb in (1 ..) in (0 | "" | [] | {})

RShiftExpr

A right-shift operation. rb x >> n

RangeLiteral

A range literal.

RationalLiteral

A rational literal.

RedoStmt

A redo statement. rb redo

ReferencePattern

A variable or value reference in a pattern, i.e. ^x, and ^(2 * x) in the following example: rb x = 10 case expr in ^x then puts "ok" in ^(2 * x) then puts "ok" end

RegExpComponent

The base class for a component of a regular expression literal.

RegExpEscapeSequenceComponent

An escape sequence component of a regex literal.

RegExpInterpolationComponent

An interpolation expression component of a regex literal.

RegExpLiteral

A regular expression literal.

RegExpMatchExpr

A regexp match expression. rb input =~ /\d/

RegExpTextComponent

A component of a regex literal that is simply text.

RelationalOperation

A relational operation, that is, one of <=, <, >, or >=.

RescueClause

A rescue clause. For example:

RescueModifierExpr

An expression with a rescue modifier. For example: rb contents = read_file rescue ""

RetryStmt

A retry statement. rb retry

ReturnStmt

A return statement. rb return return value

ReturningStmt

A statement that may return a value: return, break and next.

RubyFile

A Ruby source file

Scope

A variable scope. This is either a top-level (file), a module, a class, or a callable.

SelfScope

A scope in which a self variable exists.

SelfVariable

A self variable.

SelfVariableAccess

An access to the self variable. For example: - self == other - self.method_name - def self.method_name ... end

SelfVariableReadAccess

An access to the self variable where the value is read.

SetterMethodCall

A call to a setter method. rb self.foo = 10 a[0] = 10

SimpleParameter

A simple (normal) parameter.

SingletonClass

A definition of a singleton class on an object.

SingletonMethod

A singleton method.

SpaceshipExpr

A three-way comparison (‘spaceship’) expression. rb a <=> b

SplatExpr

A splat expression. rb foo(*args)

SplatParameter

A splat parameter. For example, *values in the following code: rb def foo(bar, *values) ... end

Stmt

A statement.

StmtSequence

A sequence of expressions.

StringComponent

The base class for a component of a string: StringTextComponent, StringEscapeSequenceComponent, or StringInterpolationComponent.

StringConcatenation

A concatenation of string literals.

StringEscapeSequenceComponent

An escape sequence component of a string or string-like literal.

StringInterpolationComponent

An interpolation expression component of a string or string-like literal.

StringLiteral

A string literal.

StringTextComponent

A component of a string (or string-like) literal that is simply text.

StringlikeLiteral

A string, symbol, regexp, or subshell literal.

SubExpr

A subtract expression. rb x - 3

SubshellLiteral

A subshell literal.

SuperCall

A call to super. rb class Foo < Bar def baz super end end

SymbolLiteral

A symbol literal.

TernaryIfExpr

A conditional expression using the ternary (?:) operator. rb (a > b) ? a : b

TestPattern

A one-line pattern match using the in operator. For example: rb foo in Point{ x:, y: }

Toplevel

A Ruby source file.

UnaryArithmeticOperation

A unary arithmetic operation.

UnaryBitwiseOperation

A unary bitwise operation.

UnaryLogicalOperation

A unary logical operation.

UnaryMinusExpr

A unary minus expression. rb - a

UnaryOperation

A unary operation.

UnaryPlusExpr

A unary plus expression. rb + a

UndefStmt

An undef statement. For example: rb - undef method_name - undef &&, :method_name - undef :"method_#{ name }"

UnknownMethodCall

A Method call that has no known target. These will typically be calls to methods inherited from a superclass. TODO: When API Graphs is able to resolve calls to methods like Kernel.send this class is no longer necessary and should be removed.

UnlessExpr

An unless expression. rb unless x == 0 y /= x end

UnlessModifierExpr

An expression modified using unless. rb y /= x unless x == 0

UntilExpr

An until loop. rb until a >= b p a a += 1 end

UntilModifierExpr

An expression looped using the until modifier. rb foo until bar

Variable

A variable declared in a scope.

VariableAccess

An access to a variable.

VariableReadAccess

An access to a variable where the value is read.

VariableWriteAccess

An access to a variable where the value is updated.

WhenClause

A when branch of a case expression. rb case when a > b then x end

WhileExpr

A while loop. rb while a < b p a a += 2 end

WhileModifierExpr

An expression looped using the while modifier. rb foo while bar

YieldCall

A call to yield. rb yield x, y

Modules

ConstantValue

Provides different sub classes of ConstantValue.