tan  0.0.1
tanlang::ASTBase Class Referenceabstract
Inheritance diagram for tanlang::ASTBase:
Collaboration diagram for tanlang::ASTBase:

Public Member Functions

 ASTBase (ASTNodeType node_type, TokenizedSourceFile *src, int bp)
 
ASTNodeType get_node_type () const
 
void set_node_type (ASTNodeType node_type)
 
int get_bp () const
 
Contextctx ()
 
virtual vector< ASTBase * > get_children () const
 Get a ordered list of child nodes. More...
 
str repr (const str &prefix="-") const
 AST tree string representation. More...
 
virtual bool is_stmt () const =0
 
virtual bool is_expr () const =0
 
virtual str terminal_token () const
 Which terminal token is expected immediately after this node. More...
 
- Public Member Functions inherited from tanlang::SourceTraceable
 SourceTraceable (TokenizedSourceFile *src)
 
uint32_t start () const
 
uint32_t end () const
 
void set_start (uint32_t val)
 
void set_end (uint32_t val)
 
TokenizedSourceFilesrc () const
 

Static Public Attributes

static umap< ASTNodeType, str > ASTTypeNames
 string representation of ASTNodeType More...
 
static umap< ASTNodeType, int > OpPrecedence
 operator precedence of tokens More...
 

Protected Member Functions

virtual str to_string (bool include_source_code=false) const
 Different from repr, to_string output doesn't include child nodes. More...
 
virtual ASTBaseget () const
 Get the "actual" this. Used for implementing proxy classes. More...
 

Detailed Description

Definition at line 13 of file ast_base.h.

Member Function Documentation

◆ get()

ASTBase * ASTBase::get ( ) const
protectedvirtual

Get the "actual" this. Used for implementing proxy classes.

Reimplemented in tanlang::BinaryOrUnary.

Definition at line 49 of file ast_base.cpp.

◆ get_children()

◆ repr()

str ASTBase::repr ( const str &  prefix = "-") const

AST tree string representation.

Definition at line 23 of file ast_base.cpp.

References get_children(), and to_string().

◆ terminal_token()

virtual str tanlang::ASTBase::terminal_token ( ) const
inlinevirtual

Which terminal token is expected immediately after this node.

Reimplemented in tanlang::If, tanlang::Loop, tanlang::CompoundStmt, tanlang::Intrinsic, tanlang::StructDecl, and tanlang::FunctionDecl.

Definition at line 45 of file ast_base.h.

◆ to_string()

str ASTBase::to_string ( bool  include_source_code = false) const
protectedvirtual

Different from repr, to_string output doesn't include child nodes.

Reimplemented in tanlang::CompoundStmt.

Definition at line 38 of file ast_base.cpp.

References ASTTypeNames.

Referenced by repr(), and tanlang::CompoundStmt::to_string().

Member Data Documentation

◆ ASTTypeNames

umap< ASTNodeType, str > ASTBase::ASTTypeNames
static

string representation of ASTNodeType

Definition at line 16 of file ast_base.h.

Referenced by to_string().

◆ OpPrecedence

umap< ASTNodeType, int > ASTBase::OpPrecedence
static
Initial value:
= {
{ASTNodeType::PROGRAM, PREC_LOWEST },
{ASTNodeType::COMPOUND_STATEMENT, PREC_LOWEST },
{ASTNodeType::PARENTHESIS, PREC_CALL },
{ASTNodeType::RET, PREC_LOWEST },
{ASTNodeType::IF, PREC_LOWEST },
{ASTNodeType::STRING_LITERAL, PREC_LITERAL},
{ASTNodeType::CAST, PREC_CAST },
{ASTNodeType::ASSIGN, PREC_ASSIGN }
}

operator precedence of tokens

Definition at line 19 of file ast_base.h.


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