class Crystal::Program

Overview

A program contains all types and top-level methods related to one compilation of a program.

It also carries around all information needed to compile a bunch of files: the unions, the symbols used, all global variables, all required files, etc. Because of this, a Program is usually passed around in every step of a compilation to record and query this information.

In a way, a Program is an alternative implementation to having global variables for all of this data, but modeled this way one can easily test and exercise programs because each one has its own definition of the types created, methods instantiated, etc.

Additionally, a Program acts as a regular type (a module) that can have types (the top-level types) and methods (the top-level methods), and which can also include other modules (this happens when you do include Module at the top-level).

Included Modules

Defined in:

compiler/crystal/codegen/codegen.cr
compiler/crystal/codegen/link.cr
compiler/crystal/macros/macros.cr
compiler/crystal/macros/types.cr
compiler/crystal/program.cr
compiler/crystal/semantic.cr
compiler/crystal/semantic/class_vars_initializer_visitor.cr
compiler/crystal/semantic/cleanup_transformer.cr
compiler/crystal/semantic/exception.cr
compiler/crystal/semantic/flags.cr
compiler/crystal/semantic/hooks.cr
compiler/crystal/semantic/main_visitor.cr
compiler/crystal/semantic/new.cr
compiler/crystal/semantic/normalizer.cr
compiler/crystal/semantic/path_lookup.cr
compiler/crystal/semantic/type_merge.cr
compiler/crystal/semantic/warnings.cr

Constant Summary

PKG_CONFIG_PATH = Process.find_executable("pkg-config")

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Crystal::DefInstanceContainer

add_def_instance(key, typed_def) add_def_instance, def_instances def_instances, lookup_def_instance(key) lookup_def_instance

Instance methods inherited from class Crystal::NonGenericModuleType

add_including_type(type) add_including_type, add_instance_var_initializer(name, value, meta_vars) add_instance_var_initializer, add_to_including_types(all_types) add_to_including_types, append_cover(array) append_cover, append_to_expand_union_types(types) append_to_expand_union_types, cover cover, cover_size cover_size, filter_by_responds_to(name) filter_by_responds_to, including_types including_types, module? module?, raw_including_types : Array(Crystal::Type)? raw_including_types, remove_indirection remove_indirection, restrict(other, context) restrict

Instance methods inherited from module Crystal::SubclassObservable

add_subclass_observer(observer) add_subclass_observer, notify_subclass_added notify_subclass_added, remove_subclass_observer(observer) remove_subclass_observer

Instance methods inherited from module Crystal::ClassVarContainer

class_vars class_vars, class_vars? class_vars?, lookup_class_var(name) lookup_class_var, lookup_class_var?(name) lookup_class_var?

Instance methods inherited from module Crystal::InstanceVarContainer

instance_vars instance_vars

Instance methods inherited from class Crystal::ModuleType

add_def(a_def) add_def, add_hook(kind : HookKind, a_macro, args_size = 0) add_hook, add_macro(a_macro) add_macro, defs : Hash(String, Array(DefWithMetadata)) | Nil defs, filter_by_responds_to(name) filter_by_responds_to, hooks : Array(Hook) | Nil hooks, include(mod) include, macros : Hash(String, Array(Macro)) | Nil macros, parents parents, type_desc type_desc

Instance methods inherited from class Crystal::NamedType

add_location(location : Location) add_location, append_full_name(io : IO, codegen : Bool = false) : Nil append_full_name, doc : String | Nil doc, doc=(doc : String | Nil) doc=, full_name full_name, locations : Array(Location) | Nil locations, name : String name, namespace : ModuleType namespace, private=(private __arg0 : Bool) private=, private? : Bool private?, to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen : Bool = false) : Nil to_s_with_options, types types, types? : Hash(String, Crystal::NamedType)? types?

Constructor methods inherited from class Crystal::NamedType

new(program, namespace : Crystal::ModuleType, name : String) new

Instance methods inherited from class Crystal::Type

abstract? abstract?, abstract_leaf? abstract_leaf?, add_including_type(mod) add_including_type, add_instance_var_initializer(name, value, meta_vars) add_instance_var_initializer, add_subclass(subclass) add_subclass, all?(&) all?, all_class_vars all_class_vars, all_instance_vars all_instance_vars, all_instance_vars_count all_instance_vars_count, all_subclasses all_subclasses, allowed_in_lib? allowed_in_lib?, allows_instance_vars? allows_instance_vars?, ancestors ancestors, append_cover(array) append_cover, append_to_expand_union_types(types) append_to_expand_union_types, bool_type? bool_type?, can_be_stored? can_be_stored?, check_method_missing(signature, call) check_method_missing, check_restriction_exception check_restriction_exception, class? class?, class_var_owner class_var_owner, class_vars class_vars, compatible_with?(type) compatible_with?, cover cover, cover_size cover_size, declare_instance_var(name, type : Type, annotations = nil) declare_instance_var, define_method_from_method_missing(method_missing, signature, original_call) define_method_from_method_missing, defs : Hash(String, Array(DefWithMetadata)) | Nil defs, depth depth, devirtualize devirtualize, doc : String | Nil doc, double_variadic? double_variadic?, each_cover(&) each_cover, each_namespace(& : ModuleType -> ) : Nil each_namespace, extern? extern?, extern_union? extern_union?, ffi_arg_type : FFI::Type ffi_arg_type, ffi_type : FFI::Type ffi_type, filter_by(other_type : Type) filter_by, filter_by_responds_to(name) filter_by_responds_to, generic_nest generic_nest, generic_type generic_type, get_instance_var_initializer(name) get_instance_var_initializer, has_def?(name) has_def?, has_def_without_parents?(name) has_def_without_parents?, has_in_type_vars?(type) has_in_type_vars?, has_inner_pointers? has_inner_pointers?, has_instance_var_initializer?(name) has_instance_var_initializer?, has_protected_access_to?(type, allow_same_namespace = true) has_protected_access_to?, implements?(other_type : Type) implements?, implicitly_converted_in_c_to?(expected_type) implicitly_converted_in_c_to?, includes_type?(type) includes_type?, including_types including_types, index_of_instance_var(name) index_of_instance_var, inspect(io : IO) : Nil inspect, instance_type instance_type, instance_vars instance_vars, leaf? leaf?, llvm_name(io)
llvm_name
llvm_name
, locations : Array(Location) | Nil locations, lookup_class_var(name) lookup_class_var, lookup_class_var?(name) lookup_class_var?, lookup_defs(name : String, lookup_ancestors_for_new : Bool = false)
lookup_defs(name : String, all_defs : Array(Def), lookup_ancestors_for_new : Bool | Nil = false)
lookup_defs
, lookup_defs_with_modules(name) lookup_defs_with_modules, lookup_defs_without_parents(name : String, all_defs : Array(Def))
lookup_defs_without_parents(name : String)
lookup_defs_without_parents
, lookup_first_def(name, block) lookup_first_def, lookup_instance_var(name : String)
lookup_instance_var(node : InstanceVar | ReadInstanceVar | MetaVar)
lookup_instance_var
, lookup_instance_var?(name : String) lookup_instance_var?, lookup_macro(name, args : Array, named_args) lookup_macro, lookup_macros(name) lookup_macros, lookup_matches(signature, owner = self, path_lookup = self, matches_array = nil, analyze_all = false) lookup_matches, lookup_matches_with_modules(signature, owner = self, path_lookup = self, matches_array = nil, analyze_all = false) lookup_matches_with_modules, lookup_matches_without_parents(signature, owner = self, path_lookup = self, matches_array = nil, analyze_all = false) lookup_matches_without_parents, lookup_method_missing lookup_method_missing, lookup_name(name) lookup_name, lookup_new_in_ancestors? lookup_new_in_ancestors?, lookup_path(path : Path, lookup_in_namespace = true, include_private = false, location = path.location) : Type | ASTNode | Nil
lookup_path(names : Array(String), lookup_in_namespace = true, include_private = false, location = nil) : Type | ASTNode | Nil
lookup_path
, lookup_path_item(name : String, lookup_self, lookup_in_namespace, include_private, location) : Type | ASTNode | Nil lookup_path_item, lookup_similar_def(name, args_size, block) lookup_similar_def, lookup_similar_def_name(name, args_size, block) lookup_similar_def_name, lookup_similar_instance_var_name(ivar_name : String)
lookup_similar_instance_var_name(name)
lookup_similar_instance_var_name
, lookup_similar_path(node : Path)
lookup_similar_path(names : Array(String), lookup_in_namespace = true)
lookup_similar_path
, lookup_type(node : ASTNode, self_type = self.instance_type, allow_typeof = true, free_vars : Hash(String, TypeVar) | Nil = nil, find_root_generic_type_parameters = true) : Type lookup_type, lookup_type?(node : ASTNode, self_type = self.instance_type, allow_typeof = true, free_vars : Hash(String, TypeVar) | Nil = nil, find_root_generic_type_parameters = true) : Type | Nil lookup_type?, lookup_type_var(node : Path, free_vars : Hash(String, TypeVar) | Nil = nil, find_root_generic_type_parameters = true, remove_alias = true) : Type | ASTNode lookup_type_var, lookup_type_var?(node : Path, free_vars : Hash(String, TypeVar) | Nil = nil, raise = false, find_root_generic_type_parameters = true) : Type | ASTNode | Nil lookup_type_var?, macros : Hash(String, Array(Macro)) | Nil macros, metaclass : Type metaclass, metaclass? metaclass?, module? module?, namespace : ModuleType namespace, nil_type? nil_type?, nilable? nilable?, no_return? no_return?, opaque_id opaque_id, packed? packed?, parents parents, passed_as_self? passed_as_self?, passed_by_value? passed_by_value?, pointer? pointer?, pretty_print(pp) pretty_print, private=(set_private) private=, private? private?, proc? proc?, program : Crystal::Program program, reference_like? reference_like?, remove_alias remove_alias, remove_alias_if_simple remove_alias_if_simple, remove_indirection remove_indirection, remove_literal remove_literal, remove_typedef remove_typedef, replace_type_parameters(instance) : Type replace_type_parameters, restrict(other : Nil, context)
restrict(other : AliasType, context)
restrict(other : UnionType, context)
restrict(other : VirtualType, context)
restrict(other : GenericClassType, context)
restrict(other : Type, context)
restrict(other : Self, context)
restrict(other : TypeOf, context)
restrict(other : Union, context)
restrict(other : Path, context)
restrict(other : Generic, context)
restrict(other : Metaclass, context)
restrict(other : ProcNotation, context)
restrict(other : Underscore, context)
restrict(other : Arg, context)
restrict(other : NumberLiteral, context)
restrict(other : Splat, context)
restrict(other : ASTNode, context)
restrict
, restriction_of?(other : UnionType, owner, self_free_vars = nil, other_free_vars = nil)
restriction_of?(other : VirtualType, owner, self_free_vars = nil, other_free_vars = nil)
restriction_of?(other : AliasType, owner, self_free_vars = nil, other_free_vars = nil)
restriction_of?(other : Type, owner, self_free_vars = nil, other_free_vars = nil)
restriction_of?(other : ASTNode, owner, self_free_vars = nil, other_free_vars = nil)
restriction_of?
, same_namespace?(other) same_namespace?, sizeof_type sizeof_type, splat_index splat_index, struct? struct?, subclasses : Array(Type) subclasses, superclass : Type | Nil superclass, to_s(io : IO) : Nil
to_s(*, generic_args : Bool = true)
to_s
, to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen : Bool = false) : Nil to_s_with_options, type_desc type_desc, type_var?(name) type_var?, type_vars type_vars, types types, types? types?, unbound? unbound?, virtual? virtual?, virtual_metaclass? virtual_metaclass?, virtual_type virtual_type, virtual_type! virtual_type!, void? void?

Constructor methods inherited from class Crystal::Type

merge!(type1 : Type, type2 : Type) : Type
merge!(types_or_nodes) : Type
merge!
, new(program : Program) new

Class methods inherited from class Crystal::Type

common_descendent(type1 : TupleInstanceType, type2 : TupleInstanceType)
common_descendent(type1 : NamedTupleInstanceType, type2 : NamedTupleInstanceType)
common_descendent(type1 : ProcInstanceType, type2 : ProcInstanceType)
common_descendent(type1 : NonGenericModuleType | GenericModuleInstanceType, type2 : AliasType)
common_descendent(type1 : NonGenericModuleType | GenericModuleInstanceType, type2 : UnionType)
common_descendent(type1 : NonGenericModuleType | GenericModuleInstanceType, type2 : VirtualType)
common_descendent(type1 : NonGenericModuleType | GenericModuleInstanceType, type2 : GenericClassType)
common_descendent(type1 : GenericModuleInstanceType, type2 : GenericModuleInstanceType)
common_descendent(type1 : GenericModuleInstanceType, type2 : GenericModuleType)
common_descendent(type1 : NonGenericModuleType | GenericModuleInstanceType, type2 : Type)
common_descendent(type1 : GenericClassInstanceType, type2 : GenericClassType)
common_descendent(type1 : GenericClassType, type2 : GenericClassInstanceType)
common_descendent(type1 : GenericInstanceType, type2 : GenericInstanceType)
common_descendent(type1 : MetaclassType, type2 : VirtualMetaclassType)
common_descendent(type1 : VirtualMetaclassType, type2 : MetaclassType)
common_descendent(type1 : VirtualMetaclassType, type2 : VirtualMetaclassType)
common_descendent(type1 : GenericClassInstanceMetaclassType | GenericModuleInstanceMetaclassType, type2 : MetaclassType | VirtualMetaclassType)
common_descendent(type1 : MetaclassType | VirtualMetaclassType, type2 : GenericClassInstanceMetaclassType | GenericModuleInstanceMetaclassType)
common_descendent(type1 : UnionType, type2 : Type)
common_descendent(type1 : AliasType, type2 : AliasType)
common_descendent(type1 : AliasType, type2 : Type)
common_descendent(type1 : TypeDefType, type2 : UnionType)
common_descendent(type1 : TypeDefType, type2 : AliasType)
common_descendent(type1 : TypeDefType, type2 : Type)
common_descendent(type1 : VirtualType, type2 : VirtualType)
common_descendent(type1 : VirtualType, type2 : AliasType)
common_descendent(type1 : VirtualType, type2 : UnionType)
common_descendent(type1 : VirtualType, type2 : Type)
common_descendent(type1 : NilType, type2 : VoidType)
common_descendent(type1 : GenericClassType, type2 : GenericClassType)
common_descendent(type1 : Type, type2 : AliasType)
common_descendent(type1 : Type, type2 : UnionType)
common_descendent(type1 : Type, type2 : VirtualType)
common_descendent(type1 : Type, type2 : GenericClassType)
common_descendent(type1 : Type, type2 : Type)
common_descendent
, least_common_ancestor(type1 : MetaclassType | GenericClassInstanceMetaclassType, type2 : MetaclassType | GenericClassInstanceMetaclassType)
least_common_ancestor(type1 : NonGenericModuleType | GenericModuleInstanceType | GenericClassType, type2 : NonGenericModuleType | GenericModuleInstanceType | GenericClassType)
least_common_ancestor(type1 : GenericClassType, type2 : ClassType | GenericClassInstanceType)
least_common_ancestor(type1 : NonGenericModuleType | GenericModuleInstanceType | GenericClassType, type2 : Type)
least_common_ancestor(type1 : ClassType | GenericClassInstanceType, type2 : GenericClassType)
least_common_ancestor(type1 : Type, type2 : NonGenericModuleType | GenericModuleInstanceType | GenericClassType)
least_common_ancestor(type1 : TupleInstanceType, type2 : TupleInstanceType)
least_common_ancestor(type1 : NamedTupleInstanceType, type2 : NamedTupleInstanceType)
least_common_ancestor(type1 : ClassType | GenericClassInstanceType, type2 : ClassType | GenericClassInstanceType)
least_common_ancestor(type1 : Type, type2 : Type)
least_common_ancestor
, merge(nodes : Enumerable(ASTNode)) : Type | Nil
merge(types : Array(Type)) : Type | Nil
merge

Instance methods inherited from module Crystal::Annotatable

add_annotation(annotation_type : AnnotationType, value : Annotation) add_annotation, all_annotations : Array(Annotation) | Nil all_annotations, annotation(annotation_type : AnnotationType) : Annotation | Nil annotation, annotations(annotation_type : AnnotationType) : Array(Annotation) | Nil
annotations : Hash(AnnotationType, Array(Annotation)) | Nil
annotations
, annotations=(annotations : Hash(AnnotationType, Array(Annotation)) | Nil) annotations=

Instance methods inherited from class Reference

==(other : self)
==(other : JSON::Any)
==(other : YAML::Any)
==(other)
==
, dup dup, hash(hasher) hash, initialize initialize, inspect(io : IO) : Nil inspect, object_id : UInt64 object_id, pretty_print(pp) : Nil pretty_print, same?(other : Reference) : Bool
same?(other : Nil)
same?
, to_s(io : IO) : Nil to_s

Constructor methods inherited from class Reference

new new, unsafe_construct(address : Pointer, *args, **opts) : self unsafe_construct

Class methods inherited from class Reference

pre_initialize(address : Pointer) pre_initialize

Instance methods inherited from class Object

! : Bool !, !=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other)
===
, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash
hash
, in?(collection : Object) : Bool
in?(*values : Object) : Bool
in?
, inspect(io : IO) : Nil
inspect : String
inspect
, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil!(message)
not_nil!
not_nil!
, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String
to_json
, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil
to_pretty_json
, to_s(io : IO) : Nil
to_s : String
to_s
, to_yaml(io : IO) : Nil
to_yaml : String
to_yaml
, try(&) try, unsafe_as(type : T.class) forall T unsafe_as

Class methods inherited from class Object

from_json(string_or_io : String | IO, root : String)
from_json(string_or_io : String | IO)
from_json
, from_yaml(string_or_io : String | IO) from_yaml

Macros inherited from class Object

class_getter(*names, &block) class_getter, class_getter!(*names) class_getter!, class_getter?(*names, &block) class_getter?, class_property(*names, &block) class_property, class_property!(*names) class_property!, class_property?(*names, &block) class_property?, class_setter(*names) class_setter, def_clone def_clone, def_equals(*fields) def_equals, def_equals_and_hash(*fields) def_equals_and_hash, def_hash(*fields) def_hash, delegate(*methods, to object) delegate, forward_missing_to(delegate) forward_missing_to, getter(*names, &block) getter, getter!(*names) getter!, getter?(*names, &block) getter?, property(*names, &block) property, property!(*names) property!, property?(*names, &block) property?, setter(*names) setter

Constructor Detail

def self.new #

[View source]

Class Method Detail

def self.flag_value(flags, name) #

[View source]

Instance Method Detail

def add_def(node : Def) #

[View source]
def add_finished_hook(scope, a_macro, node) #

[View source]
def add_macro(node : Macro) #

[View source]
def add_type(types, type : UnionType) #

[View source]
def add_type(types, type : AliasType) #

[View source]
def add_type(types, type : VoidType) #

When Void participates in a union, it becomes Nil (users shouldn't deal with real Void values)


[View source]
def add_type(types, type : Type) #

[View source]
def add_type(set, type : Nil) #

[View source]
def after_inference_types : Set(Crystal::Type) #

Types that have instance vars initializers which need to be visited (transformed) by CleanupTransformer once the semantic analysis finishes.

TODO this probably isn't needed and we can just traverse all types at the end, and analyze all instance variables initializers that we found. This should simplify a bit of code.


[View source]
def align_of(type) #

[View source]
def always_inline_annotation #

[View source]
def argc : Const #

The constant for ARGC_UNSAFE


[View source]
def argc? : Const | Nil #

The constant for ARGC_UNSAFE


[View source]
def argv : Const #

The constant for ARGV_UNSAFE


[View source]
def argv? : Const | Nil #

The constant for ARGV_UNSAFE


[View source]
def array #

[View source]
def array_of(type) #

Returns the Type for Array(type)


[View source]
def ast_node #

[View source]
def bits64? #

[View source]
def bool #

[View source]
def call_convention_annotation #

[View source]
def char #

[View source]
def check_call_to_deprecated_annotation(node : AnnotationDef) : Nil #

[View source]
def check_call_to_deprecated_macro(a_macro : Macro, call : Call) #

[View source]
def check_call_to_deprecated_method(node : Call) #

[View source]
def check_deprecated_constant(const : Const, node : Path) #

[View source]
def check_deprecated_type(type : Type, node : Path) #

[View source]
def check_private(node) #

[View source]
def class_type #

Returns the Class type


[View source]
def class_var_initializers : Array(Crystal::ClassVarInitializer) #

The class var initializers stored to be used by the cleanup transformer


[View source]
def cleanup(node, inside_def = false) #

[View source]
def cleanup_files #

[View source]
def cleanup_single_type(type, transformer) #

[View source]
def cleanup_transformer : CleanupTransformer #

[View source]
def cleanup_type(type, transformer) #

[View source]
def cleanup_types #

[View source]
def codegen(node, single_module = false, debug = Debug::Default, frame_pointers = FramePointers::Auto) #

[View source]
def codegen_target : Crystal::Codegen::Target #

[View source]
def codegen_target=(codegen_target : Codegen::Target) : Codegen::Target #

[View source]
def color=(color : Bool) #

If true, error messages can be colorized


[View source]
def color? : Bool #

If true, error messages can be colorized


[View source]
def colorize(obj) #

Colorizes the given object, depending on whether this program is configured to use colors.


[View source]
def combined_union_of(types : Array) #

[View source]
def compact_types(types) : Array(Type) #

[View source]
def compact_types(objects, &) : Array(Type) #

[View source]
def compiled_macros_cache : Hash(String, Crystal::Program::CompiledMacroRun) #

[View source]
def compiled_macros_cache=(compiled_macros_cache : Hash(String, Crystal::Program::CompiledMacroRun)) #

[View source]
def compiler : Compiler | Nil #

[View source]
def compiler=(compiler : Compiler | Nil) #

[View source]
def const_initializers : Array(Crystal::Const) #

Here we store constants, in the order that they are used. They will be initialized as soon as the program starts, before the main code.


[View source]

All constant slices constructed via the Slice.literal compiler built-in, indexed by their buffers' internal names (e.g. $Slice:0).


[View source]
def crystal #

[View source]
def crystal_path #

Returns a CrystalPath for this program.


[View source]
def define_default_new(type) #

[View source]
def define_default_new_single(type) #

[View source]
def define_new_methods(new_expansions) #

[View source]
def deprecated_annotation #

[View source]
def each_dll_path(& : String, Bool -> ) #

Searches among CRYSTAL_LIBRARY_PATH, the compiler's directory, and PATH for every DLL specified in the used @[Link] annotations. Yields the absolute path and true if found, the base name and false if not found. The directories should match Crystal::Repl::Context#dll_search_paths


[View source]
def enum #

[View source]
def enumerable #

[View source]
def evaluate(node, return_type : T.class, debug = Debug::Default) : T forall T #

[View source]
def evaluate(node, debug = Debug::Default) #

[View source]
def exception #

[View source]
def expand_macro(a_macro : Macro, call : Call, scope : Type, path_lookup : Type | Nil = nil, a_def : Def | Nil = nil) #

[View source]
def expand_macro(node : ASTNode, scope : Type, path_lookup : Type | Nil = nil, free_vars = nil, a_def : Def | Nil = nil) #

[View source]
def experimental_annotation #

[View source]
def extern_annotation #

[View source]
def file_module(filename) #

[View source]
def file_module?(filename) #

[View source]
def file_modules : Hash(String, Crystal::FileModule) #

All FileModules indexed by their filename. These store file-private defs, and top-level variables in files other than the main file.


[View source]
def filename : String | Nil #

The main filename of this program


[View source]
def filename=(filename : String | Nil) #

The main filename of this program


[View source]
def find_in_path(filename, relative_to = nil) : Array(String) | Nil #

Finds filename in the configured CRYSTAL_PATH for this program, relative to relative_to.


[View source]
def finished_hooks : Array(Crystal::Program::FinishedHook) #

[View source]
def flag_value(name : String) : String | Bool #

Returns the value of a flag in the format "#{key}=#{value}". Or true if the flags contain key.


[View source]
def flags #

Returns the flags for this program. By default these are computed from the target triple (for example x86_64, darwin, linux, etc.), but can be overwritten with flags= and also added with the -D command line argument.

See Compiler#flags.


[View source]
def flags_annotation #

[View source]
def float #

[View source]
def float32 #

[View source]
def float64 #

[View source]
def has_flag?(name : String) #

Returns true if name is in the program's flags.


[View source]
def hash_of(key_type, value_type) #

Returns the Type for Hash(key_type, value_type)


[View source]
def hash_type #

Returns the Hash type


[View source]
def host_compiler #

Creates a compiler instance with the host as target used for macro_run compilation.


[View source]
def host_flag_value(name : String) : String | Bool #

Returns the value of a host flag in the format "#{key}=#{value}". Or true if the host flags contain key.


[View source]
def host_flags #

[View source]
def indexable #

[View source]
def instance_align_of(type) #

[View source]
def instance_offset_of(type, element_index) #

[View source]
def instance_size_of(type) #

[View source]
def int #

[View source]
def int128 #

[View source]
def int16 #

[View source]
def int32 #

[View source]
def int64 #

[View source]
def int8 #

[View source]
def int?(int) #

Returns the IntegerType that matches the given Int value


[View source]
def int_type(signed, size) #

[View source]
def interpreted_node_hook : Proc(ASTNode, Bool, Bool, Location | Nil, Nil) | Nil #

[View source]
def interpreted_node_hook=(interpreted_node_hook : Proc(ASTNode, Bool, Bool, Location | Nil, Nil) | Nil) #

[View source]
def lib_flags(cross_compiling : Bool = false) #

[View source]
def link_annotation #

[View source]
def link_annotations #

Returns every @[Link] annotation in the program parsed as LinkAnnotation


[View source]
def literal_expander #

Returns a LiteralExpander useful to expand literal like arrays and hashes into simpler forms.


[View source]
def llvm_id #

[View source]
def llvm_typer #

[View source]
def lookup_macro_type(name : Path) #

Returns the macro type named by a given AST node in the macro language.


[View source]
def lookup_macro_type(name : Union) #

[View source]
def lookup_macro_type(name : ASTNode) #

[View source]
def lookup_path_item(name : String, lookup_self, lookup_in_namespace, include_private, location) #
Description copied from class Crystal::Type

Looks up a single path item relative to *self`.

If lookup_in_namespace is true, if the type is not found in self or self's parents, the path item is searched in this type's namespace. This parameter is useful because when writing Foo::Bar::Baz, Foo should be searched in enclosing namespaces, but Bar and Baz not.

If lookup_self is true, if the type is not found under self but has the same name as self, then self is returned. This has higher precedence than ancestors and the enclosing namespace.


[View source]
def lookup_private_matches(filename, signature, analyze_all = false) #

[View source]
def macro_compile(filename) #

[View source]
def macro_expanded_hook : Proc(Nil) | Nil #

[View source]
def macro_expanded_hook=(macro_expanded_hook : Proc(Nil) | Nil) #

[View source]
def macro_expander #

Returns a MacroExpander to expand macro code into crystal code.


[View source]
def macro_expansion_error_hook : Proc(Exception | Nil, Nil) | Nil #

[View source]
def macro_expansion_error_hook=(macro_expansion_error_hook : Proc(Exception | Nil, Nil) | Nil) #

[View source]
def macro_no_return #

[View source]
def macro_run(filename, args) #

[View source]
def metaclass #
Description copied from class Crystal::Type

Returns this type's metaclass, which holds class methods for this type.


[View source]
def msvc_compiler_and_flags : Tuple(String, Array(String)) #

Detects the current MSVC linker and the relevant linker flags that recreate the MSVC developer prompt's standard library paths. If both MSVC and the Windows SDK are available, the linker will be an absolute path and the linker flags will contain the /LIBPATHs for the system libraries.

Has no effect if the host compiler is not using MSVC.


[View source]
def naked_annotation #

[View source]
def named_tuple #

[View source]
def named_tuple_of(entries : Hash(String, Type) | NamedTuple) #

Returns the Type for NamedTuple(**entries)


[View source]
def named_tuple_of(entries : Array(NamedArgumentType)) #

Returns the Type for NamedTuple(**entries)


[View source]
def new_parser(source : String, var_scopes = [Set(String).new]) #

Returns a new Parser for the given source, sharing the string pool and warnings with this program.


[View source]
def new_temp_var(node : ASTNode) : Var #

[View source]
def new_temp_var(prefix : String | Nil = nil) : Var #

[View source]
def new_temp_var_name(node : ASTNode) : String #

Returns a unique variable name associated with the given AST node.

Nodes with a location include the first 8 digits of the filename's MD5 digest as part of the prefix, e.g. all names originating from foo.cr use the prefix __temp_cd6ae5dd_*. This localizes the impact on incremental object file generation to all types defined or reopened in that same file.


[View source]
def new_temp_var_name(prefix : String | Nil = nil) : String #

Returns a unique variable name associated with the given prefix.

By convention, the prefix must start with __temp_, and defaults to it as well.


[View source]
def nil #

[View source]
def nil_type #

Returns the Nil type


[View source]
def nil_var #

Returns a Var that has Nil as a type. This variable is bound to other nodes in the semantic phase for things that need to be nilable, for example to a variable that's only declared in one branch of an if expression.


[View source]
def nilable(type) #

Returns the Type for type | Nil


[View source]
def no_inline_annotation #

[View source]
def no_return #

[View source]
def node_macro_type(node : ASTNode) : MacroType #

Returns the macro type for a given AST node. This association is done through Crystal::ASTNode#class_desc.


[View source]
def normalize(node, inside_exp = false, current_def = nil) #

[View source]
def number #

[View source]
def object #

[View source]
def offset_of(type, element_index) #

[View source]
def optimization_mode : Crystal::Compiler::OptimizationMode #

[View source]
def optimization_mode=(optimization_mode : Crystal::Compiler::OptimizationMode) #

[View source]
def packed_annotation #

[View source]
def parse_macro_source(generated_source, macro_expansion_pragmas, the_macro, node, vars, current_def = nil, inside_type = false, inside_exp = false, mode : Parser::ParseMode = :normal, visibility : Visibility = :public) #

[View source]
def parse_macro_source(generated_source, macro_expansion_pragmas, the_macro, node, vars, current_def = nil, inside_type = false, inside_exp = false, visibility : Visibility = :public, &) #

[View source]
def pointer #

[View source]
def pointer_of(type) #

Returns the Type for Pointer(type)


[View source]
def predefined_constants : Array(Crystal::Const) #

[View source]
def primitive_annotation #

[View source]
def proc #

[View source]
def proc_of(nodes : Array(ASTNode), return_type : Type) #

Returns the Type for Proc(*nodes.map(&.type), return_type)


[View source]
def proc_of(types : Array) #

Returns the Type for Proc(*types)


[View source]
def process_finished_hooks(visitor) #

Visits all finished hooks with the given visitor


[View source]
def progress_tracker : Crystal::ProgressTracker #

A ProgressTracker object which tracks compilation progress.


[View source]
def progress_tracker=(progress_tracker : Crystal::ProgressTracker) #

A ProgressTracker object which tracks compilation progress.


[View source]
def raises_annotation #

[View source]
def range #

[View source]
def range_of(begin_type, end_type) #

Returns the Type for Range(begin_type, end_type)


[View source]
def record_require(filename, relative_to) : Nil #

Remembers that the program depends on this require.


[View source]
def recorded_requires : Array(Crystal::Program::RecordedRequire) #

[View source]
def recorded_requires=(recorded_requires : Array(Crystal::Program::RecordedRequire)) #

[View source]
def reference #

[View source]
def regex #

[View source]
def requires : Set(String) #

All required files. The set stores absolute files. This way files loaded by require nodes are only processed once.


[View source]
def returns_twice_annotation #

[View source]
def run(code, filename : String | Nil = nil, debug = Debug::Default) #

[View source]
def run(code, return_type : T.class, filename : String | Nil = nil, debug = Debug::Default) forall T #

[View source]
def run_requires(node : Require, filenames, &) : Nil #

[View source]
def semantic(node : ASTNode, cleanup = true, main_visitor : MainVisitor = MainVisitor.new(self)) : ASTNode #

Runs semantic analysis on the given node, returning a node that's typed. In the process types and methods are defined in this program.


[View source]
def show_error_trace=(show_error_trace : Bool) #

Whether to show error trace


[View source]
def show_error_trace? : Bool #

Whether to show error trace


[View source]
def size_bit_width #

[View source]
def size_of(type) #

[View source]
def slice #

[View source]
def splat_expansions : Hash(Def, Array(Type)) #

Hash that prevents recursive splat expansions. For example:

def foo(*x)
  foo(x)
end

foo(1)

Here x will be {Int32}, then {{Int32}}, etc.

The way we detect this is by remembering the types of the splat, associated to a def's object id (the UInt64), and on an instantiation we compare the new type with the previous ones and check if they all contain each other once the method is invoked a number of times recursively (currently 5 times or more).


[View source]
def static_array #

[View source]
def static_array_of(type, size) #

Returns the Type for StaticArray(type, size)


[View source]
def stdout : IO #

Default standard output to use in a program, while compiling.


[View source]
def stdout=(stdout : IO) #

Default standard output to use in a program, while compiling.


[View source]
def string #

[View source]
def string_pool : StringPool #

A String pool to avoid creating the same strings over and over. This pool is passed to the parser, macro expander, etc.


[View source]
def struct #

Returns the Struct type


[View source]
def symbol #

[View source]
def symbols : Set(String) #

All symbols (:foo, :bar) found in the program


[View source]
def target_feature_annotation #

[View source]
def target_machine : LLVM::TargetMachine #

[View source]
def target_machine=(target_machine : LLVM::TargetMachine) #

[View source]
def tempfiles : Array(String) #

Temporary files which are generated by macro runs that need to be deleted after the compilation is finished.


[View source]
def thread_local_annotation #

[View source]
def to_s(io : IO) : Nil #
Description copied from class Crystal::Type

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>

[View source]
def top_level_semantic(node, main_visitor : MainVisitor = MainVisitor.new(self)) #

Processes type declarations and instance/class/global vars types are guessed or followed according to type annotations.

This alone is useful for some tools like doc or hierarchy where a full semantic of the program is not needed.


[View source]
def top_level_semantic_complete=(top_level_semantic_complete : Bool) #

This property indicates that the compiler has finished the top-level semantic stage. At this point, instance variables are declared and macros #instance_vars and #has_internal_pointers? provide meaningful information.

FIXME Introduce a more generic method to track progress of compiler stages (potential synergy with ProcessTracker?).


[View source]
def top_level_semantic_complete? : Bool #

This property indicates that the compiler has finished the top-level semantic stage. At this point, instance variables are declared and macros #instance_vars and #has_internal_pointers? provide meaningful information.

FIXME Introduce a more generic method to track progress of compiler stages (potential synergy with ProcessTracker?).


[View source]
def tuple #

[View source]
def tuple_of(types) #

Returns the Type for Tuple(*types)


[View source]
def type_combine(types) #

[View source]
def type_desc #

[View source]
def type_from_literal_kind(kind : NumberKind) #

[View source]
def type_merge(first : Type | Nil, second : Type | Nil) : Type | Nil #

[View source]
def type_merge(types : Array(Type | Nil)) : Type | Nil #

[View source]
def type_merge(nodes : Enumerable(ASTNode)) : Type | Nil #

[View source]
def type_merge_union_of(types : Array(Type)) : Type | Nil #

[View source]
def uint128 #

[View source]
def uint16 #

[View source]
def uint32 #

[View source]
def uint64 #

[View source]
def uint8 #

[View source]
def undefined_class_variable(node, owner, similar_name) #

[View source]
def undefined_instance_variable(node, owner, similar_name) #

[View source]
def undefined_variable_message(kind, example_name, owner) #

[View source]
def union #

[View source]
def union_of(type1, type2) #

Returns the Type for type1 | type2


[View source]
def union_of(types : Array) #

Returns the Type for Union(*types)


[View source]

All created unions in a program, indexed by an array of opaque ids of each type in the union. The array (the key) is sorted by this opaque id.

A program caches them this way so a union of String | Int32 or Int32 | String is represented by a single, unique type in the program.


[View source]
def value #

[View source]
def vars : Hash(String, Crystal::MetaVar) #

Top-level variables found in a program (only in the main file).


[View source]
def virtual_root?(type : VirtualType | VirtualMetaclassType) #

[View source]

[View source]
def virtual_root?(type) #

Returns true if type can be used as a virtual root; that is, it must not be one of Object, Reference, Value, Struct, Number, Int, Float, or their corresponding metaclasses.


[View source]
def visit_class_vars_initializers(node) #

[View source]
def visit_main(node, visitor : MainVisitor = MainVisitor.new(self), process_finished_hooks = false, cleanup = true) #

[View source]
def visit_with_finished_hooks(node, visitor) #

[View source]
def void #

[View source]
def wants_doc=(wants_doc : Bool) #

If true, doc comments are attached to types and methods.


[View source]
def wants_doc? : Bool #

If true, doc comments are attached to types and methods.


[View source]
def warnings : Crystal::WarningCollection #

Warning settings and all detected warnings.


[View source]
def warnings=(warnings : Crystal::WarningCollection) #

Warning settings and all detected warnings.


[View source]