00001 #define TRACE_NAME "Symbol"
00002 #include "Symbol.h"
00003
00005
00006
00007
00009
00010 SymbolTable Symbol::global;
00011 const Symbol Symbol::null(Symbol::NULL_SYMBOL, "");
00012 static int bindingLoopCount = 0;
00013
00014 Symbol::Symbol(Type type, const char* text)
00015 {
00016 if (type == NULL_SYMBOL) { _table = 0; _index = 0; return; }
00017 _table = &global;
00018 _index = _table->lookupOrAdd(type, text);
00019 }
00020
00021 std::ostream& Symbol::print_to(std::ostream& stream) const {
00022 switch (getType()) {
00023 case NULL_SYMBOL:
00024 assert(_table == 0);
00025 stream << "-null-";
00026 break;
00027 case CONSTANT:
00028 assert(_table == &global);
00029 stream << "<" << text() << ">";
00030 break;
00031 case LITERAL:
00032
00033 assert(_table == &global);
00034 stream << "\"" << text() << "\"";
00035 break;
00036 case VARIABLE:
00037
00038 stream << "_";
00039 {
00040 const char* t = text();
00041 if (t) stream << ":" << t;
00042
00043 #if 0
00044 if (isBound()) {
00045 if (bindingLoopCount) {
00046 if (bindingLoopCount++ > 4) {
00047 stream << "=...";
00048 goto donePrinting;
00049 }
00050 } else {
00051 bindingLoopCount = 1;
00052 }
00053 stream << "=" << getBinding();
00054 donePrinting:
00055 bindingLoopCount--;
00056 }
00057 #endif
00058 }
00059 break;
00060 default:
00061 NOT_IMPLEMENTED;
00062 }
00063 return stream;
00064 }
00065
00066
00068
00069
00070
00072
00073
00074
00076
00077
00078
00080