// // Name table // #include #include "nt.h" void NameDef::print() const { printf("NameDef: name=%s", name.c_str()); if (isVariable()) { printf(" variable"); } else if (isFunction()) { printf(" function"); } else if (isStandardFunction()) { printf(" standard function"); } if (isGlobal()) printf(" nonlocal"); if (isVariable() && !isGlobal()) { if (value.isInt()) printf(" type=int"); else if (value.isDouble()) printf(" type=double"); else if (value.isString()) printf(" type=string"); else if (value.isArray()) printf(" type=array"); else if (value.isNone()) printf(" type=none"); printf(" value="); value.print(); } printf("\n"); } NameDef* NameTable::findName(const char *name) const { const_iterator i = find(name); if (i == end()) return 0; else return const_cast(&(*i)); } // Add name to the local table NameDef* NameTable::addName(const char *name) { iterator i = find(name); if (i == end()) { std::pair p = insert(name); assert(p.second); i = p.first; } return const_cast(&(*i)); } void NameTable::print() const { NameTable::const_iterator i = begin(); while (i != end()) { i->print(); ++i; } }