Intel® Implicit SPMD Program Compiler (Intel® ISPC)
1.13.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 |
bool | ContainsType (const Type *type) 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.
|
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.
|
private |
|
private |
bool SymbolTable::AddFunction | ( | Symbol * | symbol | ) |
Adds the given function symbol to the symbol table.
symbol | The function symbol to be added. |
Definition at line 126 of file sym.cpp.
References Assert, Symbol::name, 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 typedef
s. 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 165 of file sym.cpp.
References Error(), Symbol::name, and Symbol::type.
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 85 of file sym.cpp.
References Assert, Error(), Symbol::name, Symbol::pos, and Warning().
Referenced by Module::AddGlobalVariable(), Declaration::GetVariableDeclarations(), lDefineConstantInt(), lDefineConstantIntFunc(), and lDefineProgramIndex().
std::vector< std::string > SymbolTable::ClosestEnumTypeMatch | ( | const char * | name | ) | const |
std::vector< std::string > SymbolTable::ClosestTypeMatch | ( | const char * | name | ) | const |
|
private |
Definition at line 242 of file sym.cpp.
References StringEditDistance().
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 199 of file sym.cpp.
References Symbol::name, and StringEditDistance().
bool SymbolTable::ContainsType | ( | const Type * | type | ) | const |
Look for a type given a pointer.
Definition at line 188 of file sym.cpp.
Referenced by DeclSpecs::DeclSpecs().
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 277 of file sym.h.
Referenced by lGetExportedFunctions(), Module::writeDevStub(), Module::writeDispatchHeader(), 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.
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 139 of file sym.cpp.
Referenced by Module::AddFunctionDeclaration(), Module::AddFunctionDefinition(), Module::AddGlobalVariable(), FunctionEmitContext::All(), FunctionEmitContext::Any(), FunctionEmitContext::LaneMask(), lCreateBinaryOperatorCall(), FunctionEmitContext::LoadInst(), FunctionEmitContext::None(), and BinaryExpr::Optimize().
Symbol * SymbolTable::LookupFunction | ( | const char * | name, |
const FunctionType * | type | ||
) |
Looks for a function with the given name and type in the symbol table.
Definition at line 153 of file sym.cpp.
References Type::Equal().
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 112 of file sym.cpp.
Referenced by Module::AddFunctionDeclaration(), Module::AddGlobalVariable(), ForeachUniqueStmt::ForeachUniqueStmt(), Function::Function(), and lExtractOrCheckGlobals().
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 79 of file sym.cpp.
References Assert.
void SymbolTable::Print | ( | ) |
Prints out the entire contents of the symbol table to standard error. (Debugging method).
Definition at line 272 of file sym.cpp.
References Type::GetString(), Symbol::name, and Symbol::type.
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.
Symbol * SymbolTable::RandomSymbol | ( | ) |
Returns a random symbol from the symbol table. (It is not guaranteed that it is equally likely to return all symbols).
Definition at line 315 of file sym.cpp.
References Assert, and ispcRand().
const Type * SymbolTable::RandomType | ( | ) |
|
private |
|
private |
|
private |
|
private |