Struct ASTNode

Inheritance Relationships

Derived Types

Struct Documentation

struct ASTNode

Subclassed by AST::Assn, AST::BinOp, AST::FunctionCall, AST::Ident, AST::If, AST::Literal< _T >, AST::ObjectCall, AST::Return, AST::RhsArgs, AST::Typecase, AST::Typing, AST::UniOp, AST::While, AST::Literal< bool >, AST::Literal< int >, AST::Literal< std::string >

Public Functions

virtual ~ASTNode()
virtual void print_original_src(unsigned int indent_depth = 0) = 0
virtual bool check_initialize_before_use(InitializedList &inits, InitializedList *all_inits, bool is_method) = 0
virtual void update_initialized_list(InitializedList &inits, bool is_constructor)

Updates the initialized list in the initialized per use check.

Parameters
  • inits: Set of initialized variables.
  • is_constructor: True if the function being checked is a constructor.

virtual bool perform_type_inference(TypeCheck::Settings &settings, Quack::Class *parent_type) = 0

Implements type inference for a single note in the AST.

Return
True if type inference was successful.
Parameters
  • st: Symbol table for the method
  • return_type: Return type from the block
  • parent_type: Type of the parent node. If parent node has no type, then BASE_CLASS.

virtual bool update_inferred_type(TypeCheck::Settings &settings, Quack::Class *inferred_type, bool is_field)

Updates the symbol table and the nodes using an inferred type

Return
True if the update is successful
Parameters
  • st: Symbol table for the method
  • inferred_type: Type inferred for updating
  • this_class: Class type of the object

void set_node_type(Quack::Class *new_type)

Updates the type for the node.

Parameters
  • type: New type for the node

Quack::Class *get_node_type() const

Accessor for the type of the node.

Return
Node type

virtual std::string generate_code(CodeGen::Settings &settings, unsigned indent_lvl, bool is_lhs) const = 0
void generate_eval_branch(CodeGen::Settings settings, const unsigned indent_lvl, const std::string &true_label, const std::string &false_label)
std::string generate_temp_var(const std::string &var_to_store, CodeGen::Settings settings, unsigned indent_lvl, bool is_lhs) const

Helper function that standardizes the generation of new temporary variables.

Return
Pointer to the memory location
Parameters
  • var_to_store: Variable to store in a temporary
  • settings: Code generation settings
  • indent_lvl: Level of indentation

virtual bool contains_return_all_paths()

Checks whether the statement has a return on all paths.

Return
True the tree node has a return on all possible subpaths

Public Static Functions

static std::string indent_str(unsigned indent_level)
static const std::string define_new_label(const std::string &label_header)

Helper function used to create a label using the label header and a unique integer to ensure that there are no duplicate labels.

Return
Unique label
Parameters
  • label_header: Header used for the label

static void generate_label(CodeGen::Settings &settings, unsigned indent_lvl, const std::string &label, bool add_new_line = false)

Standardized helper function to generte a label in the output.

Parameters
  • settings: Code generation settings
  • indent_lvl: Level of indentation
  • label: Label to generate

static void generate_goto(CodeGen::Settings &settings, unsigned indent_lvl, const std::string &label, bool add_new_line = false)

Standard helper function to jump to the passed label.

Parameters
  • settings:
  • indent_lvl:
  • label: Label to go to.

static const std::string define_new_temp_var()

Helper function used to generate temporary variable names

Return
Temporary variable name

static void generate_one_line_comment(CodeGen::Settings settings, const unsigned indent_lvl, const std::string &msg)

Standardizes creating a one line comment.

Parameters
  • settings: Code generator settings
  • indent_lvl: Indentation level
  • msg: Comment message

Protected Attributes

Quack::Class *type_ = nullptr

Type for the node

Protected Static Attributes

unsigned long label_cnt_ = 0

Counter for label generator for GoTo’s

unsigned long var_cnt_ = 0

Counter for temporary variables created in the code