Mlaskal compiler support classes
Public Member Functions | List of all members
mlc::symbol_tables Class Reference

all symbol tables together More...

#include <dutables.hpp>

Public Member Functions

bool_const_symbol_pointer add_const_bool (int line, ls_id_index idx, bool val)
 creates a representation of boolean constant More...
 
int_const_symbol_pointer add_const_int (int line, ls_id_index idx, ls_int_index symidx)
 creates a representation of integer constant More...
 
real_const_symbol_pointer add_const_real (int line, ls_id_index idx, ls_real_index symidx)
 creates a representation of real constant More...
 
str_const_symbol_pointer add_const_str (int line, ls_id_index idx, ls_str_index symidx)
 creates a representation of string constant More...
 
function_symbol_pointer add_fnc (int line, ls_id_index idx, type_pointer ltype, parameter_list_ptr parlist)
 creates a representation of function More...
 
label_symbol_pointer add_label_entry (int line, ls_int_index idx, ic_label lbl)
 creates a representation of label More...
 
procedure_symbol_pointer add_proc (int line, ls_id_index idx, parameter_list_ptr parlist)
 creates a representation of procedure More...
 
type_symbol_reference add_type (int line, ls_id_index idx, type_pointer ltype)
 creates a representation of named type More...
 
variable_symbol_pointer add_var (int line, ls_id_index idx, type_pointer ltype)
 creates a variable representation More...
 
type_pointer create_array_type (type_pointer index_type, type_pointer element_type)
 creates an array type representation More...
 
type_pointer create_range_type (ls_int_index i1, ls_int_index i2)
 creates a range type representation More...
 
type_pointer create_record_type (field_list_ptr fldlist, int line=0)
 creates a record type representation More...
 
std::ostream & dump (std::ostream &o) const
 
bool enter (int line, ls_id_index idx)
 opens a block of a procedure or function More...
 
label_symbol_pointer find_label (ls_int_index idx)
 finds a label More...
 
symbol_pointer find_symbol (ls_id_index symidx)
 finds a symbol More...
 
void init_builtins ()
 
void leave (int line)
 closes a block of a procedure or function More...
 
type_pointer logical_bool ()
 boolean type More...
 
type_pointer logical_integer ()
 integer type More...
 
type_pointer logical_real ()
 real type More...
 
type_pointer logical_string ()
 string type More...
 
type_pointer logical_undef ()
 undefined type More...
 
ls_id_typels_id ()
 identifier storage More...
 
ls_int_typels_int ()
 integer literal storage More...
 
ls_real_typels_real ()
 real literal storage More...
 
ls_str_typels_str ()
 string literal storage More...
 
ls_id_index my_function_name () const
 current function More...
 
stack_address my_return_address ()
 place for the returned value More...
 
bool nested () const
 checks enter/leave status More...
 
ic_label new_label ()
 generates unique intermediate code label More...
 
ls_int_index one ()
 integer literal 1 More...
 
bool set_main_code (ls_id_index idx, icblock_pointer icb)
 assign code to the main block More...
 
bool set_subprogram_code (ls_id_index idx, icblock_pointer icb)
 assign code to a function More...
 
 symbol_tables (bool debug, mlaskal::abstract_ic *aic)
 
 ~symbol_tables ()
 

Detailed Description

all symbol tables together

Constructor & Destructor Documentation

§ symbol_tables()

mlc::symbol_tables::symbol_tables ( bool  debug,
mlaskal::abstract_ic *  aic 
)

§ ~symbol_tables()

mlc::symbol_tables::~symbol_tables ( )

Member Function Documentation

§ add_const_bool()

bool_const_symbol_pointer mlc::symbol_tables::add_const_bool ( int  line,
ls_id_index  idx,
bool  val 
)

creates a representation of boolean constant

creates a bool_const_symbol entry for 'const idx = val'

line is a line number

§ add_const_int()

int_const_symbol_pointer mlc::symbol_tables::add_const_int ( int  line,
ls_id_index  idx,
ls_int_index  symidx 
)

creates a representation of integer constant

creates a int_const_symbol entry for 'const idx = val'

line is a line number

§ add_const_real()

real_const_symbol_pointer mlc::symbol_tables::add_const_real ( int  line,
ls_id_index  idx,
ls_real_index  symidx 
)

creates a representation of real constant

creates a real_const_symbol entry for 'const idx = symidx'

line is a line number

§ add_const_str()

str_const_symbol_pointer mlc::symbol_tables::add_const_str ( int  line,
ls_id_index  idx,
ls_str_index  symidx 
)

creates a representation of string constant

creates a str_const_symbol entry for 'const idx = symidx'

line is a line number

§ add_fnc()

function_symbol_pointer mlc::symbol_tables::add_fnc ( int  line,
ls_id_index  idx,
type_pointer  ltype,
parameter_list_ptr  parlist 
)

creates a representation of function

creates a function_symbol entry for 'function idx ( parlist ) : ltype'

line is a line number

§ add_label_entry()

label_symbol_pointer mlc::symbol_tables::add_label_entry ( int  line,
ls_int_index  idx,
ic_label  lbl 
)

creates a representation of label

creates a label_symbol entry for 'label idx'

label is identified by an integer literal idx

lbl should be an unique intermediate code label (created by mlc::symbol_tables::new_label())

line is a line number

§ add_proc()

procedure_symbol_pointer mlc::symbol_tables::add_proc ( int  line,
ls_id_index  idx,
parameter_list_ptr  parlist 
)

creates a representation of procedure

creates a procedure_symbol entry for 'procedure idx ( parlist )'

line is a line number

§ add_type()

type_symbol_reference mlc::symbol_tables::add_type ( int  line,
ls_id_index  idx,
type_pointer  ltype 
)

creates a representation of named type

creates a type_symbol entry for 'type idx = symidx'

line is a line number

§ add_var()

variable_symbol_pointer mlc::symbol_tables::add_var ( int  line,
ls_id_index  idx,
type_pointer  ltype 
)

creates a variable representation

creates a global_variable_symbol or local_variable_symbol entry for 'var idx : ltype' (based on symbol_tables::nested())

line is a line number

§ create_array_type()

type_pointer mlc::symbol_tables::create_array_type ( type_pointer  index_type,
type_pointer  element_type 
)

creates an array type representation

creates an array_type entry for 'array [ index_type ] of element_type'

§ create_range_type()

type_pointer mlc::symbol_tables::create_range_type ( ls_int_index  i1,
ls_int_index  i2 
)

creates a range type representation

creates a range_type entry for 'i1 .. i2'

§ create_record_type()

type_pointer mlc::symbol_tables::create_record_type ( field_list_ptr  fldlist,
int  line = 0 
)

creates a record type representation

creates a record_type entry for 'record field_list_body end'

§ dump()

std::ostream& mlc::symbol_tables::dump ( std::ostream &  o) const

§ enter()

bool mlc::symbol_tables::enter ( int  line,
ls_id_index  idx 
)

opens a block of a procedure or function

idx must be an identifier of a procedure or a function that already has its entry

line is a line number

§ find_label()

label_symbol_pointer mlc::symbol_tables::find_label ( ls_int_index  idx)

finds a label

finds a label entry identified by integer literal idx

§ find_symbol()

symbol_pointer mlc::symbol_tables::find_symbol ( ls_id_index  symidx)

finds a symbol

returns an abstract_symbol representation assigned to the identifier symidx

  • if nested(), searches among local declarations
  • if not found, searches among global declarations
  • if not found anywhere, returns undefined (SKIND_UNDEFINED) symbol representation

§ init_builtins()

void mlc::symbol_tables::init_builtins ( )

§ leave()

void mlc::symbol_tables::leave ( int  line)

closes a block of a procedure or function

  • discards all symbol and label entries inside the block
  • closes the block (nested() becomes false)

line is a line number

§ logical_bool()

type_pointer mlc::symbol_tables::logical_bool ( )

boolean type

returns a BoolType representation of 'boolean' type

§ logical_integer()

type_pointer mlc::symbol_tables::logical_integer ( )

integer type

returns an int_type representation of 'integer' type

§ logical_real()

type_pointer mlc::symbol_tables::logical_real ( )

real type

returns a real_type representation of 'real' type

§ logical_string()

type_pointer mlc::symbol_tables::logical_string ( )

string type

returns a str_type representation of 'string' type

§ logical_undef()

type_pointer mlc::symbol_tables::logical_undef ( )

undefined type

returns an abstract_type representation of undefined type

§ ls_id()

ls_id_type& mlc::symbol_tables::ls_id ( )
inline

identifier storage

§ ls_int()

ls_int_type& mlc::symbol_tables::ls_int ( )
inline

integer literal storage

§ ls_real()

ls_real_type& mlc::symbol_tables::ls_real ( )
inline

real literal storage

§ ls_str()

ls_str_type& mlc::symbol_tables::ls_str ( )
inline

string literal storage

§ my_function_name()

ls_id_index mlc::symbol_tables::my_function_name ( ) const

current function

returns the identifier of the current function (as defined by enter())

§ my_return_address()

stack_address mlc::symbol_tables::my_return_address ( )

place for the returned value

returns the stack offset of the returned value

§ nested()

bool mlc::symbol_tables::nested ( ) const

checks enter/leave status

returns true if inside a procedure or function block

§ new_label()

ic_label mlc::symbol_tables::new_label ( )
inline

generates unique intermediate code label

§ one()

ls_int_index mlc::symbol_tables::one ( )

integer literal 1

returns the integer literal '1'

§ set_main_code()

bool mlc::symbol_tables::set_main_code ( ls_id_index  idx,
icblock_pointer  icb 
)

assign code to the main block

defines the code of the main block of a program named idx using icblock icb

icblock icb is inserted between prologue and epilogue code (including HALT) automatically generated from global variable declarations

§ set_subprogram_code()

bool mlc::symbol_tables::set_subprogram_code ( ls_id_index  idx,
icblock_pointer  icb 
)

assign code to a function

defines the code of a function/procedure named idx using icblock icb

icblock icb is inserted between prologue and epilogue code (including RET) automatically generated from local variable declarations


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