Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

BlackAdder Class Reference

#include <BlackAdder.h>

List of all members.

Public Member Functions

 BlackAdder ()
 ~BlackAdder ()
CLSadd_class (const std::string &,string_v &,const std::string &,int, bool)
NSPGetNamespace (const std::string &name, bool add=true)
void MakeDot (const std::string &group_name="")
void add_using (const std::string &)
void clear_using ()
void add_type (CLS *, const std::string &)
void set_typedef (const std::string &nspace, const std::string &,std::vector< std::string > &)
bool type_lookup (CLS *, const std::string &typ, string_v &, NSP *&)
bool is_class (const std::string &nspace, const std::string &name)

Private Member Functions

void fix_class ()
CLSfind_class (const std::string &,const std::string &)
bool locate (NSP *base, const char *, NSP *&, CLS *&, bool add=true)
bool has_subclass (NSP *nsp0, CLS *cls0, const std::string &color)
std::list< CLS * > find_base (NSP *nsp, CLS *cls)
void find_color (NSP *nsp, CLS *cls)
CLSfind_class (const std::string &name0)

Private Attributes

std::vector< NSP * > m_added
strstr_m m_using


Constructor & Destructor Documentation

BlackAdder::BlackAdder  ) 
 

Definition at line 45 of file BlackAdder.cpp.

00046 {
00047 }

BlackAdder::~BlackAdder  ) 
 

Definition at line 50 of file BlackAdder.cpp.

00051 {
00052 }


Member Function Documentation

CLS * BlackAdder::add_class const std::string &  ,
string_v ,
const std::string &  ,
int  ,
bool 
 

Definition at line 55 of file BlackAdder.cpp.

References DEB, get_group(), GetNamespace(), m_using, and string_v.

Referenced by fix_class().

00056 {
00057         NSP *nsp = GetNamespace(strNamespace);
00058         std::string name;
00059         if (0&&strNamespace.size())
00060                 name = strNamespace + "::" + vecStr[1];
00061         else
00062                 name = vecStr[1];
00063         for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00064         {
00065                 CLS *tmp = *it;
00066                 if (!strcmp(tmp -> name.c_str(),name.c_str()))
00067                         return tmp;
00068         }
00069         // class not added, so add
00070         CLS *tmp = new CLS;
00071         tmp -> name = name;
00072         tmp -> group_name = get_group(name);
00073         tmp -> m_namespace = strNamespace;
00074         tmp -> filename = filename;
00075         tmp -> line = line;
00076         tmp -> bExtern = bExtern;
00077         tmp -> bUsed = false;
00078         nsp -> added.push_back( tmp );
00079 DEB(    fprintf(stderr,"Class to add to namespace '%s': %s\n",strNamespace.c_str(),name.c_str());)
00080         bool col = false;
00081         bool debug = false;
00082         int count = 0;
00083         std::string bas;
00084         if (strstr(name.c_str(),"Form") || strstr(name.c_str(),"Web") )
00085                 debug = true;
00086         for (string_v::iterator it = vecStr.begin(); it != vecStr.end(); it++)
00087         {
00088                 if (!col)
00089                 {
00090                         if (*it == ":")
00091                                 col = true;
00092                 }
00093                 else
00094                 {
00095                         if (*it == "<")
00096                                 count++;
00097                         if (*it == ">")
00098                                 count--;
00099                         if (*it == "{" || (*it == "," && !count))
00100                         {
00101                                 tmp -> bases.push_back( bas );
00102                                 tmp -> bUsed = true;
00103                                 if (debug)
00104                                         fprintf(stderr," basklass: '%s'\n",bas.c_str());
00105                                 bas = "";
00106                         }
00107                         else
00108                         {
00109                                 if (*it != "virtual" &&
00110                                     *it != "public" &&
00111                                     *it != "protected" &&
00112                                     *it != "private")
00113                                 {
00114                                         if (bas.size())
00115                                                 bas += " " + *it;
00116                                         else
00117                                         {
00118                                                 bas = *it;
00119                                                 for (strstr_m::iterator i2 = m_using.begin(); i2 != m_using.end(); i2++)
00120                                                 {
00121                                                         if (!strcmp((*i2).first.c_str(), bas.c_str()))
00122                                                         {
00123                                                                 bas = (*i2).second;
00124                                                                 break;
00125                                                         }
00126                                                 }
00127                                         }
00128                                 }
00129                         }
00130                 }
00131         }
00132 //      printf("\n");
00133         return tmp;
00134 }

void BlackAdder::add_type CLS ,
const std::string & 
 

Definition at line 168 of file BlackAdder.cpp.

00169 {
00170         // skip namespace resolution here
00171 /*
00172         for (typedef_m::iterator it = m_typedef.begin(); it != m_typedef.end(); it++)
00173         {
00174                 if (!strcmp((*it).first.c_str(),str.c_str()))
00175                 {
00176                         std::string prev;
00177 //#define DEB(x) x
00178 DEB(                    printf("typedef '%s'\n",str.c_str());)
00179                         for (string_v::iterator it2 = (*it).second.begin(); it2 != (*it).second.end(); it2++)
00180                         {
00181                                 if (*it2 == "<")
00182                                 {
00183                                         if (prev.size())
00184                                                 add_type(cls, prev);
00185                                         prev = "";
00186                                 }
00187                                 else
00188                                 if (*it2 == ",")
00189                                 {
00190                                         if (prev.size())
00191                                                 add_type(cls, prev);
00192                                         prev = "";
00193                                 }
00194                                 else
00195                                 if (*it2 == ">")
00196                                 {
00197                                         if (prev.size())
00198                                                 add_type(cls, prev);
00199                                         prev = "";
00200                                 }
00201                                 else
00202                                 {
00203 //                                      if (prev.size())
00204 //                                              prev += " ";
00205                                         prev += *it2;
00206                                 }
00207                         }
00208 DEB(                    printf("typedef '%s' ok\n",str.c_str());)
00209                         return;
00210                 }
00211         }
00212 */
00213         for (string_v::iterator it = cls -> using_type.begin(); it != cls -> using_type.end(); it++)
00214         {
00215                 std::string x = *it;
00216                 if (!strcmp(x.c_str(), str.c_str()))
00217                         return;
00218         }
00219 fprintf(stderr, " adding type '%s' for class '%s'\n", str.c_str(), cls -> name.c_str());
00220         cls -> using_type.push_back( str );
00221 }

void BlackAdder::add_using const std::string &   ) 
 

Definition at line 137 of file BlackAdder.cpp.

References m_using.

00138 {
00139         size_t x = 0;
00140         for (size_t i = 0; i < str.size() - 1; i++)
00141                 if (str[i] == ':' && str[i + 1] == ':')
00142                         x = i + 2;
00143         m_using[str.c_str() + x] = str;
00144 }

void BlackAdder::clear_using  ) 
 

Definition at line 161 of file BlackAdder.cpp.

References m_using.

Referenced by parse_file().

00162 {
00163         while (m_using.size())
00164                 m_using.erase(m_using.begin());
00165 }

std::list< CLS * > BlackAdder::find_base NSP nsp,
CLS cls
[private]
 

Definition at line 528 of file BlackAdder.cpp.

References find_class().

Referenced by MakeDot().

00529 {
00530         std::list<CLS *> bases;
00531         std::string name;
00532         bool debug = false;
00533         if (nsp -> name.size())
00534                 name = nsp -> name + "::" + cls -> name;
00535         else
00536                 name = cls -> name;
00537         for (string_v::iterator it = cls -> bases.begin(); it != cls -> bases.end(); it++)
00538         {
00539                 std::string base = *it;
00540                 CLS *base_cls = NULL;
00541                 if (strstr(name.c_str(),"Form") ||
00542                     strstr(base.c_str(),"Form")
00543                    )
00544                 {
00545                         fprintf(stderr,"Class: '%s' : Base Class: '%s'\n",name.c_str(),base.c_str());
00546                         debug = true;
00547                 }
00548                 base_cls = find_class(base);
00549 fprintf(stderr, "Class '%s': %s\n", base.c_str(), base_cls ? "found" : "not found");
00550 /*
00551                 for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00552                 {
00553                         CLS *cls = *it;
00554                         if (!strcmp(cls -> name.c_str(),base.c_str()))
00555                         {
00556                                 if (!strstr(base.c_str(),"::") && nsp -> name.size())
00557                                         base = nsp -> name + "::" + base;
00558                                 resolved = true;
00559                                 base_cls = cls;
00560                                 if (debug)
00561                                         fprintf(stderr,"resolved as 1\n");
00562                                 break;
00563                         }
00564                 }
00565                 if (!resolved && !strstr(base.c_str(),"::") ) // find class in blank namespace
00566                 {
00567                         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
00568                         {
00569                                 NSP *nsp = *it;
00570                                 if (!nsp -> name.size()) // blank namespace
00571                                 {
00572                                         for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00573                                         {
00574                                                 CLS *cls = *it;
00575                                                 if (!strcmp(cls -> name.c_str(),base.c_str()))
00576                                                 {
00577                                                         resolved = true; // ok base class in blank namespace
00578                                                         base_cls = cls;
00579                                                         if (debug)
00580                                                                 fprintf(stderr,"resolved as 2\n");
00581                                                         break;
00582                                                 }
00583                                         }
00584                                 }
00585                         }
00586                         if (!resolved) // base must be on our namespace, somehow
00587                         {
00588                                 if (!strstr(base.c_str(),"::") && nsp -> name.size())
00589                                 {
00590                                         base = nsp -> name + "::" + base;
00591                                         if (debug)
00592                                                 fprintf(stderr,"not resolved - renamed: %s\n",base.c_str());
00593                                 }
00594                         }
00595                 }
00596 */
00597                 if (base_cls)
00598                 {
00599                         bases.push_back(base_cls);
00600                 }
00601         } // for (basklasser...
00602         return bases;
00603 }

CLS * BlackAdder::find_class const std::string &  name0  )  [private]
 

Definition at line 505 of file BlackAdder.cpp.

References m_added.

00506 {
00507         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
00508         {
00509                 NSP *nsp = *it;
00510                 for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00511                 {
00512                         CLS *cls = *it;
00513                         std::string name;
00514                         if (nsp -> name.size())
00515                                 name = nsp -> name + "::" + cls -> name;
00516                         else
00517                                 name = cls -> name;
00518                         if (name0 == name)
00519                                 return cls;
00520                         if (cls -> name == name0)
00521                                 return cls;
00522                 }
00523         }
00524         return NULL;
00525 }

CLS * BlackAdder::find_class const std::string &  ,
const std::string & 
[private]
 

Definition at line 147 of file BlackAdder.cpp.

References DEB, and GetNamespace().

Referenced by find_base(), and fix_class().

00148 {
00149         NSP *nsp = GetNamespace(strNamespace);
00150 DEB(    printf("Looking for '%s :: %s'\n",strNamespace.c_str(),strName.c_str());)
00151         for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00152         {
00153                 CLS *cls = *it;
00154                 if (!strcmp(cls -> name.c_str(),strName.c_str()))
00155                         return cls;
00156         }
00157         return NULL;
00158 }

void BlackAdder::find_color NSP nsp,
CLS cls
[private]
 

void BlackAdder::fix_class  )  [private]
 

Definition at line 244 of file BlackAdder.cpp.

References add_class(), DEB, find_class(), locate(), and m_added.

Referenced by MakeDot().

00245 {
00246         std::vector<ADD *> c2add;
00247         return;
00248 
00249         // arv
00250         
00251         // namespace loop
00252         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
00253         {
00254                 NSP *nsp = *it;
00255 DEB(            printf("\n fix_class() namespace '%s'\n",nsp -> name.c_str());)
00256 
00257                 // class loop
00258                 for (std::vector<CLS *>::iterator it2 = nsp -> added.begin(); it2 != nsp -> added.end(); it2++)
00259                 {
00260                         CLS *cls = *it2;
00261 DEB(                    printf(" fix_class()  class '%s'\n",cls -> name.c_str());)
00262                         std::string name;
00263                         if (nsp -> name.size())
00264                                 name = nsp -> name + "::" + cls -> name;
00265                         else
00266                                 name = cls -> name;
00267 DEB(                    printf(" fix_class()  classname '%s'\n",name.c_str());)
00268 
00269                         // base class loop
00270                         for (string_v::iterator it3 = cls -> bases.begin(); it3 != cls -> bases.end(); it3++)
00271                         {
00272                                 std::string base = *it3;
00273                                 bool resolved = false;
00274 
00275 DEB(                            printf(" fix_class() base_class '%s'\n",base.c_str());)
00276 
00277                                 // try to locate base class
00278                                 if (!strstr(base.c_str(),"::"))
00279                                 {
00280                                 for (std::vector<CLS *>::iterator i2 = nsp -> added.begin(); i2 != nsp -> added.end(); i2++)
00281                                 {
00282                                         CLS *cls = *i2;
00283                                         if (!strcmp(cls -> name.c_str(),base.c_str()))
00284                                         {
00285                                                 if (nsp -> name.size())
00286                                                         base = nsp -> name + "::" + base;
00287                                                 resolved = true;
00288                                                 cls -> bUsed = true;
00289                                                 break;
00290                                         }
00291                                 }
00292                                 if (!resolved) // find class in blank namespace
00293                                 {
00294                                         for (std::vector<NSP *>::iterator i2 = m_added.begin(); i2 != m_added.end(); i2++)
00295                                         {
00296                                                 NSP *nsp = *i2;
00297                                                 if (!nsp -> name.size()) // blank namespace
00298                                                 {
00299                                                         for (std::vector<CLS *>::iterator i3 = nsp -> added.begin(); i3 != nsp -> added.end(); i3++)
00300                                                         {
00301                                                                 CLS *cls = *i3;
00302                                                                 if (!strcmp(cls -> name.c_str(),base.c_str()))
00303                                                                 {
00304                                                                         resolved = true; // ok base class in blank namespace
00305                                                                         cls -> bUsed = true;
00306                                                                         break;
00307                                                                 }
00308                                                         }
00309                                                 }
00310                                         }
00311                                         if (!resolved) // base must be on our namespace, somehow
00312                                         {
00313                                                 ADD *tmp = new ADD;
00314                                                 tmp -> nsp = nsp -> name;
00315                                                 tmp -> cls = base;
00316                                                 c2add.push_back( tmp );
00317 
00318                                                 if (nsp -> name.size())
00319                                                         base = nsp -> name + "::" + base;
00320                                         }
00321                                 }
00322                                 } // !strstr(,"::")
00323 
00324                                 if (strcmp((*it3).c_str(),base.c_str()))
00325                                 {
00326 DEB(                                    printf(" fix_class() renaming base class '%s' to '%s'\n",(*it3).c_str(),base.c_str());)
00327                                         (*it3) = base;
00328                                 }
00329 
00330                                 if (!resolved)
00331                                 {
00332                                         std::string strNamespace;
00333                                         std::string strName = base;
00334                                         for (size_t i = 0; i < base.size() - 1; i++)
00335                                         {
00336                                                 if (base[i] == ':' && base[i + 1] == ':')
00337                                                 {
00338                                                         char slask[1000];
00339                                                         strcpy(slask,base.c_str());
00340                                                         slask[i] = 0;
00341                                                         strNamespace = slask;
00342                                                         strName = slask + i + 2;
00343                                                 }
00344                                         }
00345                                         CLS *t2;
00346                                         if (!(t2 = find_class(strNamespace,strName)))
00347                                         {
00348                                                 ADD *tmp = new ADD;
00349                                                 tmp -> nsp = strNamespace;
00350                                                 tmp -> cls = strName;
00351                                                 c2add.push_back( tmp );
00352                                         }
00353                                         else
00354                                         {
00355 DEB(                                            printf("setting bUsed for class '%s' in namespace '%s'\n",strName.c_str(),strNamespace.c_str());)
00356                                                 t2 -> bUsed = true;
00357                                         }
00358                                 }
00359                         }
00360                 }
00361         }
00362 DEB(    printf("fix_class() adding\n");)
00363         for (std::vector<ADD *>::iterator it = c2add.begin(); it != c2add.end(); it++)
00364         {
00365                 ADD *tmp = *it;
00366                 std::vector<std::string> vec;
00367                 vec.push_back("class");
00368                 vec.push_back(tmp -> cls);
00369                 vec.push_back("{");
00370 DEB(            printf("Adding '%s :: %s'\n",tmp -> nsp.c_str(),tmp -> cls.c_str());)
00371                 CLS *t2 = add_class(tmp -> nsp,vec,"",0,true);
00372                 t2 -> bUsed = true;
00373         }
00374 
00375         // relationer
00376 DEB(    printf("fix_class() relationer\n");)
00377         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
00378         {
00379                 NSP *nsp = *it;
00380                 for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00381                 {
00382                         CLS *cls = *it;
00383                         std::string name;
00384                         if (nsp -> name.size())
00385                                 name = nsp -> name + "::" + cls -> name;
00386                         else
00387                                 name = cls -> name;
00388                         for (string_v::iterator it = cls -> using_type.begin(); it != cls -> using_type.end(); it++)
00389                         {
00390                                 std::string typ = *it;
00391                                 char slask[1000];
00392                                 bool ptr = false;
00393                                 bool arr = false;
00394                                 bool ref = false;
00395                                 char *s;
00396                                 strcpy(slask,typ.c_str());
00397                                 if ((s = strstr(slask,"*")) != NULL)
00398                                 {
00399                                         ptr = true;
00400                                         *s = 0;
00401                                 }
00402                                 if ((s = strstr(slask,"[")) != NULL)
00403                                 {
00404                                         arr = true;
00405                                         *s = 0;
00406                                 }
00407                                 if ((s = strstr(slask,"&")) != NULL)
00408                                 {
00409                                         ref = true;
00410                                         *s = 0;
00411                                 }
00412                                 NSP *nsp2;
00413                                 CLS *cls2;
00414                                 if (locate(nsp,slask,nsp2,cls2))
00415                                 {
00416                                         cls -> bUsed = true;
00417                                         cls2 -> bUsed = true;
00418                                 }
00419                         } // for (relationer...
00420                 }
00421         }
00422         // /relationer
00423 DEB(    printf("fix_class() ok\n");)
00424 }

NSP * BlackAdder::GetNamespace const std::string &  name,
bool  add = true
 

Definition at line 225 of file BlackAdder.cpp.

References m_added.

Referenced by add_class(), find_class(), is_class(), locate(), set_typedef(), and type_lookup().

00226 {
00227         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
00228         {
00229                 NSP *nsp = *it;
00230                 if (!strcmp(nsp -> name.c_str(),name.c_str()))
00231                 {
00232                         return nsp;
00233                 }
00234         }
00235         if (!add)
00236                 return NULL;
00237         NSP *nsp = new NSP;
00238         nsp -> name = name;
00239         m_added.push_back(nsp);
00240         return nsp;
00241 }

bool BlackAdder::has_subclass NSP nsp0,
CLS cls0,
const std::string &  color
[private]
 

Definition at line 457 of file BlackAdder.cpp.

References darken(), m_added, and merge_colors().

Referenced by MakeDot().

00458 {
00459         bool r = false;
00460         std::string name0;
00461         if (nsp0 -> name.size())
00462                 name0 = nsp0 -> name + "::" + cls0 -> name;
00463         else
00464                 name0 = cls0 -> name;
00465 fprintf(stderr, "Check subclass for '%s'\n", name0.c_str());
00466         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
00467         {
00468                 NSP *nsp = *it;
00469                 for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00470                 {
00471                         CLS *cls = *it;
00472                         std::string name;
00473                         if (nsp -> name.size())
00474                                 name = nsp -> name + "::" + cls -> name;
00475                         else
00476                                 name = cls -> name;
00477                         for (string_v::iterator it = cls -> bases.begin(); it != cls -> bases.end(); it++)
00478                         {
00479                                 std::string base = *it;
00480 fprintf(stderr, " ... check base '%s'\n", base.c_str());
00481                                 if (base == name0)
00482                                 {
00483                                         if (cls -> color.size())
00484                                         {
00485                                                 cls -> color = darken(merge_colors(cls -> color, color));
00486                                         }
00487                                         else
00488                                         {
00489                                                 cls -> color = darken(color);
00490                                         }
00491                                         r = true;
00492                                 }
00493 /*
00494                                 if (base == cls0 -> name)
00495                                         return true;
00496 */
00497                         }
00498                 }
00499         }
00500 fprintf(stderr, " has_subclass OK\n");
00501         return r;
00502 }

bool BlackAdder::is_class const std::string &  nspace,
const std::string &  name
 

Definition at line 1078 of file BlackAdder.cpp.

References GetNamespace().

01079 {
01080         NSP *nsp = GetNamespace(name, false);
01081         if (!nsp)
01082                 return false;
01083         for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
01084         {
01085                 CLS *cls = *it;
01086                 if (!strcmp(cls -> name.c_str(), name.c_str()))
01087                 {
01088                         return true;
01089                 }
01090         }
01091         return false;
01092 }

bool BlackAdder::locate NSP base,
const char *  ,
NSP *&  ,
CLS *&  ,
bool  add = true
[private]
 

Definition at line 938 of file BlackAdder.cpp.

References GetNamespace(), m_added, and m_using.

Referenced by fix_class(), and MakeDot().

00939 {
00940         std::string strUsing;
00941         bool found = false;
00942         for (strstr_m::iterator it = m_using.begin(); it != m_using.end(); it++)
00943         {
00944                 if (!strcmp((*it).first.c_str(), name))
00945                 {
00946                         strUsing = (*it).second;
00947                         found = true;
00948                         break;
00949                 }
00950         }
00951         if (found && strUsing.size())
00952         {
00953                 size_t x = 0;
00954                 char slask[3000];
00955                 for (size_t i = 0; i < strUsing.size() - 2; i++)
00956                         if (strUsing[i] == ':' && strUsing[i + 1] == ':')
00957                                 x = i;
00958                 strcpy(slask,strUsing.c_str());
00959                 slask[x] = 0;
00960                 nsp2 = GetNamespace(slask,add);
00961                 for (std::vector<CLS *>::iterator it = nsp2 -> added.begin(); it != nsp2 -> added.end(); it++)
00962                 {
00963                         CLS *cls = *it;
00964                         if (!strcmp(cls -> name.c_str(),name))
00965                         {
00966                                 cls2 = cls;
00967                                 return true;
00968                         }
00969                 }
00970                 return false; // huh
00971         }
00972         else
00973         {
00974                 nsp2 = base;
00975                 for (std::vector<CLS *>::iterator it = nsp2 -> added.begin(); it != nsp2 -> added.end(); it++)
00976                 {
00977                         CLS *cls = *it;
00978                         if (!strcmp(cls -> name.c_str(),name))
00979                         {
00980                                 cls2 = cls;
00981                                 return true;
00982                         }
00983                 }
00984                 nsp2 = GetNamespace("",add);
00985                 if (!nsp2)
00986                 {
00987                         fprintf(stderr,"Couldn't find empty namespace\n");
00988                 }
00989                 else
00990                 for (std::vector<CLS *>::iterator it = nsp2 -> added.begin(); it != nsp2 -> added.end(); it++)
00991                 {
00992                         CLS *cls = *it;
00993                         if (!cls)
00994                                 fprintf(stderr,"locate, cls is NULL\n");
00995                         else
00996                         {
00997                                 if (!strcmp(cls -> name.c_str(),name))
00998                                 {
00999                                         cls2 = cls;
01000                                         return true;
01001                                 }
01002                         }
01003                 }
01004         }
01005         return false;
01006 
01007         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
01008         {
01009                 NSP *nsp = *it;
01010                 for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
01011                 {
01012                         CLS *cls = *it;
01013                         if (!strcmp(cls -> name.c_str(),name))
01014                         {
01015                                 nsp2 = nsp;
01016                                 cls2 = cls;
01017                                 return true;
01018                         }
01019                 }
01020         }
01021         return false;
01022 }

void BlackAdder::MakeDot const std::string &  group_name = ""  ) 
 

Definition at line 606 of file BlackAdder.cpp.

References box, cluster, colorcount, colors, config, darken(), DEB, find_base(), fix_class(), fontsize, has_subclass(), locate(), m_added, maxcolor, and merge_colors().

Referenced by main().

00607 {
00608         bool bCluster = true;
00609 DEB(    printf("MakeDot()\n");) 
00610         if (config["-cluster"] == "true")
00611                 bCluster = false;
00612 
00613 DEB(    printf("fix_class()\n");)
00614         fix_class();
00615 
00616 
00617 //      ---
00618         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
00619         {
00620                 NSP *nsp = *it;
00621                 for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00622                 {
00623                         CLS *cls = *it;
00624                         if (cls -> group_name != group_name)
00625                                 continue;
00626                         bool has_base = cls -> bases.size() ? true : false;
00627 fprintf(stderr, "calling has_subclass\n");
00628                         if (!has_base && has_subclass(nsp, cls, colors[colorcount % maxcolor]))
00629                         {
00630                                 cls -> color = colors[colorcount++ % maxcolor];
00631                         }
00632                 }
00633         }
00634 //      ---
00635         fprintf(stderr, "*** Assigning colors for subclasses\n");
00636         for (int i = 0; i < 10; i++)
00637         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
00638         {
00639                 NSP *nsp = *it;
00640                 for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00641                 {
00642                         CLS *cls = *it;
00643                         if (cls -> group_name != group_name)
00644                                 continue;
00645                         std::list<CLS *> vec = find_base(nsp, cls);
00646                         if (!cls -> color.size() || cls -> color == "#ffffff")
00647                         {
00648                                 std::string color = "#ffffff";
00649                                 bool ok = true;
00650                                 for (std::list<CLS *>::iterator it = vec.begin(); it != vec.end(); it++)
00651                                 {
00652                                         CLS *cls_base = *it;
00653                                         if (cls_base -> color.size() == 0)
00654                                         {
00655                                                 ok = false;
00656                                         }
00657                                         else
00658                                         {
00659                                                 color = merge_colors(color, cls_base -> color);
00660                                         }
00661                                 }
00662                                 if (ok && color != "#ffffff")
00663                                 {
00664                                         cls -> color = darken(color);
00665                                 }
00666                         }
00667                 }
00668         }
00669 //      ---
00670 
00671         for (int empty = 1; empty >= 0; empty--)
00672         {
00673 DEB(            printf(" empty = %d\n",empty);)
00674         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
00675         {
00676                 NSP *nsp = *it;
00677                 bool clust = false;
00678                 if ((nsp -> name.size() && !empty) || (!nsp -> name.size() && empty))
00679                 {
00680                         if (nsp -> name.size() && (bCluster || box[nsp -> name.c_str()] == "true") )
00681                         {
00682                                 printf("        subgraph cluster_%ld {\n",cluster++);
00683                                 printf("                style=filled;\n");
00684                                 printf("                fillcolor=lightgrey;\n");
00685                                 printf("                label=\"Namespace '%s'\"\n",nsp -> name.c_str());
00686                                 printf("                node [shape=box style=filled fillcolor=white]\n");
00687                                 clust = true;
00688                         }
00689                         else
00690                         {
00691 //                              printf("        node [shape=box]\n");
00692                         }
00693                         for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00694                         {
00695                                 CLS *cls = *it;
00696                                 if (cls -> group_name != group_name)
00697                                         continue;
00698 //                              bool has_base = cls -> bases.size() ? true : false;
00699 //                              find_color(cls);
00700                                 std::string name;
00701                                 std::string args; // [ ...args... ]
00702                                 if (nsp -> name.size())
00703                                         name = nsp -> name + "::" + cls -> name;
00704                                 else
00705                                         name = cls -> name;
00706                                 // build args
00707                                 if (cls -> filename.size())
00708                                 {
00709 //                                      char slask[1000];
00710 //                                      sprintf(slask," URL=\"index.html\" tooltip=\"%s(%d)\"",cls -> filename.c_str(),cls -> line);
00711 //                                      args += slask;
00712                                         switch (cls -> filename[0])
00713                                         {
00714                                         case '/': // sys hdr (probably)
00715                                                 args += " style=filled fillcolor=\"#e0a0a0\"";
00716                                                 break;
00717                                         case '.':
00718                                                 if (cls -> filename.size() > 1 && cls -> filename[1] == '.')
00719                                                 {
00720                                                         args += " style=filled fillcolor=\"#e0e0e0\"";
00721                                                 }
00722                                                 break;
00723                                         }
00724                                 }
00725                                 else
00726                                 if (cls -> bExtern)
00727                                 {
00728                                         args += " style=filled fillcolor=\"#e0a0a0\"";
00729                                 }
00730                                 if (!args.size())
00731                                 {
00732                                         char slask[1000];
00733                                         char tmp[1000];
00734                                         size_t j = 0;
00735                                         for (size_t i = 0; i < cls -> name.size(); i++)
00736                                         {
00737                                                 if (cls -> name[i] == '_')
00738                                                         tmp[j++] = '_';
00739                                                 tmp[j++] = cls -> name[i];
00740                                         }
00741                                         tmp[j] = 0;
00742                                         sprintf(slask," URL=\"html/class%s.html\" tooltip=\"Class documentation\"",tmp);
00743                                         args += slask;
00744                                 }
00745                                 // add fontsize
00746                                 {
00747                                         char slask[100];
00748                                         sprintf(slask, " fontsize=%d", fontsize);
00749                                         args += slask;
00750                                 }
00751 //                              if (!has_base && has_subclass(nsp, cls) )
00752                                 if (cls -> color.size())
00753                                 {
00754                                         args += " style=filled fillcolor=\""; //#ffffe0\"";
00755                                         args += cls -> color; //colors[colorcount++ % maxcolor];
00756                                         args += "\"";
00757                                 }
00758                                 // ...
00759                                 {
00760                                         if (clust)
00761                                                 printf("\t");
00762                                         if (args.size())
00763                                         {
00764                                                 printf("\t\"%s\" [%s]\n",name.c_str(),args.c_str() + 1);
00765                                         }
00766                                         else
00767                                         {
00768                                                 printf("\t\"%s\"\n",name.c_str());
00769                                         }
00770                                 }
00771                         }
00772                         if (clust)
00773                         {
00774                                 printf("        }\n");
00775                         }
00776                 } // if (empty...
00777         }
00778         // arv
00779 DEB(    printf("arv\n");)
00780         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
00781         {
00782                 NSP *nsp = *it;
00783                 bool debug = false;
00784                 if ((nsp -> name.size() && !empty) || (!nsp -> name.size() && empty))
00785                 {
00786                 for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00787                 {
00788                         CLS *cls = *it;
00789                         if (cls -> group_name != group_name)
00790                                 continue;
00791                         std::string name;
00792                         if (nsp -> name.size())
00793                                 name = nsp -> name + "::" + cls -> name;
00794                         else
00795                                 name = cls -> name;
00796                         for (string_v::iterator it = cls -> bases.begin(); it != cls -> bases.end(); it++)
00797                         {
00798                                 std::string base = *it;
00799                                 bool resolved = false;
00800                                 if (strstr(name.c_str(),"Form") ||
00801                                     strstr(base.c_str(),"Form")
00802                                    )
00803                                 {
00804                                         fprintf(stderr,"Class: '%s' : Base Class: '%s'\n",name.c_str(),base.c_str());
00805                                         debug = true;
00806                                 }
00807                                 for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00808                                 {
00809                                         CLS *cls = *it;
00810                                         if (!strcmp(cls -> name.c_str(),base.c_str()))
00811                                         {
00812                                                 if (!strstr(base.c_str(),"::") && nsp -> name.size())
00813                                                         base = nsp -> name + "::" + base;
00814                                                 resolved = true;
00815                                                 if (debug)
00816                                                         fprintf(stderr,"resolved as 1\n");
00817                                                 break;
00818                                         }
00819                                 }
00820                                 if (!resolved && !strstr(base.c_str(),"::") ) // find class in blank namespace
00821                                 {
00822                                         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
00823                                         {
00824                                                 NSP *nsp = *it;
00825                                                 if (!nsp -> name.size()) // blank namespace
00826                                                 {
00827                                                         for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00828                                                         {
00829                                                                 CLS *cls = *it;
00830                                                                 if (!strcmp(cls -> name.c_str(),base.c_str()))
00831                                                                 {
00832                                                                         resolved = true; // ok base class in blank namespace
00833                                                                         if (debug)
00834                                                                                 fprintf(stderr,"resolved as 2\n");
00835                                                                         break;
00836                                                                 }
00837                                                         }
00838                                                 }
00839                                         }
00840                                         if (!resolved) // base must be on our namespace, somehow
00841                                         {
00842                                                 if (!strstr(base.c_str(),"::") && nsp -> name.size())
00843                                                 {
00844                                                         base = nsp -> name + "::" + base;
00845                                                         if (debug)
00846                                                                 fprintf(stderr,"not resolved - renamed: %s\n",base.c_str());
00847                                                 }
00848                                         }
00849                                 }
00850                                 printf("        \"%s\" -> \"%s\" [dir=back arrowtail=empty]\n",
00851                                         base.c_str(),name.c_str());
00852                         } // for (basklasser...
00853                 }
00854                 } // if (empty...
00855         }
00856         } // for (empty)
00857 
00858         // relationer
00859 DEB(    printf("relationer\n");)
00860         for (std::vector<NSP *>::iterator it = m_added.begin(); it != m_added.end(); it++)
00861         {
00862                 NSP *nsp = *it;
00863                 for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
00864                 {
00865                         CLS *cls = *it;
00866                         if (cls -> group_name != group_name)
00867                                 continue;
00868                         std::string name;
00869                         if (nsp -> name.size())
00870                                 name = nsp -> name + "::" + cls -> name;
00871                         else
00872                                 name = cls -> name;
00873                         for (string_v::iterator it = cls -> using_type.begin(); it != cls -> using_type.end(); it++)
00874                         {
00875                                 std::string typ = *it;
00876                                 char slask[1000];
00877                                 bool ptr = false;
00878                                 bool arr = false;
00879                                 bool ref = false;
00880                                 char *s;
00881                                 strcpy(slask,typ.c_str());
00882                                 if ((s = strstr(slask,"*")) != NULL)
00883                                 {
00884                                         ptr = true;
00885                                         *s = 0;
00886                                 }
00887                                 if ((s = strstr(slask,"[")) != NULL)
00888                                 {
00889                                         arr = true;
00890                                         *s = 0;
00891                                 }
00892                                 if ((s = strstr(slask,"&")) != NULL)
00893                                 {
00894                                         ref = true;
00895                                         *s = 0;
00896                                 }
00897                                 NSP *nsp2;
00898                                 CLS *cls2;
00899                                 if (strncmp(slask, "int", 3) && locate(nsp,slask,nsp2,cls2,false))
00900                                 {
00901                                         std::string name2;
00902                                         if (nsp2 -> name.size())
00903                                                 name2 = nsp2 -> name + "::" + cls2 -> name;
00904                                         else
00905                                                 name2 = cls2 -> name;
00906 //                                      printf("        \"%s\" [fontsize=%d]\n", name.c_str(), fontsize);
00907                                         if (ptr)
00908                                         {
00909                                                 printf("        \"%s\" -> \"%s\" [arrowtail=none arrowhead=open style=dashed]\n",
00910                                                         name.c_str(),
00911                                                         name2.c_str());
00912                                         }
00913                                         else
00914                                         if (ref)
00915                                         {
00916                                                 printf("        \"%s\" -> \"%s\" [arrowtail=odiamond arrowhead=none style=dashed]\n",
00917                                                         name.c_str(),
00918                                                         name2.c_str());
00919                                         }
00920                                         else
00921                                         {
00922                                                 printf("        \"%s\" -> \"%s\" [arrowtail=diamond arrowhead=none style=dashed]\n",
00923                                                         name.c_str(),
00924                                                         name2.c_str());
00925                                         }
00926                                 }
00927                                 else
00928                                 {
00929                                 }
00930                         } // for (relationer...
00931                 }
00932         }
00933         // /relationer
00934 DEB(    printf("MakeDot() ok\n");)
00935 }

void BlackAdder::set_typedef const std::string &  nspace,
const std::string &  ,
std::vector< std::string > & 
 

Definition at line 1025 of file BlackAdder.cpp.

References GetNamespace().

01026 {
01027         NSP *nsp = GetNamespace(nspace);
01028         nsp -> typedefs[t] = def;
01029 }

bool BlackAdder::type_lookup CLS ,
const std::string &  typ,
string_v ,
NSP *& 
 

Definition at line 1032 of file BlackAdder.cpp.

References GetNamespace(), and string_v.

01033 {
01034         nsp = GetNamespace(cls -> m_namespace);
01035         for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
01036         {
01037                 CLS *cls = *it;
01038                 if (!strcmp(cls -> name.c_str(),typ.c_str()))
01039                 {
01040                         return true;
01041                 }
01042         }
01043         for (typedef_m::iterator it = nsp -> typedefs.begin(); it != nsp -> typedefs.end(); it++)
01044         {
01045                 std::string typname = (*it).first;
01046                 string_v& ref = (*it).second;
01047                 if (!strcmp(typname.c_str(), typ.c_str()))
01048                 {
01049                         translated = ref;
01050                         return true;
01051                 }
01052         }
01053         nsp = GetNamespace("", false);
01054         if (!nsp)
01055                 return false;
01056         for (std::vector<CLS *>::iterator it = nsp -> added.begin(); it != nsp -> added.end(); it++)
01057         {
01058                 CLS *cls = *it;
01059                 if (!strcmp(cls -> name.c_str(),typ.c_str()))
01060                 {
01061                         return true;
01062                 }
01063         }
01064         for (typedef_m::iterator it = nsp -> typedefs.begin(); it != nsp -> typedefs.end(); it++)
01065         {
01066                 std::string typname = (*it).first;
01067                 string_v& ref = (*it).second;
01068                 if (!strcmp(typname.c_str(), typ.c_str()))
01069                 {
01070                         translated = ref;
01071                         return true;
01072                 }
01073         }
01074         return false;
01075 }


Member Data Documentation

std::vector<NSP *> BlackAdder::m_added [private]
 

Definition at line 83 of file BlackAdder.h.

Referenced by find_class(), fix_class(), GetNamespace(), has_subclass(), locate(), and MakeDot().

strstr_m BlackAdder::m_using [private]
 

Definition at line 84 of file BlackAdder.h.

Referenced by add_class(), add_using(), clear_using(), and locate().


The documentation for this class was generated from the following files:
Generated for My SDL C++ Gui by doxygen 1.3.6