abstract class
Crystal::ASTNode
Overview
Base class for nodes in the grammar.
Direct Known Subclasses
- Crystal::Alias
- Crystal::Annotation
- Crystal::AnnotationDef
- Crystal::Arg
- Crystal::ArrayLiteral
- Crystal::Asm
- Crystal::AsmOperand
- Crystal::Assign
- Crystal::AssignWithRestriction
- Crystal::BinaryOp
- Crystal::Block
- Crystal::BoolLiteral
- Crystal::Call
- Crystal::Case
- Crystal::Cast
- Crystal::CharLiteral
- Crystal::ClassDef
- Crystal::ClassVar
- Crystal::ControlExpression
- Crystal::CStructOrUnionDef
- Crystal::Def
- Crystal::EnumDef
- Crystal::ExceptionHandler
- Crystal::Expressions
- Crystal::Extend
- Crystal::ExternalVar
- Crystal::FileNode
- Crystal::FunDef
- Crystal::Generic
- Crystal::Global
- Crystal::HashLiteral
- Crystal::If
- Crystal::ImplicitObj
- Crystal::Include
- Crystal::InstanceVar
- Crystal::IsA
- Crystal::LibDef
- Crystal::Macro
- Crystal::MacroExpression
- Crystal::MacroFor
- Crystal::MacroId
- Crystal::MacroIf
- Crystal::MacroLiteral
- Crystal::MacroVar
- Crystal::MagicConstant
- Crystal::Metaclass
- Crystal::MetaMacroVar
- Crystal::MetaVar
- Crystal::ModuleDef
- Crystal::MultiAssign
- Crystal::NamedArgument
- Crystal::NamedTupleLiteral
- Crystal::NilableCast
- Crystal::NilLiteral
- Crystal::Nop
- Crystal::NumberLiteral
- Crystal::OffsetOf
- Crystal::OpAssign
- Crystal::Path
- Crystal::Primitive
- Crystal::ProcLiteral
- Crystal::ProcNotation
- Crystal::ProcPointer
- Crystal::RangeLiteral
- Crystal::ReadInstanceVar
- Crystal::RegexLiteral
- Crystal::Require
- Crystal::Rescue
- Crystal::RespondsTo
- Crystal::Select
- Crystal::Self
- Crystal::StringInterpolation
- Crystal::StringLiteral
- Crystal::SymbolLiteral
- Crystal::TupleLiteral
- Crystal::TypeDeclaration
- Crystal::TypeDef
- Crystal::TypeFilteredNode
- Crystal::TypeNode
- Crystal::TypeOf
- Crystal::UnaryExpression
- Crystal::Underscore
- Crystal::UninitializedVar
- Crystal::Union
- Crystal::Unless
- Crystal::Unreachable
- Crystal::Until
- Crystal::Var
- Crystal::VisibilityModifier
- Crystal::When
- Crystal::While
- Crystal::Yield
- Crystal::YieldBlockBinder
Defined in:
compiler/crystal/codegen/ast.crcompiler/crystal/macros/methods.cr
compiler/crystal/macros/types.cr
compiler/crystal/semantic/ast.cr
compiler/crystal/semantic/bindings.cr
compiler/crystal/semantic/call_error.cr
compiler/crystal/semantic/filters.cr
compiler/crystal/semantic/restrictions.cr
compiler/crystal/syntax/ast.cr
compiler/crystal/syntax/to_s.cr
compiler/crystal/syntax/transformer.cr
compiler/crystal/syntax/visitor.cr
compiler/crystal/warnings.cr
Class Method Summary
Instance Method Summary
- #accept(visitor)
- #accept_children(visitor)
- #add_observer(observer)
-
#at(node : ASTNode)
Sets this node's location and end location to those of
node, and returnsself -
#at(location : Location | Nil)
Updates this node's location and returns
self -
#at_end(node : ASTNode)
Sets this node's end location to those of
nodeand returns self -
#at_end(end_location : Location | Nil)
Updates this node's end location and returns
self - #bind(from = nil, &)
- #bind_to(node : ASTNode) : Nil
- #bind_to(nodes : Indexable) : Nil
- #class_desc
- #class_name
-
#clone
Returns a deep copy of this node.
- #dependencies : SmallNodeList
-
#doc
Returns the doc comment attached to this node.
-
#doc=(doc)
Attaches a doc comment to this node.
- #enclosing_call : Call | Nil
- #enclosing_call=(enclosing_call : Call | Nil)
-
#end_location : Location | Nil
The location where this node ends, or
nilif the location is not known. -
#end_location=(end_location : Location | Nil)
The location where this node ends, or
nilif the location is not known. - #false_literal?
- #filtered_by(filter)
- #find_owner_trace(program, owner)
- #freeze_type
-
#inspect(io : IO) : Nil
Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.
- #interpret(method : String, args : Array(ASTNode), named_args : Hash(String, ASTNode) | Nil, block : Crystal::Block | Nil, interpreter : Crystal::MacroInterpreter, name_loc : Location | Nil)
- #interpret_compare(other)
-
#length : Int32 | Nil
Returns the number of lines between start and end locations
-
#location : Location | Nil
The location where this node starts, or
nilif the location is not known. -
#location=(location : Location | Nil)
The location where this node starts, or
nilif the location is not known. - #macro_is_a?(macro_type : MacroType) : Bool
- #map_type(type)
- #name_location
- #name_size
- #no_returns?
- #nop?
- #notify_observers
- #pretty_print(pp)
- #propagate
- #raise(message, inner = nil, exception_type = Crystal::TypeException)
- #raise_frozen_type(freeze_type, invalid_type, from)
- #remove_enclosing_call(enclosing_call)
- #remove_observer(observer)
-
#restrict_type_to_freeze_type(freeze_type, type)
Computes the type resulting from assigning type to freeze_type, in the case where freeze_type is not nil.
- #restriction_of?(other : Underscore, owner, self_free_vars = nil, other_free_vars = nil)
- #restriction_of?(other : ASTNode, 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, owner, self_free_vars = nil, other_free_vars = nil)
- #set_enclosing_call(enclosing_call)
- #set_type(type : Type)
- #set_type(type : Nil)
- #set_type_from(type, from)
- #simple_literal?
-
#single_expression
It yields itself for any node, but
Expressionsyields first node if it holds only a node. -
#single_expression?
It yields
nilalways. - #stringify
-
#supports_autocast?(number_autocast : Bool = true)
number_autocastdefines if casting numeric expressions to larger ones is enabled - #symbolize
- #to_macro_id
-
#to_s(io : IO, macro_expansion_pragmas = nil, emit_doc = false, emit_location_pragmas : Bool = false) : Nil
Appends a short String representation of this object which includes its class name and its object address.
- #to_string(context)
- #transform(transformer)
- #true_literal?
- #truthy?
- #type
- #type(*, with_autocast = false)
- #type=(type)
- #type?
- #type_from_dependencies : Type | Nil
- #unbind_from(nodes : Nil)
- #unbind_from(node : ASTNode)
- #unbind_from(nodes : Enumerable(ASTNode))
- #update(from = nil)
- #visibility
- #visibility=(visibility : Visibility)
- #warning(message, inner = nil, exception_type = Crystal::TypeException)
- #wrong_number_of(elements, subject, given, expected)
- #wrong_number_of(elements, given, expected)
- #wrong_number_of_arguments(subject, given, expected)
- #wrong_number_of_message(elements, subject, given, expected)
- #wrong_number_of_message(elements, given, expected)
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
Class Method Detail
Instance Method Detail
Sets this node's location and end location to those
of node, and returns self
Sets this node's end location to those of node and
returns self
Updates this node's end location and returns self
Returns a deep copy of this node. Copied nodes retain the location and end location of the original nodes.
Returns the doc comment attached to this node. Not every node
supports having doc comments, so by default this returns nil.
Attaches a doc comment to this node. Not every node supports having doc comments, so by default this does nothing and some subclasses implement this.
The location where this node ends, or nil
if the location is not known.
The location where this node ends, or nil
if the location is not known.
Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>
Returns the number of lines between start and end locations
The location where this node starts, or nil
if the location is not known.
The location where this node starts, or nil
if the location is not known.
Computes the type resulting from assigning type to freeze_type, in the case where freeze_type is not nil.
Special cases are listed inside the method body.
It yields itself for any node, but Expressions yields first node
if it holds only a node.
It yields nil always.
(It is overridden by Expressions to implement #single_expression.)
number_autocast defines if casting numeric expressions to larger ones is enabled
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>