|
Intel SPMD Program Compiler
1.3.0
|
Symbol table that holds all known symbols during parsing and compilation. More...
#include <sym.h>

Public Member Functions | |
| SymbolTable () | |
| ~SymbolTable () | |
| void | PushScope () |
| void | PopScope () |
| bool | AddVariable (Symbol *symbol) |
| Symbol * | LookupVariable (const char *name) |
| bool | AddFunction (Symbol *symbol) |
| bool | LookupFunction (const char *name, std::vector< Symbol * > *matches=NULL) |
| Symbol * | LookupFunction (const char *name, const FunctionType *type) |
| template<typename Predicate > | |
| void | GetMatchingFunctions (Predicate pred, std::vector< Symbol * > *matches) const |
| template<typename Predicate > | |
| void | GetMatchingVariables (Predicate pred, std::vector< Symbol * > *matches) const |
| bool | AddType (const char *name, const Type *type, SourcePos pos) |
| const Type * | LookupType (const char *name) const |
| std::vector< std::string > | ClosestVariableOrFunctionMatch (const char *name) const |
| std::vector< std::string > | ClosestTypeMatch (const char *name) const |
| std::vector< std::string > | ClosestEnumTypeMatch (const char *name) const |
| void | Print () |
| Symbol * | RandomSymbol () |
| const Type * | RandomType () |
Private Types | |
| typedef std::map< std::string, Symbol * > | SymbolMapType |
| typedef std::map< std::string, std::vector< Symbol * > > | FunctionMapType |
| typedef std::map< std::string, const Type * > | TypeMapType |
Private Member Functions | |
| std::vector< std::string > | closestTypeMatch (const char *str, bool structsVsEnums) const |
Private Attributes | |
| std::vector< SymbolMapType * > | variables |
| std::vector< SymbolMapType * > | freeSymbolMaps |
| FunctionMapType | functions |
| TypeMapType | types |
Symbol table that holds all known symbols during parsing and compilation.
A single instance of a SymbolTable is stored in the Module class (Module::symbolTable); it is created in the Module::Module() constructor. It is then accessed via the global variable Module *m throughout the ispc implementation.
typedef std::map<std::string, std::vector<Symbol *> > SymbolTable::FunctionMapType [private] |
Function declarations are *not* scoped. (C99, for example, allows an implementation to maintain function declarations in a single namespace.) A STL vector is used to store the function symbols for a given name since, due to function overloading, a name can have multiple function symbols associated with it.
typedef std::map<std::string, Symbol *> SymbolTable::SymbolMapType [private] |
typedef std::map<std::string, const Type *> SymbolTable::TypeMapType [private] |
| SymbolTable::SymbolTable | ( | ) |
Definition at line 62 of file sym.cpp.
References PushScope().
| SymbolTable::~SymbolTable | ( | ) |
Definition at line 67 of file sym.cpp.
References Assert, PopScope(), and variables.
| bool SymbolTable::AddFunction | ( | Symbol * | symbol | ) |
Adds the given function symbol to the symbol table.
| symbol | The function symbol to be added. |
Definition at line 147 of file sym.cpp.
References Assert, functions, LookupFunction(), Symbol::name, NULL, and Symbol::type.
Referenced by Module::AddFunctionDeclaration(), lCreateISPCSymbol(), and lCreateSymbol().
Adds the named type to the symbol table. This is used for both struct definitions (where struct Foo causes type Foo to be added to the symbol table) as well as for typedefs. For structs with forward declarations ("struct Foo;") and are thus UndefinedStructTypes, this method replaces these with an actual struct definition if one is provided.
| name | Name of the type to be added |
| type | Type that name represents |
| pos | Position in source file where the type was named |
Definition at line 192 of file sym.cpp.
References Error(), LookupType(), NULL, and types.
Referenced by Module::AddTypeDef(), and lDeclareSizeAndPtrIntTypes().
| bool SymbolTable::AddVariable | ( | Symbol * | symbol | ) |
Adds the given variable symbol to the symbol table.
| symbol | The symbol to be added |
Definition at line 98 of file sym.cpp.
References Assert, Error(), Symbol::name, NULL, Symbol::pos, variables, and Warning().
Referenced by Module::AddGlobalVariable(), Declaration::GetVariableDeclarations(), lDefineConstantInt(), lDefineConstantIntFunc(), and lDefineProgramIndex().
| std::vector< std::string > SymbolTable::ClosestEnumTypeMatch | ( | const char * | name | ) | const |
Definition at line 264 of file sym.cpp.
References closestTypeMatch().
| std::vector< std::string > SymbolTable::ClosestTypeMatch | ( | const char * | name | ) | const |
This method returns zero or more strings with the names of types in the symbol table that nearly (but not exactly) match the given name.
Definition at line 258 of file sym.cpp.
References closestTypeMatch().
| std::vector< std::string > SymbolTable::closestTypeMatch | ( | const char * | str, |
| bool | structsVsEnums | ||
| ) | const [private] |
Definition at line 270 of file sym.cpp.
References NULL, StringEditDistance(), and types.
Referenced by ClosestEnumTypeMatch(), and ClosestTypeMatch().
| std::vector< std::string > SymbolTable::ClosestVariableOrFunctionMatch | ( | const char * | name | ) | const |
This method returns zero or more strings with the names of symbols in the symbol table that nearly (but not exactly) match the given name. This is useful for issuing informative error methods when misspelled identifiers are found a programs.
| name | String to compare variable and function symbol names against. |
name. Definition at line 219 of file sym.cpp.
References functions, Symbol::name, StringEditDistance(), and variables.
| void SymbolTable::GetMatchingFunctions | ( | Predicate | pred, |
| std::vector< Symbol * > * | matches | ||
| ) | const |
Returns all of the functions in the symbol table that match the given predicate.
| pred | A unary predicate that returns true or false, given a Symbol pointer, based on whether the symbol should be included in the returned set of matches. It can either be a function, with signature bool pred(const Symbol *s), or a unary predicate object with an bool operator()(const Symbol *) method. |
| matches | Pointer to a vector in which to return the matching symbols. |
Definition at line 281 of file sym.h.
References functions.
Referenced by Module::writeDevStub(), Module::writeHeader(), and Module::writeHostStub().
| void SymbolTable::GetMatchingVariables | ( | Predicate | pred, |
| std::vector< Symbol * > * | matches | ||
| ) | const |
Returns all of the variable symbols in the symbol table that match the given predicate. The predicate is defined as in the GetMatchingFunctions() method.
Definition at line 297 of file sym.h.
References variables.
| bool SymbolTable::LookupFunction | ( | const char * | name, |
| std::vector< Symbol * > * | matches = NULL |
||
| ) |
Looks for the function or functions with the given name in the symbol name. If a function has been overloaded and multiple definitions are present for a given function name, all of them will be returned in the provided vector and it's up the the caller to resolve which one (if any) to use. Returns true if any matches were found.
Definition at line 162 of file sym.cpp.
References functions, and NULL.
Referenced by AddFunction(), Module::AddFunctionDeclaration(), Module::AddFunctionDefinition(), Module::AddGlobalVariable(), FunctionEmitContext::LaneMask(), and BinaryExpr::Optimize().
| Symbol * SymbolTable::LookupFunction | ( | const char * | name, |
| const FunctionType * | type | ||
| ) |
| const Type * SymbolTable::LookupType | ( | const char * | name | ) | const |
| Symbol * SymbolTable::LookupVariable | ( | const char * | name | ) |
Looks for a variable with the given name in the symbol table. This method searches outward from the innermost scope to the outermost, returning the first match found.
| name | The name of the variable to be searched for. |
Definition at line 131 of file sym.cpp.
References NULL, and variables.
Referenced by Module::AddFunctionDeclaration(), Module::AddGlobalVariable(), and ForeachUniqueStmt::ForeachUniqueStmt().
| void SymbolTable::PopScope | ( | ) |
For each scope started by a call to SymbolTable::PushScope(), there must be a matching call to SymbolTable::PopScope() at the end of that scope.
Definition at line 90 of file sym.cpp.
References Assert, freeSymbolMaps, and variables.
Referenced by ~SymbolTable().
| void SymbolTable::Print | ( | ) |
Prints out the entire contents of the symbol table to standard error. (Debugging method).
Definition at line 302 of file sym.cpp.
References functions, Type::GetString(), Symbol::name, stderr, Symbol::type, types, and variables.
| void SymbolTable::PushScope | ( | ) |
The parser calls this method when it enters a new scope in the program; this allows us to track variables that shadows others in outer scopes with same name as well as to efficiently discard all of the variables declared in a particular scope when we exit that scope.
Definition at line 75 of file sym.cpp.
References freeSymbolMaps, and variables.
Referenced by SymbolTable().
| Symbol * SymbolTable::RandomSymbol | ( | ) |
| const Type * SymbolTable::RandomType | ( | ) |
std::vector<SymbolMapType *> SymbolTable::freeSymbolMaps [private] |
Definition at line 263 of file sym.h.
Referenced by PopScope(), and PushScope().
FunctionMapType SymbolTable::functions [private] |
Definition at line 271 of file sym.h.
Referenced by AddFunction(), ClosestVariableOrFunctionMatch(), GetMatchingFunctions(), LookupFunction(), and Print().
TypeMapType SymbolTable::types [private] |
Definition at line 276 of file sym.h.
Referenced by AddType(), closestTypeMatch(), LookupType(), Print(), and RandomType().
std::vector<SymbolMapType *> SymbolTable::variables [private] |
Definition at line 261 of file sym.h.
Referenced by AddVariable(), ClosestVariableOrFunctionMatch(), GetMatchingVariables(), LookupVariable(), PopScope(), Print(), PushScope(), RandomSymbol(), and ~SymbolTable().
1.7.5.1