8 #include "memberlist.h"
9 #include "definition.h"
12 #include "arguments.h"
15 #define HEADER ('D'<<24)+('O'<<16)+('X'<<8)+'!'
17 void marshalInt(StorageIntf *s,int v)
21 b[1]=(((uint)v)>>16)&0xff;
22 b[2]=(((uint)v)>>8)&0xff;
24 s->write((const char *)b,4);
27 void marshalUInt(StorageIntf *s,uint v)
34 s->write((const char *)b,4);
37 void marshalUInt64(StorageIntf *s,uint64 v)
39 marshalUInt(s, uint(v>>32));
40 marshalUInt(s, uint(v&0xFFFFFFFF));
43 void marshalBool(StorageIntf *s,bool b)
46 s->write(&c,sizeof(char));
49 void marshalQCString(StorageIntf *s,const QCString &str)
53 if (l>0) s->write(str.data(),l);
56 void marshalQGString(StorageIntf *s,const QGString &str)
60 if (l>0) s->write(str.data(),l);
63 void marshalArgumentList(StorageIntf *s,ArgumentList *argList)
65 ArgumentList::marshal(s,argList);
68 void marshalArgumentLists(StorageIntf *s,QList<ArgumentList> *argLists)
72 marshalUInt(s,NULL_LIST); // null pointer representation
76 marshalUInt(s,argLists->count());
77 QListIterator<ArgumentList> ali(*argLists);
79 for (ali.toFirst();(al=ali.current());++ali)
81 marshalArgumentList(s,al);
86 void marshalBaseInfoList(StorageIntf *s, QList<BaseInfo> *baseList)
90 marshalUInt(s,NULL_LIST); // null pointer representation
94 marshalUInt(s,baseList->count());
95 QListIterator<BaseInfo> bli(*baseList);
97 for (bli.toFirst();(bi=bli.current());++bli)
99 marshalQCString(s,bi->name);
100 marshalInt(s,(int)bi->prot);
101 marshalInt(s,(int)bi->virt);
106 void marshalGroupingList(StorageIntf *s, QList<Grouping> *groups)
110 marshalUInt(s,NULL_LIST); // null pointer representation
114 marshalUInt(s,groups->count());
115 QListIterator<Grouping> gli(*groups);
117 for (gli.toFirst();(g=gli.current());++gli)
119 marshalQCString(s,g->groupname);
120 marshalInt(s,(int)g->pri);
125 void marshalSectionInfoList(StorageIntf *s, QList<SectionInfo> *anchors)
129 marshalUInt(s,NULL_LIST); // null pointer representation
133 marshalUInt(s,anchors->count());
134 QListIterator<SectionInfo> sli(*anchors);
136 for (sli.toFirst();(si=sli.current());++sli)
138 marshalQCString(s,si->label);
139 marshalQCString(s,si->title);
140 marshalQCString(s,si->ref);
141 marshalInt(s,(int)si->type);
142 marshalQCString(s,si->fileName);
143 marshalInt(s,si->lineNr);
144 marshalInt(s,si->level);
150 void marshalItemInfoList(StorageIntf *s, QList<ListItemInfo> *sli)
154 marshalUInt(s,NULL_LIST); // null pointer representation
158 marshalUInt(s,sli->count());
159 QListIterator<ListItemInfo> liii(*sli);
161 for (liii.toFirst();(lii=liii.current());++liii)
163 marshalQCString(s,lii->type);
164 marshalInt(s,lii->itemId);
169 void marshalObjPointer(StorageIntf *s,void *obj)
171 char *b = (char *)&obj;
172 s->write(b,sizeof(void *));
175 void marshalSectionDict(StorageIntf *s,SectionDict *sections)
179 marshalUInt(s,NULL_LIST); // null pointer representation
183 marshalUInt(s,sections->count());
184 SDict<SectionInfo>::IteratorDict sli(*sections);
186 for (sli.toFirst();(si=sli.current());++sli)
188 marshalQCString(s,sli.currentKey());
189 marshalObjPointer(s,si);
194 void marshalMemberSDict(StorageIntf *s,MemberSDict *memberSDict)
198 marshalUInt(s,NULL_LIST); // null pointer representation
202 marshalUInt(s,memberSDict->count());
203 //printf(" marshalMemberSDict: items=%d\n",memberSDict->count());
204 SDict<MemberDef>::IteratorDict mdi(*memberSDict);
207 for (mdi.toFirst();(md=mdi.current());++mdi)
209 //printf(" marshalMemberSDict: %d: key=%s value=%p\n",count,mdi.currentKey().data(),md);
210 marshalQCString(s,mdi.currentKey());
211 marshalObjPointer(s,md);
214 assert(count==memberSDict->count());
218 void marshalDocInfo(StorageIntf *s,DocInfo *docInfo)
222 marshalUInt(s,NULL_LIST); // null pointer representation
227 marshalQCString(s,docInfo->doc);
228 marshalInt(s,docInfo->line);
229 marshalQCString(s,docInfo->file);
233 void marshalBriefInfo(StorageIntf *s,BriefInfo *briefInfo)
237 marshalUInt(s,NULL_LIST); // null pointer representation
242 marshalQCString(s,briefInfo->doc);
243 marshalQCString(s,briefInfo->tooltip);
244 marshalInt(s,briefInfo->line);
245 marshalQCString(s,briefInfo->file);
249 void marshalBodyInfo(StorageIntf *s,BodyInfo *bodyInfo)
253 marshalUInt(s,NULL_LIST); // null pointer representation
258 marshalInt(s,bodyInfo->startLine);
259 marshalInt(s,bodyInfo->endLine);
260 marshalObjPointer(s,bodyInfo->fileDef);
264 void marshalGroupList(StorageIntf *s,GroupList *groupList)
268 marshalUInt(s,NULL_LIST); // null pointer representation
272 marshalUInt(s,groupList->count());
273 QListIterator<GroupDef> gli(*groupList);
275 for (gli.toFirst();(gd=gli.current());++gli)
277 marshalObjPointer(s,gd);
282 void marshalMemberList(StorageIntf *s,MemberList *ml)
286 marshalUInt(s,NULL_LIST); // null pointer representation
290 marshalUInt(s,ml->count());
291 MemberListIterator mli(*ml);
294 for (mli.toFirst();(md=mli.current());++mli)
296 marshalObjPointer(s,md);
299 assert(count==ml->count());
305 void marshalExampleSDict(StorageIntf *s,ExampleSDict *ed)
309 marshalUInt(s,NULL_LIST); // null pointer representation
313 marshalUInt(s,ed->count());
314 //printf(" marshalMemberSDict: items=%d\n",memberSDict->count());
315 SDict<Example>::IteratorDict edi(*ed);
317 for (edi.toFirst();(e=edi.current());++edi)
319 //printf(" marshalMemberSDict: %d: key=%s value=%p\n",count,mdi.currentKey().data(),md);
320 marshalQCString(s,edi.currentKey());
321 marshalQCString(s,e->anchor);
322 marshalQCString(s,e->name);
323 marshalQCString(s,e->file);
328 void marshalMemberLists(StorageIntf *s,SDict<MemberList> *mls)
332 marshalUInt(s,NULL_LIST); // null pointer representation
336 marshalUInt(s,mls->count());
337 //printf(" marshalMemberSDict: items=%d\n",memberSDict->count());
338 SDict<MemberList>::IteratorDict mli(*mls);
340 for (mli.toFirst();(ml=mli.current());++mli)
342 //printf(" marshalMemberSDict: %d: key=%s value=%p\n",count,mdi.currentKey().data(),md);
343 marshalQCString(s,mli.currentKey());
344 marshalObjPointer(s,ml); // assume we are not owner of the list
349 void marshalLocalToc(StorageIntf *s,const LocalToc <)
351 marshalInt(s,lt.mask());
352 marshalInt(s,lt.htmlLevel());
353 marshalInt(s,lt.latexLevel());
354 marshalInt(s,lt.xmlLevel());
355 marshalInt(s,lt.docbookLevel());
358 void marshalEntry(StorageIntf *s,Entry *e)
360 marshalUInt(s,HEADER);
361 marshalQCString(s,e->name);
362 marshalQCString(s,e->type);
363 marshalInt(s,e->section);
364 marshalInt(s,(int)e->protection);
365 marshalInt(s,(int)e->mtype);
366 marshalUInt64(s,e->spec);
367 marshalInt(s,e->initLines);
368 marshalBool(s,e->stat);
369 marshalLocalToc(s,e->localToc);
370 marshalBool(s,e->explicitExternal);
371 marshalBool(s,e->proto);
372 marshalBool(s,e->subGrouping);
373 marshalBool(s,e->callGraph);
374 marshalBool(s,e->callerGraph);
375 marshalBool(s,e->referencedByRelation);
376 marshalBool(s,e->referencesRelation);
377 marshalInt(s,(int)e->virt);
378 marshalQCString(s,e->args);
379 marshalQCString(s,e->bitfields);
380 marshalArgumentList(s,e->argList);
381 marshalArgumentLists(s,e->tArgLists);
382 marshalQGString(s,e->program);
383 marshalQGString(s,e->initializer);
384 marshalQCString(s,e->includeFile);
385 marshalQCString(s,e->includeName);
386 marshalQCString(s,e->doc);
387 marshalInt(s,e->docLine);
388 marshalQCString(s,e->docFile);
389 marshalQCString(s,e->brief);
390 marshalInt(s,e->briefLine);
391 marshalQCString(s,e->briefFile);
392 marshalQCString(s,e->inbodyDocs);
393 marshalInt(s,e->inbodyLine);
394 marshalQCString(s,e->inbodyFile);
395 marshalQCString(s,e->relates);
396 marshalInt(s,e->relatesType);
397 marshalQCString(s,e->read);
398 marshalQCString(s,e->write);
399 marshalQCString(s,e->inside);
400 marshalQCString(s,e->exception);
401 marshalArgumentList(s,e->typeConstr);
402 marshalInt(s,e->bodyLine);
403 marshalInt(s,e->endBodyLine);
404 marshalInt(s,e->mGrpId);
405 marshalBaseInfoList(s,e->extends);
406 marshalGroupingList(s,e->groups);
407 marshalSectionInfoList(s,e->anchors);
408 marshalQCString(s,e->fileName);
409 marshalInt(s,e->startLine);
410 marshalItemInfoList(s,e->sli);
411 marshalInt(s,(int)e->lang);
412 marshalBool(s,e->hidden);
413 marshalBool(s,e->artificial);
414 marshalInt(s,(int)e->groupDocType);
415 marshalQCString(s,e->id);
416 marshalQCString(s,e->metaData);
419 void marshalEntryTree(StorageIntf *s,Entry *e)
422 marshalUInt(s,e->children()->count());
423 QListIterator<Entry> eli(*e->children());
425 for (eli.toFirst();(child=eli.current());++eli)
427 marshalEntryTree(s,child);
431 //------------------------------------------------------------------
433 int unmarshalInt(StorageIntf *s)
436 s->read((char *)b,4);
437 int result=(int)((((uint)b[0])<<24)+((uint)b[1]<<16)+((uint)b[2]<<8)+(uint)b[3]);
438 //printf("unmarshalInt: %x %x %x %x: %x offset=%llx\n",b[0],b[1],b[2],b[3],result,f.pos());
442 uint unmarshalUInt(StorageIntf *s)
445 s->read((char *)b,4);
446 uint result=(((uint)b[0])<<24)+((uint)b[1]<<16)+((uint)b[2]<<8)+(uint)b[3];
447 //printf("unmarshalUInt: %x %x %x %x: %x offset=%llx\n",b[0],b[1],b[2],b[3],result,f.pos());
451 uint64 unmarshalUInt64(StorageIntf *s)
453 uint64 result=uint64(unmarshalUInt(s))<<32;
454 result|=unmarshalUInt(s);
458 bool unmarshalBool(StorageIntf *s)
461 s->read(&result,sizeof(result));
462 //printf("unmarshalBool: %x offset=%llx\n",result,f.pos());
466 QCString unmarshalQCString(StorageIntf *s)
468 uint len = unmarshalUInt(s);
469 //printf("unmarshalQCString: len=%d offset=%llx\n",len,f.pos());
470 QCString result(len+1);
474 s->read(result.rawData(),len);
476 //printf("unmarshalQCString: result=%s\n",result.data());
480 QGString unmarshalQGString(StorageIntf *s)
482 uint len = unmarshalUInt(s);
483 //printf("unmarshalQCString: len=%d offset=%llx\n",len,f.pos());
484 QGString result(len+1);
488 s->read(result.data(),len);
490 //printf("unmarshalQCString: result=%s\n",result.data());
494 ArgumentList *unmarshalArgumentList(StorageIntf *s)
496 return ArgumentList::unmarshal(s);
499 QList<ArgumentList> *unmarshalArgumentLists(StorageIntf *s)
502 uint count = unmarshalUInt(s);
503 if (count==NULL_LIST) return 0; // null list
504 QList<ArgumentList> *result = new QList<ArgumentList>;
505 result->setAutoDelete(TRUE);
506 assert(count<1000000);
507 //printf("unmarshalArgumentLists: %d\n",count);
508 for (i=0;i<count;i++)
510 result->append(unmarshalArgumentList(s));
515 QList<BaseInfo> *unmarshalBaseInfoList(StorageIntf *s)
518 uint count = unmarshalUInt(s);
519 if (count==NULL_LIST) return 0; // null list
520 QList<BaseInfo> *result = new QList<BaseInfo>;
521 result->setAutoDelete(TRUE);
522 assert(count<1000000);
523 for (i=0;i<count;i++)
525 QCString name = unmarshalQCString(s);
526 Protection prot = (Protection)unmarshalInt(s);
527 Specifier virt = (Specifier)unmarshalInt(s);
528 result->append(new BaseInfo(name,prot,virt));
533 QList<Grouping> *unmarshalGroupingList(StorageIntf *s)
536 uint count = unmarshalUInt(s);
537 if (count==NULL_LIST) return 0; // null list
538 QList<Grouping> *result = new QList<Grouping>;
539 result->setAutoDelete(TRUE);
540 assert(count<1000000);
541 for (i=0;i<count;i++)
543 QCString name = unmarshalQCString(s);
544 Grouping::GroupPri_t prio = (Grouping::GroupPri_t)unmarshalInt(s);
545 result->append(new Grouping(name,prio));
550 QList<SectionInfo> *unmarshalSectionInfoList(StorageIntf *s)
553 uint count = unmarshalUInt(s);
554 if (count==NULL_LIST) return 0; // null list
555 QList<SectionInfo> *anchors = new QList<SectionInfo>;
556 assert(count<1000000);
557 for (i=0;i<count;i++)
559 QCString label = unmarshalQCString(s);
560 QCString title = unmarshalQCString(s);
561 QCString ref = unmarshalQCString(s);
562 SectionInfo::SectionType type = (SectionInfo::SectionType)unmarshalInt(s);
563 QCString fileName = unmarshalQCString(s);
564 int lineNr = unmarshalInt(s);
565 int level = unmarshalInt(s);
566 SectionInfo *si = Doxygen::sectionDict->find(label);
567 if (si==0) // This should actually never be true since all anchors should be in sectionDict.
568 // Could still optimize the marshaling routine by only storing label.
570 SectionInfo *si = new SectionInfo(fileName,lineNr,label,title,type,level,ref);
572 Doxygen::sectionDict->append(label,si); // this dict owns the anchor objects
582 QList<ListItemInfo> *unmarshalItemInfoList(StorageIntf *s)
585 uint count = unmarshalUInt(s);
586 if (count==NULL_LIST) return 0; // null list
587 QList<ListItemInfo> *result = new QList<ListItemInfo>;
588 result->setAutoDelete(TRUE);
589 assert(count<1000000);
590 for (i=0;i<count;i++)
592 ListItemInfo *lii = new ListItemInfo;
593 lii->type = unmarshalQCString(s);
594 lii->itemId = unmarshalInt(s);
600 void *unmarshalObjPointer(StorageIntf *s)
603 s->read((char *)&result,sizeof(void*));
607 SectionDict *unmarshalSectionDict(StorageIntf *s)
610 uint count = unmarshalUInt(s);
611 //printf("unmarshalSectionDict count=%d\n",count);
612 if (count==NULL_LIST) return 0; // null list
613 SectionDict *result = new SectionDict(17);
614 assert(count<1000000);
615 for (i=0;i<count;i++)
617 QCString key = unmarshalQCString(s);
618 SectionInfo *si = (SectionInfo *)unmarshalObjPointer(s);
619 //printf(" unmarshalSectionDict i=%d key=%s si=%s\n",count,key.data(),si->label.data());
620 result->append(key,si);
625 MemberSDict *unmarshalMemberSDict(StorageIntf *s)
628 uint count = unmarshalUInt(s);
629 //printf("--- unmarshalMemberSDict count=%d\n",count);
630 if (count==NULL_LIST)
632 //printf("--- end unmarshalMemberSDict\n");
633 return 0; // null list
635 MemberSDict *result = new MemberSDict;
636 assert(count<1000000);
637 //printf("Reading %d key-value pairs\n",count);
638 for (i=0;i<count;i++)
640 //printf(" unmarshaling pair %d\n",i);
641 QCString key = unmarshalQCString(s);
642 //printf(" unmarshaling key %s\n",key.data());
643 MemberDef *md = (MemberDef *)unmarshalObjPointer(s);
644 //printf(" unmarshalMemberSDict i=%d key=%s md=%p\n",i,key.data(),md);
645 result->append(key,md);
648 //printf("--- end unmarshalMemberSDict\n");
652 DocInfo *unmarshalDocInfo(StorageIntf *s)
654 uint count = unmarshalUInt(s);
655 if (count==NULL_LIST) return 0;
656 DocInfo *result = new DocInfo;
657 result->doc = unmarshalQCString(s);
658 result->line = unmarshalInt(s);
659 result->file = unmarshalQCString(s);
663 BriefInfo *unmarshalBriefInfo(StorageIntf *s)
665 uint count = unmarshalUInt(s);
666 if (count==NULL_LIST) return 0;
667 BriefInfo *result = new BriefInfo;
668 result->doc = unmarshalQCString(s);
669 result->tooltip = unmarshalQCString(s);
670 result->line = unmarshalInt(s);
671 result->file = unmarshalQCString(s);
675 BodyInfo *unmarshalBodyInfo(StorageIntf *s)
677 uint count = unmarshalUInt(s);
678 if (count==NULL_LIST) return 0;
679 BodyInfo *result = new BodyInfo;
680 result->startLine = unmarshalInt(s);
681 result->endLine = unmarshalInt(s);
682 result->fileDef = (FileDef*)unmarshalObjPointer(s);
686 GroupList *unmarshalGroupList(StorageIntf *s)
689 uint count = unmarshalUInt(s);
690 if (count==NULL_LIST) return 0; // null list
691 assert(count<1000000);
692 GroupList *result = new GroupList;
693 for (i=0;i<count;i++)
695 GroupDef *gd = (GroupDef *)unmarshalObjPointer(s);
701 MemberList *unmarshalMemberList(StorageIntf *s)
704 uint count = unmarshalUInt(s);
705 if (count==NULL_LIST) return 0;
706 MemberList *result = new MemberList;
707 assert(count<1000000);
708 for (i=0;i<count;i++)
710 MemberDef *md = (MemberDef*)unmarshalObjPointer(s);
713 result->unmarshal(s);
717 ExampleSDict *unmarshalExampleSDict(StorageIntf *s)
720 uint count = unmarshalUInt(s);
721 if (count==NULL_LIST) return 0;
722 ExampleSDict *result = new ExampleSDict;
723 assert(count<1000000);
724 for (i=0;i<count;i++)
726 QCString key = unmarshalQCString(s);
727 Example *e = new Example;
728 e->anchor = unmarshalQCString(s);
729 e->name = unmarshalQCString(s);
730 e->file = unmarshalQCString(s);
731 result->inSort(key,e);
736 SDict<MemberList> *unmarshalMemberLists(StorageIntf *s)
739 uint count = unmarshalUInt(s);
740 if (count==NULL_LIST) return 0;
741 SDict<MemberList> *result = new SDict<MemberList>(7);
742 assert(count<1000000);
743 for (i=0;i<count;i++)
745 QCString key = unmarshalQCString(s);
746 MemberList *ml = (MemberList *)unmarshalObjPointer(s);
747 result->append(key,ml);
752 LocalToc unmarshalLocalToc(StorageIntf *s)
755 int mask = unmarshalInt(s);
756 int htmlLevel = unmarshalInt(s);
757 int latexLevel = unmarshalInt(s);
758 int xmlLevel = unmarshalInt(s);
759 int docbookLevel = unmarshalInt(s);
760 if ((mask & (1<<LocalToc::Html))!=0)
762 result.enableHtml(htmlLevel);
764 if ((mask & (1<<LocalToc::Latex))!=0)
766 result.enableLatex(latexLevel);
768 if ((mask & (1<<LocalToc::Xml))!=0)
770 result.enableXml(xmlLevel);
772 if ((mask & (1<<LocalToc::Docbook))!=0)
774 result.enableDocbook(docbookLevel);
779 Entry * unmarshalEntry(StorageIntf *s)
781 Entry *e = new Entry;
782 uint header=unmarshalUInt(s);
783 ASSERT(header==HEADER);
784 e->name = unmarshalQCString(s);
785 e->type = unmarshalQCString(s);
786 e->section = unmarshalInt(s);
787 e->protection = (Protection)unmarshalInt(s);
788 e->mtype = (MethodTypes)unmarshalInt(s);
789 e->spec = unmarshalUInt64(s);
790 e->initLines = unmarshalInt(s);
791 e->stat = unmarshalBool(s);
792 e->localToc = unmarshalLocalToc(s);
793 e->explicitExternal = unmarshalBool(s);
794 e->proto = unmarshalBool(s);
795 e->subGrouping = unmarshalBool(s);
796 e->callGraph = unmarshalBool(s);
797 e->callerGraph = unmarshalBool(s);
798 e->referencedByRelation = unmarshalBool(s);
799 e->referencesRelation = unmarshalBool(s);
800 e->virt = (Specifier)unmarshalInt(s);
801 e->args = unmarshalQCString(s);
802 e->bitfields = unmarshalQCString(s);
804 e->argList = unmarshalArgumentList(s);
805 e->tArgLists = unmarshalArgumentLists(s);
806 e->program = unmarshalQGString(s);
807 e->initializer = unmarshalQGString(s);
808 e->includeFile = unmarshalQCString(s);
809 e->includeName = unmarshalQCString(s);
810 e->doc = unmarshalQCString(s);
811 e->docLine = unmarshalInt(s);
812 e->docFile = unmarshalQCString(s);
813 e->brief = unmarshalQCString(s);
814 e->briefLine = unmarshalInt(s);
815 e->briefFile = unmarshalQCString(s);
816 e->inbodyDocs = unmarshalQCString(s);
817 e->inbodyLine = unmarshalInt(s);
818 e->inbodyFile = unmarshalQCString(s);
819 e->relates = unmarshalQCString(s);
820 e->relatesType = (RelatesType)unmarshalInt(s);
821 e->read = unmarshalQCString(s);
822 e->write = unmarshalQCString(s);
823 e->inside = unmarshalQCString(s);
824 e->exception = unmarshalQCString(s);
825 e->typeConstr = unmarshalArgumentList(s);
826 e->bodyLine = unmarshalInt(s);
827 e->endBodyLine = unmarshalInt(s);
828 e->mGrpId = unmarshalInt(s);
830 e->extends = unmarshalBaseInfoList(s);
832 e->groups = unmarshalGroupingList(s);
834 e->anchors = unmarshalSectionInfoList(s);
835 e->fileName = unmarshalQCString(s);
836 e->startLine = unmarshalInt(s);
837 e->sli = unmarshalItemInfoList(s);
838 e->lang = (SrcLangExt)unmarshalInt(s);
839 e->hidden = unmarshalBool(s);
840 e->artificial = unmarshalBool(s);
841 e->groupDocType = (Entry::GroupDocType)unmarshalInt(s);
842 e->id = unmarshalQCString(s);
843 e->metaData = unmarshalQCString(s);
847 Entry * unmarshalEntryTree(StorageIntf *s)
849 Entry *e = unmarshalEntry(s);
850 uint count = unmarshalUInt(s);
852 for (i=0;i<count;i++)
854 e->addSubEntry(unmarshalEntryTree(s));