Yume
Public Member Functions | Public Attributes | List of all members
yume::Fn Struct Reference

A function declaration in the compiler. More...

#include <vals.hpp>

Collaboration diagram for yume::Fn:
Collaboration graph
[legend]

Public Member Functions

 Fn (Def def, ast::Program *member, optional< ty::Type > parent, Substitutions subs)
 
 Fn (Def def, ast::Program *member, optional< ty::Type > parent, nullable< Substitutions * > parent_subs, vector< GenericKey > generic={}, vector< unique_ptr< ty::Generic > > primary_generics={})
 
auto fn_body () -> ast::FnDecl::Body &
 
auto compound_body () -> ast::Compound &
 
auto ast () const -> const ast::Stmt &
 
auto ast () -> ast::Stmt &
 
auto get_self_ty () const -> optional< ty::Type >
 
auto get_subs () const -> const Substitutions &
 
auto get_subs () -> Substitutions &
 
auto ret () const -> optional< ty::Type >
 
auto arg_count () const -> size_t
 
auto arg_types () const -> vector< ty::Type >
 
auto arg_names () const -> vector< string >
 
auto arg_nodes () const -> const vector< ast::TypeName > &
 
auto args () const -> vector< FnArg >
 
auto varargs () const -> bool
 
auto primitive () const -> bool
 
auto abstract () const -> bool
 
auto extern_decl () const -> bool
 
auto local () const -> bool
 
auto extern_linkage () const -> bool
 
void make_extern_linkage (bool value=true)
 
auto has_annotation (const string &name) const -> bool
 
auto name () const noexcept -> string
 
auto get_or_create_instantiation (Substitutions &subs) noexcept -> std::pair< bool, Fn & >
 
auto create_instantiation (Substitutions &subs) noexcept -> Fn &
 

Public Attributes

Def def
 The ast node that defines this declaration. More...
 
const ty::Functionfn_ty {}
 
optional< ty::Typeself_ty {}
 If this function is in the body of a struct, this points to its type. Used for the self type. More...
 
ast::Programmember {}
 The program this declaration is a member of. More...
 
vector< unique_ptr< ty::Generic > > primary_generics {}
 
Substitutions subs
 If this is an instantiation of a template, a mapping between type variables and their substitutions. More...
 
llvm::Function * llvm {}
 The LLVM function definition corresponding to this function or constructor. More...
 
std::unordered_map< Substitutions, unique_ptr< Fn > > instantiations {}
 

Detailed Description

A function declaration in the compiler.

The primary use of this structure is to bind together the AST declaration of a function (ast::FnDecl) and the bytecode body of a function (llvm::Function). A function template may also be a Fn. Since a template doesn't actually have a body, its m_llvm_fn is nullptr. All the instantiations of a template are stored in instantiations.

Definition at line 52 of file vals.hpp.

Constructor & Destructor Documentation

◆ Fn() [1/2]

yume::Fn::Fn ( Def  def,
ast::Program member,
optional< ty::Type parent,
Substitutions  subs 
)
inline

Definition at line 68 of file vals.hpp.

◆ Fn() [2/2]

yume::Fn::Fn ( Def  def,
ast::Program member,
optional< ty::Type parent,
nullable< Substitutions * >  parent_subs,
vector< GenericKey generic = {},
vector< unique_ptr< ty::Generic > >  primary_generics = {} 
)
inline

Definition at line 71 of file vals.hpp.

Member Function Documentation

◆ abstract()

auto yume::Fn::abstract ( ) const -> bool

◆ arg_count()

auto yume::Fn::arg_count ( ) const -> size_t

Definition at line 87 of file vals.cpp.

References def, and yume::visitable_variant< Ts >::visit().

◆ arg_names()

auto yume::Fn::arg_names ( ) const -> vector<string>

Definition at line 92 of file vals.cpp.

Referenced by yume::Compiler::declare().

◆ arg_nodes()

auto yume::Fn::arg_nodes ( ) const -> const vector<ast::TypeName>&

Definition at line 93 of file vals.cpp.

References ast(), def, and yume::visitable_variant< Ts >::visit().

◆ arg_types()

auto yume::Fn::arg_types ( ) const -> vector<ty::Type>

Definition at line 91 of file vals.cpp.

Referenced by yume::semantic::Overload::dump(), and yume::vtable_entry_for().

◆ args()

auto yume::Fn::args ( ) const -> vector<FnArg>

Definition at line 96 of file vals.cpp.

◆ ast() [1/2]

auto yume::Fn::ast ( ) -> ast::Stmt&

Definition at line 71 of file vals.cpp.

References yume::ast::AST::visit().

◆ ast() [2/2]

auto yume::Fn::ast ( ) const -> const ast::Stmt&

◆ compound_body()

auto yume::Fn::compound_body ( ) -> ast::Compound&

Definition at line 128 of file vals.cpp.

References yume::ast::FnDecl::body, and yume::ast::Compound::visit().

Referenced by yume::Compiler::define().

◆ create_instantiation()

auto yume::Fn::create_instantiation ( Substitutions subs) -> Fn&
noexcept

Definition at line 20 of file vals.cpp.

◆ extern_decl()

auto yume::Fn::extern_decl ( ) const -> bool

◆ extern_linkage()

auto yume::Fn::extern_linkage ( ) const -> bool

◆ fn_body()

auto yume::Fn::fn_body ( ) -> ast::FnDecl::Body&

◆ get_or_create_instantiation()

auto yume::Fn::get_or_create_instantiation ( Substitutions subs) -> std::pair<bool, Fn&>
noexcept

Definition at line 36 of file vals.cpp.

Referenced by yume::semantic::TypeWalker::expression().

◆ get_self_ty()

auto yume::Fn::get_self_ty ( ) const -> optional<ty::Type>
inline

Definition at line 80 of file vals.hpp.

References self_ty.

◆ get_subs() [1/2]

auto yume::Fn::get_subs ( ) -> Substitutions&
inline

Definition at line 82 of file vals.hpp.

References subs.

◆ get_subs() [2/2]

auto yume::Fn::get_subs ( ) const -> const Substitutions&
inline

Definition at line 81 of file vals.hpp.

References subs.

◆ has_annotation()

auto yume::Fn::has_annotation ( const string &  name) const -> bool

Definition at line 118 of file vals.cpp.

Referenced by yume::Compiler::declare(), and yume::DeclLike::opaque_self().

◆ local()

auto yume::Fn::local ( ) const -> bool

Definition at line 112 of file vals.cpp.

References yume::always_false, def, and yume::visitable_variant< Ts >::visit().

Referenced by yume::Compiler::declare().

◆ make_extern_linkage()

void yume::Fn::make_extern_linkage ( bool  value = true)

◆ name()

auto yume::Fn::name ( ) const -> string
noexcept

◆ primitive()

auto yume::Fn::primitive ( ) const -> bool

◆ ret()

auto yume::Fn::ret ( ) const -> optional<ty::Type>

Definition at line 78 of file vals.cpp.

References ast(), def, ret(), self_ty, and yume::visitable_variant< Ts >::visit().

Referenced by ret(), and yume::vtable_entry_for().

◆ varargs()

auto yume::Fn::varargs ( ) const -> bool

Member Data Documentation

◆ def

Def yume::Fn::def

The ast node that defines this declaration.

Definition at line 54 of file vals.hpp.

Referenced by abstract(), arg_count(), arg_nodes(), ast(), extern_decl(), extern_linkage(), local(), make_extern_linkage(), name(), primitive(), ret(), and varargs().

◆ fn_ty

const ty::Function* yume::Fn::fn_ty {}

Definition at line 55 of file vals.hpp.

Referenced by yume::Compiler::declare(), and yume::Compiler::expression().

◆ instantiations

std::unordered_map<Substitutions, unique_ptr<Fn> > yume::Fn::instantiations {}

Definition at line 66 of file vals.hpp.

◆ llvm

llvm::Function* yume::Fn::llvm {}

The LLVM function definition corresponding to this function or constructor.

Definition at line 65 of file vals.hpp.

Referenced by yume::Compiler::declare(), yume::Compiler::define(), and yume::Compiler::statement().

◆ member

ast::Program* yume::Fn::member {}

The program this declaration is a member of.

Definition at line 59 of file vals.hpp.

Referenced by yume::Compiler::declare(), and yume::Compiler::expression().

◆ primary_generics

vector<unique_ptr<ty::Generic> > yume::Fn::primary_generics {}

Definition at line 61 of file vals.hpp.

◆ self_ty

optional<ty::Type> yume::Fn::self_ty {}

If this function is in the body of a struct, this points to its type. Used for the self type.

Definition at line 57 of file vals.hpp.

Referenced by yume::Compiler::define(), yume::semantic::Overload::dump(), get_self_ty(), and ret().

◆ subs

Substitutions yume::Fn::subs

If this is an instantiation of a template, a mapping between type variables and their substitutions.

Definition at line 63 of file vals.hpp.

Referenced by get_subs().


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