tipc
A TIP to LLVM compiler
TypeInference.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ASTDeclNode.h"
4 #include "ASTProgram.h"
5 #include "CallGraph.h"
6 #include "SymbolTable.h"
7 #include "Unifier.h"
8 #include <memory>
9 
18  SymbolTable *symbols;
19 
20  // This unifier stores either the monomorphic or polymorphic type inference
21  // results
22  std::shared_ptr<Unifier> unifier;
23 
24 public:
25  TypeInference(SymbolTable *s, std::shared_ptr<Unifier> u)
26  : symbols(s), unifier(u) {}
27 
45  static std::shared_ptr<TypeInference>
46  run(ASTProgram *ast, bool polyInf, CallGraph *cg, SymbolTable *symbols);
47 
63  std::shared_ptr<TipType> getInferredType(ASTDeclNode *node);
64 
66  void print(std::ostream &os);
67 };
Class for declaring a name, e.g., function, parameter, variable.
Definition: ASTDeclNode.h:7
Class for a program which is a name and a list of functions.
Definition: ASTProgram.h:11
Performs control flow analysis and records results for subsequent phases Generates call graph of a pr...
Definition: CallGraph.h:22
Performs symbol analysis and records results for subsequent phases.
Definition: SymbolTable.h:17
Perform type inference and checking.
Definition: TypeInference.h:17
static std::shared_ptr< TypeInference > run(ASTProgram *ast, bool polyInf, CallGraph *cg, SymbolTable *symbols)
Generate and solve type constraints and report any errors.
Definition: TypeInference.cpp:190
TypeInference(SymbolTable *s, std::shared_ptr< Unifier > u)
Definition: TypeInference.h:25
std::shared_ptr< TipType > getInferredType(ASTDeclNode *node)
Returns the type expression inferred for the given ASTDeclNode.
Definition: TypeInference.cpp:196
void print(std::ostream &os)
Print type inference results to output stream.
Definition: TypeInference.cpp:201