00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <string>
00024 #include <vector>
00025 #include <map>
00026
00027 #include "dp.h"
00028 #include "BlackAdder.h"
00029
00030
00031 #define DEB(x)
00032
00033
00034 typedef struct
00035 {
00036 std::string nsp;
00037 std::string cls;
00038 } ADD;
00039
00040 static const char *colors[] = { "#ffffcc", "#ffccff", "#ccffff", "#ffcccc", "#ccffcc", "#ccccff", "#99ccff", "#cc99ff", "#99ffcc", "#ccff99" };
00041 static int colorcount = 0;
00042 static int maxcolor = 10;
00043
00044
00045 BlackAdder::BlackAdder()
00046 {
00047 }
00048
00049
00050 BlackAdder::~BlackAdder()
00051 {
00052 }
00053
00054
00055 CLS *BlackAdder::add_class(const std::string& strNamespace,string_v& vecStr,const std::string& filename,int line,bool bExtern)
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
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
00133 return tmp;
00134 }
00135
00136
00137 void BlackAdder::add_using(const std::string& str)
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 }
00145
00146
00147 CLS *BlackAdder::find_class(const std::string& strNamespace,const std::string& strName)
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 }
00159
00160
00161 void BlackAdder::clear_using()
00162 {
00163 while (m_using.size())
00164 m_using.erase(m_using.begin());
00165 }
00166
00167
00168 void BlackAdder::add_type(CLS *cls,const std::string& str)
00169 {
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
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 }
00222
00223
00224
00225 NSP *BlackAdder::GetNamespace(const std::string& name,bool add)
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 }
00242
00243
00244 void BlackAdder::fix_class()
00245 {
00246 std::vector<ADD *> c2add;
00247 return;
00248
00249
00250
00251
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
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
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
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)
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())
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;
00305 cls -> bUsed = true;
00306 break;
00307 }
00308 }
00309 }
00310 }
00311 if (!resolved)
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 }
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
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 }
00420 }
00421 }
00422
00423 DEB( printf("fix_class() ok\n");)
00424 }
00425
00426
00427 std::string darken(const std::string& color)
00428 {
00429 std::string r = "#";
00430 for (int i = 1; i < 7; i++)
00431 {
00432 r += color[i];
00433 if (color[i] > '0' && color[i] < 'f')
00434 {
00435 if (color[i] == 'a')
00436 r[i] = '8';
00437 else
00438 if (color[i] == 'b')
00439 r[i] = '9';
00440 else
00441 r[i] -= 2;
00442 }
00443 }
00444 return r;
00445 }
00446
00447
00448 std::string merge_colors(const std::string&c1, const std::string& c2)
00449 {
00450 std::string r;
00451 for (int i = 0; i < 7; i++)
00452 r += c1[i] < c2[i] ? c1[i] : c2[i];
00453 return r;
00454 }
00455
00456
00457 bool BlackAdder::has_subclass(NSP *nsp0, CLS *cls0, const std::string& color)
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
00495
00496
00497 }
00498 }
00499 }
00500 fprintf(stderr, " has_subclass OK\n");
00501 return r;
00502 }
00503
00504
00505 CLS *BlackAdder::find_class(const std::string& name0)
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 }
00526
00527
00528 std::list<CLS *> BlackAdder::find_base(NSP *nsp, CLS *cls)
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
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597 if (base_cls)
00598 {
00599 bases.push_back(base_cls);
00600 }
00601 }
00602 return bases;
00603 }
00604
00605
00606 void BlackAdder::MakeDot(const std::string& group_name)
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
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
00699
00700 std::string name;
00701 std::string args;
00702 if (nsp -> name.size())
00703 name = nsp -> name + "::" + cls -> name;
00704 else
00705 name = cls -> name;
00706
00707 if (cls -> filename.size())
00708 {
00709
00710
00711
00712 switch (cls -> filename[0])
00713 {
00714 case '/':
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
00746 {
00747 char slask[100];
00748 sprintf(slask, " fontsize=%d", fontsize);
00749 args += slask;
00750 }
00751
00752 if (cls -> color.size())
00753 {
00754 args += " style=filled fillcolor=\"";
00755 args += cls -> color;
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 }
00777 }
00778
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(),"::") )
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())
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;
00833 if (debug)
00834 fprintf(stderr,"resolved as 2\n");
00835 break;
00836 }
00837 }
00838 }
00839 }
00840 if (!resolved)
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 }
00853 }
00854 }
00855 }
00856 }
00857
00858
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
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 }
00931 }
00932 }
00933
00934 DEB( printf("MakeDot() ok\n");)
00935 }
00936
00937
00938 bool BlackAdder::locate(NSP *base,const char *name,NSP *&nsp2,CLS *&cls2,bool add)
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;
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 }
01023
01024
01025 void BlackAdder::set_typedef(const std::string& nspace,const std::string& t,std::vector<std::string>&def)
01026 {
01027 NSP *nsp = GetNamespace(nspace);
01028 nsp -> typedefs[t] = def;
01029 }
01030
01031
01032 bool BlackAdder::type_lookup(CLS *cls,const std::string& typ,string_v& translated,NSP *& nsp)
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 }
01076
01077
01078 bool BlackAdder::is_class(const std::string& nspace,const std::string& name)
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 }
01093
01094