TBLT;
TBLT m_tbl;
TBLT::iterator lookup(const char *str) {
TBLT::iterator i = m_tbl.begin();
for(; (i!=m_tbl.end())&&(strcmp(str, (*i)->m_name.c_str())>0);
i++)
;
if ((i != m_tbl.end())&&(strcmp(str,(*i)->m_name.c_str())==0))
return i;
return m_tbl.end();
}
public:
SYMBOL_TABLE(void) {}
~SYMBOL_TABLE(void) {
TBLT::iterator i = m_tbl.begin();
while(i != m_tbl.end()) {
delete (*i);
i = m_tbl.erase(i);
}
}
void define(const char *key, AST *value) {
SYMTABLE_ENTRY *v = new SYMTABLE_ENTRY(key, value);
TBLT::iterator i = m_tbl.begin();
for(; (i!=m_tbl.end())&&(strcmp(key, (*i)->m_name.c_str())>0);
i++)
;
m_tbl.insert(i, v);
/*
fprintf(stderr, "Defining: %s = ", key);
value->dump(stderr);
fprintf(stderr, "\n");
*/
}
bool isdefined(const char *key) {
TBLT::iterator i = lookup(key);
if (i == m_tbl.end()) {
// fprintf(stderr, "%s is not in the symbol table\n", key);
return false;
} else {
bool defined = (*i)->isdefined();
/*
if (!defined) {
fprintf(stderr, "KEY: %s = ", key);
(*i)->dump(stderr);
fprintf(stderr, " is not yet defined\n");
} */
return (*i)->isdefined();
}
}
int value(const char *key) {
TBLT::iterator i = lookup(key);
if (i == m_tbl.end())
return 0;
else
return (*i)->val();
}
};
SYMBOL_TABLE *global_context = NULL, *file_context = NULL;
bool stb_isdefined(const char *key) {
if ((file_context)&&(file_context->isdefined(key)))
return true;
else
return global_context->isdefined(key);
} int stb_value(const char *key) {
if ((file_context)&&(file_context->isdefined(key)))
return file_context->value(key);
else
return global_context->value(key);
} void stb_define(const char *key, AST *value) {
file_context->define(key, value);
} void gbl_define(const char *key, AST *value) {
global_context->define(key, value);
}
void create_new_context(void) {
if (global_context == NULL)
global_context = new SYMBOL_TABLE;
if (file_context != NULL)
delete file_context;
file_context = new SYMBOL_TABLE;
}
// Convenience functions for accessing the symbol table
bool stb_isdefined(const std::string &key) {
bool answer = stb_isdefined(key.c_str());
return answer;
} int stb_value(const std::string &key) {
return stb_value(key.c_str());
} void stb_define(const std::string &key, AST *value) {
stb_define(key.c_str(), value);
} void gbl_define(const std::string &key, AST *value) {
gbl_define(key.c_str(), value);
}
Error running this command: diff -w -U 5 "" "/tmp/S5wNOQ"
diff: : No such file or directory