Type Annotator#
-
namespace stapl#
-
namespace types#
Classes and types related to type checking.
-
class TypeAnnotator#
- #include <annotator.h>
A visitor for annotating AST nodes with types.
- Todo:
Add support for block scopes.
Public Functions
-
TypeAnnotator()#
Default constructor.
-
std::string operator()(ast::LiteralExprNode<int> &node)#
Annotate the type of a integer literal expression node and return the annotated type name.
- Parameters:
node – The node to annotate.
- Returns:
The annotated type of the node.
-
std::string operator()(ast::LiteralExprNode<double> &node)#
Annotate the type of a float literal expression node and return the annotated type name.
- Parameters:
node – The node to annotate.
- Returns:
The annotated type of the node.
-
std::string operator()(ast::LiteralExprNode<bool> &node)#
Annotate the type of a boolean literal expression node and return the annotated type name.
- Parameters:
node – The node to annotate.
- Returns:
The annotated type of the node.
-
std::string operator()(ast::VariableExprNode &node)#
Annotate the type of a variable expression node and return the annotated type name.
- Parameters:
node – The node to annotate.
- Returns:
The annotated type of the node.
-
std::string operator()(std::unique_ptr<ast::UnaryExprNode> &node)#
Annotate the type of a unary expression node and return the annotated type name.
- Parameters:
node – The node to annotate.
- Returns:
The annotated type of the node.
-
std::string operator()(std::unique_ptr<ast::BinaryExprNode> &node)#
Annotate the type of a binary expression node and return the annotated type name.
- Parameters:
node – The node to annotate.
- Returns:
The annotated type of the node.
-
std::string operator()(std::unique_ptr<ast::CallExprNode> &node)#
Annotate the type of a call expression node and return the annotated type name.
- Parameters:
node – The node to annotate.
- Returns:
The annotated type of the node.
-
void operator()(ast::LetStmtNode &node)#
Register the type of the variable declared by
letstatement.- Parameters:
node – The node to annotate.
-
void operator()(ast::AssignmentStmtNode &node)#
Annotate the type of a variable assignment statement node.
- Parameters:
node – The node to annotate.
-
void operator()(std::unique_ptr<ast::IfStmtNode> &node)#
Annotate the type of a if statement node.
- Parameters:
node – The node to annotate.
-
void operator()(std::unique_ptr<ast::WhileStmtNode> &node)#
Annotate the type of a while statement node.
- Parameters:
node – The node to annotate.
-
void operator()(ast::BreakStmtNode &node)#
Annotate the type of a break statement node.
Note
This function does not check if the break statement is in a loop.
- Parameters:
node – The node to annotate.
-
void operator()(ast::ContinueStmtNode &node)#
Annotate the type of a continue statement node.
Note
This function does not check if the continue statement is in a loop.
- Parameters:
node – The node to annotate.
-
void operator()(ast::ReturnStmtNode &node)#
Annotate the type of a return statement node.
- Parameters:
node – The node to annotate.
-
void operator()(std::unique_ptr<ast::CompoundStmtNode> &node)#
Annotate the type of a compound statement node.
- Parameters:
node – The node to annotate.
-
void operator()(ast::FunctionDeclNode &node)#
Annotate the type of a function declaration node.
- Parameters:
node – The node to annotate.
Private Members
-
std::unordered_map<std::string, std::string> variable_type_names = {}#
Type names of variables in current function.
- Todo:
Add support for generics and user-defined types.
-
std::unordered_map<std::string, std::vector<FuncTypeInfo>> func_types = {}#
Type information of functions.
-
class TypeAnnotator#
-
namespace types#