TypePtr HceParse::findUserType(const string &sid) { StructPtr sPtr = findStruct(sid); if(sPtr) return sPtr; return NULL; }
bool Module::addStruct(const Struct &value) { if (findStruct(value.name)) { return false; } structsByName_.insert(fullNameKey(value.name), structs_.size()); structs_.push_back(value); return true; }
void HceParse::checkConflict(const string &sid) { //是否和结构重名 if(findStruct(sid)) { error("conflicts with struct '" + sid + "'"); } }
void dumpStructs(FILE *fp, DNA *dna) { typedef std::list<StructName> StructList; StructList structs; for (int i=0; i<dna->getNumStructs(); i++) { short *sp = dna->getStruct(i); hgString type = dna->getType(sp[0]); int len = sp[1]; sp+=2; size_t max = 0, max2 = 0; bool hasDeps = false; for (short el = 0; el <len; el++, sp+=2) { hgString dt = dna->getType(sp[0]); hgString dn = dna->getName(sp[1]); if (dn[0] != '*' && sp[0] >= dna->getStruct(0)[0]) hasDeps = true; if (max < dt.size()) max = dt.size(); if (max2 < dn.size()) max2 = dn.size(); } StructName sn = {dna, type, findStruct(type.c_str(), dna), hasDeps ? 1 : 0, max, max2}; structs.push_back(sn); } dumpForwards(fp, dna); structs.sort(sortCmp); StructList::iterator it = structs.begin(); int index = 0; while (it != structs.end()) { StructName &sp = (*it); dumpClass(fp, dna, sp.strc, sp.max, sp.max2, index++); ++it; } }
// ---------------------------------------------------------------------------- void dumpClass(FILE *fp, DNA *dna, short *strc, int max0, int max1, int index) { hgString type = dna->getType(strc[0]); short typ = strc[0]; short len = strc[1]; strc+=2; #ifdef _DEBUG char comment[256]; fprintf(fp, "// %i DNA structure %i, %i\n", index, typ, len); #endif fprintf(fp, "struct %s\n{\n", type.c_str()); int padding = 0; for (short el = 0; el <len; el++, strc+=2) { hgString dt = dna->getType(strc[0]); hgString dn = dna->getName(strc[1]); int arrlen = dna->getArraySize(dn.c_str()); char newname[64]; char newtype[64]; if (dn[0] == '*' && strc[0] >= dna->getStruct(0)[0] && !findStruct(dt.c_str(), dna)) { // replace with void ptr sprintf(newtype, "void"); #ifdef _DEBUG sprintf(comment, "// Note: using void* on undefined DNA type: %s", dt.c_str()); #else printf("Note: using void* on undefined DNA type: %s\n", dt.c_str()); #endif } else { sprintf(newtype, "%s", dt.c_str()); #ifdef _DEBUG sprintf(comment, "// %i type, name %i, %i.", el+1, strc[0], strc[1]); #endif } sprintf(newname, "%s", dn.c_str()); #ifdef _DEBUG dt = hgString(newtype); dn = hgString(newname); hgString pad0((max0 - (int)dt.size()) + 4, ' '); hgString pad1((max1 - (int)dn.size()) + 0, ' '); fprintf(fp, " %s%s%s;%s%s\n", newtype, pad0.c_str(), newname, pad1.c_str(), comment); #else fprintf(fp, " %s %s;\n", newtype, newname); #endif } fprintf(fp, "};\n\n"); }