📄 entry.cc
字号:
/* Entry.cc Copyright (c) 1996 Roland Wunderling, Malte Zoeckler Copyright (c) 1998 Michael Meeks Copyright (c) 1999-2001 Dragos Acostachioaie This file is part of DOC++. DOC++ is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the license, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include <assert.h>#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include "doc.h"#define max(a, b) ((a) > (b) ? (a) : (b))#define MAX_CACHE 5// Reserved keywordschar cxxreserved[] = "bool char class const double enum export extern float" "friend inline int long namespace operator private" "protected public register short signed static struct" "throw typedef union unsigned using void volatile virtual";char javareserved[]= "boolean byte char class double extends final float" "implements import int interface long native package" "private protected public short static synchronized throws" "transient volatile";char idlreserved[] = "any attribute boolean case char const context default" "double enum exception FALSE fixed float in inout" "interface long module Object octet oneway out raises" "readonly sequence short string struct switch TRUE typedef" "unsigned union void wchar wstring";char phpreserved[] = "class extends function include require";static McHashTable<const char *, char *> *cxxtable;static McHashTable<const char *, char *> *javatable;static McHashTable<const char *, char *> *idltable;static McHashTable<const char *, char *> *phptable;static McHashTable<const char*, Entry*> namespace_roots(0);// Simple round robin cache for `fastNotSmall == true'static int cache_pos = 0;// So we can remember blanks as wellstatic char *cache_name[MAX_CACHE];static Entry *cache_entry[MAX_CACHE];// Don't want general bits#define worthDoing(m) !m->generalvoid makeSubLists(Entry *rt);Entry *findJavaPackage(McString n, Entry *root, Entry *p = 0);Entry *findJavaClass(McString n, Entry *root);bool isIt(const McString& n, const Entry *m);static McString* get1RefName(McString &str, int start, int end);unsigned int countCommas(McString const &args);void separateArguments(char const *args, McDArray<McString *> &arg_list);bool equalTypes(McString const &a, McString const &b);bool equalArgs(McString const &a, McString const &b);bool equalSignature(Entry *a, Entry *b);Entry *lookupEntryBySignature(Entry *group, Entry *model);bool hasDocumentation(Entry const *entry);void mergeDocumentation(Entry *original, Entry *ccentry);bool mergeEntry(Entry *ccentry);void mergeEntries(Entry *root);void getRefNames(McDArray<McString*> strings, const char *names);void addNamespace(Entry* entry){ Entry** e = namespace_roots.lookup(entry->fullName.c_str()); if(e == 0) namespace_roots[entry->fullName.c_str()] = entry;}Entry::Entry(){ static int n = 1; number = n++; subnumber = 0; protection = PUBL; section = EMPTY_SEC; file = _("No file"); parent = 0; next = 0; sub = 0; ownPage = 0; override = 0; currentParent = 0; htype = 0; hname = 0; hargs = 0; hmemo = 0; hsee = 0; hdoc = 0; line = 0; general = 0; pureVirtual = false; fromUnknownPackage = false; docify = !onlyDocs;}void Entry::addBaseClass(Entry *base, PROTECTION state){ Entry *tmp2 = this; if(state == PUBL) { pubBaseclasses.append(base); base->pubChilds.insert(0, 1, &tmp2); } else if(state == PROT) { proBaseclasses.append(base); base->proChilds.insert(0, 1, &tmp2); } else { priBaseclasses.append(base); base->priChilds.insert(0, 1, &tmp2); } baseclasses.append(base);}void Entry::addBaseClass(const char *classname, PROTECTION state){ Entry *tmp = 0, *p; McString t, *str; if(language == LANG_JAVA) { t = classname; makeFullName(t); tmp = findJavaClass(t, root); } else { p = (parent != 0) ? parent : this; tmp = getRefEntry(classname, p); } if(tmp && ((tmp->section & CLASS_SEC) || (tmp->section & INTERFACE_SEC))) addBaseClass(tmp, state); else { str = new McString(classname); if(state == PUBL) otherPubBaseclasses.append(str); else if(state == PROT) otherProBaseclasses.append(str); else otherPriBaseclasses.append(str); }}void Entry::addSubEntry(Entry *current){ int i = 1; Entry **e = ⊂ sublist.append(current); for(; *e; e = &((*e)->next), ++i) ; *e = current; current->parent = this; current->next = 0; current->subnumber = i; current->makeFullName();}void Entry::clear(){ type.clear(); name.clear(); fullName.clear(); args.clear(); memo.clear(); doc.clear(); program.clear();}void Entry::dump(FILE *foo, bool recursive){#ifdef DEBUG int i; fprintf(foo, "--------------------------Start-%p-----------------------------\n", this); fprintf(foo, "section %d protection `%c'\n", section, protection); fprintf(foo, "parent %p next %p sub %p\n", parent, next, sub); fprintf(foo, "type `%s'\n", type.c_str()); fprintf(foo, "name `%s'\n", name.c_str()); fprintf(foo, "args `%s'\n", args.c_str()); fprintf(foo, "memo `%s'\n", memo.c_str()); fprintf(foo, "doc `%s'\n", doc.c_str()); fprintf(foo, "file `%s'\n", file.c_str()); fprintf(foo, "fullName `%s'\n", fullName.c_str()); fprintf(foo, "author `%s' version `%s'\n", author.c_str(), version.c_str()); if(see.size()) fprintf(foo, "see:\n"); for(i = 0; i < see.size(); i++) fprintf(foo, " `%s'\n", see[i]->c_str()); if(param.size()) fprintf(foo, "param:\n"); for(i = 0; i < param.size(); i++) fprintf(foo, " `%s'\n", param[i]->c_str()); if(exception.size()) fprintf(foo, "exception:\n"); for(i = 0; i < exception.size(); i++) fprintf(foo, " `%s'\n", exception[i]->c_str()); if(htype) fprintf(foo, "htype `%s'", htype); if(hname) fprintf(foo, "hname `%s'", hname); if(hargs) fprintf(foo, "hargs `%s'\n", hargs); if(hmemo) fprintf(foo, "hmemo `%s'", hmemo); if(hsee) fprintf(foo, "hsee `%s'", hsee); if(hdoc) fprintf(foo, "hdoc `%s'\n", hdoc); fprintf(foo, "fileName `%s' line %d general %d ownPage %d\n", fileName.c_str(), line, general, ownPage); fprintf(foo, "number %d subnumber %d\n", number, subnumber); if(sublist.size()) { fprintf(foo, "sublist:\n"); for(i = 0; i < sublist.size(); i++) if(recursive) sublist[i]->dump(foo, recursive); else fprintf(foo, " `%s'\n", sublist[i]->name.c_str()); } fprintf(foo,"----------------------------End-%p-----------------------------\n", this);#endif}void Entry::dumpNumber(McString &s){ static char buf[33]; if(parent) { parent->dumpNumber(s); sprintf(buf, "%d", subnumber); if(parent->parent) { s += '.'; s += buf; } else s += buf; }}void Entry::dumpNumber(FILE *f){ McString num; dumpNumber(num); fprintf(f, "%s", num.c_str());}// This assumes they are sorted, and binary chop searches ?/*Entry *Entry::findSub(const McString& name, int first, int last){ int i; if(last - first < 4) // I assume this is to catch different adjacent duplicates { for(i = first + 1; i <= last - 1; i++) if(isIt(name, sublist[i])) return sublist[i]; return 0; } int n = (first + last) / 2; int result = strcmp(name.c_str(), sublist[n]->name.c_str()); if(result == 0) return sublist[n]; if(result > 0) return findSub(name, n, last); return findSub(name, first, n);}*/// This routine is called `A HELL OF A LOT' (tm), and needs keeping smallEntry *Entry::findSub(const McString& n){ int i, max; if(n == name) return this;// For some reason, the binary search fails, so let's fall down to a simple// linear search, just to be safe for(i = 0; i < sublist.size(); i++) if(isIt(n, sublist[i])) return sublist[i];/* if(sublist.size()) { max = sublist.size() - 1; if(isIt(name, sublist[0])) return sublist[0]; if(isIt(name, sublist[max])) return sublist[max]; Entry *found = findSub(name, 0, max); if(found) return found; }*/ for(i = sublist.size(); i-- > 0; ) if(sublist[i]->sub) { Entry *found = sublist[i]->findSub(n); if(found) return found; } for(i = 0; i < sublist.size(); i++) if(worthDoing(sublist[i]) && n == sublist[i]->name) return sublist[i]; return 0;}void Entry::getPackage(McString &n){ Entry *tmp = this; n = ""; while(tmp) { if(tmp->section == PACKAGE_SEC) { if(n.length() > 0) n.insert(0, "."); n.insert(0, tmp->name.c_str()); } tmp = tmp->parent; } }bool Entry::isClass(){ return((section & CLASS_SEC) || (section & INTERFACE_SEC));}void Entry::makeFullName(McString &n){ int i, p, ri;#ifdef DEBUG if(verb) printf(_("Make full name from `%s'\n"), n.c_str());#endif // If `n' is already a fully qualified name, just return if((p = n.index('.')) >= 0) { McString innerName(n, p + 1, n.length() - p - 1); McString className(n, 0, p); if(innerName.index('.') >= 0) return; else { const char *cstr = className.c_str(); if(!isupper(*cstr)) return; makeFullName(className); n = className; n += "."; n += innerName; return; } } // Search in the list of import statements for(i = 0; i < import.size(); i++) { ri = import[i]->rindex('.'); if(ri >= 0) if(strcmp(n.c_str(), (char *)(*(import[i])) + ri + 1) == 0) { n = *(import[i]); return; } } McString thispkg; getPackage(thispkg); if(thispkg.length()) thispkg += '.'; // Search the documented packages McString tmp(thispkg); tmp += n; Entry *found = findEntry(root, tmp.c_str(), CLASS_SEC | INTERFACE_SEC); for(i = 0; i < import.size() && !found; i++) { ri = import[i]->rindex('*'); if(ri >= 0) { tmp = *(import[i]); tmp.resize(ri); if(tmp.length()) tmp += '.'; tmp += n; found = findEntry(root, tmp.c_str(), CLASS_SEC | INTERFACE_SEC); } } if(found) { n = found->fullName; return; } // Try to find it in java.lang first static McHashTable<const char *, int> *jlang = NULL; if(!jlang) { // We have to initialize a hash that contains java.lang classes. jlang = new McHashTable<const char *, int>(CLASS_SEC); // The names were taken from Java 1.3. (Feb 2000) // Interfaces jlang->insert("Cloneable", INTERFACE_SEC); jlang->insert("Comparable", INTERFACE_SEC); jlang->insert("Runnable", INTERFACE_SEC); // Classes // Final classes (String) are not required here. // Character.Subset and Character.UnicodeBlock omitted. jlang->insert("ClassLoader"); jlang->insert("InheritableThreadLocal"); jlang->insert("Number"); jlang->insert("Object"); jlang->insert("Package"); jlang->insert("Process"); jlang->insert("Runtime"); jlang->insert("SecurityManager"); jlang->insert("Thread"); jlang->insert("ThreadGroup"); jlang->insert("ThreadLocal"); jlang->insert("Throwable"); // Exceptions jlang->insert("ArithmeticException"); jlang->insert("ArrayIndexOutOfBoundsException"); jlang->insert("ArrayStoreException"); jlang->insert("ClassCastException"); jlang->insert("ClassNotFoundException"); jlang->insert("CloneNotSupportedException"); jlang->insert("Exception"); jlang->insert("IllegalAccessException"); jlang->insert("IllegalArgumentException"); jlang->insert("IllegalMonitorStateException"); jlang->insert("IllegalStateException");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -