Skip to content

class Crystal::Const
inherits Crystal::NamedType

A constant inside a type. For example, given:

class Foo
  A = 1
end

A will be a Const type with a value of 1.

A constant is a type because when we do Foo::A we do a regular type lookup, which might result in a constant, so constants are saved under a type types like any other type.

Class methods

.new(program, namespace, name, value)

View source

Methods

#compile_time_value

Returns a value if this constant's value can be evaluated at compile time (things like 1 + 2 and such). Returns nil otherwise.

View source

#fake_def : Def?

View source

#fake_def=(fake_def : Def?)

View source

#initialized_llvm_name

View source

#initializer : LLVM::Value?

View source

#initializer=(initializer : LLVM::Value?)

View source

#needs_init_flag?

View source

#no_init_flag=(no_init_flag)

If true, there's no need to check whether the constant was initialized or not when reading it.

View source

#no_init_flag? : Bool

If true, there's no need to check whether the constant was initialized or not when reading it.

View source

#pointer_read=(pointer_read)

Is this constant accessed with pointerof(...)?

View source

#pointer_read? : Bool

Is this constant accessed with pointerof(...)?

View source

#read=(read)

Was this constant already read during the codegen phase? If not, and we are at the place that declares the constant, we can directly initialize the constant now, without checking for an init flag.

View source

#read? : Bool

Was this constant already read during the codegen phase? If not, and we are at the place that declares the constant, we can directly initialize the constant now, without checking for an init flag.

View source

#simple?

Returns true if this constant's value is a simple literal, like nil, a number, char, string or symbol literal.

View source

#type_desc

View source

#used=(used)

View source

#used? : Bool

View source

#value=(value : ASTNode)

View source

#visited=(visited)

View source

#visited? : Bool

View source

#visitor=(visitor : MainVisitor?)

View source