📄 symbol2.c
字号:
fprintf(fd, "\n#ifdef WITH_NOEMPTYSTRUCT\nprivate:\n\tchar dummy;\t/* dummy member to enable compilation */\n#endif"); } fprintf(fd, "\n};"); } else if (!is_transient(typ) && !is_external(typ) && !is_volatile(typ)) { sprintf(errbuf, "struct '%s' is empty", typ->id->name); semwarn(errbuf); } } else if (typ->type == Tclass) { DBGLOG(fprintf(stderr,"\nclass %s\n", typ->id->name)); if (typ->ref) { int permission = -1; fprintf(fd,"class SOAP_CMAC %s", ident(typ->id->name)); if (typ->base) fprintf(fd," : public %s", ident(typ->base->name)); fprintf(fd,"\n{"); for (Eptr = ((Table*)typ->ref)->list; Eptr; Eptr = Eptr->next) { if (permission != (Eptr->info.sto & (Sprivate | Sprotected))) { if (Eptr->info.sto & Sprivate) fprintf(fd, "\nprivate:"); else if (Eptr->info.sto & Sprotected) fprintf(fd, "\nprotected:"); else fprintf(fd, "\npublic:"); permission = (Eptr->info.sto & (Sprivate | Sprotected)); } fprintf(fd,"\n\t%s", c_storage(Eptr->info.sto)); /* if (Eptr->info.typ->type == Tclass && !is_external(Eptr->info.typ) && Eptr->info.typ->generated == False || (Eptr->info.typ->type == Tpointer || Eptr->info.typ->type == Treference) && Eptr->info.typ->ref && ((Tnode*)Eptr->info.typ->ref)->type == Tclass && !is_external(Eptr->info.typ->ref) && ((Tnode*)Eptr->info.typ->ref)->generated == False) fprintf(fd, "class "); */ fprintf(fd,"%s", c_type_id(Eptr->info.typ,Eptr->sym->name)); if (Eptr->info.sto & Sconstobj) fprintf(fd, " const"); if (Eptr->info.sto & Sabstract) fprintf(fd, " = 0;"); else fprintf(fd, ";"); if (Eptr->info.sto & Sreturn) fprintf(fd, "\t/* SOAP 1.2 RPC return element (when namespace qualified) */"); if (is_external(Eptr->info.typ)) fprintf(fd, "\t/* external */"); if (is_transient(Eptr->info.typ)) fprintf(fd, "\t/* transient */"); if (is_imported(Eptr->info.typ)) fprintf(fd, "\t/* type imported from %s */", Eptr->info.typ->imported); if (Eptr->info.sto & Sattribute) { if (Eptr->info.minOccurs >= 1) fprintf(fd, "\t/* required attribute */"); else fprintf(fd, "\t/* optional attribute */"); } if (Eptr->info.sto & (Sconst | Sprivate | Sprotected)) fprintf(fd, "\t/* not serialized */"); else if (Eptr->info.sto & SmustUnderstand) fprintf(fd, "\t/* mustUnderstand */"); else if (!is_dynamic_array(typ) && is_repetition(Eptr)) { if (!is_untyped(Eptr->next->info.typ) && has_ns(Eptr->next->info.typ->ref) && ((is_external(Eptr->next->info.typ->ref) && ((Tnode*)Eptr->next->info.typ->ref)->type == Tclass) || has_external(Eptr->next->info.typ->ref))) { sprintf(errbuf, "Field '%s' must be a pointer to an array of pointers to %s to prevent id-ref copying of %s instances containing an external object (declared at line %d)", Eptr->next->sym->name, c_type(Eptr->next->info.typ->ref), c_type(Eptr->next->info.typ->ref), Eptr->next->lineno); semwarn(errbuf); } else if (!is_untyped(Eptr->next->info.typ) && has_ns(Eptr->next->info.typ->ref) && ((is_volatile(Eptr->next->info.typ->ref) && ((Tnode*)Eptr->next->info.typ->ref)->type == Tclass) || has_volatile(Eptr->next->info.typ->ref))) { sprintf(errbuf, "Field '%s' must be a pointer to an array of pointers to %s to prevent id-ref copying of %s instances containing a volatile object (declared at line %d)", Eptr->next->sym->name, c_type(Eptr->next->info.typ->ref), c_type(Eptr->next->info.typ->ref), Eptr->next->lineno); semwarn(errbuf); } if (Eptr->info.maxOccurs > 1) fprintf(fd, "\t/* sequence of %ld to %ld elements <%s> */", Eptr->info.minOccurs, Eptr->info.maxOccurs, ns_convert(Eptr->next->sym->name)); else fprintf(fd, "\t/* sequence of elements <%s> */", ns_convert(Eptr->next->sym->name)); } else if (is_anytype(Eptr)) fprintf(fd, "\t/* any type of element <%s> (defined below) */", ns_convert(Eptr->next->sym->name)); else if (is_choice(Eptr)) fprintf(fd, "\t/* union discriminant (of union defined below) */"); else if (Eptr->info.typ->type != Tfun && !(Eptr->info.sto & (Sconst | Sprivate | Sprotected)) && !(Eptr->info.sto & Sattribute) && !is_transient(Eptr->info.typ) && !is_external(Eptr->info.typ) && strncmp(Eptr->sym->name, "__", 2)) { if (Eptr->info.maxOccurs > 1) fprintf(fd, "\t/* sequence of %ld to %ld elements */", Eptr->info.minOccurs, Eptr->info.maxOccurs); else if (Eptr->info.minOccurs >= 1) fprintf(fd, "\t/* required element of type %s */", wsdl_type(Eptr->info.typ, "")); else fprintf(fd, "\t/* optional element of type %s */", wsdl_type(Eptr->info.typ, "")); } if (!is_dynamic_array(typ) && !is_primclass(typ)) { if (!strncmp(Eptr->sym->name, "__size", 6)) { if (!Eptr->next || Eptr->next->info.typ->type != Tpointer) { sprintf(errbuf, "Field '%s' is not followed by a pointer field in struct '%s'", Eptr->sym->name, typ->id->name); semwarn(errbuf); } } else if (!strncmp(Eptr->sym->name, "__type", 6)) { if (!Eptr->next || ((Eptr->next->info.typ->type != Tpointer || ((Tnode*)Eptr->next->info.typ->ref)->type != Tvoid))) { sprintf(errbuf, "Field '%s' is not followed by a void pointer or union field in struct '%s'", Eptr->sym->name, typ->id->name); semwarn(errbuf); } } } } if (!is_transient(typ) && !is_volatile(typ)) { fprintf(fd,"\npublic:\n\tvirtual int soap_type() const { return %d; } /* = unique id %s */", typ->num, soap_type(typ)); fprintf(fd,"\n\tvirtual void soap_default(struct soap*);"); fprintf(fd,"\n\tvirtual void soap_serialize(struct soap*) const;"); fprintf(fd,"\n\tvirtual int soap_put(struct soap*, const char*, const char*) const;"); fprintf(fd,"\n\tvirtual int soap_out(struct soap*, const char*, int, const char*) const;"); fprintf(fd,"\n\tvirtual void *soap_get(struct soap*, const char*, const char*);"); fprintf(fd,"\n\tvirtual void *soap_in(struct soap*, const char*, const char*);"); if (!has_constructor(typ)) { Table *t; Entry *p; int c = ':'; fprintf(fd,"\n\t %s() ", ident(typ->id->name)); t = (Table*)typ->ref; if (t) { for (p = t->list; p; p = p->next) { if (!(p->info.sto & Sconst)) { char *val = c_init(p); if (p->info.hasval && *val) { fprintf(fd, "%c %s(%s)", c, ident(p->sym->name), val + 3); c = ','; } else if (p->info.typ->type == Tpointer) { fprintf(fd, "%c %s(NULL)", c, ident(p->sym->name)); c = ','; } else if (is_choice(p)) { fprintf(fd, "%c %s(0)", c, ident(p->sym->name)); c = ','; } else if (p->info.typ->type == Tenum) { fprintf(fd, "%c %s((%s)0)", c, ident(p->sym->name), c_type(p->info.typ)); c = ','; } else if (p->info.typ->type >= Tchar && p->info.typ->type < Tenum) { fprintf(fd, "%c %s(0)", c, ident(p->sym->name)); c = ','; } } } } fprintf(fd," { }"); } if (!has_destructor(typ)) fprintf(fd,"\n\tvirtual ~%s() { }", ident(typ->id->name)); /* the use of 'friend' causes problems linking static functions. Adding these friends could enable serializing protected/private members (which is not implemented) fprintf(fd,"\n\tfriend %s *soap_instantiate_%s(struct soap*, int, const char*, const char*, size_t*);", typ->id->name, typ->id->name); fprintf(fd,"\n\tfriend %s *soap_in_%s(struct soap*, const char*, %s*, const char*);", typ->id->name, typ->id->name, typ->id->name); fprintf(fd,"\n\tfriend int soap_out_%s(struct soap*, const char*, int, const %s*, const char*);", typ->id->name, typ->id->name); */ } else if (!((Table*)typ->ref)->list) fprintf(fd, "\n#ifdef WITH_NOEMPTYSTRUCT\nprivate:\n\tchar dummy;\t/* dummy member to enable compilation */\n#endif"); fprintf(fd,"\n};"); } else if (!is_transient(typ) && !is_external(typ) && !is_volatile(typ)) { sprintf(errbuf, "class '%s' is empty", typ->id->name); semwarn(errbuf); } } else if (typ->type == Tunion) { int i = 1; if (typ->ref) { fprintf(fd, "union %s\n{", ident(typ->id->name)); for (Eptr = ((Table*)typ->ref)->list; Eptr; Eptr = Eptr->next) { fprintf(fd, "\n#define SOAP_UNION_%s_%s\t(%d)", c_ident(typ), ident(Eptr->sym->name), i); i++; fprintf(fd, "\n\t%s", c_storage(Eptr->info.sto)); fprintf(fd, "%s;", c_type_id(Eptr->info.typ,Eptr->sym->name)); if (Eptr->info.sto & (Sconst | Sprivate | Sprotected)) fprintf(fd, "\t/* const field cannot be deserialized */"); if (is_external(Eptr->info.typ)) fprintf(fd, "\t/* external */"); if (is_transient(Eptr->info.typ)) fprintf(fd, "\t/* transient */"); if (Eptr->info.sto & Sattribute) { fprintf(fd, "\t/* attribute not allowed in union */"); sprintf(errbuf, "union '%s' contains attribute declarations", typ->id->name); semwarn(errbuf); } if (Eptr->info.sto & SmustUnderstand) fprintf(fd, "\t/* mustUnderstand */"); } fprintf(fd, "\n};"); } else if (!is_transient(typ) && !is_external(typ) && !is_volatile(typ)) { sprintf(errbuf, "union '%s' is empty", typ->id->name); semwarn(errbuf); } } if (is_volatile(typ)) fprintf(fd, "\n#endif"); if (typ->ref) fprintf(fd, "\n#endif"); fflush(fd);}voidgenerate_header(Table *t){ Entry *p, *q; banner(fheader, "Enumerations"); fflush(fheader); if (enumtable) for (p = enumtable->list; p; p = p->next) { char *x; if (is_imported(p->info.typ) || (is_transient(p->info.typ) && !p->info.typ->ref)) continue; x = xsi_type(p->info.typ); if (!x || !*x) x = wsdl_type(p->info.typ, ""); fprintf(fheader, "\n\n#ifndef %s", soap_type(p->info.typ)); fprintf(fheader, "\n#define %s (%d)",soap_type(p->info.typ),p->info.typ->num); if (is_volatile(p->info.typ)) fprintf(fheader, "\n#if 0 /* volatile type: do not redeclare */"); if (is_mask(p->info.typ)) fprintf(fheader, "\n/* Bitmask %s */", x); else fprintf(fheader, "\n/* %s */", x); fprintf(fheader, "\nenum %s {", ident(p->info.typ->id->name)); if ((Table*)p->info.typ->ref) { q = ((Table*)p->info.typ->ref)->list; if (q) { fprintf(fheader, "%s = "SOAP_LONG_FORMAT, ident(q->sym->name), q->info.val.i); for (q = q->next; q; q = q->next) fprintf(fheader, ", %s = "SOAP_LONG_FORMAT, ident(q->sym->name), q->info.val.i); } } fprintf(fheader, "};\n#endif"); if (is_volatile(p->info.typ)) fprintf(fheader, "\n#endif"); } banner(fheader, "Classes and Structs"); fflush(fheader); /* Obsolete: moved unions in classtable if (uniontable) for (p = uniontable->list; p; p = p->next) if (!is_imported(p->info.typ)) gen_union(fheader, p->info.typ); */ if (classtable) for (p = classtable->list; p; p = p->next) if (!is_imported(p->info.typ)) gen_class(fheader, p->info.typ); banner(fheader, "Types with Custom Serializers"); fflush(fheader); if (typetable) for (p = typetable->list; p; p = p->next) { if (is_external(p->info.typ) && !is_volatile(p->info.typ) && !is_imported(p->info.typ)) { fprintf(fheader, "\n#ifndef %s", soap_type(p->info.typ)); fprintf(fheader, "\n#define %s (%d)",soap_type(p->info.typ),p->info.typ->num); fprintf(fheader, "\n%s%s;", c_storage(p->info.sto), c_type_id(p->info.typ, p->sym->name)); fprintf(fheader, "\n#endif"); } } banner(fheader, "Typedefs"); fflush(fheader); if (typetable) for (p = typetable->list; p; p = p->next) { if (!is_primitive_or_string(p->info.typ) && !is_external(p->info.typ) && !is_XML(p->info.typ) && !is_transient(p->info.typ) && !has_ns_t(p->info.typ) && !is_imported(p->info.typ) && !is_template(p->info.typ)) { sprintf(errbuf, "typedef '%s' is not namespace qualified: schema definition for '%s' in WSDL file output may be invalid", p->sym->name, p->sym->name); semwarn(errbuf); } if (!is_external(p->info.typ) && !is_imported(p->info.typ)) { fprintf(fheader, "\n#ifndef %s", soap_type(p->info.typ)); fprintf(fheader, "\n#define %s (%d)",soap_type(p->info.typ),p->info.typ->num); fprintf(fheader,"\n%s%s;", c_storage(p->info.sto), c_type_id(p->info.typ, p->sym->name)); fprintf(fheader, "\n#endif\n"); } } banner(fheader, "Typedef Synonyms"); if (enumtable) for (p = enumtable->list; p; p = p->next) if (p->sym->token == TYPE) fprintf(fheader, "\ntypedef %s %s;", c_type(p->info.typ), ident(p->sym->name)); if (classtable) for (p = classtable->list; p; p = p->next) if ((p->info.typ->type == Tstruct || p->info.typ->type == Tunion) && p->sym->token == TYPE) fprintf(fheader, "\ntypedef %s %s;", c_type(p->info.typ), ident(p->sym->name)); banner(fheader, "Externals"); fflush(fheader); if (t) for (p = t->list; p; p = p->next) if (p->info.typ->type != Tfun || p->info.sto & Sextern) { fprintf(fheader,"\n\nextern %s", c_storage(p->info.sto)); fprintf(fheader,"%s;", c_type_id(p->info.typ, p->sym->name)); } fflush(fheader);}voidget_namespace_prefixes(){ Symbol *p, *q; int i, n; char *s, buf[256]; if (nslist) return; for (p = symlist; p; p = p->next) { if (*p->name != '~') { s = p->name; while (*s == '_') s++; n = (int)(strlen(s) - 2); for (i = 1; i < n; i++) { if ((s[i] == '_' && s[i+1] == '_' && s[i+2] && s[i+2] != '_') || s[i] == ':') { if (s[i+1] == ':') { i++; continue; } strncpy(buf, s, i); buf[
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -