63 Assert(variables.size() == 1);
69 if (freeSymbolMaps.size() > 0) {
70 sm = freeSymbolMaps.back();
71 freeSymbolMaps.pop_back();
72 sm->erase(sm->begin(), sm->end());
76 variables.push_back(sm);
80 Assert(variables.size() > 1);
81 freeSymbolMaps.push_back(variables.back());
89 for (
int i = (
int)variables.size() - 1; i >= 0; --i) {
91 if (sm.find(symbol->
name) != sm.end()) {
92 if (i == (
int)variables.size() - 1) {
95 Error(symbol->
pos,
"Ignoring redeclaration of symbol \"%s\".", symbol->
name.c_str());
100 Warning(symbol->
pos,
"Symbol \"%s\" shadows symbol declared in outer scope.", symbol->
name.c_str());
101 (*variables.back())[symbol->
name] = symbol;
108 (*variables.back())[symbol->
name] = symbol;
117 for (
int i = (
int)variables.size() - 1; i >= 0; --i) {
119 SymbolMapType::iterator iter = sm.find(name);
120 if (iter != sm.end())
129 if (LookupFunction(symbol->
name.c_str(), ft) != NULL)
134 std::vector<Symbol *> &funOverloads = functions[symbol->
name];
135 funOverloads.push_back(symbol);
140 FunctionMapType::iterator iter = functions.find(name);
141 if (iter != functions.end()) {
145 const std::vector<Symbol *> &funcs = iter->second;
146 for (
int j = 0; j < (int)funcs.size(); ++j)
147 matches->push_back(funcs[j]);
150 return matches ? (matches->size() > 0) :
false;
154 FunctionMapType::iterator iter = functions.find(name);
155 if (iter != functions.end()) {
156 std::vector<Symbol *> funcs = iter->second;
157 for (
int j = 0; j < (int)funcs.size(); ++j) {
166 const Type *t = LookupType(name);
167 if (t != NULL && CastType<UndefinedStructType>(t) == NULL) {
172 Error(pos,
"Ignoring redefinition of type \"%s\".", name);
182 TypeMapType::const_iterator iter = types.find(name);
183 if (iter != types.end())
189 TypeMapType::const_iterator iter = types.begin();
190 while (iter != types.end()) {
191 if (iter->second == type) {
205 const int maxDelta = 2;
206 std::vector<std::string> matches[maxDelta + 1];
208 for (
int i = 0; i < (int)variables.size(); ++i) {
210 SymbolMapType::const_iterator iter;
211 for (iter = sv.begin(); iter != sv.end(); ++iter) {
212 const Symbol *sym = iter->second;
214 if (dist <= maxDelta)
215 matches[dist].push_back(sym->
name);
219 FunctionMapType::const_iterator iter;
220 for (iter = functions.begin(); iter != functions.end(); ++iter) {
222 if (dist <= maxDelta)
223 matches[dist].push_back(iter->first);
227 for (
int i = 0; i <= maxDelta; ++i) {
228 if (matches[i].size())
233 return std::vector<std::string>();
239 return closestTypeMatch(str,
false);
247 const int maxDelta = 2;
248 std::vector<std::string> matches[maxDelta + 1];
250 TypeMapType::const_iterator iter;
251 for (iter = types.begin(); iter != types.end(); ++iter) {
254 bool isEnum = (CastType<EnumType>(iter->second) != NULL);
255 if (isEnum && structsVsEnums)
257 else if (!isEnum && !structsVsEnums)
261 if (dist <= maxDelta)
262 matches[dist].push_back(iter->first);
265 for (
int i = 0; i <= maxDelta; ++i) {
266 if (matches[i].size())
269 return std::vector<std::string>();
274 fprintf(stderr,
"Variables:\n----------------\n");
275 for (
int i = 0; i < (int)variables.size(); ++i) {
277 SymbolMapType::iterator iter;
278 for (iter = sm.begin(); iter != sm.end(); ++iter) {
279 fprintf(stderr,
"%*c", depth,
' ');
280 Symbol *sym = iter->second;
283 fprintf(stderr,
"\n");
287 fprintf(stderr,
"Functions:\n----------------\n");
288 FunctionMapType::iterator fiter = functions.begin();
289 while (fiter != functions.end()) {
290 fprintf(stderr,
"%s\n", fiter->first.c_str());
291 std::vector<Symbol *> &syms = fiter->second;
292 for (
unsigned int j = 0; j < syms.size(); ++j)
293 fprintf(stderr,
" %s\n", syms[j]->
type->
GetString().c_str());
298 fprintf(stderr,
"Named types:\n---------------\n");
299 TypeMapType::iterator siter = types.begin();
300 while (siter != types.end()) {
301 fprintf(stderr,
"%*c", depth,
' ');
302 fprintf(stderr,
"%s -> %s\n", siter->first.c_str(), siter->second->GetString().c_str());
308 #ifdef ISPC_HOST_IS_WINDOWS 316 int v =
ispcRand() % variables.size();
317 if (variables[v]->size() == 0)
319 int count =
ispcRand() % variables[v]->size();
320 SymbolMapType::iterator iter = variables[v]->begin();
321 while (count-- > 0) {
323 Assert(iter != variables[v]->end());
329 int count = types.size();
330 TypeMapType::iterator iter = types.begin();
331 while (count-- > 0) {
333 Assert(iter != types.end());
bool AddFunction(Symbol *symbol)
const Type * LookupType(const char *name) const
bool ContainsType(const Type *type) const
bool AddVariable(Symbol *symbol)
std::vector< std::string > ClosestEnumTypeMatch(const char *name) const
Symbol * LookupVariable(const char *name)
header file with declarations for symbol and symbol table classes.
std::vector< std::string > closestTypeMatch(const char *str, bool structsVsEnums) const
Symbol(const std::string &name, SourcePos pos, const Type *t=NULL, StorageClass sc=SC_NONE)
bool AddType(const char *name, const Type *type, SourcePos pos)
bool LookupFunction(const char *name, std::vector< Symbol *> *matches=NULL)
const Type * RandomType()
StorageClass storageClass
Representation of a range of positions in a source file.
virtual std::string GetString() const =0
void Error(SourcePos p, const char *fmt,...)
std::vector< std::string > ClosestTypeMatch(const char *name) const
int StringEditDistance(const std::string &str1, const std::string &str2, int maxDist)
static bool Equal(const Type *a, const Type *b)
std::map< std::string, Symbol * > SymbolMapType
Type representing a function (return type + argument types)
Representation of a program symbol.
Interface class that defines the type abstraction.
const Function * parentFunction
void Warning(SourcePos p, const char *fmt,...)
llvm::Function * exportedFunction
File with declarations for classes related to type representation.
std::vector< std::string > ClosestVariableOrFunctionMatch(const char *name) const