tipc
A TIP to LLVM compiler
SymbolTable.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ASTVisitor.h"
4 
5 #include <map>
6 #include <vector>
7 
17 class SymbolTable {
18  std::map<std::string, std::pair<ASTDeclNode *, bool>> functionNames;
19  std::map<ASTDeclNode *, std::map<std::string, ASTDeclNode *>> localNames;
20  std::vector<std::string> fieldNames;
21 
22 public:
24  std::map<std::string, std::pair<ASTDeclNode *, bool>> fMap,
25  std::map<ASTDeclNode *, std::map<std::string, ASTDeclNode *>> lMap,
26  std::vector<std::string> fSet)
27  : functionNames(fMap), localNames(lMap), fieldNames(fSet) {}
28 
33  ASTDeclNode *getFunction(std::string s);
34 
39  bool getPoly(std::string s);
40 
43  std::vector<ASTDeclNode *> getFunctions();
44 
50  ASTDeclNode *getLocal(std::string s, ASTDeclNode *f);
51 
55  std::vector<ASTDeclNode *> getLocals(ASTDeclNode *f);
56 
59  std::vector<std::string> getFields();
60 
68  static std::shared_ptr<SymbolTable> build(ASTProgram *p);
69 
71  void print(std::ostream &os);
72 };
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 symbol analysis and records results for subsequent phases.
Definition: SymbolTable.h:17
std::vector< ASTDeclNode * > getFunctions()
Return the declaration nodes for functions in the program.
Definition: SymbolTable.cpp:34
void print(std::ostream &os)
Print symbol table contents to output stream.
Definition: SymbolTable.cpp:62
bool getPoly(std::string s)
Return an indication of whether the function was declared as polymorphic.
Definition: SymbolTable.cpp:26
ASTDeclNode * getFunction(std::string s)
Return the declaration node for a given function name.
Definition: SymbolTable.cpp:18
std::vector< ASTDeclNode * > getLocals(ASTDeclNode *f)
Return the declaration nodes for locals and parameters in a function.
Definition: SymbolTable.cpp:51
std::vector< std::string > getFields()
Returns the record field names referenced in the program.
Definition: SymbolTable.cpp:60
ASTDeclNode * getLocal(std::string s, ASTDeclNode *f)
Return the declaration node for local or a parameter in a function.
Definition: SymbolTable.cpp:42
static std::shared_ptr< SymbolTable > build(ASTProgram *p)
Perform symbol analysis and construct symbol table.
Definition: SymbolTable.cpp:10
SymbolTable(std::map< std::string, std::pair< ASTDeclNode *, bool >> fMap, std::map< ASTDeclNode *, std::map< std::string, ASTDeclNode * >> lMap, std::vector< std::string > fSet)
Definition: SymbolTable.h:23