Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

Symbol.cpp

00001 #define TRACE_NAME "Symbol"
00002 #include "Symbol.h"
00003 
00005 //
00006 //  Standard Member Functions
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     // should do quoting...
00033     assert(_table == &global);
00034     stream << "\"" << text() << "\"";
00035     break;
00036     case VARIABLE:
00037     //stream << "_" << _table->getTableNumber() << "_" << _index;
00038     stream << "_";
00039     {
00040         const char* t = text();
00041         if (t) stream << ":" << t;
00042         // move this stuff into another version of print_to!
00043 #if 0
00044         if (isBound()) {
00045         if (bindingLoopCount) {    // NOT THREAD SAFE
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 //  Additional Public Member Functions
00070 //
00072 
00073 
00074 
00076 //
00077 //  Additional Private Member Functions
00078 //
00080 #undef TRACE_NAME

Home to blindfold. This page generated via doxygen 1.2.11.1 Wed Oct 10 16:40:33 2001.