abstract class Crystal::ASTNode

Overview

Base class for nodes in the grammar.

Direct Known Subclasses

Defined in:

compiler/crystal/codegen/ast.cr
compiler/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

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

def self.class_desc : String #

[View source]

Instance Method Detail

def accept(visitor) #

[View source]
def accept_children(visitor) #

[View source]
def add_observer(observer) #

[View source]
def at(node : ASTNode) #

Sets this node's location and end location to those of node, and returns self


[View source]
def at(location : Location | Nil) #

Updates this node's location and returns self


[View source]
def at_end(node : ASTNode) #

Sets this node's end location to those of node and returns self


[View source]
def at_end(end_location : Location | Nil) #

Updates this node's end location and returns self


[View source]
def bind(from = nil, &) #

[View source]
def bind_to(node : ASTNode) : Nil #

[View source]
def bind_to(nodes : Indexable) : Nil #

[View source]
def class_desc #

[View source]
def class_name #

[View source]
def clone #

Returns a deep copy of this node. Copied nodes retain the location and end location of the original nodes.


[View source]
def dependencies : SmallNodeList #

[View source]
def doc #

Returns the doc comment attached to this node. Not every node supports having doc comments, so by default this returns nil.


[View source]
def doc=(doc) #

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.


[View source]
def enclosing_call : Call | Nil #

[View source]
def enclosing_call=(enclosing_call : Call | Nil) #

[View source]
def end_location : Location | Nil #

The location where this node ends, or nil if the location is not known.


[View source]
def end_location=(end_location : Location | Nil) #

The location where this node ends, or nil if the location is not known.


[View source]
def false_literal? #

[View source]
def filtered_by(filter) #

[View source]
def find_owner_trace(program, owner) #

[View source]
def freeze_type #

[View source]
def inspect(io : IO) : Nil #
Description copied from class Reference

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>

[View source]
def interpret(method : String, args : Array(ASTNode), named_args : Hash(String, ASTNode) | Nil, block : Crystal::Block | Nil, interpreter : Crystal::MacroInterpreter, name_loc : Location | Nil) #

[View source]
def interpret_compare(other) #

[View source]
def length : Int32 | Nil #

Returns the number of lines between start and end locations


[View source]
def location : Location | Nil #

The location where this node starts, or nil if the location is not known.


[View source]
def location=(location : Location | Nil) #

The location where this node starts, or nil if the location is not known.


[View source]
def macro_is_a?(macro_type : MacroType) : Bool #

[View source]
def map_type(type) #

[View source]
def name_location #

[View source]
def name_size #

[View source]
def no_returns? #

[View source]
def nop? #

[View source]
def notify_observers #

[View source]
def pretty_print(pp) #

[View source]
def propagate #

[View source]
def raise(message, inner = nil, exception_type = Crystal::TypeException) #

[View source]
def raise_frozen_type(freeze_type, invalid_type, from) #

[View source]
def remove_enclosing_call(enclosing_call) #

[View source]
def remove_observer(observer) #

[View source]
def 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.

Special cases are listed inside the method body.


[View source]
def restriction_of?(other : Underscore, owner, self_free_vars = nil, other_free_vars = nil) #

[View source]
def restriction_of?(other : ASTNode, owner, self_free_vars = nil, other_free_vars = nil) #

[View source]
def restriction_of?(other : Type, owner, self_free_vars = nil, other_free_vars = nil) #

[View source]
def restriction_of?(other, owner, self_free_vars = nil, other_free_vars = nil) #

[View source]
def set_enclosing_call(enclosing_call) #

[View source]
def set_type(type : Type) #

[View source]
def set_type(type : Nil) #

[View source]
def set_type_from(type, from) #

[View source]
def simple_literal? #

[View source]
def single_expression #

It yields itself for any node, but Expressions yields first node if it holds only a node.


[View source]
def single_expression? #

It yields nil always. (It is overridden by Expressions to implement #single_expression.)


[View source]
def stringify #

[View source]
def supports_autocast?(number_autocast : Bool = true) #

number_autocast defines if casting numeric expressions to larger ones is enabled


[View source]
def symbolize #

[View source]
def to_macro_id #

[View source]
def to_s(io : IO, macro_expansion_pragmas = nil, emit_doc = false, emit_location_pragmas : Bool = false) : Nil #
Description copied from class Reference

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 to_string(context) #

[View source]
def transform(transformer) #

[View source]
def true_literal? #

[View source]
def truthy? #

[View source]
def type #

[View source]
def type(*, with_autocast = false) #

[View source]
def type=(type) #

[View source]
def type? #

[View source]
def type_from_dependencies : Type | Nil #

[View source]
def unbind_from(nodes : Nil) #

[View source]
def unbind_from(node : ASTNode) #

[View source]
def unbind_from(nodes : Enumerable(ASTNode)) #

[View source]
def update(from = nil) #

[View source]
def visibility #

[View source]
def visibility=(visibility : Visibility) #

[View source]
def warning(message, inner = nil, exception_type = Crystal::TypeException) #

[View source]
def wrong_number_of(elements, subject, given, expected) #

[View source]
def wrong_number_of(elements, given, expected) #

[View source]
def wrong_number_of_arguments(subject, given, expected) #

[View source]
def wrong_number_of_message(elements, subject, given, expected) #

[View source]
def wrong_number_of_message(elements, given, expected) #

[View source]