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

#include <mim/ast/tok.h>

Public Member Functions

 Tok ()
 Tok (Loc loc, Tag tag)
 Tok (Loc loc, char8_t c)
 Tok (Loc loc, uint64_t u)
 Tok (Loc loc, int64_t s)
 Tok (Loc loc, double d)
 Tok (Loc loc, uint64_t size, uint64_t val)
 size and val of an Idx literal; World::lit_idx makes a Lit of it at emit time.
 Tok (Loc loc, Tag tag, Sym sym)
bool isa (Tag tag) const
Tag tag () const
bool has_sym () const
Dbg dbg () const
Loc loc () const
 operator bool () const
std::pair< uint64_t, uint64_t > lit_i () const
char8_t lit_c () const
uint64_t lit_u () const
Sym sym () const
std::string str () const

Friends

std::ostream & operator<< (std::ostream &os, Tok tok)
std::ostream & operator<< (std::ostream &os, Tok::Tag tag)

Tag

enum class  Tag {
  Nil ,
  K_Bool ,
  K_Cn ,
  K_Fn ,
  K_I1 ,
  K_I16 ,
  K_I32 ,
  K_I64 ,
  K_I8 ,
  K_Idx ,
  K_Nat ,
  K_Type ,
  K_Univ ,
  K_and ,
  K_anx ,
  K_as ,
  K_axm ,
  K_cn ,
  K_con ,
  K_end ,
  K_extern ,
  K_ff ,
  K_fn ,
  K_fun ,
  K_i1 ,
  K_i16 ,
  K_i32 ,
  K_i64 ,
  K_i8 ,
  K_import ,
  K_inj ,
  K_lam ,
  K_let ,
  K_match ,
  K_mod ,
  K_norm ,
  K_plugin ,
  K_priv ,
  K_pub ,
  K_rec ,
  K_ret ,
  K_rule ,
  K_Rule ,
  K_tt ,
  K_use ,
  K_when ,
  K_where ,
  K_with ,
  EoF ,
  L_s ,
  L_u ,
  L_i ,
  L_f ,
  L_c ,
  L_str ,
  M_id ,
  D_angle_l ,
  D_angle_r ,
  D_brace_l ,
  D_brace_r ,
  D_brckt_l ,
  D_brckt_r ,
  D_curly_l ,
  D_curly_r ,
  D_paren_l ,
  D_paren_r ,
  D_quote_l ,
  D_quote_r ,
  T_add ,
  T_arrow_r ,
  T_fat_arrow ,
  T_assign ,
  T_at ,
  T_bot ,
  T_top ,
  T_box ,
  T_colon ,
  T_comma ,
  T_div ,
  T_dollar ,
  T_dot ,
  T_eq ,
  T_extract ,
  T_ge ,
  T_gt ,
  T_arrow_l ,
  T_le ,
  T_lm ,
  T_lt ,
  T_ne ,
  T_rem ,
  T_semicolon ,
  T_shl ,
  T_shr ,
  T_star ,
  T_sub ,
  T_union ,
  T_pipe
}
static const char * tag2str (Tok::Tag)
static constexpr bool is_key (Tag tag)
 Is tag something the keyword table yields? MIM_KEY occupies [1, Num_Keys]; MIM_SUBST adds a few more.
static constexpr std::optional< Precinfix_prec (Tag tag)
 Precedence of the infix operator tag; std::nullopt if tag isn't one.
static constexpr std::string_view infix_sym (Tag tag)
 Name the infix operator tag desugars to - including the leading ` ; empty for MIM_INFIX_CORE.
static constexpr Tok::Tag delim_l2r (Tag tag)
static constexpr bool is_delim_r (Tag tag)

Detailed Description

Definition at line 225 of file tok.h.

Member Enumeration Documentation

◆ Tag

enum class mim::ast::Tok::Tag
strong
Enumerator
Nil 
K_Bool 
K_Cn 
K_Fn 
K_I1 
K_I16 
K_I32 
K_I64 
K_I8 
K_Idx 
K_Nat 
K_Type 
K_Univ 
K_and 
K_anx 
K_as 
K_axm 
K_cn 
K_con 
K_end 
K_extern 
K_ff 
K_fn 
K_fun 
K_i1 
K_i16 
K_i32 
K_i64 
K_i8 
K_import 
K_inj 
K_lam 
K_let 
K_match 
K_mod 
K_norm 
K_plugin 
K_priv 
K_pub 
K_rec 
K_ret 
K_rule 
K_Rule 
K_tt 
K_use 
K_when 
K_where 
K_with 
EoF 
L_s 
L_u 
L_i 
L_f 
L_c 
L_str 
M_id 
D_angle_l 
D_angle_r 
D_brace_l 
D_brace_r 
D_brckt_l 
D_brckt_r 
D_curly_l 
D_curly_r 
D_paren_l 
D_paren_r 
D_quote_l 
D_quote_r 
T_add 
T_arrow_r 
T_fat_arrow 
T_assign 
T_at 
T_bot 
T_top 
T_box 
T_colon 
T_comma 
T_div 
T_dollar 
T_dot 
T_eq 
T_extract 
T_ge 
T_gt 
T_arrow_l 
T_le 
T_lm 
T_lt 
T_ne 
T_rem 
T_semicolon 
T_shl 
T_shr 
T_star 
T_sub 
T_union 
T_pipe 

Definition at line 229 of file tok.h.

Constructor & Destructor Documentation

◆ Tok() [1/8]

mim::ast::Tok::Tok ( )
inline

Definition at line 277 of file tok.h.

Referenced by operator<<.

◆ Tok() [2/8]

mim::ast::Tok::Tok ( Loc loc,
Tag tag )
inline

Definition at line 278 of file tok.h.

References loc(), and tag().

◆ Tok() [3/8]

mim::ast::Tok::Tok ( Loc loc,
char8_t c )
inline

Definition at line 281 of file tok.h.

References loc().

◆ Tok() [4/8]

mim::ast::Tok::Tok ( Loc loc,
uint64_t u )
inline

Definition at line 285 of file tok.h.

References loc().

◆ Tok() [5/8]

mim::ast::Tok::Tok ( Loc loc,
int64_t s )
inline

Definition at line 289 of file tok.h.

References loc().

◆ Tok() [6/8]

mim::ast::Tok::Tok ( Loc loc,
double d )
inline

Definition at line 293 of file tok.h.

References loc().

◆ Tok() [7/8]

mim::ast::Tok::Tok ( Loc loc,
uint64_t size,
uint64_t val )
inline

size and val of an Idx literal; World::lit_idx makes a Lit of it at emit time.

Definition at line 298 of file tok.h.

References loc().

◆ Tok() [8/8]

mim::ast::Tok::Tok ( Loc loc,
Tag tag,
Sym sym )
inline

Definition at line 302 of file tok.h.

References has_sym(), is_key(), loc(), sym(), and tag().

Member Function Documentation

◆ dbg()

Dbg mim::ast::Tok::dbg ( ) const
inline
Note
A failed Parser::expect yields a Nil Tok; its Dbg is anonymous instead of asserting in Tok::sym.

Definition at line 313 of file tok.h.

References has_sym(), and loc().

◆ delim_l2r()

constexpr Tok::Tag mim::ast::Tok::delim_l2r ( Tag tag)
inlinestaticconstexpr

Definition at line 269 of file tok.h.

References tag().

Referenced by mim::ast::TuplePtrn::delim_r().

◆ has_sym()

bool mim::ast::Tok::has_sym ( ) const
inline

Definition at line 311 of file tok.h.

References isa().

Referenced by dbg(), operator<<, sym(), and Tok().

◆ infix_prec()

constexpr std::optional< Prec > mim::ast::Tok::infix_prec ( Tag tag)
inlinestaticconstexpr

Precedence of the infix operator tag; std::nullopt if tag isn't one.

Definition at line 250 of file tok.h.

References CODE, MIM_INFIX, and tag().

◆ infix_sym()

constexpr std::string_view mim::ast::Tok::infix_sym ( Tag tag)
inlinestaticconstexpr

Name the infix operator tag desugars to - including the leading ` ; empty for MIM_INFIX_CORE.

Definition at line 260 of file tok.h.

References CODE, MIM_INFIX_SUGAR, and tag().

◆ is_delim_r()

constexpr bool mim::ast::Tok::is_delim_r ( Tag tag)
inlinestaticconstexpr

Definition at line 270 of file tok.h.

References tag().

◆ is_key()

constexpr bool mim::ast::Tok::is_key ( Tag tag)
inlinestaticconstexpr

Is tag something the keyword table yields? MIM_KEY occupies [1, Num_Keys]; MIM_SUBST adds a few more.

Definition at line 238 of file tok.h.

References CODE, MIM_SUBST, mim::ast::Num_Keys, and tag().

Referenced by Tok().

◆ isa()

bool mim::ast::Tok::isa ( Tag tag) const
inline

Definition at line 309 of file tok.h.

References tag().

Referenced by has_sym(), lit_c(), lit_i(), and lit_u().

◆ lit_c()

char8_t mim::ast::Tok::lit_c ( ) const
inline

Definition at line 318 of file tok.h.

References isa().

◆ lit_i()

std::pair< uint64_t, uint64_t > mim::ast::Tok::lit_i ( ) const
inline

Definition at line 317 of file tok.h.

References isa().

Referenced by mim::ast::LitExpr::emit_(), mim::ast::negate(), and mim::ast::LitExpr::stream().

◆ lit_u()

uint64_t mim::ast::Tok::lit_u ( ) const
inline

Definition at line 319 of file tok.h.

References isa().

Referenced by mim::ast::negate(), and mim::ast::LitExpr::stream().

◆ loc()

Loc mim::ast::Tok::loc ( ) const
inline

Definition at line 314 of file tok.h.

Referenced by dbg(), mim::ast::negate(), Tok(), Tok(), Tok(), Tok(), Tok(), Tok(), and Tok().

◆ operator bool()

mim::ast::Tok::operator bool ( ) const
inlineexplicit

Definition at line 315 of file tok.h.

◆ str()

std::string mim::ast::Tok::str ( ) const

Definition at line 22 of file tok.cpp.

◆ sym()

Sym mim::ast::Tok::sym ( ) const
inline

Definition at line 320 of file tok.h.

References has_sym().

Referenced by operator<<, and Tok().

◆ tag()

Tag mim::ast::Tok::tag ( ) const
inline

◆ tag2str()

const char * mim::ast::Tok::tag2str ( Tok::Tag tag)
static

Definition at line 10 of file tok.cpp.

References CODE, MIM_KEY, MIM_TOK, and tag().

Referenced by mim::ast::InfixExpr::emit_(), operator<<, operator<<, and mim::ast::InfixExpr::stream().

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream & os,
Tok tok )
friend

Definition at line 30 of file tok.cpp.

References has_sym(), operator<<, sym(), tag(), tag2str(), and Tok().

Referenced by operator<<.

◆ operator<< [2/2]

std::ostream & operator<< ( std::ostream & os,
Tok::Tag tag )
friend

Definition at line 325 of file tok.h.

References tag(), and tag2str().


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