Yume
Public Member Functions | Protected Member Functions | List of all members
yume::ast::AST Class Referenceabstract

All nodes in the AST tree of the program inherit from this class. More...

#include <ast.hpp>

Inheritance diagram for yume::ast::AST:
Inheritance graph
[legend]

Public Member Functions

 AST (const AST &)=delete
 
 AST (AST &&)=default
 
auto operator= (const AST &) -> AST &=delete
 
auto operator= (AST &&) -> AST &=delete
 
virtual ~AST ()=default
 
virtual void visit (Visitor &visitor) const =0
 Recursively visit this ast node and all its constituents. More...
 
auto val_ty () const noexcept -> optional< ty::Type >
 
auto ensure_ty () const -> ty::Type
 
void val_ty (optional< ty::Type > type)
 
void attach_to (nonnull< AST * > other)
 Make the type of this node depend on the type of other. More...
 
auto kind () const -> Kind
 
auto kind_name () const -> string
 Human-readable string representation of the Kind of this node. More...
 
auto token_range () const -> const span< Token > &
 
auto equals_by_hash (ast::AST &other) const -> bool
 
auto location () const -> Loc
 The union of the locations of the Tokens making up this node. More...
 
virtual auto describe () const -> string
 A short, string representation for debugging. More...
 
virtual auto clone () const -> AST *=0
 Deep copy, except for the type and attachments. More...
 

Protected Member Functions

void unify_val_ty ()
 Verify the type compatibility of the depends of this node, and merge the types if possible. This is called every time the node's type is updated. More...
 
auto tok () const noexcept -> span< Token >
 
 AST (Kind kind, span< Token > tok)
 

Detailed Description

All nodes in the AST tree of the program inherit from this class.

AST nodes cannot be copied or moved as all special member functions (aside from the destructor) are deleted. There will always be one instance for a specific node during the lifetype of the compiler. However note that AST nodes can be cloned with the clone() method, which will produce a deep copy. This is used when instantiating a template. The clone will have the exact same structure and locations but distinct types, depending on what the types the template is instantiated with.

Definition at line 224 of file ast.hpp.

Constructor & Destructor Documentation

◆ AST() [1/3]

yume::ast::AST::AST ( Kind  kind,
span< Token tok 
)
inlineprotected

Definition at line 241 of file ast.hpp.

◆ AST() [2/3]

yume::ast::AST::AST ( const AST )
delete

◆ AST() [3/3]

yume::ast::AST::AST ( AST &&  )
default

◆ ~AST()

virtual yume::ast::AST::~AST ( )
virtualdefault

Member Function Documentation

◆ attach_to()

void yume::ast::AST::attach_to ( nonnull< AST * >  other)
inline

Make the type of this node depend on the type of other.

See also
Attachment

Definition at line 266 of file ast.hpp.

References unify_val_ty().

Referenced by yume::semantic::TypeWalker::expression(), and yume::semantic::TypeWalker::statement().

◆ clone()

virtual auto yume::ast::AST::clone ( ) const -> AST *
pure virtual

◆ describe()

auto yume::ast::AST::describe ( ) const -> string
virtual

◆ ensure_ty()

auto yume::ast::AST::ensure_ty ( ) const -> ty::Type
inline

◆ equals_by_hash()

auto yume::ast::AST::equals_by_hash ( ast::AST other) const -> bool

Definition at line 37 of file ast.cpp.

◆ kind()

auto yume::ast::AST::kind ( ) const -> Kind
inline

◆ kind_name()

auto yume::ast::AST::kind_name ( ) const -> string
inline

Human-readable string representation of the Kind of this node.

Definition at line 274 of file ast.hpp.

References kind(), and yume::ast::kind_name().

Referenced by yume::semantic::TypeWalker::body_expression(), yume::Compiler::body_statement(), yume::semantic::TypeWalker::body_statement(), and describe().

◆ location()

auto yume::ast::AST::location ( ) const -> Loc

The union of the locations of the Tokens making up this node.

Definition at line 28 of file ast.cpp.

◆ operator=() [1/2]

auto yume::ast::AST::operator= ( AST &&  ) -> AST &=delete
delete

◆ operator=() [2/2]

auto yume::ast::AST::operator= ( const AST ) -> AST &=delete
delete

◆ tok()

auto yume::ast::AST::tok ( ) const -> span<Token>
inlineprotectednoexcept

◆ token_range()

auto yume::ast::AST::token_range ( ) const -> const span<Token>&
inline

Definition at line 275 of file ast.hpp.

◆ unify_val_ty()

void yume::ast::AST::unify_val_ty ( )
protected

Verify the type compatibility of the depends of this node, and merge the types if possible. This is called every time the node's type is updated.

Definition at line 10 of file ast.cpp.

Referenced by attach_to().

◆ val_ty() [1/2]

auto yume::ast::AST::val_ty ( ) const -> optional<ty::Type>
inlinenoexcept

◆ val_ty() [2/2]

void yume::ast::AST::val_ty ( optional< ty::Type type)
inline

Definition at line 258 of file ast.hpp.

◆ visit()

virtual void yume::ast::AST::visit ( Visitor visitor) const
pure virtual

The documentation for this class was generated from the following files: