// // Name table // #ifndef NT_H #define NT_H #include #include #include #include #include "lextypes.h" #include "value.h" #include "lt.h" using std::string; using std::set; class NameDef { public: string name; enum { NAME_VARIABLE = 1, NAME_FUNCTION = 2, NAME_GLOBAL = 4, NAME_STANDARD_FUNCTION = 8 }; int modifiers; Value value; int label; // For functions const Label* label_ptr; bool isVariable() const { return ((modifiers & NAME_VARIABLE) != 0); } bool isFunction() const { return ((modifiers & NAME_FUNCTION) != 0); } bool isStandardFunction() const { return ( isFunction() && (modifiers & NAME_STANDARD_FUNCTION) != 0 ); } bool isGlobal() const { return ((modifiers & NAME_GLOBAL) != 0); } void setVariable(bool set = true) { if (set) modifiers |= NAME_VARIABLE; else modifiers &= ~NAME_VARIABLE; } void setFunction(bool set = true) { if (set) modifiers |= NAME_FUNCTION; else modifiers &= ~NAME_FUNCTION; } void setGlobal(bool set = true) { if (set) modifiers |= NAME_GLOBAL; else modifiers &= ~NAME_GLOBAL; } void clearModifiers() { modifiers = 0; } NameDef(const char* str): name(str), modifiers(0), value(), label(0), label_ptr(0) {} NameDef(const string& str): name(str), modifiers(0), value(), label(0), label_ptr(0) {} bool operator==(const NameDef& n) const { return (name.compare(n.name) == 0); } bool operator!=(const NameDef& n) const { return !(operator==(n)); } bool operator<=(const NameDef& n) const { return (name.compare(n.name) <= 0); } bool operator<(const NameDef& n) const { return (name.compare(n.name) < 0); } bool operator>(const NameDef& n) const { return !(operator<=(n)); } bool operator>=(const NameDef& n) const { return !(operator<(n)); } operator const char*() const { return name.c_str(); } void print() const; }; // // Name table // class NameTable: public set { public: NameDef* findName(const char *name) const; NameDef* findName(const string& n) const { return findName(n.c_str()); } NameDef* addName(const char *name); NameDef* addName(const string& n) { return addName(n.c_str()); } void print() const; }; #endif