|
tipc
A TIP to LLVM compiler
|
Perform type inference and checking. More...
#include <TypeInference.h>
Public Member Functions | |
| TypeInference (SymbolTable *s, std::shared_ptr< Unifier > u) | |
| std::shared_ptr< TipType > | getInferredType (ASTDeclNode *node) |
| Returns the type expression inferred for the given ASTDeclNode. More... | |
| void | print (std::ostream &os) |
| Print type inference results to output stream. More... | |
Static Public Member Functions | |
| static std::shared_ptr< TypeInference > | run (ASTProgram *ast, bool polyInf, CallGraph *cg, SymbolTable *symbols) |
| Generate and solve type constraints and report any errors. More... | |
Perform type inference and checking.
This class provides the check method to run type inference/checking on a given program. The inferred types for names declared in the program can then be accessed.
|
inline |
| TypeInference::getInferredType | ( | ASTDeclNode * | node | ) |
Returns the type expression inferred for the given ASTDeclNode.
After type checking completes the inferred types can be accessed for declared names. Note that it is possible to declare a variable, but never use it, in which case the inferred type will be a free type variable. A managed pointer is returned for exactly this case – when a fresh variable is generated and returned. In other cases, the resulting type will be shared with those computed during inference – hence a shared pointer.
| node | An AST declaration node. |
| void TypeInference::print | ( | std::ostream & | os | ) |
Print type inference results to output stream.
|
static |
Generate and solve type constraints and report any errors.
Visits the AST generating type constraints for each expression and solves the resulting constraints. If a term unification error is detected a UnificationError, a subtype of SemanticError, is raised. If an access to a field whose definition is absent is detected a SemanticError is raised. If no errors are found, then the inferred types for all symbols are recorded in the symbol table.
| ast | The program AST |
| polyInf | Flag indicating whether to perform polymorphic or monomorphic inference |
| cg | The program call graph |
| symbols | The symbol table |