tipc
A TIP to LLVM compiler
Public Member Functions | List of all members
PolyTypeConstraintVisitor Class Reference

Visitor generates polymorphic type constraints and collects them. This visitor is called for a function with the requirement that all called functions already have a generalized type computed in the given function polymorphic type inference map. More...

#include <PolyTypeConstraintVisitor.h>

Inheritance diagram for PolyTypeConstraintVisitor:
Inheritance graph
[legend]
Collaboration diagram for PolyTypeConstraintVisitor:
Collaboration graph
[legend]

Public Member Functions

 PolyTypeConstraintVisitor (SymbolTable *pTable, CallGraph *callGraph, std::shared_ptr< Unifier > u, std::unique_ptr< ConstraintHandler > handler)
 
virtual void endVisit (ASTFunAppExpr *element) override
 Polymorphic type constraints for function application. More...
 
- Public Member Functions inherited from TypeConstraintVisitor
 TypeConstraintVisitor ()=delete
 
 TypeConstraintVisitor (SymbolTable *st, std::shared_ptr< ConstraintHandler > handler)
 
bool visit (ASTFunction *element) override
 
void endVisit (ASTAccessExpr *element) override
 Type constraints for field access. More...
 
void endVisit (ASTAllocExpr *element) override
 Type constraints for heap allocation. More...
 
void endVisit (ASTAssignStmt *element) override
 Type rules for assignments. More...
 
void endVisit (ASTBinaryExpr *element) override
 Type constraints for binary operator. More...
 
void endVisit (ASTDeRefExpr *element) override
 Type constraints for pointer dereference. More...
 
void endVisit (ASTErrorStmt *element) override
 Type constraints for error statement. More...
 
void endVisit (ASTFunAppExpr *element) override
 Type constraints for function application. More...
 
void endVisit (ASTFunction *element) override
 Type constraints for function definition. More...
 
void endVisit (ASTIfStmt *element) override
 Type constraints for if statement. More...
 
void endVisit (ASTInputExpr *element) override
 Type constraints for input statement. More...
 
void endVisit (ASTNullExpr *element) override
 Type constraints for null literal. More...
 
void endVisit (ASTNumberExpr *element) override
 Type constraints for numeric literal. More...
 
void endVisit (ASTOutputStmt *element) override
 Type constraints for output statement. More...
 
void endVisit (ASTRecordExpr *element) override
 Type constraints for record expression. More...
 
void endVisit (ASTRefExpr *element) override
 Type constraints for address of. More...
 
void endVisit (ASTWhileStmt *element) override
 Type constraints for while loop. More...
 
- Public Member Functions inherited from ASTVisitor
virtual bool visit (ASTProgram *element)
 
virtual void endVisit (ASTProgram *element)
 
virtual bool visit (ASTNumberExpr *element)
 
virtual bool visit (ASTVariableExpr *element)
 
virtual void endVisit (ASTVariableExpr *element)
 
virtual bool visit (ASTBinaryExpr *element)
 
virtual bool visit (ASTInputExpr *element)
 
virtual bool visit (ASTFunAppExpr *element)
 
virtual bool visit (ASTAllocExpr *element)
 
virtual bool visit (ASTRefExpr *element)
 
virtual bool visit (ASTDeRefExpr *element)
 
virtual bool visit (ASTNullExpr *element)
 
virtual bool visit (ASTFieldExpr *element)
 
virtual void endVisit (ASTFieldExpr *element)
 
virtual bool visit (ASTRecordExpr *element)
 
virtual bool visit (ASTAccessExpr *element)
 
virtual bool visit (ASTDeclNode *element)
 
virtual void endVisit (ASTDeclNode *element)
 
virtual bool visit (ASTDeclStmt *element)
 
virtual void endVisit (ASTDeclStmt *element)
 
virtual bool visit (ASTAssignStmt *element)
 
virtual bool visit (ASTWhileStmt *element)
 
virtual bool visit (ASTIfStmt *element)
 
virtual bool visit (ASTOutputStmt *element)
 
virtual bool visit (ASTReturnStmt *element)
 
virtual void endVisit (ASTReturnStmt *element)
 
virtual bool visit (ASTErrorStmt *element)
 
virtual bool visit (ASTBlockStmt *element)
 
virtual void endVisit (ASTBlockStmt *element)
 

Additional Inherited Members

- Protected Member Functions inherited from TypeConstraintVisitor
std::shared_ptr< TipTypeastToVar (ASTNode *n)
 
- Protected Attributes inherited from TypeConstraintVisitor
std::shared_ptr< ConstraintHandlerconstraintHandler
 
SymbolTablesymbolTable
 

Detailed Description

Visitor generates polymorphic type constraints and collects them. This visitor is called for a function with the requirement that all called functions already have a generalized type computed in the given function polymorphic type inference map.

Constructor & Destructor Documentation

◆ PolyTypeConstraintVisitor()

PolyTypeConstraintVisitor::PolyTypeConstraintVisitor ( SymbolTable pTable,
CallGraph callGraph,
std::shared_ptr< Unifier u,
std::unique_ptr< ConstraintHandler handler 
)
explicit

Member Function Documentation

◆ endVisit()

void PolyTypeConstraintVisitor::endVisit ( ASTFunAppExpr element)
overridevirtual

Polymorphic type constraints for function application.

Type Rules for "E(E1, ..., En)": [[E]] = ([[E1]], ..., [[En]]) -> [[E(E1, ..., En)]]

Polymorphic typing handles the case where expression "E" can have a value of a function declared with the "poly" keyword. The set of functions that may be called at this call site is computed by CFA and accessed through the call graph. The "poly" attribute is accessed through the symbol table.

For such functions, we generate constraints for this call site by creating a copy of the type for the called function with "fresh" type variables for its arguments. The type for the called function has already been computed, this is enforced by type analysis, and it is called the "generic" type. The copy is called the "instantiated" type. The idea is that for each call site we create distinct instantiated types and this makes it possible for a function to match distinct argument and return value typings, e.g., to be polymorphic.

Note that code generation works just fine with polymorphic typing as long as all of the types have a common representation, i.e., they fit into the same number of bits.

Reimplemented from ASTVisitor.


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