00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <assert.h>
00039 #include <stdint.h>
00040 #include <stdlib.h>
00041 #include <dirent.h>
00042 #include <fstream>
00043 #include <iostream>
00044 #include <string>
00045 #include <libsherpa/UExcept.hxx>
00046 #include "AST.hxx"
00047 #include "Type.hxx"
00048 #include <sstream>
00049
00050 using namespace std;
00051 using namespace boost;
00052 using namespace sherpa;
00053
00054 TvPrinter::TvPrinter(const bool pp, const std::string& _pfx)
00055 {
00056 prettyPrint = pp;
00057 pfx = _pfx;
00058 count = 0;
00059 }
00060
00061 string
00062 TvPrinter::newTvName()
00063 {
00064 stringstream ss;
00065 unsigned long long nchars = 'z' - 'a' + 1;
00066
00067 char c = 'a' + (count % nchars);
00068 ss << pfx << c;
00069
00070 unsigned long long ndx = count / nchars;
00071 if (ndx > 0)
00072 ss << ndx;
00073
00074 count++;
00075 return ss.str();
00076 }
00077
00078 string
00079 TvPrinter::tvName(shared_ptr<const Type> tvar)
00080 {
00081 if (!prettyPrint) {
00082 stringstream ss;
00083 ss << pfx << "a" << tvar->uniqueID;
00084 return ss.str();
00085 }
00086
00087 TvMap::iterator itr = tvMap.find(tvar->uniqueID);
00088
00089 if (itr == tvMap.end()) {
00090 string s = newTvName();
00091 tvMap[tvar->uniqueID] = s;
00092 return s;
00093 }
00094 else
00095 return itr->second;
00096 }
00097
00098 std::vector<std::string>
00099 TvPrinter::getAllTvarStrings()
00100 {
00101 std::vector<std::string> vec;
00102
00103 for (TvMap::iterator itr = tvMap.begin();
00104 itr != tvMap.end(); ++itr)
00105 vec.push_back(itr->second);
00106
00107 return vec;
00108 }