diff -r 000000000000 -r 42188c7ea2d9 Orb/Doxygen/src/marshal.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Orb/Doxygen/src/marshal.cpp Thu Jan 21 17:29:01 2010 +0000 @@ -0,0 +1,826 @@ +#include +#include + +#include "sortdict.h" +#include "marshal.h" +#include "entry.h" +#include "section.h" +#include "memberlist.h" +#include "definition.h" +#include "groupdef.h" +#include "example.h" + +#define HEADER ('D'<<24)+('O'<<16)+('X'<<8)+'!' + +void marshalInt(StorageIntf *s,int v) +{ + uchar b[4]; + b[0]=((uint)v)>>24; + b[1]=(((uint)v)>>16)&0xff; + b[2]=(((uint)v)>>8)&0xff; + b[3]=v&0xff; + s->write((const char *)b,4); +} + +void marshalUInt(StorageIntf *s,uint v) +{ + uchar b[4]; + b[0]=v>>24; + b[1]=(v>>16)&0xff; + b[2]=(v>>8)&0xff; + b[3]=v&0xff; + s->write((const char *)b,4); +} + +void marshalBool(StorageIntf *s,bool b) +{ + char c = b; + s->write(&c,sizeof(char)); +} + +void marshalQCString(StorageIntf *s,const QCString &str) +{ + uint l=str.length(); + marshalUInt(s,l); + if (l>0) s->write(str.data(),l); +} + +void marshalQGString(StorageIntf *s,const QGString &str) +{ + uint l=str.length(); + marshalUInt(s,l); + if (l>0) s->write(str.data(),l); +} + +void marshalArgumentList(StorageIntf *s,ArgumentList *argList) +{ + if (argList==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,argList->count()); + if (argList->count()>0) + { + ArgumentListIterator ali(*argList); + Argument *a; + for (ali.toFirst();(a=ali.current());++ali) + { + marshalQCString(s,a->attrib); + marshalQCString(s,a->type); + marshalQCString(s,a->canType); + marshalQCString(s,a->name); + marshalQCString(s,a->array); + marshalQCString(s,a->defval); + marshalQCString(s,a->docs); + } + } + marshalBool(s,argList->constSpecifier); + marshalBool(s,argList->volatileSpecifier); + marshalBool(s,argList->pureSpecifier); + } +} + +void marshalArgumentLists(StorageIntf *s,QList *argLists) +{ + if (argLists==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,argLists->count()); + QListIterator ali(*argLists); + ArgumentList *al; + for (ali.toFirst();(al=ali.current());++ali) + { + marshalArgumentList(s,al); + } + } +} + +void marshalBaseInfoList(StorageIntf *s, QList *baseList) +{ + if (baseList==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,baseList->count()); + QListIterator bli(*baseList); + BaseInfo *bi; + for (bli.toFirst();(bi=bli.current());++bli) + { + marshalQCString(s,bi->name); + marshalInt(s,(int)bi->prot); + marshalInt(s,(int)bi->virt); + } + } +} + +void marshalGroupingList(StorageIntf *s, QList *groups) +{ + if (groups==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,groups->count()); + QListIterator gli(*groups); + Grouping *g; + for (gli.toFirst();(g=gli.current());++gli) + { + marshalQCString(s,g->groupname); + marshalInt(s,(int)g->pri); + } + } +} + +void marshalSectionInfoList(StorageIntf *s, QList *anchors) +{ + if (anchors==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,anchors->count()); + QListIterator sli(*anchors); + SectionInfo *si; + for (sli.toFirst();(si=sli.current());++sli) + { + marshalQCString(s,si->label); + marshalQCString(s,si->title); + marshalQCString(s,si->ref); + marshalInt(s,(int)si->type); + marshalQCString(s,si->fileName); + } + } +} + +void marshalItemInfoList(StorageIntf *s, QList *sli) +{ + if (sli==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,sli->count()); + QListIterator liii(*sli); + ListItemInfo *lii; + for (liii.toFirst();(lii=liii.current());++liii) + { + marshalQCString(s,lii->type); + marshalInt(s,lii->itemId); + } + } +} + +void marshalObjPointer(StorageIntf *s,void *obj) +{ + char *b = (char *)&obj; + s->write(b,sizeof(void *)); +} + +void marshalSectionDict(StorageIntf *s,SectionDict *sections) +{ + if (sections==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,sections->count()); + QDictIterator sli(*sections); + SectionInfo *si; + for (sli.toFirst();(si=sli.current());++sli) + { + marshalQCString(s,sli.currentKey()); + marshalObjPointer(s,si); + } + } +} + +void marshalMemberSDict(StorageIntf *s,MemberSDict *memberSDict) +{ + if (memberSDict==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,memberSDict->count()); + //printf(" marshalMemberSDict: items=%d\n",memberSDict->count()); + SDict::IteratorDict mdi(*memberSDict); + MemberDef *md; + int count=0; + for (mdi.toFirst();(md=mdi.current());++mdi) + { + //printf(" marshalMemberSDict: %d: key=%s value=%p\n",count,mdi.currentKey().data(),md); + marshalQCString(s,mdi.currentKey()); + marshalObjPointer(s,md); + count++; + } + assert(count==memberSDict->count()); + } +} + +void marshalDocInfo(StorageIntf *s,DocInfo *docInfo) +{ + if (docInfo==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,1); + marshalQCString(s,docInfo->doc); + marshalInt(s,docInfo->line); + marshalQCString(s,docInfo->file); + } +} + +void marshalBriefInfo(StorageIntf *s,BriefInfo *briefInfo) +{ + if (briefInfo==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,1); + marshalQCString(s,briefInfo->doc); + marshalQCString(s,briefInfo->tooltip); + marshalInt(s,briefInfo->line); + marshalQCString(s,briefInfo->file); + } +} + +void marshalBodyInfo(StorageIntf *s,BodyInfo *bodyInfo) +{ + if (bodyInfo==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,1); + marshalInt(s,bodyInfo->startLine); + marshalInt(s,bodyInfo->endLine); + marshalObjPointer(s,bodyInfo->fileDef); + } +} + +void marshalGroupList(StorageIntf *s,GroupList *groupList) +{ + if (groupList==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,groupList->count()); + QListIterator gli(*groupList); + GroupDef *gd=0; + for (gli.toFirst();(gd=gli.current());++gli) + { + marshalObjPointer(s,gd); + } + } +} + +void marshalMemberList(StorageIntf *s,MemberList *ml) +{ + if (ml==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,ml->count()); + MemberListIterator mli(*ml); + MemberDef *md; + uint count=0; + for (mli.toFirst();(md=mli.current());++mli) + { + marshalObjPointer(s,md); + count++; + } + assert(count==ml->count()); + + ml->marshal(s); + } +} + +void marshalExampleSDict(StorageIntf *s,ExampleSDict *ed) +{ + if (ed==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,ed->count()); + //printf(" marshalMemberSDict: items=%d\n",memberSDict->count()); + SDict::IteratorDict edi(*ed); + Example *e; + for (edi.toFirst();(e=edi.current());++edi) + { + //printf(" marshalMemberSDict: %d: key=%s value=%p\n",count,mdi.currentKey().data(),md); + marshalQCString(s,edi.currentKey()); + marshalQCString(s,e->anchor); + marshalQCString(s,e->name); + marshalQCString(s,e->file); + } + } +} + +void marshalMemberLists(StorageIntf *s,SDict *mls) +{ + if (mls==0) + { + marshalUInt(s,NULL_LIST); // null pointer representation + } + else + { + marshalUInt(s,mls->count()); + //printf(" marshalMemberSDict: items=%d\n",memberSDict->count()); + SDict::IteratorDict mli(*mls); + MemberList *ml; + for (mli.toFirst();(ml=mli.current());++mli) + { + //printf(" marshalMemberSDict: %d: key=%s value=%p\n",count,mdi.currentKey().data(),md); + marshalQCString(s,mli.currentKey()); + marshalObjPointer(s,ml); // assume we are not owner of the list + } + } +} + +void marshalEntry(StorageIntf *s,Entry *e) +{ + marshalUInt(s,HEADER); + marshalQCString(s,e->name); + marshalQCString(s,e->type); + marshalInt(s,e->section); + marshalInt(s,(int)e->protection); + marshalInt(s,(int)e->mtype); + marshalInt(s,e->spec); + marshalInt(s,e->initLines); + marshalBool(s,e->stat); + marshalBool(s,e->explicitExternal); + marshalBool(s,e->proto); + marshalBool(s,e->subGrouping); + marshalBool(s,e->callGraph); + marshalBool(s,e->callerGraph); + marshalInt(s,(int)e->virt); + marshalQCString(s,e->args); + marshalQCString(s,e->bitfields); + marshalArgumentList(s,e->argList); + marshalArgumentLists(s,e->tArgLists); + marshalQGString(s,e->program); + marshalQGString(s,e->initializer); + marshalQCString(s,e->includeFile); + marshalQCString(s,e->includeName); + marshalQCString(s,e->doc); + marshalInt(s,e->docLine); + marshalQCString(s,e->docFile); + marshalQCString(s,e->brief); + marshalInt(s,e->briefLine); + marshalQCString(s,e->briefFile); + marshalQCString(s,e->inbodyDocs); + marshalInt(s,e->inbodyLine); + marshalQCString(s,e->inbodyFile); + marshalQCString(s,e->relates); + marshalInt(s,e->relatesType); + marshalQCString(s,e->read); + marshalQCString(s,e->write); + marshalQCString(s,e->inside); + marshalQCString(s,e->exception); + marshalArgumentList(s,e->typeConstr); + marshalInt(s,e->bodyLine); + marshalInt(s,e->endBodyLine); + marshalInt(s,e->mGrpId); + marshalBaseInfoList(s,e->extends); + marshalGroupingList(s,e->groups); + marshalSectionInfoList(s,e->anchors); + marshalQCString(s,e->fileName); + marshalInt(s,e->startLine); + marshalItemInfoList(s,e->sli); + marshalBool(s,e->objc); + marshalBool(s,e->hidden); + marshalBool(s,e->artificial); + marshalInt(s,(int)e->groupDocType); +} + +void marshalEntryTree(StorageIntf *s,Entry *e) +{ + marshalEntry(s,e); + marshalUInt(s,e->children()->count()); + QListIterator eli(*e->children()); + Entry *child; + for (eli.toFirst();(child=eli.current());++eli) + { + marshalEntryTree(s,child); + } +} + +//------------------------------------------------------------------ + +int unmarshalInt(StorageIntf *s) +{ + uchar b[4]; + s->read((char *)b,4); + int result=(int)((((uint)b[0])<<24)+((uint)b[1]<<16)+((uint)b[2]<<8)+(uint)b[3]); + //printf("unmarshalInt: %x %x %x %x: %x offset=%llx\n",b[0],b[1],b[2],b[3],result,f.pos()); + return result; +} + +uint unmarshalUInt(StorageIntf *s) +{ + uchar b[4]; + s->read((char *)b,4); + uint result=(((uint)b[0])<<24)+((uint)b[1]<<16)+((uint)b[2]<<8)+(uint)b[3]; + //printf("unmarshalUInt: %x %x %x %x: %x offset=%llx\n",b[0],b[1],b[2],b[3],result,f.pos()); + return result; +} + +bool unmarshalBool(StorageIntf *s) +{ + char result; + s->read(&result,sizeof(result)); + //printf("unmarshalBool: %x offset=%llx\n",result,f.pos()); + return result; +} + +QCString unmarshalQCString(StorageIntf *s) +{ + uint len = unmarshalUInt(s); + //printf("unmarshalQCString: len=%d offset=%llx\n",len,f.pos()); + QCString result(len+1); + result.at(len)='\0'; + if (len>0) + { + s->read(result.data(),len); + } + //printf("unmarshalQCString: result=%s\n",result.data()); + return result; +} + +QGString unmarshalQGString(StorageIntf *s) +{ + uint len = unmarshalUInt(s); + //printf("unmarshalQCString: len=%d offset=%llx\n",len,f.pos()); + QGString result(len+1); + result.at(len)='\0'; + if (len>0) + { + s->read(result.data(),len); + } + //printf("unmarshalQCString: result=%s\n",result.data()); + return result; +} + +ArgumentList *unmarshalArgumentList(StorageIntf *s) +{ + uint i; + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; // null list + ArgumentList *result = new ArgumentList; + assert(count<1000000); + //printf("unmarshalArgumentList: %d\n",count); + for (i=0;iattrib = unmarshalQCString(s); + a->type = unmarshalQCString(s); + a->canType = unmarshalQCString(s); + a->name = unmarshalQCString(s); + a->array = unmarshalQCString(s); + a->defval = unmarshalQCString(s); + a->docs = unmarshalQCString(s); + result->append(a); + } + result->constSpecifier = unmarshalBool(s); + result->volatileSpecifier = unmarshalBool(s); + result->pureSpecifier = unmarshalBool(s); + return result; +} + +QList *unmarshalArgumentLists(StorageIntf *s) +{ + uint i; + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; // null list + QList *result = new QList; + result->setAutoDelete(TRUE); + assert(count<1000000); + //printf("unmarshalArgumentLists: %d\n",count); + for (i=0;iappend(unmarshalArgumentList(s)); + } + return result; +} + +QList *unmarshalBaseInfoList(StorageIntf *s) +{ + uint i; + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; // null list + QList *result = new QList; + result->setAutoDelete(TRUE); + assert(count<1000000); + for (i=0;iappend(new BaseInfo(name,prot,virt)); + } + return result; +} + +QList *unmarshalGroupingList(StorageIntf *s) +{ + uint i; + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; // null list + QList *result = new QList; + result->setAutoDelete(TRUE); + assert(count<1000000); + for (i=0;iappend(new Grouping(name,prio)); + } + return result; +} + +QList *unmarshalSectionInfoList(StorageIntf *s) +{ + uint i; + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; // null list + QList *result = new QList; + result->setAutoDelete(TRUE); + assert(count<1000000); + for (i=0;iappend(new SectionInfo(fileName,label,title,type,ref)); + } + return result; +} + +QList *unmarshalItemInfoList(StorageIntf *s) +{ + uint i; + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; // null list + QList *result = new QList; + result->setAutoDelete(TRUE); + assert(count<1000000); + for (i=0;itype = unmarshalQCString(s); + lii->itemId = unmarshalInt(s); + result->append(lii); + } + return result; +} + +void *unmarshalObjPointer(StorageIntf *s) +{ + void *result; + s->read((char *)&result,sizeof(void*)); + return result; +} + +SectionDict *unmarshalSectionDict(StorageIntf *s) +{ + uint i; + uint count = unmarshalUInt(s); + //printf("unmarshalSectionDict count=%d\n",count); + if (count==NULL_LIST) return 0; // null list + SectionDict *result = new SectionDict(17); + assert(count<1000000); + for (i=0;ilabel.data()); + result->insert(key,si); + } + return result; +} + +MemberSDict *unmarshalMemberSDict(StorageIntf *s) +{ + uint i; + uint count = unmarshalUInt(s); + //printf("--- unmarshalMemberSDict count=%d\n",count); + if (count==NULL_LIST) + { + //printf("--- end unmarshalMemberSDict\n"); + return 0; // null list + } + MemberSDict *result = new MemberSDict; + assert(count<1000000); + //printf("Reading %d key-value pairs\n",count); + for (i=0;iinSort(key,md); // note: this can lead to unmarshalling another object! + } + //printf("--- end unmarshalMemberSDict\n"); + return result; +} + +DocInfo *unmarshalDocInfo(StorageIntf *s) +{ + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; + DocInfo *result = new DocInfo; + result->doc = unmarshalQCString(s); + result->line = unmarshalInt(s); + result->file = unmarshalQCString(s); + return result; +} + +BriefInfo *unmarshalBriefInfo(StorageIntf *s) +{ + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; + BriefInfo *result = new BriefInfo; + result->doc = unmarshalQCString(s); + result->tooltip = unmarshalQCString(s); + result->line = unmarshalInt(s); + result->file = unmarshalQCString(s); + return result; +} + +BodyInfo *unmarshalBodyInfo(StorageIntf *s) +{ + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; + BodyInfo *result = new BodyInfo; + result->startLine = unmarshalInt(s); + result->endLine = unmarshalInt(s); + result->fileDef = (FileDef*)unmarshalObjPointer(s); + return result; +} + +GroupList *unmarshalGroupList(StorageIntf *s) +{ + uint i; + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; // null list + assert(count<1000000); + GroupList *result = new GroupList; + for (i=0;iappend(gd); + } + return result; +} + +MemberList *unmarshalMemberList(StorageIntf *s) +{ + uint i; + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; + MemberList *result = new MemberList; + assert(count<1000000); + for (i=0;iappend(md); + } + result->unmarshal(s); + return result; +} + +ExampleSDict *unmarshalExampleSDict(StorageIntf *s) +{ + uint i; + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; + ExampleSDict *result = new ExampleSDict; + assert(count<1000000); + for (i=0;ianchor = unmarshalQCString(s); + e->name = unmarshalQCString(s); + e->file = unmarshalQCString(s); + result->inSort(key,e); + } + return result; +} + +SDict *unmarshalMemberLists(StorageIntf *s) +{ + uint i; + uint count = unmarshalUInt(s); + if (count==NULL_LIST) return 0; + SDict *result = new SDict(7); + assert(count<1000000); + for (i=0;iappend(key,ml); + } + return result; +} + +Entry * unmarshalEntry(StorageIntf *s) +{ + Entry *e = new Entry; + uint header=unmarshalUInt(s); + ASSERT(header==HEADER); + e->name = unmarshalQCString(s); + e->type = unmarshalQCString(s); + e->section = unmarshalInt(s); + e->protection = (Protection)unmarshalInt(s); + e->mtype = (MethodTypes)unmarshalInt(s); + e->spec = unmarshalInt(s); + e->initLines = unmarshalInt(s); + e->stat = unmarshalBool(s); + e->explicitExternal = unmarshalBool(s); + e->proto = unmarshalBool(s); + e->subGrouping = unmarshalBool(s); + e->callGraph = unmarshalBool(s); + e->callerGraph = unmarshalBool(s); + e->virt = (Specifier)unmarshalInt(s); + e->args = unmarshalQCString(s); + e->bitfields = unmarshalQCString(s); + delete e->argList; + e->argList = unmarshalArgumentList(s); + e->tArgLists = unmarshalArgumentLists(s); + e->program = unmarshalQGString(s); + e->initializer = unmarshalQGString(s); + e->includeFile = unmarshalQCString(s); + e->includeName = unmarshalQCString(s); + e->doc = unmarshalQCString(s); + e->docLine = unmarshalInt(s); + e->docFile = unmarshalQCString(s); + e->brief = unmarshalQCString(s); + e->briefLine = unmarshalInt(s); + e->briefFile = unmarshalQCString(s); + e->inbodyDocs = unmarshalQCString(s); + e->inbodyLine = unmarshalInt(s); + e->inbodyFile = unmarshalQCString(s); + e->relates = unmarshalQCString(s); + e->relatesType = (RelatesType)unmarshalInt(s); + e->read = unmarshalQCString(s); + e->write = unmarshalQCString(s); + e->inside = unmarshalQCString(s); + e->exception = unmarshalQCString(s); + e->typeConstr = unmarshalArgumentList(s); + e->bodyLine = unmarshalInt(s); + e->endBodyLine = unmarshalInt(s); + e->mGrpId = unmarshalInt(s); + delete e->extends; + e->extends = unmarshalBaseInfoList(s); + delete e->groups; + e->groups = unmarshalGroupingList(s); + delete e->anchors; + e->anchors = unmarshalSectionInfoList(s); + e->fileName = unmarshalQCString(s); + e->startLine = unmarshalInt(s); + e->sli = unmarshalItemInfoList(s); + e->objc = unmarshalBool(s); + e->hidden = unmarshalBool(s); + e->artificial = unmarshalBool(s); + e->groupDocType = (Entry::GroupDocType)unmarshalInt(s); + return e; +} + +Entry * unmarshalEntryTree(StorageIntf *s) +{ + Entry *e = unmarshalEntry(s); + uint count = unmarshalUInt(s); + uint i; + for (i=0;iaddSubEntry(unmarshalEntryTree(s)); + } + return e; +}