📄 symbol2.c
字号:
if (cflag) fprintf(fclient,"\n\n#ifdef __cplusplus\n}\n#endif"); fprintf(fclient, "\n\n/* End of %s */\n", soapClient); fclose(fclient); } if (!Cflag && !iflag) { if (namespaceid) fprintf(fserver,"\n\n} // namespace %s\n", namespaceid); if (cflag) fprintf(fserver,"\n\n#ifdef __cplusplus\n}\n#endif"); fprintf(fserver, "\n\n/* End of %s */\n", soapServer); fclose(fserver); }}voidgen_class(FILE *fd, Tnode *typ){ Entry *Eptr; char *x; x = xsi_type(typ); if (!x || !*x) x = wsdl_type(typ, ""); typ->generated = True; if (is_volatile(typ)) fprintf(fd, "\n\n#if 0 /* volatile type: do no redeclare */\n"); else if (typ->ref) { fprintf(fheader, "\n\n#ifndef %s", soap_type(typ)); fprintf(fheader, "\n#define %s (%d)\n",soap_type(typ),typ->num); } else fprintf(fd, "\n\n"); if (is_transient(typ) && typ->ref) fprintf(fd, "/* Transient type: */\n"); else if (is_invisible(typ->id->name) && typ->ref) fprintf(fd, "/* Operation wrapper: */\n"); else if (is_hexBinary(typ)) fprintf(fd, "/* hexBinary schema type: */\n"); else if (is_binary(typ)) fprintf(fd, "/* Base64 schema type: */\n"); else if (is_discriminant(typ)) fprintf(fd, "/* Choice: */\n"); else if (is_dynamic_array(typ)) { Eptr = ((Table*)typ->ref)->list; if (Eptr) { if (!is_untyped(Eptr->info.typ) && (is_external(Eptr->info.typ->ref) && ((Tnode*)Eptr->info.typ->ref)->type == Tclass || has_external(Eptr->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 containting an external object (declared at line %d)", Eptr->sym->name, c_type(Eptr->info.typ->ref), c_type(Eptr->info.typ->ref), Eptr->lineno); semwarn(errbuf); } else if (!is_untyped(Eptr->info.typ) && (is_volatile(Eptr->info.typ->ref) && ((Tnode*)Eptr->info.typ->ref)->type == Tclass || has_volatile(Eptr->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 containting a volatile object (declared at line %d)", Eptr->sym->name, c_type(Eptr->info.typ->ref), c_type(Eptr->info.typ->ref), Eptr->lineno); semwarn(errbuf); } } if (has_ns(typ) || is_untyped(typ)) fprintf(fd, "/* Sequence of %s schema type: */\n", x); else { if (!eflag) { sprintf(errbuf, "array '%s' is not compliant with WS-I Basic Profile 1.0a, reason: SOAP encoded array", c_type(typ)); compliancewarn(errbuf); } fprintf(fd, "/* SOAP encoded array of %s schema type: */\n", x); } } else if (is_primclass(typ)) fprintf(fd, "/* Primitive %s schema type: */\n", x); else if (!strcmp(typ->id->name, "SOAP_ENV__Header")) fprintf(fd, "/* SOAP Header: */\n"); else if (!strcmp(typ->id->name, "SOAP_ENV__Fault")) fprintf(fd, "/* SOAP Fault: */\n"); else if (!strcmp(typ->id->name, "SOAP_ENV__Code")) fprintf(fd, "/* SOAP Fault Code: */\n"); else if (x && *x && typ->ref) fprintf(fd, "/* %s */\n", x); fflush(fd); if (typ->type == Tstruct) { DBGLOG(fprintf(stderr,"\nstruct %s\n", typ->id->name)); if (typ->ref) { int permission = -1; fprintf(fd, "struct %s\n{", typ->id->name ); for (Eptr = ((Table*)typ->ref)->list; Eptr; Eptr = Eptr->next) { if (!cflag && 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)); } if (cflag && Eptr->info.typ->type == Tfun) continue; if (cflag && (Eptr->info.sto & Stypedef)) continue; 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 "); */ if (Eptr->sym == typ->id) /* a hack to emit constructor in a struct */ ((FNinfo*)Eptr->info.typ->ref)->ret = mknone(); fprintf(fd, "%s", c_type_id(Eptr->info.typ,Eptr->sym->name)); if (Eptr->info.sto & Sconstobj) fprintf(fd, " const;"); else fprintf(fd, ";"); if (Eptr->info.sto & Sreturn) fprintf(fd, "\t/* RPC return element */"); 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) if (Eptr->info.minOccurs >= 1) fprintf(fd, "\t/* required attribute of type %s */", wsdl_type(Eptr->info.typ, "")); else fprintf(fd, "\t/* optional attribute of type %s */", wsdl_type(Eptr->info.typ, "")); 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 of type %s */", Eptr->info.minOccurs, Eptr->info.maxOccurs, wsdl_type(Eptr->info.typ, "")); 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); } } } } 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", typ->id->name ); if (typ->base) fprintf(fd," : public %s", 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/* RPC return element */"); 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) 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() ", typ->id->name); t = (Table*)typ->ref; if (t) { for (p = t->list; p; p = p->next) { if (!(p->info.sto & Sconst) && p->info.typ->type == Tpointer) { fprintf(fd, "%c %s(NULL)", c, p->sym->name); c = ','; } } } fprintf(fd," { }"); } if (!has_destructor(typ)) fprintf(fd,"\n\tvirtual ~%s() { }", 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); */ } 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{", 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), 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -