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

TripleSink.cpp

00001 #define TRACE_NAME "TripleSink"
00002 
00003 #include "TripleSink.h"
00004 #include "TripleSource.h"
00005 #include <string>
00006 #include <stdio.h>
00007 #include "ForeignVariableScope.h"
00008 #include "LoopState.h"
00009 
00011 //
00012 //  Standard Member Functions
00013 //
00015 
00016 TripleSink::TripleSink()
00017 {
00018     // blank default    
00019 }
00020 
00021 #if 0  /* omit definitions until they are implemented */
00022 
00023 TripleSink::TripleSink(const TripleSink& other)
00024 {
00025     NOT_IMPLEMENTED
00026 }
00027 
00028 const TripleSink& TripleSink::operator=(const TripleSink& other)
00029 {
00030     NOT_IMPLEMENTED
00031 }
00032 
00033 bool TripleSink::operator==(const TripleSink& other) const
00034 {
00035     NOT_IMPLEMENTED
00036 }
00037 
00038 bool TripleSink::operator<(const TripleSink& other) const
00039 {
00040     NOT_IMPLEMENTED
00041 }
00042 
00043 size_t TripleSink::hash() const
00044 {
00045     NOT_IMPLEMENTED
00046 }
00047 
00048 std::ostream& TripleSink::print_to(std::ostream& stream) const
00049 {
00050     NOT_IMPLEMENTED
00051 }
00052 
00053 #endif /* omit definitions until they are implemented */
00054     
00055 TripleSink::~TripleSink()
00056 {
00057     // blank default    
00058 }
00059 
00061 //
00062 //  Additional Public Member Functions
00063 //
00065 
00066 VariableScope* TripleSink::getScope() const
00067 {
00068     NOT_IMPLEMENTED;
00069 }
00070 
00071 
00072 #if 0
00073 Symbol symbolFor(std::string text, TripleSink* sink)
00074 {
00075     return symbolFor(text.c_str(), sink);
00076 }
00077 
00078 Symbol symbolFor(char *text, TripleSink* sink)
00079 {
00080     return symbolFor(text, 0, sink);
00081 }
00082 
00083 Symbol symbolFor(char *text, char *early_end, TripleSink* sink)
00084 {
00085     /*
00086       There are all sorts of clever tricks we could do.
00087 
00088       We're not doing them at the moment.
00089     */
00090     std::string buf("data:,");
00091     char c[4];
00092     for (char* p=text; *p && p!=early_end; p++) {
00093     if (isalnum(*p)) {
00094         buf.append(p, 1);
00095     } else {
00096         sprintf(c, "%%%02x", *p);
00097         buf.append(c, 3);
00098     }
00099     }
00100     return Symbol(sink->getSpace(), buf.c_str());
00101 }
00102 
00103 static int count=0;
00104 Symbol symbolForAnonymous(char *text, TripleSink* sink)
00105 {
00106     return symbolForAnonymous(text, sink->getSpace());
00107 }
00108 Symbol symbolForAnonymous(char *text, SymbolSpace* space)
00109 {
00110     static char b1[16];
00111     sprintf(b1, "_:%d_", count++);
00112     std::string b2(b1);
00113     b2.append(text);
00114     
00115     return Symbol(space, b2.c_str());
00116 }
00117 #endif
00118 
00119 #if 0
00120 void addForeign(const TripleSource& source)
00121 {
00122      SymbolMap m;
00123         LoopState l;
00124         for (Triple t = tmp.fetch(Triple::NULL, l)) {
00125         for (size_t i=0; i<3; i++) {
00126             Symbol s = t.get(i);
00127             if (s.isVar()) {
00128             // remap s
00129             t.put(s);
00130             }
00131         }
00132         pool.add(t);
00133         }
00134 
00135 }
00136 #endif
00137 
00138 
00139 void TripleSink::mUnion(const TripleSource& source)
00140 {
00141     LoopState ls;
00142 
00143     if (source.getScope() == getScope()) {
00144     TRACE "degenerate mUnion stays in same scope!   yay!" << endl;
00145     while(Triple t=source.fetch(Triple::null, ls)) {
00146         add(t);
00147     }
00148     return;
00149     }
00150 
00151     size_t numVars = source.getScope()->getNumVars();
00152     std::vector<Symbol> map(numVars);
00153 
00154     TRACE "Mapping variables from " << *source.getScope() << " ==> " <<
00155     *getScope() << endl;
00156     for (size_t i=0; i<numVars; i++) {
00157     Symbol external = source.getScope()->getVar(i);
00158     TRACE " var # " << i << ":  " << external;
00159     int count=2;
00160     std::string s(external.text());
00161     std::string n(s);
00162     while (true) {
00163         bool added = false;
00164         Symbol internal = getScope()->getVar(n.c_str(), &added);
00165         if (added) {
00166         TRACE " ==> new " << internal << endl;
00167         map[i] = internal;
00168         break;
00169         } 
00170         TRACE "*collision* as " << n << ", ";
00171 
00172         char buf[20];
00173         sprintf(buf, "_%d", count++);
00174         n=s+buf;
00175         TRACE "trying as " << n << endl;
00176     }
00177     }
00178 
00179     while(Triple t=source.fetch(Triple::null, ls)) {
00180     for (int i=0; i<3; i++) {
00181         if (t.get(i).isVar()) {
00182         t.set(i, map[t.get(i).index()]);
00183         }
00184     }
00185     TRACE "mUnion adding: " << t << endl;
00186         add(t);
00187     }
00188 }
00189 
00191 //
00192 //  Additional Private Member Functions
00193 //
00195 
00196 
00197 
00198 #undef TRACE_NAME

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