class
Crystal::Program
- Crystal::Program
- Crystal::NonGenericModuleType
- Crystal::ModuleType
- Crystal::NamedType
- Crystal::Type
- Reference
- Object
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.crcompiler/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
- #add_def(node : Def)
- #add_finished_hook(scope, a_macro, node)
- #add_macro(node : Macro)
- #add_type(types, type : UnionType)
- #add_type(types, type : AliasType)
-
#add_type(types, type : VoidType)
When Void participates in a union, it becomes Nil (users shouldn't deal with real Void values)
- #add_type(types, type : Type)
- #add_type(set, type : Nil)
-
#after_inference_types : Set(Crystal::Type)
Types that have instance vars initializers which need to be visited (transformed) by
CleanupTransformeronce the semantic analysis finishes. - #align_of(type)
- #always_inline_annotation
-
#argc : Const
The constant for ARGC_UNSAFE
-
#argc? : Const | Nil
The constant for ARGC_UNSAFE
-
#argv : Const
The constant for ARGV_UNSAFE
-
#argv? : Const | Nil
The constant for ARGV_UNSAFE
- #array
- #array_of(type)
- #ast_node
- #bits64?
- #bool
- #call_convention_annotation
- #char
- #check_call_to_deprecated_annotation(node : AnnotationDef) : Nil
- #check_call_to_deprecated_macro(a_macro : Macro, call : Call)
- #check_call_to_deprecated_method(node : Call)
- #check_deprecated_constant(const : Const, node : Path)
- #check_deprecated_type(type : Type, node : Path)
- #check_private(node)
-
#class_type
Returns the
Classtype -
#class_var_initializers : Array(Crystal::ClassVarInitializer)
The class var initializers stored to be used by the cleanup transformer
- #cleanup(node, inside_def = false)
- #cleanup_files
- #cleanup_single_type(type, transformer)
- #cleanup_transformer : CleanupTransformer
- #cleanup_type(type, transformer)
- #cleanup_types
- #codegen(node, single_module = false, debug = Debug::Default, frame_pointers = FramePointers::Auto)
- #codegen_target : Crystal::Codegen::Target
- #codegen_target=(codegen_target : Codegen::Target) : Codegen::Target
-
#color=(color : Bool)
If
true, error messages can be colorized -
#color? : Bool
If
true, error messages can be colorized -
#colorize(obj)
Colorizes the given object, depending on whether this program is configured to use colors.
- #combined_union_of(types : Array)
- #compact_types(types) : Array(Type)
- #compact_types(objects, &) : Array(Type)
- #compiled_macros_cache : Hash(String, Crystal::Program::CompiledMacroRun)
- #compiled_macros_cache=(compiled_macros_cache : Hash(String, Crystal::Program::CompiledMacroRun))
- #compiler : Compiler | Nil
- #compiler=(compiler : Compiler | Nil)
-
#const_initializers : Array(Crystal::Const)
Here we store constants, in the order that they are used.
-
#const_slices : Hash(String, Crystal::Program::ConstSliceInfo)
All constant slices constructed via the
Slice.literalcompiler built-in, indexed by their buffers' internal names (e.g. - #crystal
-
#crystal_path
Returns a
CrystalPathfor this program. - #define_default_new(type)
- #define_default_new_single(type)
- #define_new_methods(new_expansions)
- #deprecated_annotation
-
#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. - #enum
- #enumerable
- #evaluate(node, return_type : T.class, debug = Debug::Default) : T forall T
- #evaluate(node, debug = Debug::Default)
- #exception
- #expand_macro(a_macro : Macro, call : Call, scope : Type, path_lookup : Type | Nil = nil, a_def : Def | Nil = nil)
- #expand_macro(node : ASTNode, scope : Type, path_lookup : Type | Nil = nil, free_vars = nil, a_def : Def | Nil = nil)
- #experimental_annotation
- #extern_annotation
- #file_module(filename)
- #file_module?(filename)
-
#file_modules : Hash(String, Crystal::FileModule)
All FileModules indexed by their filename.
-
#filename : String | Nil
The main filename of this program
-
#filename=(filename : String | Nil)
The main filename of this program
-
#find_in_path(filename, relative_to = nil) : Array(String) | Nil
Finds filename in the configured CRYSTAL_PATH for this program, relative to relative_to.
- #finished_hooks : Array(Crystal::Program::FinishedHook)
-
#flag_value(name : String) : String | Bool
Returns the value of a flag in the format
"#{key}=#{value}". -
#flags
Returns the flags for this program.
- #flags_annotation
- #float
- #float32
- #float64
-
#has_flag?(name : String)
Returns
trueif name is in the program's flags. - #hash_of(key_type, value_type)
-
#hash_type
Returns the
Hashtype -
#host_compiler
Creates a compiler instance with the host as target used for macro_run compilation.
-
#host_flag_value(name : String) : String | Bool
Returns the value of a host flag in the format
"#{key}=#{value}". - #host_flags
- #indexable
- #instance_align_of(type)
- #instance_offset_of(type, element_index)
- #instance_size_of(type)
- #int
- #int128
- #int16
- #int32
- #int64
- #int8
-
#int?(int)
Returns the
IntegerTypethat matches the given Int value - #int_type(signed, size)
- #interpreted_node_hook : Proc(ASTNode, Bool, Bool, Location | Nil, Nil) | Nil
- #interpreted_node_hook=(interpreted_node_hook : Proc(ASTNode, Bool, Bool, Location | Nil, Nil) | Nil)
- #lib_flags(cross_compiling : Bool = false)
- #link_annotation
-
#link_annotations
Returns every @[Link] annotation in the program parsed as
LinkAnnotation -
#literal_expander
Returns a
LiteralExpanderuseful to expand literal like arrays and hashes into simpler forms. - #llvm_id
- #llvm_typer
-
#lookup_macro_type(name : Path)
Returns the macro type named by a given AST node in the macro language.
- #lookup_macro_type(name : Union)
- #lookup_macro_type(name : ASTNode)
-
#lookup_path_item(name : String, lookup_self, lookup_in_namespace, include_private, location)
Looks up a single path item relative to *self`.
- #lookup_private_matches(filename, signature, analyze_all = false)
- #macro_compile(filename)
- #macro_expanded_hook : Proc(Nil) | Nil
- #macro_expanded_hook=(macro_expanded_hook : Proc(Nil) | Nil)
-
#macro_expander
Returns a
MacroExpanderto expand macro code into crystal code. - #macro_expansion_error_hook : Proc(Exception | Nil, Nil) | Nil
- #macro_expansion_error_hook=(macro_expansion_error_hook : Proc(Exception | Nil, Nil) | Nil)
- #macro_no_return
- #macro_run(filename, args)
-
#metaclass
Returns this type's metaclass, which holds class methods for this type.
-
#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.
- #naked_annotation
- #named_tuple
-
#named_tuple_of(entries : Hash(String, Type) | NamedTuple)
Returns the
TypeforNamedTuple(**entries) -
#named_tuple_of(entries : Array(NamedArgumentType))
Returns the
TypeforNamedTuple(**entries) -
#new_parser(source : String, var_scopes = [Set(String).new])
Returns a new
Parserfor the given source, sharing the string pool and warnings with this program. - #new_temp_var(node : ASTNode) : Var
- #new_temp_var(prefix : String | Nil = nil) : Var
-
#new_temp_var_name(node : ASTNode) : String
Returns a unique variable name associated with the given AST node.
-
#new_temp_var_name(prefix : String | Nil = nil) : String
Returns a unique variable name associated with the given prefix.
- #nil
-
#nil_type
Returns the
Niltype - #nil_var
- #nilable(type)
- #no_inline_annotation
- #no_return
-
#node_macro_type(node : ASTNode) : MacroType
Returns the macro type for a given AST node.
- #normalize(node, inside_exp = false, current_def = nil)
- #number
- #object
- #offset_of(type, element_index)
- #optimization_mode : Crystal::Compiler::OptimizationMode
- #optimization_mode=(optimization_mode : Crystal::Compiler::OptimizationMode)
- #packed_annotation
- #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)
- #parse_macro_source(generated_source, macro_expansion_pragmas, the_macro, node, vars, current_def = nil, inside_type = false, inside_exp = false, visibility : Visibility = :public, &)
- #pointer
- #pointer_of(type)
- #predefined_constants : Array(Crystal::Const)
- #primitive_annotation
- #proc
- #proc_of(nodes : Array(ASTNode), return_type : Type)
- #proc_of(types : Array)
-
#process_finished_hooks(visitor)
Visits all finished hooks with the given visitor
-
#progress_tracker : Crystal::ProgressTracker
A
ProgressTrackerobject which tracks compilation progress. -
#progress_tracker=(progress_tracker : Crystal::ProgressTracker)
A
ProgressTrackerobject which tracks compilation progress. - #raises_annotation
- #range
- #range_of(begin_type, end_type)
-
#record_require(filename, relative_to) : Nil
Remembers that the program depends on this require.
- #recorded_requires : Array(Crystal::Program::RecordedRequire)
- #recorded_requires=(recorded_requires : Array(Crystal::Program::RecordedRequire))
- #reference
- #regex
-
#requires : Set(String)
All required files.
- #returns_twice_annotation
- #run(code, filename : String | Nil = nil, debug = Debug::Default)
- #run(code, return_type : T.class, filename : String | Nil = nil, debug = Debug::Default) forall T
- #run_requires(node : Require, filenames, &) : Nil
-
#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.
-
#show_error_trace=(show_error_trace : Bool)
Whether to show error trace
-
#show_error_trace? : Bool
Whether to show error trace
- #size_bit_width
- #size_of(type)
- #slice
-
#splat_expansions : Hash(Def, Array(Type))
Hash that prevents recursive splat expansions.
- #static_array
-
#static_array_of(type, size)
Returns the
TypeforStaticArray(type, size) -
#stdout : IO
Default standard output to use in a program, while compiling.
-
#stdout=(stdout : IO)
Default standard output to use in a program, while compiling.
- #string
-
#string_pool : StringPool
A String pool to avoid creating the same strings over and over.
-
#struct
Returns the
Structtype - #symbol
-
#symbols : Set(String)
All symbols (:foo, :bar) found in the program
- #target_feature_annotation
- #target_machine : LLVM::TargetMachine
- #target_machine=(target_machine : LLVM::TargetMachine)
-
#tempfiles : Array(String)
Temporary files which are generated by macro runs that need to be deleted after the compilation is finished.
- #thread_local_annotation
-
#to_s(io : IO) : Nil
Appends a short String representation of this object which includes its class name and its object address.
-
#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.
-
#top_level_semantic_complete=(top_level_semantic_complete : Bool)
This property indicates that the compiler has finished the top-level semantic stage.
-
#top_level_semantic_complete? : Bool
This property indicates that the compiler has finished the top-level semantic stage.
- #tuple
- #tuple_of(types)
- #type_combine(types)
- #type_desc
- #type_from_literal_kind(kind : NumberKind)
- #type_merge(first : Type | Nil, second : Type | Nil) : Type | Nil
- #type_merge(types : Array(Type | Nil)) : Type | Nil
- #type_merge(nodes : Enumerable(ASTNode)) : Type | Nil
- #type_merge_union_of(types : Array(Type)) : Type | Nil
- #uint128
- #uint16
- #uint32
- #uint64
- #uint8
- #undefined_class_variable(node, owner, similar_name)
- #undefined_instance_variable(node, owner, similar_name)
- #undefined_variable_message(kind, example_name, owner)
- #union
-
#union_of(type1, type2)
Returns the
Typefortype1 | type2 - #union_of(types : Array)
-
#unions : Hash(Array(UInt64), Crystal::UnionType)
All created unions in a program, indexed by an array of opaque ids of each type in the union.
- #value
-
#vars : Hash(String, Crystal::MetaVar)
Top-level variables found in a program (only in the main file).
- #virtual_root?(type : VirtualType | VirtualMetaclassType)
- #virtual_root?(type : MetaclassType | GenericClassInstanceMetaclassType | GenericModuleInstanceMetaclassType)
-
#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.
- #visit_class_vars_initializers(node)
- #visit_main(node, visitor : MainVisitor = MainVisitor.new(self), process_finished_hooks = false, cleanup = true)
- #visit_with_finished_hooks(node, visitor)
- #void
-
#wants_doc=(wants_doc : Bool)
If
true, doc comments are attached to types and methods. -
#wants_doc? : Bool
If
true, doc comments are attached to types and methods. -
#warnings : Crystal::WarningCollection
Warning settings and all detected warnings.
-
#warnings=(warnings : Crystal::WarningCollection)
Warning settings and all detected warnings.
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) : Typemerge!(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) | Nilannotations : 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
Class Method Detail
Instance Method Detail
When Void participates in a union, it becomes Nil (users shouldn't deal with real Void values)
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.
The class var initializers stored to be used by the cleanup transformer
Colorizes the given object, depending on whether this program is configured to use colors.
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.
All constant slices constructed via the Slice.literal compiler built-in,
indexed by their buffers' internal names (e.g. $Slice:0).
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
All FileModules indexed by their filename. These store file-private defs, and top-level variables in files other than the main file.
Finds filename in the configured CRYSTAL_PATH for this program, relative to relative_to.
Returns the value of a flag in the format "#{key}=#{value}".
Or true if the flags contain key.
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.
Creates a compiler instance with the host as target used for macro_run compilation.
Returns the value of a host flag in the format "#{key}=#{value}".
Or true if the host flags contain key.
Returns a LiteralExpander useful to expand literal like arrays and hashes
into simpler forms.
Returns the macro type named by a given AST node in the macro language.
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.
Returns this type's metaclass, which holds class methods for this type.
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.
Returns the Type for NamedTuple(**entries)
Returns the Type for NamedTuple(**entries)
Returns a new Parser for the given source, sharing the string pool and
warnings with this program.
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.
Returns a unique variable name associated with the given prefix.
By convention, the prefix must start with __temp_, and defaults to it as
well.
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.
Returns the macro type for a given AST node. This association is done
through Crystal::ASTNode#class_desc.
A ProgressTracker object which tracks compilation progress.
A ProgressTracker object which tracks compilation progress.
Remembers that the program depends on this require.
All required files. The set stores absolute files. This way
files loaded by require nodes are only processed once.
Runs semantic analysis on the given node, returning a node that's typed. In the process types and methods are defined in this program.
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).
Default standard output to use in a program, while compiling.
A String pool to avoid creating the same strings over and over. This pool is passed to the parser, macro expander, etc.
Temporary files which are generated by macro runs that need to be deleted after the compilation is finished.
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>
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.
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?).
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?).
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.
Top-level variables found in a program (only in the main file).
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.
If true, doc comments are attached to types and methods.