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

ForeignVariableScope.cpp

00001 #define TRACE_NAME "ForeignVariableScope"
00002 
00003 #include "ForeignVariableScope.h"
00004 #include <cstdio>
00005 
00006 //
00007 //  In theory there's a race condition here, if we went concurrent on
00008 //  checking the variables names.
00009 //
00010 // $Id: ForeignVariableScope_8cpp-source.html,v 1.2 2001/10/10 20:40:58 sandro Exp $
00011 
00013 //
00014 //  Standard Member Functions
00015 //
00017 
00018 
00019 ForeignVariableScope::ForeignVariableScope(VariableScope* mbase)
00020     : mbase(mbase)
00021 {
00022 }
00023 
00024 #if 0  /* omit definitions until they are implemented */
00025 
00026 ForeignVariableScope::ForeignVariableScope(const ForeignVariableScope& other)
00027 {
00028     NOT_IMPLEMENTED
00029 }
00030 
00031 const ForeignVariableScope& ForeignVariableScope::operator=(const ForeignVariableScope& other)
00032 {
00033     NOT_IMPLEMENTED
00034 }
00035 
00036 bool ForeignVariableScope::operator==(const ForeignVariableScope& other) const
00037 {
00038     NOT_IMPLEMENTED
00039 }
00040 
00041 bool ForeignVariableScope::operator<(const ForeignVariableScope& other) const
00042 {
00043     NOT_IMPLEMENTED
00044 }
00045 
00046 size_t ForeignVariableScope::hash() const
00047 {
00048     NOT_IMPLEMENTED
00049 }
00050 
00051 
00052 #endif /* omit definitions until they are implemented */
00053     
00054 
00055 std::ostream& ForeignVariableScope::print_to(std::ostream& stream) const
00056 {
00057     stream << "Foreign wrapper for " << *mbase;
00058     return stream;
00059 }
00060 
00061 ForeignVariableScope::~ForeignVariableScope()
00062 {
00063     // blank default    
00064 }
00065 
00067 //
00068 //  Additional Public Member Functions
00069 //
00071 
00072 
00073 size_t ForeignVariableScope::getNumVars() const
00074 {
00075     return mbase->getNumVars();
00076 }
00077 Symbol ForeignVariableScope::getVar(size_t index) const
00078 {
00079     return mbase->getVar(index);
00080 }
00081 
00082 Symbol ForeignVariableScope::getVar(const char* name, bool* added_ptr=0)
00083 {
00084     return mbase->getVar(translate(name), added_ptr);
00085 }
00086 
00087 size_t ForeignVariableScope::getVarIndex(const char* name)
00088 {
00089     return mbase->getVarIndex(translate(name));
00090 }
00091 
00092 bool ForeignVariableScope::contains(const Triple& t) const
00093 {
00094     NOT_IMPLEMENTED;
00095 }
00096 
00098 //
00099 //  Additional Private Member Functions
00100 //
00102 
00103 const char* ForeignVariableScope::translate(const char* name)
00104 {
00105     TRACE "translate(" << name << ") ==> ";
00106     std::string s(name);
00107 
00108     // look it up in map
00109     Map::iterator iter;
00110     iter = map.find(s);
00111     if (iter != map.end()) {
00112     TRACE "-old-" << (*iter).second.c_str() << endl;
00113     return (*iter).second.c_str();
00114     }
00115 
00116     int count=2;
00117     std::string n(s);
00118     while (true) {
00119     bool added = false;
00120     Symbol sym = mbase->getVar(n.c_str(), &added);
00121     if (added) {
00122         map[s] = n;
00123         TRACE "*NEW* " << n << endl;
00124         // This result SHOULD be as long-lived as this table entry,
00125         // which should be plenty long enough....
00126         return map[s].c_str();
00127     } 
00128     TRACE "collision as " << n << ", ";
00129 
00130     char buf[20];
00131     sprintf(buf, "_%d", count++);
00132     n=s+buf;
00133     TRACE "trying as " << n << endl;
00134     }
00135 
00136 }
00137 
00139 //
00140 //  Additional Private Member Functions
00141 //
00143 
00144 #undef TRACE_NAME

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