MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
mim::ast::AST Class Reference

Owns the arena all AST nodes live in as well as the AnnexInfos of all plugins. More...

#include <mim/ast/ast.h>

Classes

struct  ForeignAlias
 An anx alias in one plugin for an annex of another, e.g. anx M = core.M; in mem. More...
struct  Files

Public Member Functions

 AST (const AST &)=delete
 AST (World &)
 AST (AST &&)
 ~AST ()
template<class T, class... Args>
auto ptr (Args &&... args)
 The VLA ranges of a fe::VLA node come last, in the order its VLA_Types declares them.
template<class R, class T = std::ranges::range_value_t<R>>
fe::View< T > copy (const R &range)
 An Arena-allocated copy of range - for the few lists that do not sit behind a node.
Scope & scope ()
 A fresh Scope for a ModDecl; owned here, as an AST node never runs a destructor.
Getters
World & world () const
Driver & driver () const
Error & error () const
Sym
Sym sym (const char *s)
Sym sym (std::string_view s)
Sym sym (const std::string &s)
Sym sym_return ()
 "return".
Sym sym_error ()
 "_error_".
Manage Files

A file is parsed exactly once; AST::file hands out the File every Import of that file shares.

std::pair< Ptr< File > &, bool > file (const fe::Src *src)
Manage Annex
AnnexInfo * name2annex (Scopes &s, Dbg dbg, sub_t *sub_id, const Expr *type=nullptr)
const auto & plugin2annexes (Sym plugin)
void add_foreign_alias (Sym plugin, ForeignAlias alias)
const auto & plugin2foreign_aliases (Sym plugin)
bootstrap
void bootstrap (Sym plugin, std::ostream &h)
void bootstrap_py (Sym plugin, std::ostream &h)

Friends

void swap (AST &a1, AST &a2) noexcept

Detailed Description

Owns the arena all AST nodes live in as well as the AnnexInfos of all plugins.

Definition at line 107 of file ast.h.


Class Documentation

◆ mim::ast::AST::ForeignAlias

struct mim::ast::AST::ForeignAlias

An anx alias in one plugin for an annex of another, e.g. anx M = core.M; in mem.

Definition at line 164 of file ast.h.

Class Members
Sym alias
const AnnexInfo * annex
sub_t sub

Constructor & Destructor Documentation

◆ AST() [1/3]

mim::ast::AST::AST ( const AST & )
delete

References AST().

Referenced by AST(), AST(), mim::ast::load_plugins(), and swap.

◆ AST() [2/3]

mim::ast::AST::AST ( World & world)

Definition at line 14 of file ast.cpp.

References world().

◆ AST() [3/3]

mim::ast::AST::AST ( AST && other)

Definition at line 18 of file ast.cpp.

References AST(), swap, and world().

◆ ~AST()

mim::ast::AST::~AST ( )
default

Member Function Documentation

◆ add_foreign_alias()

void mim::ast::AST::add_foreign_alias ( Sym plugin,
ForeignAlias alias )
inline

Definition at line 169 of file ast.h.

◆ bootstrap()

void mim::ast::AST::bootstrap ( Sym plugin,
std::ostream & h )

Definition at line 66 of file ast.cpp.

References mim::Annex::mangle(), plugin2annexes(), plugin2foreign_aliases(), and sym().

◆ bootstrap_py()

void mim::ast::AST::bootstrap_py ( Sym plugin,
std::ostream & h )

Definition at line 202 of file ast.cpp.

References mim::Annex::mangle(), plugin2annexes(), plugin2foreign_aliases(), and sym().

◆ copy()

template<class R, class T = std::ranges::range_value_t<R>>
fe::View< T > mim::ast::AST::copy ( const R & range)
inline

An Arena-allocated copy of range - for the few lists that do not sit behind a node.

Definition at line 138 of file ast.h.

◆ driver()

Driver & mim::ast::AST::driver ( ) const
inline

Definition at line 117 of file ast.h.

References mim::World::driver(), and world().

Referenced by mim::ast::Parser::driver(), error(), sym(), sym(), and sym().

◆ error()

Error & mim::ast::AST::error ( ) const
inline

Definition at line 118 of file ast.h.

References driver().

Referenced by mim::ast::Scopes::error(), and name2annex().

◆ file()

std::pair< Ptr< File > &, bool > mim::ast::AST::file ( const fe::Src * src)

The slot of src and whether it is fresh; a fresh slot is nullptr until the caller fills it in. A nullptr slot that is not fresh is a file still being parsed further up the stack.

Definition at line 25 of file ast.cpp.

Referenced by mim::ast::Parser::import().

◆ name2annex()

AnnexInfo * mim::ast::AST::name2annex ( Scopes & s,
Dbg dbg,
sub_t * sub_id,
const Expr * type = nullptr )

Registers dbg as an annex, deriving plugin/tag/sub from dbg's source file and s's current mod-nesting (Scopes::mod_depth/Scopes::enclosing_mod); sub_id receives dbg's sub index within its tag. nullptr if dbg is anonymous or nests more than one mod deep. type, if given, is the declared body whose constructor or field names become AnnexInfo::names.

Definition at line 359 of file bind.cpp.

References mim::ast::add_names(), error(), mim::ast::loc2plugin(), mim::Annex::mangle(), and sym_error().

◆ plugin2annexes()

const auto & mim::ast::AST::plugin2annexes ( Sym plugin)
inline

Definition at line 161 of file ast.h.

Referenced by bootstrap(), and bootstrap_py().

◆ plugin2foreign_aliases()

const auto & mim::ast::AST::plugin2foreign_aliases ( Sym plugin)
inline

Definition at line 170 of file ast.h.

Referenced by bootstrap(), and bootstrap_py().

◆ ptr()

template<class T, class... Args>
auto mim::ast::AST::ptr ( Args &&... args)
inline

The VLA ranges of a fe::VLA node come last, in the order its VLA_Types declares them.

Definition at line 132 of file ast.h.

◆ scope()

Scope & mim::ast::AST::scope ( )
inline

A fresh Scope for a ModDecl; owned here, as an AST node never runs a destructor.

Definition at line 144 of file ast.h.

◆ sym() [1/3]

Sym mim::ast::AST::sym ( const char * s)
inline

Definition at line 123 of file ast.h.

References driver().

Referenced by bootstrap(), bootstrap_py(), sym_error(), and sym_return().

◆ sym() [2/3]

Sym mim::ast::AST::sym ( const std::string & s)
inline

Definition at line 125 of file ast.h.

References driver().

◆ sym() [3/3]

Sym mim::ast::AST::sym ( std::string_view s)
inline

Definition at line 124 of file ast.h.

References driver().

◆ sym_error()

Sym mim::ast::AST::sym_error ( )
inline

"_error_".

Definition at line 127 of file ast.h.

References sym().

Referenced by name2annex().

◆ sym_return()

Sym mim::ast::AST::sym_return ( )
inline

"return".

Definition at line 126 of file ast.h.

References sym().

◆ world()

World & mim::ast::AST::world ( ) const
inline

Definition at line 116 of file ast.h.

Referenced by AST(), AST(), driver(), and mim::ast::Emitter::world().

◆ swap

void swap ( AST & a1,
AST & a2 )
friend

Definition at line 179 of file ast.h.

References AST(), and swap.

Referenced by AST(), and swap.


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