diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-22 02:59:34 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-22 02:59:34 -0600 |
commit | 6c4cc3653e8dd7668295f3e659b7eb4dc571b67c (patch) | |
tree | a559fd71fc982e35a4f984d85a5c9d92b764ae8c /sipgen | |
download | sip4-tqt-6c4cc3653e8dd7668295f3e659b7eb4dc571b67c.tar.gz sip4-tqt-6c4cc3653e8dd7668295f3e659b7eb4dc571b67c.zip |
Initial import of SIP4 for Qt3
Diffstat (limited to 'sipgen')
-rw-r--r-- | sipgen/export.c | 1136 | ||||
-rw-r--r-- | sipgen/gencode.c | 13733 | ||||
-rw-r--r-- | sipgen/heap.c | 131 | ||||
-rw-r--r-- | sipgen/lexer.c | 3500 | ||||
-rw-r--r-- | sipgen/lexer.l | 628 | ||||
-rw-r--r-- | sipgen/main.c | 515 | ||||
-rw-r--r-- | sipgen/parser.c | 9975 | ||||
-rw-r--r-- | sipgen/parser.h | 309 | ||||
-rw-r--r-- | sipgen/parser.y | 6385 | ||||
-rw-r--r-- | sipgen/sip.h | 1180 | ||||
-rw-r--r-- | sipgen/sipgen.sbf | 19 | ||||
-rw-r--r-- | sipgen/transform.c | 3445 |
12 files changed, 40956 insertions, 0 deletions
diff --git a/sipgen/export.c b/sipgen/export.c new file mode 100644 index 0000000..641ea32 --- /dev/null +++ b/sipgen/export.c @@ -0,0 +1,1136 @@ +/* + * The XML and API file generator module for SIP. + * + * Copyright (c) 2010 Riverbank Computing Limited <info@riverbankcomputing.com> + * + * This file is part of SIP. + * + * This copy of SIP is licensed for use under the terms of the SIP License + * Agreement. See the file LICENSE for more details. + * + * This copy of SIP may also used under the terms of the GNU General Public + * License v2 or v3 as published by the Free Software Foundation which can be + * found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package. + * + * SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + + +#include <stdio.h> +#include <string.h> + +#include "sip.h" + + +#define XML_VERSION_NR 0 /* The schema version number. */ + +/* Icon numbers. The values are those used by the eric IDE. */ +#define CLASS_ID 1 +#define METHOD_ID 4 +#define VARIABLE_ID 7 +#define ENUM_ID 10 + + +static void apiEnums(sipSpec *pt, moduleDef *mod, classDef *scope, FILE *fp); +static void apiVars(sipSpec *pt, moduleDef *mod, classDef *scope, FILE *fp); +static int apiCtor(sipSpec *pt, moduleDef *mod, classDef *scope, ctorDef *ct, + int sec, FILE *fp); +static int apiOverload(sipSpec *pt, moduleDef *mod, classDef *scope, + overDef *od, int sec, FILE *fp); +static int apiArgument(sipSpec *pt, argDef *ad, int out, int need_comma, + int sec, int names, int defaults, int in_str, FILE *fp); +static void xmlClass(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp); +static void xmlEnums(sipSpec *pt, moduleDef *mod, classDef *scope, int indent, + FILE *fp); +static void xmlVars(sipSpec *pt, moduleDef *mod, classDef *scope, int indent, + FILE *fp); +static void xmlFunction(sipSpec *pt, classDef *scope, memberDef *md, + overDef *oloads, int indent, FILE *fp); +static int xmlCtor(sipSpec *pt, classDef *scope, ctorDef *ct, int sec, + int indent, FILE *fp); +static int xmlOverload(sipSpec *pt, classDef *scope, memberDef *md, + overDef *od, classDef *xtnds, int stat, int sec, int indent, FILE *fp); +static void xmlCppSignature(FILE *fp, overDef *od); +static void xmlArgument(sipSpec *pt, argDef *ad, const char *dir, int res_xfer, + int sec, int indent, FILE *fp); +static void xmlType(sipSpec *pt, argDef *ad, int sec, FILE *fp); +static void xmlIndent(int indent, FILE *fp); +static const char *dirAttribute(argDef *ad); +static void exportDefaultValue(argDef *ad, int in_str, FILE *fp); +static const char *pyType(sipSpec *pt, argDef *ad, int sec, classDef **scope); + + +/* + * Generate the API file. + */ +void generateAPI(sipSpec *pt, moduleDef *mod, const char *apiFile) +{ + overDef *od; + classDef *cd; + FILE *fp; + + /* Generate the file. */ + if ((fp = fopen(apiFile, "w")) == NULL) + fatal("Unable to create file \"%s\"\n", apiFile); + + apiEnums(pt, mod, NULL, fp); + apiVars(pt, mod, NULL, fp); + + for (od = mod->overs; od != NULL; od = od->next) + { + if (od->common->module != mod) + continue; + + if (od->common->slot != no_slot) + continue; + + if (apiOverload(pt, mod, NULL, od, FALSE, fp)) + apiOverload(pt, mod, NULL, od, TRUE, fp); + } + + for (cd = pt->classes; cd != NULL; cd = cd->next) + { + ctorDef *ct; + + if (cd->iff->module != mod) + continue; + + if (isExternal(cd)) + continue; + + apiEnums(pt, mod, cd, fp); + apiVars(pt, mod, cd, fp); + + for (ct = cd->ctors; ct != NULL; ct = ct->next) + { + if (isPrivateCtor(ct)) + continue; + + if (apiCtor(pt, mod, cd, ct, FALSE, fp)) + apiCtor(pt, mod, cd, ct, TRUE, fp); + } + + for (od = cd->overs; od != NULL; od = od->next) + { + if (isPrivate(od)) + continue; + + if (od->common->slot != no_slot) + continue; + + if (apiOverload(pt, mod, cd, od, FALSE, fp)) + apiOverload(pt, mod, cd, od, TRUE, fp); + } + } + + fclose(fp); +} + + +/* + * Generate an API ctor. + */ +static int apiCtor(sipSpec *pt, moduleDef *mod, classDef *scope, ctorDef *ct, + int sec, FILE *fp) +{ + int need_sec = FALSE, need_comma, a; + + /* Do the callable type form. */ + fprintf(fp, "%s.", mod->name); + prScopedPythonName(fp, scope->ecd, scope->pyname->text); + fprintf(fp, "?%d(", CLASS_ID); + + need_comma = FALSE; + + for (a = 0; a < ct->pysig.nrArgs; ++a) + { + argDef *ad = &ct->pysig.args[a]; + + need_comma = apiArgument(pt, ad, FALSE, need_comma, sec, TRUE, TRUE, + FALSE, fp); + + if (ad->atype == rxcon_type || ad->atype == rxdis_type) + need_sec = TRUE; + } + + fprintf(fp, ")\n"); + + /* Do the call __init__ form. */ + fprintf(fp, "%s.", mod->name); + prScopedPythonName(fp, scope->ecd, scope->pyname->text); + fprintf(fp, ".__init__?%d(self", CLASS_ID); + + for (a = 0; a < ct->pysig.nrArgs; ++a) + apiArgument(pt, &ct->pysig.args[a], FALSE, TRUE, sec, TRUE, TRUE, + FALSE, fp); + + fprintf(fp, ")\n"); + + return need_sec; +} + + +/* + * Generate the APIs for all the enums in a scope. + */ +static void apiEnums(sipSpec *pt, moduleDef *mod, classDef *scope, FILE *fp) +{ + enumDef *ed; + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + enumMemberDef *emd; + + if (ed->module != mod) + continue; + + if (ed->ecd != scope) + continue; + + if (ed->pyname != NULL) + { + fprintf(fp, "%s.", mod->name); + prScopedPythonName(fp, ed->ecd, ed->pyname->text); + fprintf(fp, "?%d\n", ENUM_ID); + } + + for (emd = ed->members; emd != NULL; emd = emd->next) + { + fprintf(fp, "%s.", mod->name); + prScopedPythonName(fp, ed->ecd, emd->pyname->text); + fprintf(fp, "?%d\n", ENUM_ID); + } + } +} + + +/* + * Generate the APIs for all the variables in a scope. + */ +static void apiVars(sipSpec *pt, moduleDef *mod, classDef *scope, FILE *fp) +{ + varDef *vd; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + if (vd->module != mod) + continue; + + if (vd->ecd != scope) + continue; + + fprintf(fp, "%s.", mod->name); + prScopedPythonName(fp, vd->ecd, vd->pyname->text); + fprintf(fp, "?%d\n", VARIABLE_ID); + } +} + + +/* + * Generate a single API overload. + */ +static int apiOverload(sipSpec *pt, moduleDef *mod, classDef *scope, + overDef *od, int sec, FILE *fp) +{ + int need_sec; + + fprintf(fp, "%s.", mod->name); + prScopedPythonName(fp, scope, od->common->pyname->text); + fprintf(fp, "?%d", METHOD_ID); + + need_sec = prPythonSignature(pt, fp, &od->pysig, sec, TRUE, TRUE, FALSE, + FALSE); + + fprintf(fp, "\n"); + + return need_sec; +} + + +/* + * Generate the API for an argument. + */ +static int apiArgument(sipSpec *pt, argDef *ad, int out, int need_comma, + int sec, int names, int defaults, int in_str, FILE *fp) +{ + const char *tname; + classDef *tscope; + + if (isArraySize(ad)) + return need_comma; + + if (sec && (ad->atype == slotcon_type || ad->atype == slotdis_type)) + return need_comma; + + if ((tname = pyType(pt, ad, sec, &tscope)) == NULL) + return need_comma; + + if (need_comma) + fprintf(fp, ", "); + + prScopedPythonName(fp, tscope, tname); + + /* + * Handle the default value is required, but ignore it if it is an output + * only argument. + */ + if (defaults && ad->defval && !out) + { + if (names && ad->name != NULL) + fprintf(fp, " %s", ad->name->text); + + fprintf(fp, "="); + prcode(fp, "%M"); + exportDefaultValue(ad, in_str, fp); + prcode(fp, "%M"); + } + + return TRUE; +} + + +/* + * Generate the XML export file. + */ +void generateXML(sipSpec *pt, moduleDef *mod, const char *xmlFile) +{ + FILE *fp; + classDef *cd; + memberDef *md; + + if ((fp = fopen(xmlFile, "w")) == NULL) + fatal("Unable to create file \"%s\"\n", xmlFile); + + fprintf(fp, "<?xml version=\"1.0\"?>\n"); + fprintf(fp, "<Module version=\"%u\" name=\"%s\">\n", + XML_VERSION_NR, mod->name); + + /* + * Note that we don't yet handle mapped types, templates or exceptions. + */ + + for (cd = pt->classes; cd != NULL; cd = cd->next) + { + if (cd->iff->module != mod) + continue; + + if (isExternal(cd)) + continue; + + xmlClass(pt, mod, cd, fp); + } + + for (cd = mod->proxies; cd != NULL; cd = cd->next) + xmlClass(pt, mod, cd, fp); + + xmlEnums(pt, mod, NULL, 1, fp); + xmlVars(pt, mod, NULL, 1, fp); + + for (md = mod->othfuncs; md != NULL; md = md->next) + xmlFunction(pt, NULL, md, mod->overs, 1, fp); + + fprintf(fp, "</Module>\n"); + + fclose(fp); +} + + +/* + * Generate the XML for a class. + */ +static void xmlClass(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp) +{ + int indent = 1; + ctorDef *ct; + memberDef *md; + + if (isOpaque(cd)) + { + xmlIndent(indent, fp); + fprintf(fp, "<OpaqueClass name=\""); + prScopedPythonName(fp, cd->ecd, cd->pyname->text); + fprintf(fp, "\"/>\n"); + + return; + } + + xmlIndent(indent++, fp); + fprintf(fp, "<Class name=\""); + prScopedPythonName(fp, cd->ecd, cd->pyname->text); + fprintf(fp, "\""); + + if (cd->picklecode != NULL) + fprintf(fp, " pickle=\"1\""); + + if (cd->convtocode != NULL) + fprintf(fp, " convert=\"1\""); + + if (cd->real != NULL) + fprintf(fp, " extends=\"%s\"", cd->real->iff->module->name); + + if (cd->supers != NULL) + { + classList *cl; + + fprintf(fp, " inherits=\""); + + for (cl = cd->supers; cl != NULL; cl = cl->next) + { + if (cl != cd->supers) + fprintf(fp, " "); + + prScopedPythonName(fp, cl->cd->ecd, cl->cd->pyname->text); + } + + fprintf(fp, "\""); + } + + fprintf(fp, ">\n"); + + xmlEnums(pt, mod, cd, indent, fp); + xmlVars(pt, mod, cd, indent, fp); + + for (ct = cd->ctors; ct != NULL; ct = ct->next) + { + if (isPrivateCtor(ct)) + continue; + + if (xmlCtor(pt, cd, ct, FALSE, indent, fp)) + xmlCtor(pt, cd, ct, TRUE, indent, fp); + } + + for (md = cd->members; md != NULL; md = md->next) + xmlFunction(pt, cd, md, cd->overs, indent, fp); + + xmlIndent(--indent, fp); + fprintf(fp, "</Class>\n"); +} + + +/* + * Generate the XML for all the enums in a scope. + */ +static void xmlEnums(sipSpec *pt, moduleDef *mod, classDef *scope, int indent, + FILE *fp) +{ + enumDef *ed; + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + if (ed->module != mod) + continue; + + if (ed->ecd != scope) + continue; + + if (ed->pyname != NULL) + { + enumMemberDef *emd; + + xmlIndent(indent++, fp); + fprintf(fp, "<Enum name=\""); + prScopedPythonName(fp, ed->ecd, ed->pyname->text); + fprintf(fp, "\">\n"); + + for (emd = ed->members; emd != NULL; emd = emd->next) + { + xmlIndent(indent, fp); + fprintf(fp, "<EnumMember name=\""); + prScopedPythonName(fp, ed->ecd, emd->pyname->text); + fprintf(fp, "\"/>\n"); + } + + xmlIndent(--indent, fp); + fprintf(fp, "</Enum>\n"); + } + else + { + enumMemberDef *emd; + + for (emd = ed->members; emd != NULL; emd = emd->next) + { + xmlIndent(indent, fp); + fprintf(fp, "<Member name=\""); + prScopedPythonName(fp, ed->ecd, emd->pyname->text); + fprintf(fp, "\" const=\"1\" typename=\"int\"/>\n"); + } + } + } +} + + +/* + * Generate the XML for all the variables in a scope. + */ +static void xmlVars(sipSpec *pt, moduleDef *mod, classDef *scope, int indent, + FILE *fp) +{ + varDef *vd; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + if (vd->module != mod) + continue; + + if (vd->ecd != scope) + continue; + + xmlIndent(indent, fp); + fprintf(fp, "<Member name=\""); + prScopedPythonName(fp, vd->ecd, vd->pyname->text); + fprintf(fp, "\""); + + if (isConstArg(&vd->type) || scope == NULL) + fprintf(fp, " const=\"1\""); + + if (isStaticVar(vd)) + fprintf(fp, " static=\"1\""); + + xmlType(pt, &vd->type, FALSE, fp); + fprintf(fp, "/>\n"); + } +} + + +/* + * Generate the XML for a ctor. + */ +static int xmlCtor(sipSpec *pt, classDef *scope, ctorDef *ct, int sec, + int indent, FILE *fp) +{ + int a, need_sec; + + xmlIndent(indent++, fp); + fprintf(fp, "<Function name=\""); + prScopedPythonName(fp, scope, "__init__"); + fprintf(fp, "\""); + + /* Handle the trivial case. */ + if (ct->pysig.nrArgs == 0) + { + fprintf(fp, "/>\n"); + return FALSE; + } + + fprintf(fp, ">\n"); + + need_sec = FALSE; + + for (a = 0; a < ct->pysig.nrArgs; ++a) + { + argDef *ad = &ct->pysig.args[a]; + + xmlArgument(pt, ad, dirAttribute(ad), FALSE, sec, indent, fp); + + if (ad->atype == rxcon_type || ad->atype == rxdis_type) + need_sec = TRUE; + } + + xmlIndent(--indent, fp); + fprintf(fp, "</Function>\n"); + + return need_sec; +} + + +/* + * Generate the XML for a function. + */ +static void xmlFunction(sipSpec *pt, classDef *scope, memberDef *md, + overDef *oloads, int indent, FILE *fp) +{ + overDef *od; + const char *default_str = "default=\"1\" "; + + for (od = oloads; od != NULL; od = od->next) + { + int isstat; + classDef *xtnds; + + if (od->common != md) + continue; + + if (isPrivate(od)) + continue; + + if (isSignal(od)) + { + xmlIndent(indent, fp); + fprintf(fp, "<Signal %sname=\"", default_str); + prScopedPythonName(fp, scope, md->pyname->text); + fprintf(fp, "\" sig=\""); + xmlCppSignature(fp, od); + fprintf(fp, "\"/>\n"); + + default_str = ""; + + continue; + } + + xtnds = NULL; + isstat = (scope == NULL || scope->iff->type == namespace_iface || isStatic(od)); + + if (scope == NULL && md->slot != no_slot && od->pysig.args[0].atype == class_type) + { + xtnds = od->pysig.args[0].u.cd; + isstat = FALSE; + } + + if (xmlOverload(pt, scope, md, od, xtnds, isstat, FALSE, indent, fp)) + xmlOverload(pt, scope, md, od, xtnds, isstat, TRUE, indent, fp); + } +} + + +/* + * Generate the XML for an overload. + */ +static int xmlOverload(sipSpec *pt, classDef *scope, memberDef *md, + overDef *od, classDef *xtnds, int stat, int sec, int indent, FILE *fp) +{ + int a, need_sec, no_res; + + xmlIndent(indent++, fp); + fprintf(fp, "<Function name=\""); + prScopedPythonName(fp, scope, md->pyname->text); + fprintf(fp, "\""); + + if (isAbstract(od)) + fprintf(fp, " abstract=\"1\""); + + if (stat) + fprintf(fp, " static=\"1\""); + + if (isSlot(od)) + { + fprintf(fp, " slot=\""); + xmlCppSignature(fp, od); + fprintf(fp, "\""); + } + + if (xtnds != NULL) + { + fprintf(fp, " extends=\""); + prScopedPythonName(fp, xtnds->ecd, xtnds->pyname->text); + fprintf(fp, "\""); + } + + no_res = (od->pysig.result.atype == void_type && od->pysig.result.nrderefs == 0); + + /* Handle the trivial case. */ + if (no_res && od->pysig.nrArgs == 0) + { + fprintf(fp, "/>\n"); + return FALSE; + } + + fprintf(fp, ">\n"); + + if (!no_res) + xmlArgument(pt, &od->pysig.result, "out", isResultTransferredBack(od), + FALSE, indent, fp); + + need_sec = FALSE; + + for (a = 0; a < od->pysig.nrArgs; ++a) + { + argDef *ad = &od->pysig.args[a]; + + /* Ignore the first argument of number slots. */ + if (isNumberSlot(md) && a == 0 && od->pysig.nrArgs == 2) + continue; + + xmlArgument(pt, ad, dirAttribute(ad), FALSE, sec, indent, fp); + + if (ad->atype == rxcon_type || ad->atype == rxdis_type) + need_sec = TRUE; + } + + xmlIndent(--indent, fp); + fprintf(fp, "</Function>\n"); + + return need_sec; +} + + +/* + * Generate the XML for a C++ signature. + */ +static void xmlCppSignature(FILE *fp, overDef *od) +{ + prcode(fp, "%M"); + prOverloadDecl(fp, NULL, od, TRUE); + prcode(fp, "%M"); +} + + +/* + * Convert an arguments direction to an XML attribute value. + */ +static const char *dirAttribute(argDef *ad) +{ + if (isInArg(ad)) + { + if (isOutArg(ad)) + return "inout"; + + return NULL; + } + + return "out"; +} + + +/* + * Generate the XML for an argument. + */ +static void xmlArgument(sipSpec *pt, argDef *ad, const char *dir, int res_xfer, + int sec, int indent, FILE *fp) +{ + if (isArraySize(ad)) + return; + + if (sec && (ad->atype == slotcon_type || ad->atype == slotdis_type)) + return; + + xmlIndent(indent, fp); + fprintf(fp, "<Argument"); + xmlType(pt, ad, sec, fp); + + if (dir != NULL) + fprintf(fp, " dir=\"%s\"", dir); + + if (isAllowNone(ad)) + fprintf(fp, " allownone=\"1\""); + + if (isTransferred(ad)) + fprintf(fp, " transfer=\"to\""); + else if (isThisTransferred(ad)) + fprintf(fp, " transfer=\"this\""); + else if (res_xfer || isTransferredBack(ad)) + fprintf(fp, " transfer=\"back\""); + + /* + * Handle the default value, but ignore it if it is an output only + * argument. + */ + if (ad->defval && (dir == NULL || strcmp(dir, "out") != 0)) + { + prcode(fp, " default=\"%M"); + exportDefaultValue(ad, FALSE, fp); + prcode(fp, "%M\""); + } + + fprintf(fp, "/>\n"); +} + + +/* + * Generate the XML for a type. + */ +static void xmlType(sipSpec *pt, argDef *ad, int sec, FILE *fp) +{ + const char *type_type = NULL, *type_name; + classDef *type_scope; + + fprintf(fp, " typename=\""); + + switch (ad->atype) + { + case class_type: + type_type = (isOpaque(ad->u.cd) ? "opaque" : "class"); + break; + + case enum_type: + if (ad->u.ed->pyname != NULL) + type_type = "enum"; + break; + + case rxcon_type: + case rxdis_type: + if (!sec) + type_type = "class"; + break; + + case qobject_type: + type_type = "class"; + break; + + case slotcon_type: + case slotdis_type: + { + int a; + + prcode(fp, "SLOT("); + + for (a = 0; a < ad->u.sa->nrArgs; ++a) + { + if (a > 0) + prcode(fp, ", "); + + prcode(fp, "%M%B%M", &ad->u.sa->args[a]); + } + + prcode(fp, ")"); + } + + break; + + case mapped_type: + type_type = "mappedtype"; + break; + } + + if ((type_name = pyType(pt, ad, sec, &type_scope)) != NULL) + prScopedPythonName(fp, type_scope, type_name); + + fprintf(fp, "\""); + + if (type_type != NULL) + fprintf(fp, " typetype=\"%s\"", type_type); + + if (ad->name != NULL) + fprintf(fp, " name=\"%s\"", ad->name->text); +} + + +/* + * Generate the indentation for a line. + */ +static void xmlIndent(int indent, FILE *fp) +{ + while (indent-- > 0) + fprintf(fp, " "); +} + + +/* + * Export the default value of an argument. + */ +static void exportDefaultValue(argDef *ad, int in_str, FILE *fp) +{ + /* Use any explicitly provided documentation. */ + if (ad->docval != NULL) + { + prcode(fp, "%s", ad->docval); + return; + } + + /* Translate some special cases. */ + if (ad->defval->next == NULL && ad->defval->vtype == numeric_value) + { + if (ad->nrderefs > 0 && ad->defval->u.vnum == 0) + { + prcode(fp, "None"); + return; + } + + if (ad->atype == bool_type || ad->atype == cbool_type) + { + prcode(fp, ad->defval->u.vnum ? "True" : "False"); + return; + } + } + + generateExpression(ad->defval, in_str, fp); +} + + +/* + * Get the Python representation of a type. + */ +static const char *pyType(sipSpec *pt, argDef *ad, int sec, classDef **scope) +{ + const char *type_name; + + *scope = NULL; + + /* Use any explicit documented type. */ + if (ad->doctype != NULL) + return ad->doctype; + + /* For classes and mapped types we need the default implementation. */ + if (ad->atype == class_type || ad->atype == mapped_type) + { + classDef *def_cd = NULL; + mappedTypeDef *def_mtd = NULL; + ifaceFileDef *iff; + + if (ad->atype == class_type) + { + iff = ad->u.cd->iff; + + if (iff->api_range == NULL) + { + /* There is only one implementation. */ + def_cd = ad->u.cd; + iff = NULL; + } + } + else + { + iff = ad->u.mtd->iff; + + if (iff->api_range == NULL) + { + /* There is only one implementation. */ + def_mtd = ad->u.mtd; + iff = NULL; + } + } + + if (iff != NULL) + { + int def_api; + + /* Find the default implementation. */ + def_api = findAPI(pt, iff->api_range->api_name->text)->from; + + for (iff = iff->first_alt; iff != NULL; iff = iff->next_alt) + { + apiVersionRangeDef *avd = iff->api_range; + + if (avd->from > 0 && avd->from > def_api) + continue; + + if (avd->to > 0 && avd->to <= def_api) + continue; + + /* It's within range. */ + break; + } + + /* Find the corresponding class or mapped type. */ + for (def_cd = pt->classes; def_cd != NULL; def_cd = def_cd->next) + if (def_cd->iff == iff) + break; + + if (def_cd == NULL) + for (def_mtd = pt->mappedtypes; def_mtd != NULL; def_mtd = def_mtd->next) + if (def_mtd->iff == iff) + break; + } + + /* Now handle the correct implementation. */ + if (def_cd != NULL) + { + *scope = def_cd->ecd; + type_name = def_cd->pyname->text; + } + else + { + /* + * Give a hint that /DocType/ should be used, or there is no + * default implementation. + */ + type_name = "unknown-type"; + + if (def_mtd != NULL) + { + if (def_mtd->doctype != NULL) + type_name = def_mtd->doctype; + else if (def_mtd->pyname != NULL) + type_name = def_mtd->pyname->text; + } + } + + return type_name; + } + + switch (ad->atype) + { + case struct_type: + case void_type: + type_name = "sip.voidptr"; + break; + + case enum_type: + if (ad->u.ed->pyname != NULL) + { + type_name = ad->u.ed->pyname->text; + *scope = ad->u.ed->ecd; + } + else + type_name = "int"; + break; + + case signal_type: + type_name = "SIGNAL()"; + break; + + case slot_type: + type_name = "SLOT()"; + break; + + case rxcon_type: + case rxdis_type: + if (sec) + type_name = "callable"; + else + type_name = "QObject"; + + break; + + case qobject_type: + type_name = "QObject"; + break; + + case ustring_type: + case string_type: + case sstring_type: + case wstring_type: + case ascii_string_type: + case latin1_string_type: + case utf8_string_type: + type_name = "str"; + break; + + case ushort_type: + case uint_type: + case long_type: + case longlong_type: + case ulong_type: + case ulonglong_type: + case short_type: + case int_type: + case cint_type: + type_name = "int"; + break; + + case float_type: + case cfloat_type: + case double_type: + case cdouble_type: + type_name = "float"; + break; + + case bool_type: + case cbool_type: + type_name = "bool"; + break; + + case pyobject_type: + type_name = "object"; + break; + + case pytuple_type: + type_name = "tuple"; + break; + + case pylist_type: + type_name = "list"; + break; + + case pydict_type: + type_name = "dict"; + break; + + case pycallable_type: + type_name = "callable"; + break; + + case pyslice_type: + type_name = "slice"; + break; + + case pytype_type: + type_name = "type"; + break; + + case ellipsis_type: + type_name = "..."; + break; + + case slotcon_type: + case anyslot_type: + type_name = "SLOT()"; + break; + + default: + type_name = NULL; + } + + return type_name; +} + + +/* + * Generate a scoped Python name. + */ +void prScopedPythonName(FILE *fp, classDef *scope, const char *pyname) +{ + if (scope != NULL) + { + prScopedPythonName(fp, scope->ecd, NULL); + fprintf(fp, "%s.", scope->pyname->text); + } + + if (pyname != NULL) + fprintf(fp, "%s", pyname); +} + + +/* + * Generate a Python signature. + */ +int prPythonSignature(sipSpec *pt, FILE *fp, signatureDef *sd, int sec, + int names, int defaults, int in_str, int is_signal) +{ + int need_sec = FALSE, need_comma = FALSE, is_res, nr_out, a; + + fprintf(fp, "%c", (is_signal ? '[' : '(')); + + nr_out = 0; + + for (a = 0; a < sd->nrArgs; ++a) + { + argDef *ad = &sd->args[a]; + + if (isOutArg(ad)) + ++nr_out; + + if (!isInArg(ad)) + continue; + + need_comma = apiArgument(pt, ad, FALSE, need_comma, sec, names, + defaults, in_str, fp); + + if (ad->atype == rxcon_type || ad->atype == rxdis_type) + need_sec = TRUE; + } + + fprintf(fp, "%c", (is_signal ? ']' : ')')); + + is_res = !((sd->result.atype == void_type && sd->result.nrderefs == 0) || + (sd->result.doctype != NULL && sd->result.doctype[0] == '\0')); + + if (is_res || nr_out > 0) + { + fprintf(fp, " -> "); + + if ((is_res && nr_out > 0) || nr_out > 1) + fprintf(fp, "("); + + if (is_res) + need_comma = apiArgument(pt, &sd->result, TRUE, FALSE, sec, FALSE, + FALSE, in_str, fp); + else + need_comma = FALSE; + + for (a = 0; a < sd->nrArgs; ++a) + { + argDef *ad = &sd->args[a]; + + if (isOutArg(ad)) + /* We don't want the name in the result tuple. */ + need_comma = apiArgument(pt, ad, TRUE, need_comma, sec, FALSE, + FALSE, in_str, fp); + } + + if ((is_res && nr_out > 0) || nr_out > 1) + fprintf(fp, ")"); + } + + return need_sec; +} diff --git a/sipgen/gencode.c b/sipgen/gencode.c new file mode 100644 index 0000000..b0c3d01 --- /dev/null +++ b/sipgen/gencode.c @@ -0,0 +1,13733 @@ +/* + * The code generator module for SIP. + * + * Copyright (c) 2010 Riverbank Computing Limited <info@riverbankcomputing.com> + * + * This file is part of SIP. + * + * This copy of SIP is licensed for use under the terms of the SIP License + * Agreement. See the file LICENSE for more details. + * + * This copy of SIP may also used under the terms of the GNU General Public + * License v2 or v3 as published by the Free Software Foundation which can be + * found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package. + * + * SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + + +#include <stdio.h> +#include <time.h> +#include <errno.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> + +#include "sip.h" + + +/* Return the base (ie. C/C++) name of a super-type or meta-type. */ +#define smtypeName(sm) (strrchr((sm)->name->text, '.') + 1) + +/* Return TRUE if a wrapped variable can be set. */ +#define canSetVariable(vd) ((vd)->type.nrderefs != 0 || !isConstArg(&(vd)->type)) + + +/* Control what generateCalledArgs() actually generates. */ +typedef enum { + Declaration, + Definition +} funcArgType; + + +/* An entry in the sorted array of methods. */ +typedef struct { + memberDef *md; /* The method. */ +} sortedMethTab; + + +static int currentLineNr; /* Current output line number. */ +static const char *currentFileName; /* Current output file name. */ +static int previousLineNr; /* Previous output line number. */ +static const char *previousFileName; /* Previous output file name. */ +static int exceptions; /* Set if exceptions are enabled. */ +static int tracing; /* Set if tracing is enabled. */ +static int generating_c; /* Set if generating C. */ +static int release_gil; /* Set if always releasing the GIL. */ +static const char *prcode_last = NULL; /* The last prcode format string. */ +static int prcode_xml = FALSE; /* Set if prcode is XML aware. */ +static int docstrings; /* Set if generating docstrings. */ + + +static void generateDocumentation(sipSpec *pt, const char *docFile); +static void generateBuildFile(sipSpec *pt, const char *buildFile, + const char *srcSuffix, const char *consModule); +static void generateBuildFileSources(sipSpec *pt, moduleDef *mod, + const char *srcSuffix, FILE *fp); +static void generateInternalAPIHeader(sipSpec *pt, moduleDef *mod, + const char *codeDir, stringList *xsl); +static void generateCpp(sipSpec *pt, moduleDef *mod, const char *codeDir, + const char *srcSuffix, int parts, stringList *xsl); +static void generateCompositeCpp(sipSpec *pt, const char *codeDir); +static void generateConsolidatedCpp(sipSpec *pt, const char *codeDir, + const char *srcSuffix); +static void generateComponentCpp(sipSpec *pt, const char *codeDir, + const char *consModule); +static void generateSipImport(moduleDef *mod, FILE *fp); +static void generateSipImportVariables(FILE *fp); +static void generateModInitStart(moduleDef *mod, int gen_c, FILE *fp); +static void generateModDefinition(moduleDef *mod, const char *methods, + FILE *fp); +static void generateIfaceCpp(sipSpec *, ifaceFileDef *, const char *, + const char *, FILE *); +static void generateMappedTypeCpp(mappedTypeDef *mtd, sipSpec *pt, FILE *fp); +static void generateImportedMappedTypeAPI(mappedTypeDef *mtd, sipSpec *pt, + moduleDef *mod, FILE *fp); +static void generateMappedTypeAPI(sipSpec *pt, mappedTypeDef *mtd, FILE *fp); +static void generateClassCpp(classDef *cd, sipSpec *pt, FILE *fp); +static void generateImportedClassAPI(classDef *cd, sipSpec *pt, moduleDef *mod, + FILE *fp); +static void generateClassAPI(classDef *cd, sipSpec *pt, FILE *fp); +static void generateClassFunctions(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp); +static void generateShadowCode(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp); +static void generateFunction(sipSpec *, memberDef *, overDef *, classDef *, + classDef *, moduleDef *, FILE *); +static void generateFunctionBody(overDef *, classDef *, mappedTypeDef *, + classDef *, int deref, moduleDef *, FILE *); +static void generateTypeDefinition(sipSpec *pt, classDef *cd, FILE *fp); +static void generateTypeInit(classDef *, moduleDef *, FILE *); +static void generateCppCodeBlock(codeBlock *, FILE *); +static void generateUsedIncludes(ifaceFileList *iffl, FILE *fp); +static void generateModuleAPI(sipSpec *pt, moduleDef *mod, FILE *fp); +static void generateImportedModuleAPI(sipSpec *pt, moduleDef *mod, + moduleDef *immod, FILE *fp); +static void generateShadowClassDeclaration(sipSpec *, classDef *, FILE *); +static int hasConvertToCode(argDef *ad); +static void deleteOuts(signatureDef *sd, FILE *fp); +static void deleteTemps(signatureDef *sd, FILE *fp); +static void gc_ellipsis(signatureDef *sd, FILE *fp); +static void generateCallArgs(signatureDef *, signatureDef *, FILE *); +static void generateCalledArgs(ifaceFileDef *, signatureDef *, funcArgType, + int, FILE *); +static void generateVariable(ifaceFileDef *, argDef *, int, FILE *); +static void generateNamedValueType(ifaceFileDef *, argDef *, char *, FILE *); +static void generateBaseType(ifaceFileDef *, argDef *, int, FILE *); +static void generateNamedBaseType(ifaceFileDef *, argDef *, char *, int, + FILE *); +static void generateTupleBuilder(signatureDef *, FILE *); +static void generateEmitters(classDef *cd, FILE *fp); +static void generateEmitter(classDef *, visibleList *, FILE *); +static void generateVirtualHandler(virtHandlerDef *vhd, FILE *fp); +static void generateVirtHandlerErrorReturn(argDef *res, const char *indent, + FILE *fp); +static void generateVirtualCatcher(moduleDef *mod, classDef *cd, int virtNr, + virtOverDef *vod, FILE *fp); +static void generateVirtHandlerCall(moduleDef *mod, classDef *cd, + virtOverDef *vod, argDef *res, const char *indent, FILE *fp); +static void generateUnambiguousClass(classDef *cd, classDef *scope, FILE *fp); +static void generateProtectedEnums(sipSpec *, classDef *, FILE *); +static void generateProtectedDeclarations(classDef *, FILE *); +static void generateProtectedDefinitions(classDef *, FILE *); +static void generateProtectedCallArgs(signatureDef *sd, FILE *fp); +static void generateConstructorCall(classDef *, ctorDef *, int, int, + moduleDef *, FILE *); +static void generateHandleResult(overDef *, int, int, char *, FILE *); +static void generateOrdinaryFunction(sipSpec *pt, moduleDef *mod, + classDef *c_scope, mappedTypeDef *mt_scope, memberDef *md, FILE *fp); +static void generateSimpleFunctionCall(fcallDef *, FILE *); +static void generateFunctionCall(classDef *c_scope, mappedTypeDef *mt_scope, + ifaceFileDef *o_scope, overDef *od, int deref, moduleDef *mod, + FILE *fp); +static void generateCppFunctionCall(ifaceFileDef *scope, + ifaceFileDef *o_scope, overDef *od, FILE *fp); +static void generateSlotArg(signatureDef *sd, int argnr, FILE *fp); +static void generateComparisonSlotCall(ifaceFileDef *scope, overDef *od, + const char *op, const char *cop, int deref, FILE *fp); +static void generateBinarySlotCall(ifaceFileDef *scope, overDef *od, + const char *op, int deref, FILE *fp); +static void generateNumberSlotCall(overDef *od, char *op, FILE *fp); +static void generateVariableGetter(ifaceFileDef *, varDef *, FILE *); +static void generateVariableSetter(ifaceFileDef *, varDef *, FILE *); +static int generateObjToCppConversion(argDef *, FILE *); +static void generateVarMember(varDef *vd, FILE *fp); +static int generateVoidPointers(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp); +static int generateChars(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp); +static int generateStrings(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp); +static sortedMethTab *createFunctionTable(memberDef *, int *); +static sortedMethTab *createMethodTable(classDef *, int *); +static int generateMappedTypeMethodTable(sipSpec *pt, mappedTypeDef *mtd, + FILE *fp); +static int generateClassMethodTable(sipSpec *pt, classDef *cd, FILE *fp); +static void prMethodTable(sipSpec *pt, sortedMethTab *mtable, int nr, + ifaceFileDef *iff, overDef *overs, FILE *fp); +static void generateEnumMacros(sipSpec *pt, moduleDef *mod, classDef *cd, + mappedTypeDef *mtd, FILE *fp); +static int generateEnumMemberTable(sipSpec *pt, moduleDef *mod, classDef *cd, + mappedTypeDef *mtd, FILE *fp); +static int generateInts(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp); +static int generateLongs(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp); +static int generateUnsignedLongs(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp); +static int generateLongLongs(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp); +static int generateUnsignedLongLongs(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp); +static int generateVariableType(sipSpec *pt, moduleDef *mod, classDef *cd, + argType atype, const char *eng, const char *s1, const char *s2, + FILE *fp); +static int generateDoubles(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp); +static int generateClasses(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp); +static void generateTypesInline(sipSpec *pt, moduleDef *mod, FILE *fp); +static void generateAccessFunctions(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp); +static void generateConvertToDefinitions(mappedTypeDef *, classDef *, FILE *); +static void generateEncodedType(moduleDef *mod, classDef *cd, int last, + FILE *fp); +static int generateArgParser(signatureDef *sd, classDef *c_scope, + mappedTypeDef *mt_scope, ctorDef *ct, overDef *od, int secCall, + FILE *fp); +static void generateTry(throwArgs *, FILE *); +static void generateCatch(throwArgs *ta, signatureDef *sd, moduleDef *mod, + FILE *fp); +static void generateCatchBlock(exceptionDef *xd, signatureDef *sd, FILE *fp); +static void generateThrowSpecifier(throwArgs *, FILE *); +static void generateSlot(moduleDef *mod, classDef *cd, enumDef *ed, + memberDef *md, FILE *fp); +static void generateCastZero(argDef *ad, FILE *fp); +static void generateCallDefaultCtor(ctorDef *ct, FILE *fp); +static int countVirtuals(classDef *); +static int skipOverload(overDef *, memberDef *, classDef *, classDef *, int); +static int compareMethTab(const void *, const void *); +static int compareEnumMembers(const void *, const void *); +static char *getSubFormatChar(char, argDef *); +static char *createIfaceFileName(const char *, ifaceFileDef *, const char *); +static FILE *createCompilationUnit(moduleDef *mod, const char *fname, + const char *description); +static FILE *createFile(moduleDef *mod, const char *fname, + const char *description); +static void closeFile(FILE *); +static void prScopedName(FILE *fp, scopedNameDef *snd, char *sep); +static void prTypeName(FILE *fp, argDef *ad); +static void prScopedClassName(FILE *fp, ifaceFileDef *scope, classDef *cd); +static int isZeroArgSlot(memberDef *md); +static int isMultiArgSlot(memberDef *md); +static int isIntArgSlot(memberDef *md); +static int isInplaceNumberSlot(memberDef *md); +static int isInplaceSequenceSlot(memberDef *md); +static int needErrorFlag(codeBlock *cb); +static int needOldErrorFlag(codeBlock *cb); +static int needNewInstance(argDef *ad); +static int needDealloc(classDef *cd); +static const char *getBuildResultFormat(argDef *ad); +static const char *getParseResultFormat(argDef *ad, int res_isref, int xfervh); +static void generateParseResultExtraArgs(argDef *ad, int argnr, FILE *fp); +static char *makePartName(const char *codeDir, const char *mname, int part, + const char *srcSuffix); +static void fakeProtectedArgs(signatureDef *sd); +static void normaliseArgs(signatureDef *); +static void restoreArgs(signatureDef *); +static const char *slotName(slotType st); +static void ints_intro(classDef *cd, FILE *fp); +static const char *argName(const char *name, codeBlock *cb); +static int usedInCode(codeBlock *code, const char *str); +static void generateDefaultValue(argDef *ad, int argnr, FILE *fp); +static void generateClassFromVoid(classDef *cd, const char *cname, + const char *vname, FILE *fp); +static void generateMappedTypeFromVoid(mappedTypeDef *mtd, const char *cname, + const char *vname, FILE *fp); +static int generateSubClassConvertors(sipSpec *pt, moduleDef *mod, FILE *fp); +static void generateNameCache(sipSpec *pt, FILE *fp); +static const char *resultOwner(overDef *od); +static void prCachedName(FILE *fp, nameDef *nd, const char *prefix); +static void generateSignalTableEntry(sipSpec *pt, classDef *cd, overDef *sig, + memberDef *md, int membernr, FILE *fp); +static void generateTypesTable(sipSpec *pt, moduleDef *mod, FILE *fp); +static int py2OnlySlot(slotType st); +static int py2_5LaterSlot(slotType st); +static int keepPyReference(argDef *ad); +static int isDuplicateProtected(classDef *cd, overDef *target); +static char getEncoding(argType atype); +static void generateTypeDefName(ifaceFileDef *iff, FILE *fp); +static void generateTypeDefLink(sipSpec *pt, ifaceFileDef *iff, FILE *fp); +static int overloadHasDocstring(sipSpec *pt, overDef *od, memberDef *md); +static int hasDocstring(sipSpec *pt, overDef *od, memberDef *md, + ifaceFileDef *scope); +static void generateDocstring(sipSpec *pt, overDef *overs, memberDef *md, + const char *scope_name, classDef *scope_scope, FILE *fp); +static int overloadHasClassDocstring(sipSpec *pt, ctorDef *ct); +static int hasClassDocstring(sipSpec *pt, classDef *cd); +static void generateClassDocstring(sipSpec *pt, classDef *cd, FILE *fp); +static int isDefaultAPI(sipSpec *pt, apiVersionRangeDef *avd); +static void generateExplicitDocstring(codeBlock *docstring, FILE *fp); +static int copyConstRefArg(argDef *ad); + + +/* + * Generate the code from a specification. + */ +void generateCode(sipSpec *pt, char *codeDir, char *buildfile, char *docFile, + const char *srcSuffix, int except, int trace, int releaseGIL, + int parts, stringList *xsl, const char *consModule, int docs) +{ + exceptions = except; + tracing = trace; + release_gil = releaseGIL; + generating_c = pt->genc; + docstrings = docs; + + if (srcSuffix == NULL) + srcSuffix = (generating_c ? ".c" : ".cpp"); + + /* Generate the documentation. */ + if (docFile != NULL) + generateDocumentation(pt,docFile); + + /* Generate the code. */ + if (codeDir != NULL) + { + if (isComposite(pt->module)) + generateCompositeCpp(pt, codeDir); + else if (isConsolidated(pt->module)) + { + moduleDef *mod; + + for (mod = pt->modules; mod != NULL; mod = mod->next) + if (mod->container == pt->module) + generateCpp(pt, mod, codeDir, srcSuffix, parts, xsl); + + generateConsolidatedCpp(pt, codeDir, srcSuffix); + } + else if (consModule != NULL) + generateComponentCpp(pt, codeDir, consModule); + else + generateCpp(pt, pt->module, codeDir, srcSuffix, parts, xsl); + } + + /* Generate the build file. */ + if (buildfile != NULL) + generateBuildFile(pt, buildfile, srcSuffix, consModule); +} + + +/* + * Generate the documentation. + */ +static void generateDocumentation(sipSpec *pt, const char *docFile) +{ + FILE *fp; + codeBlock *cb; + + fp = createFile(pt->module, docFile, NULL); + + for (cb = pt->docs; cb != NULL; cb = cb->next) + fputs(cb->frag, fp); + + closeFile(fp); +} + + +/* + * Generate the build file. + */ +static void generateBuildFile(sipSpec *pt, const char *buildFile, + const char *srcSuffix, const char *consModule) +{ + const char *mname = pt->module->name; + FILE *fp; + + fp = createFile(pt->module, buildFile, NULL); + + prcode(fp, "target = %s\nsources =", mname); + + if (isComposite(pt->module)) + prcode(fp, " sip%scmodule.c", mname); + else if (isConsolidated(pt->module)) + { + moduleDef *mod; + + for (mod = pt->modules; mod != NULL; mod = mod->next) + if (mod->container == pt->module) + generateBuildFileSources(pt, mod, srcSuffix, fp); + + prcode(fp, " sip%scmodule%s", mname, srcSuffix); + } + else if (consModule == NULL) + generateBuildFileSources(pt, pt->module, srcSuffix, fp); + else + prcode(fp, " sip%scmodule.c", mname); + + if (isConsolidated(pt->module)) + { + moduleDef *mod; + + prcode(fp, "\nheaders ="); + + for (mod = pt->modules; mod != NULL; mod = mod->next) + if (mod->container == pt->module) + prcode(fp, " sipAPI%s.h", mod->name); + } + else if (!isComposite(pt->module) && consModule == NULL) + prcode(fp, "\nheaders = sipAPI%s.h", mname); + + prcode(fp, "\n"); + + closeFile(fp); +} + + +/* + * Generate the list of source files for a module. + */ +static void generateBuildFileSources(sipSpec *pt, moduleDef *mod, + const char *srcSuffix, FILE *fp) +{ + const char *mname = mod->name; + + if (mod->parts) + { + int p; + + for (p = 0; p < mod->parts; ++p) + prcode(fp, " sip%spart%d%s", mname, p, srcSuffix); + } + else + { + ifaceFileDef *iff; + + prcode(fp, " sip%scmodule%s", mname, srcSuffix); + + for (iff = pt->ifacefiles; iff != NULL; iff = iff->next) + { + if (iff->module != mod) + continue; + + if (iff->type == exception_iface) + continue; + + if (iff->api_range != NULL) + prcode(fp, " sip%s%F_%d%s", mname, iff->fqcname, iff->api_range->index, srcSuffix); + else + prcode(fp, " sip%s%F%s", mname, iff->fqcname, srcSuffix); + } + } +} + + +/* + * Generate an expression in C++. + */ +void generateExpression(valueDef *vd, int in_str, FILE *fp) +{ + while (vd != NULL) + { + if (vd->vunop != '\0') + prcode(fp,"%c",vd->vunop); + + switch (vd->vtype) + { + case qchar_value: + prcode(fp,"'%c'",vd->u.vqchar); + break; + + case string_value: + { + const char *quote = (in_str ? "\\\"" : "\""); + + prcode(fp,"%s%s%s", quote, vd->u.vstr, quote); + } + + break; + + case numeric_value: + prcode(fp,"%l",vd->u.vnum); + break; + + case real_value: + prcode(fp,"%g",vd->u.vreal); + break; + + case scoped_value: + if (prcode_xml) + prScopedName(fp, vd->u.vscp, "."); + else + prcode(fp, "%S", vd->u.vscp); + + break; + + case fcall_value: + generateSimpleFunctionCall(vd->u.fcd,fp); + break; + } + + if (vd->vbinop != '\0') + prcode(fp,"%c",vd->vbinop); + + vd = vd->next; + } +} + + +/* + * Generate the C++ internal module API header file. + */ +static void generateInternalAPIHeader(sipSpec *pt, moduleDef *mod, + const char *codeDir, stringList *xsl) +{ + char *hfile; + const char *mname = mod->name; + int noIntro; + FILE *fp; + nameDef *nd; + moduleDef *imp; + moduleListDef *mld; + + hfile = concat(codeDir, "/sipAPI", mname, ".h",NULL); + fp = createFile(mod, hfile, "Internal module API header file."); + + /* Include files. */ + + prcode(fp, +"\n" +"#ifndef _%sAPI_H\n" +"#define _%sAPI_H\n" +"\n" +"\n" +"#include <sip.h>\n" + , mname + , mname); + + if (pluginPyQt4(pt)) + prcode(fp, +"\n" +"#include <QMetaType>\n" + ); + + /* Define the enabled features. */ + noIntro = TRUE; + + for (imp = pt->modules; imp != NULL; imp = imp->next) + { + qualDef *qd; + + for (qd = imp->qualifiers; qd != NULL; qd = qd->next) + if (qd->qtype == feature_qualifier && !excludedFeature(xsl, qd)) + { + if (noIntro) + { + prcode(fp, +"\n" +"/* These are the features that are enabled. */\n" + ); + + noIntro = FALSE; + } + + prcode(fp, +"#define SIP_FEATURE_%s\n" + , qd->name); + } + } + + if (!noIntro) + prcode(fp, +"\n" + ); + + generateCppCodeBlock(pt->exphdrcode, fp); + generateCppCodeBlock(mod->hdrcode, fp); + + /* Shortcuts that hide the messy detail of the APIs. */ + noIntro = TRUE; + + for (nd = pt->namecache; nd != NULL; nd = nd->next) + { + if (!isUsedName(nd)) + continue; + + if (noIntro) + { + prcode(fp, +"\n" +"/*\n" +" * Convenient names to refer to various strings defined in this module.\n" +" * Only the class names are part of the public API.\n" +" */\n" + ); + + noIntro = FALSE; + } + + prcode(fp, +"#define %n %d\n" +"#define %N &sipStrings_%s[%d]\n" + , nd, (int)nd->offset + , nd, pt->module->name, (int)nd->offset); + } + + prcode(fp, +"\n" +"#define sipMalloc sipAPI_%s->api_malloc\n" +"#define sipFree sipAPI_%s->api_free\n" +"#define sipBuildResult sipAPI_%s->api_build_result\n" +"#define sipCallMethod sipAPI_%s->api_call_method\n" +"#define sipParseResult sipAPI_%s->api_parse_result\n" +"#define sipParseArgs sipAPI_%s->api_parse_args\n" +"#define sipParseKwdArgs sipAPI_%s->api_parse_kwd_args\n" +"#define sipParsePair sipAPI_%s->api_parse_pair\n" +"#define sipCommonDtor sipAPI_%s->api_common_dtor\n" +"#define sipConvertFromSequenceIndex sipAPI_%s->api_convert_from_sequence_index\n" +"#define sipConvertFromVoidPtr sipAPI_%s->api_convert_from_void_ptr\n" +"#define sipConvertToVoidPtr sipAPI_%s->api_convert_to_void_ptr\n" +"#define sipAddException sipAPI_%s->api_add_exception\n" +"#define sipNoFunction sipAPI_%s->api_no_function\n" +"#define sipNoMethod sipAPI_%s->api_no_method\n" +"#define sipAbstractMethod sipAPI_%s->api_abstract_method\n" +"#define sipBadClass sipAPI_%s->api_bad_class\n" +"#define sipBadCatcherResult sipAPI_%s->api_bad_catcher_result\n" +"#define sipBadCallableArg sipAPI_%s->api_bad_callable_arg\n" +"#define sipBadOperatorArg sipAPI_%s->api_bad_operator_arg\n" +"#define sipTrace sipAPI_%s->api_trace\n" +"#define sipTransferBack sipAPI_%s->api_transfer_back\n" +"#define sipTransferTo sipAPI_%s->api_transfer_to\n" +"#define sipTransferBreak sipAPI_%s->api_transfer_break\n" +"#define sipSimpleWrapper_Type sipAPI_%s->api_simplewrapper_type\n" +"#define sipWrapper_Type sipAPI_%s->api_wrapper_type\n" +"#define sipWrapperType_Type sipAPI_%s->api_wrappertype_type\n" +"#define sipVoidPtr_Type sipAPI_%s->api_voidptr_type\n" +"#define sipGetPyObject sipAPI_%s->api_get_pyobject\n" +"#define sipGetCppPtr sipAPI_%s->api_get_cpp_ptr\n" +"#define sipGetComplexCppPtr sipAPI_%s->api_get_complex_cpp_ptr\n" +"#define sipIsPyMethod sipAPI_%s->api_is_py_method\n" +"#define sipCallHook sipAPI_%s->api_call_hook\n" +"#define sipStartThread sipAPI_%s->api_start_thread\n" +"#define sipEndThread sipAPI_%s->api_end_thread\n" +"#define sipConnectRx sipAPI_%s->api_connect_rx\n" +"#define sipDisconnectRx sipAPI_%s->api_disconnect_rx\n" +"#define sipRaiseUnknownException sipAPI_%s->api_raise_unknown_exception\n" +"#define sipRaiseTypeException sipAPI_%s->api_raise_type_exception\n" +"#define sipBadLengthForSlice sipAPI_%s->api_bad_length_for_slice\n" +"#define sipAddTypeInstance sipAPI_%s->api_add_type_instance\n" +"#define sipGetAddress sipAPI_%s->api_get_address\n" +"#define sipFreeSipslot sipAPI_%s->api_free_sipslot\n" +"#define sipSameSlot sipAPI_%s->api_same_slot\n" +"#define sipPySlotExtend sipAPI_%s->api_pyslot_extend\n" +"#define sipConvertRx sipAPI_%s->api_convert_rx\n" +"#define sipAddDelayedDtor sipAPI_%s->api_add_delayed_dtor\n" +"#define sipCanConvertToType sipAPI_%s->api_can_convert_to_type\n" +"#define sipConvertToType sipAPI_%s->api_convert_to_type\n" +"#define sipForceConvertToType sipAPI_%s->api_force_convert_to_type\n" +"#define sipCanConvertToEnum sipAPI_%s->api_can_convert_to_enum\n" +"#define sipReleaseType sipAPI_%s->api_release_type\n" +"#define sipConvertFromType sipAPI_%s->api_convert_from_type\n" +"#define sipConvertFromNewType sipAPI_%s->api_convert_from_new_type\n" +"#define sipConvertFromEnum sipAPI_%s->api_convert_from_enum\n" +"#define sipGetState sipAPI_%s->api_get_state\n" +"#define sipLong_AsUnsignedLong sipAPI_%s->api_long_as_unsigned_long\n" +"#define sipExportSymbol sipAPI_%s->api_export_symbol\n" +"#define sipImportSymbol sipAPI_%s->api_import_symbol\n" +"#define sipFindType sipAPI_%s->api_find_type\n" +"#define sipFindNamedEnum sipAPI_%s->api_find_named_enum\n" +"#define sipBytes_AsChar sipAPI_%s->api_bytes_as_char\n" +"#define sipBytes_AsString sipAPI_%s->api_bytes_as_string\n" +"#define sipString_AsASCIIChar sipAPI_%s->api_string_as_ascii_char\n" +"#define sipString_AsASCIIString sipAPI_%s->api_string_as_ascii_string\n" +"#define sipString_AsLatin1Char sipAPI_%s->api_string_as_latin1_char\n" +"#define sipString_AsLatin1String sipAPI_%s->api_string_as_latin1_string\n" +"#define sipString_AsUTF8Char sipAPI_%s->api_string_as_utf8_char\n" +"#define sipString_AsUTF8String sipAPI_%s->api_string_as_utf8_string\n" +"#define sipUnicode_AsWChar sipAPI_%s->api_unicode_as_wchar\n" +"#define sipUnicode_AsWString sipAPI_%s->api_unicode_as_wstring\n" +"#define sipConvertFromConstVoidPtr sipAPI_%s->api_convert_from_const_void_ptr\n" +"#define sipConvertFromVoidPtrAndSize sipAPI_%s->api_convert_from_void_ptr_and_size\n" +"#define sipConvertFromConstVoidPtrAndSize sipAPI_%s->api_convert_from_const_void_ptr_and_size\n" +"#define sipInvokeSlot sipAPI_%s->api_invoke_slot\n" +"#define sipSaveSlot sipAPI_%s->api_save_slot\n" +"#define sipClearAnySlotReference sipAPI_%s->api_clear_any_slot_reference\n" +"#define sipVisitSlot sipAPI_%s->api_visit_slot\n" +"#define sipWrappedTypeName(wt) ((wt)->type->td_cname)\n" +"#define sipDeprecated sipAPI_%s->api_deprecated\n" +"#define sipKeepReference sipAPI_%s->api_keep_reference\n" +"#define sipRegisterPyType sipAPI_%s->api_register_py_type\n" +"#define sipTypeFromPyTypeObject sipAPI_%s->api_type_from_py_type_object\n" +"#define sipTypeScope sipAPI_%s->api_type_scope\n" +"#define sipResolveTypedef sipAPI_%s->api_resolve_typedef\n" +"#define sipRegisterAttributeGetter sipAPI_%s->api_register_attribute_getter\n" +"#define sipIsAPIEnabled sipAPI_%s->api_is_api_enabled\n" +"#define sipExportModule sipAPI_%s->api_export_module\n" +"#define sipInitModule sipAPI_%s->api_init_module\n" +"\n" +"/* These are deprecated. */\n" +"#define sipMapStringToClass sipAPI_%s->api_map_string_to_class\n" +"#define sipMapIntToClass sipAPI_%s->api_map_int_to_class\n" +"#define sipFindClass sipAPI_%s->api_find_class\n" +"#define sipFindMappedType sipAPI_%s->api_find_mapped_type\n" +"#define sipWrapper_Check(w) PyObject_TypeCheck((w), sipAPI_%s->api_wrapper_type)\n" +"#define sipGetWrapper(p, wt) sipGetPyObject((p), (wt)->type)\n" +"#define sipReleaseInstance(p, wt, s) sipReleaseType((p), (wt)->type, (s))\n" +"#define sipReleaseMappedType sipReleaseType\n" +"#define sipCanConvertToInstance(o, wt, f) sipCanConvertToType((o), (wt)->type, (f))\n" +"#define sipCanConvertToMappedType sipCanConvertToType\n" +"#define sipConvertToInstance(o, wt, t, f, s, e) sipConvertToType((o), (wt)->type, (t), (f), (s), (e))\n" +"#define sipConvertToMappedType sipConvertToType\n" +"#define sipForceConvertToInstance(o, wt, t, f, s, e) sipForceConvertToType((o), (wt)->type, (t), (f), (s), (e))\n" +"#define sipForceConvertToMappedType sipForceConvertToType\n" +"#define sipConvertFromInstance(p, wt, t) sipConvertFromType((p), (wt)->type, (t))\n" +"#define sipConvertFromMappedType sipConvertFromType\n" +"#define sipConvertFromNamedEnum(v, pt) sipConvertFromEnum((v), ((sipEnumTypeObject *)(pt))->type)\n" +"#define sipConvertFromNewInstance(p, wt, t) sipConvertFromNewType((p), (wt)->type, (t))\n" + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname + ,mname); + + /* The name strings. */ + prcode(fp, +"\n" +"/* The strings used by this module. */\n" +"extern const char sipStrings_%s[];\n" + , pt->module->name); + + /* The unscoped enum macros. */ + generateEnumMacros(pt, mod, NULL, NULL, fp); + + generateModuleAPI(pt, mod, fp); + + prcode(fp, +"\n" +"/* The SIP API, this module's API and the APIs of any imported modules. */\n" +"extern const sipAPIDef *sipAPI_%s;\n" +"extern sipExportedModuleDef sipModuleAPI_%s;\n" + , mname + , mname, mname); + + for (mld = mod->allimports; mld != NULL; mld = mld->next) + { + generateImportedModuleAPI(pt, mod, mld->module, fp); + + prcode(fp, +"extern const sipExportedModuleDef *sipModuleAPI_%s_%s;\n" + , mname, mld->module->name); + } + + if (pluginPyQt4(pt)) + prcode(fp, +"\n" +"typedef const QMetaObject *(*sip_qt_metaobject_func)(sipSimpleWrapper *,sipTypeDef *);\n" +"extern sip_qt_metaobject_func sip_%s_qt_metaobject;\n" +"\n" +"typedef int (*sip_qt_metacall_func)(sipSimpleWrapper *,sipTypeDef *,QMetaObject::Call,int,void **);\n" +"extern sip_qt_metacall_func sip_%s_qt_metacall;\n" +"\n" +"typedef int (*sip_qt_metacast_func)(sipSimpleWrapper *,sipTypeDef *,const char *);\n" +"extern sip_qt_metacast_func sip_%s_qt_metacast;\n" + , mname + , mname + , mname); + + /* + * Note that we don't forward declare the virtual handlers. This is + * because we would need to #include everything needed for their argument + * types. + */ + prcode(fp, +"\n" +"#endif\n" + ); + + closeFile(fp); + free(hfile); +} + + +/* + * Return the filename of a source code part on the heap. + */ +static char *makePartName(const char *codeDir, const char *mname, int part, + const char *srcSuffix) +{ + char buf[50]; + + sprintf(buf, "part%d", part); + + return concat(codeDir, "/sip", mname, buf, srcSuffix, NULL); +} + + +/* + * Generate the C code for a composite module. + */ +static void generateCompositeCpp(sipSpec *pt, const char *codeDir) +{ + char *cppfile; + moduleDef *mod; + FILE *fp; + + cppfile = concat(codeDir, "/sip", pt->module->name, "cmodule.c", NULL); + fp = createCompilationUnit(pt->module, cppfile, "Composite module code."); + + prcode(fp, +"\n" +"#include <Python.h>\n" +"\n" +"\n" +"static void sip_import_component_module(PyObject *d, const char *name)\n" +"{\n" +"#if PY_VERSION_HEX >= 0x02050000\n" +" PyObject *mod = PyImport_ImportModule(name);\n" +"#else\n" +" PyObject *mod = PyImport_ImportModule((char *)name);\n" +"#endif\n" +"\n" +" /*\n" +" * Note that we don't complain if the module can't be imported. This\n" +" * is a favour to Linux distro packagers who like to split PyQt into\n" +" * different sub-packages.\n" +" */\n" +" if (mod)\n" +" {\n" +" PyDict_Merge(d, PyModule_GetDict(mod), 0);\n" +" Py_DECREF(mod);\n" +" }\n" +"}\n" + ); + + generateModInitStart(pt->module, TRUE, fp); + generateModDefinition(pt->module, "NULL", fp); + + prcode(fp, +"\n" +" PyObject *sipModule, *sipModuleDict;\n" +"\n" +"#if PY_MAJOR_VERSION >= 3\n" +" sipModule = PyModule_Create(&sip_module_def);\n" +"#else\n" +" sipModule = Py_InitModule(\"%s\", 0);\n" +"#endif\n" +"\n" +" if (sipModule == NULL)\n" +" SIP_MODULE_RETURN(NULL);\n" +"\n" +" sipModuleDict = PyModule_GetDict(sipModule);\n" +"\n" + , pt->module->fullname->text); + + for (mod = pt->modules; mod != NULL; mod = mod->next) + if (mod->container == pt->module) + prcode(fp, +" sip_import_component_module(sipModuleDict, \"%s\");\n" + , mod->fullname->text); + + prcode(fp, +"\n" +" PyErr_Clear();\n" +"\n" +" SIP_MODULE_RETURN(sipModule);\n" +"}\n" + ); + + closeFile(fp); + free(cppfile); +} + + +/* + * Generate the C/C++ code for a consolidated module. + */ +static void generateConsolidatedCpp(sipSpec *pt, const char *codeDir, + const char *srcSuffix) +{ + char *cppfile; + const char *mname = pt->module->name; + moduleDef *mod; + FILE *fp; + + cppfile = concat(codeDir, "/sip", mname, "cmodule", srcSuffix, NULL); + fp = createCompilationUnit(pt->module, cppfile, "Consolidated module code."); + + prcode(fp, +"\n" +"#include <Python.h>\n" +"#include <string.h>\n" +"#include <sip.h>\n" + ); + + generateNameCache(pt, fp); + + prcode(fp, +"\n" +"\n" +"/* The component module initialisers. */\n" + ); + + /* Declare the component module initialisers. */ + for (mod = pt->modules; mod != NULL; mod = mod->next) + if (mod->container == pt->module) + prcode(fp, +"#if PY_MAJOR_VERSION >= 3\n" +"extern PyObject *sip_init_%s(void);\n" +"#else\n" +"extern void sip_init_%s(void);\n" +"#endif\n" + , mod->name + , mod->name); + + /* Generate the init function. */ + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static PyObject *sip_init(PyObject *, PyObject *);}\n" + ); + + prcode(fp, +"static PyObject *sip_init(PyObject *%s, PyObject *arg)\n" +"{\n" +" struct component {\n" +" const char *name;\n" +"#if PY_MAJOR_VERSION >= 3\n" +" PyObject *(*init)(void);\n" +"#else\n" +" void (*init)(void);\n" +"#endif\n" +" };\n" +"\n" +" static struct component components[] = {\n" + , (generating_c ? "self" : "")); + + for (mod = pt->modules; mod != NULL; mod = mod->next) + if (mod->container == pt->module) + prcode(fp, +" {\"%s\", sip_init_%s},\n" + , mod->fullname->text, mod->name); + + prcode(fp, +" {NULL, NULL}\n" +" };\n" +"\n" +" const char *name;\n" +" struct component *scd;\n" +"\n" +"#if PY_MAJOR_VERSION >= 3\n" +" name = PyBytes_AsString(arg);\n" +"#else\n" +" name = PyString_AsString(arg);\n" +"#endif\n" +"\n" +" if (name == NULL)\n" +" return NULL;\n" +"\n" +" for (scd = components; scd->name != NULL; ++scd)\n" +" if (strcmp(scd->name, name) == 0)\n" +"#if PY_MAJOR_VERSION >= 3\n" +" return (*scd->init)();\n" +"#else\n" +" {\n" +" (*scd->init)();\n" +"\n" +" Py_INCREF(Py_None);\n" +" return Py_None;\n" +" }\n" +"#endif\n" +"\n" +" PyErr_Format(PyExc_ImportError, \"unknown component module %%s\", name);\n" +"\n" +" return NULL;\n" +"}\n" + ); + + generateModInitStart(pt->module, generating_c, fp); + + prcode(fp, +" static PyMethodDef sip_methods[] = {\n" +" {SIP_MLNAME_CAST(\"init\"), sip_init, METH_O, NULL},\n" +" {NULL, NULL, 0, NULL}\n" +" };\n" + ); + + generateModDefinition(pt->module, "sip_methods", fp); + + prcode(fp, +"\n" +"#if PY_MAJOR_VERSION >= 3\n" +" return PyModule_Create(&sip_module_def);\n" +"#else\n" +" Py_InitModule(\"%s\", sip_methods);\n" +"#endif\n" +"}\n" + , mname); + + closeFile(fp); + free(cppfile); +} + + +/* + * Generate the C/C++ code for a component module. + */ +static void generateComponentCpp(sipSpec *pt, const char *codeDir, + const char *consModule) +{ + char *cppfile; + FILE *fp; + + cppfile = concat(codeDir, "/sip", pt->module->name, "cmodule.c", NULL); + fp = createCompilationUnit(pt->module, cppfile, "Component module code."); + + prcode(fp, +"\n" +"#include <Python.h>\n" + ); + + generateModInitStart(pt->module, TRUE, fp); + generateModDefinition(pt->module, "NULL", fp); + + prcode(fp, +" PyObject *sip_mod, *sip_result;\n" +"\n" +" /* Import the consolidated module. */\n" +" if ((sip_mod = PyImport_ImportModule(\"%s\")) == NULL)\n" +" SIP_MODULE_RETURN(NULL);\n" +"\n" + , consModule); + + prcode(fp, +" /* Ask the consolidated module to do the initialistion. */\n" +"#if PY_MAJOR_VERSION >= 3\n" +" sip_result = PyObject_CallMethod(sip_mod, \"init\", \"y\", \"%s\");\n" +"#else\n" +" sip_result = PyObject_CallMethod(sip_mod, \"init\", \"s\", \"%s\");\n" +"#endif\n" +" Py_DECREF(sip_mod);\n" +"\n" +"#if PY_MAJOR_VERSION >= 3\n" +" return sip_result;\n" +"#else\n" +" Py_XDECREF(sip_result);\n" +"#endif\n" +"}\n" + , pt->module->fullname->text + , pt->module->fullname->text); + + closeFile(fp); + free(cppfile); +} + + +/* + * Generate the name cache definition. + */ +static void generateNameCache(sipSpec *pt, FILE *fp) +{ + nameDef *nd; + + prcode(fp, +"\n" +"/* Define the strings used by this module. */\n" + ); + + if (isConsolidated(pt->module)) + prcode(fp, +"extern const char sipStrings_%s[];\n" + , pt->module->name); + + prcode(fp, +"const char sipStrings_%s[] = {\n" + , pt->module->name); + + for (nd = pt->namecache; nd != NULL; nd = nd->next) + { + const char *cp; + + if (!isUsedName(nd) || isSubstring(nd)) + continue; + + prcode(fp, " "); + + for (cp = nd->text; *cp != '\0'; ++cp) + prcode(fp, "'%c', ", *cp); + + prcode(fp, "0,\n"); + } + + prcode(fp, "};\n"); +} + + +/* + * Generate the C/C++ code. + */ +static void generateCpp(sipSpec *pt, moduleDef *mod, const char *codeDir, + const char *srcSuffix, int parts, stringList *xsl) +{ + char *cppfile; + const char *mname = mod->name; + int nrSccs = 0, files_in_part, max_per_part, this_part, mod_nr, enum_idx; + int is_inst_class, is_inst_voidp, is_inst_char, is_inst_string; + int is_inst_int, is_inst_long, is_inst_ulong, is_inst_longlong; + int is_inst_ulonglong, is_inst_double, nr_enummembers, is_api_versions; + int is_versioned_functions; + int hasexternal = FALSE, slot_extenders = FALSE, ctor_extenders = FALSE; + FILE *fp; + moduleListDef *mld; + classDef *cd; + memberDef *md; + enumDef *ed; + ifaceFileDef *iff; + virtHandlerDef *vhd; + exceptionDef *xd; + + /* Calculate the number of files in each part. */ + if (parts) + { + int nr_files = 1; + + for (iff = pt->ifacefiles; iff != NULL; iff = iff->next) + if (iff->module == mod && iff->type != exception_iface) + ++nr_files; + + max_per_part = (nr_files + parts - 1) / parts; + files_in_part = 1; + this_part = 0; + + cppfile = makePartName(codeDir, mname, 0, srcSuffix); + } + else + cppfile = concat(codeDir, "/sip", mname, "cmodule", srcSuffix, NULL); + + fp = createCompilationUnit(mod, cppfile, "Module code."); + + prcode(fp, +"\n" +"#include \"sipAPI%s.h\"\n" + , mname); + + /* + * Include the library headers for types used by virtual handlers, module + * level functions, module level variables and Qt meta types. + */ + generateUsedIncludes(mod->used, fp); + + /* + * If there should be a Qt support API then generate stubs values for the + * optional parts. These should be undefined in %ModuleCode if a C++ + * implementation is provided. + */ + if (mod->qobjclass >= 0) + prcode(fp, +"\n" +"#define sipQtCreateUniversalSignal 0\n" +"#define sipQtFindUniversalSignal 0\n" +"#define sipQtEmitSignal 0\n" +"#define sipQtConnectPySignal 0\n" +"#define sipQtDisconnectPySignal 0\n" + ); + + /* Define the names. */ + if (mod->container == NULL) + generateNameCache(pt, fp); + + /* Generate the C++ code blocks. */ + generateCppCodeBlock(mod->cppcode, fp); + + /* Generate any virtual handler declarations. */ + for (vhd = mod->virthandlers; vhd != NULL; vhd = vhd->next) + if (!isDuplicateVH(vhd)) + generateVirtualHandler(vhd, fp); + + /* Generate the global functions. */ + for (md = mod->othfuncs; md != NULL; md = md->next) + if (md->slot == no_slot) + generateOrdinaryFunction(pt, mod, NULL, NULL, md, fp); + else + { + overDef *od; + + /* + * Make sure that there is still an overload and we haven't moved + * them all to classes. + */ + for (od = mod->overs; od != NULL; od = od->next) + if (od->common == md) + { + generateSlot(mod, NULL, NULL, md, fp); + slot_extenders = TRUE; + break; + } + } + + /* Generate any class specific ctor or slot extenders. */ + for (cd = mod->proxies; cd != NULL; cd = cd->next) + { + if (cd->ctors != NULL) + { + generateTypeInit(cd, mod, fp); + ctor_extenders = TRUE; + } + + for (md = cd->members; md != NULL; md = md->next) + { + generateSlot(mod, cd, NULL, md, fp); + slot_extenders = TRUE; + } + } + + /* Generate any ctor extender table. */ + if (ctor_extenders) + { + prcode(fp, +"\n" +"static sipInitExtenderDef initExtenders[] = {\n" + ); + + for (cd = mod->proxies; cd != NULL; cd = cd->next) + if (cd->ctors != NULL) + { + prcode(fp, +" {%P, init_%L, ", cd->iff->api_range, cd->iff); + + generateEncodedType(mod, cd, 0, fp); + + prcode(fp, ", NULL},\n" + ); + } + + prcode(fp, +" {-1, NULL, {0, 0, 0}, NULL}\n" +"};\n" + ); + } + + /* Generate any slot extender table. */ + if (slot_extenders) + { + prcode(fp, +"\n" +"static sipPySlotExtenderDef slotExtenders[] = {\n" + ); + + for (md = mod->othfuncs; md != NULL; md = md->next) + { + overDef *od; + + if (md->slot == no_slot) + continue; + + for (od = mod->overs; od != NULL; od = od->next) + if (od->common == md) + { + if (py2OnlySlot(md->slot)) + prcode(fp, +"#if PY_MAJOR_VERSION < 3\n" + ); + else if (py2_5LaterSlot(md->slot)) + prcode(fp, +"#if PY_VERSION_HEX >= 0x02050000\n" + ); + + prcode(fp, +" {(void *)slot_%s, %s, {0, 0, 0}},\n" + , md->pyname->text, slotName(md->slot)); + + if (py2OnlySlot(md->slot) || py2_5LaterSlot(md->slot)) + prcode(fp, +"#endif\n" + ); + + break; + } + } + + for (cd = mod->proxies; cd != NULL; cd = cd->next) + for (md = cd->members; md != NULL; md = md->next) + { + if (py2OnlySlot(md->slot)) + prcode(fp, +"#if PY_MAJOR_VERSION < 3\n" + ); + else if (py2_5LaterSlot(md->slot)) + prcode(fp, +"#if PY_VERSION_HEX >= 0x02050000\n" + ); + + prcode(fp, +" {(void *)slot_%L_%s, %s, ", cd->iff, md->pyname->text, slotName(md->slot)); + + generateEncodedType(mod, cd, 0, fp); + + prcode(fp, "},\n" + ); + + if (py2OnlySlot(md->slot) || py2_5LaterSlot(md->slot)) + prcode(fp, +"#endif\n" + ); + } + + prcode(fp, +" {NULL, (sipPySlotType)0, {0, 0, 0}}\n" +"};\n" + ); + } + + /* Generate the global access functions. */ + generateAccessFunctions(pt, mod, NULL, fp); + + /* Generate any sub-class convertors. */ + nrSccs = generateSubClassConvertors(pt, mod, fp); + + /* Generate the external classes table if needed. */ + for (cd = pt->classes; cd != NULL; cd = cd->next) + { + if (!isExternal(cd)) + continue; + + if (cd->iff->module != mod) + continue; + + if (!hasexternal) + { + prcode(fp, +"\n" +"\n" +"/* This defines each external type declared in this module, */\n" +"static sipExternalTypeDef externalTypesTable[] = {\n" + ); + + hasexternal = TRUE; + } + + prcode(fp, +" {%d, \"", cd->iff->ifacenr); + prScopedName(fp, classFQCName(cd), "."); + prcode(fp,"\"},\n" + ); + } + + if (hasexternal) + prcode(fp, +" {-1, NULL}\n" +"};\n" + ); + + /* Generate any enum slot tables. */ + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + memberDef *slot; + + if (ed->module != mod || ed->fqcname == NULL) + continue; + + if (ed->slots == NULL) + continue; + + for (slot = ed->slots; slot != NULL; slot = slot->next) + generateSlot(mod, NULL, ed, slot, fp); + + prcode(fp, +"\n" +"static sipPySlotDef slots_%C[] = {\n" + , ed->fqcname); + + for (slot = ed->slots; slot != NULL; slot = slot->next) + { + const char *stype; + + if ((stype = slotName(slot->slot)) != NULL) + { + if (py2OnlySlot(slot->slot)) + prcode(fp, +"#if PY_MAJOR_VERSION < 3\n" + ); + else if (py2_5LaterSlot(slot->slot)) + prcode(fp, +"#if PY_VERSION_HEX >= 0x02050000\n" + ); + + prcode(fp, +" {(void *)slot_%C_%s, %s},\n" + , ed->fqcname, slot->pyname->text, stype); + + if (py2OnlySlot(slot->slot) || py2_5LaterSlot(slot->slot)) + prcode(fp, +"#endif\n" + ); + } + } + + prcode(fp, +" {0, (sipPySlotType)0}\n" +"};\n" +"\n" + ); + } + + /* Generate the enum type structures. */ + enum_idx = 0; + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + int type_nr = -1; + apiVersionRangeDef *avr = NULL; + + if (ed->module != mod || ed->fqcname == NULL) + continue; + + if (ed->ecd != NULL) + { + if (isTemplateClass(ed->ecd)) + continue; + + type_nr = ed->ecd->iff->first_alt->ifacenr; + avr = ed->ecd->iff->api_range; + } + else if (ed->emtd != NULL) + { + type_nr = ed->emtd->iff->first_alt->ifacenr; + avr = ed->emtd->iff->api_range; + } + + if (enum_idx == 0) + { + prcode(fp, +"static sipEnumTypeDef enumTypes[] = {\n" + ); + } + + ed->enum_idx = enum_idx++; + + prcode(fp, +" {{%P, ", avr); + + if (ed->next_alt != NULL) + prcode(fp, "&enumTypes[%d].etd_base", ed->next_alt->enum_idx); + else + prcode(fp, "0"); + + prcode(fp, ", 0, SIP_TYPE_ENUM, %n, {0}}, %n, %d, ", ed->cname, ed->pyname, type_nr); + + if (ed->slots != NULL) + prcode(fp, "slots_%C", ed->fqcname); + else + prcode(fp, "NULL"); + + prcode(fp, "},\n" + ); + } + + if (enum_idx != 0) + prcode(fp, +"};\n" + ); + + nr_enummembers = generateEnumMemberTable(pt, mod, NULL, NULL, fp); + + /* Generate the types table. */ + if (mod->nrtypes > 0) + generateTypesTable(pt, mod, fp); + + if (mod->nrtypedefs > 0) + { + typedefDef *td; + + prcode(fp, +"\n" +"\n" +"/*\n" +" * These define each typedef in this module.\n" +" */\n" +"static sipTypedefDef typedefsTable[] = {\n" + ); + + for (td = pt->typedefs; td != NULL; td = td->next) + { + if (td->module != mod) + continue; + + prcode(fp, +" {\"%S\", \"", td->fqname); + + /* The default behaviour isn't right in a couple of cases. */ + if (td->type.atype == longlong_type) + prcode(fp, "long long"); + else if (td->type.atype == ulonglong_type) + prcode(fp, "unsigned long long"); + else + prcode(fp, "%b", &td->type); + + prcode(fp, "\"},\n" + ); + } + + prcode(fp, +"};\n" + ); + } + + if (mod->nrvirthandlers > 0) + { + prcode(fp, +"\n" +"\n" +"/*\n" +" * This defines the virtual handlers that this module implements and can be\n" +" * used by other modules.\n" +" */\n" +"static sipVirtHandlerFunc virtHandlersTable[] = {\n" + ); + + for (vhd = mod->virthandlers; vhd != NULL; vhd = vhd->next) + if (!isDuplicateVH(vhd)) + prcode(fp, +" (sipVirtHandlerFunc)sipVH_%s_%d,\n" + , mname, vhd->virthandlernr); + + prcode(fp, +"};\n" + ); + } + + if (mod->allimports != NULL) + { + prcode(fp, +"\n" +"\n" +"/* This defines the modules that this module needs to import. */\n" +"static sipImportedModuleDef importsTable[] = {\n" + ); + + for (mld = mod->allimports; mld != NULL; mld = mld->next) + prcode(fp, +" {\"%s\", %d, NULL},\n" + , mld->module->fullname->text, mld->module->version); + + prcode(fp, +" {NULL, -1, NULL}\n" +"};\n" + ); + } + + if (nrSccs > 0) + { + prcode(fp, +"\n" +"\n" +"/* This defines the class sub-convertors that this module defines. */\n" +"static sipSubClassConvertorDef convertorsTable[] = {\n" + ); + + for (cd = pt->classes; cd != NULL; cd = cd->next) + { + if (cd->iff->module != mod) + continue; + + if (cd->convtosubcode == NULL) + continue; + + prcode(fp, +" {sipSubClass_%C, ",classFQCName(cd)); + + generateEncodedType(mod, cd->subbase, 0, fp); + + prcode(fp,", NULL},\n"); + } + + prcode(fp, +" {NULL, {0, 0, 0}, NULL}\n" +"};\n" + ); + } + + /* Generate any license information. */ + if (mod->license != NULL) + { + licenseDef *ld = mod->license; + + prcode(fp, +"\n" +"\n" +"/* Define the module's license. */\n" +"static sipLicenseDef module_license = {\n" + ); + + prcode(fp, +" \"%s\",\n" + , ld->type); + + if (ld->licensee != NULL) + prcode(fp, +" \"%s\",\n" + , ld->licensee); + else + prcode(fp, +" NULL,\n" + ); + + if (ld->timestamp != NULL) + prcode(fp, +" \"%s\",\n" + , ld->timestamp); + else + prcode(fp, +" NULL,\n" + ); + + if (ld->sig != NULL) + prcode(fp, +" \"%s\"\n" + , ld->sig); + else + prcode(fp, +" NULL\n" + ); + + prcode(fp, +"};\n" + ); + } + + /* Generate each instance table. */ + is_inst_class = generateClasses(pt, mod, NULL, fp); + is_inst_voidp = generateVoidPointers(pt, mod, NULL, fp); + is_inst_char = generateChars(pt, mod, NULL, fp); + is_inst_string = generateStrings(pt, mod, NULL, fp); + is_inst_int = generateInts(pt, mod, NULL, fp); + is_inst_long = generateLongs(pt, mod, NULL, fp); + is_inst_ulong = generateUnsignedLongs(pt, mod, NULL, fp); + is_inst_longlong = generateLongLongs(pt, mod, NULL, fp); + is_inst_ulonglong = generateUnsignedLongLongs(pt, mod, NULL, fp); + is_inst_double = generateDoubles(pt, mod, NULL, fp); + + /* Generate any exceptions table. */ + if (mod->nrexceptions > 0) + prcode(fp, +"\n" +"\n" +"static PyObject *exceptionsTable[%d];\n" + , mod->nrexceptions); + + /* Generate any API versions table. */ + if (mod->api_ranges != NULL || mod->api_versions != NULL) + { + apiVersionRangeDef *avr; + + is_api_versions = TRUE; + + prcode(fp, +"\n" +"\n" +"/* This defines the API versions and ranges in use. */\n" +"static int apiVersions[] = {"); + + for (avr = mod->api_ranges; avr != NULL; avr = avr->next) + prcode(fp, "%n, %d, %d, ", avr->api_name, avr->from, avr->to); + + for (avr = mod->api_versions; avr != NULL; avr = avr->next) + prcode(fp, "%n, %d, -1, ", avr->api_name, avr->from); + + prcode(fp, "-1};\n" + ); + } + else + is_api_versions = FALSE; + + /* Generate any versioned global functions. */ + is_versioned_functions = FALSE; + + for (md = mod->othfuncs; md != NULL; md = md->next) + if (md->slot == no_slot) + { + overDef *od; + int has_docstring; + + if (notVersioned(md)) + continue; + + if (!is_versioned_functions) + { + prcode(fp, +"\n" +"\n" +"/* This defines the global functions where all overloads are versioned. */\n" +"static sipVersionedFunctionDef versionedFunctions[] = {\n" + ); + + is_versioned_functions = TRUE; + } + + has_docstring = FALSE; + + if (md->docstring != NULL || (docstrings && hasDocstring(pt, mod->overs, md, NULL))) + has_docstring = TRUE; + + /* + * Every overload has an entry to capture all the version ranges. + */ + for (od = mod->overs; od != NULL; od = od->next) + { + if (od->common != md) + continue; + + prcode(fp, +" {%n, ", md->pyname); + + if (noArgParser(md) || useKeywordArgsFunction(md)) + prcode(fp, "(PyCFunction)func_%s, METH_VARARGS|METH_KEYWORDS", md->pyname->text); + else + prcode(fp, "func_%s, METH_VARARGS", md->pyname->text); + + if (has_docstring) + prcode(fp, ", doc_%s", md->pyname->text); + else + prcode(fp, ", NULL"); + + prcode(fp, ", %P},\n" + , od->api_range); + } + } + + if (is_versioned_functions) + prcode(fp, +" {-1, 0, 0, 0, -1}\n" +"};\n" + ); + + /* Generate any Qt support API. */ + if (mod->qobjclass >= 0) + prcode(fp, +"\n" +"\n" +"/* This defines the Qt support API. */\n" +"\n" +"static sipQtAPI qtAPI = {\n" +" &typesTable[%d],\n" +" sipQtCreateUniversalSignal,\n" +" sipQtFindUniversalSignal,\n" +" sipQtCreateUniversalSlot,\n" +" sipQtDestroyUniversalSlot,\n" +" sipQtFindSlot,\n" +" sipQtConnect,\n" +" sipQtDisconnect,\n" +" sipQtSameSignalSlotName,\n" +" sipQtFindSipslot,\n" +" sipQtEmitSignal,\n" +" sipQtConnectPySignal,\n" +" sipQtDisconnectPySignal\n" +"};\n" + , mod->qobjclass); + + prcode(fp, +"\n" +"\n" +"/* This defines this module. */\n" +"sipExportedModuleDef sipModuleAPI_%s = {\n" +" 0,\n" +" SIP_API_MINOR_NR,\n" +" %n,\n" +" 0,\n" +" %d,\n" +" sipStrings_%s,\n" +" %s,\n" +" %s,\n" +" %d,\n" +" %s,\n" +" %s,\n" +" %d,\n" +" %s,\n" +" %d,\n" +" %s,\n" +" %s,\n" +" %s,\n" +" {%s, %s, %s, %s, %s, %s, %s, %s, %s, %s},\n" +" %s,\n" +" %s,\n" +" %s,\n" +" %s,\n" +" %s,\n" +" NULL,\n" +" %s,\n" +" %s\n" +"};\n" + , mname + , mod->fullname + , mod->version + , pt->module->name + , mod->allimports != NULL ? "importsTable" : "NULL" + , mod->qobjclass >= 0 ? "&qtAPI" : "NULL" + , mod->nrtypes + , mod->nrtypes > 0 ? "typesTable" : "NULL" + , hasexternal ? "externalTypesTable" : "NULL" + , nr_enummembers + , nr_enummembers > 0 ? "enummembers" : "NULL" + , mod->nrtypedefs + , mod->nrtypedefs > 0 ? "typedefsTable" : "NULL" + , mod->nrvirthandlers > 0 ? "virtHandlersTable" : "NULL" + , nrSccs > 0 ? "convertorsTable" : "NULL" + , is_inst_class ? "typeInstances" : "NULL" + , is_inst_voidp ? "voidPtrInstances" : "NULL" + , is_inst_char ? "charInstances" : "NULL" + , is_inst_string ? "stringInstances" : "NULL" + , is_inst_int ? "intInstances" : "NULL" + , is_inst_long ? "longInstances" : "NULL" + , is_inst_ulong ? "unsignedLongInstances" : "NULL" + , is_inst_longlong ? "longLongInstances" : "NULL" + , is_inst_ulonglong ? "unsignedLongLongInstances" : "NULL" + , is_inst_double ? "doubleInstances" : "NULL" + , mod->license != NULL ? "&module_license" : "NULL" + , mod->nrexceptions > 0 ? "exceptionsTable" : "NULL" + , slot_extenders ? "slotExtenders" : "NULL" + , ctor_extenders ? "initExtenders" : "NULL" + , hasDelayedDtors(mod) ? "sipDelayedDtors" : "NULL" + , is_api_versions ? "apiVersions" : "NULL" + , is_versioned_functions ? "versionedFunctions" : "NULL"); + + /* Generate the storage for the external API pointers. */ + prcode(fp, +"\n" +"\n" +"/* The SIP API and the APIs of any imported modules. */\n" +"const sipAPIDef *sipAPI_%s;\n" + , mname); + + for (mld = mod->allimports; mld != NULL; mld = mld->next) + prcode(fp, +"const sipExportedModuleDef *sipModuleAPI_%s_%s;\n" + , mname, mld->module->name); + + if (pluginPyQt4(pt)) + prcode(fp, +"\n" +"sip_qt_metaobject_func sip_%s_qt_metaobject;\n" +"sip_qt_metacall_func sip_%s_qt_metacall;\n" +"sip_qt_metacast_func sip_%s_qt_metacast;\n" + , mname + , mname + , mname); + + /* Generate the Python module initialisation function. */ + + if (mod->container == pt->module) + prcode(fp, +"\n" +"#if PY_MAJOR_VERSION >= 3\n" +"#define SIP_MODULE_DISCARD(r) Py_DECREF(r)\n" +"#define SIP_MODULE_RETURN(r) return (r)\n" +"PyObject *sip_init_%s()\n" +"#else\n" +"#define SIP_MODULE_DISCARD(r)\n" +"#define SIP_MODULE_RETURN(r) return\n" +"void sip_init_%s()\n" +"#endif\n" +"{\n" + , mname + , mname); + else + generateModInitStart(pt->module, generating_c, fp); + + /* Generate the global functions. */ + + prcode(fp, +" static PyMethodDef sip_methods[] = {\n" + ); + + for (md = mod->othfuncs; md != NULL; md = md->next) + if (md->slot == no_slot) + { + int has_docstring; + + if (!notVersioned(md)) + continue; + + has_docstring = FALSE; + + if (md->docstring != NULL || (docstrings && hasDocstring(pt, mod->overs, md, NULL))) + has_docstring = TRUE; + + prcode(fp, +" {SIP_MLNAME_CAST(%N), ", md->pyname); + + if (noArgParser(md) || useKeywordArgsFunction(md)) + prcode(fp, "(PyCFunction)func_%s, METH_VARARGS|METH_KEYWORDS", md->pyname->text); + else + prcode(fp, "func_%s, METH_VARARGS", md->pyname->text); + + if (has_docstring) + prcode(fp, ", SIP_MLDOC_CAST(doc_%s)},\n" + , md->pyname->text); + else + prcode(fp, ", NULL},\n" + ); + } + + prcode(fp, +" {0, 0, 0, 0}\n" +" };\n" + ); + + generateModDefinition(mod, "sip_methods", fp); + + prcode(fp, +"\n" +" PyObject *sipModule, *sipModuleDict;\n" + ); + + generateSipImportVariables(fp); + + /* Generate any pre-initialisation code. */ + generateCppCodeBlock(mod->preinitcode, fp); + + prcode(fp, +" /* Initialise the module and get it's dictionary. */\n" +"#if PY_MAJOR_VERSION >= 3\n" +" sipModule = PyModule_Create(&sip_module_def);\n" +"#elif PY_VERSION_HEX >= 0x02050000\n" +" sipModule = Py_InitModule(%N, sip_methods);\n" +"#else\n" + , mod->fullname); + + if (generating_c) + prcode(fp, +" sipModule = Py_InitModule((char *)%N, sip_methods);\n" + , mod->fullname); + else + prcode(fp, +" sipModule = Py_InitModule(const_cast<char *>(%N), sip_methods);\n" + , mod->fullname); + + prcode(fp, +"#endif\n" +"\n" +" if (sipModule == NULL)\n" +" SIP_MODULE_RETURN(NULL);\n" +"\n" +" sipModuleDict = PyModule_GetDict(sipModule);\n" +"\n" + ); + + generateSipImport(mod, fp); + + /* Generate any initialisation code. */ + generateCppCodeBlock(mod->initcode, fp); + + prcode(fp, +" /* Export the module and publish it's API. */\n" +" if (sipExportModule(&sipModuleAPI_%s,SIP_API_MAJOR_NR,SIP_API_MINOR_NR,0) < 0)\n" +" {\n" +"#if !defined(SIP_USE_PYCAPSULE)\n" +" Py_DECREF(sip_sipmod);\n" +"#endif\n" +" SIP_MODULE_DISCARD(sipModule);\n" +" SIP_MODULE_RETURN(0);\n" +" }\n" + , mname); + + if (pluginPyQt4(pt)) + { + /* Import the helpers. */ + prcode(fp, +"\n" +" sip_%s_qt_metaobject = (sip_qt_metaobject_func)sipImportSymbol(\"qtcore_qt_metaobject\");\n" +" sip_%s_qt_metacall = (sip_qt_metacall_func)sipImportSymbol(\"qtcore_qt_metacall\");\n" +" sip_%s_qt_metacast = (sip_qt_metacast_func)sipImportSymbol(\"qtcore_qt_metacast\");\n" +"\n" + , mname + , mname + , mname); + } + + prcode(fp, +" /* Initialise the module now all its dependencies have been set up. */\n" +" if (sipInitModule(&sipModuleAPI_%s,sipModuleDict) < 0)\n" +" {\n" +"#if !defined(SIP_USE_PYCAPSULE)\n" +" Py_DECREF(sip_sipmod);\n" +"#endif\n" +" SIP_MODULE_DISCARD(sipModule);\n" +" SIP_MODULE_RETURN(0);\n" +" }\n" + , mname); + + mod_nr = 0; + + for (mld = mod->allimports; mld != NULL; mld = mld->next) + { + if (mod_nr == 0) + prcode(fp, +"\n" +" /* Get the APIs of the modules that this one is dependent on. */\n" + ); + + prcode(fp, +" sipModuleAPI_%s_%s = sipModuleAPI_%s.em_imports[%d].im_module;\n" + , mname, mld->module->name, mname, mod_nr); + + ++mod_nr; + } + + generateTypesInline(pt, mod, fp); + + /* Create any exceptions. */ + for (xd = pt->exceptions; xd != NULL; xd = xd->next) + { + if (xd->iff->module != mod) + continue; + + if (xd->iff->type != exception_iface) + continue; + + if (xd->exceptionnr < 0) + continue; + + prcode(fp, +"\n" +" if ((exceptionsTable[%d] = PyErr_NewException(\n" +"#if PY_MAJOR_VERSION >= 3\n" +" \"%s.%s\",\n" +"#else\n" +" const_cast<char *>(\"%s.%s\"),\n" +"#endif\n" +" " + , xd->exceptionnr + , xd->iff->module->name, xd->pyname + , xd->iff->module->name, xd->pyname); + + if (xd->bibase != NULL) + prcode(fp, "PyExc_%s", xd->bibase); + else if (xd->base->iff->module == mod) + prcode(fp, "exceptionsTable[%d]", xd->base->exceptionnr); + else + prcode(fp, "sipException_%C", xd->base->iff->fqcname); + + prcode(fp, ",NULL)) == NULL || PyDict_SetItemString(sipModuleDict,\"%s\",exceptionsTable[%d]) < 0)\n" +" {\n" +"#if !defined(SIP_USE_PYCAPSULE)\n" +" Py_DECREF(sip_sipmod);\n" +"#endif\n" +" SIP_MODULE_DISCARD(sipModule);\n" +" SIP_MODULE_RETURN(0);\n" +" }\n" + , xd->pyname, xd->exceptionnr); + } + + /* Generate any post-initialisation code. */ + generateCppCodeBlock(mod->postinitcode, fp); + + prcode(fp, +"\n" +" SIP_MODULE_RETURN(sipModule);\n" +"}\n" + ); + + /* Generate the interface source files. */ + for (iff = pt->ifacefiles; iff != NULL; iff = iff->next) + if (iff->module == mod && iff->type != exception_iface) + { + if (parts && files_in_part++ == max_per_part) + { + /* Close the old part. */ + closeFile(fp); + free(cppfile); + + /* Create a new one. */ + files_in_part = 1; + ++this_part; + + cppfile = makePartName(codeDir, mname, this_part, srcSuffix); + fp = createCompilationUnit(mod, cppfile, "Module code."); + + prcode(fp, +"\n" +"#include \"sipAPI%s.h\"\n" + , mname); + } + + generateIfaceCpp(pt, iff, codeDir, srcSuffix, (parts ? fp : NULL)); + } + + closeFile(fp); + free(cppfile); + + /* How many parts we actually generated. */ + if (parts) + parts = this_part + 1; + + mod->parts = parts; + + generateInternalAPIHeader(pt, mod, codeDir, xsl); +} + + +/* + * Generate the types table for a module. + */ +static void generateTypesTable(sipSpec *pt, moduleDef *mod, FILE *fp) +{ + int i; + argDef *ad; + const char *type_suffix; + + type_suffix = (pluginPyQt4(pt) || pluginPyQt3(pt)) ? ".super" : ""; + + prcode(fp, +"\n" +"\n" +"/*\n" +" * This defines each type in this module.\n" +" */\n" +"static sipTypeDef *typesTable[] = {\n" + ); + + for (ad = mod->types, i = 0; i < mod->nrtypes; ++i, ++ad) + { + switch (ad->atype) + { + case class_type: + if (isExternal(ad->u.cd)) + prcode(fp, +" 0,\n" + ); + else + prcode(fp, +" &sipTypeDef_%s_%L%s.ctd_base,\n" + , mod->name, ad->u.cd->iff, type_suffix); + + break; + + case mapped_type: + prcode(fp, +" &sipTypeDef_%s_%L.mtd_base,\n" + , mod->name, ad->u.mtd->iff); + break; + + case enum_type: + prcode(fp, +" &enumTypes[%d].etd_base,\n" + , ad->u.ed->enum_idx); + break; + } + } + + prcode(fp, +"};\n" + ); +} + + +/* + * Generate the code to import the sip module and get its API. + */ +static void generateSipImport(moduleDef *mod, FILE *fp) +{ + prcode(fp, +" /* Get the SIP module's API. */\n" +"#if defined(SIP_USE_PYCAPSULE)\n" +"\n" + ); + + if (generating_c) + prcode(fp, +" sipAPI_%s = (const sipAPIDef *)PyCapsule_Import(\"sip._C_API\", 0);\n" + , mod->name); + else + prcode(fp, +" sipAPI_%s = reinterpret_cast<const sipAPIDef *>(PyCapsule_Import(\"sip._C_API\", 0));\n" + , mod->name); + + prcode(fp, +"\n" +" if (sipAPI_%s == NULL)\n" +" {\n" +" SIP_MODULE_DISCARD(sipModule);\n" +" SIP_MODULE_RETURN(NULL);\n" +" }\n" +"\n" +"#else\n" +"\n" +"#if PY_VERSION_HEX >= 0x02050000\n" +" sip_sipmod = PyImport_ImportModule(\"sip\");\n" +"#else\n" + , mod->name); + + if (generating_c) + prcode(fp, +" sip_sipmod = PyImport_ImportModule((char *)\"sip\");\n" + ); + else + prcode(fp, +" sip_sipmod = PyImport_ImportModule(const_cast<char *>(\"sip\"));\n" + ); + + prcode(fp, +"#endif\n" +"\n" +" if (sip_sipmod == NULL)\n" +" {\n" +" SIP_MODULE_DISCARD(sipModule);\n" +" SIP_MODULE_RETURN(NULL);\n" +" }\n" +"\n" +" sip_capiobj = PyDict_GetItemString(PyModule_GetDict(sip_sipmod), \"_C_API\");\n" +"\n" +" if (sip_capiobj == NULL || !PyCObject_Check(sip_capiobj))\n" +" {\n" +" Py_DECREF(sip_sipmod);\n" +" SIP_MODULE_DISCARD(sipModule);\n" +" SIP_MODULE_RETURN(NULL);\n" +" }\n" +"\n" + ); + + if (generating_c) + prcode(fp, +" sipAPI_%s = (const sipAPIDef *)PyCObject_AsVoidPtr(sip_capiobj);\n" + , mod->name); + else + prcode(fp, +" sipAPI_%s = reinterpret_cast<const sipAPIDef *>(PyCObject_AsVoidPtr(sip_capiobj));\n" + , mod->name); + + prcode(fp, +"\n" +"#endif\n" +"\n" + ); +} + + +/* + * Generate the variables needed by generateSipImport(). + */ +static void generateSipImportVariables(FILE *fp) +{ + prcode(fp, +"#if !defined(SIP_USE_PYCAPSULE)\n" +" PyObject *sip_sipmod, *sip_capiobj;\n" +"#endif\n" +"\n" + ); +} + + +/* + * Generate the start of the Python module initialisation function. + */ +static void generateModInitStart(moduleDef *mod, int gen_c, FILE *fp) +{ + prcode(fp, +"\n" +"\n" +"/* The Python module initialisation function. */\n" +"#if PY_MAJOR_VERSION >= 3\n" +"#define SIP_MODULE_ENTRY PyInit_%s\n" +"#define SIP_MODULE_TYPE PyObject *\n" +"#define SIP_MODULE_DISCARD(r) Py_DECREF(r)\n" +"#define SIP_MODULE_RETURN(r) return (r)\n" +"#else\n" +"#define SIP_MODULE_ENTRY init%s\n" +"#define SIP_MODULE_TYPE void\n" +"#define SIP_MODULE_DISCARD(r)\n" +"#define SIP_MODULE_RETURN(r) return\n" +"#endif\n" +"\n" +"#if defined(SIP_STATIC_MODULE)\n" +"%sSIP_MODULE_TYPE SIP_MODULE_ENTRY()\n" +"#else\n" +"PyMODINIT_FUNC SIP_MODULE_ENTRY()\n" +"#endif\n" +"{\n" + , mod->name + , mod->name + , (gen_c ? "" : "extern \"C\" ")); +} + + +/* + * Generate the Python v3 module definition structure. + */ +static void generateModDefinition(moduleDef *mod, const char *methods, + FILE *fp) +{ + prcode(fp, +"\n" +"#if PY_MAJOR_VERSION >= 3\n" +" static PyModuleDef sip_module_def = {\n" +" PyModuleDef_HEAD_INIT,\n" +" \"%s\",\n" +" NULL,\n" +" -1,\n" +" %s,\n" +" NULL,\n" +" NULL,\n" +" NULL,\n" +" NULL\n" +" };\n" +"#endif\n" + , mod->fullname->text + , methods); +} + + +/* + * Generate all the sub-class convertors for a module. + */ +static int generateSubClassConvertors(sipSpec *pt, moduleDef *mod, FILE *fp) +{ + int nrSccs = 0; + classDef *cd; + + for (cd = pt->classes; cd != NULL; cd = cd->next) + { + int needs_sipClass; + + if (cd->iff->module != mod) + continue; + + if (cd->convtosubcode == NULL) + continue; + + prcode(fp, +"\n" +"\n" +"/* Convert to a sub-class if possible. */\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static const sipTypeDef *sipSubClass_%C(void **);}\n" + , classFQCName(cd)); + + /* Allow the deprecated use of sipClass rather than sipType. */ + needs_sipClass = usedInCode(cd->convtosubcode, "sipClass"); + + prcode(fp, +"static const sipTypeDef *sipSubClass_%C(void **sipCppRet)\n" +"{\n" +" %S *sipCpp = reinterpret_cast<%S *>(*sipCppRet);\n" + , classFQCName(cd) + , classFQCName(cd->subbase), classFQCName(cd->subbase)); + + if (needs_sipClass) + prcode(fp, +" sipWrapperType *sipClass;\n" +"\n" + ); + else + prcode(fp, +" const sipTypeDef *sipType;\n" +"\n" + ); + + generateCppCodeBlock(cd->convtosubcode, fp); + + if (needs_sipClass) + prcode(fp, +"\n" +" return (sipClass ? sipClass->type : 0);\n" +"}\n" + ); + else + prcode(fp, +"\n" +" return sipType;\n" +"}\n" + ); + + ++nrSccs; + } + + return nrSccs; +} + + +/* + * Generate the structure representing an encoded type. + */ +static void generateEncodedType(moduleDef *mod, classDef *cd, int last, + FILE *fp) +{ + moduleDef *cmod = cd->iff->module; + + prcode(fp, "{%u, ", cd->iff->first_alt->ifacenr); + + if (cmod == mod) + prcode(fp, "255"); + else + { + int mod_nr = 0; + moduleListDef *mld; + + for (mld = mod->allimports; mld != NULL; mld = mld->next) + { + if (mld->module == cmod) + { + prcode(fp, "%u", mod_nr); + break; + } + + ++mod_nr; + } + } + + prcode(fp, ", %u}", last); +} + + +/* + * Generate an ordinary function. + */ +static void generateOrdinaryFunction(sipSpec *pt, moduleDef *mod, + classDef *c_scope, mappedTypeDef *mt_scope, memberDef *md, FILE *fp) +{ + overDef *od; + int need_intro, has_auto_docstring; + ifaceFileDef *scope; + classDef *scope_scope; + const char *scope_name, *kw_fw_decl, *kw_decl; + + if (mt_scope != NULL) + { + scope = mt_scope->iff; + scope_name = mt_scope->pyname->text; + scope_scope = NULL; + od = mt_scope->overs; + } + else if (c_scope != NULL) + { + scope = c_scope->iff; + scope_name = c_scope->pyname->text; + scope_scope = NULL; + od = c_scope->overs; + } + else + { + scope = NULL; + scope_name = NULL; + scope_scope = NULL; + od = mod->overs; + } + + prcode(fp, +"\n" +"\n" + ); + + /* Generate the docstrings. */ + has_auto_docstring = FALSE; + + if (md->docstring != NULL || (docstrings && hasDocstring(pt, od, md, scope))) + { + if (scope != NULL) + prcode(fp, +"PyDoc_STRVAR(doc_%L_%s, ", scope, md->pyname->text); + else + prcode(fp, +"PyDoc_STRVAR(doc_%s, " , md->pyname->text); + + if (md->docstring != NULL) + { + generateExplicitDocstring(md->docstring, fp); + } + else + { + generateDocstring(pt, od, md, scope_name, scope_scope, fp); + has_auto_docstring = TRUE; + } + + prcode(fp, ");\n" +"\n" + ); + } + + if (noArgParser(md) || useKeywordArgsFunction(md)) + { + kw_fw_decl = ", PyObject *"; + kw_decl = ", PyObject *sipKwds"; + } + else + { + kw_fw_decl = ""; + kw_decl = ""; + } + + if (scope != NULL) + { + if (!generating_c) + prcode(fp, +"extern \"C\" {static PyObject *meth_%L_%s(PyObject *, PyObject *%s);}\n" + , scope, md->pyname->text, kw_fw_decl); + + prcode(fp, +"static PyObject *meth_%L_%s(PyObject *, PyObject *sipArgs%s)\n" + , scope, md->pyname->text, kw_decl); + } + else + { + const char *self = (generating_c ? "sipSelf" : ""); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static PyObject *func_%s(PyObject *,PyObject *%s);}\n" + , md->pyname->text, kw_fw_decl); + + prcode(fp, +"static PyObject *func_%s(PyObject *%s,PyObject *sipArgs%s)\n" + , md->pyname->text, self, kw_decl); + } + + prcode(fp, +"{\n" + ); + + need_intro = TRUE; + + while (od != NULL) + { + if (od->common == md) + { + if (noArgParser(md)) + { + generateCppCodeBlock(od->methodcode, fp); + break; + } + + if (need_intro) + { + prcode(fp, +" PyObject *sipParseErr = NULL;\n" + ); + + need_intro = FALSE; + } + + generateFunctionBody(od, c_scope, mt_scope, c_scope, TRUE, mod, fp); + } + + od = od->next; + } + + if (!need_intro) + { + prcode(fp, +"\n" +" /* Raise an exception if the arguments couldn't be parsed. */\n" +" sipNoFunction(sipParseErr, %N, ", md->pyname); + + if (has_auto_docstring) + { + if (scope != NULL) + prcode(fp, "doc_%L_%s", scope, md->pyname->text); + else + prcode(fp, "doc_%s", md->pyname->text); + } + else + { + prcode(fp, "NULL"); + } + + prcode(fp, ");\n" +"\n" +" return NULL;\n" + ); + } + + prcode(fp, +"}\n" + ); +} + + +/* + * Generate the table of enum members for a scope. Return the number of them. + */ +static int generateEnumMemberTable(sipSpec *pt, moduleDef *mod, classDef *cd, + mappedTypeDef *mtd, FILE *fp) +{ + int i, nr_members; + enumDef *ed; + enumMemberDef **etab, **et; + + /* First we count how many. */ + + nr_members = 0; + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + enumMemberDef *emd; + + if (ed->module != mod) + continue; + + if (cd != NULL) + { + if (ed->ecd != cd) + continue; + } + else if (mtd != NULL) + { + if (ed->emtd != mtd) + continue; + } + else if (ed->ecd != NULL || ed->emtd != NULL || ed->fqcname == NULL) + { + continue; + } + + for (emd = ed->members; emd != NULL; emd = emd->next) + ++nr_members; + } + + if (nr_members == 0) + return 0; + + /* Create a table so they can be sorted. */ + + etab = sipCalloc(nr_members, sizeof (enumMemberDef *)); + + et = etab; + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + enumMemberDef *emd; + + if (ed->module != mod) + continue; + + if (cd != NULL) + { + if (ed->ecd != cd) + continue; + } + else if (mtd != NULL) + { + if (ed->emtd != mtd) + continue; + } + else if (ed->ecd != NULL || ed->emtd != NULL || ed->fqcname == NULL) + { + continue; + } + + for (emd = ed->members; emd != NULL; emd = emd->next) + *et++ = emd; + } + + qsort(etab, nr_members, sizeof (enumMemberDef *), compareEnumMembers); + + /* Now generate the table. */ + + if (cd == NULL && mtd == NULL) + { + prcode(fp, +"\n" +"/* These are the enum members of all global enums. */\n" +"static sipEnumMemberDef enummembers[] = {\n" + ); + } + else + { + ifaceFileDef *iff = (cd != NULL ? cd->iff : mtd->iff); + + prcode(fp, +"\n" +"static sipEnumMemberDef enummembers_%L[] = {\n" + , iff); + } + + for (i = 0; i < nr_members; ++i) + { + enumMemberDef *emd; + + emd = etab[i]; + + prcode(fp, +" {%N, ", emd->pyname); + + if (cd != NULL) + { + if (isProtectedEnum(emd->ed)) + prcode(fp, "sip%C::", classFQCName(cd)); + else if (isProtectedClass(cd)) + prcode(fp, "%U::", cd); + else + prcode(fp, "%S::", classFQCName(cd)); + } + else if (mtd != NULL) + { + prcode(fp, "%S::", mtd->iff->fqcname); + } + + prcode(fp, "%s, %d},\n", emd->cname, emd->ed->first_alt->enumnr); + } + + prcode(fp, +"};\n" + ); + + return nr_members; +} + + +/* + * The qsort helper to compare two enumMemberDef structures based on the name + * of the enum member. + */ +static int compareEnumMembers(const void *m1,const void *m2) +{ + return strcmp((*(enumMemberDef **)m1)->pyname->text, + (*(enumMemberDef **)m2)->pyname->text); +} + + +/* + * Generate the access functions for the variables. + */ +static void generateAccessFunctions(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp) +{ + varDef *vd; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + if (vd->accessfunc == NULL) + continue; + + if (vd->ecd != cd || vd->module != mod) + continue; + + prcode(fp, +"\n" +"\n" +"/* Access function. */\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static void *access_%C();}\n" + , vd->fqcname); + + prcode(fp, +"static void *access_%C()\n" +"{\n" + , vd->fqcname); + + generateCppCodeBlock(vd->accessfunc, fp); + + prcode(fp, +"}\n" + ); + } +} + + +/* + * Generate the inline code to add a set of generated type instances to a + * dictionary. + */ +static void generateTypesInline(sipSpec *pt, moduleDef *mod, FILE *fp) +{ + int noIntro; + varDef *vd; + + noIntro = TRUE; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + if (vd->module != mod) + continue; + + if (vd->type.atype != class_type && vd->type.atype != mapped_type && vd->type.atype != enum_type) + continue; + + if (needsHandler(vd)) + continue; + + /* Skip classes that don't need inline code. */ + if (generating_c || vd->accessfunc != NULL || vd->type.nrderefs != 0) + continue; + + if (noIntro) + { + prcode(fp, +"\n" +" /*\n" +" * Define the class, mapped type and enum instances that have to be\n" +" * added inline.\n" +" */\n" + ); + + noIntro = FALSE; + } + + prcode(fp, +" sipAddTypeInstance("); + + if (vd->ecd == NULL) + prcode(fp, "sipModuleDict"); + else + prcode(fp, "(PyObject *)sipTypeAsPyTypeObject(sipType_%C)", classFQCName(vd->ecd)); + + prcode(fp, ",%N,", vd->pyname); + + if (isConstArg(&vd->type)) + prcode(fp, "const_cast<%b *>(&%S)", &vd->type, vd->fqcname); + else + prcode(fp, "&%S", vd->fqcname); + + if (vd->type.atype == class_type) + prcode(fp, ",sipType_%C);\n" + , classFQCName(vd->type.u.cd)); + else if (vd->type.atype == enum_type) + prcode(fp, ",sipType_%C);\n" + , vd->type.u.ed->fqcname); + else + prcode(fp, ",sipType_%T);\n" + , &vd->type); + } +} + + +/* + * Generate the code to add a set of class instances to a dictionary. Return + * TRUE if there was at least one. + */ +static int generateClasses(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp) +{ + int noIntro; + varDef *vd; + + noIntro = TRUE; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + if (vd->ecd != cd || vd->module != mod) + continue; + + if (vd->type.atype != class_type && (vd->type.atype != enum_type || vd->type.u.ed->fqcname == NULL)) + continue; + + if (needsHandler(vd)) + continue; + + /* + * Skip ordinary C++ class instances which need to be done with inline + * code rather than through a static table. This is because C++ does + * not guarantee the order in which the table and the instance will be + * created. So far this has only been seen to be a problem when + * statically linking SIP generated modules on Windows. + */ + if (!generating_c && vd->accessfunc == NULL && vd->type.nrderefs == 0) + continue; + + if (noIntro) + { + if (cd != NULL) + prcode(fp, +"\n" +"\n" +"/* Define the class and enum instances to be added to this type dictionary. */\n" +"static sipTypeInstanceDef typeInstances_%C[] = {\n" + , classFQCName(cd)); + else + prcode(fp, +"\n" +"\n" +"/* Define the class and enum instances to be added to this module dictionary. */\n" +"static sipTypeInstanceDef typeInstances[] = {\n" + ); + + noIntro = FALSE; + } + + prcode(fp, +" {%N, ", vd->pyname); + + if (vd->type.atype == class_type) + { + scopedNameDef *vcname = classFQCName(vd->type.u.cd); + + if (vd->accessfunc != NULL) + { + prcode(fp, "(void *)access_%C, &sipType_%C, SIP_ACCFUNC", vd->fqcname, vcname); + } + else if (vd->type.nrderefs != 0) + { + prcode(fp, "&%S, &sipType_%C, SIP_INDIRECT", vd->fqcname, vcname); + } + else if (isConstArg(&vd->type)) + { + prcode(fp, "const_cast<%b *>(&%S), &sipType_%C, 0", &vd->type, vd->fqcname, vcname); + } + else + { + prcode(fp, "&%S, &sipType_%C, 0", vd->fqcname, vcname); + } + } + else + { + prcode(fp, "&%S, &sipType_%C, 0", vd->fqcname, vd->type.u.ed->fqcname); + } + + prcode(fp, "},\n" + ); + } + + if (!noIntro) + prcode(fp, +" {0, 0, 0, 0}\n" +"};\n" + ); + + return !noIntro; +} + + +/* + * Generate the code to add a set of void pointers to a dictionary. Return + * TRUE if there was at least one. + */ +static int generateVoidPointers(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp) +{ + int noIntro; + varDef *vd; + + noIntro = TRUE; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + if (vd->ecd != cd || vd->module != mod) + continue; + + if (vd->type.atype != void_type && vd->type.atype != struct_type) + continue; + + if (needsHandler(vd)) + continue; + + if (noIntro) + { + if (cd != NULL) + prcode(fp, +"\n" +"\n" +"/* Define the void pointers to be added to this type dictionary. */\n" +"static sipVoidPtrInstanceDef voidPtrInstances_%C[] = {\n" + , classFQCName(cd)); + else + prcode(fp, +"\n" +"\n" +"/* Define the void pointers to be added to this module dictionary. */\n" +"static sipVoidPtrInstanceDef voidPtrInstances[] = {\n" + ); + + noIntro = FALSE; + } + + if (isConstArg(&vd->type)) + prcode(fp, +" {%N, const_cast<%b *>(%S)},\n" + , vd->pyname, &vd->type, vd->fqcname); + else + prcode(fp, +" {%N, %S},\n" + , vd->pyname, vd->fqcname); + } + + if (!noIntro) + prcode(fp, +" {0, 0}\n" +"};\n" + ); + + return !noIntro; +} + + +/* + * Generate the code to add a set of characters to a dictionary. Return TRUE + * if there was at least one. + */ +static int generateChars(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp) +{ + int noIntro; + varDef *vd; + + noIntro = TRUE; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + argType vtype = vd->type.atype; + + if (vd->ecd != cd || vd->module != mod) + continue; + + if (!((vtype == ascii_string_type || vtype == latin1_string_type || vtype == utf8_string_type || vtype == sstring_type || vtype == ustring_type || vtype == string_type || vtype == wstring_type) && vd->type.nrderefs == 0)) + continue; + + if (needsHandler(vd)) + continue; + + if (noIntro) + { + if (cd != NULL) + prcode(fp, +"\n" +"\n" +"/* Define the chars to be added to this type dictionary. */\n" +"static sipCharInstanceDef charInstances_%C[] = {\n" + , classFQCName(cd)); + else + prcode(fp, +"\n" +"\n" +"/* Define the chars to be added to this module dictionary. */\n" +"static sipCharInstanceDef charInstances[] = {\n" + ); + + noIntro = FALSE; + } + + prcode(fp, +" {%N, %S, '%c'},\n" + , vd->pyname, vd->fqcname, getEncoding(vtype)); + } + + if (!noIntro) + prcode(fp, +" {0, 0, 0}\n" +"};\n" + ); + + return !noIntro; +} + + +/* + * Generate the code to add a set of strings to a dictionary. Return TRUE if + * there is at least one. + */ +static int generateStrings(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp) +{ + int noIntro; + varDef *vd; + + noIntro = TRUE; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + argType vtype = vd->type.atype; + + if (vd->ecd != cd || vd->module != mod) + continue; + + if (!((vtype == ascii_string_type || vtype == latin1_string_type || vtype == utf8_string_type || vtype == sstring_type || vtype == ustring_type || vtype == string_type || vtype == wstring_type) && vd->type.nrderefs != 0)) + continue; + + if (needsHandler(vd)) + continue; + + if (noIntro) + { + if (cd != NULL) + prcode(fp, +"\n" +"\n" +"/* Define the strings to be added to this type dictionary. */\n" +"static sipStringInstanceDef stringInstances_%C[] = {\n" + , classFQCName(cd)); + else + prcode(fp, +"\n" +"\n" +"/* Define the strings to be added to this module dictionary. */\n" +"static sipStringInstanceDef stringInstances[] = {\n" + ); + + noIntro = FALSE; + } + + prcode(fp, +" {%N, %S, '%c'},\n" + , vd->pyname, vd->fqcname, getEncoding(vtype)); + } + + if (!noIntro) + prcode(fp, +" {0, 0, 0}\n" +"};\n" + ); + + return !noIntro; +} + + +/* + * Generate the code to add a set of ints to a dictionary. Return TRUE if + * there was at least one. + */ +static int generateInts(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp) +{ + int noIntro; + varDef *vd; + enumDef *ed; + + noIntro = TRUE; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + argType vtype = vd->type.atype; + + if (vd->ecd != cd || vd->module != mod) + continue; + + if (!(vtype == enum_type || vtype == ushort_type || + vtype == short_type || vtype == uint_type || + vtype == cint_type || vtype == int_type || + vtype == bool_type || vtype == cbool_type)) + continue; + + if (needsHandler(vd)) + continue; + + /* Named enums are handled elsewhere. */ + if (vtype == enum_type && vd->type.u.ed->fqcname != NULL) + continue; + + if (noIntro) + { + ints_intro(cd, fp); + noIntro = FALSE; + } + + prcode(fp, +" {%N, %S},\n" + , vd->pyname, vd->fqcname); + } + + /* Now do global anonymous enums. */ + if (cd == NULL) + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + enumMemberDef *em; + + if (ed->ecd != cd || ed->module != mod) + continue; + + if (ed->fqcname != NULL) + continue; + + for (em = ed->members; em != NULL; em = em->next) + { + if (noIntro) + { + ints_intro(cd, fp); + noIntro = FALSE; + } + + prcode(fp, +" {%N, %s},\n" + , em->pyname, em->cname); + } + } + + if (!noIntro) + prcode(fp, +" {0, 0}\n" +"};\n" + ); + + return !noIntro; +} + + +/* + * Generate the intro for a table of int instances. + */ +static void ints_intro(classDef *cd, FILE *fp) +{ + if (cd != NULL) + prcode(fp, +"\n" +"\n" +"/* Define the ints to be added to this type dictionary. */\n" +"static sipIntInstanceDef intInstances_%C[] = {\n" + ,classFQCName(cd)); + else + prcode(fp, +"\n" +"\n" +"/* Define the ints to be added to this module dictionary. */\n" +"static sipIntInstanceDef intInstances[] = {\n" + ); +} + + +/* + * Generate the code to add a set of longs to a dictionary. Return TRUE if + * there was at least one. + */ +static int generateLongs(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp) +{ + return generateVariableType(pt, mod, cd, long_type, "long", "Long", "long", fp); +} + + +/* + * Generate the code to add a set of unsigned longs to a dictionary. Return + * TRUE if there was at least one. + */ +static int generateUnsignedLongs(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp) +{ + return generateVariableType(pt, mod, cd, ulong_type, "unsigned long", "UnsignedLong", "unsignedLong", fp); +} + + +/* + * Generate the code to add a set of long longs to a dictionary. Return TRUE + * if there was at least one. + */ +static int generateLongLongs(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp) +{ + return generateVariableType(pt, mod, cd, longlong_type, "long long", "LongLong", "longLong", fp); +} + + +/* + * Generate the code to add a set of unsigned long longs to a dictionary. + * Return TRUE if there was at least one. + */ +static int generateUnsignedLongLongs(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp) +{ + return generateVariableType(pt, mod, cd, ulonglong_type, "unsigned long long", "UnsignedLongLong", "unsignedLongLong", fp); +} + + +/* + * Generate the code to add a set of a particular type to a dictionary. Return + * TRUE if there was at least one. + */ +static int generateVariableType(sipSpec *pt, moduleDef *mod, classDef *cd, + argType atype, const char *eng, const char *s1, const char *s2, + FILE *fp) +{ + int noIntro; + varDef *vd; + + noIntro = TRUE; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + argType vtype = vd->type.atype; + + if (vd->ecd != cd || vd->module != mod) + continue; + + if (vtype != atype) + continue; + + if (needsHandler(vd)) + continue; + + if (noIntro) + { + if (cd != NULL) + prcode(fp, +"\n" +"\n" +"/* Define the %ss to be added to this type dictionary. */\n" +"static sip%sInstanceDef %sInstances_%C[] = {\n" + , eng + , s1, s2, classFQCName(cd)); + else + prcode(fp, +"\n" +"\n" +"/* Define the %ss to be added to this module dictionary. */\n" +"static sip%sInstanceDef %sInstances[] = {\n" + , eng + , s1, s2); + + noIntro = FALSE; + } + + prcode(fp, +" {%N, %S},\n" + , vd->pyname, vd->fqcname); + } + + if (!noIntro) + prcode(fp, +" {0, 0}\n" +"};\n" + ); + + return !noIntro; +} + + +/* + * Generate the code to add a set of doubles to a dictionary. Return TRUE if + * there was at least one. + */ +static int generateDoubles(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp) +{ + int noIntro; + varDef *vd; + + noIntro = TRUE; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + argType vtype = vd->type.atype; + + if (vd->ecd != cd || vd->module != mod) + continue; + + if (!(vtype == float_type || vtype == cfloat_type || vtype == double_type || vtype == cdouble_type)) + continue; + + if (needsHandler(vd)) + continue; + + if (noIntro) + { + if (cd != NULL) + prcode(fp, +"\n" +"\n" +"/* Define the doubles to be added to this type dictionary. */\n" +"static sipDoubleInstanceDef doubleInstances_%C[] = {\n" + , classFQCName(cd)); + else + prcode(fp, +"\n" +"\n" +"/* Define the doubles to be added to this module dictionary. */\n" +"static sipDoubleInstanceDef doubleInstances[] = {\n" + ); + + noIntro = FALSE; + } + + prcode(fp, +" {%N, %S},\n" + , vd->pyname, vd->fqcname); + } + + if (!noIntro) + prcode(fp, +" {0, 0}\n" +"};\n" + ); + + return !noIntro; +} + + +/* + * Generate the C/C++ code for an interface. + */ +static void generateIfaceCpp(sipSpec *pt, ifaceFileDef *iff, + const char *codeDir, const char *srcSuffix, FILE *master) +{ + char *cppfile; + const char *cmname = iff->module->name; + classDef *cd; + mappedTypeDef *mtd; + FILE *fp; + + if (master == NULL) + { + cppfile = createIfaceFileName(codeDir,iff,srcSuffix); + fp = createCompilationUnit(iff->module, cppfile, "Interface wrapper code."); + + prcode(fp, +"\n" +"#include \"sipAPI%s.h\"\n" + , cmname); + } + else + fp = master; + + prcode(fp, +"\n" + ); + + generateCppCodeBlock(iff->hdrcode, fp); + generateUsedIncludes(iff->used, fp); + + for (cd = pt->classes; cd != NULL; cd = cd->next) + { + /* + * Protected classes must be generated in the interface file of the + * enclosing scope. + */ + if (isProtectedClass(cd)) + continue; + + if (cd->iff == iff && !isExternal(cd)) + { + classDef *pcd; + + generateClassCpp(cd, pt, fp); + + /* Generate any enclosed protected classes. */ + for (pcd = pt->classes; pcd != NULL; pcd = pcd->next) + if (isProtectedClass(pcd) && pcd->ecd == cd) + generateClassCpp(pcd, pt, fp); + } + } + + for (mtd = pt->mappedtypes; mtd != NULL; mtd = mtd->next) + if (mtd->iff == iff) + generateMappedTypeCpp(mtd, pt, fp); + + if (master == NULL) + { + closeFile(fp); + free(cppfile); + } +} + + +/* + * Return a filename for an interface C++ or header file on the heap. + */ +static char *createIfaceFileName(const char *codeDir, ifaceFileDef *iff, + const char *suffix) +{ + char *fn; + scopedNameDef *snd; + + fn = concat(codeDir,"/sip",iff->module->name,NULL); + + for (snd = iff->fqcname; snd != NULL; snd = snd->next) + append(&fn,snd->name); + + if (iff->api_range != NULL) + { + char buf[50]; + + sprintf(buf, "_%d", iff->api_range->index); + append(&fn, buf); + } + + append(&fn,suffix); + + return fn; +} + + +/* + * Generate the C++ code for a mapped type version. + */ +static void generateMappedTypeCpp(mappedTypeDef *mtd, sipSpec *pt, FILE *fp) +{ + int need_xfer, nr_methods, nr_enums; + memberDef *md; + + if (!noRelease(mtd)) + { + /* Generate the assignment helper. */ + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static void assign_%L(void *, SIP_SSIZE_T, const void *);}\n" + , mtd->iff); + + prcode(fp, +"static void assign_%L(void *sipDst, SIP_SSIZE_T sipDstIdx, const void *sipSrc)\n" +"{\n" + , mtd->iff); + + if (generating_c) + prcode(fp, +" ((%b *)sipDst)[sipDstIdx] = *((const %b *)sipSrc);\n" + , &mtd->type, &mtd->type); + else + prcode(fp, +" reinterpret_cast<%b *>(sipDst)[sipDstIdx] = *reinterpret_cast<const %b *>(sipSrc);\n" + , &mtd->type, &mtd->type); + + prcode(fp, +"}\n" + ); + + /* Generate the array allocation helper. */ + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static void *array_%L(SIP_SSIZE_T);}\n" + , mtd->iff); + + prcode(fp, +"static void *array_%L(SIP_SSIZE_T sipNrElem)\n" +"{\n" + , mtd->iff); + + if (generating_c) + prcode(fp, +" return sipMalloc(sizeof (%b) * sipNrElem);\n" + , &mtd->type); + else + prcode(fp, +" return new %b[sipNrElem];\n" + , &mtd->type); + + prcode(fp, +"}\n" + ); + + /* Generate the copy helper. */ + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static void *copy_%L(const void *, SIP_SSIZE_T);}\n" + , mtd->iff); + + prcode(fp, +"static void *copy_%L(const void *sipSrc, SIP_SSIZE_T sipSrcIdx)\n" +"{\n" + , mtd->iff); + + if (generating_c) + prcode(fp, +" %b *sipPtr = sipMalloc(sizeof (%b));\n" +" *sipPtr = ((const %b *)sipSrc)[sipSrcIdx];\n" +"\n" +" return sipPtr;\n" + , &mtd->type, &mtd->type + , &mtd->type); + else + prcode(fp, +" return new %b(reinterpret_cast<const %b *>(sipSrc)[sipSrcIdx]);\n" + , &mtd->type, &mtd->type); + + prcode(fp, +"}\n" + ); + + prcode(fp, +"\n" +"\n" +"/* Call the mapped type's destructor. */\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static void release_%L(void *, int);}\n" + , mtd->iff); + + prcode(fp, +"static void release_%L(void *ptr, int%s)\n" +"{\n" + , mtd->iff, (generating_c ? " status" : "")); + + if (release_gil) + prcode(fp, +" Py_BEGIN_ALLOW_THREADS\n" + ); + + if (generating_c) + prcode(fp, +" sipFree(ptr);\n" + ); + else + prcode(fp, +" delete reinterpret_cast<%b *>(ptr);\n" + , &mtd->type); + + if (release_gil) + prcode(fp, +" Py_END_ALLOW_THREADS\n" + ); + + prcode(fp, +"}\n" +"\n" + ); + } + + generateConvertToDefinitions(mtd,NULL,fp); + + /* Generate the from type convertor. */ + + need_xfer = (generating_c || usedInCode(mtd->convfromcode, "sipTransferObj")); + + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static PyObject *convertFrom_%L(void *, PyObject *);}\n" + , mtd->iff); + + prcode(fp, +"static PyObject *convertFrom_%L(void *sipCppV,PyObject *%s)\n" +"{\n" +" ", mtd->iff, (need_xfer ? "sipTransferObj" : "")); + + generateMappedTypeFromVoid(mtd, "sipCpp", "sipCppV", fp); + + prcode(fp, ";\n" +"\n" + ); + + generateCppCodeBlock(mtd->convfromcode,fp); + + prcode(fp, +"}\n" + ); + + /* Generate the static methods. */ + for (md = mtd->members; md != NULL; md = md->next) + generateOrdinaryFunction(pt, mtd->iff->module, NULL, mtd, md, fp); + + nr_methods = generateMappedTypeMethodTable(pt, mtd, fp); + + nr_enums = generateEnumMemberTable(pt, mtd->iff->module, NULL, mtd, fp); + + prcode(fp, +"\n" +"\n" +"sipMappedTypeDef "); + + generateTypeDefName(mtd->iff, fp); + + prcode(fp, " = {\n" +" {\n" +" %P,\n" +" " + , mtd->iff->api_range); + + generateTypeDefLink(pt, mtd->iff, fp); + + prcode(fp, ",\n" +" 0,\n" +" %sSIP_TYPE_MAPPED,\n" +" %n,\n" +" {0}\n" +" },\n" +" {\n" + , (handlesNone(mtd) ? "SIP_TYPE_ALLOW_NONE|" : "") + , mtd->cname); + + if (nr_enums == 0) + prcode(fp, +" -1,\n" + ); + else + prcode(fp, +" %n,\n" + , mtd->pyname); + + prcode(fp, +" {0, 0, 1},\n" + ); + + if (nr_methods == 0) + prcode(fp, +" 0, 0,\n" + ); + else + prcode(fp, +" %d, methods_%L,\n" + , nr_methods, mtd->iff); + + if (nr_enums == 0) + prcode(fp, +" 0, 0,\n" + ); + else + prcode(fp, +" %d, enummembers_%L,\n" + , nr_enums, mtd->iff); + + prcode(fp, +" 0, 0,\n" +" {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}\n" +" },\n" + ); + + if (noRelease(mtd)) + prcode(fp, +" 0,\n" +" 0,\n" +" 0,\n" +" 0,\n" + ); + else + prcode(fp, +" assign_%L,\n" +" array_%L,\n" +" copy_%L,\n" +" release_%L,\n" + , mtd->iff + , mtd->iff + , mtd->iff + , mtd->iff); + + prcode(fp, +" convertTo_%L,\n" +" convertFrom_%L\n" + , mtd->iff + , mtd->iff); + + prcode(fp, +"};\n" + ); +} + + +/* + * Generate the name of the type structure for a class or mapped type. + */ +static void generateTypeDefName(ifaceFileDef *iff, FILE *fp) +{ + prcode(fp, "sipTypeDef_%s_%L", iff->module->name, iff); +} + + +/* + * Generate the link to a type structure implementing an alternate API. + */ +static void generateTypeDefLink(sipSpec *pt, ifaceFileDef *iff, FILE *fp) +{ + if (iff->next_alt != NULL) + { + prcode(fp, "&"); + generateTypeDefName(iff->next_alt, fp); + + if (iff->next_alt->type == mappedtype_iface) + prcode(fp, ".mtd_base"); + else if (pluginPyQt3(pt) || pluginPyQt4(pt)) + prcode(fp, ".super.ctd_base"); + else + prcode(fp, ".ctd_base"); + } + else + prcode(fp, "0"); +} + + +/* + * Generate the C++ code for a class. + */ +static void generateClassCpp(classDef *cd, sipSpec *pt, FILE *fp) +{ + moduleDef *mod = cd->iff->module; + + /* Generate any local class code. */ + + generateCppCodeBlock(cd->cppcode, fp); + + generateClassFunctions(pt, mod, cd, fp); + + generateAccessFunctions(pt, mod, cd, fp); + + if (cd->iff->type != namespace_iface) + generateConvertToDefinitions(NULL,cd,fp); + + /* The type definition structure. */ + generateTypeDefinition(pt, cd, fp); +} + + +/* + * Return a sorted array of relevant functions for a namespace. + */ + +static sortedMethTab *createFunctionTable(memberDef *members, int *nrp) +{ + int nr; + sortedMethTab *mtab, *mt; + memberDef *md; + + /* First we need to count the number of applicable functions. */ + nr = 0; + + for (md = members; md != NULL; md = md->next) + ++nr; + + if ((*nrp = nr) == 0) + return NULL; + + /* Create the table of methods. */ + mtab = sipCalloc(nr, sizeof (sortedMethTab)); + + /* Initialise the table. */ + mt = mtab; + + for (md = members; md != NULL; md = md->next) + { + mt->md = md; + ++mt; + } + + /* Finally, sort the table. */ + qsort(mtab,nr,sizeof (sortedMethTab),compareMethTab); + + return mtab; +} + + +/* + * Return a sorted array of relevant methods (either lazy or non-lazy) for a + * class. + */ +static sortedMethTab *createMethodTable(classDef *cd, int *nrp) +{ + int nr; + visibleList *vl; + sortedMethTab *mtab, *mt; + + /* + * First we need to count the number of applicable methods. Only provide + * an entry point if there is at least one overload that is defined in this + * class and is a non-abstract function or slot. We allow private (even + * though we don't actually generate code) because we need to intercept the + * name before it reaches a more public version further up the class + * hierarchy. We add the ctor and any variable handlers as special + * entries. + */ + nr = 0; + + for (vl = cd->visible; vl != NULL; vl = vl->next) + { + overDef *od; + + if (vl->m->slot != no_slot) + continue; + + for (od = vl->cd->overs; od != NULL; od = od->next) + { + /* + * Skip protected methods if we don't have the means to handle + * them. + */ + if (isProtected(od) && !hasShadow(cd)) + continue; + + if (skipOverload(od,vl->m,cd,vl->cd,TRUE)) + continue; + + ++nr; + + break; + } + } + + if ((*nrp = nr) == 0) + return NULL; + + /* Create the table of methods. */ + + mtab = sipCalloc(nr, sizeof (sortedMethTab)); + + /* Initialise the table. */ + + mt = mtab; + + for (vl = cd->visible; vl != NULL; vl = vl->next) + { + int need_method; + overDef *od; + + if (vl->m->slot != no_slot) + continue; + + need_method = FALSE; + + for (od = vl->cd->overs; od != NULL; od = od->next) + { + /* + * Skip protected methods if we don't have the means to handle + * them. + */ + if (isProtected(od) && !hasShadow(cd)) + continue; + + if (!skipOverload(od,vl->m,cd,vl->cd,TRUE)) + need_method = TRUE; + } + + if (need_method) + { + mt->md = vl->m; + ++mt; + } + } + + /* Finally sort the table. */ + + qsort(mtab,nr,sizeof (sortedMethTab),compareMethTab); + + return mtab; +} + + +/* + * The qsort helper to compare two sortedMethTab structures based on the Python + * name of the method. + */ + +static int compareMethTab(const void *m1,const void *m2) +{ + return strcmp(((sortedMethTab *)m1)->md->pyname->text, + ((sortedMethTab *)m2)->md->pyname->text); +} + + +/* + * Generate the sorted table of static methods for a mapped type and return + * the number of entries. + */ +static int generateMappedTypeMethodTable(sipSpec *pt, mappedTypeDef *mtd, + FILE *fp) +{ + int nr; + sortedMethTab *mtab; + + mtab = createFunctionTable(mtd->members, &nr); + + if (mtab != NULL) + { + prMethodTable(pt, mtab, nr, mtd->iff, mtd->overs, fp); + free(mtab); + } + + return nr; +} + + +/* + * Generate the sorted table of methods for a class and return the number of + * entries. + */ +static int generateClassMethodTable(sipSpec *pt, classDef *cd, FILE *fp) +{ + int nr; + sortedMethTab *mtab; + + mtab = (cd->iff->type == namespace_iface) ? + createFunctionTable(cd->members, &nr) : + createMethodTable(cd, &nr); + + if (mtab != NULL) + { + prMethodTable(pt, mtab, nr, cd->iff, cd->overs, fp); + free(mtab); + } + + return nr; +} + + +/* + * Generate a method table for a class or mapped type. + */ +static void prMethodTable(sipSpec *pt, sortedMethTab *mtable, int nr, + ifaceFileDef *iff, overDef *overs, FILE *fp) +{ + int i; + + prcode(fp, +"\n" +"\n" +"static PyMethodDef methods_%L[] = {\n" + , iff); + + for (i = 0; i < nr; ++i) + { + memberDef *md = mtable[i].md; + const char *cast, *flags; + int has_docstring; + + if (noArgParser(md) || useKeywordArgsFunction(md)) + { + cast = "(PyCFunction)"; + flags = "|METH_KEYWORDS"; + } + else + { + cast = ""; + flags = ""; + } + + /* Save the index in the table. */ + md->membernr = i; + + has_docstring = FALSE; + + if (md->docstring != NULL || (docstrings && hasDocstring(pt, overs, md, iff))) + has_docstring = TRUE; + + prcode(fp, +" {SIP_MLNAME_CAST(%N), %smeth_%L_%s, METH_VARARGS%s, ", md->pyname, cast, iff, md->pyname->text, flags); + + if (has_docstring) + prcode(fp, "SIP_MLDOC_CAST(doc_%L_%s)", iff, md->pyname->text); + else + prcode(fp, "NULL"); + + prcode(fp, "}%s\n" + , ((i + 1) < nr) ? "," : ""); + } + + prcode(fp, +"};\n" + ); +} + + +/* + * Generate the "to type" convertor definitions. + */ + +static void generateConvertToDefinitions(mappedTypeDef *mtd,classDef *cd, + FILE *fp) +{ + codeBlock *convtocode; + ifaceFileDef *iff; + argDef type; + + memset(&type, 0, sizeof (argDef)); + + if (cd != NULL) + { + convtocode = cd->convtocode; + iff = cd->iff; + + type.atype = class_type; + type.u.cd = cd; + } + else + { + convtocode = mtd->convtocode; + iff = mtd->iff; + + type.atype = mapped_type; + type.u.mtd = mtd; + } + + /* Generate the type convertors. */ + + if (convtocode != NULL) + { + int need_py, need_ptr, need_iserr, need_xfer; + + /* + * Sometimes type convertors are just stubs that set the error + * flag, so check if we actually need everything so that we + * can avoid compiler warnings. + */ + need_py = (generating_c || usedInCode(convtocode, "sipPy")); + need_ptr = (generating_c || usedInCode(convtocode, "sipCppPtr")); + need_iserr = (generating_c || usedInCode(convtocode, "sipIsErr")); + need_xfer = (generating_c || usedInCode(convtocode, "sipTransferObj")); + + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static int convertTo_%L(PyObject *, void **, int *, PyObject *);}\n" + , iff); + + prcode(fp, +"static int convertTo_%L(PyObject *%s,void **%s,int *%s,PyObject *%s)\n" +"{\n" + , iff, (need_py ? "sipPy" : ""), (need_ptr ? "sipCppPtrV" : ""), (need_iserr ? "sipIsErr" : ""), (need_xfer ? "sipTransferObj" : "")); + + if (need_ptr) + { + if (generating_c) + prcode(fp, +" %b **sipCppPtr = (%b **)sipCppPtrV;\n" +"\n" + , &type, &type); + else + prcode(fp, +" %b **sipCppPtr = reinterpret_cast<%b **>(sipCppPtrV);\n" +"\n" + , &type, &type); + } + + generateCppCodeBlock(convtocode,fp); + + prcode(fp, +"}\n" + ); + } +} + + +/* + * Generate a variable getter. + */ +static void generateVariableGetter(ifaceFileDef *scope, varDef *vd, FILE *fp) +{ + argType atype = vd->type.atype; + const char *first_arg, *last_arg; + int needsNew; + + if (generating_c || !isStaticVar(vd)) + first_arg = "sipSelf"; + else + first_arg = ""; + + last_arg = (generating_c || usedInCode(vd->getcode, "sipPyType")) ? "sipPyType" : ""; + + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static PyObject *varget_%C(void *, PyObject *);}\n" + , vd->fqcname); + + prcode(fp, +"static PyObject *varget_%C(void *%s, PyObject *%s)\n" +"{\n" + , vd->fqcname, first_arg, last_arg); + + if (vd->getcode != NULL) + { + prcode(fp, +" PyObject *sipPy;\n" + ); + } + else + { + prcode(fp, +" "); + + generateNamedValueType(scope, &vd->type, "sipVal", fp); + + prcode(fp, ";\n" + ); + } + + if (!isStaticVar(vd)) + { + if (generating_c) + prcode(fp, +" %S *sipCpp = (%S *)sipSelf;\n" + , classFQCName(vd->ecd), classFQCName(vd->ecd)); + else + prcode(fp, +" %S *sipCpp = reinterpret_cast<%S *>(sipSelf);\n" + , classFQCName(vd->ecd), classFQCName(vd->ecd)); + + prcode(fp, +"\n" + ); + } + + /* Handle any handwritten getter. */ + if (vd->getcode != NULL) + { + generateCppCodeBlock(vd->getcode, fp); + + prcode(fp, +"\n" +" return sipPy;\n" +"}\n" + ); + + return; + } + + needsNew = ((atype == class_type || atype == mapped_type) && vd->type.nrderefs == 0 && isConstArg(&vd->type)); + + if (needsNew) + { + if (generating_c) + prcode(fp, +" *sipVal = "); + else + prcode(fp, +" sipVal = new %b(", &vd->type); + } + else + { + prcode(fp, +" sipVal = "); + + if ((atype == class_type || atype == mapped_type) && vd->type.nrderefs == 0) + prcode(fp, "&"); + } + + generateVarMember(vd, fp); + + prcode(fp, "%s;\n" +"\n" + , ((needsNew && !generating_c) ? ")" : "")); + + switch (atype) + { + case mapped_type: + case class_type: + { + ifaceFileDef *iff; + + if (atype == mapped_type) + iff = vd->type.u.mtd->iff; + else + iff = vd->type.u.cd->iff; + + prcode(fp, +" return sipConvertFrom%sType(", (needsNew ? "New" : "")); + + if (isConstArg(&vd->type)) + prcode(fp, "const_cast<%b *>(sipVal)", &vd->type); + else + prcode(fp, "sipVal"); + + prcode(fp, ",sipType_%C, NULL);\n" + , iff->fqcname); + } + + break; + + case bool_type: + case cbool_type: + prcode(fp, +" return PyBool_FromLong(sipVal);\n" + ); + + break; + + case ascii_string_type: + if (vd->type.nrderefs == 0) + prcode(fp, +" return PyUnicode_DecodeASCII(&sipVal, 1, NULL);\n" + ); + else + prcode(fp, +" if (sipVal == NULL)\n" +" {\n" +" Py_INCREF(Py_None);\n" +" return Py_None;\n" +" }\n" +"\n" +" return PyUnicode_DecodeASCII(sipVal, strlen(sipVal), NULL);\n" + ); + + break; + + case latin1_string_type: + if (vd->type.nrderefs == 0) + prcode(fp, +" return PyUnicode_DecodeLatin1(&sipVal, 1, NULL);\n" + ); + else + prcode(fp, +" if (sipVal == NULL)\n" +" {\n" +" Py_INCREF(Py_None);\n" +" return Py_None;\n" +" }\n" +"\n" +" return PyUnicode_DecodeLatin1(sipVal, strlen(sipVal), NULL);\n" + ); + + break; + + case utf8_string_type: + if (vd->type.nrderefs == 0) + prcode(fp, +"#if PY_MAJOR_VERSION >= 3\n" +" return PyUnicode_FromStringAndSize(&sipVal, 1);\n" +"#else\n" +" return PyUnicode_DecodeUTF8(&sipVal, 1, NULL);\n" +"#endif\n" + ); + else + prcode(fp, +" if (sipVal == NULL)\n" +" {\n" +" Py_INCREF(Py_None);\n" +" return Py_None;\n" +" }\n" +"\n" +"#if PY_MAJOR_VERSION >= 3\n" +" return PyUnicode_FromString(sipVal);\n" +"#else\n" +" return PyUnicode_DecodeUTF8(sipVal, strlen(sipVal), NULL);\n" +"#endif\n" + ); + + break; + + case sstring_type: + case ustring_type: + case string_type: + { + const char *cast = ((atype != string_type) ? "(char *)" : ""); + + if (vd->type.nrderefs == 0) + prcode(fp, +" return SIPBytes_FromStringAndSize(%s&sipVal, 1);\n" + , cast); + else + prcode(fp, +" if (sipVal == NULL)\n" +" {\n" +" Py_INCREF(Py_None);\n" +" return Py_None;\n" +" }\n" +"\n" +" return SIPBytes_FromString(%ssipVal);\n" + , cast); + } + + break; + + case wstring_type: + if (vd->type.nrderefs == 0) + prcode(fp, +" return PyUnicode_FromWideChar(&sipVal, 1);\n" + ); + else + prcode(fp, +" if (sipVal == NULL)\n" +" {\n" +" Py_INCREF(Py_None);\n" +" return Py_None;\n" +" }\n" +"\n" +" return PyUnicode_FromWideChar(sipVal, (SIP_SSIZE_T)wcslen(sipVal));\n" + ); + + break; + + case float_type: + case cfloat_type: + prcode(fp, +" return PyFloat_FromDouble((double)sipVal);\n" + ); + break; + + case double_type: + case cdouble_type: + prcode(fp, +" return PyFloat_FromDouble(sipVal);\n" + ); + break; + + case enum_type: + if (vd->type.u.ed->fqcname != NULL) + { + prcode(fp, +" return sipConvertFromEnum(sipVal, sipType_%C);\n" + , vd->type.u.ed->fqcname); + + break; + } + + /* Drop through. */ + + case short_type: + case cint_type: + case int_type: + prcode(fp, +" return SIPLong_FromLong(sipVal);\n" + ); + break; + + case long_type: + prcode(fp, +" return PyLong_FromLong(sipVal);\n" + ); + break; + + case ushort_type: + case uint_type: + case ulong_type: + prcode(fp, +" return PyLong_FromUnsignedLong(sipVal);\n" + ); + break; + + case longlong_type: + prcode(fp, +" return PyLong_FromLongLong(sipVal);\n" + ); + break; + + case ulonglong_type: + prcode(fp, +" return PyLong_FromUnsignedLongLong(sipVal);\n" + ); + break; + + case struct_type: + case void_type: + prcode(fp, +" return sipConvertFrom%sVoidPtr(sipVal);\n" + , (isConstArg(&vd->type) ? "Const" : "")); + break; + + case pyobject_type: + case pytuple_type: + case pylist_type: + case pydict_type: + case pycallable_type: + case pyslice_type: + case pytype_type: + prcode(fp, +" Py_XINCREF(sipVal);\n" +" return sipVal;\n" + ); + break; + } + + prcode(fp, +"}\n" + ); +} + + +/* + * Generate a variable setter. + */ +static void generateVariableSetter(ifaceFileDef *scope, varDef *vd, FILE *fp) +{ + argType atype = vd->type.atype; + const char *first_arg, *last_arg; + char *deref; + int might_be_temp, keep; + + keep = keepPyReference(&vd->type); + + if (generating_c || !isStaticVar(vd)) + first_arg = "sipSelf"; + else + first_arg = ""; + + if (generating_c || (!isStaticVar(vd) && keep)) + last_arg = "sipPySelf"; + else + last_arg = ""; + + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static int varset_%C(void *, PyObject *, PyObject *);}\n" + , vd->fqcname); + + prcode(fp, +"static int varset_%C(void *%s, PyObject *sipPy, PyObject *%s)\n" +"{\n" + , vd->fqcname, first_arg, last_arg); + + if (vd->setcode == NULL) + { + prcode(fp, +" "); + + generateNamedValueType(scope, &vd->type, "sipVal", fp); + + prcode(fp, ";\n" + ); + } + + if (!isStaticVar(vd)) + { + if (generating_c) + prcode(fp, +" %S *sipCpp = (%S *)sipSelf;\n" + , classFQCName(vd->ecd), classFQCName(vd->ecd)); + else + prcode(fp, +" %S *sipCpp = reinterpret_cast<%S *>(sipSelf);\n" + , classFQCName(vd->ecd), classFQCName(vd->ecd)); + + prcode(fp, +"\n" + ); + } + + /* Handle any handwritten setter. */ + if (vd->setcode != NULL) + { + prcode(fp, +" int sipErr = 0;\n" +"\n" + ); + + generateCppCodeBlock(vd->setcode, fp); + + prcode(fp, +"\n" +" return (sipErr ? -1 : 0);\n" +"}\n" + ); + + return; + } + + if (vd->type.nrderefs == 0 && (atype == mapped_type || (atype == class_type && vd->type.u.cd->convtocode != NULL))) + prcode(fp, +" int sipValState;\n" + ); + + if (atype == class_type || atype == mapped_type) + prcode(fp, +" int sipIsErr = 0;\n" +"\n" + ); + + might_be_temp = generateObjToCppConversion(&vd->type, fp); + + deref = ""; + + if (atype == class_type || atype == mapped_type) + { + if (vd->type.nrderefs == 0) + deref = "*"; + + prcode(fp, +"\n" +" if (sipIsErr)\n" +" return -1;\n" +"\n" + ); + } + else + { + prcode(fp, +"\n" +" if (PyErr_Occurred() != NULL)\n" +" return -1;\n" +"\n" + ); + } + + if (atype == pyobject_type || atype == pytuple_type || + atype == pylist_type || atype == pydict_type || + atype == pycallable_type || atype == pyslice_type || + atype == pytype_type) + { + prcode(fp, +" Py_XDECREF("); + + generateVarMember(vd, fp); + + prcode(fp, ");\n" +" Py_INCREF(sipVal);\n" +"\n" + ); + } + + prcode(fp, +" "); + + generateVarMember(vd, fp); + + prcode(fp, " = %ssipVal;\n" + , deref); + + /* Note that wchar_t * leaks here. */ + + if (might_be_temp) + prcode(fp, +"\n" +" sipReleaseType(sipVal, sipType_%C, sipValState);\n" + , classFQCName(vd->type.u.cd)); + else if (vd->type.atype == mapped_type && vd->type.nrderefs == 0 && !noRelease(vd->type.u.mtd)) + prcode(fp, +"\n" +" sipReleaseType(sipVal, sipType_%T, sipValState);\n" + , &vd->type); + + /* Generate the code to keep the object alive while we use its data. */ + if (keep) + { + if (isStaticVar(vd)) + { + prcode(fp, +"\n" +" static PyObject *sipKeep = 0;\n" +"\n" +" Py_XDECREF(sipKeep);\n" +" sipKeep = sipPy;\n" +" Py_INCREF(sipKeep);\n" + ); + } + else + { + vd->type.key = scope->module->next_key++; + + prcode(fp, +"\n" +" sipKeepReference(sipPySelf, %d, sipPy);\n" + , vd->type.key); + } + } + + prcode(fp, +"\n" +" return 0;\n" +"}\n" + ); +} + + +/* + * Generate the member variable of a class. + */ +static void generateVarMember(varDef *vd, FILE *fp) +{ + if (isStaticVar(vd)) + prcode(fp,"%S::",classFQCName(vd->ecd)); + else + prcode(fp,"sipCpp->"); + + prcode(fp, "%s", scopedNameTail(vd->fqcname)); +} + + +/* + * Generate the declaration of a variable that is initialised from a Python + * object. Return TRUE if the value might be a temporary on the heap. + */ +static int generateObjToCppConversion(argDef *ad,FILE *fp) +{ + int might_be_temp = FALSE; + char *rhs = NULL; + + prcode(fp, +" sipVal = "); + + switch (ad->atype) + { + case mapped_type: + { + const char *tail; + + if (generating_c) + { + prcode(fp, "(%b *)", ad); + tail = ""; + } + else + { + prcode(fp, "reinterpret_cast<%b *>(", ad); + tail = ")"; + } + + /* Note that we don't support /Transfer/ but could do. */ + + prcode(fp, "sipForceConvertToType(sipPy,sipType_%T,NULL,%s,%s,&sipIsErr)", ad, (ad->nrderefs ? "0" : "SIP_NOT_NONE"), (ad->nrderefs ? "NULL" : "&sipValState")); + + prcode(fp, "%s;\n" + , tail); + } + break; + + case class_type: + { + const char *tail; + + if (ad->nrderefs == 0 && ad->u.cd->convtocode != NULL) + might_be_temp = TRUE; + + if (generating_c) + { + prcode(fp, "(%b *)", ad); + tail = ""; + } + else + { + prcode(fp, "reinterpret_cast<%b *>(", ad); + tail = ")"; + } + + /* + * Note that we don't support /Transfer/ but could do. We could + * also support /Constrained/ (so long as we also supported it for + * all types). + */ + + prcode(fp, "sipForceConvertToType(sipPy,sipType_%C,NULL,%s,%s,&sipIsErr)", classFQCName(ad->u.cd), (ad->nrderefs ? "0" : "SIP_NOT_NONE"), (might_be_temp ? "&sipValState" : "NULL")); + + prcode(fp, "%s;\n" + , tail); + } + break; + + case enum_type: + prcode(fp, "(%E)SIPLong_AsLong(sipPy);\n" + , ad->u.ed); + break; + + case sstring_type: + if (ad->nrderefs == 0) + rhs = "(signed char)sipBytes_AsChar(sipPy)"; + else if (isConstArg(ad)) + rhs = "(const signed char *)sipBytes_AsString(sipPy)"; + else + rhs = "(signed char *)sipBytes_AsString(sipPy)"; + break; + + case ustring_type: + if (ad->nrderefs == 0) + rhs = "(unsigned char)sipBytes_AsChar(sipPy)"; + else if (isConstArg(ad)) + rhs = "(const unsigned char *)sipBytes_AsString(sipPy)"; + else + rhs = "(unsigned char *)sipBytes_AsString(sipPy)"; + break; + + case ascii_string_type: + if (ad->nrderefs == 0) + rhs = "sipString_AsASCIIChar(sipPy)"; + else if (isConstArg(ad)) + rhs = "sipString_AsASCIIString(&sipPy)"; + else + rhs = "(char *)sipString_AsASCIIString(&sipPy)"; + break; + + case latin1_string_type: + if (ad->nrderefs == 0) + rhs = "sipString_AsLatin1Char(sipPy)"; + else if (isConstArg(ad)) + rhs = "sipString_AsLatin1String(&sipPy)"; + else + rhs = "(char *)sipString_AsLatin1String(&sipPy)"; + break; + + case utf8_string_type: + if (ad->nrderefs == 0) + rhs = "sipString_AsUTF8Char(sipPy)"; + else if (isConstArg(ad)) + rhs = "sipString_AsUTF8String(&sipPy)"; + else + rhs = "(char *)sipString_AsUTF8String(&sipPy)"; + break; + + case string_type: + if (ad->nrderefs == 0) + rhs = "sipBytes_AsChar(sipPy)"; + else if (isConstArg(ad)) + rhs = "sipBytes_AsString(sipPy)"; + else + rhs = "(const *)sipBytes_AsString(sipPy)"; + break; + + case wstring_type: + if (ad->nrderefs == 0) + rhs = "sipUnicode_AsWChar(sipPy)"; + else + rhs = "sipUnicode_AsWString(sipPy)"; + break; + + case float_type: + case cfloat_type: + rhs = "(float)PyFloat_AsDouble(sipPy)"; + break; + + case double_type: + case cdouble_type: + rhs = "PyFloat_AsDouble(sipPy)"; + break; + + case bool_type: + case cbool_type: + rhs = "(bool)SIPLong_AsLong(sipPy)"; + break; + + case ushort_type: + rhs = "(unsigned short)sipLong_AsUnsignedLong(sipPy)"; + break; + + case short_type: + rhs = "(short)SIPLong_AsLong(sipPy)"; + break; + + case uint_type: + rhs = "(unsigned)sipLong_AsUnsignedLong(sipPy)"; + break; + + case int_type: + case cint_type: + rhs = "(int)SIPLong_AsLong(sipPy)"; + break; + + case ulong_type: + rhs = "sipLong_AsUnsignedLong(sipPy)"; + break; + + case long_type: + rhs = "PyLong_AsLong(sipPy)"; + break; + + case ulonglong_type: + rhs = "PyLong_AsUnsignedLongLong(sipPy)"; + break; + + case longlong_type: + rhs = "PyLong_AsLongLong(sipPy)"; + break; + + case struct_type: + prcode(fp, "(struct %S *)sipConvertToVoidPtr(sipPy);\n" + , ad->u.sname); + break; + + case void_type: + rhs = "sipConvertToVoidPtr(sipPy)"; + break; + + case pyobject_type: + case pytuple_type: + case pylist_type: + case pydict_type: + case pycallable_type: + case pyslice_type: + case pytype_type: + rhs = "sipPy"; + break; + } + + if (rhs != NULL) + prcode(fp, "%s;\n" + , rhs); + + return might_be_temp; +} + + +/* + * Returns TRUE if the given method is a slot that takes zero arguments. + */ +static int isZeroArgSlot(memberDef *md) +{ + slotType st = md->slot; + + return (st == str_slot || st == int_slot || st == long_slot || + st == float_slot || st == invert_slot || st == neg_slot || + st == len_slot || st == bool_slot || st == pos_slot || + st == abs_slot || st == repr_slot || st == hash_slot || + st == index_slot || st == iter_slot || st == next_slot); +} + + +/* + * Returns TRUE if the given method is a slot that takes more than one + * argument. + */ +static int isMultiArgSlot(memberDef *md) +{ + slotType st = md->slot; + + return (st == setitem_slot || st == call_slot); +} + + +/* + * Returns TRUE if the given method is a slot that returns void (ie. nothing + * other than an error indicator). + */ +int isVoidReturnSlot(memberDef *md) +{ + slotType st = md->slot; + + return (st == setitem_slot || st == delitem_slot); +} + + +/* + * Returns TRUE if the given method is a slot that returns int. + */ +int isIntReturnSlot(memberDef *md) +{ + slotType st = md->slot; + + return (st == bool_slot || st == contains_slot || st == cmp_slot); +} + + +/* + * Returns TRUE if the given method is a slot that returns SIP_SSIZE_T. + */ +int isSSizeReturnSlot(memberDef *md) +{ + slotType st = md->slot; + + return (st == len_slot); +} + + +/* + * Returns TRUE if the given method is a slot that returns long. + */ +int isLongReturnSlot(memberDef *md) +{ + slotType st = md->slot; + + return (st == hash_slot); +} + + +/* + * Returns TRUE if the given method is a slot that takes an int argument. + */ +static int isIntArgSlot(memberDef *md) +{ + slotType st = md->slot; + + return (st == repeat_slot || st == irepeat_slot); +} + + +/* + * Returns TRUE if the given method is an inplace number slot. + */ +static int isInplaceNumberSlot(memberDef *md) +{ + slotType st = md->slot; + + return (st == iadd_slot || st == isub_slot || st == imul_slot || + st == idiv_slot || st == imod_slot || st == ifloordiv_slot || + st == itruediv_slot || st == ior_slot || st == ixor_slot || + st == iand_slot || st == ilshift_slot || st == irshift_slot); +} + + +/* + * Returns TRUE if the given method is an inplace sequence slot. + */ +static int isInplaceSequenceSlot(memberDef *md) +{ + slotType st = md->slot; + + return (st == iconcat_slot || st == irepeat_slot); +} + + +/* + * Returns TRUE if the given method is a number slot. + */ +int isNumberSlot(memberDef *md) +{ + slotType st = md->slot; + + return (st == add_slot || st == sub_slot || st == mul_slot || + st == div_slot || st == mod_slot || st == floordiv_slot || + st == truediv_slot || st == and_slot || st == or_slot || + st == xor_slot || st == lshift_slot || st == rshift_slot); +} + + +/* + * Returns TRUE if the given method is a rich compare slot. + */ +int isRichCompareSlot(memberDef *md) +{ + slotType st = md->slot; + + return (st == lt_slot || st == le_slot || st == eq_slot || + st == ne_slot || st == gt_slot || st == ge_slot); +} + + +/* + * Generate a Python slot handler for either a class, an enum or an extender. + */ +static void generateSlot(moduleDef *mod, classDef *cd, enumDef *ed, + memberDef *md, FILE *fp) +{ + char *arg_str, *prefix, *ret_type; + int ret_int, nr_args; + overDef *od, *overs; + scopedNameDef *fqcname; + nameDef *pyname; + + if (ed != NULL) + { + prefix = "Type"; + pyname = ed->pyname; + fqcname = ed->fqcname; + overs = ed->overs; + } + else if (cd != NULL) + { + prefix = "Type"; + pyname = cd->pyname; + fqcname = classFQCName(cd); + overs = cd->overs; + } + else + { + prefix = NULL; + pyname = NULL; + fqcname = NULL; + overs = mod->overs; + } + + if (isVoidReturnSlot(md) || isIntReturnSlot(md)) + { + ret_int = TRUE; + ret_type = "int "; + } + else + { + ret_int = FALSE; + + if (isSSizeReturnSlot(md)) + ret_type = "SIP_SSIZE_T "; + else if (isLongReturnSlot(md)) + ret_type = "long "; + else + ret_type = "PyObject *"; + } + + if (isIntArgSlot(md)) + { + nr_args = 0; + arg_str = "PyObject *sipSelf,int a0"; + } + else if (isMultiArgSlot(md)) + { + nr_args = 2; + arg_str = "PyObject *sipSelf,PyObject *sipArgs"; + } + else if (isZeroArgSlot(md)) + { + nr_args = 0; + arg_str = "PyObject *sipSelf"; + } + else if (isNumberSlot(md)) + { + nr_args = 2; + arg_str = "PyObject *sipArg0,PyObject *sipArg1"; + } + else + { + nr_args = 1; + arg_str = "PyObject *sipSelf,PyObject *sipArg"; + } + + prcode(fp, +"\n" +"\n" + ); + + if (py2OnlySlot(md->slot)) + prcode(fp, +"#if PY_MAJOR_VERSION < 3\n" + ); + else if (py2_5LaterSlot(md->slot)) + prcode(fp, +"#if PY_VERSION_HEX >= 0x02050000\n" + ); + + if (!generating_c) + { + prcode(fp, +"extern \"C\" {static %sslot_", ret_type); + + if (cd != NULL) + prcode(fp, "%L_", cd->iff); + else if (fqcname != NULL) + prcode(fp, "%C_", fqcname); + + prcode(fp, "%s(%s);}\n" + , md->pyname->text, arg_str); + } + + prcode(fp, +"static %sslot_", ret_type); + + if (cd != NULL) + prcode(fp, "%L_", cd->iff); + else if (fqcname != NULL) + prcode(fp, "%C_", fqcname); + + prcode(fp, "%s(%s)\n" +"{\n" + , md->pyname->text, arg_str); + + if (isInplaceNumberSlot(md)) + prcode(fp, +" if (!PyObject_TypeCheck(sipSelf, sipTypeAsPyTypeObject(sip%s_%C)))\n" +" {\n" +" Py_INCREF(Py_NotImplemented);\n" +" return Py_NotImplemented;\n" +" }\n" +"\n" + , prefix, fqcname); + + if (!isNumberSlot(md)) + { + if (cd != NULL) + prcode(fp, +" %S *sipCpp = reinterpret_cast<%S *>(sipGetCppPtr((sipSimpleWrapper *)sipSelf,sipType_%C));\n" +"\n" +" if (!sipCpp)\n" +" return %s;\n" +"\n" + , fqcname, fqcname, fqcname + , (md->slot == cmp_slot ? "-2" : (ret_int ? "-1" : "0"))); + else + prcode(fp, +" %S sipCpp = static_cast<%S>(SIPLong_AsLong(sipSelf));\n" +"\n" + , fqcname, fqcname); + } + + if (nr_args > 0) + prcode(fp, +" PyObject *sipParseErr = NULL;\n" + ); + + for (od = overs; od != NULL; od = od->next) + if (od->common == md && isAbstract(od)) + { + prcode(fp, +" PyObject *sipOrigSelf = sipSelf;\n" + ); + + break; + } + + for (od = overs; od != NULL; od = od->next) + if (od->common == md) + generateFunctionBody(od, cd, NULL, cd, (ed == NULL && !dontDerefSelf(od)), mod, fp); + + if (nr_args > 0) + { + switch (md->slot) + { + case cmp_slot: + prcode(fp, +"\n" +" return 2;\n" + ); + break; + + case concat_slot: + case iconcat_slot: + case repeat_slot: + case irepeat_slot: + prcode(fp, +"\n" +" /* Raise an exception if the argument couldn't be parsed. */\n" +" sipBadOperatorArg(sipSelf,sipArg,%s);\n" +"\n" +" return NULL;\n" + ,slotName(md->slot)); + break; + + default: + if (isNumberSlot(md) || isRichCompareSlot(md) || isInplaceNumberSlot(md)) + { + prcode(fp, +"\n" +" Py_XDECREF(sipParseErr);\n" +"\n" +" if (sipParseErr == Py_None)\n" +" return NULL;\n" + ); + } + + if (isNumberSlot(md) || isRichCompareSlot(md)) + { + /* We can't extend enum slots. */ + if (cd == NULL) + prcode(fp, +"\n" +" Py_INCREF(Py_NotImplemented);\n" +" return Py_NotImplemented;\n" + ); + else if (isNumberSlot(md)) + prcode(fp, +"\n" +" return sipPySlotExtend(&sipModuleAPI_%s,%s,NULL,sipArg0,sipArg1);\n" + , mod->name, slotName(md->slot)); + else + prcode(fp, +"\n" +" return sipPySlotExtend(&sipModuleAPI_%s,%s,sipType_%C,sipSelf,sipArg);\n" + , mod->name, slotName(md->slot), fqcname); + } + else if (isInplaceNumberSlot(md)) + { + prcode(fp, +"\n" +" PyErr_Clear();\n" +"\n" +" Py_INCREF(Py_NotImplemented);\n" +" return Py_NotImplemented;\n" + ); + } + else + { + prcode(fp, +"\n" +" /* Raise an exception if the arguments couldn't be parsed. */\n" +" sipNoMethod(sipParseErr, %N, %N, NULL);\n" +"\n" +" return %s;\n" + , pyname, md->pyname + ,ret_int ? "-1" : "0"); + } + } + } + + prcode(fp, +"}\n" + ); + + if (py2OnlySlot(md->slot) || py2_5LaterSlot(md->slot)) + prcode(fp, +"#endif\n" + ); +} + + +/* + * Generate the member functions for a class. + */ +static void generateClassFunctions(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp) +{ + visibleList *vl; + memberDef *md; + + /* Any shadow code. */ + if (hasShadow(cd)) + { + generateShadowClassDeclaration(pt, cd, fp); + generateShadowCode(pt, mod, cd, fp); + } + + /* The member functions. */ + for (vl = cd->visible; vl != NULL; vl = vl->next) + if (vl->m->slot == no_slot) + generateFunction(pt, vl->m, vl->cd->overs, cd, vl->cd, mod, fp); + + /* The slot functions. */ + for (md = cd->members; md != NULL; md = md->next) + if (cd->iff->type == namespace_iface) + generateOrdinaryFunction(pt, mod, cd, NULL, md, fp); + else if (md->slot != no_slot && md->slot != unicode_slot) + generateSlot(mod, cd, NULL, md, fp); + + if (cd->iff->type != namespace_iface && !generating_c) + { + classList *cl; + int need_ptr, need_cast_ptr, need_state; + + /* The cast function. */ + prcode(fp, +"\n" +"\n" +"/* Cast a pointer to a type somewhere in its superclass hierarchy. */\n" +"extern \"C\" {static void *cast_%L(void *, const sipTypeDef *);}\n" +"static void *cast_%L(void *ptr, const sipTypeDef *targetType)\n" +"{\n" + , cd->iff + , cd->iff); + + if (cd->supers != NULL) + prcode(fp, +" void *res;\n" +"\n" + ); + + prcode(fp, +" if (targetType == sipType_%C)\n" +" return ptr;\n" + ,classFQCName(cd)); + + for (cl = cd->supers; cl != NULL; cl = cl->next) + { + scopedNameDef *sname = cl->cd->iff->fqcname; + + prcode(fp, +"\n" +" if ((res = ((const sipClassTypeDef *)sipType_%C)->ctd_cast((%S *)(%S *)ptr,targetType)) != NULL)\n" +" return res;\n" + ,sname,sname,classFQCName(cd)); + } + + prcode(fp, +"\n" +" return NULL;\n" +"}\n" + ); + + /* Generate the release function without compiler warnings. */ + need_ptr = need_cast_ptr = need_state = FALSE; + + if (cd->dealloccode != NULL) + need_ptr = need_cast_ptr = usedInCode(cd->dealloccode, "sipCpp"); + + if (canCreate(cd) || isPublicDtor(cd)) + { + if (hasShadow(cd)) + need_ptr = need_state = TRUE; + else if (isPublicDtor(cd)) + need_ptr = TRUE; + } + + prcode(fp, +"\n" +"\n" +"/* Call the instance's destructor. */\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static void release_%L(void *, int);}\n" + , cd->iff); + + prcode(fp, +"static void release_%L(void *%s,int%s)\n" +"{\n" + , cd->iff, (need_ptr ? "sipCppV" : ""), (need_state ? " sipState" : "")); + + if (cd->dealloccode != NULL) + { + if (need_cast_ptr) + { + prcode(fp, +" "); + + generateClassFromVoid(cd, "sipCpp", "sipCppV", fp); + + prcode(fp, ";\n" +"\n" + ); + } + + generateCppCodeBlock(cd->dealloccode, fp); + + prcode(fp, +"\n" + ); + } + + if (canCreate(cd) || isPublicDtor(cd)) + { + int rgil = ((release_gil || isReleaseGILDtor(cd)) && !isHoldGILDtor(cd)); + + /* + * If there is an explicit public dtor then assume there is some + * way to call it which we haven't worked out (because we don't + * fully understand C++). + */ + + if (rgil) + prcode(fp, +" Py_BEGIN_ALLOW_THREADS\n" +"\n" + ); + + if (hasShadow(cd)) + { + prcode(fp, +" if (sipState & SIP_DERIVED_CLASS)\n" +" delete reinterpret_cast<sip%C *>(sipCppV);\n" + , classFQCName(cd)); + + if (isPublicDtor(cd)) + prcode(fp, +" else\n" +" delete reinterpret_cast<%U *>(sipCppV);\n" + , cd); + } + else if (isPublicDtor(cd)) + prcode(fp, +" delete reinterpret_cast<%U *>(sipCppV);\n" + , cd); + + if (rgil) + prcode(fp, +"\n" +" Py_END_ALLOW_THREADS\n" + ); + } + + prcode(fp, +"}\n" + ); + } + + /* The traverse function. */ + if (cd->travcode != NULL) + { + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static int traverse_%C(void *, visitproc, void *);}\n" + , classFQCName(cd)); + + prcode(fp, +"static int traverse_%C(void *sipCppV,visitproc sipVisit,void *sipArg)\n" +"{\n" +" ", classFQCName(cd)); + + generateClassFromVoid(cd, "sipCpp", "sipCppV", fp); + + prcode(fp, ";\n" +" int sipRes;\n" +"\n" + ); + + generateCppCodeBlock(cd->travcode, fp); + + prcode(fp, +"\n" +" return sipRes;\n" +"}\n" + ); + } + + /* The clear function. */ + if (cd->clearcode != NULL) + { + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static int clear_%C(void *);}\n" + , classFQCName(cd)); + + prcode(fp, +"static int clear_%C(void *sipCppV)\n" +"{\n" +" ", classFQCName(cd)); + + generateClassFromVoid(cd, "sipCpp", "sipCppV", fp); + + prcode(fp, ";\n" +" int sipRes;\n" +"\n" + ); + + generateCppCodeBlock(cd->clearcode, fp); + + prcode(fp, +"\n" +" return sipRes;\n" +"}\n" + ); + } + + /* The buffer interface functions. */ + if (cd->getbufcode != NULL) + { + int need_cpp = usedInCode(cd->getbufcode, "sipCpp"); + + prcode(fp, +"\n" +"\n" +"#if PY_MAJOR_VERSION >= 3\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static int getbuffer_%C(PyObject *, void *, Py_buffer *, int);}\n" + , classFQCName(cd)); + + prcode(fp, +"static int getbuffer_%C(PyObject *%s, void *%s, Py_buffer *sipBuffer, int %s)\n" +"{\n" + , classFQCName(cd), argName("sipSelf", cd->getbufcode), (generating_c || need_cpp ? "sipCppV" : ""), argName("sipFlags", cd->getbufcode)); + + if (need_cpp) + { + prcode(fp, " "); + generateClassFromVoid(cd, "sipCpp", "sipCppV", fp); + prcode(fp, ";\n" + ); + } + + prcode(fp, +" int sipRes;\n" +"\n" + ); + + generateCppCodeBlock(cd->getbufcode, fp); + + prcode(fp, +"\n" +" return sipRes;\n" +"}\n" +"#endif\n" + ); + } + + if (cd->releasebufcode != NULL) + { + prcode(fp, +"\n" +"\n" +"#if PY_MAJOR_VERSION >= 3\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static void releasebuffer_%C(PyObject *, void *, Py_buffer *);}\n" + , classFQCName(cd)); + + prcode(fp, +"static void releasebuffer_%C(PyObject *%s, void *sipCppV, Py_buffer *)\n" +"{\n" +" ", classFQCName(cd) + , argName("sipSelf", cd->releasebufcode)); + + generateClassFromVoid(cd, "sipCpp", "sipCppV", fp); + + prcode(fp, ";\n" +"\n" + ); + + generateCppCodeBlock(cd->releasebufcode, fp); + + prcode(fp, +"}\n" +"#endif\n" + ); + } + + if (cd->readbufcode != NULL) + { + prcode(fp, +"\n" +"\n" +"#if PY_MAJOR_VERSION < 3\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static SIP_SSIZE_T getreadbuffer_%C(PyObject *, void *, SIP_SSIZE_T, void **);}\n" + , classFQCName(cd)); + + prcode(fp, +"static SIP_SSIZE_T getreadbuffer_%C(PyObject *%s, void *sipCppV, SIP_SSIZE_T %s, void **%s)\n" +"{\n" +" ", classFQCName(cd) + , argName("sipSelf", cd->readbufcode) + , argName("sipSegment", cd->readbufcode) + , argName("sipPtrPtr", cd->readbufcode)); + + generateClassFromVoid(cd, "sipCpp", "sipCppV", fp); + + prcode(fp, ";\n" +" SIP_SSIZE_T sipRes;\n" +"\n" + ); + + generateCppCodeBlock(cd->readbufcode, fp); + + prcode(fp, +"\n" +" return sipRes;\n" +"}\n" +"#endif\n" + ); + } + + if (cd->writebufcode != NULL) + { + prcode(fp, +"\n" +"\n" +"#if PY_MAJOR_VERSION < 3\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static SIP_SSIZE_T getwritebuffer_%C(PyObject *, void *, SIP_SSIZE_T, void **);}\n" + , classFQCName(cd)); + + prcode(fp, +"static SIP_SSIZE_T getwritebuffer_%C(PyObject *%s, void *sipCppV, SIP_SSIZE_T %s, void **%s)\n" +"{\n" +" ", classFQCName(cd) + , argName("sipSelf", cd->writebufcode) + , argName("sipSegment", cd->writebufcode) + , argName("sipPtrPtr", cd->writebufcode)); + + generateClassFromVoid(cd, "sipCpp", "sipCppV", fp); + + prcode(fp, ";\n" +" SIP_SSIZE_T sipRes;\n" +"\n" + ); + + generateCppCodeBlock(cd->writebufcode, fp); + + prcode(fp, +"\n" +" return sipRes;\n" +"}\n" +"#endif\n" + ); + } + + if (cd->segcountcode != NULL) + { + prcode(fp, +"\n" +"\n" +"#if PY_MAJOR_VERSION < 3\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static SIP_SSIZE_T getsegcount_%C(PyObject *, void *, SIP_SSIZE_T *);}\n" + , classFQCName(cd)); + + prcode(fp, +"static SIP_SSIZE_T getsegcount_%C(PyObject *%s, void *sipCppV, SIP_SSIZE_T *%s)\n" +"{\n" +" ", classFQCName(cd) + , argName("sipSelf", cd->segcountcode) + , argName("sipLenPtr", cd->segcountcode)); + + generateClassFromVoid(cd, "sipCpp", "sipCppV", fp); + + prcode(fp, ";\n" +" SIP_SSIZE_T sipRes;\n" +"\n" + ); + + generateCppCodeBlock(cd->segcountcode, fp); + + prcode(fp, +"\n" +" return sipRes;\n" +"}\n" +"#endif\n" + ); + } + + if (cd->charbufcode != NULL) + { + prcode(fp, +"\n" +"\n" +"#if PY_MAJOR_VERSION < 3\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static SIP_SSIZE_T getcharbuffer_%C(PyObject *, void *, SIP_SSIZE_T, void **);}\n" + , classFQCName(cd)); + + prcode(fp, +"static SIP_SSIZE_T getcharbuffer_%C(PyObject *%s, void *sipCppV, SIP_SSIZE_T %s, void **%s)\n" +"{\n" +" ", classFQCName(cd) + , argName("sipSelf", cd->charbufcode) + , argName("sipSegment", cd->charbufcode) + , argName("sipPtrPtr", cd->charbufcode)); + + generateClassFromVoid(cd, "sipCpp", "sipCppV", fp); + + prcode(fp, ";\n" +" SIP_SSIZE_T sipRes;\n" +"\n" + ); + + generateCppCodeBlock(cd->charbufcode, fp); + + prcode(fp, +"\n" +" return sipRes;\n" +"}\n" +"#endif\n" + ); + } + + /* The pickle function. */ + if (cd->picklecode != NULL) + { + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static PyObject *pickle_%C(void *);}\n" + , classFQCName(cd)); + + prcode(fp, +"static PyObject *pickle_%C(void *sipCppV)\n" +"{\n" +" ", classFQCName(cd)); + + generateClassFromVoid(cd, "sipCpp", "sipCppV", fp); + + prcode(fp, ";\n" +" PyObject *sipRes;\n" +"\n" + ); + + generateCppCodeBlock(cd->picklecode, fp); + + prcode(fp, +"\n" +" return sipRes;\n" +"}\n" + ); + } + + if (generating_c || assignmentHelper(cd)) + { + /* The assignment helper. */ + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static void assign_%L(void *, SIP_SSIZE_T, const void *);}\n" + , cd->iff); + + prcode(fp, +"static void assign_%L(void *sipDst, SIP_SSIZE_T sipDstIdx, const void *sipSrc)\n" +"{\n" + , cd->iff); + + if (generating_c) + prcode(fp, +" ((%S *)sipDst)[sipDstIdx] = *((const %S *)sipSrc);\n" + , classFQCName(cd), classFQCName(cd)); + else + prcode(fp, +" reinterpret_cast<%S *>(sipDst)[sipDstIdx] = *reinterpret_cast<const %S *>(sipSrc);\n" + , classFQCName(cd), classFQCName(cd)); + + prcode(fp, +"}\n" + ); + + /* The array allocation helper. */ + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static void *array_%L(SIP_SSIZE_T);}\n" + , cd->iff); + + prcode(fp, +"static void *array_%L(SIP_SSIZE_T sipNrElem)\n" +"{\n" + , cd->iff); + + if (generating_c) + prcode(fp, +" return sipMalloc(sizeof (%S) * sipNrElem);\n" + , classFQCName(cd)); + else + prcode(fp, +" return new %S[sipNrElem];\n" + , classFQCName(cd)); + + prcode(fp, +"}\n" + ); + + /* The copy helper. */ + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static void *copy_%L(const void *, SIP_SSIZE_T);}\n" + , cd->iff); + + prcode(fp, +"static void *copy_%L(const void *sipSrc, SIP_SSIZE_T sipSrcIdx)\n" +"{\n" + , cd->iff); + + if (generating_c) + prcode(fp, +" %S *sipPtr = sipMalloc(sizeof (%S));\n" +" *sipPtr = ((const %S *)sipSrc)[sipSrcIdx];\n" +"\n" +" return sipPtr;\n" + , classFQCName(cd), classFQCName(cd) + , classFQCName(cd)); + else + prcode(fp, +" return new %S(reinterpret_cast<const %S *>(sipSrc)[sipSrcIdx]);\n" + , classFQCName(cd), classFQCName(cd)); + + prcode(fp, +"}\n" + ); + } + + /* The dealloc function. */ + if (needDealloc(cd)) + { + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static void dealloc_%L(sipSimpleWrapper *);}\n" + , cd->iff); + + prcode(fp, +"static void dealloc_%L(sipSimpleWrapper *sipSelf)\n" +"{\n" + , cd->iff); + + if (tracing) + prcode(fp, +" sipTrace(SIP_TRACE_DEALLOCS,\"dealloc_%L()\\n\");\n" +"\n" + , cd->iff); + + /* Disable the virtual handlers. */ + if (hasShadow(cd)) + prcode(fp, +" if (sipIsDerived(sipSelf))\n" +" reinterpret_cast<sip%C *>(sipSelf->u.cppPtr)->sipPySelf = NULL;\n" +"\n" + ,classFQCName(cd)); + + if (generating_c || isPublicDtor(cd) || (hasShadow(cd) && isProtectedDtor(cd))) + { + prcode(fp, +" if (sipIsPyOwned(sipSelf))\n" +" {\n" + ); + + if (isDelayedDtor(cd)) + prcode(fp, +" sipAddDelayedDtor(sipSelf);\n" + ); + else if (generating_c) + prcode(fp, +" sipFree(sipSelf->u.cppPtr);\n" + ); + else + prcode(fp, +" release_%L(sipSelf->u.cppPtr,%s);\n" + , cd->iff, (hasShadow(cd) ? "sipSelf->flags" : "0")); + + prcode(fp, +" }\n" + ); + } + + prcode(fp, +"}\n" + ); + } + + /* The type initialisation function. */ + if (canCreate(cd)) + generateTypeInit(cd, mod, fp); +} + + +/* + * Generate the shadow (derived) class code. + */ +static void generateShadowCode(sipSpec *pt, moduleDef *mod, classDef *cd, + FILE *fp) +{ + int nrVirts, virtNr; + virtOverDef *vod; + ctorDef *ct; + + nrVirts = countVirtuals(cd); + + /* Generate the wrapper class constructors. */ + + for (ct = cd->ctors; ct != NULL; ct = ct->next) + { + ctorDef *dct; + + if (isPrivateCtor(ct)) + continue; + + if (ct->cppsig == NULL) + continue; + + /* Check we haven't already handled this C++ signature. */ + for (dct = cd->ctors; dct != ct; dct = dct->next) + if (dct->cppsig != NULL && sameSignature(dct->cppsig, ct->cppsig, TRUE)) + break; + + if (dct != ct) + continue; + + prcode(fp, +"\n" +"sip%C::sip%C(",classFQCName(cd),classFQCName(cd)); + + generateCalledArgs(cd->iff, ct->cppsig, Definition, TRUE, fp); + + prcode(fp,")%X: %S(",ct->exceptions,classFQCName(cd)); + + generateProtectedCallArgs(ct->cppsig, fp); + + prcode(fp,"), sipPySelf(0)\n" +"{\n" + ); + + if (tracing) + { + prcode(fp, +" sipTrace(SIP_TRACE_CTORS,\"sip%C::sip%C(",classFQCName(cd),classFQCName(cd)); + generateCalledArgs(cd->iff, ct->cppsig, Declaration, TRUE, fp); + prcode(fp,")%X (this=0x%%08x)\\n\",this);\n" +"\n" + ,ct->exceptions); + } + + if (nrVirts > 0) + prcode(fp, +" memset(sipPyMethods, 0, sizeof (sipPyMethods));\n" + ); + + prcode(fp, +"}\n" + ); + } + + /* The destructor. */ + + if (!isPrivateDtor(cd)) + { + prcode(fp, +"\n" +"sip%C::~sip%C()%X\n" +"{\n" + ,classFQCName(cd),classFQCName(cd),cd->dtorexceptions); + + if (tracing) + prcode(fp, +" sipTrace(SIP_TRACE_DTORS,\"sip%C::~sip%C()%X (this=0x%%08x)\\n\",this);\n" +"\n" + ,classFQCName(cd),classFQCName(cd),cd->dtorexceptions); + + if (cd->dtorcode != NULL) + generateCppCodeBlock(cd->dtorcode,fp); + + prcode(fp, +" sipCommonDtor(sipPySelf);\n" +"}\n" + ); + } + + /* The meta methods if required. */ + if (pluginPyQt4(pt) && isQObjectSubClass(cd)) + { + if (!noPyQt4QMetaObject(cd)) + prcode(fp, +"\n" +"const QMetaObject *sip%C::metaObject() const\n" +"{\n" +" return sip_%s_qt_metaobject(sipPySelf,sipType_%C);\n" +"}\n" + , classFQCName(cd) + , mod->name, classFQCName(cd)); + + prcode(fp, +"\n" +"int sip%C::qt_metacall(QMetaObject::Call _c,int _id,void **_a)\n" +"{\n" +" _id = %S::qt_metacall(_c,_id,_a);\n" +"\n" +" if (_id >= 0)\n" +" _id = sip_%s_qt_metacall(sipPySelf,sipType_%C,_c,_id,_a);\n" +"\n" +" return _id;\n" +"}\n" +"\n" +"void *sip%C::qt_metacast(const char *_clname)\n" +"{\n" +" return (sip_%s_qt_metacast && sip_%s_qt_metacast(sipPySelf,sipType_%C,_clname)) ? this : %S::qt_metacast(_clname);\n" +"}\n" + , classFQCName(cd) + , classFQCName(cd) + , mod->name, classFQCName(cd) + , classFQCName(cd) + , mod->name, mod->name, classFQCName(cd), classFQCName(cd)); + } + + /* Generate the virtual catchers. */ + + virtNr = 0; + + for (vod = cd->vmembers; vod != NULL; vod = vod->next) + { + overDef *od = &vod->o; + virtOverDef *dvod; + + if (isPrivate(od)) + continue; + + /* + * Check we haven't already handled this C++ signature. The same C++ + * signature should only appear more than once for overloads that are + * enabled for different APIs and that differ in their /In/ and/or + * /Out/ annotations. + */ + for (dvod = cd->vmembers; dvod != vod; dvod = dvod->next) + if (strcmp(dvod->o.cppname, od->cppname) == 0 && sameSignature(dvod->o.cppsig, od->cppsig, TRUE)) + break; + + if (dvod == vod) + generateVirtualCatcher(mod, cd, virtNr++, vod, fp); + } + + /* Generate the wrapper around each protected member function. */ + + generateProtectedDefinitions(cd,fp); + + /* Generate the emitters if needed. */ + if (pluginPyQt3(pt)) + generateEmitters(cd, fp); +} + + +/* + * Generate the emitter functions. + */ +static void generateEmitters(classDef *cd, FILE *fp) +{ + int noIntro; + visibleList *vl; + + for (vl = cd->visible; vl != NULL; vl = vl->next) + { + overDef *od; + + for (od = vl->cd->overs; od != NULL; od = od->next) + if (od->common == vl->m && isSignal(od)) + { + generateEmitter(cd,vl,fp); + break; + } + } + + /* Generate the table of signals to support fan-outs. */ + + noIntro = TRUE; + + for (vl = cd->visible; vl != NULL; vl = vl->next) + { + overDef *od; + + for (od = vl->cd->overs; od != NULL; od = od->next) + if (od->common == vl->m && isSignal(od)) + { + if (noIntro) + { + setHasSigSlots(cd); + + prcode(fp, +"\n" +"static pyqt3QtSignal signals_%C[] = {\n" + ,classFQCName(cd)); + + noIntro = FALSE; + } + + prcode(fp, +" {%N, %C_emit_%s},\n" + ,vl->m->pyname,classFQCName(cd),vl->m->pyname->text); + + break; + } + } + + if (!noIntro) + prcode(fp, +" {NULL, NULL}\n" +"};\n" + ); +} + + +/* + * Generate the protected enums for a class. + */ +static void generateProtectedEnums(sipSpec *pt,classDef *cd,FILE *fp) +{ + enumDef *ed; + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + char *eol; + mroDef *mro; + enumMemberDef *emd; + + if (!isProtectedEnum(ed)) + continue; + + /* See if the class defining the enum is in our class hierachy. */ + for (mro = cd->mro; mro != NULL; mro = mro->next) + if (mro->cd == ed->ecd) + break; + + if (mro == NULL) + continue; + + prcode(fp, +"\n" +" /* Expose this protected enum. */\n" +" enum"); + + if (ed->fqcname != NULL) + prcode(fp," sip%s",scopedNameTail(ed->fqcname)); + + prcode(fp," {"); + + eol = "\n"; + + for (emd = ed->members; emd != NULL; emd = emd->next) + { + prcode(fp,"%s" +" %s = %S::%s",eol,emd->cname,classFQCName(ed->ecd),emd->cname); + + eol = ",\n"; + } + + prcode(fp,"\n" +" };\n" + ); + } +} + + +/* + * Generate the catcher for a virtual function. + */ +static void generateVirtualCatcher(moduleDef *mod, classDef *cd, int virtNr, + virtOverDef *vod, FILE *fp) +{ + overDef *od = &vod->o; + argDef *res; + apiVersionRangeDef *avr; + + normaliseArgs(od->cppsig); + + res = &od->cppsig->result; + + if (res->atype == void_type && res->nrderefs == 0) + res = NULL; + + prcode(fp, +"\n"); + + generateBaseType(cd->iff, &od->cppsig->result, TRUE, fp); + + prcode(fp," sip%C::%O(",classFQCName(cd),od); + generateCalledArgs(cd->iff, od->cppsig, Definition, TRUE, fp); + prcode(fp,")%s%X\n" +"{\n" + ,(isConst(od) ? " const" : ""),od->exceptions); + + if (tracing) + { + prcode(fp, +" sipTrace(SIP_TRACE_CATCHERS,\""); + + generateBaseType(cd->iff, &od->cppsig->result, TRUE, fp); + prcode(fp," sip%C::%O(",classFQCName(cd),od); + generateCalledArgs(cd->iff, od->cppsig, Declaration, TRUE, fp); + prcode(fp,")%s%X (this=0x%%08x)\\n\",this);\n" +"\n" + ,(isConst(od) ? " const" : ""),od->exceptions); + } + + restoreArgs(od->cppsig); + + prcode(fp, +" sip_gilstate_t sipGILState;\n" +" PyObject *meth;\n" +"\n" +" meth = sipIsPyMethod(&sipGILState,"); + + if (isConst(od)) + prcode(fp, "const_cast<char *>("); + + prcode(fp,"&sipPyMethods[%d]",virtNr); + + if (isConst(od)) + prcode(fp,")"); + + prcode(fp,",sipPySelf,"); + + if (isAbstract(od)) + prcode(fp, "%N", cd->pyname); + else + prcode(fp,"NULL"); + + prcode(fp,",%N);\n" +"\n" + ,od->common->pyname); + + prcode(fp, +" if (!meth)\n" + ); + + if (isAbstract(od)) + generateVirtHandlerErrorReturn(res, " ", fp); + else + { + int a; + + if (res == NULL) + prcode(fp, +" {\n" +" "); + else + prcode(fp, +" return "); + + generateUnambiguousClass(cd,vod->scope,fp); + + prcode(fp,"::%O(",od); + + for (a = 0; a < od->cppsig->nrArgs; ++a) + prcode(fp,"%sa%d",(a == 0 ? "" : ","),a); + + prcode(fp,");\n" + ); + + if (res == NULL) + prcode(fp, +" return;\n" +" }\n" + ); + } + + /* + * If this overload doesn't have an API version assume that there are none + * that do. + */ + avr = od->api_range; + + if (avr == NULL) + { + prcode(fp, +"\n" + ); + + generateVirtHandlerCall(mod, cd, vod, res, " ", fp); + } + else + { + virtOverDef *versioned_vod = vod; + + do + { + prcode(fp, +"\n" +" if (sipIsAPIEnabled(%N, %d, %d))\n" +" {\n" + , avr->api_name, avr->from, avr->to); + + generateVirtHandlerCall(mod, cd, versioned_vod, res, " ", fp); + + if (res == NULL) + prcode(fp, +" return;\n" + ); + + prcode(fp, +" }\n" + ); + + /* Find the next overload. */ + while ((versioned_vod = versioned_vod->next) != NULL) + { + if (strcmp(versioned_vod->o.cppname, od->cppname) == 0 && sameSignature(versioned_vod->o.cppsig, od->cppsig, TRUE)) + { + avr = versioned_vod->o.api_range; + + /* Check that it has an API specified. */ + if (avr == NULL) + { + fatalScopedName(classFQCName(cd)); + fatal("::"); + prOverloadName(stderr, od); + fatal(" has versioned and unversioned overloads\n"); + } + + break; + } + } + } + while (versioned_vod != NULL); + + prcode(fp, +"\n" + ); + + if (isAbstract(od)) + generateVirtHandlerErrorReturn(res, " ", fp); + else + { + int a; + + prcode(fp, " %s", (res != NULL ? "return " : "")); + + generateUnambiguousClass(cd, vod->scope, fp); + + prcode(fp, "::%O(", od); + + for (a = 0; a < od->cppsig->nrArgs; ++a) + prcode(fp, "%sa%d", (a == 0 ? "" : ","), a); + + prcode(fp,");\n" + ); + } + } + + prcode(fp, +"}\n" + ); +} + + +/* + * Generate a call to a single virtual handler. + */ +static void generateVirtHandlerCall(moduleDef *mod, classDef *cd, + virtOverDef *vod, argDef *res, const char *indent, FILE *fp) +{ + overDef *od = &vod->o; + virtHandlerDef *vhd = od->virthandler; + signatureDef saved; + argDef *ad; + int a, args_keep = FALSE, result_keep = FALSE; + + if (isNewThread(od)) + prcode(fp, +"%ssipStartThread();\n" +"\n" + , indent); + + saved = *vhd->cppsig; + fakeProtectedArgs(vhd->cppsig); + + if (vhd->module == mod) + { + prcode(fp, +"%sextern ", indent); + + generateBaseType(cd->iff, &od->cppsig->result, FALSE, fp); + + prcode(fp, " sipVH_%s_%d(sip_gilstate_t,PyObject *", vhd->module->name, vhd->virthandlernr); + } + else + { + prcode(fp, +"%stypedef ", indent); + + generateBaseType(cd->iff, &od->cppsig->result, FALSE, fp); + + prcode(fp, " (*sipVH_%s_%d)(sip_gilstate_t,PyObject *", vhd->module->name, vhd->virthandlernr); + } + + if (vhd->cppsig->nrArgs > 0) + { + prcode(fp, ","); + generateCalledArgs(cd->iff, vhd->cppsig, Declaration, FALSE, fp); + } + + *vhd->cppsig = saved; + + /* Add extra arguments for all the references we need to keep. */ + if (res != NULL && keepPyReference(res)) + { + result_keep = TRUE; + res->key = mod->next_key++; + prcode(fp, ",int"); + } + + for (ad = od->cppsig->args, a = 0; a < od->cppsig->nrArgs; ++a, ++ad) + if (isOutArg(ad) && keepPyReference(ad)) + { + args_keep = TRUE; + ad->key = mod->next_key++; + prcode(fp, ",int"); + } + + if (result_keep || args_keep) + prcode(fp, ",sipSimpleWrapper *"); + + prcode(fp,");\n" +"\n" +"%s", indent); + + if (!isNewThread(od) && res != NULL) + prcode(fp, "return "); + + if (vhd->module == mod) + prcode(fp, "sipVH_%s_%d", vhd->module->name,vhd->virthandlernr); + else + prcode(fp, "((sipVH_%s_%d)(sipModuleAPI_%s_%s->em_virthandlers[%d]))", vhd->module->name, vhd->virthandlernr, mod->name, vhd->module->name, vhd->virthandlernr); + + prcode(fp,"(sipGILState,meth"); + + for (ad = od->cppsig->args, a = 0; a < od->cppsig->nrArgs; ++a, ++ad) + { + if (ad->atype == class_type && isProtectedClass(ad->u.cd)) + prcode(fp, ",%sa%d", ((isReference(ad) || ad->nrderefs == 0) ? "&" : ""), a); + else if (ad->atype == enum_type && isProtectedEnum(ad->u.ed)) + prcode(fp, ",(%E)a%d", ad->u.ed, a); + else + prcode(fp,",a%d",a); + } + + /* Pass the keys to maintain the kept references. */ + if (result_keep) + prcode(fp, ",%d", res->key); + + if (args_keep) + for (ad = od->cppsig->args, a = 0; a < od->cppsig->nrArgs; ++a, ++ad) + if (isOutArg(ad) && keepPyReference(ad)) + prcode(fp, ",%d", ad->key); + + if (result_keep || args_keep) + prcode(fp, ",sipPySelf"); + + prcode(fp,");\n" + ); + + if (isNewThread(od)) + prcode(fp, +"\n" +"%sSIP_BLOCK_THREADS\n" +"%ssipEndThread();\n" +"%sSIP_UNBLOCK_THREADS\n" + , indent + , indent + , indent); + +} + + +/* + * Generate the scope of the near class of a virtual taking duplicate + * super-classes into account. + */ +static void generateUnambiguousClass(classDef *cd,classDef *scope,FILE *fp) +{ + mroDef *mro; + + /* See if the near class has a duplicate. */ + for (mro = cd->mro; mro != NULL; mro = mro->next) + if (mro->cd == scope) + { + if (hasDuplicateSuper(mro)) + { + mroDef *guardc; + + /* + * Backtrack to find the class that directly + * sub-classes the duplicated one. This will + * be the one that disambiguates the duplicated + * one. + */ + guardc = mro; + + while (guardc != cd->mro) + { + mroDef *sub; + classList *cl; + + for (sub = cd->mro; sub->next != guardc; sub = sub->next) + ; + + for (cl = sub->cd->supers; cl != NULL; cl = cl->next) + if (cl->cd == mro->cd) + { + prcode(fp,"%S",classFQCName(sub->cd)); + + return; + } + + /* Try the previous one. */ + guardc = sub; + } + } + + break; + } + + /* If we got here there is nothing to worry about. */ + prcode(fp,"%S",classFQCName(scope)); +} + + +/* + * Generate a cast to zero. + */ +static void generateCastZero(argDef *ad,FILE *fp) +{ + if (ad->atype == enum_type) + prcode(fp,"(%E)",ad->u.ed); + + prcode(fp,"0"); +} + + +/* + * Generate the return statement for a virtual handler when there has been an + * error (ie. there is nothing sensible to return). + */ +static void generateVirtHandlerErrorReturn(argDef *res, const char *indent, + FILE *fp) +{ + prcode(fp, +"%sreturn", indent); + + if (res == NULL) + { + prcode(fp,";\n" + ); + + return; + } + + prcode(fp," "); + + if (res->atype == mapped_type && res->nrderefs == 0) + { + argDef res_noconstref; + + /* + * We don't know anything about the mapped type so we just hope + * is has a default ctor. + */ + + if (isReference(res)) + prcode(fp,"*new "); + + res_noconstref = *res; + resetIsConstArg(&res_noconstref); + resetIsReference(&res_noconstref); + prcode(fp,"%B()",&res_noconstref); + } + else if (res->atype == class_type && res->nrderefs == 0) + { + ctorDef *ct = res->u.cd->defctor; + + /* + * If we don't have a suitable ctor then the generated code + * will issue an error message. + */ + if (ct != NULL && isPublicCtor(ct) && ct->cppsig != NULL) + { + argDef res_noconstref; + + /* + * If this is a badly designed class. We can only + * generate correct code by leaking memory. + */ + if (isReference(res)) + prcode(fp,"*new "); + + res_noconstref = *res; + resetIsConstArg(&res_noconstref); + resetIsReference(&res_noconstref); + prcode(fp,"%B",&res_noconstref); + + generateCallDefaultCtor(ct,fp); + } + else + { + fatalScopedName(classFQCName(res->u.cd)); + fatal(" must have a default constructor\n"); + } + } + else + generateCastZero(res,fp); + + prcode(fp,";\n" + ); +} + + +/* + * Generate the call to a default ctor. + */ +static void generateCallDefaultCtor(ctorDef *ct, FILE *fp) +{ + int a; + + prcode(fp, "("); + + for (a = 0; a < ct->cppsig->nrArgs; ++a) + { + argDef *ad = &ct->cppsig->args[a]; + argType atype = ad->atype; + + if (ad->defval != NULL) + break; + + if (a > 0) + prcode(fp, ","); + + /* Do what we can to provide type information to the compiler. */ + if (atype == class_type && ad->nrderefs > 0 && !isReference(ad)) + prcode(fp, "static_cast<%B>(0)", ad); + else if (atype == enum_type) + prcode(fp, "static_cast<%E>(0)", ad->u.ed); + else if (atype == float_type || atype == cfloat_type) + prcode(fp, "0.0F"); + else if (atype == double_type || atype == cdouble_type) + prcode(fp, "0.0"); + else if (atype == uint_type) + prcode(fp, "0U"); + else if (atype == long_type || atype == longlong_type) + prcode(fp, "0L"); + else if (atype == ulong_type || atype == ulonglong_type) + prcode(fp, "0UL"); + else if ((atype == ascii_string_type || atype == latin1_string_type || atype == utf8_string_type || atype == ustring_type || atype == sstring_type || atype == string_type) && ad->nrderefs == 0) + prcode(fp, "'\\0'"); + else if (atype == wstring_type && ad->nrderefs == 0) + prcode(fp, "L'\\0'"); + else + prcode(fp, "0"); + } + + prcode(fp, ")"); +} + + +/* + * Generate the emitter function for a signal. + */ +static void generateEmitter(classDef *cd, visibleList *vl, FILE *fp) +{ + const char *pname = vl->m->pyname->text; + overDef *od; + + prcode(fp, +"\n" +"int sip%C::sipEmit_%s(PyObject *sipArgs)\n" +"{\n" +" PyObject *sipParseErr = NULL;\n" + ,classFQCName(cd),pname); + + for (od = vl->cd->overs; od != NULL; od = od->next) + { + int rgil = ((release_gil || isReleaseGIL(od)) && !isHoldGIL(od)); + + if (od->common != vl->m || !isSignal(od)) + continue; + + /* + * Generate the code that parses the args and emits the appropriate + * overloaded signal. + */ + prcode(fp, +"\n" +" {\n" + ); + + generateArgParser(&od->pysig, cd, NULL, NULL, NULL, FALSE, fp); + + prcode(fp, +" {\n" + ); + + if (rgil) + prcode(fp, +" Py_BEGIN_ALLOW_THREADS\n" + ); + + prcode(fp, +" emit %s(" + ,od->cppname); + + generateCallArgs(od->cppsig, &od->pysig, fp); + + prcode(fp,");\n" + ); + + if (rgil) + prcode(fp, +" Py_END_ALLOW_THREADS\n" + ); + + deleteTemps(&od->pysig, fp); + + prcode(fp, +"\n" +" return 0;\n" +" }\n" +" }\n" + ); + } + + prcode(fp, +"\n" +" sipNoMethod(sipParseErr, %N, %N, NULL);\n" +"\n" +" return -1;\n" +"}\n" +"\n" + , cd->pyname, vl->m->pyname); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static int %C_emit_%s(sipSimpleWrapper *, PyObject *);}\n" + , classFQCName(cd), pname); + + prcode(fp, +"static int %C_emit_%s(sipSimpleWrapper *sw,PyObject *sipArgs)\n" +"{\n" +" sip%C *ptr = reinterpret_cast<sip%C *>(sipGetComplexCppPtr(sw));\n" +"\n" +" return (ptr ? ptr->sipEmit_%s(sipArgs) : -1);\n" +"}\n" + ,classFQCName(cd),pname + ,classFQCName(cd),classFQCName(cd) + ,pname); +} + + +/* + * Generate the declarations of the protected wrapper functions for a class. + */ +static void generateProtectedDeclarations(classDef *cd,FILE *fp) +{ + int noIntro; + visibleList *vl; + + noIntro = TRUE; + + for (vl = cd->visible; vl != NULL; vl = vl->next) + { + overDef *od; + + if (vl->m->slot != no_slot) + continue; + + for (od = vl->cd->overs; od != NULL; od = od->next) + { + if (od->common != vl->m || !isProtected(od)) + continue; + + /* + * Check we haven't already handled this signature (eg. if we have + * specified the same method with different Python names. + */ + if (isDuplicateProtected(cd, od)) + continue; + + if (noIntro) + { + prcode(fp, +"\n" +" /*\n" +" * There is a public method for every protected method visible from\n" +" * this class.\n" +" */\n" + ); + + noIntro = FALSE; + } + + prcode(fp, +" "); + + if (isStatic(od)) + prcode(fp,"static "); + + generateBaseType(cd->iff, &od->cppsig->result, TRUE, fp); + + if (!isStatic(od) && !isAbstract(od) && (isVirtual(od) || isVirtualReimp(od))) + { + prcode(fp, " sipProtectVirt_%s(bool", od->cppname); + + if (od->cppsig->nrArgs > 0) + prcode(fp, ","); + } + else + prcode(fp, " sipProtect_%s(", od->cppname); + + generateCalledArgs(cd->iff, od->cppsig, Declaration, TRUE, fp); + prcode(fp,")%s;\n" + ,(isConst(od) ? " const" : "")); + } + } +} + + +/* + * Generate the definitions of the protected wrapper functions for a class. + */ +static void generateProtectedDefinitions(classDef *cd,FILE *fp) +{ + visibleList *vl; + + for (vl = cd->visible; vl != NULL; vl = vl->next) + { + overDef *od; + + if (vl->m->slot != no_slot) + continue; + + for (od = vl->cd->overs; od != NULL; od = od->next) + { + char *mname = od->cppname; + int parens; + argDef *res; + + if (od->common != vl->m || !isProtected(od)) + continue; + + /* + * Check we haven't already handled this signature (eg. if we have + * specified the same method with different Python names. + */ + if (isDuplicateProtected(cd, od)) + continue; + + prcode(fp, +"\n" + ); + + generateBaseType(cd->iff, &od->cppsig->result, TRUE, fp); + + if (!isStatic(od) && !isAbstract(od) && (isVirtual(od) || isVirtualReimp(od))) + { + prcode(fp, " sip%C::sipProtectVirt_%s(bool sipSelfWasArg", classFQCName(cd), mname); + + if (od->cppsig->nrArgs > 0) + prcode(fp, ","); + } + else + prcode(fp, " sip%C::sipProtect_%s(", classFQCName(cd), mname); + + generateCalledArgs(cd->iff, od->cppsig, Definition, TRUE, fp); + prcode(fp,")%s\n" +"{\n" + ,(isConst(od) ? " const" : "")); + + parens = 1; + + res = &od->cppsig->result; + + if (res->atype == void_type && res->nrderefs == 0) + prcode(fp, +" "); + else + { + prcode(fp, +" return "); + + if (res->atype == class_type && isProtectedClass(res->u.cd)) + { + prcode(fp,"static_cast<%U *>(",res->u.cd); + ++parens; + } + else if (res->atype == enum_type && isProtectedEnum(res->u.ed)) + /* + * One or two older compilers can't handle a static_cast + * here so we revert to a C-style cast. + */ + prcode(fp,"(%E)",res->u.ed); + } + + if (!isAbstract(od)) + { + if (isVirtual(od) || isVirtualReimp(od)) + { + prcode(fp, "(sipSelfWasArg ? %S::%s(", classFQCName(vl->cd), mname); + + generateProtectedCallArgs(od->cppsig, fp); + + prcode(fp, ") : "); + ++parens; + } + else + prcode(fp, "%S::", classFQCName(vl->cd)); + } + + prcode(fp,"%s(",mname); + + generateProtectedCallArgs(od->cppsig, fp); + + while (parens--) + prcode(fp,")"); + + prcode(fp,";\n" +"}\n" + ); + } + } +} + + +/* + * Return TRUE if a protected method is a duplicate. + */ +static int isDuplicateProtected(classDef *cd, overDef *target) +{ + visibleList *vl; + + for (vl = cd->visible; vl != NULL; vl = vl->next) + { + overDef *od; + + if (vl->m->slot != no_slot) + continue; + + for (od = vl->cd->overs; od != NULL; od = od->next) + { + if (od->common != vl->m || !isProtected(od)) + continue; + + if (od == target) + return FALSE; + + if (strcmp(od->cppname, target->cppname) == 0 && sameSignature(od->cppsig, target->cppsig, TRUE)) + return TRUE; + } + } + + /* We should never actually get here. */ + return FALSE; +} + + +/* + * Generate the arguments for a call to a protected method. + */ +static void generateProtectedCallArgs(signatureDef *sd, FILE *fp) +{ + int a; + + for (a = 0; a < sd->nrArgs; ++a) + { + argDef *ad = &sd->args[a]; + + if (a > 0) + prcode(fp, ","); + + if (ad->atype == enum_type && isProtectedEnum(ad->u.ed)) + prcode(fp, "(%S)", ad->u.ed->fqcname); + + prcode(fp, "a%d", a); + } +} + + +/* + * Generate the function that does most of the work to handle a particular + * virtual function. + */ +static void generateVirtualHandler(virtHandlerDef *vhd, FILE *fp) +{ + int a, nrvals, res_isref, need_self; + argDef *res, res_noconstref, *ad; + signatureDef saved; + + res = &vhd->cppsig->result; + + res_isref = FALSE; + + if (res->atype == void_type && res->nrderefs == 0) + res = NULL; + else + { + /* + * If we are returning a reference to an instance then we take care to + * handle Python errors but still return a valid C++ instance. + */ + if ((res->atype == class_type || res->atype == mapped_type) && res->nrderefs == 0) + { + if (isReference(res)) + res_isref = TRUE; + } + + res_noconstref = *res; + resetIsConstArg(&res_noconstref); + resetIsReference(&res_noconstref); + } + + prcode(fp, +"\n" + ); + + saved = *vhd->cppsig; + fakeProtectedArgs(vhd->cppsig); + + generateBaseType(NULL, &vhd->cppsig->result, FALSE, fp); + + prcode(fp," sipVH_%s_%d(sip_gilstate_t sipGILState,PyObject *sipMethod" + , vhd->module->name, vhd->virthandlernr); + + if (vhd->cppsig->nrArgs > 0) + { + prcode(fp,","); + generateCalledArgs(NULL, vhd->cppsig, Definition, FALSE, fp); + } + + *vhd->cppsig = saved; + + /* Declare the extra arguments for kept references. */ + need_self = FALSE; + + if (res != NULL && keepPyReference(res)) + { + need_self = TRUE; + prcode(fp, ",int"); + + if (vhd->virtcode == NULL || usedInCode(vhd->virtcode, "sipResKey")) + prcode(fp, " sipResKey"); + } + + for (ad = vhd->cppsig->args, a = 0; a < vhd->cppsig->nrArgs; ++a, ++ad) + if (isOutArg(ad) && keepPyReference(ad)) + { + need_self = TRUE; + prcode(fp, ",int a%dKey", a); + } + + if (need_self) + { + prcode(fp, ",sipSimpleWrapper *"); + + if (vhd->virtcode == NULL || usedInCode(vhd->virtcode, "sipPySelf")) + prcode(fp, "sipPySelf"); + } + + prcode(fp,")\n" +"{\n" + ); + + if (res != NULL) + { + prcode(fp, " "); + + /* + * wchar_t * return values are always on the heap. To reduce memory + * leaks we keep the last result around until we have a new one. This + * means that ownership of the return value stays with the function + * returning it - which is consistent with how other types work, even + * thought it may not be what's required in all cases. Note that we + * should do this in the code that calls the handler instead of here + * (as we do with strings) so that it doesn't get shared between all + * callers. + */ + if (res->atype == wstring_type && res->nrderefs == 1) + prcode(fp, "static "); + + generateBaseType(NULL, &res_noconstref, FALSE, fp); + + prcode(fp," %ssipRes",(res_isref ? "*" : "")); + + if ((res->atype == class_type || res->atype == mapped_type) && res->nrderefs == 0) + { + if (res->atype == class_type) + { + ctorDef *ct = res->u.cd->defctor; + + if (ct != NULL && isPublicCtor(ct) && ct->cppsig != NULL && ct->cppsig->nrArgs > 0 && ct->cppsig->args[0].defval == NULL) + generateCallDefaultCtor(ct,fp); + } + } + else + { + /* + * We initialise the result to try and suppress a + * compiler warning. + */ + prcode(fp," = "); + generateCastZero(res,fp); + } + + prcode(fp,";\n" + ); + + if (res->atype == wstring_type && res->nrderefs == 1) + prcode(fp, +"\n" +" if (sipRes)\n" +" {\n" +" // Return any previous result to the heap.\n" +" sipFree(%s);\n" +" sipRes = 0;\n" +" }\n" +"\n" + , (isConstArg(res) ? "const_cast<wchar_t *>(sipRes)" : "sipRes")); + } + + if (vhd->virtcode != NULL) + { + int error_flag = needErrorFlag(vhd->virtcode); + int old_error_flag = needOldErrorFlag(vhd->virtcode); + + if (error_flag) + prcode(fp, +" sipErrorState sipError = sipErrorNone;\n" + ); + else if (old_error_flag) + prcode(fp, +" int sipIsErr = 0;\n" + ); + + prcode(fp, +"\n" + ); + + generateCppCodeBlock(vhd->virtcode,fp); + + if (error_flag || old_error_flag) + prcode(fp, +"\n" +" if (%s)\n" +" PyErr_Print();\n" + , (error_flag ? "sipError != sipErrorNone" : "sipIsErr")); + + prcode(fp, +"\n" +" Py_DECREF(sipMethod);\n" +"\n" +" SIP_RELEASE_GIL(sipGILState)\n" + ); + + if (res != NULL) + prcode(fp, +"\n" +" return sipRes;\n" + ); + + prcode(fp, +"}\n" + ); + + return; + } + + /* See how many values we expect. */ + nrvals = (res != NULL ? 1 : 0); + + for (a = 0; a < vhd->pysig->nrArgs; ++a) + if (isOutArg(&vhd->pysig->args[a])) + ++nrvals; + + /* Call the method. */ + prcode(fp, +" PyObject *resObj = sipCallMethod(0,sipMethod,"); + + saved = *vhd->pysig; + fakeProtectedArgs(vhd->pysig); + generateTupleBuilder(vhd->pysig, fp); + *vhd->pysig = saved; + + prcode(fp,");\n" +"\n" +" %s (!resObj || sipParseResult(0,sipMethod,resObj,\"",(res_isref ? "int sipIsErr =" : "if")); + + /* Build the format string. */ + if (need_self) + prcode(fp, "S"); + + if (nrvals == 0) + prcode(fp,"Z"); + else + { + if (nrvals > 1) + prcode(fp,"("); + + if (res != NULL) + prcode(fp, "%s", getParseResultFormat(res, res_isref, isTransferVH(vhd))); + + for (a = 0; a < vhd->pysig->nrArgs; ++a) + { + argDef *ad = &vhd->pysig->args[a]; + + if (isOutArg(ad)) + prcode(fp, "%s", getParseResultFormat(ad, FALSE, FALSE)); + } + + if (nrvals > 1) + prcode(fp,")"); + } + + prcode(fp,"\""); + + if (need_self) + prcode(fp, ",sipPySelf"); + + /* Pass the destination pointers. */ + if (res != NULL) + { + generateParseResultExtraArgs(res, -1, fp); + prcode(fp, ",&sipRes"); + } + + for (a = 0; a < vhd->pysig->nrArgs; ++a) + { + argDef *ad = &vhd->pysig->args[a]; + + if (isOutArg(ad)) + { + generateParseResultExtraArgs(ad, a, fp); + prcode(fp,",%sa%d",(isReference(ad) ? "&" : ""),a); + } + } + + if (res_isref) + prcode(fp,") < 0);\n" +"\n" +" if (sipIsErr)\n" + ); + else + prcode(fp,") < 0)\n" + ); + + prcode(fp, +" PyErr_Print();\n" + ); + + prcode(fp, +"\n" +" Py_XDECREF(resObj);\n" +" Py_DECREF(sipMethod);\n" +"\n" +" SIP_RELEASE_GIL(sipGILState)\n" + ); + + if (res != NULL) + { + if (res_isref) + { + prcode(fp, +"\n" +" if (sipIsErr)\n" + ); + + generateVirtHandlerErrorReturn(res, " ", fp); + } + + prcode(fp, +"\n" +" return %ssipRes;\n" + ,(res_isref ? "*" : "")); + } + + prcode(fp, +"}\n" + ); +} + + +/* + * Generate the extra arguments needed by sipParseResult() for a particular + * type. + */ +static void generateParseResultExtraArgs(argDef *ad, int argnr, FILE *fp) +{ + switch (ad->atype) + { + case mapped_type: + prcode(fp, ",sipType_%T", ad); + break; + + case class_type: + prcode(fp, ",sipType_%C", classFQCName(ad->u.cd)); + break; + + case pytuple_type: + prcode(fp,",&PyTuple_Type"); + break; + + case pylist_type: + prcode(fp,",&PyList_Type"); + break; + + case pydict_type: + prcode(fp,",&PyDict_Type"); + break; + + case pyslice_type: + prcode(fp,",&PySlice_Type"); + break; + + case pytype_type: + prcode(fp,",&PyType_Type"); + break; + + case enum_type: + if (ad->u.ed->fqcname != NULL) + prcode(fp, ",sipType_%C", ad->u.ed->fqcname); + break; + + default: + if (keepPyReference(ad)) + { + if (argnr < 0) + prcode(fp, ",sipResKey"); + else + prcode(fp, ",a%dKey", argnr); + } + } +} + + +/* + * Return the format characters used by sipParseResult() for a particular type. + */ +static const char *getParseResultFormat(argDef *ad, int res_isref, int xfervh) +{ + switch (ad->atype) + { + case mapped_type: + case fake_void_type: + case class_type: + { + static const char *type_formats[] = { + "H0", "H1", "H2", "H3", "H4", "H5", "H6", "H7" + }; + + int f = 0x00; + + if (ad->nrderefs == 0) + { + f |= 0x01; + + if (!res_isref) + f |= 0x04; + } + + if (xfervh) + f |= 0x02; + + return type_formats[f]; + } + + case bool_type: + case cbool_type: + return "b"; + + case ascii_string_type: + return ((ad->nrderefs == 0) ? "aA" : "AA"); + + case latin1_string_type: + return ((ad->nrderefs == 0) ? "aL" : "AL"); + + case utf8_string_type: + return ((ad->nrderefs == 0) ? "a8" : "A8"); + + case sstring_type: + case ustring_type: + case string_type: + return ((ad->nrderefs == 0) ? "c" : "B"); + + case wstring_type: + return ((ad->nrderefs == 0) ? "w" : "x"); + + case enum_type: + return ((ad->u.ed->fqcname != NULL) ? "F" : "e"); + + case ushort_type: + return "t"; + + case short_type: + return "h"; + + case int_type: + case cint_type: + return "i"; + + case uint_type: + return "u"; + + case long_type: + return "l"; + + case ulong_type: + return "m"; + + case longlong_type: + return "n"; + + case ulonglong_type: + return "o"; + + case void_type: + case struct_type: + return "V"; + + case float_type: + case cfloat_type: + return "f"; + + case double_type: + case cdouble_type: + return "d"; + + case pyobject_type: + return "O"; + + case pytuple_type: + case pylist_type: + case pydict_type: + case pyslice_type: + case pytype_type: + return (isAllowNone(ad) ? "N" : "T"); + } + + /* We should never get here. */ + return " "; +} + + +/* + * Generate the code to build a tuple of Python arguments. + */ +static void generateTupleBuilder(signatureDef *sd,FILE *fp) +{ + int a, arraylenarg; + + prcode(fp,"\""); + + for (a = 0; a < sd->nrArgs; ++a) + { + char *fmt = ""; + argDef *ad = &sd->args[a]; + + if (!isInArg(ad)) + continue; + + switch (ad->atype) + { + case ascii_string_type: + if (ad->nrderefs == 0 || (ad->nrderefs == 1 && isOutArg(ad))) + fmt = "aA"; + else + fmt = "AA"; + + break; + + case latin1_string_type: + if (ad->nrderefs == 0 || (ad->nrderefs == 1 && isOutArg(ad))) + fmt = "aL"; + else + fmt = "AL"; + + break; + + case utf8_string_type: + if (ad->nrderefs == 0 || (ad->nrderefs == 1 && isOutArg(ad))) + fmt = "a8"; + else + fmt = "A8"; + + break; + + case sstring_type: + case ustring_type: + case string_type: + if (ad->nrderefs == 0 || (ad->nrderefs == 1 && isOutArg(ad))) + fmt = "c"; + else if (isArray(ad)) + fmt = "g"; + else + fmt = "s"; + + break; + + case wstring_type: + if (ad->nrderefs == 0 || (ad->nrderefs == 1 && isOutArg(ad))) + fmt = "w"; + else if (isArray(ad)) + fmt = "G"; + else + fmt = "x"; + + break; + + case bool_type: + case cbool_type: + fmt = "b"; + break; + + case enum_type: + fmt = (ad->u.ed->fqcname != NULL) ? "F" : "e"; + break; + + case cint_type: + fmt = "i"; + break; + + case uint_type: + if (isArraySize(ad)) + arraylenarg = a; + else + fmt = "u"; + + break; + + case int_type: + if (isArraySize(ad)) + arraylenarg = a; + else + fmt = "i"; + + break; + + case ushort_type: + if (isArraySize(ad)) + arraylenarg = a; + else + fmt = "t"; + + break; + + case short_type: + if (isArraySize(ad)) + arraylenarg = a; + else + fmt = "h"; + + break; + + case long_type: + if (isArraySize(ad)) + arraylenarg = a; + else + fmt = "l"; + + break; + + case ulong_type: + if (isArraySize(ad)) + arraylenarg = a; + else + fmt = "m"; + + break; + + case longlong_type: + if (isArraySize(ad)) + arraylenarg = a; + else + fmt = "n"; + + break; + + case ulonglong_type: + if (isArraySize(ad)) + arraylenarg = a; + else + fmt = "o"; + + break; + + case struct_type: + case void_type: + fmt = "V"; + break; + + case float_type: + case cfloat_type: + fmt = "f"; + break; + + case double_type: + case cdouble_type: + fmt = "d"; + break; + + case signal_type: + case slot_type: + case slotcon_type: + case slotdis_type: + fmt = "s"; + break; + + case mapped_type: + case class_type: + if (isArray(ad)) + { + fmt = "r"; + break; + } + + if (copyConstRefArg(ad)) + { + fmt = "N"; + break; + } + + /* Drop through. */ + + case fake_void_type: + case rxcon_type: + case rxdis_type: + case qobject_type: + fmt = "D"; + break; + + case pyobject_type: + case pytuple_type: + case pylist_type: + case pydict_type: + case pycallable_type: + case pyslice_type: + case pytype_type: + fmt = "S"; + break; + } + + prcode(fp,fmt); + } + + prcode(fp,"\""); + + for (a = 0; a < sd->nrArgs; ++a) + { + int derefs; + argDef *ad = &sd->args[a]; + + if (!isInArg(ad)) + continue; + + derefs = ad->nrderefs; + + switch (ad->atype) + { + case ascii_string_type: + case latin1_string_type: + case utf8_string_type: + case sstring_type: + case ustring_type: + case string_type: + case wstring_type: + if (!(ad->nrderefs == 0 || (ad->nrderefs == 1 && isOutArg(ad)))) + --derefs; + + break; + + case mapped_type: + case fake_void_type: + case class_type: + if (ad->nrderefs > 0) + --derefs; + + break; + + case struct_type: + case void_type: + --derefs; + break; + } + + if (ad->atype == mapped_type || ad->atype == class_type || + ad->atype == rxcon_type || ad->atype == rxdis_type || + ad->atype == qobject_type || ad->atype == fake_void_type) + { + int copy = copyConstRefArg(ad); + + prcode(fp,","); + + if (copy) + { + prcode(fp,"new %b(",ad); + } + else + { + if (isConstArg(ad)) + prcode(fp,"const_cast<%b *>(",ad); + + if (ad->nrderefs == 0) + prcode(fp,"&"); + else + while (derefs-- != 0) + prcode(fp,"*"); + } + + prcode(fp,"a%d",a); + + if (copy || isConstArg(ad)) + prcode(fp,")"); + + if (isArray(ad)) + prcode(fp, ",(SIP_SSIZE_T)a%d", arraylenarg); + + if (ad->atype == mapped_type) + prcode(fp, ",sipType_%T", ad); + else if (ad->atype == fake_void_type || ad->atype == class_type) + prcode(fp, ",sipType_%C", classFQCName(ad->u.cd)); + else + prcode(fp,",sipType_QObject"); + + if (!isArray(ad)) + prcode(fp, ",NULL"); + } + else + { + if (!isArraySize(ad)) + { + prcode(fp, ","); + + while (derefs-- != 0) + prcode(fp, "*"); + + prcode(fp, "a%d", a); + } + + if (isArray(ad)) + prcode(fp, ",(SIP_SSIZE_T)a%d", arraylenarg); + else if (ad->atype == enum_type && ad->u.ed->fqcname != NULL) + prcode(fp, ",sipType_%C", ad->u.ed->fqcname); + } + } +} + + +/* + * Generate the library header #include directives required by either a class + * or a module. + */ +static void generateUsedIncludes(ifaceFileList *iffl, FILE *fp) +{ + prcode(fp, +"\n" + ); + + while (iffl != NULL) + { + generateCppCodeBlock(iffl->iff->hdrcode, fp); + iffl = iffl->next; + } +} + + +/* + * Generate the API details for a module. + */ +static void generateModuleAPI(sipSpec *pt, moduleDef *mod, FILE *fp) +{ + classDef *cd; + mappedTypeDef *mtd; + exceptionDef *xd; + + for (cd = pt->classes; cd != NULL; cd = cd->next) + if (cd->iff->module == mod) + generateClassAPI(cd, pt, fp); + + for (mtd = pt->mappedtypes; mtd != NULL; mtd = mtd->next) + if (mtd->iff->module == mod) + generateMappedTypeAPI(pt, mtd, fp); + + for (xd = pt->exceptions; xd != NULL; xd = xd->next) + if (xd->iff->module == mod && xd->exceptionnr >= 0) + prcode(fp, +"\n" +"#define sipException_%C sipModuleAPI_%s.em_exceptions[%d]\n" + , xd->iff->fqcname, mod->name, xd->exceptionnr); +} + + +/* + * Generate the API details for an imported module. + */ +static void generateImportedModuleAPI(sipSpec *pt, moduleDef *mod, + moduleDef *immod, FILE *fp) +{ + classDef *cd; + mappedTypeDef *mtd; + exceptionDef *xd; + + for (cd = pt->classes; cd != NULL; cd = cd->next) + if (cd->iff->module == immod && !isExternal(cd)) + generateImportedClassAPI(cd, pt, mod, fp); + + for (mtd = pt->mappedtypes; mtd != NULL; mtd = mtd->next) + if (mtd->iff->module == immod) + generateImportedMappedTypeAPI(mtd, pt, mod, fp); + + for (xd = pt->exceptions; xd != NULL; xd = xd->next) + if (xd->iff->module == immod && xd->exceptionnr >= 0) + prcode(fp, +"\n" +"#define sipException_%C sipModuleAPI_%s_%s->em_exceptions[%d]\n" + , xd->iff->fqcname, mod->name, xd->iff->module->name, xd->exceptionnr); +} + + +/* + * Generate the API details for an imported mapped type. + */ +static void generateImportedMappedTypeAPI(mappedTypeDef *mtd, sipSpec *pt, + moduleDef *mod, FILE *fp) +{ + /* Ignore alternate API implementations. */ + if (mtd->iff->first_alt == mtd->iff) + { + const char *mname = mod->name; + const char *imname = mtd->iff->module->name; + argDef type; + + memset(&type, 0, sizeof (argDef)); + + type.atype = mapped_type; + type.u.mtd = mtd; + + prcode(fp, +"\n" +"#define sipType_%T sipModuleAPI_%s_%s->em_types[%d]\n" + , &type, mname, imname, mtd->iff->ifacenr); + } + + generateEnumMacros(pt, mod, NULL, mtd, fp); +} + + +/* + * Generate the API details for a mapped type. + */ +static void generateMappedTypeAPI(sipSpec *pt, mappedTypeDef *mtd, FILE *fp) +{ + argDef type; + + memset(&type, 0, sizeof (argDef)); + + type.atype = mapped_type; + type.u.mtd = mtd; + + if (mtd->iff->first_alt == mtd->iff) + prcode(fp, +"\n" +"#define sipType_%T sipModuleAPI_%s.em_types[%d]\n" + , &type, mtd->iff->module->name, mtd->iff->ifacenr); + + prcode(fp, +"\n" +"extern sipMappedTypeDef sipTypeDef_%s_%L;\n" + , mtd->iff->module->name, mtd->iff); + + generateEnumMacros(pt, mtd->iff->module, NULL, mtd, fp); +} + + +/* + * Generate the API details for an imported class. + */ +static void generateImportedClassAPI(classDef *cd, sipSpec *pt, moduleDef *mod, + FILE *fp) +{ + prcode(fp, +"\n" + ); + + /* Ignore alternate API implementations. */ + if (cd->iff->first_alt == cd->iff) + { + const char *mname = mod->name; + const char *imname = cd->iff->module->name; + + if (cd->iff->type == namespace_iface) + prcode(fp, +"#if !defined(sipType_%L)\n" + , cd->iff); + + prcode(fp, +"#define sipType_%C sipModuleAPI_%s_%s->em_types[%d]\n" +"#define sipClass_%C sipModuleAPI_%s_%s->em_types[%d]->u.td_wrapper_type\n" + , classFQCName(cd), mname, imname, cd->iff->ifacenr + , classFQCName(cd), mname, imname, cd->iff->ifacenr); + + if (cd->iff->type == namespace_iface) + prcode(fp, +"#endif\n" + ); + } + + generateEnumMacros(pt, mod, cd, NULL, fp); +} + + +/* + * Generate the C++ API for a class. + */ +static void generateClassAPI(classDef *cd, sipSpec *pt, FILE *fp) +{ + const char *mname = cd->iff->module->name; + + prcode(fp, +"\n" + ); + + if (cd->real == NULL && cd->iff->first_alt == cd->iff) + prcode(fp, +"#define sipType_%C sipModuleAPI_%s.em_types[%d]\n" +"#define sipClass_%C sipModuleAPI_%s.em_types[%d]->u.td_wrapper_type\n" + , classFQCName(cd), mname, cd->iff->ifacenr + , classFQCName(cd), mname, cd->iff->ifacenr); + + generateEnumMacros(pt, cd->iff->module, cd, NULL, fp); + + if (!isExternal(cd)) + { + const char *type_prefix; + + if (pluginPyQt4(pt)) + type_prefix = "pyqt4"; + else if (pluginPyQt3(pt)) + type_prefix = "pyqt3"; + else + type_prefix = "sip"; + + prcode(fp, +"\n" +"extern %sClassTypeDef sipTypeDef_%s_%L;\n" + , type_prefix, mname, cd->iff); + } +} + + +/* + * Generate the sipEnum_* macros. + */ +static void generateEnumMacros(sipSpec *pt, moduleDef *mod, classDef *cd, + mappedTypeDef *mtd, FILE *fp) +{ + enumDef *ed; + int noIntro = TRUE; + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + if (ed->fqcname == NULL) + continue; + + if (ed->first_alt != ed) + continue; + + if (cd != NULL) + { + if (ed->ecd != cd) + continue; + } + else if (mtd != NULL) + { + if (ed->emtd != mtd) + continue; + } + else if (ed->ecd != NULL || ed->emtd != NULL) + { + continue; + } + + if (noIntro) + { + prcode(fp, +"\n" + ); + + noIntro = FALSE; + } + + if (mod == ed->module) + prcode(fp, +"#define sipType_%C sipModuleAPI_%s.em_types[%d]\n" +"#define sipEnum_%C sipModuleAPI_%s.em_types[%d]->u.td_py_type\n" + , ed->fqcname, mod->name, ed->enumnr + , ed->fqcname, mod->name, ed->enumnr); + else + prcode(fp, +"#define sipType_%C sipModuleAPI_%s_%s->em_types[%d]\n" +"#define sipEnum_%C sipModuleAPI_%s_%s->em_types[%d]->u.td_py_type\n" + , ed->fqcname, mod->name, ed->module->name, ed->enumnr + , ed->fqcname, mod->name, ed->module->name, ed->enumnr); + } +} + + +/* + * Generate the shadow class declaration. + */ +static void generateShadowClassDeclaration(sipSpec *pt,classDef *cd,FILE *fp) +{ + int noIntro, nrVirts; + ctorDef *ct; + virtOverDef *vod; + classDef *pcd; + + prcode(fp, +"\n" +"\n" +"class sip%C : public %S\n" +"{\n" +"public:\n" + ,classFQCName(cd),classFQCName(cd)); + + /* Define a shadow class for any protected classes we have. */ + + for (pcd = pt->classes; pcd != NULL; pcd = pcd->next) + { + mroDef *mro; + + if (!isProtectedClass(pcd)) + continue; + + /* See if the class defining the class is in our class hierachy. */ + for (mro = cd->mro; mro != NULL; mro = mro->next) + if (mro->cd == pcd->ecd) + break; + + if (mro == NULL) + continue; + + prcode(fp, +" class sip%s : public %s {\n" +" public:\n" + , classBaseName(pcd), classBaseName(pcd)); + + generateProtectedEnums(pt, pcd, fp); + + prcode(fp, +" };\n" +"\n" + ); + } + + /* The constructor declarations. */ + + for (ct = cd->ctors; ct != NULL; ct = ct->next) + { + ctorDef *dct; + + if (isPrivateCtor(ct)) + continue; + + if (ct->cppsig == NULL) + continue; + + /* Check we haven't already handled this C++ signature. */ + for (dct = cd->ctors; dct != ct; dct = dct->next) + if (dct->cppsig != NULL && sameSignature(dct->cppsig, ct->cppsig, TRUE)) + break; + + if (dct != ct) + continue; + + prcode(fp, +" sip%C(",classFQCName(cd)); + + generateCalledArgs(cd->iff, ct->cppsig, Declaration, TRUE, fp); + + prcode(fp,")%X;\n" + ,ct->exceptions); + } + + /* The destructor. */ + + if (!isPrivateDtor(cd)) + prcode(fp, +" %s~sip%C()%X;\n" + ,(cd->vmembers != NULL ? "virtual " : ""),classFQCName(cd),cd->dtorexceptions); + + /* The metacall methods if required. */ + if (pluginPyQt4(pt) && isQObjectSubClass(cd)) + { + prcode(fp, +"\n" +" int qt_metacall(QMetaObject::Call,int,void **);\n" +" void *qt_metacast(const char *);\n" + ); + + if (!noPyQt4QMetaObject(cd)) + prcode(fp, +" const QMetaObject *metaObject() const;\n" + ); + } + + /* The exposure of protected enums. */ + + generateProtectedEnums(pt,cd,fp); + + /* The wrapper around each protected member function. */ + + generateProtectedDeclarations(cd,fp); + + /* The public wrapper around each signal emitter. */ + if (pluginPyQt3(pt)) + { + visibleList *vl; + + noIntro = TRUE; + + for (vl = cd->visible; vl != NULL; vl = vl->next) + { + overDef *od; + + if (vl->m->slot != no_slot) + continue; + + for (od = vl->cd->overs; od != NULL; od = od->next) + { + if (od->common != vl->m || !isSignal(od)) + continue; + + if (noIntro) + { + prcode(fp, +"\n" +" /*\n" +" * There is a public method for every Qt signal that can be emitted\n" +" * by this object. This function is called by Python to emit the\n" +" * signal.\n" +" */\n" + ); + + noIntro = FALSE; + } + + prcode(fp, +" int sipEmit_%s(PyObject *);\n" + ,vl->m->pyname->text); + + break; + } + } + } + + /* The catcher around each virtual function in the hierarchy. */ + noIntro = TRUE; + + for (vod = cd->vmembers; vod != NULL; vod = vod->next) + { + overDef *od = &vod->o; + virtOverDef *dvod; + + if (isPrivate(od)) + continue; + + /* Check we haven't already handled this C++ signature. */ + for (dvod = cd->vmembers; dvod != vod; dvod = dvod->next) + if (strcmp(dvod->o.cppname,od->cppname) == 0 && sameSignature(dvod->o.cppsig,od->cppsig,TRUE)) + break; + + if (dvod != vod) + continue; + + if (noIntro) + { + prcode(fp, +"\n" +" /*\n" +" * There is a protected method for every virtual method visible from\n" +" * this class.\n" +" */\n" +"protected:\n" + ); + + noIntro = FALSE; + } + + prcode(fp, +" "); + + prOverloadDecl(fp, cd->iff, od, FALSE); + prcode(fp, ";\n"); + } + + prcode(fp, +"\n" +"public:\n" +" sipSimpleWrapper *sipPySelf;\n" + ); + + /* The private declarations. */ + + prcode(fp, +"\n" +"private:\n" +" sip%C(const sip%C &);\n" +" sip%C &operator = (const sip%C &);\n" + ,classFQCName(cd),classFQCName(cd) + ,classFQCName(cd),classFQCName(cd)); + + if ((nrVirts = countVirtuals(cd)) > 0) + prcode(fp, +"\n" +" char sipPyMethods[%d];\n" + ,nrVirts); + + prcode(fp, +"};\n" + ); +} + + +/* + * Generate the C++ declaration for an overload. + */ +void prOverloadDecl(FILE *fp, ifaceFileDef *scope, overDef *od, int defval) +{ + int a; + + normaliseArgs(od->cppsig); + + generateBaseType(scope, &od->cppsig->result, TRUE, fp); + + prcode(fp, " %O(", od); + + for (a = 0; a < od->cppsig->nrArgs; ++a) + { + argDef *ad = &od->cppsig->args[a]; + + if (a > 0) + prcode(fp, ","); + + generateBaseType(scope, ad, TRUE, fp); + + if (defval && ad->defval != NULL) + { + prcode(fp, " = "); + generateExpression(ad->defval, FALSE, fp); + } + } + + prcode(fp, ")%s%X", (isConst(od) ? " const" : ""), od->exceptions); + + restoreArgs(od->cppsig); +} + + +/* + * Generate typed arguments for a declaration or a definition. + */ +static void generateCalledArgs(ifaceFileDef *scope, signatureDef *sd, + funcArgType ftype, int use_typename, FILE *fp) +{ + char name[50]; + int a; + + for (a = 0; a < sd->nrArgs; ++a) + { + argDef *ad = &sd->args[a]; + + if (a > 0) + prcode(fp,","); + + if (ftype == Definition) + sprintf(name, "a%d", a); + else + name[0] = '\0'; + + generateNamedBaseType(scope, ad, name, use_typename, fp); + } +} + + +/* + * Generate typed arguments for a call. + */ +static void generateCallArgs(signatureDef *sd, signatureDef *py_sd, FILE *fp) +{ + int a; + + for (a = 0; a < sd->nrArgs; ++a) + { + char *ind = NULL; + argDef *ad, *py_ad; + + if (a > 0) + prcode(fp,","); + + ad = &sd->args[a]; + + /* See if the argument needs dereferencing or it's address taking. */ + switch (ad->atype) + { + case ascii_string_type: + case latin1_string_type: + case utf8_string_type: + case sstring_type: + case ustring_type: + case string_type: + case wstring_type: + if (ad->nrderefs > (isOutArg(ad) ? 0 : 1)) + ind = "&"; + + break; + + case mapped_type: + case class_type: + if (ad->nrderefs == 2) + ind = "&"; + else if (ad->nrderefs == 0) + ind = "*"; + + break; + + case struct_type: + case void_type: + if (ad->nrderefs == 2) + ind = "&"; + + break; + + default: + if (ad->nrderefs == 1) + ind = "&"; + } + + if (ind != NULL) + prcode(fp, ind); + + /* + * See if we need to cast a Python void * to the correct C/C++ pointer + * type. + */ + if (py_sd != sd) + { + py_ad = &py_sd->args[a]; + + if (py_ad->atype != void_type || ad->atype == void_type || py_ad->nrderefs != ad->nrderefs) + py_ad = NULL; + } + else + py_ad = NULL; + + if (py_ad == NULL) + { + if (isArraySize(ad)) + prcode(fp, "(%b)", ad); + + prcode(fp, "a%d", a); + } + else if (generating_c) + prcode(fp, "(%b *)a%d", ad, a); + else + prcode(fp, "reinterpret_cast<%b *>(a%d)", ad, a); + } +} + + +/* + * Generate the declaration of a named variable to hold a result from a C++ + * function call. + */ +static void generateNamedValueType(ifaceFileDef *scope, argDef *ad, + char *name, FILE *fp) +{ + argDef mod = *ad; + + if (ad->nrderefs == 0) + { + if (ad->atype == class_type || ad->atype == mapped_type) + mod.nrderefs = 1; + else + resetIsConstArg(&mod); + } + + resetIsReference(&mod); + generateNamedBaseType(scope, &mod, name, TRUE, fp); +} + + +/* + * Generate a C++ type. + */ +static void generateBaseType(ifaceFileDef *scope, argDef *ad, + int use_typename, FILE *fp) +{ + generateNamedBaseType(scope, ad, "", use_typename, fp); +} + + +/* + * Generate a C++ type and name. + */ +static void generateNamedBaseType(ifaceFileDef *scope, argDef *ad, char *name, + int use_typename, FILE *fp) +{ + typedefDef *td = ad->original_type; + int nr_derefs = ad->nrderefs; + int is_reference = isReference(ad); + + if (use_typename && td != NULL && !noTypeName(td) && !isArraySize(ad)) + { + if (isConstArg(ad) && !isConstArg(&td->type)) + prcode(fp, "const "); + + nr_derefs -= td->type.nrderefs; + + if (isReference(&td->type)) + is_reference = FALSE; + + prcode(fp, "%S", td->fqname); + } + else + { + /* + * A function type is handled differently because of the position of + * the name. + */ + if (ad->atype == function_type) + { + int i; + signatureDef *sig = ad->u.sa; + + generateBaseType(scope, &sig->result, TRUE, fp); + + prcode(fp," ("); + + for (i = 0; i < nr_derefs; ++i) + prcode(fp, "*"); + + prcode(fp, "%s)(",name); + generateCalledArgs(scope, sig, Declaration, use_typename, fp); + prcode(fp, ")"); + + return; + } + + if (isConstArg(ad)) + prcode(fp, "const "); + + switch (ad->atype) + { + case sstring_type: + prcode(fp, "signed char"); + break; + + case ustring_type: + prcode(fp, "unsigned char"); + break; + + case wstring_type: + prcode(fp, "wchar_t"); + break; + + case signal_type: + case slot_type: + case anyslot_type: + case slotcon_type: + case slotdis_type: + nr_derefs = 1; + + /* Drop through. */ + + case ascii_string_type: + case latin1_string_type: + case utf8_string_type: + case string_type: + prcode(fp, "char"); + break; + + case ushort_type: + prcode(fp, "unsigned short"); + break; + + case short_type: + prcode(fp, "short"); + break; + + case uint_type: + prcode(fp, "unsigned"); + break; + + case int_type: + case cint_type: + prcode(fp, "int"); + break; + + case ssize_type: + prcode(fp, "SIP_SSIZE_T"); + break; + + case ulong_type: + prcode(fp, "unsigned long"); + break; + + case long_type: + prcode(fp, "long"); + break; + + case ulonglong_type: + prcode(fp, "unsigned PY_LONG_LONG"); + break; + + case longlong_type: + prcode(fp, "PY_LONG_LONG"); + break; + + case struct_type: + prcode(fp, "struct %S", ad->u.sname); + break; + + case fake_void_type: + case void_type: + prcode(fp, "void"); + break; + + case bool_type: + case cbool_type: + prcode(fp, "bool"); + break; + + case float_type: + case cfloat_type: + prcode(fp, "float"); + break; + + case double_type: + case cdouble_type: + prcode(fp, "double"); + break; + + case defined_type: + /* + * The only defined types still remaining are arguments to + * templates and default values. + */ + if (prcode_xml) + prScopedName(fp, ad->u.snd, "."); + else + prcode(fp, "%S", ad->u.snd); + break; + + case rxcon_type: + case rxdis_type: + nr_derefs = 1; + prcode(fp, "QObject"); + break; + + case mapped_type: + generateBaseType(scope, &ad->u.mtd->type, TRUE, fp); + break; + + case class_type: + prcode(fp, "%V", scope, ad->u.cd); + break; + + case template_type: + { + static const char tail[] = ">"; + int a; + templateDef *td = ad->u.td; + + prcode(fp, "%S%s", td->fqname, (prcode_xml ? "<" : "<")); + + for (a = 0; a < td->types.nrArgs; ++a) + { + if (a > 0) + prcode(fp, ","); + + generateBaseType(scope, &td->types.args[a], TRUE, fp); + } + + if (prcode_last == tail) + prcode(fp, " "); + + prcode(fp, (prcode_xml ? ">" : tail)); + break; + } + + case enum_type: + prcode(fp, "%E", ad->u.ed); + break; + + case pyobject_type: + case pytuple_type: + case pylist_type: + case pydict_type: + case pycallable_type: + case pyslice_type: + case pytype_type: + case qobject_type: + case ellipsis_type: + prcode(fp, "PyObject *"); + break; + } + } + + if (nr_derefs > 0) + { + int i; + + prcode(fp, " "); + + for (i = 0; i < nr_derefs; ++i) + prcode(fp, "*"); + } + + if (is_reference) + prcode(fp, (prcode_xml ? "&" : "&")); + + if (*name != '\0') + { + if (nr_derefs == 0) + prcode(fp, " "); + + prcode(fp, name); + } +} + + +/* + * Generate the definition of an argument variable and any supporting + * variables. + */ +static void generateVariable(ifaceFileDef *scope, argDef *ad, int argnr, + FILE *fp) +{ + argType atype = ad->atype; + argDef orig; + + if (isInArg(ad) && ad->defval != NULL && + (atype == class_type || atype == mapped_type) && + (ad->nrderefs == 0 || isReference(ad))) + { + /* + * Generate something to hold the default value as it cannot be + * assigned straight away. + */ + prcode(fp, +" %A a%ddef = ", scope, ad, argnr); + + generateExpression(ad->defval, FALSE, fp); + + prcode(fp,";\n" + ); + } + + /* Adjust the type so we have the type that will really handle it. */ + + orig = *ad; + + switch (atype) + { + case ascii_string_type: + case latin1_string_type: + case utf8_string_type: + case sstring_type: + case ustring_type: + case string_type: + case wstring_type: + if (!isReference(ad)) + { + if (ad->nrderefs == 2) + ad->nrderefs = 1; + else if (ad->nrderefs == 1 && isOutArg(ad)) + ad->nrderefs = 0; + } + + break; + + case mapped_type: + case class_type: + case void_type: + case struct_type: + ad->nrderefs = 1; + break; + + default: + ad->nrderefs = 0; + } + + /* Array sizes are always SIP_SSIZE_T. */ + if (isArraySize(ad)) + ad->atype = ssize_type; + + resetIsReference(ad); + + if (ad->nrderefs == 0) + resetIsConstArg(ad); + + prcode(fp, +" %A a%d", scope, ad, argnr); + + if (atype == anyslot_type) + prcode(fp, "Name"); + + *ad = orig; + + generateDefaultValue(ad, argnr, fp); + + prcode(fp,";\n" + ); + + /* Some types have supporting variables. */ + if (isInArg(ad)) + { + if (isGetWrapper(ad)) + prcode(fp, +" PyObject *a%dWrapper%s;\n" + , argnr, (ad->defval != NULL ? " = 0" : "")); + else if (keepReference(ad)) + prcode(fp, +" PyObject *a%dKeep%s;\n" + , argnr, (ad->defval != NULL ? " = 0" : "")); + + switch (atype) + { + case class_type: + if (ad->u.cd->convtocode != NULL && !isConstrained(ad)) + prcode(fp, +" int a%dState = 0;\n" + ,argnr); + + break; + + case mapped_type: + if (!noRelease(ad->u.mtd) && !isConstrained(ad)) + prcode(fp, +" int a%dState = 0;\n" + ,argnr); + + break; + + case ascii_string_type: + case latin1_string_type: + case utf8_string_type: + if (!keepReference(ad) && ad->nrderefs == 1) + prcode(fp, +" PyObject *a%dKeep%s;\n" + , argnr, (ad->defval != NULL ? " = 0" : "")); + + break; + + case anyslot_type: + prcode(fp, +" PyObject *a%dCallable", argnr); + generateDefaultValue(ad, argnr, fp); + prcode(fp, ";\n" + ); + break; + } + } +} + + +/* + * Generate a default value. + */ +static void generateDefaultValue(argDef *ad, int argnr, FILE *fp) +{ + if (isInArg(ad) && ad->defval != NULL) + { + prcode(fp," = "); + + if ((ad->atype == class_type || ad->atype == mapped_type) && + (ad->nrderefs == 0 || isReference(ad))) + prcode(fp, "&a%ddef", argnr); + else + generateExpression(ad->defval, FALSE, fp); + } +} + + +/* + * Generate a simple function call. + */ +static void generateSimpleFunctionCall(fcallDef *fcd,FILE *fp) +{ + int i; + + prcode(fp, "%B(", &fcd->type); + + for (i = 0; i < fcd->nrArgs; ++i) + { + if (i > 0) + prcode(fp,","); + + generateExpression(fcd->args[i], FALSE, fp); + } + + prcode(fp,")"); +} + + +/* + * Generate the type structure that contains all the information needed by the + * meta-type. A sub-set of this is used to extend namespaces. + */ +static void generateTypeDefinition(sipSpec *pt, classDef *cd, FILE *fp) +{ + const char *mname, *sep, *type_prefix; + int is_slots, is_signals, nr_methods, nr_enums, nr_vars, embedded; + int is_inst_class, is_inst_voidp, is_inst_char, is_inst_string; + int is_inst_int, is_inst_long, is_inst_ulong, is_inst_longlong; + int is_inst_ulonglong, is_inst_double, has_docstring; + memberDef *md; + moduleDef *mod; + + mod = cd->iff->module; + mname = mod->name; + + if (cd->supers != NULL) + { + classList *cl; + + prcode(fp, +"\n" +"\n" +"/* Define this type's super-types. */\n" +"static sipEncodedTypeDef supers_%C[] = {", classFQCName(cd)); + + for (cl = cd->supers; cl != NULL; cl = cl->next) + { + if (cl != cd->supers) + prcode(fp, ", "); + + generateEncodedType(mod, cl->cd, (cl->next == NULL), fp); + } + + prcode(fp,"};\n" + ); + } + + /* Generate the slots table. */ + is_slots = FALSE; + + for (md = cd->members; md != NULL; md = md->next) + { + const char *stype; + + if (md->slot == no_slot) + continue; + + if (!is_slots) + { + prcode(fp, +"\n" +"\n" +"/* Define this type's Python slots. */\n" +"static sipPySlotDef slots_%L[] = {\n" + , cd->iff); + + is_slots = TRUE; + } + + if ((stype = slotName(md->slot)) != NULL) + { + if (py2OnlySlot(md->slot)) + prcode(fp, +"#if PY_MAJOR_VERSION < 3\n" + ); + else if (py2_5LaterSlot(md->slot)) + prcode(fp, +"#if PY_VERSION_HEX >= 0x02050000\n" + ); + + prcode(fp, +" {(void *)slot_%L_%s, %s},\n" + , cd->iff, md->pyname->text, stype); + + if (py2OnlySlot(md->slot) || py2_5LaterSlot(md->slot)) + prcode(fp, +"#endif\n" + ); + } + } + + if (is_slots) + prcode(fp, +" {0, (sipPySlotType)0}\n" +"};\n" + ); + + /* Generate the attributes tables. */ + nr_methods = generateClassMethodTable(pt, cd, fp); + nr_enums = generateEnumMemberTable(pt, mod, cd, NULL, fp); + + /* Generate the PyQt4 signals table. */ + is_signals = FALSE; + + if (pluginPyQt4(pt) && isQObjectSubClass(cd)) + { + /* The signals must be grouped by name. */ + for (md = cd->members; md != NULL; md = md->next) + { + overDef *od; + int membernr = md->membernr; + + for (od = cd->overs; od != NULL; od = od->next) + { + int a, nr_args; + + if (od->common != md || !isSignal(od)) + continue; + + if (membernr >= 0) + { + /* See if there is a non-signal overload. */ + + overDef *nsig; + + for (nsig = cd->overs; nsig != NULL; nsig = nsig->next) + if (nsig != od && nsig->common == md && !isSignal(nsig)) + break; + + if (nsig == NULL) + membernr = -1; + } + + if (!is_signals) + { + is_signals = TRUE; + + prcode(fp, +"\n" +"\n" +"/* Define this type's PyQt4 signals. */\n" +"static const pyqt4QtSignal pyqt4_signals_%C[] = {\n" + , classFQCName(cd)); + } + + /* + * Default arguments are handled as multiple signals. We make + * sure the largest is first and the smallest last. + */ + generateSignalTableEntry(pt, cd, od, md, membernr, fp); + membernr = -1; + + nr_args = od->cppsig->nrArgs; + + for (a = nr_args - 1; a >= 0; --a) + { + if (od->cppsig->args[a].defval == NULL) + break; + + od->cppsig->nrArgs = a; + generateSignalTableEntry(pt, cd, od, md, -1, fp); + } + + od->cppsig->nrArgs = nr_args; + } + } + + if (is_signals) + prcode(fp, +" {0, 0, 0}\n" +"};\n" + ); + } + + /* Generate the variable handlers. */ + nr_vars = 0; + + if (hasVarHandlers(cd)) + { + varDef *vd; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + if (vd->ecd == cd && needsHandler(vd)) + { + ++nr_vars; + + generateVariableGetter(cd->iff, vd, fp); + + if (canSetVariable(vd)) + generateVariableSetter(cd->iff, vd, fp); + } + + /* Generate the variable table. */ + prcode(fp, +"\n" +"sipVariableDef variables_%L[] = {\n" + , cd->iff); + + for (vd = pt->vars; vd != NULL; vd = vd->next) + if (vd->ecd == cd && needsHandler(vd)) + { + prcode(fp, +" {%N, varget_%C, ", vd->pyname, vd->fqcname); + + if (canSetVariable(vd)) + prcode(fp, "varset_%C", vd->fqcname); + else + prcode(fp, "NULL"); + + prcode(fp, ", %d},\n" + , (isStaticVar(vd) ? 1 : 0)); + } + + prcode(fp, +"};\n" + ); + } + + /* Generate each instance table. */ + is_inst_class = generateClasses(pt, mod, cd, fp); + is_inst_voidp = generateVoidPointers(pt, mod, cd, fp); + is_inst_char = generateChars(pt, mod, cd, fp); + is_inst_string = generateStrings(pt, mod, cd, fp); + is_inst_int = generateInts(pt, mod, cd, fp); + is_inst_long = generateLongs(pt, mod, cd, fp); + is_inst_ulong = generateUnsignedLongs(pt, mod, cd, fp); + is_inst_longlong = generateLongLongs(pt, mod, cd, fp); + is_inst_ulonglong = generateUnsignedLongLongs(pt, mod, cd, fp); + is_inst_double = generateDoubles(pt, mod, cd, fp); + + /* Generate the docstrings. */ + has_docstring = FALSE; + + if (cd->docstring != NULL || (docstrings && hasClassDocstring(pt, cd))) + { + prcode(fp, +"\n" +"PyDoc_STRVAR(doc_%L, ", cd->iff); + + if (cd->docstring != NULL) + generateExplicitDocstring(cd->docstring, fp); + else + generateClassDocstring(pt, cd, fp); + + prcode(fp, ");\n" + ); + + has_docstring = TRUE; + } + + if (pluginPyQt4(pt)) + { + type_prefix = "pyqt4"; + embedded = TRUE; + } + else if (pluginPyQt3(pt)) + { + type_prefix = "pyqt3"; + embedded = TRUE; + } + else + { + type_prefix = "sip"; + embedded = FALSE; + } + + prcode(fp, +"\n" +"\n" +"%sClassTypeDef ", type_prefix); + + generateTypeDefName(cd->iff, fp); + + prcode(fp, " = {\n" +"%s" +" {\n" +" %P,\n" +" " + , (embedded ? "{\n" : "") + , cd->iff->api_range); + + generateTypeDefLink(pt, cd->iff, fp); + + prcode(fp, ",\n" +" 0,\n" +" "); + + sep = ""; + + if (isAbstractClass(cd)) + { + prcode(fp, "%sSIP_TYPE_ABSTRACT", sep); + sep = "|"; + } + + if (cd->subbase != NULL) + { + prcode(fp, "%sSIP_TYPE_SCC", sep); + sep = "|"; + } + + if (classHandlesNone(cd)) + { + prcode(fp, "%sSIP_TYPE_ALLOW_NONE", sep); + sep = "|"; + } + + if (cd->iff->type == namespace_iface) + { + prcode(fp, "%sSIP_TYPE_NAMESPACE", sep); + sep = "|"; + } + else + { + prcode(fp, "%sSIP_TYPE_CLASS", sep); + sep = "|"; + } + + if (*sep == '\0') + prcode(fp, "0"); + + prcode(fp, ",\n"); + + prcode(fp, +" %n,\n" +" {0}\n" +" },\n" +" {\n" + , cd->iff->name); + + if (cd->real == NULL) + prcode(fp, +" %n,\n" + , cd->pyname); + else + prcode(fp, +" -1,\n" + ); + + prcode(fp, " "); + + if (cd->real != NULL) + generateEncodedType(mod, cd->real, 0, fp); + else if (cd->ecd != NULL) + generateEncodedType(mod, cd->ecd, 0, fp); + else + prcode(fp, "{0, 0, 1}"); + + prcode(fp, ",\n" + ); + + if (nr_methods == 0) + prcode(fp, +" 0, 0,\n" + ); + else + prcode(fp, +" %d, methods_%L,\n" + , nr_methods, cd->iff); + + if (nr_enums == 0) + prcode(fp, +" 0, 0,\n" + ); + else + prcode(fp, +" %d, enummembers_%L,\n" + , nr_enums, cd->iff); + + if (nr_vars == 0) + prcode(fp, +" 0, 0,\n" + ); + else + prcode(fp, +" %d, variables_%L,\n" + , nr_vars, cd->iff); + + prcode(fp, +" {"); + + if (is_inst_class) + prcode(fp, "typeInstances_%C, ", classFQCName(cd)); + else + prcode(fp, "0, "); + + if (is_inst_voidp) + prcode(fp, "voidPtrInstances_%C, ", classFQCName(cd)); + else + prcode(fp, "0, "); + + if (is_inst_char) + prcode(fp, "charInstances_%C, ", classFQCName(cd)); + else + prcode(fp, "0, "); + + if (is_inst_string) + prcode(fp, "stringInstances_%C, ", classFQCName(cd)); + else + prcode(fp, "0, "); + + if (is_inst_int) + prcode(fp, "intInstances_%C, ", classFQCName(cd)); + else + prcode(fp, "0, "); + + if (is_inst_long) + prcode(fp, "longInstances_%C, ", classFQCName(cd)); + else + prcode(fp, "0, "); + + if (is_inst_ulong) + prcode(fp, "unsignedLongInstances_%C, ", classFQCName(cd)); + else + prcode(fp, "0, "); + + if (is_inst_longlong) + prcode(fp, "longLongInstances_%C, ", classFQCName(cd)); + else + prcode(fp,"0, "); + + if (is_inst_ulonglong) + prcode(fp, "unsignedLongLongInstances_%C, ", classFQCName(cd)); + else + prcode(fp, "0, "); + + if (is_inst_double) + prcode(fp, "doubleInstances_%C", classFQCName(cd)); + else + prcode(fp, "0"); + + prcode(fp,"},\n" +" },\n" + ); + + if (has_docstring) + prcode(fp, +" doc_%L,\n" + , cd->iff); + else + prcode(fp, +" 0,\n" + ); + + if (cd->metatype != NULL) + prcode(fp, +" %n,\n" + , cd->metatype); + else + prcode(fp, +" -1,\n" + ); + + if (cd->supertype != NULL) + prcode(fp, +" %n,\n" + , cd->supertype); + else + prcode(fp, +" -1,\n" + ); + + if (cd->supers != NULL) + prcode(fp, +" supers_%C,\n" + , classFQCName(cd)); + else + prcode(fp, +" 0,\n" + ); + + if (is_slots) + prcode(fp, +" slots_%L,\n" + , cd->iff); + else + prcode(fp, +" 0,\n" + ); + + if (canCreate(cd)) + prcode(fp, +" init_%L,\n" + , cd->iff); + else + prcode(fp, +" 0,\n" + ); + + if (cd->travcode != NULL) + prcode(fp, +" traverse_%C,\n" + , classFQCName(cd)); + else + prcode(fp, +" 0,\n" + ); + + if (cd->clearcode != NULL) + prcode(fp, +" clear_%C,\n" + , classFQCName(cd)); + else + prcode(fp, +" 0,\n" + ); + + prcode(fp, +"#if PY_MAJOR_VERSION >= 3\n" + ); + + if (cd->getbufcode != NULL) + prcode(fp, +" getbuffer_%C,\n" + , classFQCName(cd)); + else + prcode(fp, +" 0,\n" + ); + + if (cd->releasebufcode != NULL) + prcode(fp, +" releasebuffer_%C,\n" + , classFQCName(cd)); + else + prcode(fp, +" 0,\n" + ); + + prcode(fp, +"#else\n" + ); + + if (cd->readbufcode != NULL) + prcode(fp, +" getreadbuffer_%C,\n" + , classFQCName(cd)); + else + prcode(fp, +" 0,\n" + ); + + if (cd->writebufcode != NULL) + prcode(fp, +" getwritebuffer_%C,\n" + , classFQCName(cd)); + else + prcode(fp, +" 0,\n" + ); + + if (cd->segcountcode != NULL) + prcode(fp, +" getsegcount_%C,\n" + , classFQCName(cd)); + else + prcode(fp, +" 0,\n" + ); + + if (cd->charbufcode != NULL) + prcode(fp, +" getcharbuffer_%C,\n" + , classFQCName(cd)); + else + prcode(fp, +" 0,\n" + ); + + prcode(fp, +"#endif\n" + ); + + if (needDealloc(cd)) + prcode(fp, +" dealloc_%L,\n" + , cd->iff); + else + prcode(fp, +" 0,\n" + ); + + if (generating_c || assignmentHelper(cd)) + prcode(fp, +" assign_%L,\n" +" array_%L,\n" +" copy_%L,\n" + , cd->iff + , cd->iff + , cd->iff); + else + prcode(fp, +" 0,\n" +" 0,\n" +" 0,\n" + ); + + if (cd->iff->type == namespace_iface || generating_c) + prcode(fp, +" 0,\n" +" 0,\n" + ); + else + prcode(fp, +" release_%L,\n" +" cast_%L,\n" + , cd->iff + , cd->iff); + + if (cd->iff->type == namespace_iface) + prcode(fp, +" 0,\n" + ); + else + { + if (cd->convtocode != NULL) + prcode(fp, +" convertTo_%L,\n" + , cd->iff); + else + prcode(fp, +" 0,\n" + ); + } + + prcode(fp, +" 0,\n" + ); + + if (cd->picklecode != NULL) + prcode(fp, +" pickle_%C\n" + , classFQCName(cd)); + else + prcode(fp, +" 0\n" + ); + + if (embedded) + prcode(fp, +"},\n" + ); + + if (pluginPyQt3(pt)) + { + if (hasSigSlots(cd)) + prcode(fp, +" signals_%C\n" + , classFQCName(cd)); + else + prcode(fp, +" 0\n" + ); + } + + if (pluginPyQt4(pt)) + { + if (isQObjectSubClass(cd) && !noPyQt4QMetaObject(cd)) + prcode(fp, +" &%U::staticMetaObject,\n" + , cd); + else + prcode(fp, +" 0,\n" + ); + + prcode(fp, +" %u,\n" + , cd->pyqt4_flags); + + if (is_signals) + prcode(fp, +" pyqt4_signals_%C\n" + , classFQCName(cd)); + else + prcode(fp, +" 0\n" + ); + } + + prcode(fp, +"};\n" + ); +} + + +/* + * Generate an entry in the PyQt4 signal table. + */ +static void generateSignalTableEntry(sipSpec *pt, classDef *cd, overDef *sig, + memberDef *md, int membernr, FILE *fp) +{ + prcode(fp, +" {\"%s(", sig->cppname); + + generateCalledArgs(cd->iff, sig->cppsig, Declaration, TRUE, fp); + + prcode(fp,")\", "); + + if (docstrings) + { + fprintf(fp, "\"\\1"); + prScopedPythonName(fp, cd->ecd, cd->pyname->text); + fprintf(fp, ".%s", md->pyname->text); + prPythonSignature(pt, fp, &sig->pysig, FALSE, FALSE, FALSE, FALSE, + TRUE); + fprintf(fp, "\", "); + } + else + { + prcode(fp, "0, "); + } + + if (membernr >= 0) + prcode(fp, "&methods_%L[%d]", cd->iff, membernr); + else + prcode(fp, "0"); + + prcode(fp,"},\n" + ); +} + + +/* + * Return TRUE if the slot is specific to Python v2. + */ +static int py2OnlySlot(slotType st) +{ + /* + * Note that we place interpretations on div_slot and idiv_slot for Python + * v3 so they are not included. + */ + return (st == long_slot || st == cmp_slot); +} + + +/* + * Return TRUE if the slot is specific to Python v2.5 and later. + */ +static int py2_5LaterSlot(slotType st) +{ + return (st == index_slot); +} + + +/* + * Return the sip module's string equivalent of a slot. + */ +static const char *slotName(slotType st) +{ + const char *sn; + + switch (st) + { + case str_slot: + sn = "str_slot"; + break; + + case int_slot: + sn = "int_slot"; + break; + + case long_slot: + sn = "long_slot"; + break; + + case float_slot: + sn = "float_slot"; + break; + + case len_slot: + sn = "len_slot"; + break; + + case contains_slot: + sn = "contains_slot"; + break; + + case add_slot: + sn = "add_slot"; + break; + + case concat_slot: + sn = "concat_slot"; + break; + + case sub_slot: + sn = "sub_slot"; + break; + + case mul_slot: + sn = "mul_slot"; + break; + + case repeat_slot: + sn = "repeat_slot"; + break; + + case div_slot: + sn = "div_slot"; + break; + + case mod_slot: + sn = "mod_slot"; + break; + + case floordiv_slot: + sn = "floordiv_slot"; + break; + + case truediv_slot: + sn = "truediv_slot"; + break; + + case and_slot: + sn = "and_slot"; + break; + + case or_slot: + sn = "or_slot"; + break; + + case xor_slot: + sn = "xor_slot"; + break; + + case lshift_slot: + sn = "lshift_slot"; + break; + + case rshift_slot: + sn = "rshift_slot"; + break; + + case iadd_slot: + sn = "iadd_slot"; + break; + + case iconcat_slot: + sn = "iconcat_slot"; + break; + + case isub_slot: + sn = "isub_slot"; + break; + + case imul_slot: + sn = "imul_slot"; + break; + + case irepeat_slot: + sn = "irepeat_slot"; + break; + + case idiv_slot: + sn = "idiv_slot"; + break; + + case imod_slot: + sn = "imod_slot"; + break; + + case ifloordiv_slot: + sn = "ifloordiv_slot"; + break; + + case itruediv_slot: + sn = "itruediv_slot"; + break; + + case iand_slot: + sn = "iand_slot"; + break; + + case ior_slot: + sn = "ior_slot"; + break; + + case ixor_slot: + sn = "ixor_slot"; + break; + + case ilshift_slot: + sn = "ilshift_slot"; + break; + + case irshift_slot: + sn = "irshift_slot"; + break; + + case invert_slot: + sn = "invert_slot"; + break; + + case call_slot: + sn = "call_slot"; + break; + + case getitem_slot: + sn = "getitem_slot"; + break; + + case setitem_slot: + sn = "setitem_slot"; + break; + + case delitem_slot: + sn = "delitem_slot"; + break; + + case lt_slot: + sn = "lt_slot"; + break; + + case le_slot: + sn = "le_slot"; + break; + + case eq_slot: + sn = "eq_slot"; + break; + + case ne_slot: + sn = "ne_slot"; + break; + + case gt_slot: + sn = "gt_slot"; + break; + + case ge_slot: + sn = "ge_slot"; + break; + + case cmp_slot: + sn = "cmp_slot"; + break; + + case bool_slot: + sn = "bool_slot"; + break; + + case neg_slot: + sn = "neg_slot"; + break; + + case pos_slot: + sn = "pos_slot"; + break; + + case abs_slot: + sn = "abs_slot"; + break; + + case repr_slot: + sn = "repr_slot"; + break; + + case hash_slot: + sn = "hash_slot"; + break; + + case index_slot: + sn = "index_slot"; + break; + + case iter_slot: + sn = "iter_slot"; + break; + + case next_slot: + sn = "next_slot"; + break; + + default: + sn = NULL; + } + + return sn; +} + + +/* + * Generate the initialisation function or cast operators for the type. + */ +static void generateTypeInit(classDef *cd, moduleDef *mod, FILE *fp) +{ + ctorDef *ct; + int need_self, need_owner; + + /* + * See if we need to name the self and owner arguments so that we can + * avoid a compiler warning about an unused argument. + */ + need_self = (generating_c || hasShadow(cd)); + need_owner = generating_c; + + for (ct = cd->ctors; ct != NULL; ct = ct->next) + { + if (usedInCode(ct->methodcode, "sipSelf")) + need_self = TRUE; + + if (isResultTransferredCtor(ct)) + need_owner = TRUE; + else + { + int a; + + for (a = 0; a < ct->pysig.nrArgs; ++a) + if (isThisTransferred(&ct->pysig.args[a])) + { + need_owner = TRUE; + break; + } + } + } + + prcode(fp, +"\n" +"\n" + ); + + if (!generating_c) + prcode(fp, +"extern \"C\" {static void *init_%L(sipSimpleWrapper *, PyObject *, PyObject *, PyObject **, PyObject **, PyObject **);}\n" + , cd->iff); + + prcode(fp, +"static void *init_%L(sipSimpleWrapper *%s, PyObject *sipArgs, PyObject *sipKwds, PyObject **sipUnused, PyObject **%s, PyObject **sipParseErr)\n" +"{\n" + , cd->iff, (need_self ? "sipSelf" : ""), (need_owner ? "sipOwner" : "")); + + if (hasShadow(cd)) + prcode(fp, +" sip%C *sipCpp = 0;\n" + ,classFQCName(cd)); + else + prcode(fp, +" %U *sipCpp = 0;\n" + ,cd); + + if (tracing) + prcode(fp, +"\n" +" sipTrace(SIP_TRACE_INITS,\"init_%L()\\n\");\n" + , cd->iff); + + /* + * Generate the code that parses the Python arguments and calls the + * correct constructor. + */ + for (ct = cd->ctors; ct != NULL; ct = ct->next) + { + int needSecCall, error_flag, old_error_flag; + apiVersionRangeDef *avr; + + if (isPrivateCtor(ct)) + continue; + + avr = ct->api_range; + + prcode(fp, +"\n" + ); + + if (avr != NULL) + prcode(fp, +" if (sipIsAPIEnabled(%N, %d, %d))\n" + , avr->api_name, avr->from, avr->to); + + prcode(fp, +" {\n" + ); + + if (ct->methodcode != NULL) + { + error_flag = needErrorFlag(ct->methodcode); + old_error_flag = needOldErrorFlag(ct->methodcode); + } + else + { + error_flag = old_error_flag = FALSE; + } + + needSecCall = generateArgParser(&ct->pysig, cd, NULL, ct, NULL, FALSE, + fp); + generateConstructorCall(cd, ct, error_flag, old_error_flag, mod, fp); + + if (needSecCall) + { + prcode(fp, +" }\n" +"\n" + ); + + if (avr != NULL) + prcode(fp, +" if (sipIsAPIEnabled(%N, %d, %d))\n" + , avr->api_name, avr->from, avr->to); + + prcode(fp, +" {\n" + ); + + generateArgParser(&ct->pysig, cd, NULL, ct, NULL, TRUE, fp); + generateConstructorCall(cd, ct, error_flag, old_error_flag, mod, + fp); + } + + prcode(fp, +" }\n" + ); + } + + prcode(fp, +"\n" +" return NULL;\n" +"}\n" + ); +} + + +/* + * Count the number of virtual members in a class. + */ +static int countVirtuals(classDef *cd) +{ + int nrvirts; + virtOverDef *vod; + + nrvirts = 0; + + for (vod = cd->vmembers; vod != NULL; vod = vod->next) + if (!isPrivate(&vod->o)) + ++nrvirts; + + return nrvirts; +} + + +/* + * Generate the try block for a call. + */ +static void generateTry(throwArgs *ta,FILE *fp) +{ + /* + * Generate the block if there was no throw specifier, or a non-empty + * throw specifier. + */ + if (exceptions && (ta == NULL || ta->nrArgs > 0)) + prcode(fp, +" try\n" +" {\n" + ); +} + + +/* + * Generate the catch blocks for a call. + */ +static void generateCatch(throwArgs *ta, signatureDef *sd, moduleDef *mod, + FILE *fp) +{ + /* + * Generate the block if there was no throw specifier, or a non-empty + * throw specifier. + */ + if (exceptions && (ta == NULL || ta->nrArgs > 0)) + { + prcode(fp, +" }\n" + ); + + if (ta != NULL) + { + int a; + + for (a = 0; a < ta->nrArgs; ++a) + generateCatchBlock(ta->args[a], sd, fp); + } + else if (mod->defexception != NULL) + { + generateCatchBlock(mod->defexception, sd, fp); + } + + prcode(fp, +" catch (...)\n" +" {\n" + ); + + if (release_gil) + prcode(fp, +" Py_BLOCK_THREADS\n" +"\n" + ); + + deleteOuts(sd, fp); + deleteTemps(sd, fp); + + prcode(fp, +" sipRaiseUnknownException();\n" +" return NULL;\n" +" }\n" + ); + } +} + + +/* + * Generate a single catch block. + */ +static void generateCatchBlock(exceptionDef *xd, signatureDef *sd, FILE *fp) +{ + scopedNameDef *ename = xd->iff->fqcname; + + prcode(fp, +" catch (%S &%s)\n" +" {\n" + ,ename,(xd->cd != NULL || usedInCode(xd->raisecode, "sipExceptionRef")) ? "sipExceptionRef" : ""); + + if (release_gil) + prcode(fp, +"\n" +" Py_BLOCK_THREADS\n" + ); + + deleteOuts(sd, fp); + deleteTemps(sd, fp); + + /* See if the exception is a wrapped class. */ + if (xd->cd != NULL) + prcode(fp, +" /* Hope that there is a valid copy ctor. */\n" +" %S *sipExceptionCopy = new %S(sipExceptionRef);\n" +"\n" +" sipRaiseTypeException(sipType_%C,sipExceptionCopy);\n" + , ename, ename + , ename); + else + generateCppCodeBlock(xd->raisecode, fp); + + prcode(fp, +"\n" +" return NULL;\n" +" }\n" + ); +} + + +/* + * Generate a throw specifier. + */ +static void generateThrowSpecifier(throwArgs *ta,FILE *fp) +{ + if (exceptions && ta != NULL) + { + int a; + + prcode(fp," throw("); + + for (a = 0; a < ta->nrArgs; ++a) + { + if (a > 0) + prcode(fp,","); + + prcode(fp,"%S",ta->args[a]->iff->fqcname); + } + + prcode(fp,")"); + } +} + + +/* + * Generate a single constructor call. + */ +static void generateConstructorCall(classDef *cd, ctorDef *ct, int error_flag, + int old_error_flag, moduleDef *mod, FILE *fp) +{ + prcode(fp, +" {\n" + ); + + if (error_flag) + prcode(fp, +" sipErrorState sipError = sipErrorNone;\n" +"\n" + ); + else if (old_error_flag) + prcode(fp, +" int sipIsErr = 0;\n" +"\n" + ); + + if (isDeprecatedCtor(ct)) + /* Note that any temporaries will leak if an exception is raised. */ + prcode(fp, +" if (sipDeprecated(%N,NULL) < 0)\n" +" return NULL;\n" +"\n" + , cd->pyname); + + /* Call any pre-hook. */ + if (ct->prehook != NULL) + prcode(fp, +" sipCallHook(\"%s\");\n" +"\n" + ,ct->prehook); + + if (ct->methodcode != NULL) + generateCppCodeBlock(ct->methodcode,fp); + else if (generating_c) + prcode(fp, +" sipCpp = sipMalloc(sizeof (%S));\n" + ,classFQCName(cd)); + else + { + int rgil = ((release_gil || isReleaseGILCtor(ct)) && !isHoldGILCtor(ct)); + + if (rgil) + prcode(fp, +" Py_BEGIN_ALLOW_THREADS\n" + ); + + generateTry(ct->exceptions,fp); + + if (hasShadow(cd)) + prcode(fp, +" sipCpp = new sip%C(",classFQCName(cd)); + else + prcode(fp, +" sipCpp = new %U(",cd); + + if (isCastCtor(ct)) + { + classDef *ocd; + + /* We have to fiddle the type to generate the correct code. */ + ocd = ct->pysig.args[0].u.cd; + ct->pysig.args[0].u.cd = cd; + prcode(fp, "a0->operator %B()", &ct->pysig.args[0]); + ct->pysig.args[0].u.cd = ocd; + } + else + generateCallArgs(ct->cppsig, &ct->pysig, fp); + + prcode(fp,");\n" + ); + + generateCatch(ct->exceptions, &ct->pysig, mod, fp); + + if (rgil) + prcode(fp, +" Py_END_ALLOW_THREADS\n" + ); + + /* + * This is a bit of a hack to say we want the result transferred. We + * don't simply call sipTransferTo() because the wrapper object hasn't + * been fully initialised yet. + */ + if (isResultTransferredCtor(ct)) + prcode(fp, +"\n" +" *sipOwner = Py_None;\n" + ); + } + + gc_ellipsis(&ct->pysig, fp); + + deleteTemps(&ct->pysig, fp); + + prcode(fp, +"\n" + ); + + if (error_flag) + { + prcode(fp, +" if (sipError == sipErrorNone)\n" + ); + + if (hasShadow(cd) || ct->posthook != NULL) + prcode(fp, +" {\n" + ); + + if (hasShadow(cd)) + prcode(fp, +" sipCpp->sipPySelf = sipSelf;\n" +"\n" + ); + + /* Call any post-hook. */ + if (ct->posthook != NULL) + prcode(fp, +" sipCallHook(\"%s\");\n" +"\n" + , ct->posthook); + + prcode(fp, +" return sipCpp;\n" + ); + + if (hasShadow(cd) || ct->posthook != NULL) + prcode(fp, +" }\n" + ); + + prcode(fp, +"\n" +" if (sipUnused)\n" +" {\n" +" Py_XDECREF(*sipUnused);\n" +" }\n" +"\n" +" sipAddException(sipError, sipParseErr);\n" +"\n" +" if (sipError == sipErrorFail)\n" +" return NULL;\n" + ); + } + else + { + if (old_error_flag) + { + prcode(fp, +" if (sipIsErr)\n" +" {\n" +" if (sipUnused)\n" +" {\n" +" Py_XDECREF(*sipUnused);\n" +" }\n" +"\n" +" sipAddException(sipErrorFail, sipParseErr);\n" +" return NULL;\n" +" }\n" +"\n" + ); + } + + if (hasShadow(cd)) + prcode(fp, +" sipCpp->sipPySelf = sipSelf;\n" +"\n" + ); + + /* Call any post-hook. */ + if (ct->posthook != NULL) + prcode(fp, +" sipCallHook(\"%s\");\n" +"\n" + , ct->posthook); + + prcode(fp, +" return sipCpp;\n" + ); + } + + prcode(fp, +" }\n" + ); +} + + +/* + * See if a member overload should be skipped. + */ +static int skipOverload(overDef *od,memberDef *md,classDef *cd,classDef *ccd, + int want_local) +{ + /* Skip if it's not the right name. */ + if (od->common != md) + return TRUE; + + /* Skip if it's a signal. */ + if (isSignal(od)) + return TRUE; + + /* Skip if it's a private abstract. */ + if (isAbstract(od) && isPrivate(od)) + return TRUE; + + /* + * If we are disallowing them, skip if it's not in the current class + * unless it is protected. + */ + if (want_local && !isProtected(od) && ccd != cd) + return TRUE; + + return FALSE; +} + + +/* + * Generate a class member function. + */ +static void generateFunction(sipSpec *pt, memberDef *md, overDef *overs, + classDef *cd, classDef *ocd, moduleDef *mod, FILE *fp) +{ + overDef *od; + int need_method, need_self, need_args, need_selfarg, need_orig_self, need_kwds; + + /* + * Check that there is at least one overload that needs to be handled. + * See if we can avoid naming the "self" argument (and suppress a + * compiler warning). See if we need to remember if "self" was explicitly + * passed as an argument. See if we need to handle keyword arguments. + */ + need_method = need_self = need_args = need_selfarg = need_orig_self = need_kwds = FALSE; + + for (od = overs; od != NULL; od = od->next) + { + /* + * Skip protected methods if we don't have the means to handle + * them. + */ + if (isProtected(od) && !hasShadow(cd)) + continue; + + if (!skipOverload(od,md,cd,ocd,TRUE)) + { + need_method = TRUE; + + if (!isPrivate(od)) + { + need_args = TRUE; + + if (!isStatic(od)) + { + need_self = TRUE; + + if (isAbstract(od)) + need_orig_self = TRUE; + else if (isVirtual(od) || isVirtualReimp(od) || usedInCode(od->methodcode, "sipSelfWasArg")) + need_selfarg = TRUE; + } + + if (useKeywordArgs(od)) + need_kwds = TRUE; + } + } + } + + if (need_method) + { + const char *pname = md->pyname->text; + int has_auto_docstring; + + prcode(fp, +"\n" +"\n" + ); + + /* Generate the docstrings. */ + has_auto_docstring = FALSE; + + if (md->docstring != NULL || (docstrings && hasDocstring(pt, overs, md, cd->iff))) + { + prcode(fp, +"PyDoc_STRVAR(doc_%L_%s, " , cd->iff, pname); + + if (md->docstring != NULL) + { + generateExplicitDocstring(md->docstring, fp); + } + else + { + generateDocstring(pt, overs, md, cd->pyname->text, cd->ecd, fp); + has_auto_docstring = TRUE; + } + + prcode(fp, ");\n" +"\n" + ); + } + + if (!generating_c) + prcode(fp, +"extern \"C\" {static PyObject *meth_%L_%s(PyObject *, PyObject *%s);}\n" + , cd->iff, pname, (noArgParser(md) || need_kwds ? ", PyObject *" : "")); + + prcode(fp, +"static PyObject *meth_%L_%s(PyObject *%s, PyObject *%s%s)\n" +"{\n" + , cd->iff, pname, (need_self ? "sipSelf" : ""), (need_args ? "sipArgs" : ""), (noArgParser(md) || need_kwds ? ", PyObject *sipKwds" : "")); + + if (tracing) + prcode(fp, +" sipTrace(SIP_TRACE_METHODS,\"meth_%L_%s()\\n\");\n" +"\n" + , cd->iff, pname); + + if (!noArgParser(md)) + { + if (need_args) + prcode(fp, +" PyObject *sipParseErr = NULL;\n" + ); + + if (need_selfarg) + { + /* + * This determines if we call the explicitly scoped version or + * the unscoped version (which will then go via the vtable). + * + * - If the call was unbound and self was passed as the first + * argument (ie. Foo.meth(self)) then we always want to call + * the explicitly scoped version. + * + * - If the call was bound then we only call the unscoped + * version in case there is a C++ reimplementation that + * Python knows nothing about. Otherwise, if the call was + * invoked by super() within a Python reimplementation then + * the Python reimplementation would be called recursively. + */ + prcode(fp, +" bool sipSelfWasArg = (!sipSelf || sipIsDerived((sipSimpleWrapper *)sipSelf));\n" + ); + } + + if (need_orig_self) + { + /* + * This is similar to the above but for abstract methods. We + * allow the (potential) recursion because it means that the + * concrete implementation can be put in a mixin and it will + * all work. + */ + prcode(fp, +" PyObject *sipOrigSelf = sipSelf;\n" + ); + } + } + + for (od = overs; od != NULL; od = od->next) + { + /* If we are handling one variant then we must handle them all. */ + if (skipOverload(od, md, cd, ocd, FALSE)) + continue; + + if (isPrivate(od)) + continue; + + if (noArgParser(md)) + { + generateCppCodeBlock(od->methodcode, fp); + break; + } + + generateFunctionBody(od, cd, NULL, ocd, TRUE, mod, fp); + } + + if (!noArgParser(md)) + { + prcode(fp, +"\n" +" /* Raise an exception if the arguments couldn't be parsed. */\n" +" sipNoMethod(%s, %N, %N, ", (need_args ? "sipParseErr" : "NULL"), cd->pyname, md->pyname); + + if (has_auto_docstring) + prcode(fp, "doc_%L_%s", cd->iff, pname); + else + prcode(fp, "NULL"); + + prcode(fp, ");\n" +"\n" +" return NULL;\n" + ); + } + + prcode(fp, +"}\n" + ); + } +} + + +/* + * Generate the function calls for a particular overload. + */ +static void generateFunctionBody(overDef *od, classDef *c_scope, + mappedTypeDef *mt_scope, classDef *ocd, int deref, moduleDef *mod, + FILE *fp) +{ + int needSecCall; + signatureDef saved; + ifaceFileDef *o_scope; + apiVersionRangeDef *avr; + + if (mt_scope != NULL) + o_scope = mt_scope->iff; + else if (ocd != NULL) + o_scope = ocd->iff; + else + o_scope = NULL; + + if (o_scope != NULL) + avr = od->api_range; + else + avr = NULL; + + if (avr != NULL) + prcode(fp, +"\n" +" if (sipIsAPIEnabled(%N, %d, %d))\n" +" {\n" + , avr->api_name, avr->from, avr->to); + else + prcode(fp, +"\n" +" {\n" + ); + + /* In case we have to fiddle with it. */ + saved = od->pysig; + + if (isNumberSlot(od->common)) + { + /* + * Number slots must have two arguments because we parse them slightly + * differently. + */ + if (od->pysig.nrArgs == 1) + { + od->pysig.nrArgs = 2; + od->pysig.args[1] = od->pysig.args[0]; + + /* Insert self in the right place. */ + od->pysig.args[0].atype = class_type; + od->pysig.args[0].name = NULL; + od->pysig.args[0].argflags = ARG_IS_REF|ARG_IN; + od->pysig.args[0].nrderefs = 0; + od->pysig.args[0].defval = NULL; + od->pysig.args[0].original_type = NULL; + od->pysig.args[0].u.cd = ocd; + } + + generateArgParser(&od->pysig, c_scope, mt_scope, NULL, od, FALSE, fp); + needSecCall = FALSE; + } + else if (isIntArgSlot(od->common) || isZeroArgSlot(od->common)) + needSecCall = FALSE; + else + needSecCall = generateArgParser(&od->pysig, c_scope, mt_scope, NULL, od, FALSE, fp); + + generateFunctionCall(c_scope, mt_scope, o_scope, od, deref, mod, fp); + + if (needSecCall) + { + prcode(fp, +" }\n" +"\n" +" {\n" + ); + + generateArgParser(&od->pysig, c_scope, mt_scope, NULL, od, TRUE, fp); + generateFunctionCall(c_scope, mt_scope, o_scope, od, deref, mod, fp); + } + + prcode(fp, +" }\n" + ); + + od->pysig = saved; +} + + +/* + * Generate the code to handle the result of a call to a member function. + */ +static void generateHandleResult(overDef *od, int isNew, int result_size, + char *prefix, FILE *fp) +{ + char *vname, vnamebuf[50]; + int a, nrvals, only, has_owner; + argDef *res, *ad; + + res = &od->pysig.result; + + if (res->atype == void_type && res->nrderefs == 0) + res = NULL; + + /* See if we are returning 0, 1 or more values. */ + nrvals = 0; + + if (res != NULL) + { + only = -1; + ++nrvals; + } + + has_owner = FALSE; + + for (a = 0; a < od->pysig.nrArgs; ++a) + { + if (isOutArg(&od->pysig.args[a])) + { + only = a; + ++nrvals; + } + + if (isThisTransferred(&od->pysig.args[a])) + has_owner = TRUE; + } + + /* Handle the trivial case. */ + if (nrvals == 0) + { + prcode(fp, +" Py_INCREF(Py_None);\n" +" %s Py_None;\n" + ,prefix); + + return; + } + + /* Handle results that are classes or mapped types separately. */ + if (res != NULL) + { + ifaceFileDef *iff; + + if (res->atype == mapped_type) + iff = res->u.mtd->iff; + else if (res->atype == class_type) + iff = res->u.cd->iff; + else + iff = NULL; + + if (iff != NULL) + { + if (isNew || isFactory(od)) + { + prcode(fp, +" %s sipConvertFromNewType(",(nrvals == 1 ? prefix : "PyObject *sipResObj =")); + + if (isConstArg(res)) + prcode(fp,"const_cast<%b *>(sipRes)",res); + else + prcode(fp,"sipRes"); + + prcode(fp,",sipType_%C,%s);\n" + , iff->fqcname, ((has_owner && isFactory(od)) ? "(PyObject *)sipOwner" : "NULL")); + + /* + * Shortcut if this is the only value returned. + */ + if (nrvals == 1) + return; + } + else + { + prcode(fp, +" %s sipConvertFromType(",(nrvals == 1 ? prefix : "PyObject *sipResObj =")); + + if (isConstArg(res)) + prcode(fp,"const_cast<%b *>(sipRes)",res); + else + prcode(fp,"sipRes"); + + prcode(fp, ",sipType_%C,%s);\n" + , iff->fqcname, resultOwner(od)); + + /* + * Shortcut if this is the only value returned. + */ + if (nrvals == 1) + return; + } + } + } + + /* If there are multiple values then build a tuple. */ + if (nrvals > 1) + { + prcode(fp, +" %s sipBuildResult(0,\"(",prefix); + + /* Build the format string. */ + if (res != NULL) + prcode(fp, "%s", ((res->atype == mapped_type || res->atype == class_type) ? "R" : getBuildResultFormat(res))); + + for (a = 0; a < od->pysig.nrArgs; ++a) + { + argDef *ad = &od->pysig.args[a]; + + if (isOutArg(ad)) + prcode(fp, "%s", getBuildResultFormat(ad)); + } + + prcode(fp,")\""); + + /* Pass the values for conversion. */ + if (res != NULL) + { + prcode(fp, ",sipRes"); + + if (res->atype == mapped_type || res->atype == class_type) + prcode(fp, "Obj"); + else if (res->atype == enum_type && res->u.ed->fqcname != NULL) + prcode(fp, ",sipType_%C", res->u.ed->fqcname); + } + + for (a = 0; a < od->pysig.nrArgs; ++a) + { + argDef *ad = &od->pysig.args[a]; + + if (isOutArg(ad)) + { + prcode(fp, ",a%d", a); + + if (ad->atype == mapped_type) + prcode(fp, ",sipType_%T,%s", ad, (isTransferredBack(ad) ? "Py_None" : "NULL")); + else if (ad->atype == class_type) + prcode(fp, ",sipType_%C,%s", classFQCName(ad->u.cd), (isTransferredBack(ad) ? "Py_None" : "NULL")); + else if (ad->atype == enum_type && ad->u.ed->fqcname != NULL) + prcode(fp,",sipType_%C", ad->u.ed->fqcname); + } + } + + prcode(fp,");\n" + ); + + /* All done for multiple values. */ + return; + } + + /* Deal with the only returned value. */ + if (only < 0) + { + ad = res; + vname = "sipRes"; + } + else + { + ad = &od->pysig.args[only]; + + sprintf(vnamebuf,"a%d",only); + vname = vnamebuf; + } + + switch (ad->atype) + { + case mapped_type: + case class_type: + { + int needNew = needNewInstance(ad); + ifaceFileDef *iff; + + if (ad->atype == mapped_type) + iff = ad->u.mtd->iff; + else + iff = ad->u.cd->iff; + + prcode(fp, +" %s sipConvertFrom%sType(", prefix, (needNew ? "New" : "")); + + if (isConstArg(ad)) + prcode(fp,"const_cast<%b *>(%s)",ad,vname); + else + prcode(fp,"%s",vname); + + prcode(fp, ",sipType_%C,", iff->fqcname); + + if (needNew || !isTransferredBack(ad)) + prcode(fp, "NULL);\n"); + else + prcode(fp, "Py_None);\n"); + } + + break; + + case bool_type: + case cbool_type: + prcode(fp, +" %s PyBool_FromLong(%s);\n" + ,prefix,vname); + + break; + + case ascii_string_type: + if (ad->nrderefs == 0) + prcode(fp, +" %s PyUnicode_DecodeASCII(&%s, 1, NULL);\n" + , prefix, vname); + else + prcode(fp, +" if (%s == NULL)\n" +" {\n" +" Py_INCREF(Py_None);\n" +" return Py_None;\n" +" }\n" +"\n" +" %s PyUnicode_DecodeASCII(%s, strlen(%s), NULL);\n" + , vname + , prefix, vname, vname); + + break; + + case latin1_string_type: + if (ad->nrderefs == 0) + prcode(fp, +" %s PyUnicode_DecodeLatin1(&%s, 1, NULL);\n" + , prefix, vname); + else + prcode(fp, +" if (%s == NULL)\n" +" {\n" +" Py_INCREF(Py_None);\n" +" return Py_None;\n" +" }\n" +"\n" +" %s PyUnicode_DecodeLatin1(%s, strlen(%s), NULL);\n" + , vname + , prefix, vname, vname); + + break; + + case utf8_string_type: + if (ad->nrderefs == 0) + prcode(fp, +"#if PY_MAJOR_VERSION >= 3\n" +" %s PyUnicode_FromStringAndSize(&%s, 1);\n" +"#else\n" +" %s PyUnicode_DecodeUTF8(&%s, 1, NULL);\n" +"#endif\n" + , prefix, vname + , prefix, vname); + else + prcode(fp, +" if (%s == NULL)\n" +" {\n" +" Py_INCREF(Py_None);\n" +" return Py_None;\n" +" }\n" +"\n" +"#if PY_MAJOR_VERSION >= 3\n" +" %s PyUnicode_FromString(%s);\n" +"#else\n" +" %s PyUnicode_DecodeUTF8(%s, strlen(%s), NULL);\n" +"#endif\n" + , vname + , prefix, vname + , prefix, vname, vname); + + break; + + case sstring_type: + case ustring_type: + case string_type: + if (ad->nrderefs == 0) + prcode(fp, +" %s SIPBytes_FromStringAndSize(%s&%s,1);\n" + ,prefix,(ad->atype != string_type) ? "(char *)" : "",vname); + else + prcode(fp, +" if (%s == NULL)\n" +" {\n" +" Py_INCREF(Py_None);\n" +" return Py_None;\n" +" }\n" +"\n" +" %s SIPBytes_FromString(%s%s);\n" + ,vname + ,prefix,(ad->atype != string_type) ? "(char *)" : "",vname); + + break; + + case wstring_type: + if (ad->nrderefs == 0) + prcode(fp, +" %s PyUnicode_FromWideChar(&%s,1);\n" + , prefix, vname); + else + prcode(fp, +" if (%s == NULL)\n" +" {\n" +" Py_INCREF(Py_None);\n" +" return Py_None;\n" +" }\n" +"\n" +" %s PyUnicode_FromWideChar(%s,(SIP_SSIZE_T)wcslen(%s));\n" + , vname + , prefix, vname, vname); + + break; + + case enum_type: + if (ad->u.ed->fqcname != NULL) + { + prcode(fp, +" %s sipConvertFromEnum(%s,sipType_%C);\n" + , prefix, vname, ad->u.ed->fqcname); + + break; + } + + /* Drop through. */ + + case short_type: + case int_type: + case cint_type: + prcode(fp, +" %s SIPLong_FromLong(%s);\n" + ,prefix,vname); + + break; + + case long_type: + prcode(fp, +" %s PyLong_FromLong(%s);\n" + ,prefix,vname); + + break; + + case ushort_type: + case uint_type: + case ulong_type: + prcode(fp, +" %s PyLong_FromUnsignedLong(%s);\n" + ,prefix,vname); + + break; + + case longlong_type: + prcode(fp, +" %s PyLong_FromLongLong(%s);\n" + ,prefix,vname); + + break; + + case ulonglong_type: + prcode(fp, +" %s PyLong_FromUnsignedLongLong(%s);\n" + ,prefix,vname); + + break; + + case void_type: + { + const char *cnst = (isConstArg(ad) ? "Const" : ""); + + if (result_size < 0) + prcode(fp, +" %s sipConvertFrom%sVoidPtr(%s);\n" + , prefix, cnst, vname); + else + prcode(fp, +" %s sipConvertFrom%sVoidPtrAndSize(%s,a%d);\n" + , prefix, cnst, vname, result_size); + } + + break; + + case struct_type: + prcode(fp, +" %s sipConvertFrom%sVoidPtr(%s);\n" + , prefix, (isConstArg(ad) ? "Const" : ""), vname); + break; + + case float_type: + case cfloat_type: + prcode(fp, +" %s PyFloat_FromDouble((double)%s);\n" + ,prefix,vname); + + break; + + case double_type: + case cdouble_type: + prcode(fp, +" %s PyFloat_FromDouble(%s);\n" + ,prefix,vname); + + break; + + case pyobject_type: + case pytuple_type: + case pylist_type: + case pydict_type: + case pycallable_type: + case pyslice_type: + case pytype_type: + prcode(fp, +" %s %s;\n" + ,prefix,vname); + + break; + } +} + + +/* + * Return the owner of a method result. + */ +static const char *resultOwner(overDef *od) +{ + if (isResultTransferredBack(od)) + return "Py_None"; + + if (isResultTransferred(od)) + return "sipSelf"; + + return "NULL"; +} + + +/* + * Return the format string used by sipBuildResult() for a particular type. + */ +static const char *getBuildResultFormat(argDef *ad) +{ + switch (ad->atype) + { + case fake_void_type: + case mapped_type: + case class_type: + if (needNewInstance(ad)) + return "N"; + + return "D"; + + case bool_type: + case cbool_type: + return "b"; + + case ascii_string_type: + return (ad->nrderefs > (isOutArg(ad) ? 1 : 0)) ? "AA" : "aA"; + + case latin1_string_type: + return (ad->nrderefs > (isOutArg(ad) ? 1 : 0)) ? "AL" : "aL"; + + case utf8_string_type: + return (ad->nrderefs > (isOutArg(ad) ? 1 : 0)) ? "A8" : "a8"; + + case sstring_type: + case ustring_type: + case string_type: + return (ad->nrderefs > (isOutArg(ad) ? 1 : 0)) ? "s" : "c"; + + case wstring_type: + return (ad->nrderefs > (isOutArg(ad) ? 1 : 0)) ? "x" : "w"; + + case enum_type: + return (ad->u.ed->fqcname != NULL) ? "F" : "e"; + + case short_type: + return "h"; + + case ushort_type: + return "t"; + + case int_type: + case cint_type: + return "i"; + + case uint_type: + return "u"; + + case long_type: + return "l"; + + case ulong_type: + return "m"; + + case longlong_type: + return "n"; + + case ulonglong_type: + return "o"; + + case void_type: + case struct_type: + return "V"; + + case float_type: + case cfloat_type: + return "f"; + + case double_type: + case cdouble_type: + return "d"; + + case pyobject_type: + case pytuple_type: + case pylist_type: + case pydict_type: + case pycallable_type: + case pyslice_type: + case pytype_type: + return "R"; + } + + /* We should never get here. */ + return ""; +} + + +/* + * Return TRUE if an argument (or result) should be copied because it is a + * const reference to a type. + */ +static int copyConstRefArg(argDef *ad) +{ + if (!noCopy(ad) && (ad->atype == class_type || ad->atype == mapped_type) && ad->nrderefs == 0) + { + /* Make a copy if it is not a reference or it is a const reference. */ + if (!isReference(ad) || isConstArg(ad)) + { + /* If it is a class then we must be able to copy it. */ + if (ad->atype != class_type || !(cannotCopy(ad->u.cd) || isAbstractClass(ad->u.cd))) + { + return TRUE; + } + } + } + + return FALSE; +} + + +/* + * Generate a function call. + */ +static void generateFunctionCall(classDef *c_scope, mappedTypeDef *mt_scope, + ifaceFileDef *o_scope, overDef *od, int deref, moduleDef *mod, + FILE *fp) +{ + int needsNew, error_flag, old_error_flag, newline, is_result, result_size, + a, deltemps; + const char *error_value; + argDef *res = &od->pysig.result, orig_res; + ifaceFileDef *scope; + nameDef *pyname; + + if (mt_scope != NULL) + { + scope = mt_scope->iff; + pyname = mt_scope->pyname; + } + else if (c_scope != NULL) + { + scope = c_scope->iff; + pyname = c_scope->pyname; + } + else + { + scope = NULL; + pyname = NULL; + } + + prcode(fp, +" {\n" + ); + + /* + * If there is no shadow class then protected methods can never be + * called. + */ + if (isProtected(od) && !hasShadow(c_scope)) + { + prcode(fp, +" /* Never reached. */\n" +" }\n" + ); + + return; + } + + /* Save the full result type as we may want to fiddle with it. */ + orig_res = *res; + + /* See if we need to make a copy of the result on the heap. */ + needsNew = copyConstRefArg(res); + + if (needsNew) + resetIsConstArg(res); + + /* See if sipRes is needed. */ + is_result = (!isInplaceNumberSlot(od->common) && + !isInplaceSequenceSlot(od->common) && + (res->atype != void_type || res->nrderefs != 0)); + + newline = FALSE; + + if (is_result) + { + prcode(fp, +" "); + + generateNamedValueType(scope, res, "sipRes", fp); + + /* + * The typical %MethodCode usually causes a compiler warning, + * so we initialise the result in that case to try and suppress + * it. + */ + if (od->methodcode != NULL) + { + prcode(fp," = "); + + generateCastZero(res,fp); + } + + prcode(fp,";\n" + ); + + newline = TRUE; + } + + result_size = -1; + deltemps = TRUE; + + for (a = 0; a < od->pysig.nrArgs; ++a) + { + argDef *ad = &od->pysig.args[a]; + + if (isResultSize(ad)) + result_size = a; + + /* + * If we have an In,Out argument that has conversion code then we delay + * the destruction of any temporary variables until after we have + * converted the outputs. + */ + if (isInArg(ad) && isOutArg(ad) && hasConvertToCode(ad) && deltemps) + { + deltemps = FALSE; + + prcode(fp, +" PyObject *sipResult;\n" + ); + + newline = TRUE; + } + + /* + * If we are returning a class via an output only reference or pointer + * then we need an instance on the heap. + */ + if (needNewInstance(ad)) + { + prcode(fp, +" a%d = new %b();\n" + ,a,ad); + + newline = TRUE; + } + } + + error_flag = old_error_flag = FALSE; + + if (od->methodcode != NULL) + { + /* See if the handwritten code seems to be using the error flag. */ + if (needErrorFlag(od->methodcode)) + { + prcode(fp, +" sipErrorState sipError = sipErrorNone;\n" + ); + + newline = TRUE; + error_flag = TRUE; + } + else if (needOldErrorFlag(od->methodcode)) + { + prcode(fp, +" int sipIsErr = 0;\n" + ); + + newline = TRUE; + old_error_flag = TRUE; + } + } + + if (newline) + prcode(fp, +"\n" + ); + + /* If it is abstract make sure that self was bound. */ + if (isAbstract(od)) + prcode(fp, +" if (!sipOrigSelf)\n" +" {\n" +" sipAbstractMethod(%N, %N);\n" +" return NULL;\n" +" }\n" +"\n" + , c_scope->pyname, od->common->pyname); + + if (isDeprecated(od)) + { + /* Note that any temporaries will leak if an exception is raised. */ + if (pyname != NULL) + prcode(fp, +" if (sipDeprecated(%N,%N) < 0)\n" + , pyname, od->common->pyname); + else + prcode(fp, +" if (sipDeprecated(NULL,%N) < 0)\n" + , od->common->pyname); + + prcode(fp, +" return %s;\n" +"\n" + , ((isVoidReturnSlot(od->common) || isIntReturnSlot(od->common) || isSSizeReturnSlot(od->common) || isLongReturnSlot(od->common)) ? "-1" : "NULL")); + } + + /* Call any pre-hook. */ + if (od->prehook != NULL) + prcode(fp, +" sipCallHook(\"%s\");\n" +"\n" + ,od->prehook); + + if (od->methodcode != NULL) + generateCppCodeBlock(od->methodcode,fp); + else + { + int rgil = ((release_gil || isReleaseGIL(od)) && !isHoldGIL(od)); + + if (needsNew && generating_c) + { + prcode(fp, +" if ((sipRes = (%b *)sipMalloc(sizeof (%b))) == NULL)\n" +" {\n" + ,res,res); + + gc_ellipsis(&od->pysig, fp); + + prcode(fp, +" return NULL;\n" +" }\n" +"\n" + ); + } + + if (rgil) + prcode(fp, +" Py_BEGIN_ALLOW_THREADS\n" + ); + + generateTry(od->exceptions,fp); + + prcode(fp, +" "); + + if (od->common->slot != cmp_slot && is_result) + { + /* Construct a copy on the heap if needed. */ + if (needsNew) + { + if (generating_c) + prcode(fp,"*sipRes = "); + else + prcode(fp,"sipRes = new %b(",res); + } + else + { + prcode(fp,"sipRes = "); + + /* See if we need the address of the result. */ + if ((res->atype == class_type || res->atype == mapped_type) && (res->nrderefs == 0 || isReference(res))) + prcode(fp,"&"); + } + } + + switch (od->common->slot) + { + case no_slot: + generateCppFunctionCall(scope, o_scope, od, fp); + break; + + case getitem_slot: + prcode(fp, "(*sipCpp)["); + generateSlotArg(&od->pysig, 0, fp); + prcode(fp,"]"); + break; + + case call_slot: + prcode(fp, "(*sipCpp)("); + generateCallArgs(od->cppsig, &od->pysig, fp); + prcode(fp,")"); + break; + + case int_slot: + case long_slot: + case float_slot: + prcode(fp, "*sipCpp"); + break; + + case add_slot: + generateNumberSlotCall(od,"+",fp); + break; + + case concat_slot: + generateBinarySlotCall(scope, od, "+", deref, fp); + break; + + case sub_slot: + generateNumberSlotCall(od,"-",fp); + break; + + case mul_slot: + generateNumberSlotCall(od,"*",fp); + break; + + case repeat_slot: + generateBinarySlotCall(scope, od, "*", deref, fp); + break; + + case div_slot: + case truediv_slot: + generateNumberSlotCall(od,"/",fp); + break; + + case mod_slot: + generateNumberSlotCall(od,"%",fp); + break; + + case and_slot: + generateNumberSlotCall(od,"&",fp); + break; + + case or_slot: + generateNumberSlotCall(od,"|",fp); + break; + + case xor_slot: + generateNumberSlotCall(od,"^",fp); + break; + + case lshift_slot: + generateNumberSlotCall(od,"<<",fp); + break; + + case rshift_slot: + generateNumberSlotCall(od,">>",fp); + break; + + case iadd_slot: + case iconcat_slot: + generateBinarySlotCall(scope, od, "+=", deref, fp); + break; + + case isub_slot: + generateBinarySlotCall(scope, od, "-=", deref, fp); + break; + + case imul_slot: + case irepeat_slot: + generateBinarySlotCall(scope, od, "*=", deref, fp); + break; + + case idiv_slot: + case itruediv_slot: + generateBinarySlotCall(scope, od, "/=", deref, fp); + break; + + case imod_slot: + generateBinarySlotCall(scope, od, "%=", deref, fp); + break; + + case iand_slot: + generateBinarySlotCall(scope, od, "&=", deref, fp); + break; + + case ior_slot: + generateBinarySlotCall(scope, od, "|=", deref, fp); + break; + + case ixor_slot: + generateBinarySlotCall(scope, od, "^=", deref, fp); + break; + + case ilshift_slot: + generateBinarySlotCall(scope, od, "<<=", deref, fp); + break; + + case irshift_slot: + generateBinarySlotCall(scope, od, ">>=", deref, fp); + break; + + case invert_slot: + prcode(fp, "~(*sipCpp)"); + break; + + case lt_slot: + generateComparisonSlotCall(scope, od, "<", ">=", deref, fp); + break; + + case le_slot: + generateComparisonSlotCall(scope, od, "<=", ">", deref, fp); + break; + + case eq_slot: + generateComparisonSlotCall(scope, od, "==", "!=", deref, fp); + break; + + case ne_slot: + generateComparisonSlotCall(scope, od, "!=", "==", deref, fp); + break; + + case gt_slot: + generateComparisonSlotCall(scope, od, ">", "<=", deref, fp); + break; + + case ge_slot: + generateComparisonSlotCall(scope, od, ">=", "<", deref, fp); + break; + + case neg_slot: + prcode(fp, "-(*sipCpp)"); + break; + + case pos_slot: + prcode(fp, "+(*sipCpp)"); + break; + + case cmp_slot: + prcode(fp,"if "); + generateBinarySlotCall(scope, od, "<", deref, fp); + prcode(fp,"\n" +" sipRes = -1;\n" +" else if "); + generateBinarySlotCall(scope, od, ">", deref, fp); + prcode(fp,"\n" +" sipRes = 1;\n" +" else\n" +" sipRes = 0"); + + break; + } + + if (needsNew && !generating_c) + prcode(fp,")"); + + prcode(fp,";\n" + ); + + generateCatch(od->exceptions, &od->pysig, mod, fp); + + if (rgil) + prcode(fp, +" Py_END_ALLOW_THREADS\n" + ); + } + + for (a = 0; a < od->pysig.nrArgs; ++a) + { + argDef *ad = &od->pysig.args[a]; + + if (!isInArg(ad)) + continue; + + /* Handle any /KeepReference/ arguments. */ + if (keepReference(ad)) + { + prcode(fp, +"\n" +" sipKeepReference(sipSelf, %d, a%d%s);\n" + , ad->key, a, (((ad->atype == ascii_string_type || ad->atype == latin1_string_type || ad->atype == utf8_string_type) && ad->nrderefs == 1) || !isGetWrapper(ad) ? "Keep" : "Wrapper")); + } + + /* Handle /TransferThis/ for non-factory methods. */ + if (!isFactory(od) && isThisTransferred(ad)) + { + prcode(fp, +"\n" +" if (sipOwner)\n" +" sipTransferTo(sipSelf, (PyObject *)sipOwner);\n" +" else\n" +" sipTransferBack(sipSelf);\n" + ); + } + } + + if (isThisTransferredMeth(od)) + prcode(fp, +"\n" +" sipTransferTo(sipSelf, NULL);\n" + ); + + gc_ellipsis(&od->pysig, fp); + + if (deltemps && !isZeroArgSlot(od->common)) + deleteTemps(&od->pysig, fp); + + prcode(fp, +"\n" + ); + + /* Handle the error flag if it was used. */ + error_value = ((isVoidReturnSlot(od->common) || isIntReturnSlot(od->common) || isSSizeReturnSlot(od->common) || isLongReturnSlot(od->common)) ? "-1" : "0"); + + if (error_flag) + { + prcode(fp, +" if (sipError == sipErrorFail)\n" +" return %s;\n" +"\n" +" if (sipError == sipErrorNone)\n" +" {\n" + , error_value); + } + else if (old_error_flag) + { + prcode(fp, +" if (sipIsErr)\n" +" return %s;\n" +"\n" + , error_value); + } + + /* Call any post-hook. */ + if (od->posthook != NULL) + prcode(fp, +"\n" +" sipCallHook(\"%s\");\n" + ,od->posthook); + + if (isVoidReturnSlot(od->common)) + prcode(fp, +" return 0;\n" + ); + else if (isInplaceNumberSlot(od->common) || isInplaceSequenceSlot(od->common)) + prcode(fp, +" Py_INCREF(sipSelf);\n" +" return sipSelf;\n" + ); + else if (isIntReturnSlot(od->common) || isSSizeReturnSlot(od->common) || isLongReturnSlot(od->common)) + prcode(fp, +" return sipRes;\n" + ); + else + { + generateHandleResult(od, needsNew, result_size, + (deltemps ? "return" : "sipResult ="), fp); + + /* Delete the temporaries now if we haven't already done so. */ + if (!deltemps) + { + deleteTemps(&od->pysig, fp); + + prcode(fp, +"\n" +" return sipResult;\n" + ); + } + } + + if (error_flag) + prcode(fp, +" }\n" +"\n" +" sipAddException(sipError, &sipParseErr);\n" + ); + + prcode(fp, +" }\n" + ); + + /* Restore the full type of the result. */ + *res = orig_res; +} + + +/* + * Generate a call to a C++ function. + */ +static void generateCppFunctionCall(ifaceFileDef *scope, + ifaceFileDef *o_scope, overDef *od, FILE *fp) +{ + char *mname = od->cppname; + int parens = 1; + + /* + * If the function is protected then call the public wrapper. If it is + * virtual then call the explicit scoped function if "self" was passed as + * the first argument. + */ + + if (scope == NULL) + prcode(fp, "%s(", mname); + else if (scope->type == namespace_iface) + prcode(fp, "%S::%s(", scope->fqcname, mname); + else if (isStatic(od)) + { + if (isProtected(od)) + prcode(fp, "sip%C::sipProtect_%s(", scope->fqcname, mname); + else + prcode(fp, "%S::%s(", o_scope->fqcname, mname); + } + else if (isProtected(od)) + { + if (!isAbstract(od) && (isVirtual(od) || isVirtualReimp(od))) + { + prcode(fp, "sipCpp->sipProtectVirt_%s(sipSelfWasArg", mname); + + if (od->cppsig->nrArgs > 0) + prcode(fp, ","); + } + else + prcode(fp, "sipCpp->sipProtect_%s(", mname); + } + else if (!isAbstract(od) && (isVirtual(od) || isVirtualReimp(od))) + { + prcode(fp, "(sipSelfWasArg ? sipCpp->%S::%s(", o_scope->fqcname, mname); + generateCallArgs(od->cppsig, &od->pysig, fp); + prcode(fp, ") : sipCpp->%s(", mname); + ++parens; + } + else + prcode(fp, "sipCpp->%s(", mname); + + generateCallArgs(od->cppsig, &od->pysig, fp); + + while (parens--) + prcode(fp, ")"); +} + + +/* + * Generate argument to a slot. + */ +static void generateSlotArg(signatureDef *sd, int argnr, FILE *fp) +{ + argDef *ad; + int deref; + + ad = &sd->args[argnr]; + deref = ((ad->atype == class_type || ad->atype == mapped_type) && ad->nrderefs == 0); + + prcode(fp, "%sa%d", (deref ? "*" : ""), argnr); +} + + +/* + * Generate the call to a comparison slot method. + */ +static void generateComparisonSlotCall(ifaceFileDef *scope, overDef *od, + const char *op, const char *cop, int deref, FILE *fp) +{ + if (isComplementary(od)) + { + op = cop; + prcode(fp, "!"); + } + + if (!isGlobal(od)) + { + const char *deref_s = (deref ? "->" : "."); + + if (isAbstract(od)) + prcode(fp, "sipCpp%soperator%s(", deref_s, op); + else + prcode(fp, "sipCpp%s%S::operator%s(", deref_s, scope->fqcname, op); + } + else if (deref) + prcode(fp, "operator%s((*sipCpp), ", op); + else + prcode(fp, "operator%s(sipCpp, ", op); + + generateSlotArg(&od->pysig, 0, fp); + prcode(fp, ")"); +} + + +/* + * Generate the call to a binary (non-number) slot method. + */ +static void generateBinarySlotCall(ifaceFileDef *scope, overDef *od, + const char *op, int deref, FILE *fp) +{ + generateComparisonSlotCall(scope, od, op, "", deref, fp); +} + + +/* + * Generate the call to a binary number slot method. + */ +static void generateNumberSlotCall(overDef *od, char *op, FILE *fp) +{ + prcode(fp, "("); + generateSlotArg(&od->pysig, 0, fp); + prcode(fp, " %s ", op); + generateSlotArg(&od->pysig, 1, fp); + prcode(fp, ")"); +} + + +/* + * Generate the argument variables for a member function/constructor/operator. + */ +static int generateArgParser(signatureDef *sd, classDef *c_scope, + mappedTypeDef *mt_scope, ctorDef *ct, overDef *od, int secCall, + FILE *fp) +{ + int a, isQtSlot, optargs, arraylenarg, sigarg, handle_self, single_arg; + int slotconarg, slotdisarg, need_owner; + ifaceFileDef *scope; + + if (mt_scope != NULL) + scope = mt_scope->iff; + else if (c_scope != NULL) + { + /* If the class is just a namespace, then ignore it. */ + if (c_scope->iff->type == namespace_iface) + { + c_scope = NULL; + scope = NULL; + } + else + scope = c_scope->iff; + } + else + scope = NULL; + + handle_self = (od != NULL && od->common->slot == no_slot && !isStatic(od) && c_scope != NULL); + + /* Assume there isn't a Qt slot. */ + isQtSlot = FALSE; + + /* + * Generate the local variables that will hold the parsed arguments and + * values returned via arguments. + */ + sigarg = -1; + need_owner = FALSE; + + for (a = 0; a < sd->nrArgs; ++a) + { + argDef *ad = &sd->args[a]; + + switch (ad->atype) + { + case signal_type: + sigarg = a; + break; + + case rxcon_type: + case rxdis_type: + isQtSlot = TRUE; + break; + + case slotcon_type: + slotconarg = a; + break; + + case slotdis_type: + slotdisarg = a; + break; + } + + if (isArraySize(ad)) + arraylenarg = a; + + generateVariable(scope, ad, a, fp); + + if (isThisTransferred(ad)) + need_owner = TRUE; + } + + if (od != NULL && need_owner) + prcode(fp, +" sipWrapper *sipOwner = 0;\n" + ); + + if (handle_self) + { + if (isProtected(od) && hasShadow(c_scope)) + prcode(fp, +" sip%C *sipCpp;\n" + , classFQCName(c_scope)); + else + prcode(fp, +" %U *sipCpp;\n" + , c_scope); + + prcode(fp, +"\n" + ); + } + else if (sd->nrArgs != 0) + prcode(fp, +"\n" + ); + + /* Generate the call to the parser function. */ + single_arg = FALSE; + + if (od != NULL && isNumberSlot(od->common)) + { + prcode(fp, +" if (sipParsePair(%ssipParseErr, sipArg0, sipArg1, \"", (ct != NULL ? "" : "&")); + } + else if ((od != NULL && useKeywordArgsFunction(od->common)) || ct != NULL) + { + int this_uses_kwds; + + /* + * We handle keywords if we might have been passed some (because one of + * the overloads uses them or we are a ctor). However this particular + * overload might not have any. + */ + this_uses_kwds = ((od != NULL && useKeywordArgs(od)) || (ct != NULL && useKeywordArgsCtor(ct))); + + if (this_uses_kwds) + { + int a; + + prcode(fp, +" static const char *sipKwdList[] = {\n" + ); + + for (a = 0; a < sd->nrArgs; ++a) + { + nameDef *nd = sd->args[a].name; + + if (nd != NULL) + prcode(fp, +" %N,\n" + , nd); + else + prcode(fp, +" NULL,\n" + ); + } + + prcode(fp, + " };\n" + "\n" + ); + } + + prcode(fp, +" if (sipParseKwdArgs(%ssipParseErr, sipArgs, sipKwds, %s, %s, \"", (ct != NULL ? "" : "&"), (this_uses_kwds ? "sipKwdList" : "NULL"), (ct != NULL ? "sipUnused" : "NULL")); + } + else + { + single_arg = (od != NULL && od->common->slot != no_slot && !isMultiArgSlot(od->common)); + + prcode(fp, +" if (sipParseArgs(%ssipParseErr, sipArg%s, \"", (ct != NULL ? "" : "&"), (single_arg ? "" : "s")); + } + + /* Generate the format string. */ + optargs = FALSE; + + if (single_arg) + prcode(fp, "1"); + + if (handle_self) + prcode(fp,"%c",(isReallyProtected(od) ? 'p' : 'B')); + else if (isQtSlot && od == NULL) + prcode(fp,"C"); + + for (a = 0; a < sd->nrArgs; ++a) + { + char *fmt = ""; + argDef *ad = &sd->args[a]; + + if (!isInArg(ad)) + continue; + + if (ad->defval != NULL && !optargs) + { + prcode(fp,"|"); + optargs = TRUE; + } + + switch (ad->atype) + { + case ascii_string_type: + if (ad->nrderefs == 0 || (isOutArg(ad) && ad->nrderefs == 1)) + fmt = "aA"; + else + fmt = "AA"; + + break; + + case latin1_string_type: + if (ad->nrderefs == 0 || (isOutArg(ad) && ad->nrderefs == 1)) + fmt = "aL"; + else + fmt = "AL"; + + break; + + case utf8_string_type: + if (ad->nrderefs == 0 || (isOutArg(ad) && ad->nrderefs == 1)) + fmt = "a8"; + else + fmt = "A8"; + + break; + + case sstring_type: + case ustring_type: + case string_type: + if (ad->nrderefs == 0 || (isOutArg(ad) && ad->nrderefs == 1)) + fmt = "c"; + else if (isArray(ad)) + fmt = "k"; + else + fmt = "s"; + + break; + + case wstring_type: + if (ad->nrderefs == 0 || (isOutArg(ad) && ad->nrderefs == 1)) + fmt = "w"; + else if (isArray(ad)) + fmt = "K"; + else + fmt = "x"; + + break; + + case enum_type: + if (ad->u.ed->fqcname == NULL) + fmt = "e"; + else if (isConstrained(ad)) + fmt = "XE"; + else + fmt = "E"; + break; + + case bool_type: + fmt = "b"; + break; + + case cbool_type: + fmt = "Xb"; + break; + + case int_type: + if (!isArraySize(ad)) + fmt = "i"; + + break; + + case uint_type: + if (!isArraySize(ad)) + fmt = "u"; + + break; + + case cint_type: + fmt = "Xi"; + break; + + case short_type: + if (!isArraySize(ad)) + fmt = "h"; + + break; + + case ushort_type: + if (!isArraySize(ad)) + fmt = "t"; + + break; + + case long_type: + if (!isArraySize(ad)) + fmt = "l"; + + break; + + case ulong_type: + if (!isArraySize(ad)) + fmt = "m"; + + break; + + case longlong_type: + if (!isArraySize(ad)) + fmt = "n"; + + break; + + case ulonglong_type: + if (!isArraySize(ad)) + fmt = "o"; + + break; + + case struct_type: + case void_type: + fmt = "v"; + break; + + case float_type: + fmt = "f"; + break; + + case cfloat_type: + fmt = "Xf"; + break; + + case double_type: + fmt = "d"; + break; + + case cdouble_type: + fmt = "Xd"; + break; + + case signal_type: + fmt = "G"; + break; + + case slot_type: + fmt = "S"; + break; + + case anyslot_type: + fmt = "U"; + break; + + case slotcon_type: + case slotdis_type: + fmt = (secCall ? "" : "S"); + break; + + case rxcon_type: + fmt = (secCall ? (isSingleShot(ad) ? "g" : "y") : "q"); + break; + + case rxdis_type: + fmt = (secCall ? "Y" : "Q"); + break; + + case mapped_type: + case class_type: + if (isArray(ad)) + { + if (ad->nrderefs != 1 || !isInArg(ad) || isReference(ad)) + fatal("Mapped type or class with /Array/ is not a pointer\n"); + + if (ad->atype == mapped_type && noRelease(ad->u.mtd)) + fatal("Mapped type does not support /Array/\n"); + + if (ad->atype == class_type && !(generating_c || assignmentHelper(ad->u.cd))) + { + fatalScopedName(classFQCName(ad->u.cd)); + fatal(" does not support /Array/\n"); + } + + fmt = "r"; + } + else + { + fmt = getSubFormatChar('J', ad); + } + + break; + + case pyobject_type: + fmt = getSubFormatChar('P',ad); + break; + + case pytuple_type: + case pylist_type: + case pydict_type: + case pyslice_type: + case pytype_type: + fmt = (isAllowNone(ad) ? "N" : "T"); + break; + + case pycallable_type: + fmt = (isAllowNone(ad) ? "H" : "F"); + break; + + case qobject_type: + fmt = "R"; + break; + + case ellipsis_type: + fmt = "W"; + break; + } + + /* + * Get the wrapper if explicitly asked for or we are going to keep a + * reference to. However if it is an encoded string then we will get + * the actual wrapper from the format character. + */ + if (isGetWrapper(ad) || (keepReference(ad) && ad->atype != ascii_string_type && ad->atype != latin1_string_type && ad->atype != utf8_string_type) || (keepReference(ad) && ad->nrderefs != 1)) + prcode(fp, "@"); + + prcode(fp,fmt); + } + + prcode(fp,"\""); + + /* Generate the parameters corresponding to the format string. */ + + if (handle_self) + prcode(fp,", &sipSelf, sipType_%C, &sipCpp",classFQCName(c_scope)); + else if (isQtSlot && od == NULL) + prcode(fp,", sipSelf"); + + for (a = 0; a < sd->nrArgs; ++a) + { + argDef *ad = &sd->args[a]; + + if (!isInArg(ad)) + continue; + + /* Use the wrapper name if it was explicitly asked for. */ + if (isGetWrapper(ad)) + prcode(fp, ", &a%dWrapper", a); + else if (keepReference(ad)) + prcode(fp, ", &a%dKeep", a); + + switch (ad->atype) + { + case mapped_type: + prcode(fp, ", sipType_%T,&a%d", ad, a); + + if (isArray(ad)) + { + prcode(fp,", &a%d",arraylenarg); + } + else if (!isConstrained(ad)) + { + if (noRelease(ad->u.mtd)) + prcode(fp, ",NULL"); + else + prcode(fp, ", &a%dState", a); + } + + break; + + case class_type: + prcode(fp, ", sipType_%T, &a%d", ad, a); + + if (isArray(ad)) + { + prcode(fp,", &a%d",arraylenarg); + } + else + { + if (isThisTransferred(ad)) + prcode(fp, ", %ssipOwner", (ct != NULL ? "" : "&")); + + if (ad->u.cd->convtocode != NULL && !isConstrained(ad)) + prcode(fp, ", &a%dState", a); + } + + break; + + case ascii_string_type: + if (!keepReference(ad) && ad->nrderefs == 1) + prcode(fp, ", &a%dKeep", a); + + prcode(fp, ", &a%d", a); + break; + + case latin1_string_type: + if (!keepReference(ad) && ad->nrderefs == 1) + prcode(fp, ", &a%dKeep", a); + + prcode(fp, ", &a%d", a); + break; + + case utf8_string_type: + if (!keepReference(ad) && ad->nrderefs == 1) + prcode(fp, ", &a%dKeep", a); + + prcode(fp, ", &a%d", a); + break; + + case rxcon_type: + { + if (sigarg > 0) + prcode(fp,", a%d",sigarg); + else + { + prcode(fp,", \"("); + + generateCalledArgs(scope, sd->args[slotconarg].u.sa, Declaration, TRUE, fp); + + prcode(fp,")\""); + } + + prcode(fp,", &a%d, &a%d",a,slotconarg); + + break; + } + + case rxdis_type: + { + prcode(fp,", \"("); + + generateCalledArgs(scope, sd->args[slotdisarg].u.sa, Declaration, TRUE, fp); + + prcode(fp,")\", &a%d, &a%d",a,slotdisarg); + + break; + } + + case slotcon_type: + case slotdis_type: + if (!secCall) + prcode(fp,", &a%d",a); + + break; + + case anyslot_type: + prcode(fp, ", &a%dName, &a%dCallable", a, a); + break; + + case pytuple_type: + prcode(fp,", &PyTuple_Type, &a%d",a); + break; + + case pylist_type: + prcode(fp,", &PyList_Type, &a%d",a); + break; + + case pydict_type: + prcode(fp,", &PyDict_Type, &a%d",a); + break; + + case pyslice_type: + prcode(fp,", &PySlice_Type, &a%d",a); + break; + + case pytype_type: + prcode(fp,", &PyType_Type, &a%d",a); + break; + + case enum_type: + if (ad->u.ed->fqcname != NULL) + prcode(fp, ", sipType_%C", ad->u.ed->fqcname); + + prcode(fp,", &a%d",a); + break; + + default: + if (!isArraySize(ad)) + prcode(fp,", &a%d",a); + + if (isArray(ad)) + prcode(fp,", &a%d",arraylenarg); + } + } + + prcode(fp,"))\n"); + + return isQtSlot; +} + + +/* + * Get the format character string for something that has sub-formats. + */ + +static char *getSubFormatChar(char fc, argDef *ad) +{ + static char fmt[3]; + char flags; + + flags = 0; + + if (isTransferred(ad)) + flags |= 0x02; + + if (isTransferredBack(ad)) + flags |= 0x04; + + if (ad->atype == class_type || ad->atype == mapped_type) + { + if (ad->nrderefs == 0) + flags |= 0x01; + + if (isThisTransferred(ad)) + flags |= 0x10; + + if (isConstrained(ad) || (ad->atype == class_type && ad->u.cd->convtocode == NULL)) + flags |= 0x08; + } + + fmt[0] = fc; + fmt[1] = '0' + flags; + fmt[2] = '\0'; + + return fmt; +} + + +/* + * Return TRUE if a type has %ConvertToTypeCode. + */ +static int hasConvertToCode(argDef *ad) +{ + codeBlock *convtocode; + + if (ad->atype == class_type && !isConstrained(ad)) + convtocode = ad->u.cd->convtocode; + else if (ad->atype == mapped_type && !isConstrained(ad)) + convtocode = ad->u.mtd->convtocode; + else + convtocode = NULL; + + return (convtocode != NULL); +} + + +/* + * Garbage collect any ellipsis argument. + */ +static void gc_ellipsis(signatureDef *sd, FILE *fp) +{ + if (sd->nrArgs > 0 && sd->args[sd->nrArgs - 1].atype == ellipsis_type) + prcode(fp, +"\n" +" Py_DECREF(a%d);\n" + , sd->nrArgs - 1); +} + + +/* + * Delete any instances created to hold /Out/ arguments. + */ +static void deleteOuts(signatureDef *sd, FILE *fp) +{ + int a; + + for (a = 0; a < sd->nrArgs; ++a) + { + argDef *ad = &sd->args[a]; + + if (needNewInstance(ad)) + prcode(fp, +" delete a%d;\n" + , a); + } +} + + + +/* + * Delete any temporary variables on the heap created by type convertors. + */ +static void deleteTemps(signatureDef *sd, FILE *fp) +{ + int a; + + for (a = 0; a < sd->nrArgs; ++a) + { + argDef *ad = &sd->args[a]; + + if (isArray(ad) && (ad->atype == mapped_type || ad->atype == class_type)) + { + if (generating_c) + prcode(fp, +" sipFree(a%d);\n" + , a); + else + prcode(fp, +" delete[] a%d;\n" + , a); + + continue; + } + + if (!isInArg(ad)) + continue; + + if ((ad->atype == ascii_string_type || ad->atype == latin1_string_type || ad->atype == utf8_string_type) && ad->nrderefs == 1) + { + prcode(fp, +" Py_%sDECREF(a%dKeep);\n" + , (ad->defval != NULL ? "X" : ""), a); + } + else if (ad->atype == wstring_type && ad->nrderefs == 1) + { + if (generating_c || !isConstArg(ad)) + prcode(fp, +" sipFree(a%d);\n" + , a); + else + prcode(fp, +" sipFree(const_cast<wchar_t *>(a%d));\n" + , a); + } + else if (hasConvertToCode(ad)) + { + if (ad->atype == mapped_type && noRelease(ad->u.mtd)) + continue; + + if (generating_c || !isConstArg(ad)) + prcode(fp, +" sipReleaseType(a%d,sipType_%T,a%dState);\n" + , a, ad, a); + else + prcode(fp, +" sipReleaseType(const_cast<%b *>(a%d),sipType_%T,a%dState);\n" + , ad, a, ad, a); + } + } +} + + +/* + * Generate a C++ code block. + */ +static void generateCppCodeBlock(codeBlock *code, FILE *fp) +{ + int reset_line = FALSE; + codeBlock *cb; + + for (cb = code; cb != NULL; cb = cb->next) + { + const char *cp; + + /* + * Fragmented fragments (possibly created when applying template types) + * don't have a filename. + */ + if ((cp = cb->filename) != NULL) + { + reset_line = TRUE; + + prcode(fp, +"#line %d \"", cb->linenr); + + while (*cp != '\0') + { + prcode(fp, "%c", *cp); + + if (*cp == '\\') + prcode(fp, "\\"); + + ++cp; + } + + prcode(fp, "\"\n" + ); + } + + prcode(fp, "%s", cb->frag); + } + + if (reset_line) + { + const char *bn; + + /* Just use the base name. */ + if ((bn = strrchr(currentFileName, '/')) != NULL) + ++bn; + else + bn = currentFileName; + + prcode(fp, +"#line %d \"%s\"\n" + , currentLineNr + 1, bn); + } +} + + +/* + * Create a source file. + */ +static FILE *createCompilationUnit(moduleDef *mod, const char *fname, + const char *description) +{ + FILE *fp = createFile(mod, fname, description); + + if (fp != NULL) + generateCppCodeBlock(mod->unitcode, fp); + + return fp; +} + + +/* + * Create a file with an optional standard header. + */ +static FILE *createFile(moduleDef *mod, const char *fname, + const char *description) +{ + FILE *fp; + + /* Create the file. */ + if ((fp = fopen(fname, "w")) == NULL) + fatal("Unable to create file \"%s\"\n",fname); + + /* The "stack" doesn't have to be very deep. */ + previousLineNr = currentLineNr; + currentLineNr = 1; + previousFileName = currentFileName; + currentFileName = fname; + + if (description != NULL) + { + int needComment; + codeBlock *cb; + time_t now; + + /* Write the header. */ + now = time(NULL); + + prcode(fp, +"/*\n" +" * %s\n" +" *\n" +" * Generated by SIP %s on %s" + ,description + ,sipVersion,ctime(&now)); + + if (mod->copying != NULL) + prcode(fp, +" *\n" + ); + + needComment = TRUE; + + for (cb = mod->copying; cb != NULL; cb = cb->next) + { + const char *cp; + + for (cp = cb->frag; *cp != '\0'; ++cp) + { + if (needComment) + { + needComment = FALSE; + prcode(fp," * "); + } + + prcode(fp,"%c",*cp); + + if (*cp == '\n') + needComment = TRUE; + } + } + + prcode(fp, +" */\n" + ); + } + + return fp; +} + + +/* + * Close a file and report any errors. + */ +static void closeFile(FILE *fp) +{ + if (ferror(fp)) + fatal("Error writing to \"%s\"\n",currentFileName); + + if (fclose(fp)) + fatal("Error closing \"%s\"\n",currentFileName); + + currentLineNr = previousLineNr; + currentFileName = previousFileName; +} + + +/* + * Print formatted code. + */ +void prcode(FILE *fp, const char *fmt, ...) +{ + char ch; + va_list ap; + + prcode_last = fmt; + + va_start(ap,fmt); + + while ((ch = *fmt++) != '\0') + if (ch == '%') + { + ch = *fmt++; + + switch (ch) + { + case 'c': + { + char c = (char)va_arg(ap,int); + + if (c == '\n') + ++currentLineNr; + + fputc(c,fp); + break; + } + + case 's': + { + const char *cp = va_arg(ap,const char *); + + while (*cp != '\0') + { + if (*cp == '\n') + ++currentLineNr; + + fputc(*cp,fp); + ++cp; + } + + break; + } + + case 'l': + fprintf(fp,"%ld",va_arg(ap,long)); + break; + + case 'u': + fprintf(fp,"%u",va_arg(ap,unsigned)); + break; + + case 'd': + fprintf(fp,"%d",va_arg(ap,int)); + break; + + case 'g': + fprintf(fp,"%g",va_arg(ap,double)); + break; + + case 'x': + fprintf(fp,"0x%08x",va_arg(ap,unsigned)); + break; + + case '\0': + fputc('%',fp); + --fmt; + break; + + case '\n': + fputc('\n',fp); + ++currentLineNr; + break; + + case 'b': + { + argDef *ad, orig; + + ad = va_arg(ap,argDef *); + orig = *ad; + + resetIsConstArg(ad); + resetIsReference(ad); + ad->nrderefs = 0; + + generateBaseType(NULL, ad, TRUE, fp); + + *ad = orig; + + break; + } + + case 'M': + prcode_xml = !prcode_xml; + break; + + case 'A': + { + ifaceFileDef *scope = va_arg(ap, ifaceFileDef *); + argDef *ad = va_arg(ap, argDef *); + + generateBaseType(scope, ad, TRUE, fp); + break; + } + + case 'B': + generateBaseType(NULL, va_arg(ap,argDef *),TRUE, fp); + break; + + case 'T': + prTypeName(fp, va_arg(ap,argDef *)); + break; + + case 'I': + { + int indent = va_arg(ap,int); + + while (indent-- > 0) + fputc('\t',fp); + + break; + } + + case 'N': + { + nameDef *nd = va_arg(ap,nameDef *); + + prCachedName(fp, nd, "sipName_"); + break; + } + + case 'n': + { + nameDef *nd = va_arg(ap,nameDef *); + + prCachedName(fp, nd, "sipNameNr_"); + break; + } + + case 'E': + { + enumDef *ed = va_arg(ap,enumDef *); + + if (ed->fqcname == NULL || isProtectedEnum(ed)) + fprintf(fp,"int"); + else + prScopedName(fp,ed->fqcname,"::"); + + break; + } + + case 'F': + prScopedName(fp,va_arg(ap,scopedNameDef *),""); + break; + + case 'C': + prScopedName(fp,va_arg(ap,scopedNameDef *),"_"); + break; + + case 'L': + { + ifaceFileDef *iff = va_arg(ap, ifaceFileDef *); + + prScopedName(fp, iff->fqcname, "_"); + + if (iff->api_range != NULL) + fprintf(fp, "_%d", iff->api_range->index); + + break; + } + + case 'P': + { + apiVersionRangeDef *avr = va_arg(ap, apiVersionRangeDef *); + + fprintf(fp, "%d", (avr != NULL ? avr->index : -1)); + + break; + } + + case 'S': + if (generating_c) + fprintf(fp,"struct "); + + prScopedName(fp,va_arg(ap,scopedNameDef *),"::"); + break; + + case 'U': + { + classDef *cd = va_arg(ap, classDef *); + + if (generating_c) + fprintf(fp,"struct "); + + prScopedClassName(fp, cd->iff, cd); + break; + } + + case 'V': + { + ifaceFileDef *scope = va_arg(ap, ifaceFileDef *); + classDef *cd = va_arg(ap, classDef *); + + if (generating_c) + fprintf(fp,"struct "); + + prScopedClassName(fp, scope, cd); + break; + } + + case 'O': + prOverloadName(fp, va_arg(ap, overDef *)); + break; + + case 'X': + generateThrowSpecifier(va_arg(ap,throwArgs *),fp); + break; + + default: + fputc(ch,fp); + } + } + else if (ch == '\n') + { + fputc('\n',fp); + ++currentLineNr; + } + else + fputc(ch,fp); + + va_end(ap); +} + + +/* + * Generate the symbolic name of a cached name. + */ +static void prCachedName(FILE *fp, nameDef *nd, const char *prefix) +{ + prcode(fp, "%s", prefix); + + /* + * If the name seems to be a template then just use the offset to ensure + * that it is unique. + */ + if (strchr(nd->text, '<') != NULL) + prcode(fp, "%d", nd->offset); + else + { + const char *cp; + + /* Handle C++ and Python scopes. */ + for (cp = nd->text; *cp != '\0'; ++cp) + { + char ch = *cp; + + if (ch == ':' || ch == '.') + ch = '_'; + + prcode(fp, "%c", ch); + } + } +} + + +/* + * Generate the C++ name of an overloaded function. + */ +void prOverloadName(FILE *fp, overDef *od) +{ + char *pt1, *pt2; + + pt1 = "operator"; + + switch (od->common->slot) + { + case add_slot: + pt2 = "+"; + break; + + case sub_slot: + pt2 = "-"; + break; + + case mul_slot: + pt2 = "*"; + break; + + case div_slot: + case truediv_slot: + pt2 = "/"; + break; + + case mod_slot: + pt2 = "%"; + break; + + case and_slot: + pt2 = "&"; + break; + + case or_slot: + pt2 = "|"; + break; + + case xor_slot: + pt2 = "^"; + break; + + case lshift_slot: + pt2 = "<<"; + break; + + case rshift_slot: + pt2 = ">>"; + break; + + case iadd_slot: + pt2 = "+="; + break; + + case isub_slot: + pt2 = "-="; + break; + + case imul_slot: + pt2 = "*="; + break; + + case idiv_slot: + case itruediv_slot: + pt2 = "/="; + break; + + case imod_slot: + pt2 = "%="; + break; + + case iand_slot: + pt2 = "&="; + break; + + case ior_slot: + pt2 = "|="; + break; + + case ixor_slot: + pt2 = "^="; + break; + + case ilshift_slot: + pt2 = "<<="; + break; + + case irshift_slot: + pt2 = ">>="; + break; + + case invert_slot: + pt2 = "~"; + break; + + case call_slot: + pt2 = "()"; + break; + + case getitem_slot: + pt2 = "[]"; + break; + + case lt_slot: + pt2 = "<"; + break; + + case le_slot: + pt2 = "<="; + break; + + case eq_slot: + pt2 = "=="; + break; + + case ne_slot: + pt2 = "!="; + break; + + case gt_slot: + pt2 = ">"; + break; + + case ge_slot: + pt2 = ">="; + break; + + default: + pt1 = ""; + pt2 = od->cppname; + } + + fprintf(fp, "%s%s", pt1, pt2); +} + + +/* + * Generate a scoped name with the given separator string. + */ +static void prScopedName(FILE *fp,scopedNameDef *snd,char *sep) +{ + while (snd != NULL) + { + fprintf(fp,"%s",snd->name); + + if ((snd = snd->next) != NULL) + fprintf(fp,"%s",sep); + } +} + + +/* + * Generate a scoped class name. + */ +static void prScopedClassName(FILE *fp, ifaceFileDef *scope, classDef *cd) +{ + /* Protected classes have to be explicitly scoped. */ + if (isProtectedClass(cd)) + { + /* This should never happen. */ + if (scope == NULL) + scope = cd->iff; + + prcode(fp, "sip%C::sip%s", scope->fqcname, classBaseName(cd)); + } + else + { + scopedNameDef *snd = classFQCName(cd); + + while (snd != NULL) + { + fprintf(fp,"%s",snd->name); + + if ((snd = snd->next) != NULL) + fprintf(fp, "::"); + } + } +} + + +/* + * Generate a type name to be used as part of an identifier name. + */ +static void prTypeName(FILE *fp, argDef *ad) +{ + scopedNameDef *snd; + + switch (ad->atype) + { + case struct_type: + snd = ad->u.sname; + break; + + case defined_type: + snd = ad->u.snd; + break; + + case enum_type: + snd = ad->u.ed->fqcname; + break; + + case mapped_type: + snd = ad->u.mtd->iff->fqcname; + break; + + case class_type: + snd = classFQCName(ad->u.cd); + break; + + default: + /* This should never happen. */ + snd = NULL; + } + + if (snd != NULL) + prcode(fp, "%C", snd); +} + + +/* + * Return TRUE if handwritten code uses the error flag. + */ +static int needErrorFlag(codeBlock *cb) +{ + return usedInCode(cb, "sipError"); +} + + +/* + * Return TRUE if handwritten code uses the deprecated error flag. + */ +static int needOldErrorFlag(codeBlock *cb) +{ + return usedInCode(cb, "sipIsErr"); +} + + +/* + * Return TRUE if the argument type means an instance needs to be created on + * the heap to pass back to Python. + */ +static int needNewInstance(argDef *ad) +{ + return ((ad->atype == mapped_type || ad->atype == class_type) && + ((isReference(ad) && ad->nrderefs == 0) || (!isReference(ad) && ad->nrderefs == 1)) && + !isInArg(ad) && isOutArg(ad)); +} + + +/* + * Convert any protected arguments (ie. those whose type is unavailable outside + * of a shadow class) to a fundamental type to be used instead (with suitable + * casts). + */ +static void fakeProtectedArgs(signatureDef *sd) +{ + int a; + argDef *ad = sd->args; + + for (a = 0; a < sd->nrArgs; ++a) + { + if (ad->atype == class_type && isProtectedClass(ad->u.cd)) + { + ad->atype = fake_void_type; + ad->nrderefs = 1; + resetIsReference(ad); + } + else if (ad->atype == enum_type && isProtectedEnum(ad->u.ed)) + ad->atype = int_type; + + ++ad; + } +} + + +/* + * Reset and save any argument flags so that the signature will be rendered + * exactly as defined in C++. + */ +static void normaliseArgs(signatureDef *sd) +{ + int a; + argDef *ad = sd->args; + + for (a = 0; a < sd->nrArgs; ++a) + { + if (ad->atype == class_type && isProtectedClass(ad->u.cd)) + { + resetIsProtectedClass(ad->u.cd); + setWasProtectedClass(ad->u.cd); + } + else if (ad->atype == enum_type && isProtectedEnum(ad->u.ed)) + { + resetIsProtectedEnum(ad->u.ed); + setWasProtectedEnum(ad->u.ed); + } + + ++ad; + } +} + + +/* + * Restore any argument flags modified by normaliseArgs(). + */ +static void restoreArgs(signatureDef *sd) +{ + int a; + argDef *ad = sd->args; + + for (a = 0; a < sd->nrArgs; ++a) + { + if (ad->atype == class_type && wasProtectedClass(ad->u.cd)) + { + resetWasProtectedClass(ad->u.cd); + setIsProtectedClass(ad->u.cd); + } + else if (ad->atype == enum_type && wasProtectedEnum(ad->u.ed)) + { + resetWasProtectedEnum(ad->u.ed); + setIsProtectedEnum(ad->u.ed); + } + + ++ad; + } +} + + +/* + * Return TRUE if a dealloc function is needed for a class. + */ +static int needDealloc(classDef *cd) +{ + if (cd->iff->type == namespace_iface) + return FALSE; + + /* All of these conditions cause some code to be generated. */ + + if (tracing) + return TRUE; + + if (generating_c) + return TRUE; + + if (cd->dealloccode != NULL) + return TRUE; + + if (isPublicDtor(cd)) + return TRUE; + + if (hasShadow(cd)) + return TRUE; + + return FALSE; +} + + +/* + * Return the argument name to use in a function definition for handwritten + * code. + */ +static const char *argName(const char *name, codeBlock *cb) +{ + static const char noname[] = ""; + + /* Always use the name in C code. */ + if (generating_c) + return name; + + /* Use the name if it is used in the handwritten code. */ + if (usedInCode(cb, name)) + return name; + + /* Don't use the name and avoid a compiler warning. */ + return noname; +} + + +/* + * Returns TRUE if a string is used in a code block. + */ +static int usedInCode(codeBlock *code, const char *str) +{ + while (code != NULL) + { + if (strstr(code->frag, str) != NULL) + return TRUE; + + code = code->next; + } + + return FALSE; +} + + +/* + * Generate an assignment statement from a void * variable to a class instance + * variable. + */ +static void generateClassFromVoid(classDef *cd, const char *cname, + const char *vname, FILE *fp) +{ + if (generating_c) + prcode(fp, "%S *%s = (%S *)%s", classFQCName(cd), cname, classFQCName(cd), vname); + else + prcode(fp, "%S *%s = reinterpret_cast<%S *>(%s)", classFQCName(cd), cname, classFQCName(cd), vname); +} + + +/* + * Generate an assignment statement from a void * variable to a mapped type + * variable. + */ +static void generateMappedTypeFromVoid(mappedTypeDef *mtd, const char *cname, + const char *vname, FILE *fp) +{ + if (generating_c) + prcode(fp, "%b *%s = (%b *)%s", &mtd->type, cname, &mtd->type, vname); + else + prcode(fp, "%b *%s = reinterpret_cast<%b *>(%s)", &mtd->type, cname, &mtd->type, vname); +} + + +/* + * Returns TRUE if the argument has a type that requires an extra reference to + * the originating object to be kept. + */ +static int keepPyReference(argDef *ad) +{ + if (ad->atype == ascii_string_type || ad->atype == latin1_string_type || + ad->atype == utf8_string_type || ad->atype == ustring_type || + ad->atype == sstring_type || ad->atype == string_type) + { + if (!isReference(ad) && ad->nrderefs > 0) + return TRUE; + } + + return FALSE; +} + + +/* + * Return the encoding character for the given type. + */ +static char getEncoding(argType atype) +{ + char encoding; + + switch (atype) + { + case ascii_string_type: + encoding = 'A'; + break; + + case latin1_string_type: + encoding = 'L'; + break; + + case utf8_string_type: + encoding = '8'; + break; + + default: + encoding = 'N'; + } + + return encoding; +} + + +/* + * Return TRUE if a docstring can be automatically generated for a function + * overload. + */ +static int overloadHasDocstring(sipSpec *pt, overDef *od, memberDef *md) +{ + if (isPrivate(od) || isSignal(od)) + return FALSE; + + if (od->common != md) + return FALSE; + + /* If it is versioned then make sure it is the default API. */ + return isDefaultAPI(pt, od->api_range); +} + + +/* + * Return TRUE if a docstring can be automatically generated for a function. + */ +static int hasDocstring(sipSpec *pt, overDef *overs, memberDef *md, + ifaceFileDef *scope) +{ + overDef *od; + + if (noArgParser(md)) + return FALSE; + + if (scope != NULL && !isDefaultAPI(pt, scope->api_range)) + return FALSE; + + for (od = overs; od != NULL; od = od->next) + if (overloadHasDocstring(pt, od, md)) + return TRUE; + + return FALSE; +} + + +/* + * Generate the docstring for a function or method. + */ +static void generateDocstring(sipSpec *pt, overDef *overs, memberDef *md, + const char *scope_name, classDef *scope_scope, FILE *fp) +{ + const char *sep = NULL; + overDef *od; + + for (od = overs; od != NULL; od = od->next) + { + int need_sec; + + if (!overloadHasDocstring(pt, od, md)) + continue; + + if (sep == NULL) + { + fprintf(fp, "\""); + sep = "\\n\"\n \""; + } + else + { + fprintf(fp, "%s", sep); + } + + prScopedPythonName(fp, scope_scope, scope_name); + + if (scope_name != NULL) + fprintf(fp, "."); + + fprintf(fp, "%s", md->pyname->text); + need_sec = prPythonSignature(pt, fp, &od->pysig, FALSE, TRUE, TRUE, + TRUE, FALSE); + ++currentLineNr; + + if (need_sec) + { + fprintf(fp, "%s", sep); + + prScopedPythonName(fp, scope_scope, scope_name); + + if (scope_name != NULL) + fprintf(fp, "."); + + fprintf(fp, "%s", md->pyname->text); + prPythonSignature(pt, fp, &od->pysig, TRUE, TRUE, TRUE, TRUE, + FALSE); + ++currentLineNr; + } + } + + if (sep != NULL) + fprintf(fp, "\""); +} + + +/* + * Return TRUE if a docstring can be automatically generated for a class + * overload. + */ +static int overloadHasClassDocstring(sipSpec *pt, ctorDef *ct) +{ + if (isPrivateCtor(ct)) + return FALSE; + + /* If it is versioned then make sure it is the default API. */ + return isDefaultAPI(pt, ct->api_range); +} + + +/* + * Return TRUE if a docstring can be automatically generated for a class. + */ +static int hasClassDocstring(sipSpec *pt, classDef *cd) +{ + ctorDef *ct; + + if (!canCreate(cd)) + return FALSE; + + if (!isDefaultAPI(pt, cd->iff->api_range)) + return FALSE; + + for (ct = cd->ctors; ct != NULL; ct = ct->next) + if (overloadHasClassDocstring(pt, ct)) + return TRUE; + + return FALSE; +} + + +/* + * Generate the docstring for a class. + */ +static void generateClassDocstring(sipSpec *pt, classDef *cd, FILE *fp) +{ + const char *sep = NULL; + ctorDef *ct; + + for (ct = cd->ctors; ct != NULL; ct = ct->next) + { + int need_sec; + + if (!overloadHasClassDocstring(pt, ct)) + continue; + + if (sep == NULL) + { + fprintf(fp, "\"\\1"); + sep = "\\n\"\n \""; + } + else + { + fprintf(fp, "%s", sep); + } + + prScopedPythonName(fp, cd->ecd, cd->pyname->text); + need_sec = prPythonSignature(pt, fp, &ct->pysig, FALSE, TRUE, TRUE, + TRUE, FALSE); + ++currentLineNr; + + if (need_sec) + { + fprintf(fp, "%s", sep); + + prScopedPythonName(fp, cd->ecd, cd->pyname->text); + prPythonSignature(pt, fp, &ct->pysig, TRUE, TRUE, TRUE, TRUE, + FALSE); + ++currentLineNr; + } + } + + if (sep != NULL) + fprintf(fp, "\""); +} + + +/* + * Returns TRUE if the given API version corresponds to the default. + */ +static int isDefaultAPI(sipSpec *pt, apiVersionRangeDef *avd) +{ + int def_api; + + /* Handle the trivial case. */ + if (avd == NULL) + return TRUE; + + def_api = findAPI(pt, avd->api_name->text)->from; + + if (avd->from > 0 && avd->from > def_api) + return FALSE; + + if (avd->to > 0 && avd->to <= def_api) + return FALSE; + + return TRUE; +} + + +/* + * Generate an explicit docstring. + */ +static void generateExplicitDocstring(codeBlock *docstring, FILE *fp) +{ + const char *sep = NULL; + codeBlock *cb; + + for (cb = docstring; cb != NULL; cb = cb->next) + { + const char *cp; + + if (sep == NULL) + { + prcode(fp, "\""); + sep = "\\n\"\n \""; + } + else + { + prcode(fp, "%s", sep); + } + + for (cp = cb->frag; *cp != '\0'; ++cp) + { + if (*cp == '\n') + { + /* Ignore if this is the last character of the fragment. */ + if (cp[1] != '\0') + prcode(fp, "%s", sep); + } + else + { + if (*cp == '\\' || *cp == '\"') + prcode(fp, "\\"); + + prcode(fp, "%c", *cp); + } + } + } + + if (sep != NULL) + prcode(fp, "\""); +} diff --git a/sipgen/heap.c b/sipgen/heap.c new file mode 100644 index 0000000..a4b42ba --- /dev/null +++ b/sipgen/heap.c @@ -0,0 +1,131 @@ +/* + * Wrappers around standard functions that use the heap. + * + * Copyright (c) 2010 Riverbank Computing Limited <info@riverbankcomputing.com> + * + * This file is part of SIP. + * + * This copy of SIP is licensed for use under the terms of the SIP License + * Agreement. See the file LICENSE for more details. + * + * This copy of SIP may also used under the terms of the GNU General Public + * License v2 or v3 as published by the Free Software Foundation which can be + * found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package. + * + * SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + + +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <sys/types.h> + +#include "sip.h" + + +static void nomem(void); + + +/* + * Wrap malloc() and handle any errors. + */ +void *sipMalloc(size_t n) +{ + void *h; + + if ((h = malloc(n)) == NULL) + nomem(); + + memset(h, 0, n); + + return h; +} + + +/* + * Wrap calloc() and handle any errors. + */ +void *sipCalloc(size_t nr, size_t n) +{ + void *h; + + if ((h = calloc(nr, n)) == NULL) + nomem(); + + return h; +} + + +/* + * Wrap strdup() and handle any errors. + */ +char *sipStrdup(const char *s) +{ + char *h; + + if ((h = strdup(s)) == NULL) + nomem(); + + return h; +} + + +/* + * Return a string on the heap which is the concatenation of all the arguments. + */ +char *concat(const char *s, ...) +{ + const char *sp; + char *new; + size_t len; + va_list ap; + + /* Find the length of the final string. */ + + len = 1; + va_start(ap,s); + + for (sp = s; sp != NULL; sp = va_arg(ap, const char *)) + len += strlen(sp); + + va_end(ap); + + /* Create the new string. */ + + new = sipMalloc(len); + *new = '\0'; + + va_start(ap,s); + + for (sp = s; sp != NULL; sp = va_arg(ap, const char *)) + strcat(new,sp); + + va_end(ap); + + return new; +} + + +/* + * Append a string to another that is on the heap. + */ + +void append(char **s, const char *new) +{ + if ((*s = realloc(*s,strlen(*s) + strlen(new) + 1)) == NULL) + nomem(); + + strcat(*s,new); +} + + +/* + * Display a standard error message when the heap is exhausted. + */ + +static void nomem(void) +{ + fatal("Unable to allocate memory on the heap\n"); +} diff --git a/sipgen/lexer.c b/sipgen/lexer.c new file mode 100644 index 0000000..06309e1 --- /dev/null +++ b/sipgen/lexer.c @@ -0,0 +1,3500 @@ +#line 2 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.c" + +#line 4 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <stdlib.h> + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include <inttypes.h> +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart(yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +extern int yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart (FILE *input_file ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); +void yy_delete_buffer (YY_BUFFER_STATE b ); +void yy_flush_buffer (YY_BUFFER_STATE b ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state (void ); + +static void yyensure_buffer_stack (void ); +static void yy_load_buffer_state (void ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +typedef unsigned char YY_CHAR; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +typedef int yy_state_type; + +extern int yylineno; + +int yylineno = 1; + +extern char *yytext; +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 125 +#define YY_END_OF_BUFFER 126 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[859] = + { 0, + 0, 0, 0, 0, 0, 0, 126, 124, 74, 75, + 124, 124, 124, 78, 124, 77, 77, 124, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 124, 74, 124, + 123, 122, 123, 87, 85, 87, 0, 82, 0, 83, + 78, 77, 0, 81, 78, 81, 81, 78, 84, 76, + 78, 0, 56, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 57, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 86, 78, 0, 73, 0, + 0, 78, 76, 79, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 36, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 78, 49, 80, 80, 80, + + 34, 32, 80, 80, 80, 42, 80, 80, 80, 37, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 47, 80, 80, 80, 40, 80, 0, 0, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 115, 20, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 121, 80, 80, 80, 80, 80, 80, 80, 21, 45, + 80, 80, 48, 38, 80, 80, 80, 80, 80, 35, + 80, 80, 29, 80, 80, 80, 53, 80, 80, 80, + + 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 80, 31, 80, 80, 80, 80, 80, 80, 39, 80, + 80, 80, 80, 80, 23, 80, 43, 46, 22, 80, + 80, 80, 80, 80, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 80, 30, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 25, + 80, 26, 80, 50, 80, 41, 33, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, + 0, 0, 0, 0, 0, 7, 0, 0, 0, 3, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 28, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 66, 54, 80, 52, 80, 55, 44, 7, + 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, + + 0, 88, 0, 0, 0, 0, 13, 0, 0, 119, + 4, 0, 14, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 120, 0, 0, 0, 0, + 0, 27, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 51, 24, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 117, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 11, 100, + 0, 98, 0, 80, 80, 61, 60, 80, 80, 80, + 64, 80, 80, 65, 80, 80, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 114, 16, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 12, 0, 0, 0, 113, 0, 0, + 67, 80, 80, 63, 59, 72, 80, 80, 80, 80, + 118, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 15, 101, 99, 0, 0, 111, 0, 0, 0, 0, + 0, 80, 58, 80, 80, 70, 71, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 116, 0, 104, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 80, 68, 69, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 112, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 103, 0, 0, 0, 0, 0, 94, 0, 105, 0, + 0, 0, 0, 0, 10, 0, 0, 0, 0, 2, + 18, 0, 0, 0, 0, 5, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, + 0, 93, 0, 0, 0, 0, 0, 109, 0, 0, + 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 9, 0, 0, 92, 96, 0, 0, + 102, 110, 107, 0, 106, 89, 0, 0, 0, 108, + 0, 0, 0, 91, 0, 95, 97, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 5, 1, 1, 6, 1, 7, 1, + 1, 8, 9, 1, 10, 11, 12, 13, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 15, 1, 1, + 1, 1, 1, 1, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 26, + 1, 1, 1, 1, 41, 1, 42, 43, 44, 45, + + 46, 47, 48, 49, 50, 26, 51, 52, 53, 54, + 55, 56, 26, 57, 58, 59, 60, 61, 62, 63, + 64, 26, 1, 65, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[66] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 1, 1, 3, + 3, 3, 4, 4, 1, 4, 4, 4, 4, 4, + 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 1 + } ; + +static yyconst flex_int16_t yy_base[867] = + { 0, + 0, 64, 1770, 65, 64, 66, 1772, 1774, 1774, 1774, + 70, 73, 68, 73, 80, 84, 88, 1756, 79, 96, + 100, 103, 106, 111, 114, 118, 126, 132, 138, 141, + 144, 147, 163, 177, 184, 180, 187, 1705, 94, 226, + 1774, 1774, 1749, 1774, 1774, 1756, 159, 1774, 164, 1774, + 219, 256, 167, 191, 261, 170, 196, 204, 1774, 0, + 1774, 0, 1774, 207, 268, 217, 273, 276, 279, 282, + 286, 289, 299, 302, 305, 308, 315, 318, 322, 325, + 331, 334, 340, 343, 350, 354, 357, 368, 372, 377, + 382, 387, 391, 396, 1774, 218, 430, 102, 1743, 49, + + 130, 195, 1720, 218, 362, 1715, 358, 1708, 362, 1721, + 1716, 120, 1707, 1710, 1705, 1774, 409, 425, 408, 126, + 414, 454, 0, 0, 459, 466, 462, 469, 472, 477, + 484, 487, 494, 497, 500, 503, 506, 512, 515, 521, + 526, 529, 540, 543, 552, 555, 558, 561, 564, 569, + 572, 579, 583, 586, 591, 597, 1727, 197, 1711, 284, + 389, 213, 1704, 1705, 1730, 1709, 112, 1697, 490, 1704, + 1706, 1704, 329, 1706, 287, 1688, 1774, 1690, 326, 1701, + 396, 1685, 1698, 1683, 1697, 460, 1682, 1693, 1688, 1678, + 1683, 1679, 1684, 1676, 1687, 591, 616, 619, 632, 636, + + 639, 643, 646, 649, 653, 661, 664, 667, 670, 673, + 676, 679, 682, 685, 688, 691, 699, 705, 708, 715, + 725, 732, 736, 741, 744, 750, 754, 757, 409, 1687, + 1686, 1673, 1683, 1774, 1681, 1680, 1679, 1679, 1667, 498, + 1658, 1679, 1662, 1774, 1673, 1663, 1658, 1664, 1658, 1696, + 1658, 1660, 1652, 1664, 1663, 1652, 1658, 1646, 1655, 1653, + 1644, 1654, 1642, 461, 1642, 1681, 1652, 1651, 1637, 1636, + 1774, 760, 763, 768, 771, 789, 792, 796, 805, 814, + 817, 822, 825, 828, 831, 834, 837, 840, 844, 847, + 850, 858, 861, 864, 867, 870, 879, 887, 894, 899, + + 903, 1636, 1633, 1634, 1632, 1638, 1629, 1633, 1632, 1640, + 1635, 1624, 1624, 1626, 1624, 1620, 1633, 1636, 1622, 1619, + 1615, 1624, 1619, 1625, 1625, 1615, 1617, 1613, 1615, 1619, + 1615, 1640, 1609, 1598, 1615, 1605, 1607, 592, 1640, 1597, + 906, 909, 913, 920, 917, 946, 949, 952, 925, 955, + 958, 962, 967, 973, 976, 979, 982, 985, 991, 996, + 999, 1004, 1008, 1011, 1604, 1597, 1007, 1608, 1601, 1594, + 1599, 1593, 1595, 1596, 1590, 1587, 1586, 1587, 1601, 1581, + 1596, 1581, 1594, 1596, 1579, 1586, 1590, 1589, 1587, 1578, + 1585, 1575, 1575, 1574, 1577, 1567, 1607, 1579, 1573, 1567, + + 1575, 1565, 1577, 1016, 1019, 1023, 1037, 1051, 1054, 1057, + 1061, 1069, 1072, 1075, 1079, 1083, 1088, 1091, 1100, 1103, + 1109, 1112, 1115, 1118, 1121, 1126, 1129, 1572, 1599, 1556, + 1566, 1568, 1567, 1555, 1569, 1564, 1559, 1558, 1548, 1558, + 1546, 1554, 1553, 1556, 1555, 1543, 1553, 1552, 1774, 1551, + 1544, 1549, 1542, 1558, 1574, 593, 1549, 1572, 1532, 1774, + 1538, 1528, 1537, 1530, 1538, 1529, 1537, 1539, 1535, 1527, + 1133, 1138, 1141, 1152, 1148, 1161, 1164, 1167, 1173, 1179, + 1182, 1185, 1198, 1201, 1204, 1207, 1210, 1213, 1216, 1774, + 1523, 1530, 1534, 1533, 1526, 1523, 1514, 1774, 1512, 1525, + + 513, 1774, 756, 1515, 1513, 1522, 1774, 1548, 1508, 1774, + 1774, 1514, 1774, 1517, 1498, 1506, 1505, 1513, 1506, 1502, + 1503, 1496, 1504, 1498, 1507, 1774, 1505, 1504, 1504, 1502, + 1529, 1219, 1222, 1226, 1230, 1233, 1236, 1248, 1251, 1259, + 1262, 1265, 1271, 1274, 1277, 1284, 1501, 1498, 1487, 1498, + 1524, 1482, 1494, 1493, 1496, 1480, 1481, 1481, 1488, 1473, + 1484, 1477, 253, 1475, 1471, 1470, 1774, 1471, 1481, 1480, + 1482, 1499, 1477, 1463, 1470, 1477, 1464, 1471, 1774, 1774, + 1470, 1774, 1473, 1289, 1292, 1299, 1302, 1305, 1308, 1315, + 1319, 1322, 1326, 1329, 1336, 1339, 1468, 1467, 1495, 1494, + + 1455, 1463, 1491, 1479, 1447, 1450, 551, 1460, 1444, 1446, + 1774, 1774, 1446, 1454, 1454, 1452, 1455, 1450, 1449, 1448, + 1448, 1438, 1445, 1774, 1448, 1437, 1470, 1774, 1430, 1427, + 1342, 1348, 1357, 1360, 1363, 1366, 1369, 1372, 1375, 1378, + 1774, 1428, 1424, 1423, 1422, 1464, 1420, 1424, 1432, 1424, + 1416, 1411, 1419, 1431, 1426, 1427, 1428, 1423, 1450, 1408, + 1774, 1774, 1774, 1420, 1421, 1774, 1410, 1386, 1379, 1405, + 1378, 1383, 1390, 1395, 1403, 1406, 1409, 1393, 1362, 1361, + 1349, 1338, 1350, 1346, 1319, 1327, 1318, 1300, 1310, 1284, + 1285, 1774, 1277, 1774, 1266, 1257, 1248, 1245, 1241, 1232, + + 1222, 1209, 1208, 1415, 1418, 1421, 1199, 1204, 1202, 1176, + 1159, 1158, 1143, 1174, 1136, 1169, 1135, 1130, 1105, 1097, + 1108, 1101, 1087, 1116, 1057, 1058, 1065, 1060, 1059, 1050, + 1428, 1032, 1030, 1013, 1040, 1009, 1008, 1000, 996, 988, + 990, 1021, 984, 980, 948, 947, 953, 944, 926, 935, + 933, 893, 1774, 905, 892, 900, 888, 885, 885, 861, + 844, 854, 850, 848, 850, 831, 837, 837, 811, 847, + 1774, 846, 808, 784, 763, 771, 1774, 800, 1774, 795, + 794, 764, 748, 778, 1774, 735, 775, 733, 743, 1774, + 1774, 741, 730, 702, 703, 1774, 690, 684, 678, 677, + + 675, 682, 705, 667, 660, 652, 648, 620, 1774, 595, + 592, 1774, 580, 580, 587, 578, 577, 1774, 564, 568, + 553, 532, 539, 1774, 482, 473, 446, 473, 413, 407, + 391, 386, 375, 1774, 344, 301, 1774, 1774, 330, 284, + 1774, 1774, 1774, 277, 1774, 1774, 261, 247, 192, 1774, + 175, 166, 119, 1774, 57, 1774, 1774, 1774, 1440, 1444, + 1448, 1452, 1454, 1456, 1460, 74 + } ; + +static yyconst flex_int16_t yy_def[867] = + { 0, + 858, 1, 859, 859, 860, 860, 858, 858, 858, 858, + 861, 862, 858, 863, 858, 858, 858, 858, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 861, 858, 862, 858, + 858, 858, 863, 863, 863, 863, 863, 863, 858, 865, + 858, 866, 858, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 858, 858, 858, 858, 858, 858, + + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 863, 858, + 863, 863, 865, 866, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 864, 864, 864, 864, + + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 864, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + + 864, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + + 858, 858, 858, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 864, 864, 864, 864, 864, 864, 864, + 864, 864, 864, 864, 864, 864, 858, 858, 858, 858, + + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 864, 864, 864, 864, 864, 864, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + + 858, 858, 858, 864, 864, 864, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 864, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 0, 858, 858, + 858, 858, 858, 858, 858, 858 + } ; + +static yyconst flex_int16_t yy_nxt[1840] = + { 0, + 8, 9, 10, 9, 11, 8, 12, 8, 8, 13, + 14, 15, 16, 17, 18, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 20, 19, + 19, 21, 19, 22, 19, 19, 19, 19, 19, 19, + 19, 19, 23, 24, 25, 26, 27, 19, 19, 28, + 19, 29, 19, 30, 31, 32, 19, 33, 34, 35, + 36, 37, 19, 19, 38, 39, 45, 42, 45, 40, + 43, 46, 48, 46, 48, 50, 168, 124, 51, 50, + 52, 52, 53, 54, 53, 55, 55, 59, 53, 56, + 53, 60, 57, 58, 51, 96, 52, 52, 51, 97, + + 52, 52, 857, 169, 61, 53, 56, 53, 61, 53, + 56, 53, 53, 56, 53, 53, 56, 53, 57, 58, + 53, 56, 53, 53, 56, 53, 67, 53, 56, 53, + 61, 65, 165, 236, 61, 53, 56, 53, 196, 196, + 66, 53, 56, 53, 237, 166, 62, 53, 56, 53, + 53, 56, 53, 53, 56, 53, 53, 56, 53, 69, + 68, 48, 70, 48, 856, 71, 50, 75, 72, 191, + 50, 73, 53, 56, 53, 170, 53, 76, 53, 53, + 74, 53, 79, 192, 171, 77, 53, 56, 53, 53, + 56, 53, 78, 53, 56, 53, 53, 56, 53, 80, + + 53, 119, 53, 81, 120, 121, 82, 53, 122, 122, + 855, 83, 84, 53, 85, 53, 53, 56, 53, 96, + 854, 86, 87, 97, 168, 88, 53, 56, 53, 92, + 94, 117, 117, 89, 93, 175, 853, 91, 118, 61, + 90, 98, 99, 100, 101, 102, 103, 104, 172, 105, + 126, 229, 106, 107, 232, 108, 109, 173, 110, 111, + 112, 113, 114, 176, 118, 61, 51, 233, 52, 52, + 53, 613, 53, 55, 55, 614, 61, 53, 56, 53, + 57, 58, 53, 56, 53, 53, 56, 53, 53, 56, + 53, 53, 56, 53, 125, 53, 56, 53, 53, 56, + + 53, 852, 61, 127, 248, 851, 57, 58, 53, 56, + 53, 53, 56, 53, 53, 56, 53, 53, 56, 53, + 129, 249, 850, 130, 53, 56, 53, 53, 56, 53, + 128, 53, 56, 53, 53, 56, 53, 172, 849, 131, + 53, 56, 53, 53, 56, 53, 230, 848, 132, 53, + 56, 53, 53, 56, 53, 847, 135, 134, 133, 53, + 56, 53, 136, 53, 56, 53, 53, 56, 53, 252, + 140, 138, 245, 137, 139, 253, 143, 53, 56, 53, + 141, 53, 56, 53, 246, 142, 53, 56, 53, 846, + 145, 53, 56, 53, 144, 147, 53, 56, 53, 181, + + 53, 56, 53, 182, 146, 53, 56, 53, 177, 149, + 148, 185, 183, 186, 178, 179, 187, 53, 188, 53, + 845, 117, 117, 53, 150, 53, 122, 122, 118, 61, + 844, 151, 152, 120, 120, 177, 843, 196, 196, 153, + 155, 178, 231, 154, 156, 157, 255, 158, 159, 160, + 103, 256, 842, 161, 118, 61, 106, 162, 841, 108, + 163, 239, 302, 53, 164, 53, 122, 122, 53, 56, + 53, 53, 56, 53, 58, 53, 56, 53, 53, 56, + 53, 53, 56, 53, 333, 197, 53, 56, 53, 198, + 840, 334, 199, 53, 56, 53, 53, 56, 53, 839, + + 58, 261, 200, 53, 56, 53, 53, 56, 53, 53, + 56, 53, 53, 56, 53, 53, 56, 53, 838, 262, + 201, 53, 56, 53, 53, 56, 53, 837, 202, 205, + 53, 56, 53, 556, 203, 53, 56, 53, 53, 56, + 53, 204, 239, 240, 209, 241, 206, 557, 207, 53, + 56, 53, 53, 56, 53, 309, 836, 208, 310, 210, + 211, 53, 56, 53, 53, 56, 53, 53, 56, 53, + 53, 56, 53, 53, 56, 53, 835, 212, 53, 56, + 53, 53, 56, 53, 651, 652, 213, 214, 53, 56, + 53, 215, 53, 56, 53, 53, 56, 53, 834, 216, + + 53, 56, 53, 196, 196, 217, 53, 56, 53, 400, + 517, 61, 833, 218, 401, 518, 219, 223, 832, 221, + 220, 831, 830, 222, 224, 53, 56, 53, 53, 56, + 53, 829, 225, 828, 827, 227, 826, 61, 228, 825, + 272, 53, 56, 53, 226, 53, 56, 53, 53, 56, + 53, 274, 53, 56, 53, 53, 56, 53, 53, 56, + 53, 273, 53, 56, 53, 824, 275, 276, 277, 278, + 53, 56, 53, 53, 56, 53, 53, 56, 53, 53, + 56, 53, 53, 56, 53, 53, 56, 53, 53, 56, + 53, 53, 56, 53, 53, 56, 53, 53, 56, 53, + + 53, 56, 53, 279, 281, 823, 822, 280, 53, 56, + 53, 821, 283, 282, 53, 56, 53, 53, 56, 53, + 286, 820, 819, 287, 53, 56, 53, 818, 284, 817, + 288, 816, 815, 285, 53, 56, 53, 289, 814, 813, + 291, 53, 56, 53, 292, 53, 56, 53, 812, 290, + 53, 56, 53, 53, 56, 53, 811, 294, 295, 53, + 56, 53, 293, 53, 56, 53, 53, 56, 53, 53, + 56, 53, 53, 56, 53, 558, 296, 53, 56, 53, + 53, 56, 53, 559, 810, 298, 809, 808, 341, 560, + 807, 299, 806, 297, 805, 804, 343, 342, 53, 56, + + 53, 53, 56, 53, 803, 53, 56, 53, 802, 300, + 344, 801, 800, 301, 53, 56, 53, 799, 345, 347, + 798, 797, 348, 53, 56, 53, 53, 56, 53, 796, + 346, 53, 56, 53, 53, 56, 53, 53, 56, 53, + 53, 56, 53, 53, 56, 53, 53, 56, 53, 53, + 56, 53, 795, 53, 56, 53, 53, 56, 53, 53, + 56, 53, 349, 794, 793, 350, 792, 53, 56, 53, + 53, 56, 53, 53, 56, 53, 53, 56, 53, 53, + 56, 53, 791, 354, 790, 789, 351, 355, 53, 56, + 53, 788, 352, 787, 786, 353, 53, 56, 53, 785, + + 784, 356, 357, 53, 56, 53, 783, 358, 53, 56, + 53, 360, 53, 56, 53, 53, 56, 53, 53, 56, + 53, 404, 53, 56, 53, 359, 53, 56, 53, 53, + 56, 53, 361, 413, 53, 56, 53, 407, 408, 782, + 363, 781, 405, 364, 780, 779, 409, 362, 778, 410, + 777, 776, 406, 411, 412, 53, 56, 53, 53, 56, + 53, 53, 56, 53, 53, 56, 53, 53, 56, 53, + 415, 53, 56, 53, 775, 414, 53, 56, 53, 774, + 773, 416, 53, 56, 53, 53, 56, 53, 53, 56, + 53, 53, 56, 53, 53, 56, 53, 772, 771, 418, + + 53, 56, 53, 770, 417, 53, 56, 53, 53, 56, + 53, 769, 420, 53, 56, 53, 419, 53, 56, 53, + 53, 56, 53, 430, 431, 53, 56, 53, 53, 56, + 53, 421, 53, 56, 53, 768, 422, 767, 766, 432, + 433, 765, 471, 764, 434, 424, 53, 56, 53, 425, + 763, 762, 473, 761, 423, 760, 472, 759, 758, 426, + 53, 56, 53, 53, 56, 53, 53, 56, 53, 427, + 53, 56, 53, 476, 474, 757, 756, 475, 53, 56, + 53, 53, 56, 53, 53, 56, 53, 477, 53, 56, + 53, 481, 53, 56, 53, 755, 480, 53, 56, 53, + + 53, 56, 53, 754, 478, 753, 752, 482, 479, 53, + 56, 53, 53, 56, 53, 751, 750, 483, 53, 56, + 53, 53, 56, 53, 53, 56, 53, 53, 56, 53, + 53, 56, 53, 749, 485, 53, 56, 53, 53, 56, + 53, 748, 53, 56, 53, 747, 484, 53, 56, 53, + 53, 56, 53, 746, 487, 745, 486, 53, 56, 53, + 488, 53, 56, 53, 533, 489, 532, 534, 744, 535, + 53, 56, 53, 53, 56, 53, 53, 56, 53, 743, + 742, 536, 53, 56, 53, 537, 741, 538, 53, 56, + 53, 53, 56, 53, 53, 56, 53, 539, 541, 740, + + 543, 739, 738, 540, 737, 736, 542, 53, 56, 53, + 53, 56, 53, 53, 56, 53, 53, 56, 53, 53, + 56, 53, 53, 56, 53, 53, 56, 53, 53, 56, + 53, 53, 56, 53, 735, 53, 56, 53, 544, 53, + 56, 53, 53, 56, 53, 53, 56, 53, 734, 545, + 733, 584, 585, 732, 546, 588, 730, 53, 56, 53, + 53, 56, 53, 729, 586, 589, 728, 587, 53, 56, + 53, 53, 56, 53, 53, 56, 53, 590, 591, 592, + 53, 56, 53, 53, 56, 53, 53, 56, 53, 727, + 726, 595, 596, 53, 56, 53, 725, 594, 53, 56, + + 53, 53, 56, 53, 724, 593, 723, 632, 53, 56, + 53, 53, 56, 53, 53, 56, 53, 53, 56, 53, + 722, 721, 633, 631, 53, 56, 53, 634, 53, 56, + 53, 53, 56, 53, 635, 53, 56, 53, 53, 56, + 53, 720, 719, 637, 638, 53, 56, 53, 53, 56, + 53, 53, 56, 53, 718, 717, 636, 53, 56, 53, + 716, 715, 640, 714, 672, 639, 53, 56, 53, 53, + 56, 53, 53, 56, 53, 53, 56, 53, 53, 56, + 53, 53, 56, 53, 53, 56, 53, 53, 56, 53, + 713, 673, 53, 56, 53, 675, 712, 711, 674, 53, + + 56, 53, 710, 676, 53, 56, 53, 709, 708, 704, + 707, 677, 53, 56, 53, 53, 56, 53, 53, 56, + 53, 703, 702, 705, 53, 56, 53, 53, 56, 53, + 53, 56, 53, 701, 731, 700, 706, 53, 56, 53, + 41, 41, 41, 41, 44, 44, 44, 44, 47, 47, + 47, 47, 49, 49, 49, 49, 56, 56, 64, 64, + 123, 699, 123, 123, 698, 697, 696, 695, 694, 693, + 692, 691, 690, 689, 688, 687, 686, 685, 684, 683, + 682, 681, 680, 679, 678, 671, 670, 669, 668, 667, + 666, 665, 664, 663, 662, 661, 660, 659, 658, 657, + + 656, 655, 654, 653, 650, 649, 648, 647, 646, 645, + 644, 643, 642, 641, 630, 629, 628, 627, 626, 625, + 624, 623, 622, 621, 620, 619, 618, 617, 616, 615, + 612, 611, 610, 609, 608, 607, 606, 605, 604, 603, + 602, 601, 600, 599, 598, 597, 583, 582, 581, 580, + 579, 578, 577, 576, 575, 574, 573, 572, 571, 570, + 569, 568, 567, 566, 565, 564, 563, 562, 561, 555, + 554, 553, 552, 551, 550, 549, 548, 547, 531, 530, + 529, 528, 527, 526, 525, 524, 523, 522, 521, 520, + 519, 516, 515, 514, 513, 512, 511, 510, 509, 508, + + 507, 506, 505, 504, 503, 502, 501, 500, 499, 498, + 497, 496, 495, 494, 493, 492, 491, 490, 470, 469, + 468, 467, 466, 465, 464, 463, 462, 461, 460, 459, + 458, 457, 456, 455, 454, 453, 452, 451, 450, 449, + 448, 447, 446, 445, 444, 443, 442, 441, 440, 439, + 438, 437, 436, 435, 429, 428, 403, 402, 399, 398, + 397, 396, 395, 394, 393, 392, 391, 390, 389, 388, + 387, 386, 385, 384, 383, 382, 381, 380, 379, 378, + 377, 376, 375, 374, 373, 372, 371, 370, 369, 368, + 367, 366, 365, 309, 340, 339, 338, 337, 336, 335, + + 332, 331, 330, 329, 328, 327, 326, 325, 324, 323, + 322, 321, 320, 319, 318, 317, 316, 315, 314, 313, + 312, 311, 308, 307, 306, 305, 304, 303, 256, 252, + 245, 271, 270, 269, 268, 267, 266, 265, 264, 263, + 260, 259, 258, 257, 254, 251, 250, 247, 244, 243, + 242, 238, 235, 234, 191, 186, 170, 165, 195, 194, + 193, 190, 189, 184, 180, 174, 167, 116, 115, 95, + 63, 858, 42, 7, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858 + } ; + +static yyconst flex_int16_t yy_chk[1840] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 2, 5, 4, 6, 2, + 4, 5, 11, 6, 11, 12, 100, 866, 13, 12, + 13, 13, 14, 14, 14, 14, 14, 15, 19, 19, + 19, 15, 14, 14, 16, 39, 16, 16, 17, 39, + + 17, 17, 855, 100, 16, 20, 20, 20, 17, 21, + 21, 21, 22, 22, 22, 23, 23, 23, 14, 14, + 24, 24, 24, 25, 25, 25, 22, 26, 26, 26, + 16, 20, 98, 167, 17, 27, 27, 27, 120, 120, + 21, 28, 28, 28, 167, 98, 16, 29, 29, 29, + 30, 30, 30, 31, 31, 31, 32, 32, 32, 24, + 23, 47, 24, 47, 853, 24, 49, 27, 25, 112, + 49, 26, 33, 33, 33, 101, 53, 27, 53, 56, + 26, 56, 30, 112, 101, 28, 34, 34, 34, 36, + 36, 36, 29, 35, 35, 35, 37, 37, 37, 31, + + 54, 54, 54, 32, 57, 57, 32, 57, 57, 57, + 852, 33, 33, 58, 33, 58, 64, 64, 64, 96, + 851, 33, 34, 96, 158, 34, 66, 66, 66, 36, + 37, 51, 51, 34, 36, 104, 849, 35, 51, 51, + 34, 40, 40, 40, 40, 40, 40, 40, 102, 40, + 66, 158, 40, 40, 162, 40, 40, 102, 40, 40, + 40, 40, 40, 104, 51, 51, 52, 162, 52, 52, + 55, 563, 55, 55, 55, 563, 52, 65, 65, 65, + 55, 55, 67, 67, 67, 68, 68, 68, 69, 69, + 69, 70, 70, 70, 65, 71, 71, 71, 72, 72, + + 72, 848, 52, 67, 175, 847, 55, 55, 73, 73, + 73, 74, 74, 74, 75, 75, 75, 76, 76, 76, + 69, 175, 844, 70, 77, 77, 77, 78, 78, 78, + 68, 79, 79, 79, 80, 80, 80, 160, 840, 71, + 81, 81, 81, 82, 82, 82, 160, 839, 72, 83, + 83, 83, 84, 84, 84, 836, 75, 74, 73, 85, + 85, 85, 76, 86, 86, 86, 87, 87, 87, 179, + 80, 78, 173, 77, 79, 179, 82, 88, 88, 88, + 81, 89, 89, 89, 173, 81, 90, 90, 90, 835, + 84, 91, 91, 91, 83, 86, 92, 92, 92, 107, + + 93, 93, 93, 107, 85, 94, 94, 94, 105, 87, + 86, 109, 107, 109, 105, 105, 109, 119, 109, 119, + 833, 117, 117, 121, 88, 121, 121, 121, 117, 117, + 832, 89, 90, 118, 118, 161, 831, 118, 118, 91, + 93, 161, 161, 92, 94, 97, 181, 97, 97, 97, + 97, 181, 830, 97, 117, 117, 97, 97, 829, 97, + 97, 229, 229, 122, 97, 122, 122, 122, 125, 125, + 125, 127, 127, 127, 122, 126, 126, 126, 128, 128, + 128, 129, 129, 129, 264, 125, 130, 130, 130, 126, + 828, 264, 126, 131, 131, 131, 132, 132, 132, 827, + + 122, 186, 127, 133, 133, 133, 134, 134, 134, 135, + 135, 135, 136, 136, 136, 137, 137, 137, 826, 186, + 128, 138, 138, 138, 139, 139, 139, 825, 129, 132, + 140, 140, 140, 501, 130, 141, 141, 141, 142, 142, + 142, 131, 169, 169, 136, 169, 133, 501, 134, 143, + 143, 143, 144, 144, 144, 240, 823, 135, 240, 138, + 139, 145, 145, 145, 146, 146, 146, 147, 147, 147, + 148, 148, 148, 149, 149, 149, 822, 140, 150, 150, + 150, 151, 151, 151, 607, 607, 141, 142, 152, 152, + 152, 143, 153, 153, 153, 154, 154, 154, 821, 144, + + 155, 155, 155, 196, 196, 145, 156, 156, 156, 338, + 456, 196, 820, 146, 338, 456, 147, 151, 819, 149, + 148, 817, 816, 150, 152, 197, 197, 197, 198, 198, + 198, 815, 153, 814, 813, 155, 811, 196, 156, 810, + 198, 199, 199, 199, 154, 200, 200, 200, 201, 201, + 201, 200, 202, 202, 202, 203, 203, 203, 204, 204, + 204, 199, 205, 205, 205, 808, 200, 200, 200, 200, + 206, 206, 206, 207, 207, 207, 208, 208, 208, 209, + 209, 209, 210, 210, 210, 211, 211, 211, 212, 212, + 212, 213, 213, 213, 214, 214, 214, 215, 215, 215, + + 216, 216, 216, 203, 205, 807, 806, 204, 217, 217, + 217, 805, 208, 207, 218, 218, 218, 219, 219, 219, + 212, 804, 803, 213, 220, 220, 220, 802, 209, 801, + 214, 800, 799, 211, 221, 221, 221, 215, 798, 797, + 217, 222, 222, 222, 217, 223, 223, 223, 795, 216, + 224, 224, 224, 225, 225, 225, 794, 219, 220, 226, + 226, 226, 218, 227, 227, 227, 228, 228, 228, 272, + 272, 272, 273, 273, 273, 503, 221, 274, 274, 274, + 275, 275, 275, 503, 793, 224, 792, 789, 272, 503, + 788, 225, 787, 222, 786, 784, 274, 273, 276, 276, + + 276, 277, 277, 277, 783, 278, 278, 278, 782, 226, + 275, 781, 780, 228, 279, 279, 279, 778, 276, 278, + 776, 775, 278, 280, 280, 280, 281, 281, 281, 774, + 277, 282, 282, 282, 283, 283, 283, 284, 284, 284, + 285, 285, 285, 286, 286, 286, 287, 287, 287, 288, + 288, 288, 773, 289, 289, 289, 290, 290, 290, 291, + 291, 291, 281, 772, 770, 282, 769, 292, 292, 292, + 293, 293, 293, 294, 294, 294, 295, 295, 295, 296, + 296, 296, 768, 288, 767, 766, 285, 289, 297, 297, + 297, 765, 286, 764, 763, 287, 298, 298, 298, 762, + + 761, 291, 292, 299, 299, 299, 760, 294, 300, 300, + 300, 296, 301, 301, 301, 341, 341, 341, 342, 342, + 342, 341, 343, 343, 343, 295, 345, 345, 345, 344, + 344, 344, 298, 345, 349, 349, 349, 344, 344, 759, + 300, 758, 342, 301, 757, 756, 344, 299, 755, 344, + 754, 752, 343, 344, 344, 346, 346, 346, 347, 347, + 347, 348, 348, 348, 350, 350, 350, 351, 351, 351, + 347, 352, 352, 352, 751, 346, 353, 353, 353, 750, + 749, 348, 354, 354, 354, 355, 355, 355, 356, 356, + 356, 357, 357, 357, 358, 358, 358, 748, 747, 351, + + 359, 359, 359, 746, 350, 360, 360, 360, 361, 361, + 361, 745, 353, 362, 362, 362, 352, 363, 363, 363, + 364, 364, 364, 367, 367, 404, 404, 404, 405, 405, + 405, 354, 406, 406, 406, 744, 356, 743, 742, 367, + 367, 741, 404, 740, 367, 361, 407, 407, 407, 362, + 739, 738, 407, 737, 360, 736, 406, 735, 734, 363, + 408, 408, 408, 409, 409, 409, 410, 410, 410, 364, + 411, 411, 411, 410, 408, 733, 732, 409, 412, 412, + 412, 413, 413, 413, 414, 414, 414, 411, 415, 415, + 415, 414, 416, 416, 416, 730, 413, 417, 417, 417, + + 418, 418, 418, 729, 412, 728, 727, 415, 412, 419, + 419, 419, 420, 420, 420, 726, 725, 416, 421, 421, + 421, 422, 422, 422, 423, 423, 423, 424, 424, 424, + 425, 425, 425, 724, 418, 426, 426, 426, 427, 427, + 427, 723, 471, 471, 471, 722, 417, 472, 472, 472, + 473, 473, 473, 721, 421, 720, 419, 475, 475, 475, + 423, 474, 474, 474, 472, 425, 471, 473, 719, 474, + 476, 476, 476, 477, 477, 477, 478, 478, 478, 718, + 717, 475, 479, 479, 479, 476, 716, 477, 480, 480, + 480, 481, 481, 481, 482, 482, 482, 478, 480, 715, + + 482, 714, 713, 479, 712, 711, 481, 483, 483, 483, + 484, 484, 484, 485, 485, 485, 486, 486, 486, 487, + 487, 487, 488, 488, 488, 489, 489, 489, 532, 532, + 532, 533, 533, 533, 710, 534, 534, 534, 483, 535, + 535, 535, 536, 536, 536, 537, 537, 537, 709, 485, + 708, 533, 534, 707, 487, 537, 703, 538, 538, 538, + 539, 539, 539, 702, 535, 538, 701, 536, 540, 540, + 540, 541, 541, 541, 542, 542, 542, 539, 540, 541, + 543, 543, 543, 544, 544, 544, 545, 545, 545, 700, + 699, 544, 544, 546, 546, 546, 698, 543, 584, 584, + + 584, 585, 585, 585, 697, 542, 696, 585, 586, 586, + 586, 587, 587, 587, 588, 588, 588, 589, 589, 589, + 695, 693, 588, 584, 590, 590, 590, 589, 591, 591, + 591, 592, 592, 592, 590, 593, 593, 593, 594, 594, + 594, 691, 690, 593, 593, 595, 595, 595, 596, 596, + 596, 631, 631, 631, 689, 688, 592, 632, 632, 632, + 687, 686, 596, 685, 632, 595, 633, 633, 633, 634, + 634, 634, 635, 635, 635, 636, 636, 636, 637, 637, + 637, 638, 638, 638, 639, 639, 639, 640, 640, 640, + 684, 633, 672, 672, 672, 638, 683, 682, 637, 673, + + 673, 673, 681, 639, 674, 674, 674, 680, 679, 672, + 678, 640, 675, 675, 675, 676, 676, 676, 677, 677, + 677, 671, 670, 674, 704, 704, 704, 705, 705, 705, + 706, 706, 706, 669, 704, 668, 675, 731, 731, 731, + 859, 859, 859, 859, 860, 860, 860, 860, 861, 861, + 861, 861, 862, 862, 862, 862, 863, 863, 864, 864, + 865, 667, 865, 865, 665, 664, 660, 659, 658, 657, + 656, 655, 654, 653, 652, 651, 650, 649, 648, 647, + 646, 645, 644, 643, 642, 630, 629, 627, 626, 625, + 623, 622, 621, 620, 619, 618, 617, 616, 615, 614, + + 613, 610, 609, 608, 606, 605, 604, 603, 602, 601, + 600, 599, 598, 597, 583, 581, 578, 577, 576, 575, + 574, 573, 572, 571, 570, 569, 568, 566, 565, 564, + 562, 561, 560, 559, 558, 557, 556, 555, 554, 553, + 552, 551, 550, 549, 548, 547, 531, 530, 529, 528, + 527, 525, 524, 523, 522, 521, 520, 519, 518, 517, + 516, 515, 514, 512, 509, 508, 506, 505, 504, 500, + 499, 497, 496, 495, 494, 493, 492, 491, 470, 469, + 468, 467, 466, 465, 464, 463, 462, 461, 459, 458, + 457, 455, 454, 453, 452, 451, 450, 448, 447, 446, + + 445, 444, 443, 442, 441, 440, 439, 438, 437, 436, + 435, 434, 433, 432, 431, 430, 429, 428, 403, 402, + 401, 400, 399, 398, 397, 396, 395, 394, 393, 392, + 391, 390, 389, 388, 387, 386, 385, 384, 383, 382, + 381, 380, 379, 378, 377, 376, 375, 374, 373, 372, + 371, 370, 369, 368, 366, 365, 340, 339, 337, 336, + 335, 334, 333, 332, 331, 330, 329, 328, 327, 326, + 325, 324, 323, 322, 321, 320, 319, 318, 317, 316, + 315, 314, 313, 312, 311, 310, 309, 308, 307, 306, + 305, 304, 303, 302, 270, 269, 268, 267, 266, 265, + + 263, 262, 261, 260, 259, 258, 257, 256, 255, 254, + 253, 252, 251, 250, 249, 248, 247, 246, 245, 243, + 242, 241, 239, 238, 237, 236, 235, 233, 232, 231, + 230, 195, 194, 193, 192, 191, 190, 189, 188, 187, + 185, 184, 183, 182, 180, 178, 176, 174, 172, 171, + 170, 168, 166, 165, 164, 163, 159, 157, 115, 114, + 113, 111, 110, 108, 106, 103, 99, 46, 43, 38, + 18, 7, 3, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + 858, 858, 858, 858, 858, 858, 858, 858, 858 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +/* + * The SIP lexer. + * + * Copyright (c) 2010 Riverbank Computing Limited <info@riverbankcomputing.com> + * + * This file is part of SIP. + * + * This copy of SIP is licensed for use under the terms of the SIP License + * Agreement. See the file LICENSE for more details. + * + * This copy of SIP may also used under the terms of the GNU General Public + * License v2 or v3 as published by the Free Software Foundation which can be + * found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package. + * + * SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ +#line 20 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "sip.h" +#include "parser.h" + + +#ifndef FLEX_SCANNER +#error "Only flex is supported at the moment" +#endif + + +#define YY_NO_UNISTD_H +#define YY_FATAL_ERROR(s) fatallex(s) + +#define MAX_INCLUDE_DEPTH 10 +#define MAX_CODE_LINE_LENGTH 1000 + + +static struct inputFile { + int lineno; /* The line number. */ + YY_BUFFER_STATE bs; /* The flex buffer state handle. */ + char *name; /* The file name. */ + char *cwd; /* The path part of the file name. */ + parserContext pc; /* The parser context. */ +} inputFileStack[MAX_INCLUDE_DEPTH]; + +static int currentFile = -1; /* Index of the current input file. */ +static char codeLine[MAX_CODE_LINE_LENGTH + 2]; /* The current code line. */ +static int codeIdx = -1; /* Index of next code character. */ + +static FILE *openFile(const char *); +static void fatallex(char *); + + +#line 1203 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.c" + +#define INITIAL 0 +#define code 1 +#define ccomment 2 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include <unistd.h> +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy (void ); + +int yyget_debug (void ); + +void yyset_debug (int debug_flag ); + +YY_EXTRA_TYPE yyget_extra (void ); + +void yyset_extra (YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in (void ); + +void yyset_in (FILE * in_str ); + +FILE *yyget_out (void ); + +void yyset_out (FILE * out_str ); + +int yyget_leng (void ); + +char *yyget_text (void ); + +int yyget_lineno (void ); + +void yyset_lineno (int line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap (void ); +#else +extern int yywrap (void ); +#endif +#endif + + static void yyunput (int c,char *buf_ptr ); + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + if ( yyleng > 0 ) \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ + (yytext[yyleng - 1] == '\n'); \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 60 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" + + +#line 1398 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.c" + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); + yy_current_state += YY_AT_BOL(); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 859 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 1774 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 62 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_API;} + YY_BREAK +case 2: +YY_RULE_SETUP +#line 63 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_DEFENCODING;} + YY_BREAK +case 3: +YY_RULE_SETUP +#line 64 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_PLUGIN;} + YY_BREAK +case 4: +YY_RULE_SETUP +#line 65 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_INCLUDE;} + YY_BREAK +case 5: +YY_RULE_SETUP +#line 66 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_OPTINCLUDE;} + YY_BREAK +case 6: +YY_RULE_SETUP +#line 67 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_IMPORT;} + YY_BREAK +case 7: +YY_RULE_SETUP +#line 68 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_MODULE;} + YY_BREAK +case 8: +YY_RULE_SETUP +#line 69 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_CMODULE;} + YY_BREAK +case 9: +YY_RULE_SETUP +#line 70 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_CONSMODULE;} + YY_BREAK +case 10: +YY_RULE_SETUP +#line 71 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_COMPOMODULE;} + YY_BREAK +case 11: +YY_RULE_SETUP +#line 72 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_TIMELINE;} + YY_BREAK +case 12: +YY_RULE_SETUP +#line 73 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_PLATFORMS;} + YY_BREAK +case 13: +YY_RULE_SETUP +#line 74 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_FEATURE;} + YY_BREAK +case 14: +YY_RULE_SETUP +#line 75 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_LICENSE;} + YY_BREAK +case 15: +YY_RULE_SETUP +#line 76 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_MAPPEDTYPE;} + YY_BREAK +case 16: +YY_RULE_SETUP +#line 77 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_EXCEPTION;} + YY_BREAK +case 17: +YY_RULE_SETUP +#line 78 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_IF;} + YY_BREAK +case 18: +YY_RULE_SETUP +#line 79 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_DEFMETATYPE;} + YY_BREAK +case 19: +YY_RULE_SETUP +#line 80 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_DEFSUPERTYPE;} + YY_BREAK +case 20: +YY_RULE_SETUP +#line 81 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_END;} + YY_BREAK +case 21: +YY_RULE_SETUP +#line 82 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_CLASS;} + YY_BREAK +case 22: +YY_RULE_SETUP +#line 83 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_STRUCT;} + YY_BREAK +case 23: +YY_RULE_SETUP +#line 84 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_PUBLIC;} + YY_BREAK +case 24: +YY_RULE_SETUP +#line 85 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_PROTECTED;} + YY_BREAK +case 25: +YY_RULE_SETUP +#line 86 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_PRIVATE;} + YY_BREAK +case 26: +YY_RULE_SETUP +#line 87 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SIGNALS;} + YY_BREAK +case 27: +YY_RULE_SETUP +#line 88 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SIGNALS;} + YY_BREAK +case 28: +YY_RULE_SETUP +#line 89 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SIGNAL_METHOD;} + YY_BREAK +case 29: +YY_RULE_SETUP +#line 90 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SLOTS;} + YY_BREAK +case 30: +YY_RULE_SETUP +#line 91 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SLOTS;} + YY_BREAK +case 31: +YY_RULE_SETUP +#line 92 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SLOT_METHOD;} + YY_BREAK +case 32: +YY_RULE_SETUP +#line 93 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_CHAR;} + YY_BREAK +case 33: +YY_RULE_SETUP +#line 94 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_WCHAR_T;} + YY_BREAK +case 34: +YY_RULE_SETUP +#line 95 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_BOOL;} + YY_BREAK +case 35: +YY_RULE_SETUP +#line 96 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SHORT;} + YY_BREAK +case 36: +YY_RULE_SETUP +#line 97 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_INT;} + YY_BREAK +case 37: +YY_RULE_SETUP +#line 98 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_LONG;} + YY_BREAK +case 38: +YY_RULE_SETUP +#line 99 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_FLOAT;} + YY_BREAK +case 39: +YY_RULE_SETUP +#line 100 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_DOUBLE;} + YY_BREAK +case 40: +YY_RULE_SETUP +#line 101 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_VOID;} + YY_BREAK +case 41: +YY_RULE_SETUP +#line 102 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_VIRTUAL;} + YY_BREAK +case 42: +YY_RULE_SETUP +#line 103 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_ENUM;} + YY_BREAK +case 43: +YY_RULE_SETUP +#line 104 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SIGNED;} + YY_BREAK +case 44: +YY_RULE_SETUP +#line 105 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_UNSIGNED;} + YY_BREAK +case 45: +YY_RULE_SETUP +#line 106 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_CONST;} + YY_BREAK +case 46: +YY_RULE_SETUP +#line 107 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_STATIC;} + YY_BREAK +case 47: +YY_RULE_SETUP +#line 108 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_TRUE;} + YY_BREAK +case 48: +YY_RULE_SETUP +#line 109 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_FALSE;} + YY_BREAK +case 49: +YY_RULE_SETUP +#line 110 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_NULL;} + YY_BREAK +case 50: +YY_RULE_SETUP +#line 111 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_TYPEDEF;} + YY_BREAK +case 51: +YY_RULE_SETUP +#line 112 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_NAMESPACE;} + YY_BREAK +case 52: +YY_RULE_SETUP +#line 113 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_OPERATOR;} + YY_BREAK +case 53: +YY_RULE_SETUP +#line 114 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_THROW;} + YY_BREAK +case 54: +YY_RULE_SETUP +#line 115 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_EXPLICIT;} + YY_BREAK +case 55: +YY_RULE_SETUP +#line 116 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_TEMPLATE;} + YY_BREAK +case 56: +YY_RULE_SETUP +#line 117 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SCOPE;} + YY_BREAK +case 57: +YY_RULE_SETUP +#line 118 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_LOGICAL_OR;} + YY_BREAK +case 58: +YY_RULE_SETUP +#line 119 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_PYOBJECT;} + YY_BREAK +case 59: +YY_RULE_SETUP +#line 120 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_PYTUPLE;} + YY_BREAK +case 60: +YY_RULE_SETUP +#line 121 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_PYLIST;} + YY_BREAK +case 61: +YY_RULE_SETUP +#line 122 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_PYDICT;} + YY_BREAK +case 62: +YY_RULE_SETUP +#line 123 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_PYCALLABLE;} + YY_BREAK +case 63: +YY_RULE_SETUP +#line 124 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_PYSLICE;} + YY_BREAK +case 64: +YY_RULE_SETUP +#line 125 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_PYTYPE;} + YY_BREAK +case 65: +YY_RULE_SETUP +#line 126 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SIPSIGNAL;} + YY_BREAK +case 66: +YY_RULE_SETUP +#line 127 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SIPSLOT;} + YY_BREAK +case 67: +YY_RULE_SETUP +#line 128 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SIPANYSLOT;} + YY_BREAK +case 68: +YY_RULE_SETUP +#line 129 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SIPRXCON;} + YY_BREAK +case 69: +YY_RULE_SETUP +#line 130 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SIPRXDIS;} + YY_BREAK +case 70: +YY_RULE_SETUP +#line 131 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SIPSLOTCON;} + YY_BREAK +case 71: +YY_RULE_SETUP +#line 132 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_SIPSLOTDIS;} + YY_BREAK +case 72: +YY_RULE_SETUP +#line 133 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_QOBJECT;} + YY_BREAK +case 73: +YY_RULE_SETUP +#line 134 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{return TK_ELLIPSIS;} + YY_BREAK +case 74: +YY_RULE_SETUP +#line 137 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* Ignore whitespace. */ + ; +} + YY_BREAK +case 75: +/* rule 75 can match eol */ +YY_RULE_SETUP +#line 141 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* Maintain the line number. */ + ++inputFileStack[currentFile].lineno; + + if (codeIdx == 0) + { + BEGIN code; + } +} + YY_BREAK +case 76: +YY_RULE_SETUP +#line 150 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* Ignore C++ style comments. */ + ; +} + YY_BREAK +case 77: +YY_RULE_SETUP +#line 155 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* A signed decimal number. */ + yylval.number = strtol(yytext,NULL,0); + return TK_NUMBER; +} + YY_BREAK +case 78: +YY_RULE_SETUP +#line 161 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{/* A floating point number. */ + yylval.real = strtod(yytext,NULL); + return TK_REAL; +} + YY_BREAK +case 79: +YY_RULE_SETUP +#line 167 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* An unsigned hexadecimal number. */ + yylval.number = strtol(yytext,NULL,16); + return TK_NUMBER; +} + YY_BREAK +case 80: +YY_RULE_SETUP +#line 173 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* An identifier name. */ + yylval.text = sipStrdup(yytext); + return TK_NAME; +} + YY_BREAK +case 81: +YY_RULE_SETUP +#line 179 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* A relative pathname. */ + yylval.text = sipStrdup(yytext); + return TK_PATHNAME; +} + YY_BREAK +case 82: +/* rule 82 can match eol */ +YY_RULE_SETUP +#line 185 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* A double-quoted string. */ + char *dp, *sp; + + /* Copy the string without the quotes. */ + + yylval.text = sipMalloc(strlen(yytext) + 1); + + dp = yylval.text; + sp = yytext; + + while (*sp != '\0') + { + if (*sp != '"') + *dp++ = *sp; + + ++sp; + } + + *dp = '\0'; + + return TK_STRING; +} + YY_BREAK +case 83: +/* rule 83 can match eol */ +YY_RULE_SETUP +#line 209 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* A single-quoted character. */ + if (strlen(yytext) != 3) + fatallex("Exactly one character expected between single quotes"); + + yylval.qchar = yytext[1]; + + return TK_QCHAR; +} + YY_BREAK +case 84: +YY_RULE_SETUP +#line 219 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* Ignore C-style comments. */ + BEGIN ccomment; +} + YY_BREAK +case 85: +/* rule 85 can match eol */ +YY_RULE_SETUP +#line 222 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ + ++inputFileStack[currentFile].lineno; +} + YY_BREAK +case 86: +YY_RULE_SETUP +#line 225 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ + BEGIN INITIAL; +} + YY_BREAK +case 87: +YY_RULE_SETUP +#line 228 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ + ; +} + YY_BREAK +case 88: +YY_RULE_SETUP +#line 233 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The software license. */ + codeIdx = 0; + return TK_COPYING; +} + YY_BREAK +case 89: +YY_RULE_SETUP +#line 238 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a from-type code block. */ + codeIdx = 0; + return TK_FROMTYPE; +} + YY_BREAK +case 90: +YY_RULE_SETUP +#line 243 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a to-type code block. */ + codeIdx = 0; + return TK_TOTYPE; +} + YY_BREAK +case 91: +YY_RULE_SETUP +#line 248 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a to-sub-class code block. */ + codeIdx = 0; + return TK_TOSUBCLASS; +} + YY_BREAK +case 92: +YY_RULE_SETUP +#line 253 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of an exported header code block. */ + codeIdx = 0; + return TK_EXPHEADERCODE; +} + YY_BREAK +case 93: +YY_RULE_SETUP +#line 258 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a module header code block. */ + codeIdx = 0; + return TK_MODHEADERCODE; +} + YY_BREAK +case 94: +YY_RULE_SETUP +#line 263 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a type header code block. */ + codeIdx = 0; + return TK_TYPEHEADERCODE; +} + YY_BREAK +case 95: +YY_RULE_SETUP +#line 268 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a pre-initialisation code block. */ + codeIdx = 0; + return TK_PREINITCODE; +} + YY_BREAK +case 96: +YY_RULE_SETUP +#line 273 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of an initialisation code block. */ + codeIdx = 0; + return TK_INITCODE; +} + YY_BREAK +case 97: +YY_RULE_SETUP +#line 278 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a post-initialisation code block. */ + codeIdx = 0; + return TK_POSTINITCODE; +} + YY_BREAK +case 98: +YY_RULE_SETUP +#line 283 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a unit code block. */ + codeIdx = 0; + return TK_UNITCODE; +} + YY_BREAK +case 99: +YY_RULE_SETUP +#line 288 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a module code block. */ + codeIdx = 0; + return TK_MODCODE; +} + YY_BREAK +case 100: +YY_RULE_SETUP +#line 293 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a type code block. */ + codeIdx = 0; + return TK_TYPECODE; +} + YY_BREAK +case 101: +YY_RULE_SETUP +#line 298 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a C++ method code block. */ + codeIdx = 0; + return TK_METHODCODE; +} + YY_BREAK +case 102: +YY_RULE_SETUP +#line 303 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a C++ virtual code block. */ + codeIdx = 0; + return TK_VIRTUALCATCHERCODE; +} + YY_BREAK +case 103: +YY_RULE_SETUP +#line 308 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a traverse code block. */ + codeIdx = 0; + return TK_TRAVERSECODE; +} + YY_BREAK +case 104: +YY_RULE_SETUP +#line 313 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a clear code block. */ + codeIdx = 0; + return TK_CLEARCODE; +} + YY_BREAK +case 105: +YY_RULE_SETUP +#line 318 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a get buffer code block. */ + codeIdx = 0; + return TK_GETBUFFERCODE; +} + YY_BREAK +case 106: +YY_RULE_SETUP +#line 323 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a release buffer code block. */ + codeIdx = 0; + return TK_RELEASEBUFFERCODE; +} + YY_BREAK +case 107: +YY_RULE_SETUP +#line 328 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a read buffer code block. */ + codeIdx = 0; + return TK_READBUFFERCODE; +} + YY_BREAK +case 108: +YY_RULE_SETUP +#line 333 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a write buffer code block. */ + codeIdx = 0; + return TK_WRITEBUFFERCODE; +} + YY_BREAK +case 109: +YY_RULE_SETUP +#line 338 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a segment count code block. */ + codeIdx = 0; + return TK_SEGCOUNTCODE; +} + YY_BREAK +case 110: +YY_RULE_SETUP +#line 343 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a char buffer code block. */ + codeIdx = 0; + return TK_CHARBUFFERCODE; +} + YY_BREAK +case 111: +YY_RULE_SETUP +#line 348 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a pickle code block. */ + codeIdx = 0; + return TK_PICKLECODE; +} + YY_BREAK +case 112: +YY_RULE_SETUP +#line 353 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a pre-Python code block. */ + codeIdx = 0; + return TK_PREPYCODE; +} + YY_BREAK +case 113: +YY_RULE_SETUP +#line 358 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a raise exception code block. */ + codeIdx = 0; + return TK_RAISECODE; +} + YY_BREAK +case 114: +YY_RULE_SETUP +#line 363 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a docstring block. */ + codeIdx = 0; + return TK_DOCSTRING; +} + YY_BREAK +case 115: +YY_RULE_SETUP +#line 368 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a documentation block. */ + codeIdx = 0; + return TK_DOC; +} + YY_BREAK +case 116: +YY_RULE_SETUP +#line 373 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of an exported documentation block. */ + codeIdx = 0; + return TK_EXPORTEDDOC; +} + YY_BREAK +case 117: +YY_RULE_SETUP +#line 378 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a Makefile code block. */ + codeIdx = 0; + return TK_MAKEFILE; +} + YY_BREAK +case 118: +YY_RULE_SETUP +#line 383 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of an access code block. */ + codeIdx = 0; + return TK_ACCESSCODE; +} + YY_BREAK +case 119: +YY_RULE_SETUP +#line 388 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a get code block. */ + codeIdx = 0; + return TK_GETCODE; +} + YY_BREAK +case 120: +YY_RULE_SETUP +#line 393 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The start of a set code block. */ + codeIdx = 0; + return TK_SETCODE; +} + YY_BREAK +case 121: +YY_RULE_SETUP +#line 398 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The end of a code block. */ + BEGIN INITIAL; + codeIdx = -1; + return TK_END; +} + YY_BREAK +case 122: +/* rule 122 can match eol */ +YY_RULE_SETUP +#line 404 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The end of a code line . */ + struct inputFile *ifp; + + codeLine[codeIdx] = '\n'; + codeLine[codeIdx + 1] = '\0'; + codeIdx = 0; + + ifp = &inputFileStack[currentFile]; + + yylval.codeb = sipMalloc(sizeof (codeBlock)); + + yylval.codeb -> frag = sipStrdup(codeLine); + yylval.codeb -> linenr = ifp -> lineno++; + yylval.codeb -> filename = sipStrdup(ifp -> name); + yylval.codeb -> next = NULL; + + return TK_CODELINE; +} + YY_BREAK +case 123: +YY_RULE_SETUP +#line 423 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* The contents of a code line. */ + if (codeIdx == MAX_CODE_LINE_LENGTH) + fatallex("Line is too long"); + + codeLine[codeIdx++] = yytext[0]; +} + YY_BREAK +case 124: +YY_RULE_SETUP +#line 430 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +{ /* Anything else is returned as is. */ + return yytext[0]; +} + YY_BREAK +case 125: +YY_RULE_SETUP +#line 434 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" +ECHO; + YY_BREAK +#line 2301 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.c" +case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(code): +case YY_STATE_EOF(ccomment): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), (size_t) num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + yy_current_state += YY_AT_BOL(); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 859 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + register int yy_is_jam; + register char *yy_cp = (yy_c_buf_p); + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 859 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 858); + + return yy_is_jam ? 0 : yy_current_state; +} + + static void yyunput (int c, register char * yy_bp ) +{ + register char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = (yy_n_chars) + 2; + register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + register char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart(yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_init_buffer(YY_CURRENT_BUFFER,input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree((void *) b->yy_ch_buf ); + + yyfree((void *) b ); +} + +#ifndef __cplusplus +extern int isatty (int ); +#endif /* __cplusplus */ + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + int num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer(b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) +{ + + return yy_scan_bytes(yystr,strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) yyalloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +int yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param line_number + * + */ +void yyset_lineno (int line_number ) +{ + + yylineno = line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * in_str ) +{ + yyin = in_str ; +} + +void yyset_out (FILE * out_str ) +{ + yyout = out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int bdebug ) +{ + yy_flex_debug = bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = (FILE *) 0; + yyout = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 434 "/home/phil/hg/sip/sip-4.10.5/sipgen/lexer.l" + + + +/* + * Hook into EOF handling. Return 0 if there is more to process. + */ + +int yywrap() +{ + char *cwd; + struct inputFile *ifp; + + if ((cwd = inputFileStack[currentFile].cwd) != NULL) + free(cwd); + + ifp = &inputFileStack[currentFile--]; + + /* Tell the parser if this is the end of a file. */ + + parserEOF(ifp -> name, &ifp -> pc); + + /* Tidy up this file. */ + + fclose(yyin); + free(ifp -> name); + + /* See if this was the original file. */ + + if (currentFile < 0) + return 1; + + yy_delete_buffer(YY_CURRENT_BUFFER); + yy_switch_to_buffer(ifp -> bs); + + return 0; +} + + +/* + * Set up an input file to be read by the lexer, opening it if necessary. TRUE + * is returned if the file has not already been read. + */ +int setInputFile(FILE *open_fp, parserContext *pc, int optional) +{ + static stringList *all = NULL; + char *cwd, *fullname = NULL; + FILE *fp = open_fp; + + if (currentFile >= MAX_INCLUDE_DEPTH - 1) + fatal("Too many nested %%Include, %%OptionalInclude or %%Import statements\n"); + + if (fp != NULL || (fp = openFile(pc->filename)) != NULL) + fullname = sipStrdup(pc->filename); + else + { + char *cwd; + + /* Try the directory that contains the current file. */ + if (currentFile >= 0 && (cwd = inputFileStack[currentFile].cwd) != NULL) + { + fullname = concat(cwd, "/", pc->filename, NULL); + + if ((fp = openFile(fullname)) == NULL) + { + free(fullname); + fullname = NULL; + } + } + } + + /* Try the include path if we haven't found anything yet. */ + if (fullname == NULL) + { + stringList *sl; + + fullname = NULL; + + for (sl = includeDirList; sl != NULL; sl = sl -> next) + { + if (fullname != NULL) + free(fullname); + + fullname = concat(sl->s, "/", pc->filename, NULL); + + if ((fp = openFile(fullname)) != NULL) + break; + } + + if (fp == NULL) + { + if (optional) + return FALSE; + + fatal("Unable to find file \"%s\"\n", pc->filename); + } + } + + /* + * If we have just opened the file, make sure that we haven't already read + * it. While it should never happen with normal modules (if the user + * doesn't specify recursive %Imports or %Includes) it is likely to happen + * with consolidated modules. + */ + if (open_fp == NULL) + { + stringList *sl; + + for (sl = all; sl != NULL; sl = sl->next) + if (strcmp(sl->s, fullname) == 0) + { + fclose(fp); + return FALSE; + } + } + + /* Remember the filename. */ + appendString(&all, sipStrdup(fullname)); + + yyin = fp; + + ++currentFile; + + /* Remember the directory containing the new file and make it "current". */ + if ((cwd = strchr(fullname, '/')) != NULL) + { + cwd = sipStrdup(fullname); + *strrchr(cwd,'/') = '\0'; + } + + inputFileStack[currentFile].lineno = 1; + inputFileStack[currentFile].name = fullname; + inputFileStack[currentFile].pc = *pc; + inputFileStack[currentFile].cwd = cwd; + + if (currentFile > 0) + { + inputFileStack[currentFile].bs = YY_CURRENT_BUFFER; + yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE)); + } + + return TRUE; +} + + +/* + * Open a file for reading or return NULL if it doesn't exist. Any other error + * is fatal. + */ +static FILE *openFile(const char *name) +{ + FILE *fp; + + if ((fp = fopen(name,"r")) == NULL && errno != ENOENT) + fatal("Error in opening file %s\n",name); + + return fp; +} + + +/* + * Handle fatal yacc errors. + */ +void yyerror(char *s) +{ + if (currentFile < 0) + fatal("%s\n", s); + + fatal("%s:%d: %s\n", + inputFileStack[currentFile].name, + inputFileStack[currentFile].lineno, + s); +} + + +/* + * Handle warnings while parsing. + */ +void yywarning(char *s) +{ + warning("%s:%d: %s\n", + inputFileStack[currentFile].name, + inputFileStack[currentFile].lineno, + s); +} + + +/* + * Handle fatal lex errors. + */ +static void fatallex(char *s) +{ + fatal("%s:%d: Lexical analyser error: %s\n", + inputFileStack[currentFile].name, + inputFileStack[currentFile].lineno, + s); +} + diff --git a/sipgen/lexer.l b/sipgen/lexer.l new file mode 100644 index 0000000..35fb9c2 --- /dev/null +++ b/sipgen/lexer.l @@ -0,0 +1,628 @@ +/* + * The SIP lexer. + * + * Copyright (c) 2010 Riverbank Computing Limited <info@riverbankcomputing.com> + * + * This file is part of SIP. + * + * This copy of SIP is licensed for use under the terms of the SIP License + * Agreement. See the file LICENSE for more details. + * + * This copy of SIP may also used under the terms of the GNU General Public + * License v2 or v3 as published by the Free Software Foundation which can be + * found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package. + * + * SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + +%{ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "sip.h" +#include "parser.h" + + +#ifndef FLEX_SCANNER +#error "Only flex is supported at the moment" +#endif + + +#define YY_NO_UNISTD_H +#define YY_FATAL_ERROR(s) fatallex(s) + +#define MAX_INCLUDE_DEPTH 10 +#define MAX_CODE_LINE_LENGTH 1000 + + +static struct inputFile { + int lineno; /* The line number. */ + YY_BUFFER_STATE bs; /* The flex buffer state handle. */ + char *name; /* The file name. */ + char *cwd; /* The path part of the file name. */ + parserContext pc; /* The parser context. */ +} inputFileStack[MAX_INCLUDE_DEPTH]; + +static int currentFile = -1; /* Index of the current input file. */ +static char codeLine[MAX_CODE_LINE_LENGTH + 2]; /* The current code line. */ +static int codeIdx = -1; /* Index of next code character. */ + +static FILE *openFile(const char *); +static void fatallex(char *); +%} + +%x code +%x ccomment + +%% + +^[ \t]*%API {return TK_API;} +^[ \t]*%DefaultEncoding {return TK_DEFENCODING;} +^[ \t]*%Plugin {return TK_PLUGIN;} +^[ \t]*%Include {return TK_INCLUDE;} +^[ \t]*%OptionalInclude {return TK_OPTINCLUDE;} +^[ \t]*%Import {return TK_IMPORT;} +^[ \t]*%Module {return TK_MODULE;} +^[ \t]*%CModule {return TK_CMODULE;} +^[ \t]*%ConsolidatedModule {return TK_CONSMODULE;} +^[ \t]*%CompositeModule {return TK_COMPOMODULE;} +^[ \t]*%Timeline {return TK_TIMELINE;} +^[ \t]*%Platforms {return TK_PLATFORMS;} +^[ \t]*%Feature {return TK_FEATURE;} +^[ \t]*%License {return TK_LICENSE;} +^[ \t]*%MappedType {return TK_MAPPEDTYPE;} +^[ \t]*%Exception {return TK_EXCEPTION;} +^[ \t]*%If {return TK_IF;} +^[ \t]*%DefaultMetatype {return TK_DEFMETATYPE;} +^[ \t]*%DefaultSupertype {return TK_DEFSUPERTYPE;} +<INITIAL>^[ \t]*%End {return TK_END;} +class {return TK_CLASS;} +struct {return TK_STRUCT;} +public {return TK_PUBLIC;} +protected {return TK_PROTECTED;} +private {return TK_PRIVATE;} +signals {return TK_SIGNALS;} +Q_SIGNALS {return TK_SIGNALS;} +Q_SIGNAL {return TK_SIGNAL_METHOD;} +slots {return TK_SLOTS;} +Q_SLOTS {return TK_SLOTS;} +Q_SLOT {return TK_SLOT_METHOD;} +char {return TK_CHAR;} +wchar_t {return TK_WCHAR_T;} +bool {return TK_BOOL;} +short {return TK_SHORT;} +int {return TK_INT;} +long {return TK_LONG;} +float {return TK_FLOAT;} +double {return TK_DOUBLE;} +void {return TK_VOID;} +virtual {return TK_VIRTUAL;} +enum {return TK_ENUM;} +signed {return TK_SIGNED;} +unsigned {return TK_UNSIGNED;} +const {return TK_CONST;} +static {return TK_STATIC;} +true {return TK_TRUE;} +false {return TK_FALSE;} +NULL {return TK_NULL;} +typedef {return TK_TYPEDEF;} +namespace {return TK_NAMESPACE;} +operator {return TK_OPERATOR;} +throw {return TK_THROW;} +explicit {return TK_EXPLICIT;} +template {return TK_TEMPLATE;} +:: {return TK_SCOPE;} +\|\| {return TK_LOGICAL_OR;} +SIP_PYOBJECT {return TK_PYOBJECT;} +SIP_PYTUPLE {return TK_PYTUPLE;} +SIP_PYLIST {return TK_PYLIST;} +SIP_PYDICT {return TK_PYDICT;} +SIP_PYCALLABLE {return TK_PYCALLABLE;} +SIP_PYSLICE {return TK_PYSLICE;} +SIP_PYTYPE {return TK_PYTYPE;} +SIP_SIGNAL {return TK_SIPSIGNAL;} +SIP_SLOT {return TK_SIPSLOT;} +SIP_ANYSLOT {return TK_SIPANYSLOT;} +SIP_RXOBJ_CON {return TK_SIPRXCON;} +SIP_RXOBJ_DIS {return TK_SIPRXDIS;} +SIP_SLOT_CON {return TK_SIPSLOTCON;} +SIP_SLOT_DIS {return TK_SIPSLOTDIS;} +SIP_QOBJECT {return TK_QOBJECT;} +\.\.\. {return TK_ELLIPSIS;} + + +[ \t\r] { /* Ignore whitespace. */ + ; +} + +\n { /* Maintain the line number. */ + ++inputFileStack[currentFile].lineno; + + if (codeIdx == 0) + { + BEGIN code; + } +} + +\/\/.* { /* Ignore C++ style comments. */ + ; +} + + +-?[0-9]+ { /* A signed decimal number. */ + yylval.number = strtol(yytext,NULL,0); + return TK_NUMBER; +} + + +-?(([0-9]+)|([0-9]*\.[0-9]*)([eE][-+]?[0-9]+)?)[fF]? {/* A floating point number. */ + yylval.real = strtod(yytext,NULL); + return TK_REAL; +} + + +0x[0-9a-fA-F]+ { /* An unsigned hexadecimal number. */ + yylval.number = strtol(yytext,NULL,16); + return TK_NUMBER; +} + + +[_A-Za-z][_A-Za-z0-9]* { /* An identifier name. */ + yylval.text = sipStrdup(yytext); + return TK_NAME; +} + + +[._A-Za-z][._/A-Za-z0-9\-]*[._A-Za-z0-9] { /* A relative pathname. */ + yylval.text = sipStrdup(yytext); + return TK_PATHNAME; +} + + +\"[^"\n]*["\n] { /* A double-quoted string. */ + char *dp, *sp; + + /* Copy the string without the quotes. */ + + yylval.text = sipMalloc(strlen(yytext) + 1); + + dp = yylval.text; + sp = yytext; + + while (*sp != '\0') + { + if (*sp != '"') + *dp++ = *sp; + + ++sp; + } + + *dp = '\0'; + + return TK_STRING; +} + + +\'[^'\n]*['\n] { /* A single-quoted character. */ + if (strlen(yytext) != 3) + fatallex("Exactly one character expected between single quotes"); + + yylval.qchar = yytext[1]; + + return TK_QCHAR; +} + + +\/\* { /* Ignore C-style comments. */ + BEGIN ccomment; +} +<ccomment>\n { + ++inputFileStack[currentFile].lineno; +} +<ccomment>\*\/ { + BEGIN INITIAL; +} +<ccomment>. { + ; +} + + +^%Copying { /* The software license. */ + codeIdx = 0; + return TK_COPYING; +} + +^%ConvertFromTypeCode { /* The start of a from-type code block. */ + codeIdx = 0; + return TK_FROMTYPE; +} + +^%ConvertToTypeCode { /* The start of a to-type code block. */ + codeIdx = 0; + return TK_TOTYPE; +} + +^%ConvertToSubClassCode { /* The start of a to-sub-class code block. */ + codeIdx = 0; + return TK_TOSUBCLASS; +} + +^%ExportedHeaderCode { /* The start of an exported header code block. */ + codeIdx = 0; + return TK_EXPHEADERCODE; +} + +^%ModuleHeaderCode { /* The start of a module header code block. */ + codeIdx = 0; + return TK_MODHEADERCODE; +} + +^%TypeHeaderCode { /* The start of a type header code block. */ + codeIdx = 0; + return TK_TYPEHEADERCODE; +} + +^%PreInitialisationCode { /* The start of a pre-initialisation code block. */ + codeIdx = 0; + return TK_PREINITCODE; +} + +^%InitialisationCode { /* The start of an initialisation code block. */ + codeIdx = 0; + return TK_INITCODE; +} + +^%PostInitialisationCode { /* The start of a post-initialisation code block. */ + codeIdx = 0; + return TK_POSTINITCODE; +} + +^%UnitCode { /* The start of a unit code block. */ + codeIdx = 0; + return TK_UNITCODE; +} + +^%ModuleCode { /* The start of a module code block. */ + codeIdx = 0; + return TK_MODCODE; +} + +^%TypeCode { /* The start of a type code block. */ + codeIdx = 0; + return TK_TYPECODE; +} + +^%MethodCode { /* The start of a C++ method code block. */ + codeIdx = 0; + return TK_METHODCODE; +} + +^%VirtualCatcherCode { /* The start of a C++ virtual code block. */ + codeIdx = 0; + return TK_VIRTUALCATCHERCODE; +} + +^%GCTraverseCode { /* The start of a traverse code block. */ + codeIdx = 0; + return TK_TRAVERSECODE; +} + +^%GCClearCode { /* The start of a clear code block. */ + codeIdx = 0; + return TK_CLEARCODE; +} + +^%BIGetBufferCode { /* The start of a get buffer code block. */ + codeIdx = 0; + return TK_GETBUFFERCODE; +} + +^%BIReleaseBufferCode { /* The start of a release buffer code block. */ + codeIdx = 0; + return TK_RELEASEBUFFERCODE; +} + +^%BIGetReadBufferCode { /* The start of a read buffer code block. */ + codeIdx = 0; + return TK_READBUFFERCODE; +} + +^%BIGetWriteBufferCode { /* The start of a write buffer code block. */ + codeIdx = 0; + return TK_WRITEBUFFERCODE; +} + +^%BIGetSegCountCode { /* The start of a segment count code block. */ + codeIdx = 0; + return TK_SEGCOUNTCODE; +} + +^%BIGetCharBufferCode { /* The start of a char buffer code block. */ + codeIdx = 0; + return TK_CHARBUFFERCODE; +} + +^%PickleCode { /* The start of a pickle code block. */ + codeIdx = 0; + return TK_PICKLECODE; +} + +^%PrePythonCode { /* The start of a pre-Python code block. */ + codeIdx = 0; + return TK_PREPYCODE; +} + +^%RaiseCode { /* The start of a raise exception code block. */ + codeIdx = 0; + return TK_RAISECODE; +} + +^%Docstring { /* The start of a docstring block. */ + codeIdx = 0; + return TK_DOCSTRING; +} + +^%Doc { /* The start of a documentation block. */ + codeIdx = 0; + return TK_DOC; +} + +^%ExportedDoc { /* The start of an exported documentation block. */ + codeIdx = 0; + return TK_EXPORTEDDOC; +} + +^%Makefile { /* The start of a Makefile code block. */ + codeIdx = 0; + return TK_MAKEFILE; +} + +^%AccessCode { /* The start of an access code block. */ + codeIdx = 0; + return TK_ACCESSCODE; +} + +^%GetCode { /* The start of a get code block. */ + codeIdx = 0; + return TK_GETCODE; +} + +^%SetCode { /* The start of a set code block. */ + codeIdx = 0; + return TK_SETCODE; +} + +<code>^%End { /* The end of a code block. */ + BEGIN INITIAL; + codeIdx = -1; + return TK_END; +} + +<code>\n { /* The end of a code line . */ + struct inputFile *ifp; + + codeLine[codeIdx] = '\n'; + codeLine[codeIdx + 1] = '\0'; + codeIdx = 0; + + ifp = &inputFileStack[currentFile]; + + yylval.codeb = sipMalloc(sizeof (codeBlock)); + + yylval.codeb -> frag = sipStrdup(codeLine); + yylval.codeb -> linenr = ifp -> lineno++; + yylval.codeb -> filename = sipStrdup(ifp -> name); + yylval.codeb -> next = NULL; + + return TK_CODELINE; +} + +<code>. { /* The contents of a code line. */ + if (codeIdx == MAX_CODE_LINE_LENGTH) + fatallex("Line is too long"); + + codeLine[codeIdx++] = yytext[0]; +} + +. { /* Anything else is returned as is. */ + return yytext[0]; +} + +%% + +/* + * Hook into EOF handling. Return 0 if there is more to process. + */ + +int yywrap() +{ + char *cwd; + struct inputFile *ifp; + + if ((cwd = inputFileStack[currentFile].cwd) != NULL) + free(cwd); + + ifp = &inputFileStack[currentFile--]; + + /* Tell the parser if this is the end of a file. */ + + parserEOF(ifp -> name, &ifp -> pc); + + /* Tidy up this file. */ + + fclose(yyin); + free(ifp -> name); + + /* See if this was the original file. */ + + if (currentFile < 0) + return 1; + + yy_delete_buffer(YY_CURRENT_BUFFER); + yy_switch_to_buffer(ifp -> bs); + + return 0; +} + + +/* + * Set up an input file to be read by the lexer, opening it if necessary. TRUE + * is returned if the file has not already been read. + */ +int setInputFile(FILE *open_fp, parserContext *pc, int optional) +{ + static stringList *all = NULL; + char *cwd, *fullname = NULL; + FILE *fp = open_fp; + + if (currentFile >= MAX_INCLUDE_DEPTH - 1) + fatal("Too many nested %%Include, %%OptionalInclude or %%Import statements\n"); + + if (fp != NULL || (fp = openFile(pc->filename)) != NULL) + fullname = sipStrdup(pc->filename); + else + { + char *cwd; + + /* Try the directory that contains the current file. */ + if (currentFile >= 0 && (cwd = inputFileStack[currentFile].cwd) != NULL) + { + fullname = concat(cwd, "/", pc->filename, NULL); + + if ((fp = openFile(fullname)) == NULL) + { + free(fullname); + fullname = NULL; + } + } + } + + /* Try the include path if we haven't found anything yet. */ + if (fullname == NULL) + { + stringList *sl; + + fullname = NULL; + + for (sl = includeDirList; sl != NULL; sl = sl -> next) + { + if (fullname != NULL) + free(fullname); + + fullname = concat(sl->s, "/", pc->filename, NULL); + + if ((fp = openFile(fullname)) != NULL) + break; + } + + if (fp == NULL) + { + if (optional) + return FALSE; + + fatal("Unable to find file \"%s\"\n", pc->filename); + } + } + + /* + * If we have just opened the file, make sure that we haven't already read + * it. While it should never happen with normal modules (if the user + * doesn't specify recursive %Imports or %Includes) it is likely to happen + * with consolidated modules. + */ + if (open_fp == NULL) + { + stringList *sl; + + for (sl = all; sl != NULL; sl = sl->next) + if (strcmp(sl->s, fullname) == 0) + { + fclose(fp); + return FALSE; + } + } + + /* Remember the filename. */ + appendString(&all, sipStrdup(fullname)); + + yyin = fp; + + ++currentFile; + + /* Remember the directory containing the new file and make it "current". */ + if ((cwd = strchr(fullname, '/')) != NULL) + { + cwd = sipStrdup(fullname); + *strrchr(cwd,'/') = '\0'; + } + + inputFileStack[currentFile].lineno = 1; + inputFileStack[currentFile].name = fullname; + inputFileStack[currentFile].pc = *pc; + inputFileStack[currentFile].cwd = cwd; + + if (currentFile > 0) + { + inputFileStack[currentFile].bs = YY_CURRENT_BUFFER; + yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE)); + } + + return TRUE; +} + + +/* + * Open a file for reading or return NULL if it doesn't exist. Any other error + * is fatal. + */ +static FILE *openFile(const char *name) +{ + FILE *fp; + + if ((fp = fopen(name,"r")) == NULL && errno != ENOENT) + fatal("Error in opening file %s\n",name); + + return fp; +} + + +/* + * Handle fatal yacc errors. + */ +void yyerror(char *s) +{ + if (currentFile < 0) + fatal("%s\n", s); + + fatal("%s:%d: %s\n", + inputFileStack[currentFile].name, + inputFileStack[currentFile].lineno, + s); +} + + +/* + * Handle warnings while parsing. + */ +void yywarning(char *s) +{ + warning("%s:%d: %s\n", + inputFileStack[currentFile].name, + inputFileStack[currentFile].lineno, + s); +} + + +/* + * Handle fatal lex errors. + */ +static void fatallex(char *s) +{ + fatal("%s:%d: Lexical analyser error: %s\n", + inputFileStack[currentFile].name, + inputFileStack[currentFile].lineno, + s); +} diff --git a/sipgen/main.c b/sipgen/main.c new file mode 100644 index 0000000..4cf81f1 --- /dev/null +++ b/sipgen/main.c @@ -0,0 +1,515 @@ +/* + * The main module for SIP. + * + * Copyright (c) 2010 Riverbank Computing Limited <info@riverbankcomputing.com> + * + * This file is part of SIP. + * + * This copy of SIP is licensed for use under the terms of the SIP License + * Agreement. See the file LICENSE for more details. + * + * This copy of SIP may also used under the terms of the GNU General Public + * License v2 or v3 as published by the Free Software Foundation which can be + * found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package. + * + * SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <ctype.h> + +#include "sip.h" + + +#ifndef PACKAGE +#define PACKAGE "sip" +#endif + +#define VERSION "4.10.5" + + +/* Global variables - see sip.h for their meaning. */ +char *sipVersion; +stringList *includeDirList; + +static char *sipPackage = PACKAGE; +static int warnings = FALSE; + + +static void help(void); +static void version(void); +static void usage(void); +static char parseopt(int,char **,char *,char **,int *,char **); +static int parseInt(char *,char); + + +int main(int argc, char **argv) +{ + char *filename, *docFile, *codeDir, *srcSuffix, *flagFile, *consModule; + char arg, *optarg, *buildFile, *apiFile, *xmlFile; + int optnr, exceptions, tracing, releaseGIL, parts, kwdArgs, protHack, docs; + FILE *file; + sipSpec spec; + stringList *versions, *xfeatures; + + /* Initialise. */ + sipVersion = VERSION; + includeDirList = NULL; + versions = NULL; + xfeatures = NULL; + buildFile = NULL; + codeDir = NULL; + docFile = NULL; + srcSuffix = NULL; + flagFile = NULL; + apiFile = NULL; + xmlFile = NULL; + consModule = NULL; + exceptions = FALSE; + tracing = FALSE; + releaseGIL = FALSE; + parts = 0; + kwdArgs = FALSE; + protHack = FALSE; + docs = FALSE; + + /* Parse the command line. */ + optnr = 1; + + while ((arg = parseopt(argc, argv, "hVa:b:ec:d:gI:j:km:op:Prs:t:wx:z:", &flagFile, &optnr, &optarg)) != '\0') + switch (arg) + { + case 'o': + /* Generate docstrings. */ + docs = TRUE; + break; + + case 'p': + /* The name of the consolidated module. */ + consModule = optarg; + break; + + case 'P': + /* Enable the protected/public hack. */ + protHack = TRUE; + break; + + case 'a': + /* Where to generate the API file. */ + apiFile = optarg; + break; + + case 'm': + /* Where to generate the XML file. */ + xmlFile = optarg; + break; + + case 'b': + /* Generate a build file. */ + buildFile = optarg; + break; + + case 'e': + /* Enable exceptions. */ + exceptions = TRUE; + break; + + case 'g': + /* Always release the GIL. */ + releaseGIL = TRUE; + break; + + case 'j': + /* Generate the code in this number of parts. */ + parts = parseInt(optarg,'j'); + break; + + case 'z': + /* Read a file for the next flags. */ + if (flagFile != NULL) + fatal("The -z flag cannot be specified in an argument file\n"); + + flagFile = optarg; + break; + + case 'c': + /* Where to generate the code. */ + codeDir = optarg; + break; + + case 'd': + /* Where to generate the documentation. */ + docFile = optarg; + break; + + case 't': + /* Which platform or version to generate code for. */ + appendString(&versions,optarg); + break; + + case 'x': + /* Which features are disabled. */ + appendString(&xfeatures,optarg); + break; + + case 'I': + /* Where to get included files from. */ + appendString(&includeDirList,optarg); + break; + + case 'r': + /* Enable tracing. */ + tracing = TRUE; + break; + + case 's': + /* The suffix to use for source files. */ + srcSuffix = optarg; + break; + + case 'w': + /* Enable warning messages. */ + warnings = TRUE; + break; + + case 'k': + /* Allow keyword arguments in functions and methods. */ + kwdArgs = TRUE; + break; + + case 'h': + /* Help message. */ + help(); + break; + + case 'V': + /* Display the version number. */ + version(); + break; + + default: + usage(); + } + + if (optnr < argc) + { + file = NULL; + filename = argv[optnr++]; + + if (optnr < argc) + usage(); + } + else + { + file = stdin; + filename = "stdin"; + } + + /* Parse the input file. */ + parse(&spec, file, filename, versions, xfeatures, kwdArgs, protHack); + + /* Verify and transform the parse tree. */ + transform(&spec); + + /* Generate code. */ + generateCode(&spec, codeDir, buildFile, docFile, srcSuffix, exceptions, + tracing, releaseGIL, parts, xfeatures, consModule, docs); + + /* Generate the API file. */ + if (apiFile != NULL) + generateAPI(&spec, spec.module, apiFile); + + /* Generate the XML export. */ + if (xmlFile != NULL) + generateXML(&spec, spec.module, xmlFile); + + /* All done. */ + return 0; +} + + +/* + * Parse the next command line argument - similar to UNIX getopts(). Allow a + * flag to specify that a file contains further arguments. + */ +static char parseopt(int argc, char **argv, char *opts, char **flags, + int *optnrp, char **optargp) +{ + char arg, *op, *fname; + int optnr; + static FILE *fp = NULL; + + /* Deal with any file first. */ + + fname = *flags; + + if (fname != NULL && fp == NULL && (fp = fopen(fname,"r")) == NULL) + fatal("Unable to open %s\n",fname); + + if (fp != NULL) + { + char buf[200], *cp, *fname; + int ch; + + fname = *flags; + cp = buf; + + while ((ch = fgetc(fp)) != EOF) + { + /* Skip leading whitespace. */ + + if (cp == buf && isspace(ch)) + continue; + + if (ch == '\n') + break; + + if (cp == &buf[sizeof (buf) - 1]) + fatal("A flag in %s is too long\n",fname); + + *cp++ = (char)ch; + } + + *cp = '\0'; + + if (ch == EOF) + { + fclose(fp); + fp = NULL; + *flags = NULL; + } + + /* + * Get the option character and any optional argument from the + * line. + */ + + if (buf[0] != '\0') + { + if (buf[0] != '-' || buf[1] == '\0') + fatal("An non-flag was given in %s\n",fname); + + arg = buf[1]; + + /* Find any optional argument. */ + + for (cp = &buf[2]; *cp != '\0'; ++cp) + if (!isspace(*cp)) + break; + + if (*cp == '\0') + cp = NULL; + else + cp = sipStrdup(cp); + + *optargp = cp; + + if ((op = strchr(opts,arg)) == NULL) + fatal("An invalid flag was given in %s\n",fname); + + if (op[1] == ':' && cp == NULL) + fatal("Missing flag argument in %s\n",fname); + + if (op[1] != ':' && cp != NULL) + fatal("Unexpected flag argument in %s\n",fname); + + return arg; + } + } + + /* Check there is an argument and it is a switch. */ + + optnr = *optnrp; + + if (optnr >= argc || argv[optnr] == NULL || argv[optnr][0] != '-') + return '\0'; + + /* Check it is a valid switch. */ + + arg = argv[optnr][1]; + + if (arg == '\0' || (op = strchr(opts,arg)) == NULL) + usage(); + + /* Check for the switch parameter, if any. */ + + if (op[1] == ':') + { + if (argv[optnr][2] != '\0') + { + *optargp = &argv[optnr][2]; + ++optnr; + } + else if (optnr + 1 >= argc || argv[optnr + 1] == NULL) + usage(); + else + { + *optargp = argv[optnr + 1]; + optnr += 2; + } + } + else if (argv[optnr][2] != '\0') + usage(); + else + { + *optargp = NULL; + ++optnr; + } + + *optnrp = optnr; + + return arg; +} + + +/* + * Parse an integer option. + */ +static int parseInt(char *arg, char opt) +{ + char *endptr; + int val; + + val = strtol(arg, &endptr, 10); + + if (*arg == '\0' || *endptr != '\0') + fatal("Invalid integer argument for -%c flag\n", opt); + + return val; +} + + +/* + * Append a string to a list of them. + */ +void appendString(stringList **headp, const char *s) +{ + stringList *sl; + + /* Create the new entry. */ + + sl = sipMalloc(sizeof (stringList)); + + sl -> s = s; + sl -> next = NULL; + + /* Append it to the list. */ + + while (*headp != NULL) + headp = &(*headp) -> next; + + *headp = sl; +} + + +/* + * Display a warning message. + */ +void warning(char *fmt,...) +{ + static int start = TRUE; + + va_list ap; + + if (!warnings) + return; + + if (start) + { + fprintf(stderr,"%s: Warning: ",sipPackage); + start = FALSE; + } + + va_start(ap,fmt); + vfprintf(stderr,fmt,ap); + va_end(ap); + + if (strchr(fmt,'\n') != NULL) + start = TRUE; +} + + +/* + * Display all or part of a one line error message describing a fatal error. + * If the message is complete (it has a newline) then the program exits. + */ +void fatal(char *fmt,...) +{ + static int start = TRUE; + + va_list ap; + + if (start) + { + fprintf(stderr,"%s: ",sipPackage); + start = FALSE; + } + + va_start(ap,fmt); + vfprintf(stderr,fmt,ap); + va_end(ap); + + if (strchr(fmt,'\n') != NULL) + exit(1); +} + + +/* + * Display the SIP version number on stdout and exit with zero exit status. + */ +static void version(void) +{ + printf("%s\n",sipVersion); + exit(0); +} + + +/* + * Display the help message on stdout and exit with zero exit status. + */ +static void help(void) +{ + printf( +"Usage:\n" +" %s [-h] [-V] [-a file] [-b file] [-c dir] [-d file] [-e] [-g] [-I dir] [-j #] [-k] [-m file] [-o] [-p module] [-P] [-r] [-s suffix] [-t tag] [-w] [-x feature] [-z file] [file]\n" +"where:\n" +" -h display this help message\n" +" -V display the %s version number\n" +" -a file the name of the QScintilla API file [default not generated]\n" +" -b file the name of the build file [default none generated]\n" +" -c dir the name of the code directory [default not generated]\n" +" -d file the name of the documentation file [default not generated]\n" +" -e enable support for exceptions [default disabled]\n" +" -g always release and reacquire the GIL [default only when specified]\n" +" -I dir look in this directory when including files\n" +" -j # split the generated code into # files [default 1 per class]\n" +" -k support keyword arguments in functions and methods\n" +" -m file the name of the XML export file [default not generated]\n" +" -o enable the automatic generation of docstrings [default disabled]\n" +" -p module the name of the consolidated module that this is a component of\n" +" -P enable the protected/public hack\n" +" -r generate code with tracing enabled [default disabled]\n" +" -s suffix the suffix to use for C or C++ source files [default \".c\" or \".cpp\"]\n" +" -t tag the version/platform to generate code for\n" +" -w enable warning messages\n" +" -x feature this feature is disabled\n" +" -z file the name of a file containing more command line flags\n" +" file the name of the specification file [default stdin]\n" + , sipPackage, sipPackage); + + exit(0); +} + + +/* + * Display the usage message. + */ +static void usage(void) +{ + fatal("Usage: %s [-h] [-V] [-a file] [-b file] [-c dir] [-d file] [-e] [-g] [-I dir] [-j #] [-k] [-m file] [-o] [-p module] [-P] [-r] [-s suffix] [-t tag] [-w] [-x feature] [-z file] [file]\n", sipPackage); +} diff --git a/sipgen/parser.c b/sipgen/parser.c new file mode 100644 index 0000000..5c51d1d --- /dev/null +++ b/sipgen/parser.c @@ -0,0 +1,9975 @@ + +/* A Bison parser, made by GNU Bison 2.4.1. */ + +/* Skeleton implementation for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.4.1" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + +/* Using locations. */ +#define YYLSP_NEEDED 0 + + + +/* Copy the first part of user declarations. */ + +/* Line 189 of yacc.c */ +#line 19 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + +#include <stdlib.h> +#include <string.h> +#include <ctype.h> + +#include "sip.h" + + +#define MAX_NESTED_IF 10 +#define MAX_NESTED_SCOPE 10 + +#define inMainModule() (currentSpec->module == currentModule || currentModule->container != NULL) + + +static sipSpec *currentSpec; /* The current spec being parsed. */ +static stringList *neededQualifiers; /* The list of required qualifiers. */ +static stringList *excludedQualifiers; /* The list of excluded qualifiers. */ +static moduleDef *currentModule; /* The current module being parsed. */ +static mappedTypeDef *currentMappedType; /* The current mapped type. */ +static enumDef *currentEnum; /* The current enum being parsed. */ +static int sectionFlags; /* The current section flags. */ +static int currentOverIsVirt; /* Set if the overload is virtual. */ +static int currentCtorIsExplicit; /* Set if the ctor is explicit. */ +static int currentIsStatic; /* Set if the current is static. */ +static int currentIsSignal; /* Set if the current is Q_SIGNAL. */ +static int currentIsSlot; /* Set if the current is Q_SLOT. */ +static int currentIsTemplate; /* Set if the current is a template. */ +static char *previousFile; /* The file just parsed. */ +static parserContext currentContext; /* The current context. */ +static int skipStackPtr; /* The skip stack pointer. */ +static int skipStack[MAX_NESTED_IF]; /* Stack of skip flags. */ +static classDef *scopeStack[MAX_NESTED_SCOPE]; /* The scope stack. */ +static int sectFlagsStack[MAX_NESTED_SCOPE]; /* The section flags stack. */ +static int currentScopeIdx; /* The scope stack index. */ +static int currentTimelineOrder; /* The current timeline order. */ +static classList *currentSupers; /* The current super-class list. */ +static int defaultKwdArgs; /* Support keyword arguments by default. */ +static int makeProtPublic; /* Treat protected items as public. */ + + +static const char *getPythonName(optFlags *optflgs, const char *cname); +static classDef *findClass(sipSpec *pt, ifaceFileType iftype, + apiVersionRangeDef *api_range, scopedNameDef *fqname); +static classDef *findClassWithInterface(sipSpec *pt, ifaceFileDef *iff); +static classDef *newClass(sipSpec *pt, ifaceFileType iftype, + apiVersionRangeDef *api_range, scopedNameDef *snd); +static void finishClass(sipSpec *, moduleDef *, classDef *, optFlags *); +static exceptionDef *findException(sipSpec *pt, scopedNameDef *fqname, int new); +static mappedTypeDef *newMappedType(sipSpec *,argDef *, optFlags *); +static enumDef *newEnum(sipSpec *pt, moduleDef *mod, mappedTypeDef *mt_scope, + char *name, optFlags *of, int flags); +static void instantiateClassTemplate(sipSpec *pt, moduleDef *mod, classDef *scope, scopedNameDef *fqname, classTmplDef *tcd, templateDef *td); +static void newTypedef(sipSpec *, moduleDef *, char *, argDef *, optFlags *); +static void newVar(sipSpec *, moduleDef *, char *, int, argDef *, optFlags *, + codeBlock *, codeBlock *, codeBlock *); +static void newCtor(char *, int, signatureDef *, optFlags *, codeBlock *, + throwArgs *, signatureDef *, int, codeBlock *); +static void newFunction(sipSpec *, moduleDef *, classDef *, mappedTypeDef *, + int, int, int, int, int, char *, signatureDef *, int, int, optFlags *, + codeBlock *, codeBlock *, throwArgs *, signatureDef *, codeBlock *); +static optFlag *findOptFlag(optFlags *,char *,flagType); +static memberDef *findFunction(sipSpec *, moduleDef *, classDef *, + mappedTypeDef *, const char *, int, int, int); +static void checkAttributes(sipSpec *, moduleDef *, classDef *, + mappedTypeDef *, const char *, int); +static void newModule(FILE *fp, char *filename); +static moduleDef *allocModule(); +static void parseFile(FILE *fp, char *name, moduleDef *prevmod, int optional); +static void handleEOF(void); +static void handleEOM(void); +static qualDef *findQualifier(const char *name); +static scopedNameDef *text2scopedName(ifaceFileDef *scope, char *text); +static scopedNameDef *scopeScopedName(ifaceFileDef *scope, + scopedNameDef *name); +static void pushScope(classDef *); +static void popScope(void); +static classDef *currentScope(void); +static void newQualifier(moduleDef *,int,int,char *,qualType); +static void newImport(char *filename); +static int timePeriod(char *,char *); +static int platOrFeature(char *,int); +static int isNeeded(qualDef *); +static int notSkipping(void); +static void getHooks(optFlags *,char **,char **); +static int getTransfer(optFlags *optflgs); +static int getReleaseGIL(optFlags *optflgs); +static int getHoldGIL(optFlags *optflgs); +static int getDeprecated(optFlags *optflgs); +static int getAllowNone(optFlags *optflgs); +static const char *getDocType(optFlags *optflgs); +static const char *getDocValue(optFlags *optflgs); +static void templateSignature(signatureDef *sd, int result, classTmplDef *tcd, templateDef *td, classDef *ncd); +static void templateType(argDef *ad, classTmplDef *tcd, templateDef *td, classDef *ncd); +static int search_back(const char *end, const char *start, const char *target); +static char *type2string(argDef *ad); +static char *scopedNameToString(scopedNameDef *name); +static void addUsedFromCode(sipSpec *pt, ifaceFileList **used, const char *sname); +static int sameName(scopedNameDef *snd, const char *sname); +static int stringFind(stringList *sl, const char *s); +static void setModuleName(sipSpec *pt, moduleDef *mod, const char *fullname); +static int foundInScope(scopedNameDef *fq_name, scopedNameDef *rel_name); +static void defineClass(scopedNameDef *snd, classList *supers, optFlags *of); +static classDef *completeClass(scopedNameDef *snd, optFlags *of, int has_def); +static memberDef *instantiateTemplateMethods(memberDef *tmd, moduleDef *mod); +static void instantiateTemplateEnums(sipSpec *pt, classTmplDef *tcd, + templateDef *td, classDef *cd, ifaceFileList **used, + scopedNameDef *type_names, scopedNameDef *type_values); +static void instantiateTemplateVars(sipSpec *pt, classTmplDef *tcd, + templateDef *td, classDef *cd, ifaceFileList **used, + scopedNameDef *type_names, scopedNameDef *type_values); +static overDef *instantiateTemplateOverloads(sipSpec *pt, overDef *tod, + memberDef *tmethods, memberDef *methods, classTmplDef *tcd, + templateDef *td, classDef *cd, ifaceFileList **used, + scopedNameDef *type_names, scopedNameDef *type_values); +static void resolveAnyTypedef(sipSpec *pt, argDef *ad); +static void addVariable(sipSpec *pt, varDef *vd); +static void applyTypeFlags(moduleDef *mod, argDef *ad, optFlags *flags); +static argType convertEncoding(const char *encoding); +static apiVersionRangeDef *getAPIRange(optFlags *optflgs); +static apiVersionRangeDef *convertAPIRange(moduleDef *mod, nameDef *name, + int from, int to); +static char *convertFeaturedString(char *fs); +static scopedNameDef *text2scopePart(char *text); +static int usesKeywordArgs(optFlags *optflgs, signatureDef *sd); +static char *strip(char *s); +static int isEnabledFeature(const char *name); + + +/* Line 189 of yacc.c */ +#line 202 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.c" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + TK_API = 258, + TK_DEFENCODING = 259, + TK_PLUGIN = 260, + TK_DOCSTRING = 261, + TK_DOC = 262, + TK_EXPORTEDDOC = 263, + TK_MAKEFILE = 264, + TK_ACCESSCODE = 265, + TK_GETCODE = 266, + TK_SETCODE = 267, + TK_PREINITCODE = 268, + TK_INITCODE = 269, + TK_POSTINITCODE = 270, + TK_UNITCODE = 271, + TK_MODCODE = 272, + TK_TYPECODE = 273, + TK_PREPYCODE = 274, + TK_COPYING = 275, + TK_MAPPEDTYPE = 276, + TK_CODELINE = 277, + TK_IF = 278, + TK_END = 279, + TK_NAME = 280, + TK_PATHNAME = 281, + TK_STRING = 282, + TK_VIRTUALCATCHERCODE = 283, + TK_TRAVERSECODE = 284, + TK_CLEARCODE = 285, + TK_GETBUFFERCODE = 286, + TK_RELEASEBUFFERCODE = 287, + TK_READBUFFERCODE = 288, + TK_WRITEBUFFERCODE = 289, + TK_SEGCOUNTCODE = 290, + TK_CHARBUFFERCODE = 291, + TK_PICKLECODE = 292, + TK_METHODCODE = 293, + TK_FROMTYPE = 294, + TK_TOTYPE = 295, + TK_TOSUBCLASS = 296, + TK_INCLUDE = 297, + TK_OPTINCLUDE = 298, + TK_IMPORT = 299, + TK_EXPHEADERCODE = 300, + TK_MODHEADERCODE = 301, + TK_TYPEHEADERCODE = 302, + TK_MODULE = 303, + TK_CMODULE = 304, + TK_CONSMODULE = 305, + TK_COMPOMODULE = 306, + TK_CLASS = 307, + TK_STRUCT = 308, + TK_PUBLIC = 309, + TK_PROTECTED = 310, + TK_PRIVATE = 311, + TK_SIGNALS = 312, + TK_SIGNAL_METHOD = 313, + TK_SLOTS = 314, + TK_SLOT_METHOD = 315, + TK_BOOL = 316, + TK_SHORT = 317, + TK_INT = 318, + TK_LONG = 319, + TK_FLOAT = 320, + TK_DOUBLE = 321, + TK_CHAR = 322, + TK_WCHAR_T = 323, + TK_VOID = 324, + TK_PYOBJECT = 325, + TK_PYTUPLE = 326, + TK_PYLIST = 327, + TK_PYDICT = 328, + TK_PYCALLABLE = 329, + TK_PYSLICE = 330, + TK_PYTYPE = 331, + TK_VIRTUAL = 332, + TK_ENUM = 333, + TK_SIGNED = 334, + TK_UNSIGNED = 335, + TK_SCOPE = 336, + TK_LOGICAL_OR = 337, + TK_CONST = 338, + TK_STATIC = 339, + TK_SIPSIGNAL = 340, + TK_SIPSLOT = 341, + TK_SIPANYSLOT = 342, + TK_SIPRXCON = 343, + TK_SIPRXDIS = 344, + TK_SIPSLOTCON = 345, + TK_SIPSLOTDIS = 346, + TK_NUMBER = 347, + TK_REAL = 348, + TK_TYPEDEF = 349, + TK_NAMESPACE = 350, + TK_TIMELINE = 351, + TK_PLATFORMS = 352, + TK_FEATURE = 353, + TK_LICENSE = 354, + TK_QCHAR = 355, + TK_TRUE = 356, + TK_FALSE = 357, + TK_NULL = 358, + TK_OPERATOR = 359, + TK_THROW = 360, + TK_QOBJECT = 361, + TK_EXCEPTION = 362, + TK_RAISECODE = 363, + TK_EXPLICIT = 364, + TK_TEMPLATE = 365, + TK_ELLIPSIS = 366, + TK_DEFMETATYPE = 367, + TK_DEFSUPERTYPE = 368 + }; +#endif +/* Tokens. */ +#define TK_API 258 +#define TK_DEFENCODING 259 +#define TK_PLUGIN 260 +#define TK_DOCSTRING 261 +#define TK_DOC 262 +#define TK_EXPORTEDDOC 263 +#define TK_MAKEFILE 264 +#define TK_ACCESSCODE 265 +#define TK_GETCODE 266 +#define TK_SETCODE 267 +#define TK_PREINITCODE 268 +#define TK_INITCODE 269 +#define TK_POSTINITCODE 270 +#define TK_UNITCODE 271 +#define TK_MODCODE 272 +#define TK_TYPECODE 273 +#define TK_PREPYCODE 274 +#define TK_COPYING 275 +#define TK_MAPPEDTYPE 276 +#define TK_CODELINE 277 +#define TK_IF 278 +#define TK_END 279 +#define TK_NAME 280 +#define TK_PATHNAME 281 +#define TK_STRING 282 +#define TK_VIRTUALCATCHERCODE 283 +#define TK_TRAVERSECODE 284 +#define TK_CLEARCODE 285 +#define TK_GETBUFFERCODE 286 +#define TK_RELEASEBUFFERCODE 287 +#define TK_READBUFFERCODE 288 +#define TK_WRITEBUFFERCODE 289 +#define TK_SEGCOUNTCODE 290 +#define TK_CHARBUFFERCODE 291 +#define TK_PICKLECODE 292 +#define TK_METHODCODE 293 +#define TK_FROMTYPE 294 +#define TK_TOTYPE 295 +#define TK_TOSUBCLASS 296 +#define TK_INCLUDE 297 +#define TK_OPTINCLUDE 298 +#define TK_IMPORT 299 +#define TK_EXPHEADERCODE 300 +#define TK_MODHEADERCODE 301 +#define TK_TYPEHEADERCODE 302 +#define TK_MODULE 303 +#define TK_CMODULE 304 +#define TK_CONSMODULE 305 +#define TK_COMPOMODULE 306 +#define TK_CLASS 307 +#define TK_STRUCT 308 +#define TK_PUBLIC 309 +#define TK_PROTECTED 310 +#define TK_PRIVATE 311 +#define TK_SIGNALS 312 +#define TK_SIGNAL_METHOD 313 +#define TK_SLOTS 314 +#define TK_SLOT_METHOD 315 +#define TK_BOOL 316 +#define TK_SHORT 317 +#define TK_INT 318 +#define TK_LONG 319 +#define TK_FLOAT 320 +#define TK_DOUBLE 321 +#define TK_CHAR 322 +#define TK_WCHAR_T 323 +#define TK_VOID 324 +#define TK_PYOBJECT 325 +#define TK_PYTUPLE 326 +#define TK_PYLIST 327 +#define TK_PYDICT 328 +#define TK_PYCALLABLE 329 +#define TK_PYSLICE 330 +#define TK_PYTYPE 331 +#define TK_VIRTUAL 332 +#define TK_ENUM 333 +#define TK_SIGNED 334 +#define TK_UNSIGNED 335 +#define TK_SCOPE 336 +#define TK_LOGICAL_OR 337 +#define TK_CONST 338 +#define TK_STATIC 339 +#define TK_SIPSIGNAL 340 +#define TK_SIPSLOT 341 +#define TK_SIPANYSLOT 342 +#define TK_SIPRXCON 343 +#define TK_SIPRXDIS 344 +#define TK_SIPSLOTCON 345 +#define TK_SIPSLOTDIS 346 +#define TK_NUMBER 347 +#define TK_REAL 348 +#define TK_TYPEDEF 349 +#define TK_NAMESPACE 350 +#define TK_TIMELINE 351 +#define TK_PLATFORMS 352 +#define TK_FEATURE 353 +#define TK_LICENSE 354 +#define TK_QCHAR 355 +#define TK_TRUE 356 +#define TK_FALSE 357 +#define TK_NULL 358 +#define TK_OPERATOR 359 +#define TK_THROW 360 +#define TK_QOBJECT 361 +#define TK_EXCEPTION 362 +#define TK_RAISECODE 363 +#define TK_EXPLICIT 364 +#define TK_TEMPLATE 365 +#define TK_ELLIPSIS 366 +#define TK_DEFMETATYPE 367 +#define TK_DEFSUPERTYPE 368 + + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ + +/* Line 214 of yacc.c */ +#line 147 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + + char qchar; + char *text; + long number; + double real; + argDef memArg; + signatureDef signature; + signatureDef *optsignature; + throwArgs *throwlist; + codeBlock *codeb; + valueDef value; + valueDef *valp; + optFlags optflags; + optFlag flag; + scopedNameDef *scpvalp; + fcallDef fcall; + int boolean; + exceptionDef exceptionbase; + classDef *klass; + + + +/* Line 214 of yacc.c */ +#line 487 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.c" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + + +/* Copy the second part of user declarations. */ + + +/* Line 264 of yacc.c */ +#line 499 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.c" + +#ifdef short +# undef short +#endif + +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else +typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; +#elif (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +typedef signed char yytype_int8; +#else +typedef short int yytype_int8; +#endif + +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; +#else +typedef unsigned short int yytype_uint16; +#endif + +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned int +# endif +#endif + +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) + +#ifndef YY_ +# if YYENABLE_NLS +# if ENABLE_NLS +# include <libintl.h> /* INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(e) ((void) (e)) +#else +# define YYUSE(e) /* empty */ +#endif + +/* Identity function, used to suppress warnings about constant conditions. */ +#ifndef lint +# define YYID(n) (n) +#else +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static int +YYID (int yyi) +#else +static int +YYID (yyi) + int yyi; +#endif +{ + return yyi; +} +#endif + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include <alloca.h> /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include <malloc.h> /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined _STDLIB_H \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (YYID (0)) + +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 4 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 1193 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 136 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 151 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 372 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 637 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 368 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const yytype_uint8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 119, 2, 2, 2, 134, 126, 2, + 117, 118, 124, 123, 121, 120, 2, 125, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 131, 116, + 129, 122, 130, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 132, 2, 133, 135, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 114, 127, 115, 128, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, + 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, + 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, 113 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const yytype_uint16 yyprhs[] = +{ + 0, 0, 3, 5, 8, 9, 12, 14, 16, 18, + 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, + 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, + 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, + 80, 82, 84, 86, 88, 90, 92, 94, 96, 99, + 102, 106, 116, 117, 121, 124, 125, 131, 132, 139, + 144, 146, 149, 151, 154, 157, 159, 161, 175, 176, + 184, 186, 189, 190, 196, 198, 201, 203, 206, 207, + 213, 215, 218, 220, 225, 227, 230, 234, 239, 241, + 245, 247, 250, 253, 256, 259, 262, 266, 268, 270, + 272, 274, 275, 277, 280, 283, 286, 287, 290, 291, + 294, 295, 298, 301, 304, 307, 310, 311, 313, 316, + 319, 322, 325, 328, 331, 334, 337, 340, 343, 346, + 349, 352, 355, 358, 361, 364, 367, 372, 375, 377, + 380, 381, 390, 391, 393, 394, 396, 397, 399, 401, + 404, 406, 408, 413, 414, 416, 417, 420, 421, 424, + 426, 430, 432, 434, 436, 438, 440, 442, 443, 445, + 447, 449, 451, 454, 456, 460, 462, 464, 469, 471, + 473, 475, 477, 479, 481, 483, 484, 486, 490, 496, + 508, 509, 510, 519, 520, 524, 529, 530, 531, 540, + 541, 544, 546, 550, 552, 553, 557, 559, 562, 564, + 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, + 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, + 606, 608, 611, 614, 618, 622, 626, 629, 630, 632, + 644, 645, 649, 651, 662, 663, 669, 670, 677, 678, + 680, 695, 703, 718, 732, 734, 736, 738, 740, 742, + 744, 746, 748, 751, 754, 757, 760, 763, 766, 769, + 772, 775, 778, 782, 786, 788, 791, 794, 796, 799, + 802, 805, 807, 810, 811, 813, 814, 817, 818, 822, + 824, 828, 830, 834, 836, 842, 844, 846, 849, 850, + 852, 853, 856, 857, 860, 862, 863, 865, 869, 874, + 879, 884, 888, 892, 899, 906, 910, 913, 914, 918, + 919, 923, 925, 926, 930, 932, 934, 936, 937, 941, + 943, 951, 956, 960, 964, 965, 967, 968, 971, 973, + 978, 981, 984, 986, 988, 991, 993, 995, 998, 1001, + 1005, 1007, 1009, 1011, 1014, 1017, 1019, 1021, 1023, 1025, + 1027, 1029, 1031, 1033, 1035, 1037, 1039, 1041, 1045, 1046, + 1051, 1052, 1054 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yytype_int16 yyrhs[] = +{ + 137, 0, -1, 138, -1, 137, 138, -1, -1, 139, + 140, -1, 177, -1, 175, -1, 176, -1, 143, -1, + 187, -1, 181, -1, 182, -1, 183, -1, 144, -1, + 164, -1, 159, -1, 163, -1, 172, -1, 142, -1, + 173, -1, 174, -1, 188, -1, 189, -1, 201, -1, + 203, -1, 204, -1, 205, -1, 206, -1, 207, -1, + 208, -1, 209, -1, 210, -1, 148, -1, 150, -1, + 141, -1, 168, -1, 171, -1, 156, -1, 232, -1, + 238, -1, 235, -1, 145, -1, 231, -1, 213, -1, + 255, -1, 278, -1, 190, -1, 4, 27, -1, 5, + 25, -1, 3, 25, 92, -1, 107, 227, 146, 259, + 114, 191, 147, 115, 116, -1, -1, 117, 227, 118, + -1, 108, 211, -1, -1, 21, 283, 259, 149, 152, + -1, -1, 237, 21, 283, 259, 151, 152, -1, 114, + 153, 115, 116, -1, 154, -1, 153, 154, -1, 190, + -1, 39, 211, -1, 40, 211, -1, 213, -1, 155, + -1, 84, 279, 25, 117, 267, 118, 257, 285, 259, + 253, 116, 264, 265, -1, -1, 95, 25, 157, 114, + 158, 115, 116, -1, 141, -1, 158, 141, -1, -1, + 97, 160, 114, 161, 115, -1, 162, -1, 161, 162, + -1, 25, -1, 98, 25, -1, -1, 96, 165, 114, + 166, 115, -1, 167, -1, 166, 167, -1, 25, -1, + 23, 117, 170, 118, -1, 25, -1, 119, 25, -1, + 169, 82, 25, -1, 169, 82, 119, 25, -1, 169, + -1, 216, 120, 216, -1, 24, -1, 99, 259, -1, + 112, 179, -1, 113, 179, -1, 50, 179, -1, 51, + 179, -1, 178, 179, 180, -1, 48, -1, 49, -1, + 25, -1, 26, -1, -1, 92, -1, 42, 26, -1, + 43, 26, -1, 44, 26, -1, -1, 10, 211, -1, + -1, 11, 211, -1, -1, 12, 211, -1, 20, 211, + -1, 45, 211, -1, 46, 211, -1, 47, 211, -1, + -1, 190, -1, 29, 211, -1, 30, 211, -1, 31, + 211, -1, 32, 211, -1, 33, 211, -1, 34, 211, + -1, 35, 211, -1, 36, 211, -1, 37, 211, -1, + 17, 211, -1, 18, 211, -1, 13, 211, -1, 14, + 211, -1, 15, 211, -1, 16, 211, -1, 19, 211, + -1, 7, 211, -1, 8, 211, -1, 9, 26, 215, + 211, -1, 212, 24, -1, 22, -1, 212, 22, -1, + -1, 78, 216, 259, 214, 114, 217, 115, 116, -1, + -1, 26, -1, -1, 25, -1, -1, 218, -1, 219, + -1, 218, 219, -1, 168, -1, 171, -1, 25, 221, + 259, 220, -1, -1, 121, -1, -1, 122, 226, -1, + -1, 122, 223, -1, 226, -1, 223, 224, 226, -1, + 120, -1, 123, -1, 124, -1, 125, -1, 126, -1, + 127, -1, -1, 119, -1, 128, -1, 120, -1, 123, + -1, 225, 229, -1, 228, -1, 227, 81, 228, -1, + 25, -1, 227, -1, 283, 117, 230, 118, -1, 93, + -1, 92, -1, 101, -1, 102, -1, 103, -1, 27, + -1, 100, -1, -1, 223, -1, 230, 121, 223, -1, + 94, 279, 25, 259, 116, -1, 94, 279, 117, 282, + 25, 118, 117, 284, 118, 259, 116, -1, -1, -1, + 53, 227, 233, 241, 259, 234, 244, 116, -1, -1, + 237, 236, 238, -1, 110, 129, 284, 130, -1, -1, + -1, 52, 227, 239, 241, 259, 240, 244, 116, -1, + -1, 131, 242, -1, 243, -1, 242, 121, 243, -1, + 227, -1, -1, 114, 245, 115, -1, 246, -1, 245, + 246, -1, 168, -1, 171, -1, 156, -1, 232, -1, + 238, -1, 145, -1, 231, -1, 213, -1, 263, -1, + 202, -1, 190, -1, 192, -1, 193, -1, 194, -1, + 195, -1, 196, -1, 197, -1, 198, -1, 199, -1, + 200, -1, 249, -1, 248, -1, 270, -1, 41, 211, + -1, 40, 211, -1, 54, 247, 131, -1, 55, 247, + 131, -1, 56, 247, 131, -1, 57, 131, -1, -1, + 59, -1, 254, 128, 25, 117, 118, 285, 258, 259, + 116, 265, 266, -1, -1, 109, 250, 251, -1, 251, + -1, 25, 117, 267, 118, 285, 259, 252, 116, 264, + 265, -1, -1, 132, 117, 267, 118, 133, -1, -1, + 132, 279, 117, 267, 118, 133, -1, -1, 77, -1, + 279, 25, 117, 267, 118, 257, 285, 258, 259, 253, + 116, 264, 265, 266, -1, 279, 104, 122, 117, 279, + 118, 116, -1, 279, 104, 256, 117, 267, 118, 257, + 285, 258, 259, 253, 116, 265, 266, -1, 104, 279, + 117, 267, 118, 257, 285, 258, 259, 253, 116, 265, + 266, -1, 123, -1, 120, -1, 124, -1, 125, -1, + 134, -1, 126, -1, 127, -1, 135, -1, 129, 129, + -1, 130, 130, -1, 123, 122, -1, 120, 122, -1, + 124, 122, -1, 125, 122, -1, 134, 122, -1, 126, + 122, -1, 127, 122, -1, 135, 122, -1, 129, 129, + 122, -1, 130, 130, 122, -1, 128, -1, 117, 118, + -1, 132, 133, -1, 129, -1, 129, 122, -1, 122, + 122, -1, 119, 122, -1, 130, -1, 130, 122, -1, + -1, 83, -1, -1, 122, 92, -1, -1, 125, 260, + 125, -1, 261, -1, 260, 121, 261, -1, 25, -1, + 25, 122, 262, -1, 179, -1, 25, 131, 180, 120, + 180, -1, 27, -1, 92, -1, 6, 211, -1, -1, + 263, -1, -1, 38, 211, -1, -1, 28, 211, -1, + 268, -1, -1, 269, -1, 268, 121, 269, -1, 85, + 216, 259, 222, -1, 86, 216, 259, 222, -1, 87, + 216, 259, 222, -1, 88, 216, 259, -1, 89, 216, + 259, -1, 90, 117, 267, 118, 216, 259, -1, 91, + 117, 267, 118, 216, 259, -1, 106, 216, 259, -1, + 280, 222, -1, -1, 58, 271, 273, -1, -1, 60, + 272, 273, -1, 273, -1, -1, 84, 274, 275, -1, + 275, -1, 276, -1, 278, -1, -1, 77, 277, 255, + -1, 255, -1, 279, 25, 259, 116, 184, 185, 186, + -1, 83, 283, 282, 281, -1, 283, 282, 281, -1, + 279, 216, 259, -1, -1, 126, -1, -1, 282, 124, + -1, 227, -1, 227, 129, 284, 130, -1, 53, 227, + -1, 80, 62, -1, 62, -1, 80, -1, 80, 63, + -1, 63, -1, 64, -1, 80, 64, -1, 64, 64, + -1, 80, 64, 64, -1, 65, -1, 66, -1, 61, + -1, 79, 67, -1, 80, 67, -1, 67, -1, 68, + -1, 69, -1, 70, -1, 71, -1, 72, -1, 73, + -1, 74, -1, 75, -1, 76, -1, 111, -1, 279, + -1, 284, 121, 279, -1, -1, 105, 117, 286, 118, + -1, -1, 227, -1, 286, 121, 227, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = +{ + 0, 350, 350, 351, 354, 354, 373, 374, 375, 376, + 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, + 387, 388, 389, 393, 397, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 414, 415, 416, 417, + 418, 419, 420, 421, 422, 423, 424, 425, 438, 447, + 452, 478, 517, 521, 595, 600, 600, 606, 606, 656, + 670, 671, 674, 678, 687, 696, 697, 700, 714, 714, + 751, 752, 755, 755, 782, 783, 786, 791, 796, 796, + 821, 822, 825, 830, 843, 846, 849, 852, 857, 858, + 863, 869, 896, 907, 918, 931, 944, 977, 980, 985, + 986, 1002, 1005, 1008, 1013, 1018, 1023, 1026, 1031, 1034, + 1039, 1042, 1047, 1052, 1057, 1062, 1067, 1070, 1073, 1078, + 1083, 1088, 1093, 1098, 1103, 1108, 1113, 1118, 1123, 1128, + 1134, 1140, 1146, 1152, 1161, 1167, 1172, 1178, 1181, 1182, + 1193, 1193, 1205, 1208, 1213, 1216, 1221, 1222, 1225, 1226, + 1229, 1230, 1231, 1259, 1260, 1263, 1264, 1267, 1270, 1275, + 1276, 1294, 1297, 1300, 1303, 1306, 1309, 1314, 1317, 1320, + 1323, 1326, 1331, 1349, 1350, 1358, 1363, 1372, 1382, 1386, + 1390, 1394, 1398, 1402, 1406, 1412, 1417, 1423, 1441, 1448, + 1473, 1479, 1473, 1494, 1494, 1520, 1525, 1531, 1525, 1543, + 1544, 1547, 1548, 1551, 1590, 1593, 1598, 1599, 1602, 1603, + 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1620, 1624, 1628, + 1639, 1650, 1661, 1672, 1683, 1694, 1705, 1716, 1727, 1728, + 1729, 1730, 1741, 1752, 1759, 1766, 1773, 1782, 1785, 1790, + 1844, 1844, 1845, 1848, 1875, 1878, 1885, 1888, 1896, 1899, + 1904, 1922, 1942, 1971, 2049, 2050, 2051, 2052, 2053, 2054, + 2055, 2056, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2064, + 2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, + 2075, 2076, 2077, 2080, 2083, 2088, 2091, 2099, 2102, 2108, + 2112, 2124, 2128, 2134, 2138, 2161, 2165, 2171, 2176, 2179, + 2182, 2185, 2190, 2193, 2198, 2246, 2251, 2257, 2284, 2293, + 2302, 2311, 2322, 2330, 2344, 2358, 2364, 2371, 2371, 2372, + 2372, 2373, 2377, 2377, 2378, 2382, 2383, 2387, 2387, 2388, + 2391, 2426, 2431, 2438, 2510, 2513, 2521, 2524, 2529, 2537, + 2548, 2563, 2567, 2571, 2575, 2579, 2583, 2587, 2591, 2595, + 2599, 2603, 2607, 2611, 2615, 2619, 2623, 2627, 2631, 2635, + 2639, 2643, 2647, 2651, 2655, 2659, 2665, 2671, 2687, 2690, + 2698, 2704, 2711 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "TK_API", "TK_DEFENCODING", "TK_PLUGIN", + "TK_DOCSTRING", "TK_DOC", "TK_EXPORTEDDOC", "TK_MAKEFILE", + "TK_ACCESSCODE", "TK_GETCODE", "TK_SETCODE", "TK_PREINITCODE", + "TK_INITCODE", "TK_POSTINITCODE", "TK_UNITCODE", "TK_MODCODE", + "TK_TYPECODE", "TK_PREPYCODE", "TK_COPYING", "TK_MAPPEDTYPE", + "TK_CODELINE", "TK_IF", "TK_END", "TK_NAME", "TK_PATHNAME", "TK_STRING", + "TK_VIRTUALCATCHERCODE", "TK_TRAVERSECODE", "TK_CLEARCODE", + "TK_GETBUFFERCODE", "TK_RELEASEBUFFERCODE", "TK_READBUFFERCODE", + "TK_WRITEBUFFERCODE", "TK_SEGCOUNTCODE", "TK_CHARBUFFERCODE", + "TK_PICKLECODE", "TK_METHODCODE", "TK_FROMTYPE", "TK_TOTYPE", + "TK_TOSUBCLASS", "TK_INCLUDE", "TK_OPTINCLUDE", "TK_IMPORT", + "TK_EXPHEADERCODE", "TK_MODHEADERCODE", "TK_TYPEHEADERCODE", "TK_MODULE", + "TK_CMODULE", "TK_CONSMODULE", "TK_COMPOMODULE", "TK_CLASS", "TK_STRUCT", + "TK_PUBLIC", "TK_PROTECTED", "TK_PRIVATE", "TK_SIGNALS", + "TK_SIGNAL_METHOD", "TK_SLOTS", "TK_SLOT_METHOD", "TK_BOOL", "TK_SHORT", + "TK_INT", "TK_LONG", "TK_FLOAT", "TK_DOUBLE", "TK_CHAR", "TK_WCHAR_T", + "TK_VOID", "TK_PYOBJECT", "TK_PYTUPLE", "TK_PYLIST", "TK_PYDICT", + "TK_PYCALLABLE", "TK_PYSLICE", "TK_PYTYPE", "TK_VIRTUAL", "TK_ENUM", + "TK_SIGNED", "TK_UNSIGNED", "TK_SCOPE", "TK_LOGICAL_OR", "TK_CONST", + "TK_STATIC", "TK_SIPSIGNAL", "TK_SIPSLOT", "TK_SIPANYSLOT", + "TK_SIPRXCON", "TK_SIPRXDIS", "TK_SIPSLOTCON", "TK_SIPSLOTDIS", + "TK_NUMBER", "TK_REAL", "TK_TYPEDEF", "TK_NAMESPACE", "TK_TIMELINE", + "TK_PLATFORMS", "TK_FEATURE", "TK_LICENSE", "TK_QCHAR", "TK_TRUE", + "TK_FALSE", "TK_NULL", "TK_OPERATOR", "TK_THROW", "TK_QOBJECT", + "TK_EXCEPTION", "TK_RAISECODE", "TK_EXPLICIT", "TK_TEMPLATE", + "TK_ELLIPSIS", "TK_DEFMETATYPE", "TK_DEFSUPERTYPE", "'{'", "'}'", "';'", + "'('", "')'", "'!'", "'-'", "','", "'='", "'+'", "'*'", "'/'", "'&'", + "'|'", "'~'", "'<'", "'>'", "':'", "'['", "']'", "'%'", "'^'", "$accept", + "specification", "statement", "$@1", "modstatement", "nsstatement", + "defencoding", "plugin", "api", "exception", "baseexception", + "raisecode", "mappedtype", "$@2", "mappedtypetmpl", "$@3", + "mtdefinition", "mtbody", "mtline", "mtfunction", "namespace", "$@4", + "nsbody", "platforms", "$@5", "platformlist", "platform", "feature", + "timeline", "$@6", "qualifierlist", "qualifiername", "ifstart", + "oredqualifiers", "qualifiers", "ifend", "license", "defmetatype", + "defsupertype", "consmodule", "compmodule", "module", "modlang", + "dottedname", "optnumber", "include", "optinclude", "import", + "optaccesscode", "optgetcode", "optsetcode", "copying", "exphdrcode", + "modhdrcode", "typehdrcode", "opttypehdrcode", "travcode", "clearcode", + "getbufcode", "releasebufcode", "readbufcode", "writebufcode", + "segcountcode", "charbufcode", "picklecode", "modcode", "typecode", + "preinitcode", "initcode", "postinitcode", "unitcode", "prepycode", + "doc", "exporteddoc", "makefile", "codeblock", "codelines", "enum", + "$@7", "optfilename", "optname", "optenumbody", "enumbody", "enumline", + "optcomma", "optenumassign", "optassign", "expr", "binop", "optunop", + "value", "scopedname", "scopepart", "simplevalue", "exprlist", "typedef", + "struct", "$@8", "$@9", "classtmpl", "$@10", "template", "class", "$@11", + "$@12", "superclasses", "superlist", "superclass", "optclassbody", + "classbody", "classline", "optslot", "dtor", "ctor", "$@13", + "simplector", "optctorsig", "optsig", "optvirtual", "function", + "operatorname", "optconst", "optabstract", "optflags", "flaglist", + "flag", "flagvalue", "docstring", "optdocstring", "methodcode", + "virtualcatchercode", "arglist", "rawarglist", "argvalue", "varmember", + "$@14", "$@15", "simple_varmem", "$@16", "varmem", "member", "$@17", + "variable", "cpptype", "argtype", "optref", "deref", "basetype", + "cpptypelist", "optexceptions", "exceptionlist", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const yytype_uint16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, + 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, + 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, + 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, + 365, 366, 367, 368, 123, 125, 59, 40, 41, 33, + 45, 44, 61, 43, 42, 47, 38, 124, 126, 60, + 62, 58, 91, 93, 37, 94 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint16 yyr1[] = +{ + 0, 136, 137, 137, 139, 138, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 140, 141, 141, 141, 141, + 141, 141, 141, 141, 141, 141, 141, 141, 142, 143, + 144, 145, 146, 146, 147, 149, 148, 151, 150, 152, + 153, 153, 154, 154, 154, 154, 154, 155, 157, 156, + 158, 158, 160, 159, 161, 161, 162, 163, 165, 164, + 166, 166, 167, 168, 169, 169, 169, 169, 170, 170, + 171, 172, 173, 174, 175, 176, 177, 178, 178, 179, + 179, 180, 180, 181, 182, 183, 184, 184, 185, 185, + 186, 186, 187, 188, 189, 190, 191, 191, 192, 193, + 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, + 204, 205, 206, 207, 208, 209, 210, 211, 212, 212, + 214, 213, 215, 215, 216, 216, 217, 217, 218, 218, + 219, 219, 219, 220, 220, 221, 221, 222, 222, 223, + 223, 224, 224, 224, 224, 224, 224, 225, 225, 225, + 225, 225, 226, 227, 227, 228, 229, 229, 229, 229, + 229, 229, 229, 229, 229, 230, 230, 230, 231, 231, + 233, 234, 232, 236, 235, 237, 239, 240, 238, 241, + 241, 242, 242, 243, 244, 244, 245, 245, 246, 246, + 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, + 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, + 246, 246, 246, 246, 246, 246, 246, 247, 247, 248, + 250, 249, 249, 251, 252, 252, 253, 253, 254, 254, + 255, 255, 255, 255, 256, 256, 256, 256, 256, 256, + 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, + 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, + 256, 256, 256, 257, 257, 258, 258, 259, 259, 260, + 260, 261, 261, 262, 262, 262, 262, 263, 264, 264, + 265, 265, 266, 266, 267, 268, 268, 268, 269, 269, + 269, 269, 269, 269, 269, 269, 269, 271, 270, 272, + 270, 270, 274, 273, 273, 275, 275, 277, 276, 276, + 278, 279, 279, 280, 281, 281, 282, 282, 283, 283, + 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, + 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, + 283, 283, 283, 283, 283, 283, 284, 284, 285, 285, + 286, 286, 286 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 1, 2, 0, 2, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, + 3, 9, 0, 3, 2, 0, 5, 0, 6, 4, + 1, 2, 1, 2, 2, 1, 1, 13, 0, 7, + 1, 2, 0, 5, 1, 2, 1, 2, 0, 5, + 1, 2, 1, 4, 1, 2, 3, 4, 1, 3, + 1, 2, 2, 2, 2, 2, 3, 1, 1, 1, + 1, 0, 1, 2, 2, 2, 0, 2, 0, 2, + 0, 2, 2, 2, 2, 2, 0, 1, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 4, 2, 1, 2, + 0, 8, 0, 1, 0, 1, 0, 1, 1, 2, + 1, 1, 4, 0, 1, 0, 2, 0, 2, 1, + 3, 1, 1, 1, 1, 1, 1, 0, 1, 1, + 1, 1, 2, 1, 3, 1, 1, 4, 1, 1, + 1, 1, 1, 1, 1, 0, 1, 3, 5, 11, + 0, 0, 8, 0, 3, 4, 0, 0, 8, 0, + 2, 1, 3, 1, 0, 3, 1, 2, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 2, 3, 3, 3, 2, 0, 1, 11, + 0, 3, 1, 10, 0, 5, 0, 6, 0, 1, + 14, 7, 14, 13, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 3, 3, 1, 2, 2, 1, 2, 2, + 2, 1, 2, 0, 1, 0, 2, 0, 3, 1, + 3, 1, 3, 1, 5, 1, 1, 2, 0, 1, + 0, 2, 0, 2, 1, 0, 1, 3, 4, 4, + 4, 3, 3, 6, 6, 3, 2, 0, 3, 0, + 3, 1, 0, 3, 1, 1, 1, 0, 3, 1, + 7, 4, 3, 3, 0, 1, 0, 2, 1, 4, + 2, 2, 1, 1, 2, 1, 1, 2, 2, 3, + 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 3, 0, 4, + 0, 1, 3 +}; + +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const yytype_uint16 yydefact[] = +{ + 4, 4, 2, 0, 1, 3, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 90, 175, 0, 0, 0, 0, 0, 0, 97, + 98, 0, 0, 0, 0, 352, 342, 345, 346, 350, + 351, 355, 356, 357, 358, 359, 360, 361, 362, 363, + 364, 144, 0, 343, 0, 0, 0, 78, 72, 0, + 287, 0, 0, 0, 365, 0, 0, 5, 35, 19, + 9, 14, 42, 33, 34, 38, 16, 17, 15, 36, + 37, 18, 20, 21, 7, 8, 6, 0, 11, 12, + 13, 10, 22, 23, 47, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 44, 338, 173, 43, 39, 41, + 193, 40, 45, 46, 0, 336, 0, 48, 49, 138, + 134, 0, 135, 142, 129, 130, 131, 132, 127, 133, + 112, 0, 287, 144, 103, 104, 105, 113, 114, 115, + 99, 100, 94, 95, 196, 190, 348, 145, 287, 353, + 341, 344, 347, 354, 336, 0, 68, 0, 0, 77, + 0, 91, 0, 52, 0, 92, 93, 101, 0, 0, + 0, 0, 287, 0, 334, 50, 139, 137, 143, 0, + 340, 55, 84, 0, 88, 0, 0, 199, 199, 140, + 349, 334, 287, 336, 0, 0, 0, 291, 0, 289, + 305, 0, 287, 366, 0, 102, 96, 174, 0, 287, + 194, 305, 0, 0, 0, 255, 0, 254, 256, 257, + 259, 260, 274, 277, 281, 0, 258, 261, 0, 337, + 335, 332, 136, 0, 85, 0, 83, 144, 0, 287, + 287, 0, 331, 0, 0, 0, 82, 0, 80, 76, + 0, 74, 0, 0, 288, 144, 144, 144, 144, 144, + 0, 0, 144, 0, 304, 306, 144, 157, 0, 0, + 0, 195, 339, 57, 0, 106, 275, 280, 265, 0, + 279, 264, 266, 267, 269, 270, 278, 262, 282, 263, + 276, 268, 271, 305, 0, 56, 86, 0, 89, 203, + 200, 201, 197, 191, 146, 188, 0, 70, 0, 193, + 79, 81, 73, 75, 99, 295, 296, 293, 292, 290, + 287, 287, 287, 287, 287, 305, 305, 287, 283, 0, + 287, 167, 316, 53, 116, 367, 0, 283, 0, 108, + 0, 272, 273, 0, 0, 0, 0, 0, 60, 66, + 62, 65, 87, 0, 204, 204, 155, 150, 151, 0, + 147, 148, 0, 0, 71, 101, 157, 157, 157, 311, + 312, 0, 0, 315, 284, 368, 307, 333, 168, 170, + 171, 169, 158, 0, 159, 117, 0, 58, 368, 107, + 0, 110, 0, 283, 63, 64, 0, 0, 61, 202, + 248, 0, 0, 167, 287, 0, 149, 0, 69, 0, + 308, 309, 310, 144, 144, 0, 285, 161, 162, 163, + 164, 165, 166, 167, 183, 179, 178, 184, 180, 181, + 182, 176, 172, 0, 0, 0, 285, 109, 0, 330, + 251, 368, 0, 59, 0, 0, 175, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 237, 237, + 237, 0, 317, 319, 327, 322, 240, 213, 210, 208, + 209, 218, 219, 220, 221, 222, 223, 224, 225, 226, + 227, 217, 215, 214, 211, 212, 248, 206, 229, 228, + 242, 0, 329, 216, 230, 321, 324, 325, 326, 198, + 192, 156, 153, 141, 0, 101, 287, 287, 370, 0, + 287, 160, 167, 54, 0, 287, 111, 285, 305, 297, + 128, 305, 118, 119, 120, 121, 122, 123, 124, 125, + 126, 232, 231, 238, 0, 0, 0, 236, 0, 0, + 0, 0, 0, 205, 207, 0, 154, 152, 287, 294, + 313, 314, 371, 0, 286, 246, 186, 0, 51, 246, + 287, 0, 0, 233, 234, 235, 327, 318, 320, 328, + 0, 323, 0, 241, 0, 0, 369, 0, 0, 0, + 177, 167, 0, 246, 283, 368, 0, 0, 189, 372, + 0, 300, 187, 298, 0, 368, 287, 368, 305, 0, + 302, 299, 300, 300, 287, 244, 285, 0, 301, 0, + 253, 302, 302, 246, 0, 0, 287, 0, 303, 250, + 252, 0, 305, 298, 0, 247, 298, 0, 300, 300, + 300, 0, 243, 302, 67, 245, 239 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = +{ + -1, 1, 2, 3, 67, 68, 69, 70, 71, 72, + 202, 435, 73, 233, 74, 336, 295, 347, 348, 349, + 75, 194, 308, 76, 158, 250, 251, 77, 78, 157, + 247, 248, 79, 184, 185, 80, 81, 82, 83, 84, + 85, 86, 87, 142, 206, 88, 89, 90, 339, 391, + 439, 91, 92, 93, 94, 386, 472, 473, 474, 475, + 476, 477, 478, 479, 480, 95, 481, 96, 97, 98, + 99, 100, 101, 102, 103, 120, 121, 104, 241, 179, + 148, 359, 360, 361, 547, 404, 332, 382, 423, 383, + 384, 105, 106, 432, 557, 107, 108, 188, 355, 109, + 171, 309, 111, 187, 354, 239, 300, 301, 401, 486, + 487, 534, 488, 489, 542, 490, 615, 579, 491, 492, + 228, 375, 510, 161, 198, 199, 318, 601, 602, 600, + 610, 263, 264, 265, 494, 538, 539, 495, 541, 496, + 497, 540, 498, 266, 267, 231, 174, 115, 204, 416, + 553 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -544 +static const yytype_int16 yypact[] = +{ + -544, 62, -544, 558, -544, -544, 76, 88, 126, 144, + 144, 150, 144, 144, 144, 144, 144, 144, 144, 1082, + 87, -544, -544, 159, 183, 190, 144, 144, 144, -544, + -544, 165, 165, 189, 189, -544, -544, -544, 154, -544, + -544, -544, -544, -544, -544, -544, -544, -544, -544, -544, + -544, 203, 169, 97, 1082, 321, 212, -544, -544, 213, + 114, 321, 189, 111, -544, 165, 165, -544, -544, -544, + -544, -544, -544, -544, -544, -544, -544, -544, -544, -544, + -544, -544, -544, -544, -544, -544, -544, 165, -544, -544, + -544, -544, -544, -544, -544, -544, -544, -544, -544, -544, + -544, -544, -544, -544, -544, -26, -544, -544, -544, -544, + 220, -544, -544, -544, 9, -544, 153, -544, -544, -544, + -544, 63, -544, 216, -544, -544, -544, -544, -544, -544, + -544, 189, 114, 2, -544, -544, -544, -544, -544, -544, + -544, -544, -544, -544, 167, 8, -544, -544, 114, -544, + -544, -544, 182, -544, -544, 12, -544, 135, 138, -544, + 228, -544, 137, -18, 321, -544, -544, 164, 189, 321, + 1082, 205, -11, 395, 81, -544, -544, -544, -544, 144, + 167, -544, 139, 235, 179, 145, 146, 133, 133, -544, + -544, 81, 114, -544, 151, 242, 244, 148, -65, -544, + 924, 189, 114, -544, -54, -544, -544, -544, -44, 114, + -544, 924, 155, 156, 157, 158, -6, 160, 181, 185, + 186, 187, -544, -56, -12, 140, 191, 193, 161, -544, + -544, -544, -544, 162, -544, 11, -544, 203, 189, 114, + 114, 196, -544, 195, 4, 872, -544, 18, -544, -544, + 20, -544, 71, 228, -544, 203, 203, 203, 203, 203, + 199, 200, 203, 163, 202, -544, 203, 198, -27, 207, + 321, -544, -544, -544, 194, 262, -544, -544, -544, 321, + -544, -544, -544, -544, -544, -544, -544, 209, -544, 210, + -544, -544, -544, 924, 110, -544, -544, 299, -544, 167, + 204, -544, -544, -544, 188, -544, 211, -544, 811, -544, + -544, -544, -544, -544, 206, -544, -544, -544, -544, -544, + 114, 114, 114, 114, 114, 924, 924, 114, 255, 924, + 114, 64, -544, -544, 280, -544, 162, 255, 144, 328, + 223, -544, -544, 224, 144, 144, 321, 41, -544, -544, + -544, -544, -544, 189, 226, 226, 221, -544, -544, 230, + 188, -544, 231, 233, -544, 164, 198, 198, 198, -544, + -544, 229, 232, -544, -544, 246, -544, -544, -544, -544, + -544, -544, 75, 400, -544, -544, 245, -544, 246, -544, + 144, 340, 238, 255, -544, -544, 330, 240, -544, -544, + 748, 241, 243, 64, 114, 247, -544, 321, -544, 248, + -544, -544, -544, 203, 203, 249, 236, -544, -544, -544, + -544, -544, -544, 64, -544, -544, -544, -544, -544, -544, + -544, -34, -544, 250, 144, 254, 236, -544, 144, -544, + -544, 246, 253, -544, 144, 144, 256, 144, 144, 144, + 144, 144, 144, 144, 144, 144, 144, 144, 302, 302, + 302, 234, -544, -544, 251, -544, -544, -544, -544, -544, + -544, -544, -544, -544, -544, -544, -544, -544, -544, -544, + -544, -544, -544, -544, -544, -544, 654, -544, -544, -544, + -544, 274, -544, -544, -544, -544, -544, -544, -544, -544, + -544, -544, 260, -544, 37, 164, 114, 114, 189, 270, + 114, -544, 54, -544, 259, 114, -544, 236, 924, -544, + -544, 924, -544, -544, -544, -544, -544, -544, -544, -544, + -544, -544, -544, -544, 272, 277, 278, -544, 976, 976, + 222, 1029, 339, -544, -544, 346, -544, -544, 114, -544, + -544, -544, 167, 50, -544, 279, 75, 68, -544, 279, + 114, 258, 294, -544, -544, -544, -544, -544, -544, -544, + 16, -544, 256, -544, 296, 261, -544, 189, 321, 298, + -544, 64, 300, 279, 255, 246, 301, 303, -544, 167, + 305, 334, 75, 411, 304, 246, 114, 246, 924, 144, + 391, -544, 334, 334, 114, 297, 236, 308, -544, 144, + -544, 391, 391, 279, 313, 315, 114, 316, -544, -544, + -544, 317, 924, 411, 320, -544, 411, 332, 334, 334, + 334, 318, -544, 391, -544, -544, -544 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int16 yypgoto[] = +{ + -544, -544, 451, -544, -544, -203, -544, -544, -544, -369, + -544, -544, -544, -544, -544, -544, 118, -544, 108, -544, + -350, -544, -544, -544, -544, -544, 208, -544, -544, -544, + -544, 239, -278, -544, -544, -276, -544, -544, -544, -544, + -544, -544, -544, -8, -335, -544, -544, -544, -544, -544, + -544, -544, -544, -544, -269, -544, -544, -544, -544, -544, + -544, -544, -544, -544, -544, -544, -544, -544, -544, -544, + -544, -544, -544, -544, -544, -10, -544, -254, -544, -544, + -114, -544, -544, 96, -544, -544, -133, -474, -544, -544, + -359, -23, 289, -544, -544, -349, -348, -544, -544, -544, + -544, 456, -150, -544, -544, 290, -544, 124, 127, -544, + -3, -263, -544, -544, -544, -61, -544, -513, -544, 6, + -544, -322, -413, -100, -544, 237, -544, -339, -420, -449, + -543, -199, -544, 166, -544, -544, -544, -313, -544, -53, + -544, -544, 10, -2, -544, 306, -119, -5, -149, -366, + -544 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -341 +static const yytype_int16 yytable[] = +{ + 122, 114, 124, 125, 126, 127, 128, 129, 130, 112, + 144, 145, 274, 113, 132, 388, 137, 138, 139, 186, + 208, 210, 436, 515, 143, 350, 357, 182, 358, 306, + 409, 467, 181, -340, 172, 191, 296, 192, 556, 163, + 351, 586, 307, 246, 501, 249, 582, 168, 189, 154, + 468, 483, 484, 155, 168, 168, 253, 165, 166, 162, + 254, 493, 4, 168, 511, 385, 286, 270, 619, 620, + 594, 441, 212, 287, 244, 517, 271, 270, 350, 167, + 344, 345, 357, -338, 358, 176, 272, 177, 28, 168, + 636, 333, 243, 351, 343, 169, 314, 141, 315, 201, + 621, 116, 269, 169, 560, 364, 211, 592, 180, 273, + 288, 279, -340, 173, 160, 117, 280, 467, 289, 51, + 173, 183, 469, 298, 470, 346, 371, 372, 229, 193, + 297, 471, -340, 310, -340, 312, 468, 483, 484, 302, + 303, 320, 321, 322, 323, 324, 482, 493, 327, 344, + 345, 118, 330, 611, 612, 548, 397, 28, 270, 150, + 151, 152, 203, 316, 153, 209, 119, 203, 576, 232, + 549, 577, -185, 378, 379, -185, 123, 380, 268, 632, + 633, 634, 381, 378, 379, 134, 580, 380, 51, 581, + 140, 141, 381, 616, 346, 417, 535, 536, 418, 419, + 420, 421, 422, 628, 133, 229, 630, 230, 469, 135, + 470, 20, 21, 356, 22, 299, 136, 471, 146, 596, + 366, 367, 368, 369, 370, 567, 568, 373, 147, 604, + 377, 606, 482, 410, 411, 412, 149, 156, 159, 160, + 164, 170, 178, 114, 317, 175, 190, 22, 168, 195, + 485, 112, 196, 197, 200, 113, 205, 33, 504, -145, + 234, 235, 595, 236, 238, 245, 237, 246, 335, 249, + 252, 275, 338, 290, 276, 131, 294, 340, 293, 277, + 278, 328, 281, 35, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 506, + 507, 52, 53, 282, 502, 54, 114, 283, 284, 285, + 304, 305, 337, 291, 112, 292, 325, 326, 113, 561, + 331, 334, 562, 329, 352, 353, 61, 28, 389, 362, + 299, 341, 342, 64, 394, 395, 485, 365, 374, 390, + 400, 392, 393, 403, 396, 405, 22, 413, 407, 408, + 414, 415, 438, 434, 440, 442, 443, 499, 509, 500, + 431, 533, 554, 503, 572, 537, 508, 512, 505, 514, + 518, 574, 599, 521, 131, 558, 584, 588, 433, -249, + 437, 546, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 114, 607, + 52, 53, 545, 563, 54, 203, 550, 551, 564, 565, + 555, 578, 585, 587, 591, 559, 593, 444, 211, 609, + 603, 597, 598, 627, 513, 22, 617, 424, 516, 614, + 622, 623, 64, 626, 519, 520, 629, 522, 523, 524, + 525, 526, 527, 528, 529, 530, 531, 532, 575, 625, + 631, 635, 5, 131, 387, 398, 406, 207, 313, 110, + 583, 35, 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 399, 240, 52, + 53, 573, 402, 544, 114, 552, 311, 0, 571, 0, + 319, 0, 425, 426, 0, 376, 605, 242, 0, 0, + 427, 428, 429, 430, 613, 0, 0, 0, 0, 0, + 0, 64, 213, 0, 214, 215, 624, 216, 217, 218, + 219, 220, 221, 222, 223, 224, 0, 225, 0, 226, + 227, 0, 0, 0, 0, 0, 114, 114, 570, 114, + 0, 0, 0, 0, 0, 0, 569, 0, 0, 0, + 0, 0, 0, 0, 589, 0, 0, 0, 0, 0, + 0, 6, 7, 8, 0, 9, 10, 11, 0, 0, + 0, 12, 13, 14, 15, 16, 590, 17, 18, 19, + 0, 20, 21, 22, 0, 0, 0, 0, 0, 608, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 618, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 0, 0, 0, 0, 0, 0, 0, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 46, 47, 48, 49, 50, 0, 51, 52, 53, 0, + 0, 54, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 55, 56, 57, 58, 59, 60, 0, 0, + 444, 0, 61, 0, 0, 62, 0, 0, 63, 64, + 65, 66, 445, 0, 0, 0, 0, 20, 21, 446, + 0, 0, 0, 447, 448, 449, 450, 451, 452, 453, + 454, 455, 0, 0, 456, 457, 0, 0, 0, 0, + 0, 28, 0, 0, 0, 0, 33, 34, 458, 459, + 460, 461, 462, 0, 463, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 464, 51, 52, 53, 0, 0, 54, 465, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 55, 56, + 0, 0, 0, 0, 444, 0, 0, 0, 61, 0, + 0, 62, 0, 466, 0, 64, 445, 0, 0, 543, + 0, 20, 21, 446, 0, 0, 0, 447, 448, 449, + 450, 451, 452, 453, 454, 455, 0, 0, 456, 457, + 0, 0, 0, 0, 0, 28, 0, 0, 0, 0, + 33, 34, 458, 459, 460, 461, 462, 0, 463, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 46, 47, 48, 49, 50, 464, 51, 52, 53, 0, + 0, 54, 465, 0, 20, 21, 22, 0, 0, 0, + 0, 0, 55, 56, 0, 0, 0, 0, 0, 0, + 0, 0, 61, 0, 0, 62, 0, 466, 28, 64, + 0, 0, 0, 33, 34, 0, 0, 0, 0, 0, + 0, 0, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 0, 51, + 52, 53, 0, 0, 54, 20, 21, 22, 0, 0, + 0, 0, 0, 0, 0, 55, 56, 0, 0, 0, + 0, 0, 0, 0, 0, 61, 0, 0, 62, 28, + 0, 63, 64, 0, 33, 34, 363, 0, 0, 0, + 0, 0, 0, 35, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 22, + 51, 52, 53, 0, 0, 54, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 55, 56, 0, 0, + 0, 0, 0, 0, 0, 0, 61, 131, 0, 62, + 0, 0, 63, 64, 0, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 22, 0, 52, 53, 0, 0, 54, 0, 255, + 256, 257, 258, 259, 260, 261, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 131, + 262, 0, 0, 0, 0, 64, 0, 35, 36, 37, + 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 566, 22, 52, 53, 0, 0, 54, + 465, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 61, 0, 131, 0, 0, 0, 0, 64, 0, 0, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 566, 22, 52, 53, + 0, 0, 54, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 61, 0, 131, 0, 0, 0, 0, + 64, 0, 0, 35, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, + 0, 52, 53, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 64 +}; + +static const yytype_int16 yycheck[] = +{ + 10, 3, 12, 13, 14, 15, 16, 17, 18, 3, + 33, 34, 211, 3, 19, 337, 26, 27, 28, 133, + 169, 171, 388, 436, 32, 294, 304, 25, 304, 25, + 365, 400, 132, 25, 25, 154, 25, 25, 512, 62, + 294, 25, 245, 25, 403, 25, 559, 81, 148, 54, + 400, 400, 400, 55, 81, 81, 121, 65, 66, 61, + 125, 400, 0, 81, 423, 334, 122, 121, 611, 612, + 583, 393, 172, 129, 193, 441, 130, 121, 347, 87, + 39, 40, 360, 117, 360, 22, 130, 24, 47, 81, + 633, 118, 192, 347, 293, 129, 25, 26, 27, 117, + 613, 25, 202, 129, 517, 308, 117, 581, 131, 209, + 122, 117, 104, 104, 125, 27, 122, 486, 130, 78, + 104, 119, 400, 237, 400, 84, 325, 326, 124, 117, + 119, 400, 124, 115, 126, 115, 486, 486, 486, 239, + 240, 255, 256, 257, 258, 259, 400, 486, 262, 39, + 40, 25, 266, 602, 603, 118, 115, 47, 121, 62, + 63, 64, 164, 92, 67, 170, 22, 169, 118, 179, + 505, 121, 118, 119, 120, 121, 26, 123, 201, 628, + 629, 630, 128, 119, 120, 26, 118, 123, 78, 121, + 25, 26, 128, 606, 84, 120, 459, 460, 123, 124, + 125, 126, 127, 623, 117, 124, 626, 126, 486, 26, + 486, 23, 24, 25, 25, 238, 26, 486, 64, 585, + 320, 321, 322, 323, 324, 538, 539, 327, 25, 595, + 330, 597, 486, 366, 367, 368, 67, 25, 25, 125, + 129, 21, 26, 245, 252, 92, 64, 25, 81, 114, + 400, 245, 114, 25, 117, 245, 92, 52, 407, 120, + 25, 82, 584, 118, 131, 114, 120, 25, 270, 25, + 122, 116, 10, 133, 118, 53, 114, 279, 117, 122, + 122, 118, 122, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 70, 71, 72, 73, 74, 75, 76, 413, + 414, 79, 80, 122, 404, 83, 308, 122, 122, 122, + 114, 116, 118, 122, 308, 122, 117, 117, 308, 518, + 122, 114, 521, 121, 25, 121, 104, 47, 338, 118, + 353, 122, 122, 111, 344, 345, 486, 131, 83, 11, + 114, 118, 118, 122, 346, 115, 25, 118, 117, 116, + 118, 105, 12, 108, 116, 25, 116, 116, 122, 116, + 383, 59, 92, 116, 25, 131, 117, 117, 120, 115, + 117, 25, 38, 117, 53, 116, 118, 116, 383, 128, + 390, 121, 61, 62, 63, 64, 65, 66, 67, 68, + 69, 70, 71, 72, 73, 74, 75, 76, 400, 598, + 79, 80, 128, 131, 83, 407, 506, 507, 131, 131, + 510, 132, 118, 117, 116, 515, 116, 6, 117, 28, + 116, 118, 117, 622, 434, 25, 118, 27, 438, 132, + 117, 116, 111, 116, 444, 445, 116, 447, 448, 449, + 450, 451, 452, 453, 454, 455, 456, 457, 548, 133, + 118, 133, 1, 53, 336, 347, 360, 168, 250, 3, + 560, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, 75, 76, 353, 188, 79, + 80, 542, 355, 486, 486, 508, 247, -1, 541, -1, + 253, -1, 92, 93, -1, 329, 596, 191, -1, -1, + 100, 101, 102, 103, 604, -1, -1, -1, -1, -1, + -1, 111, 117, -1, 119, 120, 616, 122, 123, 124, + 125, 126, 127, 128, 129, 130, -1, 132, -1, 134, + 135, -1, -1, -1, -1, -1, 538, 539, 540, 541, + -1, -1, -1, -1, -1, -1, 540, -1, -1, -1, + -1, -1, -1, -1, 577, -1, -1, -1, -1, -1, + -1, 3, 4, 5, -1, 7, 8, 9, -1, -1, + -1, 13, 14, 15, 16, 17, 578, 19, 20, 21, + -1, 23, 24, 25, -1, -1, -1, -1, -1, 599, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 609, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, -1, -1, -1, -1, -1, -1, -1, 61, + 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, -1, 78, 79, 80, -1, + -1, 83, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 94, 95, 96, 97, 98, 99, -1, -1, + 6, -1, 104, -1, -1, 107, -1, -1, 110, 111, + 112, 113, 18, -1, -1, -1, -1, 23, 24, 25, + -1, -1, -1, 29, 30, 31, 32, 33, 34, 35, + 36, 37, -1, -1, 40, 41, -1, -1, -1, -1, + -1, 47, -1, -1, -1, -1, 52, 53, 54, 55, + 56, 57, 58, -1, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + 76, 77, 78, 79, 80, -1, -1, 83, 84, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 94, 95, + -1, -1, -1, -1, 6, -1, -1, -1, 104, -1, + -1, 107, -1, 109, -1, 111, 18, -1, -1, 115, + -1, 23, 24, 25, -1, -1, -1, 29, 30, 31, + 32, 33, 34, 35, 36, 37, -1, -1, 40, 41, + -1, -1, -1, -1, -1, 47, -1, -1, -1, -1, + 52, 53, 54, 55, 56, 57, 58, -1, 60, 61, + 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, 80, -1, + -1, 83, 84, -1, 23, 24, 25, -1, -1, -1, + -1, -1, 94, 95, -1, -1, -1, -1, -1, -1, + -1, -1, 104, -1, -1, 107, -1, 109, 47, 111, + -1, -1, -1, 52, 53, -1, -1, -1, -1, -1, + -1, -1, 61, 62, 63, 64, 65, 66, 67, 68, + 69, 70, 71, 72, 73, 74, 75, 76, -1, 78, + 79, 80, -1, -1, 83, 23, 24, 25, -1, -1, + -1, -1, -1, -1, -1, 94, 95, -1, -1, -1, + -1, -1, -1, -1, -1, 104, -1, -1, 107, 47, + -1, 110, 111, -1, 52, 53, 115, -1, -1, -1, + -1, -1, -1, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 70, 71, 72, 73, 74, 75, 76, 25, + 78, 79, 80, -1, -1, 83, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 94, 95, -1, -1, + -1, -1, -1, -1, -1, -1, 104, 53, -1, 107, + -1, -1, 110, 111, -1, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + 76, 25, -1, 79, 80, -1, -1, 83, -1, 85, + 86, 87, 88, 89, 90, 91, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 53, + 106, -1, -1, -1, -1, 111, -1, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, + 74, 75, 76, 77, 25, 79, 80, -1, -1, 83, + 84, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 104, -1, 53, -1, -1, -1, -1, 111, -1, -1, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 74, 75, 76, 77, 25, 79, 80, + -1, -1, 83, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 104, -1, 53, -1, -1, -1, -1, + 111, -1, -1, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 70, 71, 72, 73, 74, 75, 76, -1, + -1, 79, 80, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 111 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint16 yystos[] = +{ + 0, 137, 138, 139, 0, 138, 3, 4, 5, 7, + 8, 9, 13, 14, 15, 16, 17, 19, 20, 21, + 23, 24, 25, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 53, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + 76, 78, 79, 80, 83, 94, 95, 96, 97, 98, + 99, 104, 107, 110, 111, 112, 113, 140, 141, 142, + 143, 144, 145, 148, 150, 156, 159, 163, 164, 168, + 171, 172, 173, 174, 175, 176, 177, 178, 181, 182, + 183, 187, 188, 189, 190, 201, 203, 204, 205, 206, + 207, 208, 209, 210, 213, 227, 228, 231, 232, 235, + 237, 238, 255, 278, 279, 283, 25, 27, 25, 22, + 211, 212, 211, 26, 211, 211, 211, 211, 211, 211, + 211, 53, 283, 117, 26, 26, 26, 211, 211, 211, + 25, 26, 179, 179, 227, 227, 64, 25, 216, 67, + 62, 63, 64, 67, 283, 279, 25, 165, 160, 25, + 125, 259, 279, 227, 129, 179, 179, 179, 81, 129, + 21, 236, 25, 104, 282, 92, 22, 24, 26, 215, + 227, 259, 25, 119, 169, 170, 216, 239, 233, 259, + 64, 282, 25, 117, 157, 114, 114, 25, 260, 261, + 117, 117, 146, 279, 284, 92, 180, 228, 284, 283, + 238, 117, 259, 117, 119, 120, 122, 123, 124, 125, + 126, 127, 128, 129, 130, 132, 134, 135, 256, 124, + 126, 281, 211, 149, 25, 82, 118, 120, 131, 241, + 241, 214, 281, 259, 282, 114, 25, 166, 167, 25, + 161, 162, 122, 121, 125, 85, 86, 87, 88, 89, + 90, 91, 106, 267, 268, 269, 279, 280, 227, 259, + 121, 130, 130, 259, 267, 116, 118, 122, 122, 117, + 122, 122, 122, 122, 122, 122, 122, 129, 122, 130, + 133, 122, 122, 117, 114, 152, 25, 119, 216, 227, + 242, 243, 259, 259, 114, 116, 25, 141, 158, 237, + 115, 167, 115, 162, 25, 27, 92, 179, 262, 261, + 216, 216, 216, 216, 216, 117, 117, 216, 118, 121, + 216, 122, 222, 118, 114, 279, 151, 118, 10, 184, + 279, 122, 122, 267, 39, 40, 84, 153, 154, 155, + 190, 213, 25, 121, 240, 234, 25, 168, 171, 217, + 218, 219, 118, 115, 141, 131, 259, 259, 259, 259, + 259, 267, 267, 259, 83, 257, 269, 259, 119, 120, + 123, 128, 223, 225, 226, 190, 191, 152, 257, 211, + 11, 185, 118, 118, 211, 211, 279, 115, 154, 243, + 114, 244, 244, 122, 221, 115, 219, 117, 116, 180, + 222, 222, 222, 118, 118, 105, 285, 120, 123, 124, + 125, 126, 127, 224, 27, 92, 93, 100, 101, 102, + 103, 227, 229, 283, 108, 147, 285, 211, 12, 186, + 116, 257, 25, 116, 6, 18, 25, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 40, 41, 54, 55, + 56, 57, 58, 60, 77, 84, 109, 145, 156, 168, + 171, 190, 192, 193, 194, 195, 196, 197, 198, 199, + 200, 202, 213, 231, 232, 238, 245, 246, 248, 249, + 251, 254, 255, 263, 270, 273, 275, 276, 278, 116, + 116, 226, 259, 116, 284, 120, 216, 216, 117, 122, + 258, 226, 117, 211, 115, 258, 211, 285, 117, 211, + 211, 117, 211, 211, 211, 211, 211, 211, 211, 211, + 211, 211, 211, 59, 247, 247, 247, 131, 271, 272, + 277, 274, 250, 115, 246, 128, 121, 220, 118, 180, + 259, 259, 227, 286, 92, 259, 223, 230, 116, 259, + 258, 267, 267, 131, 131, 131, 77, 273, 273, 255, + 279, 275, 25, 251, 25, 259, 118, 121, 132, 253, + 118, 121, 253, 259, 118, 118, 25, 117, 116, 227, + 279, 116, 223, 116, 253, 257, 285, 118, 117, 38, + 265, 263, 264, 116, 285, 259, 285, 267, 211, 28, + 266, 265, 265, 259, 132, 252, 258, 118, 211, 266, + 266, 253, 117, 116, 259, 133, 116, 267, 264, 116, + 264, 118, 265, 265, 265, 133, 266 +}; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ + +#define YYFAIL goto yyerrlab + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yytoken = YYTRANSLATE (yychar); \ + YYPOPSTACK (1); \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ +while (YYID (0)) + + +#define YYTERROR 1 +#define YYERRCODE 256 + + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (YYID (0)) +#endif + + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#ifdef YYLEX_PARAM +# define YYLEX yylex (YYLEX_PARAM) +#else +# define YYLEX yylex () +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include <stdio.h> /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (YYID (0)) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (YYID (0)) + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +#else +static void +yy_symbol_value_print (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; +#endif +{ + if (!yyvaluep) + return; +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# else + YYUSE (yyoutput); +# endif + switch (yytype) + { + default: + break; + } +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +#else +static void +yy_symbol_print (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; +#endif +{ + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + yy_symbol_value_print (yyoutput, yytype, yyvaluep); + YYFPRINTF (yyoutput, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +#else +static void +yy_stack_print (yybottom, yytop) + yytype_int16 *yybottom; + yytype_int16 *yytop; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (YYID (0)) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_reduce_print (YYSTYPE *yyvsp, int yyrule) +#else +static void +yy_reduce_print (yyvsp, yyrule) + YYSTYPE *yyvsp; + int yyrule; +#endif +{ + int yynrhs = yyr2[yyrule]; + int yyi; + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + &(yyvsp[(yyi + 1) - (yynrhs)]) + ); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyvsp, Rule); \ +} while (YYID (0)) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static YYSIZE_T +yystrlen (const char *yystr) +#else +static YYSIZE_T +yystrlen (yystr) + const char *yystr; +#endif +{ + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static char * +yystpcpy (char *yydest, const char *yysrc) +#else +static char * +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +#endif +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +/* Copy into YYRESULT an error message about the unexpected token + YYCHAR while in state YYSTATE. Return the number of bytes copied, + including the terminating null byte. If YYRESULT is null, do not + copy anything; just return the number of bytes that would be + copied. As a special case, return 0 if an ordinary "syntax error" + message will do. Return YYSIZE_MAXIMUM if overflow occurs during + size calculation. */ +static YYSIZE_T +yysyntax_error (char *yyresult, int yystate, int yychar) +{ + int yyn = yypact[yystate]; + + if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) + return 0; + else + { + int yytype = YYTRANSLATE (yychar); + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + int yysize_overflow = 0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + int yyx; + +# if 0 + /* This is so xgettext sees the translatable formats that are + constructed on the fly. */ + YY_("syntax error, unexpected %s"); + YY_("syntax error, unexpected %s, expecting %s"); + YY_("syntax error, unexpected %s, expecting %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); +# endif + char *yyfmt; + char const *yyf; + static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyexpecting[] = ", expecting %s"; + static char const yyor[] = " or %s"; + char yyformat[sizeof yyunexpected + + sizeof yyexpecting - 1 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) + * (sizeof yyor - 1))]; + char const *yyprefix = yyexpecting; + + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 1; + + yyarg[0] = yytname[yytype]; + yyfmt = yystpcpy (yyformat, yyunexpected); + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + yyformat[sizeof yyunexpected - 1] = '\0'; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + yyfmt = yystpcpy (yyfmt, yyprefix); + yyprefix = yyor; + } + + yyf = YY_(yyformat); + yysize1 = yysize + yystrlen (yyf); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + + if (yysize_overflow) + return YYSIZE_MAXIMUM; + + if (yyresult) + { + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + char *yyp = yyresult; + int yyi = 0; + while ((*yyp = *yyf) != '\0') + { + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyf += 2; + } + else + { + yyp++; + yyf++; + } + } + } + return yysize; + } +} +#endif /* YYERROR_VERBOSE */ + + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +#else +static void +yydestruct (yymsg, yytype, yyvaluep) + const char *yymsg; + int yytype; + YYSTYPE *yyvaluep; +#endif +{ + YYUSE (yyvaluep); + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } +} + +/* Prevent warnings from -Wmissing-prototypes. */ +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (void); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; + +/* Number of syntax errors so far. */ +int yynerrs; + + + +/*-------------------------. +| yyparse or yypush_parse. | +`-------------------------*/ + +#ifdef YYPARSE_PARAM +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void *YYPARSE_PARAM) +#else +int +yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +#endif +#else /* ! YYPARSE_PARAM */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void) +#else +int +yyparse () + +#endif +#endif +{ + + + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + `yyss': related to states. + `yyvs': related to semantic values. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + YYSIZE_T yystacksize; + + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + yytoken = 0; + yyss = yyssa; + yyvs = yyvsa; + yystacksize = YYINITDEPTH; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + yyssp = yyss; + yyvsp = yyvs; + + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yyn == YYPACT_NINF) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yyn == 0 || yyn == YYTABLE_NINF) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the shifted token. */ + yychar = YYEMPTY; + + yystate = yyn; + *++yyvsp = yylval; + + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 4: + +/* Line 1455 of yacc.c */ +#line 354 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* + * We don't do these in parserEOF() because the parser is reading + * ahead and that would be too early. + */ + + if (previousFile != NULL) + { + handleEOF(); + + if (currentContext.prevmod != NULL) + handleEOM(); + + free(previousFile); + previousFile = NULL; + } + } + break; + + case 22: + +/* Line 1455 of yacc.c */ +#line 389 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + appendCodeBlock(¤tSpec->exphdrcode, (yyvsp[(1) - (1)].codeb)); + } + break; + + case 23: + +/* Line 1455 of yacc.c */ +#line 393 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + appendCodeBlock(¤tModule->hdrcode, (yyvsp[(1) - (1)].codeb)); + } + break; + + case 24: + +/* Line 1455 of yacc.c */ +#line 397 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + appendCodeBlock(¤tModule->cppcode, (yyvsp[(1) - (1)].codeb)); + } + break; + + case 47: + +/* Line 1455 of yacc.c */ +#line 425 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope == NULL) + yyerror("%TypeHeaderCode can only be used in a namespace, class or mapped type"); + + appendCodeBlock(&scope->iff->hdrcode, (yyvsp[(1) - (1)].codeb)); + } + } + break; + + case 48: + +/* Line 1455 of yacc.c */ +#line 438 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + if ((currentModule->encoding = convertEncoding((yyvsp[(2) - (2)].text))) == no_type) + yyerror("The value of %DefaultEncoding must be one of \"ASCII\", \"Latin-1\", \"UTF-8\" or \"None\""); + } + } + break; + + case 49: + +/* Line 1455 of yacc.c */ +#line 447 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + appendString(¤tSpec->plugins, (yyvsp[(2) - (2)].text)); + } + break; + + case 50: + +/* Line 1455 of yacc.c */ +#line 452 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + apiVersionRangeDef *avd; + + if (findAPI(currentSpec, (yyvsp[(2) - (3)].text)) != NULL) + yyerror("The API name in the %API directive has already been defined"); + + if ((yyvsp[(3) - (3)].number) < 1) + yyerror("The version number in the %API directive must be greater than or equal to 1"); + + avd = sipMalloc(sizeof (apiVersionRangeDef)); + + avd->api_name = cacheName(currentSpec, (yyvsp[(2) - (3)].text)); + avd->from = (yyvsp[(3) - (3)].number); + avd->to = -1; + + avd->next = currentModule->api_versions; + currentModule->api_versions = avd; + + if (inMainModule()) + setIsUsedName(avd->api_name); + } + } + break; + + case 51: + +/* Line 1455 of yacc.c */ +#line 478 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + exceptionDef *xd; + const char *pyname; + + if (currentSpec->genc) + yyerror("%Exception not allowed in a C module"); + + pyname = getPythonName(&(yyvsp[(4) - (9)].optflags), scopedNameTail((yyvsp[(2) - (9)].scpvalp))); + + checkAttributes(currentSpec, currentModule, NULL, NULL, + pyname, FALSE); + + xd = findException(currentSpec, (yyvsp[(2) - (9)].scpvalp), TRUE); + + if (xd->cd != NULL) + yyerror("%Exception name has already been seen as a class name - it must be defined before being used"); + + if (xd->iff->module != NULL) + yyerror("The %Exception has already been defined"); + + /* Complete the definition. */ + xd->iff->module = currentModule; + xd->iff->hdrcode = (yyvsp[(6) - (9)].codeb); + xd->pyname = pyname; + xd->bibase = (yyvsp[(3) - (9)].exceptionbase).bibase; + xd->base = (yyvsp[(3) - (9)].exceptionbase).base; + xd->raisecode = (yyvsp[(7) - (9)].codeb); + + if (findOptFlag(&(yyvsp[(4) - (9)].optflags), "Default", bool_flag) != NULL) + currentModule->defexception = xd; + + if (xd->bibase != NULL || xd->base != NULL) + xd->exceptionnr = currentModule->nrexceptions++; + } + } + break; + + case 52: + +/* Line 1455 of yacc.c */ +#line 517 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.exceptionbase).bibase = NULL; + (yyval.exceptionbase).base = NULL; + } + break; + + case 53: + +/* Line 1455 of yacc.c */ +#line 521 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + exceptionDef *xd; + + (yyval.exceptionbase).bibase = NULL; + (yyval.exceptionbase).base = NULL; + + /* See if it is a defined exception. */ + for (xd = currentSpec->exceptions; xd != NULL; xd = xd->next) + if (compareScopedNames(xd->iff->fqcname, (yyvsp[(2) - (3)].scpvalp)) == 0) + { + (yyval.exceptionbase).base = xd; + break; + } + + if (xd == NULL && (yyvsp[(2) - (3)].scpvalp)->next == NULL && strncmp((yyvsp[(2) - (3)].scpvalp)->name, "SIP_", 4) == 0) + { + /* See if it is a builtin exception. */ + + static char *builtins[] = { + "Exception", + "StopIteration", + "StandardError", + "ArithmeticError", + "LookupError", + "AssertionError", + "AttributeError", + "EOFError", + "FloatingPointError", + "EnvironmentError", + "IOError", + "OSError", + "ImportError", + "IndexError", + "KeyError", + "KeyboardInterrupt", + "MemoryError", + "NameError", + "OverflowError", + "RuntimeError", + "NotImplementedError", + "SyntaxError", + "IndentationError", + "TabError", + "ReferenceError", + "SystemError", + "SystemExit", + "TypeError", + "UnboundLocalError", + "UnicodeError", + "UnicodeEncodeError", + "UnicodeDecodeError", + "UnicodeTranslateError", + "ValueError", + "ZeroDivisionError", + "WindowsError", + "VMSError", + NULL + }; + + char **cp; + + for (cp = builtins; *cp != NULL; ++cp) + if (strcmp((yyvsp[(2) - (3)].scpvalp)->name + 4, *cp) == 0) + { + (yyval.exceptionbase).bibase = *cp; + break; + } + } + + if ((yyval.exceptionbase).bibase == NULL && (yyval.exceptionbase).base == NULL) + yyerror("Unknown exception base type"); + } + break; + + case 54: + +/* Line 1455 of yacc.c */ +#line 595 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 55: + +/* Line 1455 of yacc.c */ +#line 600 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + currentMappedType = newMappedType(currentSpec, &(yyvsp[(2) - (3)].memArg), &(yyvsp[(3) - (3)].optflags)); + } + break; + + case 57: + +/* Line 1455 of yacc.c */ +#line 606 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + int a; + + if (currentSpec->genc) + yyerror("%MappedType templates not allowed in a C module"); + + /* Check the template arguments are basic types or simple names. */ + for (a = 0; a < (yyvsp[(1) - (4)].signature).nrArgs; ++a) + { + argDef *ad = &(yyvsp[(1) - (4)].signature).args[a]; + + if (ad->atype == defined_type && ad->u.snd->next != NULL) + yyerror("%MappedType template arguments must be simple names"); + } + + if ((yyvsp[(3) - (4)].memArg).atype != template_type) + yyerror("%MappedType template must map a template type"); + + if (notSkipping()) + { + mappedTypeTmplDef *mtt; + ifaceFileDef *iff; + + /* Check a template hasn't already been provided. */ + for (mtt = currentSpec->mappedtypetemplates; mtt != NULL; mtt = mtt->next) + if (compareScopedNames(mtt->mt->type.u.td->fqname, (yyvsp[(3) - (4)].memArg).u.td->fqname) == 0 && sameTemplateSignature(&mtt->mt->type.u.td->types, &(yyvsp[(3) - (4)].memArg).u.td->types, TRUE)) + yyerror("%MappedType template for this type has already been defined"); + + (yyvsp[(3) - (4)].memArg).nrderefs = 0; + (yyvsp[(3) - (4)].memArg).argflags = 0; + + mtt = sipMalloc(sizeof (mappedTypeTmplDef)); + + mtt->sig = (yyvsp[(1) - (4)].signature); + mtt->mt = allocMappedType(currentSpec, &(yyvsp[(3) - (4)].memArg)); + mtt->mt->doctype = getDocType(&(yyvsp[(4) - (4)].optflags)); + mtt->next = currentSpec->mappedtypetemplates; + + currentSpec->mappedtypetemplates = mtt; + + currentMappedType = mtt->mt; + + /* Create a dummy interface file. */ + iff = sipMalloc(sizeof (ifaceFileDef)); + iff->hdrcode = NULL; + mtt->mt->iff = iff; + } + } + break; + + case 59: + +/* Line 1455 of yacc.c */ +#line 656 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + if (currentMappedType->convfromcode == NULL) + yyerror("%MappedType must have a %ConvertFromTypeCode directive"); + + if (currentMappedType->convtocode == NULL) + yyerror("%MappedType must have a %ConvertToTypeCode directive"); + + currentMappedType = NULL; + } + } + break; + + case 62: + +/* Line 1455 of yacc.c */ +#line 674 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + appendCodeBlock(¤tMappedType->iff->hdrcode, (yyvsp[(1) - (1)].codeb)); + } + break; + + case 63: + +/* Line 1455 of yacc.c */ +#line 678 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + if (currentMappedType -> convfromcode != NULL) + yyerror("%MappedType has more than one %ConvertFromTypeCode directive"); + + currentMappedType -> convfromcode = (yyvsp[(2) - (2)].codeb); + } + } + break; + + case 64: + +/* Line 1455 of yacc.c */ +#line 687 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + if (currentMappedType -> convtocode != NULL) + yyerror("%MappedType has more than one %ConvertToTypeCode directive"); + + currentMappedType -> convtocode = (yyvsp[(2) - (2)].codeb); + } + } + break; + + case 67: + +/* Line 1455 of yacc.c */ +#line 700 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + applyTypeFlags(currentModule, &(yyvsp[(2) - (13)].memArg), &(yyvsp[(9) - (13)].optflags)); + + (yyvsp[(5) - (13)].signature).result = (yyvsp[(2) - (13)].memArg); + + newFunction(currentSpec, currentModule, NULL, + currentMappedType, 0, TRUE, FALSE, FALSE, FALSE, (yyvsp[(3) - (13)].text), + &(yyvsp[(5) - (13)].signature), (yyvsp[(7) - (13)].number), FALSE, &(yyvsp[(9) - (13)].optflags), (yyvsp[(13) - (13)].codeb), NULL, (yyvsp[(8) - (13)].throwlist), (yyvsp[(10) - (13)].optsignature), (yyvsp[(12) - (13)].codeb)); + } + } + break; + + case 68: + +/* Line 1455 of yacc.c */ +#line 714 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (currentSpec -> genc) + yyerror("namespace definition not allowed in a C module"); + + if (notSkipping()) + { + classDef *ns, *c_scope; + ifaceFileDef *scope; + + if ((c_scope = currentScope()) != NULL) + scope = c_scope->iff; + else + scope = NULL; + + ns = newClass(currentSpec, namespace_iface, NULL, + text2scopedName(scope, (yyvsp[(2) - (2)].text))); + + pushScope(ns); + + sectionFlags = 0; + } + } + break; + + case 69: + +/* Line 1455 of yacc.c */ +#line 735 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + if (inMainModule()) + { + classDef *ns = currentScope(); + + setIsUsedName(ns->iff->name); + setIsUsedName(ns->pyname); + } + + popScope(); + } + } + break; + + case 72: + +/* Line 1455 of yacc.c */ +#line 755 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + qualDef *qd; + + for (qd = currentModule -> qualifiers; qd != NULL; qd = qd -> next) + if (qd -> qtype == platform_qualifier) + yyerror("%Platforms has already been defined for this module"); + } + break; + + case 73: + +/* Line 1455 of yacc.c */ +#line 762 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + qualDef *qd; + int nrneeded; + + /* + * Check that exactly one platform in the set was + * requested. + */ + + nrneeded = 0; + + for (qd = currentModule -> qualifiers; qd != NULL; qd = qd -> next) + if (qd -> qtype == platform_qualifier && isNeeded(qd)) + ++nrneeded; + + if (nrneeded > 1) + yyerror("No more than one of these %Platforms must be specified with the -t flag"); + } + break; + + case 76: + +/* Line 1455 of yacc.c */ +#line 786 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + newQualifier(currentModule,-1,-1,(yyvsp[(1) - (1)].text),platform_qualifier); + } + break; + + case 77: + +/* Line 1455 of yacc.c */ +#line 791 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + newQualifier(currentModule,-1,-1,(yyvsp[(2) - (2)].text),feature_qualifier); + } + break; + + case 78: + +/* Line 1455 of yacc.c */ +#line 796 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + currentTimelineOrder = 0; + } + break; + + case 79: + +/* Line 1455 of yacc.c */ +#line 799 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + qualDef *qd; + int nrneeded; + + /* + * Check that exactly one time slot in the set was + * requested. + */ + + nrneeded = 0; + + for (qd = currentModule -> qualifiers; qd != NULL; qd = qd -> next) + if (qd -> qtype == time_qualifier && isNeeded(qd)) + ++nrneeded; + + if (nrneeded > 1) + yyerror("At most one of this %Timeline must be specified with the -t flag"); + + currentModule -> nrtimelines++; + } + break; + + case 82: + +/* Line 1455 of yacc.c */ +#line 825 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + newQualifier(currentModule,currentModule -> nrtimelines,currentTimelineOrder++,(yyvsp[(1) - (1)].text),time_qualifier); + } + break; + + case 83: + +/* Line 1455 of yacc.c */ +#line 830 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (skipStackPtr >= MAX_NESTED_IF) + yyerror("Internal error: increase the value of MAX_NESTED_IF"); + + /* Nested %Ifs are implicit logical ands. */ + + if (skipStackPtr > 0) + (yyvsp[(3) - (4)].boolean) = ((yyvsp[(3) - (4)].boolean) && skipStack[skipStackPtr - 1]); + + skipStack[skipStackPtr++] = (yyvsp[(3) - (4)].boolean); + } + break; + + case 84: + +/* Line 1455 of yacc.c */ +#line 843 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.boolean) = platOrFeature((yyvsp[(1) - (1)].text),FALSE); + } + break; + + case 85: + +/* Line 1455 of yacc.c */ +#line 846 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.boolean) = platOrFeature((yyvsp[(2) - (2)].text),TRUE); + } + break; + + case 86: + +/* Line 1455 of yacc.c */ +#line 849 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.boolean) = (platOrFeature((yyvsp[(3) - (3)].text),FALSE) || (yyvsp[(1) - (3)].boolean)); + } + break; + + case 87: + +/* Line 1455 of yacc.c */ +#line 852 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.boolean) = (platOrFeature((yyvsp[(4) - (4)].text),TRUE) || (yyvsp[(1) - (4)].boolean)); + } + break; + + case 89: + +/* Line 1455 of yacc.c */ +#line 858 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.boolean) = timePeriod((yyvsp[(1) - (3)].text),(yyvsp[(3) - (3)].text)); + } + break; + + case 90: + +/* Line 1455 of yacc.c */ +#line 863 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (skipStackPtr-- <= 0) + yyerror("Too many %End directives"); + } + break; + + case 91: + +/* Line 1455 of yacc.c */ +#line 869 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + optFlag *of; + + if ((yyvsp[(2) - (2)].optflags).nrFlags == 0) + yyerror("%License details not specified"); + + if ((of = findOptFlag(&(yyvsp[(2) - (2)].optflags),"Type",string_flag)) == NULL) + yyerror("%License type not specified"); + + currentModule -> license = sipMalloc(sizeof (licenseDef)); + + currentModule -> license -> type = of -> fvalue.sval; + + currentModule -> license -> licensee = + ((of = findOptFlag(&(yyvsp[(2) - (2)].optflags),"Licensee",string_flag)) != NULL) + ? of -> fvalue.sval : NULL; + + currentModule -> license -> timestamp = + ((of = findOptFlag(&(yyvsp[(2) - (2)].optflags),"Timestamp",string_flag)) != NULL) + ? of -> fvalue.sval : NULL; + + currentModule -> license -> sig = + ((of = findOptFlag(&(yyvsp[(2) - (2)].optflags),"Signature",string_flag)) != NULL) + ? of -> fvalue.sval : NULL; + } + break; + + case 92: + +/* Line 1455 of yacc.c */ +#line 896 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + if (currentModule->defmetatype != NULL) + yyerror("%DefaultMetatype has already been defined for this module"); + + currentModule->defmetatype = cacheName(currentSpec, (yyvsp[(2) - (2)].text)); + } + } + break; + + case 93: + +/* Line 1455 of yacc.c */ +#line 907 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + if (currentModule->defsupertype != NULL) + yyerror("%DefaultSupertype has already been defined for this module"); + + currentModule->defsupertype = cacheName(currentSpec, (yyvsp[(2) - (2)].text)); + } + } + break; + + case 94: + +/* Line 1455 of yacc.c */ +#line 918 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* Make sure this is the first mention of a module. */ + if (currentSpec->module != currentModule) + yyerror("A %ConsolidatedModule cannot be %Imported"); + + if (currentModule->fullname != NULL) + yyerror("%ConsolidatedModule must appear before any %Module or %CModule directive"); + + setModuleName(currentSpec, currentModule, (yyvsp[(2) - (2)].text)); + setIsConsolidated(currentModule); + } + break; + + case 95: + +/* Line 1455 of yacc.c */ +#line 931 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* Make sure this is the first mention of a module. */ + if (currentSpec->module != currentModule) + yyerror("A %CompositeModule cannot be %Imported"); + + if (currentModule->fullname != NULL) + yyerror("%CompositeModule must appear before any %Module or %CModule directive"); + + setModuleName(currentSpec, currentModule, (yyvsp[(2) - (2)].text)); + setIsComposite(currentModule); + } + break; + + case 96: + +/* Line 1455 of yacc.c */ +#line 944 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* Check the module hasn't already been defined. */ + + moduleDef *mod; + + for (mod = currentSpec->modules; mod != NULL; mod = mod->next) + if (mod->fullname != NULL && strcmp(mod->fullname->text, (yyvsp[(2) - (3)].text)) == 0) + yyerror("Module is already defined"); + + /* + * If we are in a container module then create a component module + * and make it current. + */ + if (isContainer(currentModule) || currentModule->container != NULL) + { + mod = allocModule(); + + mod->file = currentContext.filename; + mod->container = (isContainer(currentModule) ? currentModule : currentModule->container); + + currentModule = mod; + } + + setModuleName(currentSpec, currentModule, (yyvsp[(2) - (3)].text)); + currentModule->version = (yyvsp[(3) - (3)].number); + + if (currentSpec->genc < 0) + currentSpec->genc = (yyvsp[(1) - (3)].boolean); + else if (currentSpec->genc != (yyvsp[(1) - (3)].boolean)) + yyerror("Cannot mix C and C++ modules"); + } + break; + + case 97: + +/* Line 1455 of yacc.c */ +#line 977 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.boolean) = FALSE; + } + break; + + case 98: + +/* Line 1455 of yacc.c */ +#line 980 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.boolean) = TRUE; + } + break; + + case 100: + +/* Line 1455 of yacc.c */ +#line 986 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* + * The grammar design is a bit broken and this is the easiest way + * to allow periods in names. + */ + + char *cp; + + for (cp = (yyvsp[(1) - (1)].text); *cp != '\0'; ++cp) + if (*cp != '.' && *cp != '_' && !isalnum(*cp)) + yyerror("Invalid character in name"); + + (yyval.text) = (yyvsp[(1) - (1)].text); + } + break; + + case 101: + +/* Line 1455 of yacc.c */ +#line 1002 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.number) = -1; + } + break; + + case 103: + +/* Line 1455 of yacc.c */ +#line 1008 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + parseFile(NULL, (yyvsp[(2) - (2)].text), NULL, FALSE); + } + break; + + case 104: + +/* Line 1455 of yacc.c */ +#line 1013 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + parseFile(NULL, (yyvsp[(2) - (2)].text), NULL, TRUE); + } + break; + + case 105: + +/* Line 1455 of yacc.c */ +#line 1018 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + newImport((yyvsp[(2) - (2)].text)); + } + break; + + case 106: + +/* Line 1455 of yacc.c */ +#line 1023 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = NULL; + } + break; + + case 107: + +/* Line 1455 of yacc.c */ +#line 1026 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 108: + +/* Line 1455 of yacc.c */ +#line 1031 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = NULL; + } + break; + + case 109: + +/* Line 1455 of yacc.c */ +#line 1034 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 110: + +/* Line 1455 of yacc.c */ +#line 1039 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = NULL; + } + break; + + case 111: + +/* Line 1455 of yacc.c */ +#line 1042 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 112: + +/* Line 1455 of yacc.c */ +#line 1047 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + appendCodeBlock(¤tModule->copying, (yyvsp[(2) - (2)].codeb)); + } + break; + + case 113: + +/* Line 1455 of yacc.c */ +#line 1052 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 114: + +/* Line 1455 of yacc.c */ +#line 1057 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 115: + +/* Line 1455 of yacc.c */ +#line 1062 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 116: + +/* Line 1455 of yacc.c */ +#line 1067 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = NULL; + } + break; + + case 118: + +/* Line 1455 of yacc.c */ +#line 1073 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 119: + +/* Line 1455 of yacc.c */ +#line 1078 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 120: + +/* Line 1455 of yacc.c */ +#line 1083 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 121: + +/* Line 1455 of yacc.c */ +#line 1088 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 122: + +/* Line 1455 of yacc.c */ +#line 1093 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 123: + +/* Line 1455 of yacc.c */ +#line 1098 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 124: + +/* Line 1455 of yacc.c */ +#line 1103 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 125: + +/* Line 1455 of yacc.c */ +#line 1108 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 126: + +/* Line 1455 of yacc.c */ +#line 1113 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 127: + +/* Line 1455 of yacc.c */ +#line 1118 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 128: + +/* Line 1455 of yacc.c */ +#line 1123 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 129: + +/* Line 1455 of yacc.c */ +#line 1128 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + appendCodeBlock(¤tModule->preinitcode, (yyvsp[(2) - (2)].codeb)); + } + break; + + case 130: + +/* Line 1455 of yacc.c */ +#line 1134 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + appendCodeBlock(¤tModule->initcode, (yyvsp[(2) - (2)].codeb)); + } + break; + + case 131: + +/* Line 1455 of yacc.c */ +#line 1140 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + appendCodeBlock(¤tModule->postinitcode, (yyvsp[(2) - (2)].codeb)); + } + break; + + case 132: + +/* Line 1455 of yacc.c */ +#line 1146 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + appendCodeBlock(¤tModule->unitcode, (yyvsp[(2) - (2)].codeb)); + } + break; + + case 133: + +/* Line 1455 of yacc.c */ +#line 1152 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* + * This is a no-op and is retained for compatibility + * until the last use of it (by SIP v3) can be removed + * from PyQt. + */ + } + break; + + case 134: + +/* Line 1455 of yacc.c */ +#line 1161 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (inMainModule()) + appendCodeBlock(¤tSpec -> docs,(yyvsp[(2) - (2)].codeb)); + } + break; + + case 135: + +/* Line 1455 of yacc.c */ +#line 1167 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + appendCodeBlock(¤tSpec -> docs,(yyvsp[(2) - (2)].codeb)); + } + break; + + case 136: + +/* Line 1455 of yacc.c */ +#line 1172 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (inMainModule()) + yywarning("%Makefile is ignored, please use the -b flag instead"); + } + break; + + case 139: + +/* Line 1455 of yacc.c */ +#line 1182 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(1) - (2)].codeb); + + append(&(yyval.codeb)->frag, (yyvsp[(2) - (2)].codeb)->frag); + + free((yyvsp[(2) - (2)].codeb)->frag); + free((char *)(yyvsp[(2) - (2)].codeb)->filename); + free((yyvsp[(2) - (2)].codeb)); + } + break; + + case 140: + +/* Line 1455 of yacc.c */ +#line 1193 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + if (sectionFlags != 0 && (sectionFlags & ~(SECT_IS_PUBLIC | SECT_IS_PROT)) != 0) + yyerror("Class enums must be in the public or protected sections"); + + currentEnum = newEnum(currentSpec, currentModule, + currentMappedType, (yyvsp[(2) - (3)].text), &(yyvsp[(3) - (3)].optflags), sectionFlags); + } + } + break; + + case 142: + +/* Line 1455 of yacc.c */ +#line 1205 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.text) = NULL; + } + break; + + case 143: + +/* Line 1455 of yacc.c */ +#line 1208 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.text) = (yyvsp[(1) - (1)].text); + } + break; + + case 144: + +/* Line 1455 of yacc.c */ +#line 1213 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.text) = NULL; + } + break; + + case 145: + +/* Line 1455 of yacc.c */ +#line 1216 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.text) = (yyvsp[(1) - (1)].text); + } + break; + + case 152: + +/* Line 1455 of yacc.c */ +#line 1231 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + enumMemberDef *emd, **tail; + + /* Note that we don't use the assigned value. */ + emd = sipMalloc(sizeof (enumMemberDef)); + + emd -> pyname = cacheName(currentSpec, getPythonName(&(yyvsp[(3) - (4)].optflags), (yyvsp[(1) - (4)].text))); + emd -> cname = (yyvsp[(1) - (4)].text); + emd -> ed = currentEnum; + emd -> next = NULL; + + checkAttributes(currentSpec, currentModule, emd->ed->ecd, + emd->ed->emtd, emd->pyname->text, FALSE); + + /* Append to preserve the order. */ + for (tail = ¤tEnum->members; *tail != NULL; tail = &(*tail)->next) + ; + + *tail = emd; + + if (inMainModule()) + setIsUsedName(emd -> pyname); + } + } + break; + + case 157: + +/* Line 1455 of yacc.c */ +#line 1267 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.valp) = NULL; + } + break; + + case 158: + +/* Line 1455 of yacc.c */ +#line 1270 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.valp) = (yyvsp[(2) - (2)].valp); + } + break; + + case 160: + +/* Line 1455 of yacc.c */ +#line 1276 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + valueDef *vd; + + if ((yyvsp[(1) - (3)].valp) -> vtype == string_value || (yyvsp[(3) - (3)].valp) -> vtype == string_value) + yyerror("Invalid binary operator for string"); + + /* Find the last value in the existing expression. */ + + for (vd = (yyvsp[(1) - (3)].valp); vd -> next != NULL; vd = vd -> next) + ; + + vd -> vbinop = (yyvsp[(2) - (3)].qchar); + vd -> next = (yyvsp[(3) - (3)].valp); + + (yyval.valp) = (yyvsp[(1) - (3)].valp); + } + break; + + case 161: + +/* Line 1455 of yacc.c */ +#line 1294 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.qchar) = '-'; + } + break; + + case 162: + +/* Line 1455 of yacc.c */ +#line 1297 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.qchar) = '+'; + } + break; + + case 163: + +/* Line 1455 of yacc.c */ +#line 1300 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.qchar) = '*'; + } + break; + + case 164: + +/* Line 1455 of yacc.c */ +#line 1303 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.qchar) = '/'; + } + break; + + case 165: + +/* Line 1455 of yacc.c */ +#line 1306 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.qchar) = '&'; + } + break; + + case 166: + +/* Line 1455 of yacc.c */ +#line 1309 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.qchar) = '|'; + } + break; + + case 167: + +/* Line 1455 of yacc.c */ +#line 1314 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.qchar) = '\0'; + } + break; + + case 168: + +/* Line 1455 of yacc.c */ +#line 1317 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.qchar) = '!'; + } + break; + + case 169: + +/* Line 1455 of yacc.c */ +#line 1320 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.qchar) = '~'; + } + break; + + case 170: + +/* Line 1455 of yacc.c */ +#line 1323 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.qchar) = '-'; + } + break; + + case 171: + +/* Line 1455 of yacc.c */ +#line 1326 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.qchar) = '+'; + } + break; + + case 172: + +/* Line 1455 of yacc.c */ +#line 1331 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if ((yyvsp[(1) - (2)].qchar) != '\0' && (yyvsp[(2) - (2)].value).vtype == string_value) + yyerror("Invalid unary operator for string"); + + /* + * Convert the value to a simple expression on the + * heap. + */ + + (yyval.valp) = sipMalloc(sizeof (valueDef)); + + *(yyval.valp) = (yyvsp[(2) - (2)].value); + (yyval.valp) -> vunop = (yyvsp[(1) - (2)].qchar); + (yyval.valp) -> vbinop = '\0'; + (yyval.valp) -> next = NULL; + } + break; + + case 174: + +/* Line 1455 of yacc.c */ +#line 1350 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (currentSpec -> genc) + yyerror("Scoped names are not allowed in a C module"); + + appendScopedName(&(yyvsp[(1) - (3)].scpvalp),(yyvsp[(3) - (3)].scpvalp)); + } + break; + + case 175: + +/* Line 1455 of yacc.c */ +#line 1358 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.scpvalp) = text2scopePart((yyvsp[(1) - (1)].text)); + } + break; + + case 176: + +/* Line 1455 of yacc.c */ +#line 1363 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* + * We let the C++ compiler decide if the value is a valid one - no + * point in building a full C++ parser here. + */ + + (yyval.value).vtype = scoped_value; + (yyval.value).u.vscp = (yyvsp[(1) - (1)].scpvalp); + } + break; + + case 177: + +/* Line 1455 of yacc.c */ +#line 1372 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + fcallDef *fcd; + + fcd = sipMalloc(sizeof (fcallDef)); + *fcd = (yyvsp[(3) - (4)].fcall); + fcd -> type = (yyvsp[(1) - (4)].memArg); + + (yyval.value).vtype = fcall_value; + (yyval.value).u.fcd = fcd; + } + break; + + case 178: + +/* Line 1455 of yacc.c */ +#line 1382 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.value).vtype = real_value; + (yyval.value).u.vreal = (yyvsp[(1) - (1)].real); + } + break; + + case 179: + +/* Line 1455 of yacc.c */ +#line 1386 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.value).vtype = numeric_value; + (yyval.value).u.vnum = (yyvsp[(1) - (1)].number); + } + break; + + case 180: + +/* Line 1455 of yacc.c */ +#line 1390 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.value).vtype = numeric_value; + (yyval.value).u.vnum = 1; + } + break; + + case 181: + +/* Line 1455 of yacc.c */ +#line 1394 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.value).vtype = numeric_value; + (yyval.value).u.vnum = 0; + } + break; + + case 182: + +/* Line 1455 of yacc.c */ +#line 1398 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.value).vtype = numeric_value; + (yyval.value).u.vnum = 0; + } + break; + + case 183: + +/* Line 1455 of yacc.c */ +#line 1402 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.value).vtype = string_value; + (yyval.value).u.vstr = (yyvsp[(1) - (1)].text); + } + break; + + case 184: + +/* Line 1455 of yacc.c */ +#line 1406 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.value).vtype = qchar_value; + (yyval.value).u.vqchar = (yyvsp[(1) - (1)].qchar); + } + break; + + case 185: + +/* Line 1455 of yacc.c */ +#line 1412 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* No values. */ + + (yyval.fcall).nrArgs = 0; + } + break; + + case 186: + +/* Line 1455 of yacc.c */ +#line 1417 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* The single or first expression. */ + + (yyval.fcall).args[0] = (yyvsp[(1) - (1)].valp); + (yyval.fcall).nrArgs = 1; + } + break; + + case 187: + +/* Line 1455 of yacc.c */ +#line 1423 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* Check that it wasn't ...(,expression...). */ + + if ((yyval.fcall).nrArgs == 0) + yyerror("First argument to function call is missing"); + + /* Check there is room. */ + + if ((yyvsp[(1) - (3)].fcall).nrArgs == MAX_NR_ARGS) + yyerror("Too many arguments to function call"); + + (yyval.fcall) = (yyvsp[(1) - (3)].fcall); + + (yyval.fcall).args[(yyval.fcall).nrArgs] = (yyvsp[(3) - (3)].valp); + (yyval.fcall).nrArgs++; + } + break; + + case 188: + +/* Line 1455 of yacc.c */ +#line 1441 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + applyTypeFlags(currentModule, &(yyvsp[(2) - (5)].memArg), &(yyvsp[(4) - (5)].optflags)); + newTypedef(currentSpec, currentModule, (yyvsp[(3) - (5)].text), &(yyvsp[(2) - (5)].memArg), &(yyvsp[(4) - (5)].optflags)); + } + } + break; + + case 189: + +/* Line 1455 of yacc.c */ +#line 1448 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + signatureDef *sig; + argDef ftype; + + applyTypeFlags(currentModule, &(yyvsp[(2) - (11)].memArg), &(yyvsp[(10) - (11)].optflags)); + + memset(&ftype, 0, sizeof (argDef)); + + /* Create the full signature on the heap. */ + sig = sipMalloc(sizeof (signatureDef)); + *sig = (yyvsp[(8) - (11)].signature); + sig->result = (yyvsp[(2) - (11)].memArg); + + /* Create the full type. */ + ftype.atype = function_type; + ftype.nrderefs = (yyvsp[(4) - (11)].number); + ftype.u.sa = sig; + + newTypedef(currentSpec, currentModule, (yyvsp[(5) - (11)].text), &ftype, &(yyvsp[(10) - (11)].optflags)); + } + } + break; + + case 190: + +/* Line 1455 of yacc.c */ +#line 1473 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (currentSpec -> genc && (yyvsp[(2) - (2)].scpvalp)->next != NULL) + yyerror("Namespaces not allowed in a C module"); + + if (notSkipping()) + currentSupers = NULL; + } + break; + + case 191: + +/* Line 1455 of yacc.c */ +#line 1479 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + if (currentSpec->genc && currentSupers != NULL) + yyerror("Super-classes not allowed in a C module struct"); + + defineClass((yyvsp[(2) - (5)].scpvalp), currentSupers, &(yyvsp[(5) - (5)].optflags)); + sectionFlags = SECT_IS_PUBLIC; + } + } + break; + + case 192: + +/* Line 1455 of yacc.c */ +#line 1488 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + completeClass((yyvsp[(2) - (8)].scpvalp), &(yyvsp[(5) - (8)].optflags), (yyvsp[(7) - (8)].boolean)); + } + break; + + case 193: + +/* Line 1455 of yacc.c */ +#line 1494 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {currentIsTemplate = TRUE;} + break; + + case 194: + +/* Line 1455 of yacc.c */ +#line 1494 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (currentSpec->genc) + yyerror("Class templates not allowed in a C module"); + + if (notSkipping()) + { + classTmplDef *tcd; + + /* + * Make sure there is room for the extra class name argument. + */ + if ((yyvsp[(1) - (3)].signature).nrArgs == MAX_NR_ARGS) + yyerror("Internal error - increase the value of MAX_NR_ARGS"); + + tcd = sipMalloc(sizeof (classTmplDef)); + tcd->sig = (yyvsp[(1) - (3)].signature); + tcd->cd = (yyvsp[(3) - (3)].klass); + tcd->next = currentSpec->classtemplates; + + currentSpec->classtemplates = tcd; + } + + currentIsTemplate = FALSE; + } + break; + + case 195: + +/* Line 1455 of yacc.c */ +#line 1520 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.signature) = (yyvsp[(3) - (4)].signature); + } + break; + + case 196: + +/* Line 1455 of yacc.c */ +#line 1525 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (currentSpec->genc) + yyerror("Class definition not allowed in a C module"); + + if (notSkipping()) + currentSupers = NULL; + } + break; + + case 197: + +/* Line 1455 of yacc.c */ +#line 1531 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + defineClass((yyvsp[(2) - (5)].scpvalp), currentSupers, &(yyvsp[(5) - (5)].optflags)); + sectionFlags = SECT_IS_PRIVATE; + } + } + break; + + case 198: + +/* Line 1455 of yacc.c */ +#line 1537 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + (yyval.klass) = completeClass((yyvsp[(2) - (8)].scpvalp), &(yyvsp[(5) - (8)].optflags), (yyvsp[(7) - (8)].boolean)); + } + break; + + case 203: + +/* Line 1455 of yacc.c */ +#line 1551 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + argDef ad; + classDef *super; + scopedNameDef *snd = (yyvsp[(1) - (1)].scpvalp); + + /* + * This is a hack to allow typedef'ed classes to be used before + * we have resolved the typedef definitions. Unlike elsewhere, + * we require that the typedef is defined before being used. + */ + for (;;) + { + ad.atype = no_type; + ad.argflags = 0; + ad.nrderefs = 0; + ad.original_type = NULL; + + searchTypedefs(currentSpec, snd, &ad); + + if (ad.atype != defined_type) + break; + + if (ad.nrderefs != 0 || isConstArg(&ad) || isReference(&ad)) + break; + + snd = ad.u.snd; + } + + if (ad.atype != no_type) + yyerror("Super-class list contains an invalid type"); + + super = findClass(currentSpec, class_iface, NULL, snd); + appendToClassList(¤tSupers, super); + } + } + break; + + case 204: + +/* Line 1455 of yacc.c */ +#line 1590 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.boolean) = FALSE; + } + break; + + case 205: + +/* Line 1455 of yacc.c */ +#line 1593 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.boolean) = TRUE; + } + break; + + case 216: + +/* Line 1455 of yacc.c */ +#line 1610 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + /* Make sure this is before any ctor docstrings. */ + (yyvsp[(1) - (1)].codeb)->next = scope->docstring; + scope->docstring = (yyvsp[(1) - (1)].codeb); + } + } + break; + + case 217: + +/* Line 1455 of yacc.c */ +#line 1620 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + appendCodeBlock(¤tScope()->cppcode, (yyvsp[(1) - (1)].codeb)); + } + break; + + case 218: + +/* Line 1455 of yacc.c */ +#line 1624 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + appendCodeBlock(¤tScope()->iff->hdrcode, (yyvsp[(1) - (1)].codeb)); + } + break; + + case 219: + +/* Line 1455 of yacc.c */ +#line 1628 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->travcode != NULL) + yyerror("%GCTraverseCode already given for class"); + + scope->travcode = (yyvsp[(1) - (1)].codeb); + } + } + break; + + case 220: + +/* Line 1455 of yacc.c */ +#line 1639 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->clearcode != NULL) + yyerror("%GCClearCode already given for class"); + + scope->clearcode = (yyvsp[(1) - (1)].codeb); + } + } + break; + + case 221: + +/* Line 1455 of yacc.c */ +#line 1650 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->getbufcode != NULL) + yyerror("%BIGetBufferCode already given for class"); + + scope->getbufcode = (yyvsp[(1) - (1)].codeb); + } + } + break; + + case 222: + +/* Line 1455 of yacc.c */ +#line 1661 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->releasebufcode != NULL) + yyerror("%BIReleaseBufferCode already given for class"); + + scope->releasebufcode = (yyvsp[(1) - (1)].codeb); + } + } + break; + + case 223: + +/* Line 1455 of yacc.c */ +#line 1672 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->readbufcode != NULL) + yyerror("%BIGetReadBufferCode already given for class"); + + scope->readbufcode = (yyvsp[(1) - (1)].codeb); + } + } + break; + + case 224: + +/* Line 1455 of yacc.c */ +#line 1683 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->writebufcode != NULL) + yyerror("%BIGetWriteBufferCode already given for class"); + + scope->writebufcode = (yyvsp[(1) - (1)].codeb); + } + } + break; + + case 225: + +/* Line 1455 of yacc.c */ +#line 1694 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->segcountcode != NULL) + yyerror("%BIGetSegCountCode already given for class"); + + scope->segcountcode = (yyvsp[(1) - (1)].codeb); + } + } + break; + + case 226: + +/* Line 1455 of yacc.c */ +#line 1705 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->charbufcode != NULL) + yyerror("%BIGetCharBufferCode already given for class"); + + scope->charbufcode = (yyvsp[(1) - (1)].codeb); + } + } + break; + + case 227: + +/* Line 1455 of yacc.c */ +#line 1716 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->picklecode != NULL) + yyerror("%PickleCode already given for class"); + + scope->picklecode = (yyvsp[(1) - (1)].codeb); + } + } + break; + + case 231: + +/* Line 1455 of yacc.c */ +#line 1730 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->convtosubcode != NULL) + yyerror("Class has more than one %ConvertToSubClassCode directive"); + + scope->convtosubcode = (yyvsp[(2) - (2)].codeb); + } + } + break; + + case 232: + +/* Line 1455 of yacc.c */ +#line 1741 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->convtocode != NULL) + yyerror("Class has more than one %ConvertToTypeCode directive"); + + scope->convtocode = (yyvsp[(2) - (2)].codeb); + } + } + break; + + case 233: + +/* Line 1455 of yacc.c */ +#line 1752 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (currentSpec -> genc) + yyerror("public section not allowed in a C module"); + + if (notSkipping()) + sectionFlags = SECT_IS_PUBLIC | (yyvsp[(2) - (3)].number); + } + break; + + case 234: + +/* Line 1455 of yacc.c */ +#line 1759 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (currentSpec -> genc) + yyerror("protected section not allowed in a C module"); + + if (notSkipping()) + sectionFlags = SECT_IS_PROT | (yyvsp[(2) - (3)].number); + } + break; + + case 235: + +/* Line 1455 of yacc.c */ +#line 1766 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (currentSpec -> genc) + yyerror("private section not allowed in a C module"); + + if (notSkipping()) + sectionFlags = SECT_IS_PRIVATE | (yyvsp[(2) - (3)].number); + } + break; + + case 236: + +/* Line 1455 of yacc.c */ +#line 1773 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (currentSpec -> genc) + yyerror("signals section not allowed in a C module"); + + if (notSkipping()) + sectionFlags = SECT_IS_SIGNAL; + } + break; + + case 237: + +/* Line 1455 of yacc.c */ +#line 1782 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.number) = 0; + } + break; + + case 238: + +/* Line 1455 of yacc.c */ +#line 1785 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.number) = SECT_IS_SLOT; + } + break; + + case 239: + +/* Line 1455 of yacc.c */ +#line 1790 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* Note that we allow non-virtual dtors in C modules. */ + + if (notSkipping()) + { + classDef *cd = currentScope(); + + if (strcmp(classBaseName(cd),(yyvsp[(3) - (11)].text)) != 0) + yyerror("Destructor doesn't have the same name as its class"); + + if (isDtor(cd)) + yyerror("Destructor has already been defined"); + + if (currentSpec -> genc && (yyvsp[(10) - (11)].codeb) == NULL) + yyerror("Destructor in C modules must include %MethodCode"); + + cd -> dealloccode = (yyvsp[(10) - (11)].codeb); + cd -> dtorcode = (yyvsp[(11) - (11)].codeb); + cd -> dtorexceptions = (yyvsp[(6) - (11)].throwlist); + + /* + * Note that we don't apply the protected/public hack to dtors + * as it (I think) may change the behaviour of the wrapped API. + */ + cd->classflags |= sectionFlags; + + if ((yyvsp[(7) - (11)].number)) + { + if (!(yyvsp[(1) - (11)].number)) + yyerror("Abstract destructor must be virtual"); + + setIsAbstractClass(cd); + } + + /* + * The class has a shadow if we have a virtual dtor or some + * dtor code. + */ + if ((yyvsp[(1) - (11)].number) || (yyvsp[(11) - (11)].codeb) != NULL) + { + if (currentSpec -> genc) + yyerror("Virtual destructor or %VirtualCatcherCode not allowed in a C module"); + + setHasShadow(cd); + } + + if (getReleaseGIL(&(yyvsp[(8) - (11)].optflags))) + setIsReleaseGILDtor(cd); + else if (getHoldGIL(&(yyvsp[(8) - (11)].optflags))) + setIsHoldGILDtor(cd); + } + } + break; + + case 240: + +/* Line 1455 of yacc.c */ +#line 1844 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {currentCtorIsExplicit = TRUE;} + break; + + case 243: + +/* Line 1455 of yacc.c */ +#line 1848 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* Note that we allow ctors in C modules. */ + + if (notSkipping()) + { + if (currentSpec -> genc) + { + if ((yyvsp[(10) - (10)].codeb) == NULL && (yyvsp[(3) - (10)].signature).nrArgs != 0) + yyerror("Constructors with arguments in C modules must include %MethodCode"); + + if (currentCtorIsExplicit) + yyerror("Explicit constructors not allowed in a C module"); + } + + if ((sectionFlags & (SECT_IS_PUBLIC | SECT_IS_PROT | SECT_IS_PRIVATE)) == 0) + yyerror("Constructor must be in the public, private or protected sections"); + + newCtor((yyvsp[(1) - (10)].text), sectionFlags, &(yyvsp[(3) - (10)].signature), &(yyvsp[(6) - (10)].optflags), (yyvsp[(10) - (10)].codeb), (yyvsp[(5) - (10)].throwlist), (yyvsp[(7) - (10)].optsignature), + currentCtorIsExplicit, (yyvsp[(9) - (10)].codeb)); + } + + free((yyvsp[(1) - (10)].text)); + + currentCtorIsExplicit = FALSE; + } + break; + + case 244: + +/* Line 1455 of yacc.c */ +#line 1875 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.optsignature) = NULL; + } + break; + + case 245: + +/* Line 1455 of yacc.c */ +#line 1878 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.optsignature) = sipMalloc(sizeof (signatureDef)); + + *(yyval.optsignature) = (yyvsp[(3) - (5)].signature); + } + break; + + case 246: + +/* Line 1455 of yacc.c */ +#line 1885 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.optsignature) = NULL; + } + break; + + case 247: + +/* Line 1455 of yacc.c */ +#line 1888 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.optsignature) = sipMalloc(sizeof (signatureDef)); + + *(yyval.optsignature) = (yyvsp[(4) - (6)].signature); + (yyval.optsignature) -> result = (yyvsp[(2) - (6)].memArg); + } + break; + + case 248: + +/* Line 1455 of yacc.c */ +#line 1896 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.number) = FALSE; + } + break; + + case 249: + +/* Line 1455 of yacc.c */ +#line 1899 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.number) = TRUE; + } + break; + + case 250: + +/* Line 1455 of yacc.c */ +#line 1904 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + applyTypeFlags(currentModule, &(yyvsp[(1) - (14)].memArg), &(yyvsp[(9) - (14)].optflags)); + + (yyvsp[(4) - (14)].signature).result = (yyvsp[(1) - (14)].memArg); + + newFunction(currentSpec, currentModule, currentScope(), NULL, + sectionFlags, currentIsStatic, currentIsSignal, + currentIsSlot, currentOverIsVirt, (yyvsp[(2) - (14)].text), &(yyvsp[(4) - (14)].signature), (yyvsp[(6) - (14)].number), (yyvsp[(8) - (14)].number), &(yyvsp[(9) - (14)].optflags), + (yyvsp[(13) - (14)].codeb), (yyvsp[(14) - (14)].codeb), (yyvsp[(7) - (14)].throwlist), (yyvsp[(10) - (14)].optsignature), (yyvsp[(12) - (14)].codeb)); + } + + currentIsStatic = FALSE; + currentIsSignal = FALSE; + currentIsSlot = FALSE; + currentOverIsVirt = FALSE; + } + break; + + case 251: + +/* Line 1455 of yacc.c */ +#line 1922 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* + * It looks like an assignment operator (though we don't bother to + * check the types) so make sure it is private. + */ + if (notSkipping()) + { + classDef *cd = currentScope(); + + if (cd == NULL || !(sectionFlags & SECT_IS_PRIVATE)) + yyerror("Assignment operators may only be defined as private"); + + setCannotAssign(cd); + } + + currentIsStatic = FALSE; + currentIsSignal = FALSE; + currentIsSlot = FALSE; + currentOverIsVirt = FALSE; + } + break; + + case 252: + +/* Line 1455 of yacc.c */ +#line 1942 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + classDef *cd = currentScope(); + + applyTypeFlags(currentModule, &(yyvsp[(1) - (14)].memArg), &(yyvsp[(10) - (14)].optflags)); + + /* Handle the unary '+' and '-' operators. */ + if ((cd != NULL && (yyvsp[(5) - (14)].signature).nrArgs == 0) || (cd == NULL && (yyvsp[(5) - (14)].signature).nrArgs == 1)) + { + if (strcmp((yyvsp[(3) - (14)].text), "__add__") == 0) + (yyvsp[(3) - (14)].text) = "__pos__"; + else if (strcmp((yyvsp[(3) - (14)].text), "__sub__") == 0) + (yyvsp[(3) - (14)].text) = "__neg__"; + } + + (yyvsp[(5) - (14)].signature).result = (yyvsp[(1) - (14)].memArg); + + newFunction(currentSpec, currentModule, cd, NULL, + sectionFlags, currentIsStatic, currentIsSignal, + currentIsSlot, currentOverIsVirt, (yyvsp[(3) - (14)].text), &(yyvsp[(5) - (14)].signature), (yyvsp[(7) - (14)].number), (yyvsp[(9) - (14)].number), + &(yyvsp[(10) - (14)].optflags), (yyvsp[(13) - (14)].codeb), (yyvsp[(14) - (14)].codeb), (yyvsp[(8) - (14)].throwlist), (yyvsp[(11) - (14)].optsignature), NULL); + } + + currentIsStatic = FALSE; + currentIsSignal = FALSE; + currentIsSlot = FALSE; + currentOverIsVirt = FALSE; + } + break; + + case 253: + +/* Line 1455 of yacc.c */ +#line 1971 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + char *sname; + classDef *scope = currentScope(); + + if (scope == NULL || (yyvsp[(4) - (13)].signature).nrArgs != 0) + yyerror("Operator casts must be specified in a class and have no arguments"); + + applyTypeFlags(currentModule, &(yyvsp[(2) - (13)].memArg), &(yyvsp[(9) - (13)].optflags)); + + switch ((yyvsp[(2) - (13)].memArg).atype) + { + case defined_type: + sname = NULL; + break; + + case bool_type: + case cbool_type: + case short_type: + case ushort_type: + case int_type: + case cint_type: + case uint_type: + sname = "__int__"; + break; + + case long_type: + case ulong_type: + case longlong_type: + case ulonglong_type: + sname = "__long__"; + break; + + case float_type: + case cfloat_type: + case double_type: + case cdouble_type: + sname = "__float__"; + break; + + default: + yyerror("Unsupported operator cast"); + } + + if (sname != NULL) + { + (yyvsp[(4) - (13)].signature).result = (yyvsp[(2) - (13)].memArg); + + newFunction(currentSpec, currentModule, scope, NULL, + sectionFlags, currentIsStatic, currentIsSignal, + currentIsSlot, currentOverIsVirt, sname, &(yyvsp[(4) - (13)].signature), (yyvsp[(6) - (13)].number), + (yyvsp[(8) - (13)].number), &(yyvsp[(9) - (13)].optflags), (yyvsp[(12) - (13)].codeb), (yyvsp[(13) - (13)].codeb), (yyvsp[(7) - (13)].throwlist), (yyvsp[(10) - (13)].optsignature), NULL); + } + else + { + argList *al; + + /* Check it doesn't already exist. */ + for (al = scope->casts; al != NULL; al = al->next) + if (compareScopedNames((yyvsp[(2) - (13)].memArg).u.snd, al->arg.u.snd) == 0) + yyerror("This operator cast has already been specified in this class"); + + al = sipMalloc(sizeof (argList)); + al->arg = (yyvsp[(2) - (13)].memArg); + al->next = scope->casts; + + scope->casts = al; + } + } + + currentIsStatic = FALSE; + currentIsSignal = FALSE; + currentIsSlot = FALSE; + currentOverIsVirt = FALSE; + } + break; + + case 254: + +/* Line 1455 of yacc.c */ +#line 2049 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__add__";} + break; + + case 255: + +/* Line 1455 of yacc.c */ +#line 2050 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__sub__";} + break; + + case 256: + +/* Line 1455 of yacc.c */ +#line 2051 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__mul__";} + break; + + case 257: + +/* Line 1455 of yacc.c */ +#line 2052 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__div__";} + break; + + case 258: + +/* Line 1455 of yacc.c */ +#line 2053 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__mod__";} + break; + + case 259: + +/* Line 1455 of yacc.c */ +#line 2054 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__and__";} + break; + + case 260: + +/* Line 1455 of yacc.c */ +#line 2055 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__or__";} + break; + + case 261: + +/* Line 1455 of yacc.c */ +#line 2056 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__xor__";} + break; + + case 262: + +/* Line 1455 of yacc.c */ +#line 2057 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__lshift__";} + break; + + case 263: + +/* Line 1455 of yacc.c */ +#line 2058 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__rshift__";} + break; + + case 264: + +/* Line 1455 of yacc.c */ +#line 2059 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__iadd__";} + break; + + case 265: + +/* Line 1455 of yacc.c */ +#line 2060 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__isub__";} + break; + + case 266: + +/* Line 1455 of yacc.c */ +#line 2061 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__imul__";} + break; + + case 267: + +/* Line 1455 of yacc.c */ +#line 2062 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__idiv__";} + break; + + case 268: + +/* Line 1455 of yacc.c */ +#line 2063 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__imod__";} + break; + + case 269: + +/* Line 1455 of yacc.c */ +#line 2064 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__iand__";} + break; + + case 270: + +/* Line 1455 of yacc.c */ +#line 2065 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__ior__";} + break; + + case 271: + +/* Line 1455 of yacc.c */ +#line 2066 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__ixor__";} + break; + + case 272: + +/* Line 1455 of yacc.c */ +#line 2067 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__ilshift__";} + break; + + case 273: + +/* Line 1455 of yacc.c */ +#line 2068 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__irshift__";} + break; + + case 274: + +/* Line 1455 of yacc.c */ +#line 2069 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__invert__";} + break; + + case 275: + +/* Line 1455 of yacc.c */ +#line 2070 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__call__";} + break; + + case 276: + +/* Line 1455 of yacc.c */ +#line 2071 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__getitem__";} + break; + + case 277: + +/* Line 1455 of yacc.c */ +#line 2072 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__lt__";} + break; + + case 278: + +/* Line 1455 of yacc.c */ +#line 2073 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__le__";} + break; + + case 279: + +/* Line 1455 of yacc.c */ +#line 2074 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__eq__";} + break; + + case 280: + +/* Line 1455 of yacc.c */ +#line 2075 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__ne__";} + break; + + case 281: + +/* Line 1455 of yacc.c */ +#line 2076 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__gt__";} + break; + + case 282: + +/* Line 1455 of yacc.c */ +#line 2077 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {(yyval.text) = "__ge__";} + break; + + case 283: + +/* Line 1455 of yacc.c */ +#line 2080 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.number) = FALSE; + } + break; + + case 284: + +/* Line 1455 of yacc.c */ +#line 2083 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.number) = TRUE; + } + break; + + case 285: + +/* Line 1455 of yacc.c */ +#line 2088 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.number) = 0; + } + break; + + case 286: + +/* Line 1455 of yacc.c */ +#line 2091 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if ((yyvsp[(2) - (2)].number) != 0) + yyerror("Abstract virtual function '= 0' expected"); + + (yyval.number) = TRUE; + } + break; + + case 287: + +/* Line 1455 of yacc.c */ +#line 2099 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.optflags).nrFlags = 0; + } + break; + + case 288: + +/* Line 1455 of yacc.c */ +#line 2102 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.optflags) = (yyvsp[(2) - (3)].optflags); + } + break; + + case 289: + +/* Line 1455 of yacc.c */ +#line 2108 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.optflags).flags[0] = (yyvsp[(1) - (1)].flag); + (yyval.optflags).nrFlags = 1; + } + break; + + case 290: + +/* Line 1455 of yacc.c */ +#line 2112 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* Check there is room. */ + + if ((yyvsp[(1) - (3)].optflags).nrFlags == MAX_NR_FLAGS) + yyerror("Too many optional flags"); + + (yyval.optflags) = (yyvsp[(1) - (3)].optflags); + + (yyval.optflags).flags[(yyval.optflags).nrFlags++] = (yyvsp[(3) - (3)].flag); + } + break; + + case 291: + +/* Line 1455 of yacc.c */ +#line 2124 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.flag).ftype = bool_flag; + (yyval.flag).fname = (yyvsp[(1) - (1)].text); + } + break; + + case 292: + +/* Line 1455 of yacc.c */ +#line 2128 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.flag) = (yyvsp[(3) - (3)].flag); + (yyval.flag).fname = (yyvsp[(1) - (3)].text); + } + break; + + case 293: + +/* Line 1455 of yacc.c */ +#line 2134 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.flag).ftype = (strchr((yyvsp[(1) - (1)].text), '.') != NULL) ? dotted_name_flag : name_flag; + (yyval.flag).fvalue.sval = (yyvsp[(1) - (1)].text); + } + break; + + case 294: + +/* Line 1455 of yacc.c */ +#line 2138 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + apiVersionRangeDef *avd; + int from, to; + + (yyval.flag).ftype = api_range_flag; + + /* Check that the API is known. */ + if ((avd = findAPI(currentSpec, (yyvsp[(1) - (5)].text))) == NULL) + yyerror("unknown API name in API annotation"); + + if (inMainModule()) + setIsUsedName(avd->api_name); + + /* Unbounded values are represented by 0. */ + if ((from = (yyvsp[(3) - (5)].number)) < 0) + from = 0; + + if ((to = (yyvsp[(5) - (5)].number)) < 0) + to = 0; + + (yyval.flag).fvalue.aval = convertAPIRange(currentModule, avd->api_name, + from, to); + } + break; + + case 295: + +/* Line 1455 of yacc.c */ +#line 2161 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.flag).ftype = string_flag; + (yyval.flag).fvalue.sval = convertFeaturedString((yyvsp[(1) - (1)].text)); + } + break; + + case 296: + +/* Line 1455 of yacc.c */ +#line 2165 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.flag).ftype = integer_flag; + (yyval.flag).fvalue.ival = (yyvsp[(1) - (1)].number); + } + break; + + case 297: + +/* Line 1455 of yacc.c */ +#line 2171 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 298: + +/* Line 1455 of yacc.c */ +#line 2176 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = NULL; + } + break; + + case 300: + +/* Line 1455 of yacc.c */ +#line 2182 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = NULL; + } + break; + + case 301: + +/* Line 1455 of yacc.c */ +#line 2185 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 302: + +/* Line 1455 of yacc.c */ +#line 2190 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = NULL; + } + break; + + case 303: + +/* Line 1455 of yacc.c */ +#line 2193 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.codeb) = (yyvsp[(2) - (2)].codeb); + } + break; + + case 304: + +/* Line 1455 of yacc.c */ +#line 2198 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + int a, nrrxcon, nrrxdis, nrslotcon, nrslotdis, nrarray, nrarraysize; + + nrrxcon = nrrxdis = nrslotcon = nrslotdis = nrarray = nrarraysize = 0; + + for (a = 0; a < (yyvsp[(1) - (1)].signature).nrArgs; ++a) + { + argDef *ad = &(yyvsp[(1) - (1)].signature).args[a]; + + switch (ad -> atype) + { + case rxcon_type: + ++nrrxcon; + break; + + case rxdis_type: + ++nrrxdis; + break; + + case slotcon_type: + ++nrslotcon; + break; + + case slotdis_type: + ++nrslotdis; + break; + } + + if (isArray(ad)) + ++nrarray; + + if (isArraySize(ad)) + ++nrarraysize; + } + + if (nrrxcon != nrslotcon || nrrxcon > 1) + yyerror("SIP_RXOBJ_CON and SIP_SLOT_CON must both be given and at most once"); + + if (nrrxdis != nrslotdis || nrrxdis > 1) + yyerror("SIP_RXOBJ_DIS and SIP_SLOT_DIS must both be given and at most once"); + + if (nrarray != nrarraysize || nrarray > 1) + yyerror("/Array/ and /ArraySize/ must both be given and at most once"); + + (yyval.signature) = (yyvsp[(1) - (1)].signature); + } + break; + + case 305: + +/* Line 1455 of yacc.c */ +#line 2246 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* No arguments. */ + + (yyval.signature).nrArgs = 0; + } + break; + + case 306: + +/* Line 1455 of yacc.c */ +#line 2251 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* The single or first argument. */ + + (yyval.signature).args[0] = (yyvsp[(1) - (1)].memArg); + (yyval.signature).nrArgs = 1; + } + break; + + case 307: + +/* Line 1455 of yacc.c */ +#line 2257 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* Check that it wasn't ...(,arg...). */ + if ((yyvsp[(1) - (3)].signature).nrArgs == 0) + yyerror("First argument of the list is missing"); + + /* Check there is nothing after an ellipsis. */ + if ((yyvsp[(1) - (3)].signature).args[(yyvsp[(1) - (3)].signature).nrArgs - 1].atype == ellipsis_type) + yyerror("An ellipsis must be at the end of the argument list"); + + /* + * If this argument has no default value, then the + * previous one mustn't either. + */ + if ((yyvsp[(3) - (3)].memArg).defval == NULL && (yyvsp[(1) - (3)].signature).args[(yyvsp[(1) - (3)].signature).nrArgs - 1].defval != NULL) + yyerror("Compulsory argument given after optional argument"); + + /* Check there is room. */ + if ((yyvsp[(1) - (3)].signature).nrArgs == MAX_NR_ARGS) + yyerror("Internal error - increase the value of MAX_NR_ARGS"); + + (yyval.signature) = (yyvsp[(1) - (3)].signature); + + (yyval.signature).args[(yyval.signature).nrArgs] = (yyvsp[(3) - (3)].memArg); + (yyval.signature).nrArgs++; + } + break; + + case 308: + +/* Line 1455 of yacc.c */ +#line 2284 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.memArg).atype = signal_type; + (yyval.memArg).argflags = ARG_IS_CONST; + (yyval.memArg).nrderefs = 0; + (yyval.memArg).name = cacheName(currentSpec, (yyvsp[(2) - (4)].text)); + (yyval.memArg).defval = (yyvsp[(4) - (4)].valp); + + currentSpec -> sigslots = TRUE; + } + break; + + case 309: + +/* Line 1455 of yacc.c */ +#line 2293 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.memArg).atype = slot_type; + (yyval.memArg).argflags = ARG_IS_CONST; + (yyval.memArg).nrderefs = 0; + (yyval.memArg).name = cacheName(currentSpec, (yyvsp[(2) - (4)].text)); + (yyval.memArg).defval = (yyvsp[(4) - (4)].valp); + + currentSpec -> sigslots = TRUE; + } + break; + + case 310: + +/* Line 1455 of yacc.c */ +#line 2302 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.memArg).atype = anyslot_type; + (yyval.memArg).argflags = ARG_IS_CONST; + (yyval.memArg).nrderefs = 0; + (yyval.memArg).name = cacheName(currentSpec, (yyvsp[(2) - (4)].text)); + (yyval.memArg).defval = (yyvsp[(4) - (4)].valp); + + currentSpec -> sigslots = TRUE; + } + break; + + case 311: + +/* Line 1455 of yacc.c */ +#line 2311 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.memArg).atype = rxcon_type; + (yyval.memArg).argflags = 0; + (yyval.memArg).nrderefs = 0; + (yyval.memArg).name = cacheName(currentSpec, (yyvsp[(2) - (3)].text)); + + if (findOptFlag(&(yyvsp[(3) - (3)].optflags), "SingleShot", bool_flag) != NULL) + (yyval.memArg).argflags |= ARG_SINGLE_SHOT; + + currentSpec -> sigslots = TRUE; + } + break; + + case 312: + +/* Line 1455 of yacc.c */ +#line 2322 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.memArg).atype = rxdis_type; + (yyval.memArg).argflags = 0; + (yyval.memArg).nrderefs = 0; + (yyval.memArg).name = cacheName(currentSpec, (yyvsp[(2) - (3)].text)); + + currentSpec -> sigslots = TRUE; + } + break; + + case 313: + +/* Line 1455 of yacc.c */ +#line 2330 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.memArg).atype = slotcon_type; + (yyval.memArg).argflags = ARG_IS_CONST; + (yyval.memArg).nrderefs = 0; + (yyval.memArg).name = cacheName(currentSpec, (yyvsp[(5) - (6)].text)); + + memset(&(yyvsp[(3) - (6)].signature).result, 0, sizeof (argDef)); + (yyvsp[(3) - (6)].signature).result.atype = void_type; + + (yyval.memArg).u.sa = sipMalloc(sizeof (signatureDef)); + *(yyval.memArg).u.sa = (yyvsp[(3) - (6)].signature); + + currentSpec -> sigslots = TRUE; + } + break; + + case 314: + +/* Line 1455 of yacc.c */ +#line 2344 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.memArg).atype = slotdis_type; + (yyval.memArg).argflags = ARG_IS_CONST; + (yyval.memArg).nrderefs = 0; + (yyval.memArg).name = cacheName(currentSpec, (yyvsp[(5) - (6)].text)); + + memset(&(yyvsp[(3) - (6)].signature).result, 0, sizeof (argDef)); + (yyvsp[(3) - (6)].signature).result.atype = void_type; + + (yyval.memArg).u.sa = sipMalloc(sizeof (signatureDef)); + *(yyval.memArg).u.sa = (yyvsp[(3) - (6)].signature); + + currentSpec -> sigslots = TRUE; + } + break; + + case 315: + +/* Line 1455 of yacc.c */ +#line 2358 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.memArg).atype = qobject_type; + (yyval.memArg).argflags = 0; + (yyval.memArg).nrderefs = 0; + (yyval.memArg).name = cacheName(currentSpec, (yyvsp[(2) - (3)].text)); + } + break; + + case 316: + +/* Line 1455 of yacc.c */ +#line 2364 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.memArg) = (yyvsp[(1) - (2)].memArg); + (yyval.memArg).defval = (yyvsp[(2) - (2)].valp); + } + break; + + case 317: + +/* Line 1455 of yacc.c */ +#line 2371 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {currentIsSignal = TRUE;} + break; + + case 319: + +/* Line 1455 of yacc.c */ +#line 2372 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {currentIsSlot = TRUE;} + break; + + case 322: + +/* Line 1455 of yacc.c */ +#line 2377 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {currentIsStatic = TRUE;} + break; + + case 327: + +/* Line 1455 of yacc.c */ +#line 2387 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + {currentOverIsVirt = TRUE;} + break; + + case 330: + +/* Line 1455 of yacc.c */ +#line 2391 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (notSkipping()) + { + /* Check the section. */ + + if (sectionFlags != 0) + { + if ((sectionFlags & SECT_IS_PUBLIC) == 0) + yyerror("Class variables must be in the public section"); + + if (!currentIsStatic && (yyvsp[(5) - (7)].codeb) != NULL) + yyerror("%AccessCode cannot be specified for non-static class variables"); + } + + if (currentIsStatic && currentSpec -> genc) + yyerror("Cannot have static members in a C structure"); + + applyTypeFlags(currentModule, &(yyvsp[(1) - (7)].memArg), &(yyvsp[(3) - (7)].optflags)); + + if ((yyvsp[(6) - (7)].codeb) != NULL || (yyvsp[(7) - (7)].codeb) != NULL) + { + if ((yyvsp[(5) - (7)].codeb) != NULL) + yyerror("Cannot mix %AccessCode and %GetCode or %SetCode"); + + if (currentScope() == NULL) + yyerror("Cannot specify %GetCode or %SetCode for global variables"); + } + + newVar(currentSpec,currentModule,(yyvsp[(2) - (7)].text),currentIsStatic,&(yyvsp[(1) - (7)].memArg),&(yyvsp[(3) - (7)].optflags),(yyvsp[(5) - (7)].codeb),(yyvsp[(6) - (7)].codeb),(yyvsp[(7) - (7)].codeb)); + } + + currentIsStatic = FALSE; + } + break; + + case 331: + +/* Line 1455 of yacc.c */ +#line 2426 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.memArg) = (yyvsp[(2) - (4)].memArg); + (yyval.memArg).nrderefs += (yyvsp[(3) - (4)].number); + (yyval.memArg).argflags |= ARG_IS_CONST | (yyvsp[(4) - (4)].number); + } + break; + + case 332: + +/* Line 1455 of yacc.c */ +#line 2431 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.memArg) = (yyvsp[(1) - (3)].memArg); + (yyval.memArg).nrderefs += (yyvsp[(2) - (3)].number); + (yyval.memArg).argflags |= (yyvsp[(3) - (3)].number); + } + break; + + case 333: + +/* Line 1455 of yacc.c */ +#line 2438 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.memArg) = (yyvsp[(1) - (3)].memArg); + (yyval.memArg).name = cacheName(currentSpec, (yyvsp[(2) - (3)].text)); + + if (getAllowNone(&(yyvsp[(3) - (3)].optflags))) + (yyval.memArg).argflags |= ARG_ALLOW_NONE; + + if (findOptFlag(&(yyvsp[(3) - (3)].optflags),"GetWrapper",bool_flag) != NULL) + (yyval.memArg).argflags |= ARG_GET_WRAPPER; + + if (findOptFlag(&(yyvsp[(3) - (3)].optflags),"Array",bool_flag) != NULL) + (yyval.memArg).argflags |= ARG_ARRAY; + + if (findOptFlag(&(yyvsp[(3) - (3)].optflags),"ArraySize",bool_flag) != NULL) + (yyval.memArg).argflags |= ARG_ARRAY_SIZE; + + if (getTransfer(&(yyvsp[(3) - (3)].optflags))) + (yyval.memArg).argflags |= ARG_XFERRED; + + if (findOptFlag(&(yyvsp[(3) - (3)].optflags),"TransferThis",bool_flag) != NULL) + (yyval.memArg).argflags |= ARG_THIS_XFERRED; + + if (findOptFlag(&(yyvsp[(3) - (3)].optflags),"TransferBack",bool_flag) != NULL) + (yyval.memArg).argflags |= ARG_XFERRED_BACK; + + if (findOptFlag(&(yyvsp[(3) - (3)].optflags), "KeepReference", bool_flag) != NULL) + { + (yyval.memArg).argflags |= ARG_KEEP_REF; + (yyval.memArg).key = currentModule->next_key++; + } + + if (findOptFlag(&(yyvsp[(3) - (3)].optflags),"In",bool_flag) != NULL) + (yyval.memArg).argflags |= ARG_IN; + + if (findOptFlag(&(yyvsp[(3) - (3)].optflags),"Out",bool_flag) != NULL) + (yyval.memArg).argflags |= ARG_OUT; + + if (findOptFlag(&(yyvsp[(3) - (3)].optflags), "ResultSize", bool_flag) != NULL) + (yyval.memArg).argflags |= ARG_RESULT_SIZE; + + if (findOptFlag(&(yyvsp[(3) - (3)].optflags), "NoCopy", bool_flag) != NULL) + (yyval.memArg).argflags |= ARG_NO_COPY; + + if (findOptFlag(&(yyvsp[(3) - (3)].optflags),"Constrained",bool_flag) != NULL) + { + (yyval.memArg).argflags |= ARG_CONSTRAINED; + + switch ((yyval.memArg).atype) + { + case bool_type: + (yyval.memArg).atype = cbool_type; + break; + + case int_type: + (yyval.memArg).atype = cint_type; + break; + + case float_type: + (yyval.memArg).atype = cfloat_type; + break; + + case double_type: + (yyval.memArg).atype = cdouble_type; + break; + } + } + + applyTypeFlags(currentModule, &(yyval.memArg), &(yyvsp[(3) - (3)].optflags)); + (yyval.memArg).docval = getDocValue(&(yyvsp[(3) - (3)].optflags)); + } + break; + + case 334: + +/* Line 1455 of yacc.c */ +#line 2510 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.number) = 0; + } + break; + + case 335: + +/* Line 1455 of yacc.c */ +#line 2513 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (currentSpec -> genc) + yyerror("References not allowed in a C module"); + + (yyval.number) = ARG_IS_REF; + } + break; + + case 336: + +/* Line 1455 of yacc.c */ +#line 2521 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.number) = 0; + } + break; + + case 337: + +/* Line 1455 of yacc.c */ +#line 2524 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.number) = (yyvsp[(1) - (2)].number) + 1; + } + break; + + case 338: + +/* Line 1455 of yacc.c */ +#line 2529 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = defined_type; + (yyval.memArg).u.snd = (yyvsp[(1) - (1)].scpvalp); + + /* Try and resolve typedefs as early as possible. */ + resolveAnyTypedef(currentSpec, &(yyval.memArg)); + } + break; + + case 339: + +/* Line 1455 of yacc.c */ +#line 2537 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + templateDef *td; + + td = sipMalloc(sizeof(templateDef)); + td->fqname = (yyvsp[(1) - (4)].scpvalp); + td->types = (yyvsp[(3) - (4)].signature); + + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = template_type; + (yyval.memArg).u.td = td; + } + break; + + case 340: + +/* Line 1455 of yacc.c */ +#line 2548 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + + /* In a C module all structures must be defined. */ + if (currentSpec -> genc) + { + (yyval.memArg).atype = defined_type; + (yyval.memArg).u.snd = (yyvsp[(2) - (2)].scpvalp); + } + else + { + (yyval.memArg).atype = struct_type; + (yyval.memArg).u.sname = (yyvsp[(2) - (2)].scpvalp); + } + } + break; + + case 341: + +/* Line 1455 of yacc.c */ +#line 2563 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = ushort_type; + } + break; + + case 342: + +/* Line 1455 of yacc.c */ +#line 2567 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = short_type; + } + break; + + case 343: + +/* Line 1455 of yacc.c */ +#line 2571 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = uint_type; + } + break; + + case 344: + +/* Line 1455 of yacc.c */ +#line 2575 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = uint_type; + } + break; + + case 345: + +/* Line 1455 of yacc.c */ +#line 2579 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = int_type; + } + break; + + case 346: + +/* Line 1455 of yacc.c */ +#line 2583 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = long_type; + } + break; + + case 347: + +/* Line 1455 of yacc.c */ +#line 2587 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = ulong_type; + } + break; + + case 348: + +/* Line 1455 of yacc.c */ +#line 2591 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = longlong_type; + } + break; + + case 349: + +/* Line 1455 of yacc.c */ +#line 2595 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = ulonglong_type; + } + break; + + case 350: + +/* Line 1455 of yacc.c */ +#line 2599 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = float_type; + } + break; + + case 351: + +/* Line 1455 of yacc.c */ +#line 2603 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = double_type; + } + break; + + case 352: + +/* Line 1455 of yacc.c */ +#line 2607 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = bool_type; + } + break; + + case 353: + +/* Line 1455 of yacc.c */ +#line 2611 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = sstring_type; + } + break; + + case 354: + +/* Line 1455 of yacc.c */ +#line 2615 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = ustring_type; + } + break; + + case 355: + +/* Line 1455 of yacc.c */ +#line 2619 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = string_type; + } + break; + + case 356: + +/* Line 1455 of yacc.c */ +#line 2623 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = wstring_type; + } + break; + + case 357: + +/* Line 1455 of yacc.c */ +#line 2627 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = void_type; + } + break; + + case 358: + +/* Line 1455 of yacc.c */ +#line 2631 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = pyobject_type; + } + break; + + case 359: + +/* Line 1455 of yacc.c */ +#line 2635 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = pytuple_type; + } + break; + + case 360: + +/* Line 1455 of yacc.c */ +#line 2639 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = pylist_type; + } + break; + + case 361: + +/* Line 1455 of yacc.c */ +#line 2643 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = pydict_type; + } + break; + + case 362: + +/* Line 1455 of yacc.c */ +#line 2647 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = pycallable_type; + } + break; + + case 363: + +/* Line 1455 of yacc.c */ +#line 2651 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = pyslice_type; + } + break; + + case 364: + +/* Line 1455 of yacc.c */ +#line 2655 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = pytype_type; + } + break; + + case 365: + +/* Line 1455 of yacc.c */ +#line 2659 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + memset(&(yyval.memArg), 0, sizeof (argDef)); + (yyval.memArg).atype = ellipsis_type; + } + break; + + case 366: + +/* Line 1455 of yacc.c */ +#line 2665 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* The single or first type. */ + + (yyval.signature).args[0] = (yyvsp[(1) - (1)].memArg); + (yyval.signature).nrArgs = 1; + } + break; + + case 367: + +/* Line 1455 of yacc.c */ +#line 2671 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* Check there is nothing after an ellipsis. */ + if ((yyvsp[(1) - (3)].signature).args[(yyvsp[(1) - (3)].signature).nrArgs - 1].atype == ellipsis_type) + yyerror("An ellipsis must be at the end of the argument list"); + + /* Check there is room. */ + if ((yyvsp[(1) - (3)].signature).nrArgs == MAX_NR_ARGS) + yyerror("Internal error - increase the value of MAX_NR_ARGS"); + + (yyval.signature) = (yyvsp[(1) - (3)].signature); + + (yyval.signature).args[(yyval.signature).nrArgs] = (yyvsp[(3) - (3)].memArg); + (yyval.signature).nrArgs++; + } + break; + + case 368: + +/* Line 1455 of yacc.c */ +#line 2687 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + (yyval.throwlist) = NULL; + } + break; + + case 369: + +/* Line 1455 of yacc.c */ +#line 2690 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + if (currentSpec->genc) + yyerror("Exceptions not allowed in a C module"); + + (yyval.throwlist) = (yyvsp[(3) - (4)].throwlist); + } + break; + + case 370: + +/* Line 1455 of yacc.c */ +#line 2698 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* Empty list so use a blank. */ + + (yyval.throwlist) = sipMalloc(sizeof (throwArgs)); + (yyval.throwlist) -> nrArgs = 0; + } + break; + + case 371: + +/* Line 1455 of yacc.c */ +#line 2704 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* The only or first exception. */ + + (yyval.throwlist) = sipMalloc(sizeof (throwArgs)); + (yyval.throwlist) -> nrArgs = 1; + (yyval.throwlist) -> args[0] = findException(currentSpec, (yyvsp[(1) - (1)].scpvalp), FALSE); + } + break; + + case 372: + +/* Line 1455 of yacc.c */ +#line 2711 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + { + /* Check that it wasn't ...(,arg...). */ + + if ((yyvsp[(1) - (3)].throwlist) -> nrArgs == 0) + yyerror("First exception of throw specifier is missing"); + + /* Check there is room. */ + + if ((yyvsp[(1) - (3)].throwlist) -> nrArgs == MAX_NR_ARGS) + yyerror("Internal error - increase the value of MAX_NR_ARGS"); + + (yyval.throwlist) = (yyvsp[(1) - (3)].throwlist); + (yyval.throwlist) -> args[(yyval.throwlist) -> nrArgs++] = findException(currentSpec, (yyvsp[(3) - (3)].scpvalp), FALSE); + } + break; + + + +/* Line 1455 of yacc.c */ +#line 6104 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.c" + default: break; + } + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (YY_("syntax error")); +#else + { + YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); + if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) + { + YYSIZE_T yyalloc = 2 * yysize; + if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) + yyalloc = YYSTACK_ALLOC_MAXIMUM; + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yyalloc); + if (yymsg) + yymsg_alloc = yyalloc; + else + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + } + } + + if (0 < yysize && yysize <= yymsg_alloc) + { + (void) yysyntax_error (yymsg, yystate, yychar); + yyerror (yymsg); + } + else + { + yyerror (YY_("syntax error")); + if (yysize != 0) + goto yyexhaustedlab; + } + } +#endif + } + + + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (/*CONSTCOND*/ 0) + goto yyerrorlab; + + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYPACT_NINF) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + + yydestruct ("Error: popping", + yystos[yystate], yyvsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + *++yyvsp = yylval; + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#if !defined(yyoverflow) || YYERROR_VERBOSE +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: + if (yychar != YYEMPTY) + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + /* Make sure YYID is used. */ + return YYID (yyresult); +} + + + +/* Line 1675 of yacc.c */ +#line 2727 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + + + +/* + * Parse the specification. + */ +void parse(sipSpec *spec, FILE *fp, char *filename, stringList *tsl, + stringList *xfl, int kwdArgs, int protHack) +{ + classTmplDef *tcd; + + /* Initialise the spec. */ + + spec->modules = NULL; + spec->namecache = NULL; + spec->ifacefiles = NULL; + spec->classes = NULL; + spec->classtemplates = NULL; + spec->exceptions = NULL; + spec->mappedtypes = NULL; + spec->mappedtypetemplates = NULL; + spec->enums = NULL; + spec->vars = NULL; + spec->typedefs = NULL; + spec->exphdrcode = NULL; + spec->docs = NULL; + spec->sigslots = FALSE; + spec->genc = -1; + spec->plugins = NULL; + + currentSpec = spec; + neededQualifiers = tsl; + excludedQualifiers = xfl; + currentModule = NULL; + currentMappedType = NULL; + currentOverIsVirt = FALSE; + currentCtorIsExplicit = FALSE; + currentIsStatic = FALSE; + currentIsSignal = FALSE; + currentIsSlot = FALSE; + currentIsTemplate = FALSE; + previousFile = NULL; + skipStackPtr = 0; + currentScopeIdx = 0; + sectionFlags = 0; + defaultKwdArgs = kwdArgs; + makeProtPublic = protHack; + + newModule(fp, filename); + spec->module = currentModule; + + yyparse(); + + handleEOF(); + handleEOM(); + + /* + * Go through each template class and remove it from the list of classes. + */ + for (tcd = spec->classtemplates; tcd != NULL; tcd = tcd->next) + { + classDef **cdp; + + for (cdp = &spec->classes; *cdp != NULL; cdp = &(*cdp)->next) + if (*cdp == tcd->cd) + { + ifaceFileDef **ifdp; + + /* Remove the interface file as well. */ + for (ifdp = &spec->ifacefiles; *ifdp != NULL; ifdp = &(*ifdp)->next) + if (*ifdp == tcd->cd->iff) + { + *ifdp = (*ifdp)->next; + break; + } + + *cdp = (*cdp)->next; + break; + } + } +} + + +/* + * Tell the parser that a complete file has now been read. + */ +void parserEOF(char *name, parserContext *pc) +{ + previousFile = sipStrdup(name); + currentContext = *pc; +} + + +/* + * Append a class definition to a class list if it doesn't already appear. + * Append is needed specifically for the list of super-classes because the + * order is important to Python. + */ +void appendToClassList(classList **clp,classDef *cd) +{ + classList *new; + + /* Find the end of the list. */ + + while (*clp != NULL) + { + if ((*clp) -> cd == cd) + return; + + clp = &(*clp) -> next; + } + + new = sipMalloc(sizeof (classList)); + + new -> cd = cd; + new -> next = NULL; + + *clp = new; +} + + +/* + * Create a new module for the current specification and make it current. + */ +static void newModule(FILE *fp, char *filename) +{ + moduleDef *mod; + + parseFile(fp, filename, currentModule, FALSE); + + mod = allocModule(); + mod->file = filename; + + if (currentModule != NULL) + mod->defexception = currentModule->defexception; + + currentModule = mod; +} + + +/* + * Allocate and initialise the memory for a new module. + */ +static moduleDef *allocModule() +{ + moduleDef *newmod, **tailp; + + newmod = sipMalloc(sizeof (moduleDef)); + + newmod->version = -1; + newmod->encoding = no_type; + newmod->qobjclass = -1; + newmod->nrvirthandlers = -1; + newmod->next_key = 1; + + /* + * The consolidated module support needs these to be in order that they + * appeared. + */ + for (tailp = ¤tSpec->modules; *tailp != NULL; tailp = &(*tailp)->next) + ; + + *tailp = newmod; + + return newmod; +} + + +/* + * Switch to parsing a new file. + */ +static void parseFile(FILE *fp, char *name, moduleDef *prevmod, int optional) +{ + parserContext pc; + + pc.filename = name; + pc.ifdepth = skipStackPtr; + pc.prevmod = prevmod; + + if (setInputFile(fp, &pc, optional)) + currentContext = pc; +} + + +/* + * Find an interface file, or create a new one. + */ +ifaceFileDef *findIfaceFile(sipSpec *pt, moduleDef *mod, scopedNameDef *fqname, + ifaceFileType iftype, apiVersionRangeDef *api_range, argDef *ad) +{ + ifaceFileDef *iff, *first_alt = NULL; + + /* See if the name is already used. */ + + for (iff = pt->ifacefiles; iff != NULL; iff = iff->next) + { + if (compareScopedNames(iff->fqcname, fqname) != 0) + continue; + + /* + * If they are both versioned then assume the user knows what they are + * doing. + */ + if (iff->api_range != NULL && api_range != NULL && iff->module == mod) + { + /* Remember the first of the alternate APIs. */ + if ((first_alt = iff->first_alt) == NULL) + first_alt = iff; + + break; + } + + /* + * They must be the same type except that we allow a class if we want + * an exception. This is because we allow classes to be used before + * they are defined. + */ + if (iff->type != iftype) + if (iftype != exception_iface || iff->type != class_iface) + yyerror("A class, exception, namespace or mapped type has already been defined with the same name"); + + /* Ignore an external class declared in another module. */ + if (iftype == class_iface && iff->module != mod) + { + classDef *cd; + + for (cd = pt->classes; cd != NULL; cd = cd->next) + if (cd->iff == iff) + break; + + if (cd != NULL && iff->module != NULL && isExternal(cd)) + continue; + } + + /* + * If this is a mapped type with the same name defined in a different + * module, then check that this type isn't the same as any of the + * mapped types defined in that module. + */ + if (iftype == mappedtype_iface && iff->module != mod) + { + mappedTypeDef *mtd; + + /* + * This is a bit of a cheat. With consolidated modules it's + * possible to have two implementations of a mapped type in + * different branches of the module hierarchy. We assume that, if + * there really are multiple implementations in the same branch, + * then it will be picked up in a non-consolidated build. + */ + if (isConsolidated(pt->module)) + continue; + + for (mtd = pt->mappedtypes; mtd != NULL; mtd = mtd->next) + { + if (mtd->iff != iff) + continue; + + if (ad->atype != template_type || + mtd->type.atype != template_type || + sameBaseType(ad, &mtd->type)) + yyerror("Mapped type has already been defined in another module"); + } + + /* + * If we got here then we have a mapped type based on an existing + * template, but with unique parameters. We don't want to use + * interface files from other modules, so skip this one. + */ + + continue; + } + + /* Ignore a namespace defined in another module. */ + if (iftype == namespace_iface && iff->module != mod) + continue; + + return iff; + } + + iff = sipMalloc(sizeof (ifaceFileDef)); + + iff->name = cacheName(pt, scopedNameToString(fqname)); + iff->api_range = api_range; + + if (first_alt != NULL) + { + iff->first_alt = first_alt; + iff->next_alt = first_alt->next_alt; + + first_alt->next_alt = iff; + } + else + { + /* This is the first alternate so point to itself. */ + iff->first_alt = iff; + } + + iff->type = iftype; + iff->ifacenr = -1; + iff->fqcname = fqname; + iff->module = NULL; + iff->hdrcode = NULL; + iff->used = NULL; + iff->next = pt->ifacefiles; + + pt->ifacefiles = iff; + + return iff; +} + + +/* + * Find a class definition in a parse tree. + */ +static classDef *findClass(sipSpec *pt, ifaceFileType iftype, + apiVersionRangeDef *api_range, scopedNameDef *fqname) +{ + return findClassWithInterface(pt, findIfaceFile(pt, currentModule, fqname, iftype, api_range, NULL)); +} + + +/* + * Find a class definition given an existing interface file. + */ +static classDef *findClassWithInterface(sipSpec *pt, ifaceFileDef *iff) +{ + classDef *cd; + + for (cd = pt -> classes; cd != NULL; cd = cd -> next) + if (cd -> iff == iff) + return cd; + + /* Create a new one. */ + cd = sipMalloc(sizeof (classDef)); + + cd->iff = iff; + cd->pyname = cacheName(pt, classBaseName(cd)); + cd->next = pt->classes; + + pt->classes = cd; + + return cd; +} + + +/* + * Add an interface file to an interface file list if it isn't already there. + */ +void addToUsedList(ifaceFileList **ifflp, ifaceFileDef *iff) +{ + /* Make sure we don't try to add an interface file to its own list. */ + if (&iff->used != ifflp) + { + ifaceFileList *iffl; + + while ((iffl = *ifflp) != NULL) + { + /* Don't bother if it is already there. */ + if (iffl->iff == iff) + return; + + ifflp = &iffl -> next; + } + + iffl = sipMalloc(sizeof (ifaceFileList)); + + iffl->iff = iff; + iffl->next = NULL; + + *ifflp = iffl; + } +} + + +/* + * Find an undefined (or create a new) exception definition in a parse tree. + */ +static exceptionDef *findException(sipSpec *pt, scopedNameDef *fqname, int new) +{ + exceptionDef *xd, **tail; + ifaceFileDef *iff; + classDef *cd; + + iff = findIfaceFile(pt, currentModule, fqname, exception_iface, NULL, NULL); + + /* See if it is an existing one. */ + for (xd = pt->exceptions; xd != NULL; xd = xd->next) + if (xd->iff == iff) + return xd; + + /* + * If it is an exception interface file then we have never seen this + * name before. We require that exceptions are defined before being + * used, but don't make the same requirement of classes (for reasons of + * backwards compatibility). Therefore the name must be reinterpreted + * as a (as yet undefined) class. + */ + if (new) + { + if (iff->type == exception_iface) + cd = NULL; + else + yyerror("There is already a class with the same name or the exception has been used before being defined"); + } + else + { + if (iff->type == exception_iface) + iff->type = class_iface; + + cd = findClassWithInterface(pt, iff); + } + + /* Create a new one. */ + xd = sipMalloc(sizeof (exceptionDef)); + + xd->exceptionnr = -1; + xd->iff = iff; + xd->pyname = NULL; + xd->cd = cd; + xd->bibase = NULL; + xd->base = NULL; + xd->raisecode = NULL; + xd->next = NULL; + + /* Append it to the list. */ + for (tail = &pt->exceptions; *tail != NULL; tail = &(*tail)->next) + ; + + *tail = xd; + + return xd; +} + + +/* + * Find an undefined (or create a new) class definition in a parse tree. + */ +static classDef *newClass(sipSpec *pt, ifaceFileType iftype, + apiVersionRangeDef *api_range, scopedNameDef *fqname) +{ + int flags; + classDef *cd, *scope; + codeBlock *hdrcode; + + if (sectionFlags & SECT_IS_PRIVATE) + yyerror("Classes, structs and namespaces must be in the public or protected sections"); + + flags = 0; + + if ((scope = currentScope()) != NULL) + { + if (sectionFlags & SECT_IS_PROT && !makeProtPublic) + { + flags = CLASS_IS_PROTECTED; + + if (scope->iff->type == class_iface) + setHasShadow(scope); + } + + /* Header code from outer scopes is also included. */ + hdrcode = scope->iff->hdrcode; + } + else + hdrcode = NULL; + + if (pt -> genc) + { + /* C structs are always global types. */ + while (fqname -> next != NULL) + fqname = fqname -> next; + + scope = NULL; + } + + cd = findClass(pt, iftype, api_range, fqname); + + /* Check it hasn't already been defined. */ + if (iftype != namespace_iface && cd->iff->module != NULL) + yyerror("The struct/class has already been defined"); + + /* Complete the initialisation. */ + cd->classflags |= flags; + cd->ecd = scope; + cd->iff->module = currentModule; + + if (currentIsTemplate) + setIsTemplateClass(cd); + + appendCodeBlock(&cd->iff->hdrcode, hdrcode); + + /* See if it is a namespace extender. */ + if (iftype == namespace_iface) + { + classDef *ns; + + for (ns = pt->classes; ns != NULL; ns = ns->next) + { + if (ns == cd) + continue; + + if (ns->iff->type != namespace_iface) + continue; + + if (compareScopedNames(ns->iff->fqcname, fqname) != 0) + continue; + + cd->real = ns; + break; + } + } + + return cd; +} + + +/* + * Tidy up after finishing a class definition. + */ +static void finishClass(sipSpec *pt, moduleDef *mod, classDef *cd, + optFlags *of) +{ + const char *pyname; + optFlag *flg; + + /* Get the Python name and see if it is different to the C++ name. */ + pyname = getPythonName(of, classBaseName(cd)); + + cd->pyname = NULL; + checkAttributes(pt, mod, cd->ecd, NULL, pyname, FALSE); + cd->pyname = cacheName(pt, pyname); + + if ((flg = findOptFlag(of, "Metatype", dotted_name_flag)) != NULL) + cd->metatype = cacheName(pt, flg->fvalue.sval); + + if ((flg = findOptFlag(of, "Supertype", dotted_name_flag)) != NULL) + cd->supertype = cacheName(pt, flg->fvalue.sval); + + if ((flg = findOptFlag(of, "PyQt4Flags", integer_flag)) != NULL) + cd->pyqt4_flags = flg->fvalue.ival; + + if (findOptFlag(of, "PyQt4NoQMetaObject", bool_flag) != NULL) + setPyQt4NoQMetaObject(cd); + + if (isOpaque(cd)) + { + if (findOptFlag(of, "External", bool_flag) != NULL) + setIsExternal(cd); + } + else + { + int seq_might, seq_not; + memberDef *md; + + if (findOptFlag(of, "NoDefaultCtors", bool_flag) != NULL) + setNoDefaultCtors(cd); + + if (cd -> ctors == NULL) + { + if (!noDefaultCtors(cd)) + { + /* Provide a default ctor. */ + + cd->ctors = sipMalloc(sizeof (ctorDef)); + + cd->ctors->ctorflags = SECT_IS_PUBLIC; + cd->ctors->pysig.result.atype = void_type; + cd->ctors->cppsig = &cd->ctors->pysig; + + cd->defctor = cd->ctors; + + setCanCreate(cd); + } + } + else if (cd -> defctor == NULL) + { + ctorDef *ct, *last = NULL; + + for (ct = cd -> ctors; ct != NULL; ct = ct -> next) + { + if (!isPublicCtor(ct)) + continue; + + if (ct -> pysig.nrArgs == 0 || ct -> pysig.args[0].defval != NULL) + { + cd -> defctor = ct; + break; + } + + if (last == NULL) + last = ct; + } + + /* The last resort is the first public ctor. */ + if (cd->defctor == NULL) + cd->defctor = last; + } + + if (getDeprecated(of)) + setIsDeprecatedClass(cd); + + if (cd->convtocode != NULL && getAllowNone(of)) + setClassHandlesNone(cd); + + if (findOptFlag(of,"Abstract",bool_flag) != NULL) + { + setIsAbstractClass(cd); + setIsIncomplete(cd); + resetCanCreate(cd); + } + + /* We assume a public dtor if nothing specific was provided. */ + if (!isDtor(cd)) + setIsPublicDtor(cd); + + if (findOptFlag(of, "DelayDtor", bool_flag) != NULL) + { + setIsDelayedDtor(cd); + setHasDelayedDtors(mod); + } + + /* + * There are subtle differences between the add and concat methods and + * the multiply and repeat methods. The number versions can have their + * operands swapped and may return NotImplemented. If the user has + * used the /Numeric/ annotation or there are other numeric operators + * then we use add/multiply. Otherwise, if there are indexing + * operators then we use concat/repeat. + */ + seq_might = seq_not = FALSE; + + for (md = cd -> members; md != NULL; md = md -> next) + switch (md -> slot) + { + case getitem_slot: + case setitem_slot: + case delitem_slot: + /* This might be a sequence. */ + seq_might = TRUE; + break; + + case sub_slot: + case isub_slot: + case div_slot: + case idiv_slot: + case mod_slot: + case imod_slot: + case floordiv_slot: + case ifloordiv_slot: + case truediv_slot: + case itruediv_slot: + case pos_slot: + case neg_slot: + /* This is definately not a sequence. */ + seq_not = TRUE; + break; + } + + if (!seq_not && seq_might) + for (md = cd -> members; md != NULL; md = md -> next) + { + /* Ignore if the user has been explicit. */ + if (isNumeric(md)) + continue; + + switch (md -> slot) + { + case add_slot: + md -> slot = concat_slot; + break; + + case iadd_slot: + md -> slot = iconcat_slot; + break; + + case mul_slot: + md -> slot = repeat_slot; + break; + + case imul_slot: + md -> slot = irepeat_slot; + break; + } + } + } + + if (inMainModule()) + { + setIsUsedName(cd->iff->name); + setIsUsedName(cd->pyname); + } +} + + +/* + * Return the encoded name of a template (ie. including its argument types) as + * a scoped name. + */ +scopedNameDef *encodedTemplateName(templateDef *td) +{ + int a; + scopedNameDef *snd; + + snd = copyScopedName(td->fqname); + + for (a = 0; a < td->types.nrArgs; ++a) + { + char buf[50]; + int flgs; + scopedNameDef *arg_snd; + argDef *ad = &td->types.args[a]; + + flgs = 0; + + if (isConstArg(ad)) + flgs += 1; + + if (isReference(ad)) + flgs += 2; + + /* We use numbers so they don't conflict with names. */ + sprintf(buf, "%02d%d%d", ad->atype, flgs, ad->nrderefs); + + switch (ad->atype) + { + case defined_type: + arg_snd = copyScopedName(ad->u.snd); + break; + + case template_type: + arg_snd = encodedTemplateName(ad->u.td); + break; + + case struct_type: + arg_snd = copyScopedName(ad->u.sname); + break; + + default: + arg_snd = NULL; + } + + /* + * Replace the first element of the argument name with a copy with the + * encoding prepended. + */ + if (arg_snd != NULL) + arg_snd->name = concat(buf, arg_snd->name, NULL); + else + arg_snd = text2scopePart(sipStrdup(buf)); + + appendScopedName(&snd, arg_snd); + } + + return snd; +} + + +/* + * Create a new mapped type. + */ +static mappedTypeDef *newMappedType(sipSpec *pt, argDef *ad, optFlags *of) +{ + mappedTypeDef *mtd; + scopedNameDef *snd; + ifaceFileDef *iff; + const char *cname; + + /* Check that the type is one we want to map. */ + switch (ad->atype) + { + case defined_type: + snd = ad->u.snd; + cname = scopedNameTail(snd); + break; + + case template_type: + snd = encodedTemplateName(ad->u.td); + cname = NULL; + break; + + case struct_type: + snd = ad->u.sname; + cname = scopedNameTail(snd); + break; + + default: + yyerror("Invalid type for %MappedType"); + } + + iff = findIfaceFile(pt, currentModule, snd, mappedtype_iface, + getAPIRange(of), ad); + + /* Check it hasn't already been defined. */ + for (mtd = pt->mappedtypes; mtd != NULL; mtd = mtd->next) + if (mtd->iff == iff) + { + /* + * We allow types based on the same template but with different + * arguments. + */ + if (ad->atype != template_type || sameBaseType(ad, &mtd->type)) + yyerror("Mapped type has already been defined in this module"); + } + + /* The module may not have been set yet. */ + iff->module = currentModule; + + /* Create a new mapped type. */ + mtd = allocMappedType(pt, ad); + + if (cname != NULL) + mtd->pyname = cacheName(pt, getPythonName(of, cname)); + + if (findOptFlag(of, "NoRelease", bool_flag) != NULL) + setNoRelease(mtd); + + if (getAllowNone(of)) + setHandlesNone(mtd); + + mtd->doctype = getDocType(of); + + mtd->iff = iff; + mtd->next = pt->mappedtypes; + + pt->mappedtypes = mtd; + + if (inMainModule()) + { + setIsUsedName(mtd->cname); + + if (mtd->pyname) + setIsUsedName(mtd->pyname); + } + + return mtd; +} + + +/* + * Allocate, intialise and return a mapped type structure. + */ +mappedTypeDef *allocMappedType(sipSpec *pt, argDef *type) +{ + mappedTypeDef *mtd; + + mtd = sipMalloc(sizeof (mappedTypeDef)); + + mtd->type = *type; + mtd->type.argflags = 0; + mtd->type.nrderefs = 0; + + mtd->cname = cacheName(pt, type2string(&mtd->type)); + + return mtd; +} + + +/* + * Create a new enum. + */ +static enumDef *newEnum(sipSpec *pt, moduleDef *mod, mappedTypeDef *mt_scope, + char *name, optFlags *of, int flags) +{ + enumDef *ed, *first_alt, *next_alt; + classDef *c_scope; + ifaceFileDef *scope; + + if (mt_scope != NULL) + { + scope = mt_scope->iff; + c_scope = NULL; + } + else + { + if ((c_scope = currentScope()) != NULL) + scope = c_scope->iff; + else + scope = NULL; + } + + ed = sipMalloc(sizeof (enumDef)); + + /* Assume the enum isn't versioned. */ + first_alt = ed; + next_alt = NULL; + + if (name != NULL) + { + ed->pyname = cacheName(pt, getPythonName(of, name)); + checkAttributes(pt, mod, c_scope, mt_scope, ed->pyname->text, FALSE); + + ed->fqcname = text2scopedName(scope, name); + ed->cname = cacheName(pt, scopedNameToString(ed->fqcname)); + + if (inMainModule()) + { + setIsUsedName(ed->pyname); + setIsUsedName(ed->cname); + } + + /* If the scope is versioned then look for any alternate. */ + if (scope != NULL && scope->api_range != NULL) + { + enumDef *alt; + + for (alt = pt->enums; alt != NULL; alt = alt->next) + { + if (alt->module != mod || alt->fqcname == NULL) + continue; + + if (compareScopedNames(alt->fqcname, ed->fqcname) == 0) + { + first_alt = alt->first_alt; + next_alt = first_alt->next_alt; + first_alt->next_alt = ed; + + break; + } + } + } + } + else + { + ed->pyname = NULL; + ed->fqcname = NULL; + ed->cname = NULL; + } + + if (flags & SECT_IS_PROT && makeProtPublic) + { + flags &= ~SECT_IS_PROT; + flags |= SECT_IS_PUBLIC; + } + + ed->enumflags = flags; + ed->enumnr = -1; + ed->ecd = c_scope; + ed->emtd = mt_scope; + ed->first_alt = first_alt; + ed->next_alt = next_alt; + ed->module = mod; + ed->members = NULL; + ed->slots = NULL; + ed->overs = NULL; + ed->next = pt -> enums; + + pt->enums = ed; + + return ed; +} + + +/* + * Get the type values and (optionally) the type names for substitution in + * handwritten code. + */ +void appendTypeStrings(scopedNameDef *ename, signatureDef *patt, signatureDef *src, signatureDef *known, scopedNameDef **names, scopedNameDef **values) +{ + int a; + + for (a = 0; a < patt->nrArgs; ++a) + { + argDef *pad = &patt->args[a]; + + if (pad->atype == defined_type) + { + char *nam = NULL, *val; + argDef *sad; + + /* + * If the type names are already known then check that this is one + * of them. + */ + if (known == NULL) + nam = scopedNameTail(pad->u.snd); + else if (pad->u.snd->next == NULL) + { + int k; + + for (k = 0; k < known->nrArgs; ++k) + { + /* Skip base types. */ + if (known->args[k].atype != defined_type) + continue; + + if (strcmp(pad->u.snd->name, known->args[k].u.snd->name) == 0) + { + nam = pad->u.snd->name; + break; + } + } + } + + if (nam == NULL) + continue; + + /* Add the name. */ + appendScopedName(names, text2scopePart(nam)); + + /* + * Add the corresponding value. For defined types we don't want + * any indirection or references. + */ + sad = &src->args[a]; + + if (sad->atype == defined_type) + val = scopedNameToString(sad->u.snd); + else + val = type2string(sad); + + appendScopedName(values, text2scopePart(val)); + } + else if (pad->atype == template_type) + { + argDef *sad = &src->args[a]; + + /* These checks shouldn't be necessary, but... */ + if (sad->atype == template_type && pad->u.td->types.nrArgs == sad->u.td->types.nrArgs) + appendTypeStrings(ename, &pad->u.td->types, &sad->u.td->types, known, names, values); + } + } +} + + +/* + * Convert a type to a string on the heap. The string will use the minimum + * whitespace while still remaining valid C++. + */ +static char *type2string(argDef *ad) +{ + int i, on_heap = FALSE; + int nr_derefs = ad->nrderefs; + int is_reference = isReference(ad); + char *s; + + /* Use the original type if possible. */ + if (ad->original_type != NULL && !noTypeName(ad->original_type)) + { + s = scopedNameToString(ad->original_type->fqname); + on_heap = TRUE; + + nr_derefs -= ad->original_type->type.nrderefs; + + if (isReference(&ad->original_type->type)) + is_reference = FALSE; + } + else + switch (ad->atype) + { + case template_type: + { + templateDef *td = ad->u.td; + + s = scopedNameToString(td->fqname); + append(&s, "<"); + + for (i = 0; i < td->types.nrArgs; ++i) + { + char *sub_type = type2string(&td->types.args[i]); + + if (i > 0) + append(&s, ","); + + append(&s, sub_type); + free(sub_type); + } + + if (s[strlen(s) - 1] == '>') + append(&s, " >"); + else + append(&s, ">"); + + on_heap = TRUE; + break; + } + + case struct_type: + s = scopedNameToString(ad->u.sname); + on_heap = TRUE; + break; + + case defined_type: + s = scopedNameToString(ad->u.snd); + on_heap = TRUE; + break; + + case ustring_type: + s = "unsigned char"; + break; + + case ascii_string_type: + case latin1_string_type: + case utf8_string_type: + case string_type: + s = "char"; + break; + + case sstring_type: + s = "signed char"; + break; + + case wstring_type: + s = "wchar_t"; + break; + + case ushort_type: + s = "unsigned short"; + break; + + case short_type: + s = "short"; + break; + + case uint_type: + s = "unsigned int"; + break; + + case int_type: + case cint_type: + s = "int"; + break; + + case ulong_type: + s = "unsigned long"; + break; + + case long_type: + s = "long"; + break; + + case ulonglong_type: + s = "unsigned long long"; + break; + + case longlong_type: + s = "long long"; + break; + + case float_type: + case cfloat_type: + s = "float"; + break; + + case double_type: + case cdouble_type: + s = "double"; + break; + + case bool_type: + case cbool_type: + s = "bool"; + break; + + default: + fatal("Unsupported type argument to type2string(): %d\n", ad->atype); + } + + /* Make sure the string is on the heap. */ + if (!on_heap) + s = sipStrdup(s); + + while (nr_derefs-- > 0) + append(&s, "*"); + + if (is_reference) + append(&s, "&"); + + return s; +} + + +/* + * Convert a scoped name to a string on the heap. + */ +static char *scopedNameToString(scopedNameDef *name) +{ + static const char scope_string[] = "::"; + size_t len; + scopedNameDef *snd; + char *s, *dp; + + /* Work out the length of buffer needed. */ + len = 0; + + for (snd = name; snd != NULL; snd = snd->next) + { + len += strlen(snd->name); + + if (snd->next != NULL) + { + /* Ignore the encoded part of template names. */ + if (isdigit(snd->next->name[0])) + break; + + len += strlen(scope_string); + } + } + + /* Allocate and populate the buffer. */ + dp = s = sipMalloc(len + 1); + + for (snd = name; snd != NULL; snd = snd->next) + { + strcpy(dp, snd->name); + dp += strlen(snd->name); + + if (snd->next != NULL) + { + /* Ignore the encoded part of template names. */ + if (isdigit(snd->next->name[0])) + break; + + strcpy(dp, scope_string); + dp += strlen(scope_string); + } + } + + return s; +} + + +/* + * Instantiate a class template. + */ +static void instantiateClassTemplate(sipSpec *pt, moduleDef *mod, + classDef *scope, scopedNameDef *fqname, classTmplDef *tcd, + templateDef *td) +{ + scopedNameDef *type_names, *type_values; + classDef *cd; + ctorDef *oct, **cttail; + argDef *ad; + ifaceFileList *iffl, **used; + + type_names = type_values = NULL; + appendTypeStrings(classFQCName(tcd->cd), &tcd->sig, &td->types, NULL, &type_names, &type_values); + + /* + * Add a mapping from the template name to the instantiated name. If we + * have got this far we know there is room for it. + */ + ad = &tcd->sig.args[tcd->sig.nrArgs++]; + memset(ad, 0, sizeof (argDef)); + ad->atype = defined_type; + ad->u.snd = classFQCName(tcd->cd); + + appendScopedName(&type_names, text2scopePart(scopedNameTail(classFQCName(tcd->cd)))); + appendScopedName(&type_values, text2scopePart(scopedNameToString(fqname))); + + /* Create the new class. */ + cd = sipMalloc(sizeof (classDef)); + + /* Start with a shallow copy. */ + *cd = *tcd->cd; + + resetIsTemplateClass(cd); + cd->pyname = cacheName(pt, scopedNameTail(fqname)); + cd->td = td; + + /* Handle the interface file. */ + cd->iff = findIfaceFile(pt, mod, fqname, class_iface, + (scope != NULL ? scope->iff->api_range : NULL), NULL); + cd->iff->module = mod; + + /* Make a copy of the used list and add the enclosing scope. */ + used = &cd->iff->used; + + for (iffl = tcd->cd->iff->used; iffl != NULL; iffl = iffl->next) + addToUsedList(used, iffl->iff); + + /* Include any scope header code. */ + if (scope != NULL) + appendCodeBlock(&cd->iff->hdrcode, scope->iff->hdrcode); + + if (inMainModule()) + { + setIsUsedName(cd->iff->name); + setIsUsedName(cd->pyname); + } + + cd->ecd = currentScope(); + + /* Handle the enums. */ + instantiateTemplateEnums(pt, tcd, td, cd, used, type_names, type_values); + + /* Handle the variables. */ + instantiateTemplateVars(pt, tcd, td, cd, used, type_names, type_values); + + /* Handle the ctors. */ + cd->ctors = NULL; + cttail = &cd->ctors; + + for (oct = tcd->cd->ctors; oct != NULL; oct = oct->next) + { + ctorDef *nct = sipMalloc(sizeof (ctorDef)); + + /* Start with a shallow copy. */ + *nct = *oct; + + templateSignature(&nct->pysig, FALSE, tcd, td, cd); + + if (oct->cppsig == NULL) + nct->cppsig = NULL; + else if (oct->cppsig == &oct->pysig) + nct->cppsig = &nct->pysig; + else + { + nct->cppsig = sipMalloc(sizeof (signatureDef)); + + *nct->cppsig = *oct->cppsig; + + templateSignature(nct->cppsig, FALSE, tcd, td, cd); + } + + nct->methodcode = templateCode(pt, used, nct->methodcode, type_names, type_values); + + nct->next = NULL; + *cttail = nct; + cttail = &nct->next; + + /* Handle the default ctor. */ + if (tcd->cd->defctor == oct) + cd->defctor = nct; + } + + cd->dealloccode = templateCode(pt, used, cd->dealloccode, type_names, type_values); + cd->dtorcode = templateCode(pt, used, cd->dtorcode, type_names, type_values); + + /* Handle the methods. */ + cd->members = instantiateTemplateMethods(tcd->cd->members, mod); + cd->overs = instantiateTemplateOverloads(pt, tcd->cd->overs, + tcd->cd->members, cd->members, tcd, td, cd, used, type_names, + type_values); + + cd->cppcode = templateCode(pt, used, cd->cppcode, type_names, type_values); + cd->iff->hdrcode = templateCode(pt, used, cd->iff->hdrcode, type_names, type_values); + cd->convtosubcode = templateCode(pt, used, cd->convtosubcode, type_names, type_values); + cd->convtocode = templateCode(pt, used, cd->convtocode, type_names, type_values); + cd->travcode = templateCode(pt, used, cd->travcode, type_names, type_values); + cd->clearcode = templateCode(pt, used, cd->clearcode, type_names, type_values); + cd->getbufcode = templateCode(pt, used, cd->getbufcode, type_names, type_values); + cd->releasebufcode = templateCode(pt, used, cd->releasebufcode, type_names, type_values); + cd->readbufcode = templateCode(pt, used, cd->readbufcode, type_names, type_values); + cd->writebufcode = templateCode(pt, used, cd->writebufcode, type_names, type_values); + cd->segcountcode = templateCode(pt, used, cd->segcountcode, type_names, type_values); + cd->charbufcode = templateCode(pt, used, cd->charbufcode, type_names, type_values); + cd->picklecode = templateCode(pt, used, cd->picklecode, type_names, type_values); + cd->next = pt->classes; + + pt->classes = cd; + + tcd->sig.nrArgs--; + + freeScopedName(type_names); + freeScopedName(type_values); +} + + +/* + * Instantiate the methods of a template class. + */ +static memberDef *instantiateTemplateMethods(memberDef *tmd, moduleDef *mod) +{ + memberDef *md, *methods, **mdtail; + + methods = NULL; + mdtail = &methods; + + for (md = tmd; md != NULL; md = md->next) + { + memberDef *nmd = sipMalloc(sizeof (memberDef)); + + /* Start with a shallow copy. */ + *nmd = *md; + + nmd->module = mod; + + if (inMainModule()) + setIsUsedName(nmd->pyname); + + nmd->next = NULL; + *mdtail = nmd; + mdtail = &nmd->next; + } + + return methods; +} + + +/* + * Instantiate the overloads of a template class. + */ +static overDef *instantiateTemplateOverloads(sipSpec *pt, overDef *tod, + memberDef *tmethods, memberDef *methods, classTmplDef *tcd, + templateDef *td, classDef *cd, ifaceFileList **used, + scopedNameDef *type_names, scopedNameDef *type_values) +{ + overDef *od, *overloads, **odtail; + + overloads = NULL; + odtail = &overloads; + + for (od = tod; od != NULL; od = od->next) + { + overDef *nod = sipMalloc(sizeof (overDef)); + memberDef *nmd, *omd; + + /* Start with a shallow copy. */ + *nod = *od; + + for (nmd = methods, omd = tmethods; omd != NULL; omd = omd->next, nmd = nmd->next) + if (omd == od->common) + { + nod->common = nmd; + break; + } + + templateSignature(&nod->pysig, TRUE, tcd, td, cd); + + if (od->cppsig == &od->pysig) + nod->cppsig = &nod->pysig; + else + { + nod->cppsig = sipMalloc(sizeof (signatureDef)); + + *nod->cppsig = *od->cppsig; + + templateSignature(nod->cppsig, TRUE, tcd, td, cd); + } + + nod->methodcode = templateCode(pt, used, nod->methodcode, type_names, type_values); + + /* Handle any virtual handler. */ + if (od->virthandler != NULL) + { + moduleDef *mod = cd->iff->module; + + nod->virthandler = sipMalloc(sizeof (virtHandlerDef)); + + /* Start with a shallow copy. */ + *nod->virthandler = *od->virthandler; + + if (od->virthandler->cppsig == &od->pysig) + nod->virthandler->cppsig = &nod->pysig; + else + { + nod->virthandler->cppsig = sipMalloc(sizeof (signatureDef)); + + *nod->virthandler->cppsig = *od->virthandler->cppsig; + + templateSignature(nod->virthandler->cppsig, TRUE, tcd, td, cd); + } + + nod->virthandler->module = mod; + nod->virthandler->virtcode = templateCode(pt, used, nod->virthandler->virtcode, type_names, type_values); + nod->virthandler->next = mod->virthandlers; + + mod->virthandlers = nod->virthandler; + } + + nod->next = NULL; + *odtail = nod; + odtail = &nod->next; + } + + return overloads; +} + + +/* + * Instantiate the enums of a template class. + */ +static void instantiateTemplateEnums(sipSpec *pt, classTmplDef *tcd, + templateDef *td, classDef *cd, ifaceFileList **used, + scopedNameDef *type_names, scopedNameDef *type_values) +{ + enumDef *ted; + moduleDef *mod = cd->iff->module; + + for (ted = pt->enums; ted != NULL; ted = ted->next) + if (ted->ecd == tcd->cd) + { + enumDef *ed; + enumMemberDef *temd; + + ed = sipMalloc(sizeof (enumDef)); + + /* Start with a shallow copy. */ + *ed = *ted; + + if (ed->fqcname != NULL) + { + ed->fqcname = text2scopedName(cd->iff, + scopedNameTail(ed->fqcname)); + ed->cname = cacheName(pt, scopedNameToString(ed->fqcname)); + } + + if (inMainModule()) + { + if (ed->pyname != NULL) + setIsUsedName(ed->pyname); + + if (ed->cname != NULL) + setIsUsedName(ed->cname); + } + + ed->ecd = cd; + ed->first_alt = ed; + ed->module = mod; + ed->members = NULL; + + for (temd = ted->members; temd != NULL; temd = temd->next) + { + enumMemberDef *emd; + + emd = sipMalloc(sizeof (enumMemberDef)); + + /* Start with a shallow copy. */ + *emd = *temd; + emd->ed = ed; + + emd->next = ed->members; + ed->members = emd; + } + + ed->slots = instantiateTemplateMethods(ted->slots, mod); + ed->overs = instantiateTemplateOverloads(pt, ted->overs, + ted->slots, ed->slots, tcd, td, cd, used, type_names, + type_values); + + ed->next = pt->enums; + pt->enums = ed; + } +} + + +/* + * Instantiate the variables of a template class. + */ +static void instantiateTemplateVars(sipSpec *pt, classTmplDef *tcd, + templateDef *td, classDef *cd, ifaceFileList **used, + scopedNameDef *type_names, scopedNameDef *type_values) +{ + varDef *tvd; + + for (tvd = pt->vars; tvd != NULL; tvd = tvd->next) + if (tvd->ecd == tcd->cd) + { + varDef *vd; + + vd = sipMalloc(sizeof (varDef)); + + /* Start with a shallow copy. */ + *vd = *tvd; + + if (inMainModule()) + setIsUsedName(vd->pyname); + + vd->fqcname = text2scopedName(cd->iff, + scopedNameTail(vd->fqcname)); + vd->ecd = cd; + vd->module = cd->iff->module; + + templateType(&vd->type, tcd, td, cd); + + vd->accessfunc = templateCode(pt, used, vd->accessfunc, type_names, type_values); + vd->getcode = templateCode(pt, used, vd->getcode, type_names, type_values); + vd->setcode = templateCode(pt, used, vd->setcode, type_names, type_values); + + addVariable(pt, vd); + } +} + + +/* + * Replace any template arguments in a signature. + */ +static void templateSignature(signatureDef *sd, int result, classTmplDef *tcd, templateDef *td, classDef *ncd) +{ + int a; + + if (result) + templateType(&sd->result, tcd, td, ncd); + + for (a = 0; a < sd->nrArgs; ++a) + templateType(&sd->args[a], tcd, td, ncd); +} + + +/* + * Replace any template arguments in a type. + */ +static void templateType(argDef *ad, classTmplDef *tcd, templateDef *td, classDef *ncd) +{ + int a; + char *name; + + /* Descend into any sub-templates. */ + if (ad->atype == template_type) + { + templateDef *new_td = sipMalloc(sizeof (templateDef)); + + /* Make a deep copy of the template definition. */ + *new_td = *ad->u.td; + ad->u.td = new_td; + + templateSignature(&ad->u.td->types, FALSE, tcd, td, ncd); + + return; + } + + /* Ignore if it isn't an unscoped name. */ + if (ad->atype != defined_type || ad->u.snd->next != NULL) + return; + + name = ad->u.snd->name; + + for (a = 0; a < tcd->sig.nrArgs - 1; ++a) + if (strcmp(name, scopedNameTail(tcd->sig.args[a].u.snd)) == 0) + { + argDef *tad = &td->types.args[a]; + + ad->atype = tad->atype; + + /* We take the constrained flag from the real type. */ + resetIsConstrained(ad); + + if (isConstrained(tad)) + setIsConstrained(ad); + + ad->u = tad->u; + + return; + } + + /* Handle the class name itself. */ + if (strcmp(name, scopedNameTail(classFQCName(tcd->cd))) == 0) + { + ad->atype = class_type; + ad->u.cd = ncd; + ad->original_type = NULL; + } +} + + +/* + * Replace any template arguments in a literal code block. + */ +codeBlock *templateCode(sipSpec *pt, ifaceFileList **used, codeBlock *ocb, + scopedNameDef *names, scopedNameDef *values) +{ + codeBlock *ncb = NULL, **tail = &ncb; + + while (ocb != NULL) + { + char *at = ocb->frag; + + do + { + char *first = NULL; + codeBlock *cb; + scopedNameDef *nam, *val, *nam_first, *val_first; + + /* + * Go through the rest of this fragment looking for each of the + * types and the name of the class itself. + */ + nam = names; + val = values; + + while (nam != NULL && val != NULL) + { + char *cp; + + if ((cp = strstr(at, nam->name)) != NULL) + if (first == NULL || first > cp) + { + nam_first = nam; + val_first = val; + first = cp; + } + + nam = nam->next; + val = val->next; + } + + /* Create the new fragment. */ + cb = sipMalloc(sizeof (codeBlock)); + + if (at == ocb->frag) + { + cb->filename = ocb->filename; + cb->linenr = ocb->linenr; + } + else + cb->filename = NULL; + + cb->next = NULL; + *tail = cb; + tail = &cb->next; + + /* See if anything was found. */ + if (first == NULL) + { + /* We can just point to this. */ + cb->frag = at; + + /* All done with this one. */ + at = NULL; + } + else + { + static char *gen_names[] = { + "sipType_", + "sipClass_", + "sipEnum_", + "sipException_", + NULL + }; + + char *dp, *sp, **gn; + int genname = FALSE; + + /* + * If the context in which the text is used is in the name of a + * SIP generated object then translate any "::" scoping to "_". + */ + for (gn = gen_names; *gn != NULL; ++gn) + if (search_back(first, at, *gn)) + { + addUsedFromCode(pt, used, val_first->name); + genname = TRUE; + break; + } + + /* Fragment the fragment. */ + cb->frag = sipMalloc(first - at + strlen(val_first->name) + 1); + + strncpy(cb->frag, at, first - at); + + dp = &cb->frag[first - at]; + sp = val_first->name; + + if (genname) + { + char gch; + + while ((gch = *sp++) != '\0') + if (gch == ':' && *sp == ':') + { + *dp++ = '_'; + ++sp; + } + else + *dp++ = gch; + + *dp = '\0'; + } + else + strcpy(dp, sp); + + /* Move past the replaced text. */ + at = first + strlen(nam_first->name); + } + } + while (at != NULL && *at != '\0'); + + ocb = ocb->next; + } + + return ncb; +} + + +/* + * Return TRUE if the text at the end of a string matches the target string. + */ +static int search_back(const char *end, const char *start, const char *target) +{ + size_t tlen = strlen(target); + + if (start + tlen >= end) + return FALSE; + + return (strncmp(end - tlen, target, tlen) == 0); +} + + +/* + * Add any needed interface files based on handwritten code. + */ +static void addUsedFromCode(sipSpec *pt, ifaceFileList **used, const char *sname) +{ + ifaceFileDef *iff; + enumDef *ed; + + for (iff = pt->ifacefiles; iff != NULL; iff = iff->next) + { + if (iff->type != class_iface && iff->type != exception_iface) + continue; + + if (sameName(iff->fqcname, sname)) + { + addToUsedList(used, iff); + return; + } + } + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + if (ed->ecd == NULL) + continue; + + if (sameName(ed->fqcname, sname)) + { + addToUsedList(used, ed->ecd->iff); + return; + } + } +} + + +/* + * Compare a scoped name with its string equivalent. + */ +static int sameName(scopedNameDef *snd, const char *sname) +{ + while (snd != NULL && *sname != '\0') + { + const char *sp = snd->name; + + while (*sp != '\0' && *sname != ':' && *sname != '\0') + if (*sp++ != *sname++) + return FALSE; + + if (*sp != '\0' || (*sname != ':' && *sname != '\0')) + return FALSE; + + snd = snd->next; + + if (*sname == ':') + sname += 2; + } + + return (snd == NULL && *sname == '\0'); +} + + +/* + * Compare a (possibly) relative scoped name with a fully qualified scoped name + * while taking the current scope into account. + */ +static int foundInScope(scopedNameDef *fq_name, scopedNameDef *rel_name) +{ + classDef *scope; + + for (scope = currentScope(); scope != NULL; scope = scope->ecd) + { + scopedNameDef *snd; + int found; + + snd = copyScopedName(classFQCName(scope)); + appendScopedName(&snd, copyScopedName(rel_name)); + + found = (compareScopedNames(fq_name, snd) == 0); + + freeScopedName(snd); + + if (found) + return TRUE; + } + + return compareScopedNames(fq_name, rel_name) == 0; +} + + +/* + * Create a new typedef. + */ +static void newTypedef(sipSpec *pt, moduleDef *mod, char *name, argDef *type, + optFlags *optflgs) +{ + typedefDef *td, **tdp; + scopedNameDef *fqname; + classDef *scope; + + scope = currentScope(); + fqname = text2scopedName((scope != NULL ? scope->iff : NULL), name); + + /* See if we are instantiating a template class. */ + if (type->atype == template_type) + { + classTmplDef *tcd; + templateDef *td = type->u.td; + + for (tcd = pt->classtemplates; tcd != NULL; tcd = tcd->next) + if (foundInScope(tcd->cd->iff->fqcname, td->fqname) && + sameTemplateSignature(&tcd->sig, &td->types, FALSE)) + { + instantiateClassTemplate(pt, mod, scope, fqname, tcd, td); + + /* All done. */ + return; + } + } + + /* + * Check it doesn't already exist and find the position in the sorted list + * where it should be put. + */ + for (tdp = &pt->typedefs; *tdp != NULL; tdp = &(*tdp)->next) + { + int res = compareScopedNames((*tdp)->fqname, fqname); + + if (res == 0) + { + fatalScopedName(fqname); + fatal(" already defined\n"); + } + + if (res > 0) + break; + } + + td = sipMalloc(sizeof (typedefDef)); + + td->tdflags = 0; + td->fqname = fqname; + td->ecd = scope; + td->module = mod; + td->type = *type; + + td->next = *tdp; + *tdp = td; + + if (findOptFlag(optflgs, "NoTypeName", bool_flag) != NULL) + setNoTypeName(td); + + mod->nrtypedefs++; +} + + +/* + * Speculatively try and resolve any typedefs. In some cases (eg. when + * comparing template signatures) it helps to use the real type if it is known. + * Note that this wouldn't be necessary if we required that all types be known + * before they are used. + */ +static void resolveAnyTypedef(sipSpec *pt, argDef *ad) +{ + argDef orig = *ad; + + while (ad->atype == defined_type) + { + ad->atype = no_type; + searchTypedefs(pt, ad->u.snd, ad); + + /* + * Don't resolve to a template type as it may be superceded later on + * by a more specific mapped type. + */ + if (ad->atype == no_type || ad->atype == template_type) + { + *ad = orig; + break; + } + } +} + + +/* + * Return TRUE if the template signatures are the same. A deep comparison is + * used for mapped type templates where we want to recurse into any nested + * templates. + */ +int sameTemplateSignature(signatureDef *tmpl_sd, signatureDef *args_sd, + int deep) +{ + int a; + + if (tmpl_sd->nrArgs != args_sd->nrArgs) + return FALSE; + + for (a = 0; a < tmpl_sd->nrArgs; ++a) + { + argDef *tmpl_ad = &tmpl_sd->args[a]; + argDef *args_ad = &args_sd->args[a]; + + /* + * If we are doing a shallow comparision (ie. for class templates) then + * a type name in the template signature matches anything in the + * argument signature. + */ + if (tmpl_ad->atype == defined_type && !deep) + continue; + + /* + * For type names only compare the references and pointers, and do the + * same for any nested templates. + */ + if (tmpl_ad->atype == defined_type && args_ad->atype == defined_type) + { + if (isReference(tmpl_ad) != isReference(args_ad) || tmpl_ad->nrderefs != args_ad->nrderefs) + return FALSE; + } + else if (tmpl_ad->atype == template_type && args_ad->atype == template_type) + { + if (!sameTemplateSignature(&tmpl_ad->u.td->types, &args_ad->u.td->types, deep)) + return FALSE; + } + else if (!sameBaseType(tmpl_ad, args_ad)) + return FALSE; + } + + return TRUE; +} + + +/* + * Create a new variable. + */ +static void newVar(sipSpec *pt,moduleDef *mod,char *name,int isstatic, + argDef *type,optFlags *of,codeBlock *acode,codeBlock *gcode, + codeBlock *scode) +{ + varDef *var; + classDef *escope = currentScope(); + nameDef *nd = cacheName(pt,getPythonName(of,name)); + + if (inMainModule()) + setIsUsedName(nd); + + checkAttributes(pt, mod, escope, NULL, nd->text, FALSE); + + var = sipMalloc(sizeof (varDef)); + + var->pyname = nd; + var->fqcname = text2scopedName((escope != NULL ? escope->iff : NULL), + name); + var->ecd = escope; + var->module = mod; + var->varflags = 0; + var->type = *type; + var->accessfunc = acode; + var->getcode = gcode; + var->setcode = scode; + + if (isstatic || (escope != NULL && escope->iff->type == namespace_iface)) + setIsStaticVar(var); + + addVariable(pt, var); +} + + +/* + * Create a new ctor. + */ +static void newCtor(char *name, int sectFlags, signatureDef *args, + optFlags *optflgs, codeBlock *methodcode, throwArgs *exceptions, + signatureDef *cppsig, int explicit, codeBlock *docstring) +{ + ctorDef *ct, **ctp; + classDef *cd = currentScope(); + + /* Check the name of the constructor. */ + if (strcmp(classBaseName(cd), name) != 0) + yyerror("Constructor doesn't have the same name as its class"); + + if (docstring != NULL) + appendCodeBlock(&cd->docstring, docstring); + + /* Add to the list of constructors. */ + ct = sipMalloc(sizeof (ctorDef)); + + if (sectFlags & SECT_IS_PROT && makeProtPublic) + { + sectFlags &= ~SECT_IS_PROT; + sectFlags |= SECT_IS_PUBLIC; + } + + /* Allow the signature to be used like an function signature. */ + memset(&args->result, 0, sizeof (argDef)); + args->result.atype = void_type; + + ct->ctorflags = sectFlags; + ct->api_range = getAPIRange(optflgs); + ct->pysig = *args; + ct->cppsig = (cppsig != NULL ? cppsig : &ct->pysig); + ct->exceptions = exceptions; + ct->methodcode = methodcode; + + if (!isPrivateCtor(ct)) + setCanCreate(cd); + + if (isProtectedCtor(ct)) + setHasShadow(cd); + + if (explicit) + setIsExplicitCtor(ct); + + getHooks(optflgs, &ct->prehook, &ct->posthook); + + if (getReleaseGIL(optflgs)) + setIsReleaseGILCtor(ct); + else if (getHoldGIL(optflgs)) + setIsHoldGILCtor(ct); + + if (getTransfer(optflgs)) + setIsResultTransferredCtor(ct); + + if (getDeprecated(optflgs)) + setIsDeprecatedCtor(ct); + + if (!isPrivateCtor(ct) && usesKeywordArgs(optflgs, &ct->pysig)) + setUseKeywordArgsCtor(ct); + + if (findOptFlag(optflgs, "NoDerived", bool_flag) != NULL) + { + if (cppsig != NULL) + yyerror("The /NoDerived/ annotation cannot be used with a C++ signature"); + + if (methodcode == NULL) + yyerror("The /NoDerived/ annotation must be used with %MethodCode"); + + ct->cppsig = NULL; + } + + if (findOptFlag(optflgs, "Default", bool_flag) != NULL) + { + if (cd->defctor != NULL) + yyerror("A constructor with the /Default/ annotation has already been defined"); + + cd->defctor = ct; + } + + /* Append to the list. */ + for (ctp = &cd->ctors; *ctp != NULL; ctp = &(*ctp)->next) + ; + + *ctp = ct; +} + + +/* + * Create a new function. + */ +static void newFunction(sipSpec *pt, moduleDef *mod, classDef *c_scope, + mappedTypeDef *mt_scope, int sflags, int isstatic, int issignal, + int isslot, int isvirt, char *name, signatureDef *sig, int isconst, + int isabstract, optFlags *optflgs, codeBlock *methodcode, + codeBlock *vcode, throwArgs *exceptions, signatureDef *cppsig, + codeBlock *docstring) +{ + int factory, xferback, no_arg_parser; + overDef *od, **odp, **headp; + optFlag *of; + virtHandlerDef *vhd; + + /* Extra checks for a C module. */ + if (pt->genc) + { + if (c_scope != NULL) + yyerror("Function declaration not allowed in a struct in a C module"); + + if (isstatic) + yyerror("Static functions not allowed in a C module"); + + if (exceptions != NULL) + yyerror("Exceptions not allowed in a C module"); + } + + if (mt_scope != NULL) + headp = &mt_scope->overs; + else if (c_scope != NULL) + headp = &c_scope->overs; + else + headp = &mod->overs; + + /* See if it is a factory method. */ + if (findOptFlag(optflgs, "Factory", bool_flag) != NULL) + factory = TRUE; + else + { + int a; + + factory = FALSE; + + /* Check /TransferThis/ wasn't specified. */ + if (c_scope == NULL || isstatic) + for (a = 0; a < sig->nrArgs; ++a) + if (isThisTransferred(&sig->args[a])) + yyerror("/TransferThis/ may only be specified in constructors and class methods"); + } + + /* See if the result is to be returned to Python ownership. */ + xferback = (findOptFlag(optflgs, "TransferBack", bool_flag) != NULL); + + if (factory && xferback) + yyerror("/TransferBack/ and /Factory/ cannot both be specified"); + + /* Create a new overload definition. */ + + od = sipMalloc(sizeof (overDef)); + + /* Set the overload flags. */ + + if ((sflags & SECT_IS_PROT) && makeProtPublic) + { + sflags &= ~SECT_IS_PROT; + sflags |= SECT_IS_PUBLIC | OVER_REALLY_PROT; + } + + od->overflags = sflags; + + if (issignal) + { + resetIsSlot(od); + setIsSignal(od); + } + else if (isslot) + { + resetIsSignal(od); + setIsSlot(od); + } + + if (factory) + setIsFactory(od); + + if (xferback) + setIsResultTransferredBack(od); + + if (getTransfer(optflgs)) + setIsResultTransferred(od); + + if (findOptFlag(optflgs, "TransferThis", bool_flag) != NULL) + setIsThisTransferredMeth(od); + + if (isProtected(od)) + setHasShadow(c_scope); + + if ((isSlot(od) || isSignal(od)) && !isPrivate(od)) + { + if (isSignal(od)) + setHasShadow(c_scope); + + pt->sigslots = TRUE; + } + + if (isSignal(od) && (methodcode != NULL || vcode != NULL)) + yyerror("Cannot provide code for signals"); + + if (isstatic) + { + if (isSignal(od)) + yyerror("Static functions cannot be signals"); + + if (isvirt) + yyerror("Static functions cannot be virtual"); + + setIsStatic(od); + } + + if (isconst) + setIsConst(od); + + if (isabstract) + { + if (sflags == 0) + yyerror("Non-class function specified as abstract"); + + setIsAbstract(od); + } + + if ((of = findOptFlag(optflgs, "AutoGen", opt_name_flag)) != NULL) + { + if (of->fvalue.sval == NULL || isEnabledFeature(of->fvalue.sval)) + setIsAutoGen(od); + } + + if (isvirt) + { + if (isSignal(od) && pluginPyQt3(pt)) + yyerror("Virtual signals aren't supported"); + + setIsVirtual(od); + setHasShadow(c_scope); + + vhd = sipMalloc(sizeof (virtHandlerDef)); + + vhd->virthandlernr = -1; + vhd->vhflags = 0; + vhd->pysig = &od->pysig; + vhd->cppsig = (cppsig != NULL ? cppsig : &od->pysig); + vhd->virtcode = vcode; + + if (factory || xferback) + setIsTransferVH(vhd); + + /* + * Only add it to the module's virtual handlers if we are not in a + * class template. + */ + if (!currentIsTemplate) + { + vhd->module = mod; + + vhd->next = mod->virthandlers; + mod->virthandlers = vhd; + } + } + else + { + if (vcode != NULL) + yyerror("%VirtualCatcherCode provided for non-virtual function"); + + vhd = NULL; + } + + od->cppname = name; + od->pysig = *sig; + od->cppsig = (cppsig != NULL ? cppsig : &od->pysig); + od->exceptions = exceptions; + od->methodcode = methodcode; + od->virthandler = vhd; + + no_arg_parser = (findOptFlag(optflgs, "NoArgParser", bool_flag) != NULL); + + if (no_arg_parser) + { + if (methodcode == NULL) + yyerror("%MethodCode must be supplied if /NoArgParser/ is specified"); + } + + if (findOptFlag(optflgs, "NoCopy", bool_flag) != NULL) + setNoCopy(&od->pysig.result); + + od->common = findFunction(pt, mod, c_scope, mt_scope, + getPythonName(optflgs, name), (methodcode != NULL), sig->nrArgs, + no_arg_parser); + + if (docstring != NULL) + appendCodeBlock(&od->common->docstring, docstring); + + od->api_range = getAPIRange(optflgs); + + if (od->api_range == NULL) + setNotVersioned(od->common); + + if (findOptFlag(optflgs, "Numeric", bool_flag) != NULL) + setIsNumeric(od->common); + + /* Methods that run in new threads must be virtual. */ + if (findOptFlag(optflgs, "NewThread", bool_flag) != NULL) + { + argDef *res; + + if (!isvirt) + yyerror("/NewThread/ may only be specified for virtual functions"); + + /* + * This is an arbitary limitation to make the code generator slightly + * easier - laziness on my part. + */ + res = &od->cppsig->result; + + if (res->atype != void_type || res->nrderefs != 0) + yyerror("/NewThread/ may only be specified for void functions"); + + setIsNewThread(od); + } + + getHooks(optflgs, &od->prehook, &od->posthook); + + if (getReleaseGIL(optflgs)) + setIsReleaseGIL(od); + else if (getHoldGIL(optflgs)) + setIsHoldGIL(od); + + if (getDeprecated(optflgs)) + setIsDeprecated(od); + + if (!isPrivate(od) && !isSignal(od) && od->common->slot == no_slot && usesKeywordArgs(optflgs, &od->pysig)) + { + setUseKeywordArgs(od); + setUseKeywordArgsFunction(od->common); + } + + /* See if we want to auto-generate a __len__() method. */ + if (findOptFlag(optflgs, "__len__", bool_flag) != NULL) + { + overDef *len; + + len = sipMalloc(sizeof (overDef)); + + len->cppname = "__len__"; + len->overflags = SECT_IS_PUBLIC; + len->pysig.result.atype = ssize_type; + len->pysig.nrArgs = 0; + len->cppsig = &len->pysig; + + len->common = findFunction(pt, mod, c_scope, mt_scope, len->cppname, + TRUE, 0, FALSE); + + if ((len->methodcode = od->methodcode) == NULL) + { + char *buf = sipStrdup(" sipRes = (SIP_SSIZE_T)sipCpp->"); + codeBlock *code; + + append(&buf, od->cppname); + append(&buf, "();\n"); + + code = sipMalloc(sizeof (codeBlock)); + + code->frag = buf; + code->filename = "Auto-generated"; + code->linenr = 0; + code->next = NULL; + + len->methodcode = code; + } + + len->next = NULL; + + od->next = len; + } + else + { + od->next = NULL; + } + + /* Append to the list. */ + for (odp = headp; *odp != NULL; odp = &(*odp)->next) + ; + + *odp = od; +} + + +/* + * Return the Python name based on the C/C++ name and any /PyName/ annotation. + */ +static const char *getPythonName(optFlags *optflgs, const char *cname) +{ + const char *pname; + optFlag *of; + + if ((of = findOptFlag(optflgs, "PyName", name_flag)) != NULL) + pname = of->fvalue.sval; + else + pname = cname; + + return pname; +} + + +/* + * Cache a name in a module. Entries in the cache are stored in order of + * decreasing length. + */ +nameDef *cacheName(sipSpec *pt, const char *name) +{ + nameDef *nd, **ndp; + size_t len; + + /* Allow callers to be lazy about checking if there is really a name. */ + if (name == NULL) + return NULL; + + /* Skip entries that are too large. */ + ndp = &pt->namecache; + len = strlen(name); + + while (*ndp != NULL && (*ndp)->len > len) + ndp = &(*ndp)->next; + + /* Check entries that are the right length. */ + for (nd = *ndp; nd != NULL && nd->len == len; nd = nd->next) + if (memcmp(nd->text, name, len) == 0) + return nd; + + /* Create a new one. */ + nd = sipMalloc(sizeof (nameDef)); + + nd->nameflags = 0; + nd->text = name; + nd->len = len; + nd->next = *ndp; + + *ndp = nd; + + return nd; +} + + +/* + * Find (or create) an overloaded function name. + */ +static memberDef *findFunction(sipSpec *pt, moduleDef *mod, classDef *c_scope, + mappedTypeDef *mt_scope, const char *pname, int hwcode, int nrargs, + int no_arg_parser) +{ + static struct slot_map { + const char *name; /* The slot name. */ + slotType type; /* The corresponding type. */ + int needs_hwcode; /* Set if handwritten code is required. */ + int nrargs; /* Nr. of arguments. */ + } slot_table[] = { + {"__str__", str_slot, TRUE, 0}, + {"__unicode__", unicode_slot, TRUE, 0}, + {"__int__", int_slot, FALSE, 0}, + {"__long__", long_slot, FALSE, 0}, + {"__float__", float_slot, FALSE, 0}, + {"__len__", len_slot, TRUE, 0}, + {"__contains__", contains_slot, TRUE, 1}, + {"__add__", add_slot, FALSE, 1}, + {"__sub__", sub_slot, FALSE, 1}, + {"__mul__", mul_slot, FALSE, 1}, + {"__div__", div_slot, FALSE, 1}, + {"__mod__", mod_slot, FALSE, 1}, + {"__floordiv__", floordiv_slot, TRUE, 1}, + {"__truediv__", truediv_slot, FALSE, 1}, + {"__and__", and_slot, FALSE, 1}, + {"__or__", or_slot, FALSE, 1}, + {"__xor__", xor_slot, FALSE, 1}, + {"__lshift__", lshift_slot, FALSE, 1}, + {"__rshift__", rshift_slot, FALSE, 1}, + {"__iadd__", iadd_slot, FALSE, 1}, + {"__isub__", isub_slot, FALSE, 1}, + {"__imul__", imul_slot, FALSE, 1}, + {"__idiv__", idiv_slot, FALSE, 1}, + {"__imod__", imod_slot, FALSE, 1}, + {"__ifloordiv__", ifloordiv_slot, TRUE, 1}, + {"__itruediv__", itruediv_slot, FALSE, 1}, + {"__iand__", iand_slot, FALSE, 1}, + {"__ior__", ior_slot, FALSE, 1}, + {"__ixor__", ixor_slot, FALSE, 1}, + {"__ilshift__", ilshift_slot, FALSE, 1}, + {"__irshift__", irshift_slot, FALSE, 1}, + {"__invert__", invert_slot, FALSE, 0}, + {"__call__", call_slot, FALSE, -1}, + {"__getitem__", getitem_slot, FALSE, 1}, + {"__setitem__", setitem_slot, TRUE, 2}, + {"__delitem__", delitem_slot, TRUE, 1}, + {"__lt__", lt_slot, FALSE, 1}, + {"__le__", le_slot, FALSE, 1}, + {"__eq__", eq_slot, FALSE, 1}, + {"__ne__", ne_slot, FALSE, 1}, + {"__gt__", gt_slot, FALSE, 1}, + {"__ge__", ge_slot, FALSE, 1}, + {"__cmp__", cmp_slot, FALSE, 1}, + {"__bool__", bool_slot, TRUE, 0}, + {"__nonzero__", bool_slot, TRUE, 0}, + {"__neg__", neg_slot, FALSE, 0}, + {"__pos__", pos_slot, FALSE, 0}, + {"__abs__", abs_slot, TRUE, 0}, + {"__repr__", repr_slot, TRUE, 0}, + {"__hash__", hash_slot, TRUE, 0}, + {"__index__", index_slot, TRUE, 0}, + {"__iter__", iter_slot, TRUE, 0}, + {"__next__", next_slot, TRUE, 0}, + {NULL} + }; + + memberDef *md, **flist; + struct slot_map *sm; + slotType st; + + /* Get the slot type. */ + st = no_slot; + + for (sm = slot_table; sm->name != NULL; ++sm) + if (strcmp(sm->name, pname) == 0) + { + if (sm->needs_hwcode && !hwcode) + yyerror("This Python slot requires %MethodCode"); + + if (sm->nrargs >= 0) + { + if (mt_scope == NULL && c_scope == NULL) + { + /* Global operators need one extra argument. */ + if (sm -> nrargs + 1 != nrargs) + yyerror("Incorrect number of arguments to global operator"); + } + else if (sm->nrargs != nrargs) + yyerror("Incorrect number of arguments to Python slot"); + } + + st = sm->type; + + break; + } + + /* Check there is no name clash. */ + checkAttributes(pt, mod, c_scope, mt_scope, pname, TRUE); + + /* See if it already exists. */ + if (mt_scope != NULL) + flist = &mt_scope->members; + else if (c_scope != NULL) + flist = &c_scope->members; + else + flist = &mod->othfuncs; + + for (md = *flist; md != NULL; md = md->next) + if (strcmp(md->pyname->text, pname) == 0 && md->module == mod) + break; + + if (md == NULL) + { + /* Create a new one. */ + md = sipMalloc(sizeof (memberDef)); + + md->pyname = cacheName(pt, pname); + md->memberflags = 0; + md->slot = st; + md->module = mod; + md->next = *flist; + + *flist = md; + + if (inMainModule()) + setIsUsedName(md->pyname); + + if (no_arg_parser) + setNoArgParser(md); + } + else if (noArgParser(md)) + yyerror("Another overload has already been defined that is annotated as /NoArgParser/"); + + /* Global operators are a subset. */ + if (mt_scope == NULL && c_scope == NULL && st != no_slot && st != neg_slot && st != pos_slot && !isNumberSlot(md) && !isRichCompareSlot(md)) + yyerror("Global operators must be either numeric or comparison operators"); + + return md; +} + + +/* + * Search a set of flags for a particular one and check its type. + */ +static optFlag *findOptFlag(optFlags *flgs,char *name,flagType ft) +{ + int f; + + for (f = 0; f < flgs -> nrFlags; ++f) + { + optFlag *of = &flgs -> flags[f]; + + if (strcmp(of -> fname,name) == 0) + { + /* + * An optional name can look like a boolean or a name. + */ + + if (ft == opt_name_flag) + { + if (of -> ftype == bool_flag) + { + of -> ftype = opt_name_flag; + of -> fvalue.sval = NULL; + } + else if (of -> ftype == name_flag) + of -> ftype = opt_name_flag; + } + + if (ft != of -> ftype) + yyerror("Optional flag has a value of the wrong type"); + + return of; + } + } + + return NULL; +} + + +/* + * A name is going to be used as a Python attribute name within a Python scope + * (ie. a Python dictionary), so check against what we already know is going in + * the same scope in case there is a clash. + */ +static void checkAttributes(sipSpec *pt, moduleDef *mod, classDef *py_c_scope, + mappedTypeDef *py_mt_scope, const char *attr, int isfunc) +{ + enumDef *ed; + varDef *vd; + classDef *cd; + + /* Check the enums. */ + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + enumMemberDef *emd; + + if (ed->pyname == NULL) + continue; + + if (py_c_scope != NULL) + { + if (ed->ecd != py_c_scope) + continue; + } + else if (py_mt_scope != NULL) + { + if (ed->emtd != py_mt_scope) + continue; + } + else if (ed->ecd != NULL || ed->emtd != NULL) + { + continue; + } + + if (strcmp(ed->pyname->text, attr) == 0) + yyerror("There is already an enum in scope with the same Python name"); + + for (emd = ed->members; emd != NULL; emd = emd->next) + if (strcmp(emd->pyname->text, attr) == 0) + yyerror("There is already an enum member in scope with the same Python name"); + } + + /* + * Only check the members if this attribute isn't a member because we + * can handle members with the same name in the same scope. + */ + if (!isfunc) + { + memberDef *md, *membs; + overDef *overs; + + if (py_mt_scope != NULL) + { + membs = py_mt_scope->members; + overs = py_mt_scope->overs; + } + else if (py_c_scope != NULL) + { + membs = py_c_scope->members; + overs = py_c_scope->overs; + } + else + { + membs = mod->othfuncs; + overs = mod->overs; + } + + for (md = membs; md != NULL; md = md->next) + { + overDef *od; + + if (strcmp(md->pyname->text, attr) != 0) + continue; + + /* Check for a conflict with all overloads. */ + for (od = overs; od != NULL; od = od->next) + { + if (od->common != md) + continue; + + yyerror("There is already a function in scope with the same Python name"); + } + } + } + + /* If the scope was a mapped type then that's all we have to check. */ + if (py_mt_scope != NULL) + return; + + /* Check the variables. */ + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + if (vd->ecd != py_c_scope) + continue; + + if (strcmp(vd->pyname->text,attr) == 0) + yyerror("There is already a variable in scope with the same Python name"); + } + + /* Check the classes. */ + for (cd = pt->classes; cd != NULL; cd = cd->next) + { + if (cd->ecd != py_c_scope || cd->pyname == NULL) + continue; + + if (strcmp(cd->pyname->text, attr) == 0 && !isExternal(cd)) + yyerror("There is already a class or namespace in scope with the same Python name"); + } + + /* Check the exceptions. */ + if (py_c_scope == NULL) + { + exceptionDef *xd; + + for (xd = pt->exceptions; xd != NULL; xd = xd->next) + if (xd->pyname != NULL && strcmp(xd->pyname, attr) == 0) + yyerror("There is already an exception with the same Python name"); + } +} + + +/* + * Append a code block to a list of them. Append is needed to give the + * specifier easy control over the order of the documentation. + */ +void appendCodeBlock(codeBlock **headp, codeBlock *new) +{ + while (*headp != NULL) + headp = &(*headp)->next; + + *headp = new; +} + + +/* + * Handle the end of a fully parsed a file. + */ +static void handleEOF() +{ + /* + * Check that the number of nested if's is the same as when we started + * the file. + */ + + if (skipStackPtr > currentContext.ifdepth) + fatal("Too many %%If statements in %s\n", previousFile); + + if (skipStackPtr < currentContext.ifdepth) + fatal("Too many %%End statements in %s\n", previousFile); +} + + +/* + * Handle the end of a fully parsed a module. + */ +static void handleEOM() +{ + moduleDef *from; + + /* Check it has been named. */ + if (currentModule->name == NULL) + fatal("No %%Module has been specified for module defined in %s\n", + previousFile); + + from = currentContext.prevmod; + + if (from != NULL && from->encoding == no_type) + from->encoding = currentModule->encoding; + + /* The previous module is now current. */ + currentModule = from; +} + + +/* + * Find an existing qualifier. + */ +static qualDef *findQualifier(const char *name) +{ + moduleDef *mod; + + for (mod = currentSpec->modules; mod != NULL; mod = mod->next) + { + qualDef *qd; + + for (qd = mod->qualifiers; qd != NULL; qd = qd->next) + if (strcmp(qd->name, name) == 0) + return qd; + } + + return NULL; +} + + +/* + * Find an existing API. + */ +apiVersionRangeDef *findAPI(sipSpec *pt, const char *name) +{ + moduleDef *mod; + + for (mod = pt->modules; mod != NULL; mod = mod->next) + { + apiVersionRangeDef *avd; + + for (avd = mod->api_versions; avd != NULL; avd = avd->next) + if (strcmp(avd->api_name->text, name) == 0) + return avd; + } + + return NULL; +} + + +/* + * Return a copy of a scoped name. + */ +scopedNameDef *copyScopedName(scopedNameDef *snd) +{ + scopedNameDef *head; + + head = NULL; + + while (snd != NULL) + { + appendScopedName(&head,text2scopePart(snd -> name)); + snd = snd -> next; + } + + return head; +} + + +/* + * Append a name to a list of scopes. + */ +void appendScopedName(scopedNameDef **headp,scopedNameDef *newsnd) +{ + while (*headp != NULL) + headp = &(*headp) -> next; + + *headp = newsnd; +} + + +/* + * Free a scoped name - but not the text itself. + */ +void freeScopedName(scopedNameDef *snd) +{ + while (snd != NULL) + { + scopedNameDef *next = snd -> next; + + free(snd); + + snd = next; + } +} + + +/* + * Convert a text string to a scope part structure. + */ +static scopedNameDef *text2scopePart(char *text) +{ + scopedNameDef *snd; + + snd = sipMalloc(sizeof (scopedNameDef)); + + snd->name = text; + snd->next = NULL; + + return snd; +} + + +/* + * Convert a text string to a fully scoped name. + */ +static scopedNameDef *text2scopedName(ifaceFileDef *scope, char *text) +{ + return scopeScopedName(scope, text2scopePart(text)); +} + + +/* + * Prepend any current scope to a scoped name. + */ +static scopedNameDef *scopeScopedName(ifaceFileDef *scope, scopedNameDef *name) +{ + scopedNameDef *snd; + + snd = (scope != NULL ? copyScopedName(scope->fqcname) : NULL); + + appendScopedName(&snd, name); + + return snd; +} + + +/* + * Return a pointer to the tail part of a scoped name. + */ +char *scopedNameTail(scopedNameDef *snd) +{ + if (snd == NULL) + return NULL; + + while (snd -> next != NULL) + snd = snd -> next; + + return snd -> name; +} + + +/* + * Push the given scope onto the scope stack. + */ +static void pushScope(classDef *scope) +{ + if (currentScopeIdx >= MAX_NESTED_SCOPE) + fatal("Internal error: increase the value of MAX_NESTED_SCOPE\n"); + + scopeStack[currentScopeIdx] = scope; + sectFlagsStack[currentScopeIdx] = sectionFlags; + + ++currentScopeIdx; +} + + +/* + * Pop the scope stack. + */ +static void popScope(void) +{ + if (currentScopeIdx > 0) + sectionFlags = sectFlagsStack[--currentScopeIdx]; +} + + +/* + * Return non-zero if the current input should be parsed rather than be + * skipped. + */ +static int notSkipping() +{ + return (skipStackPtr == 0 ? TRUE : skipStack[skipStackPtr - 1]); +} + + +/* + * Return the value of an expression involving a time period. + */ +static int timePeriod(char *lname,char *uname) +{ + int this, line; + qualDef *qd, *lower, *upper; + moduleDef *mod; + + if (lname == NULL) + lower = NULL; + else if ((lower = findQualifier(lname)) == NULL || lower -> qtype != time_qualifier) + yyerror("Lower bound is not a time version"); + + if (uname == NULL) + upper = NULL; + else if ((upper = findQualifier(uname)) == NULL || upper -> qtype != time_qualifier) + yyerror("Upper bound is not a time version"); + + /* Sanity checks on the bounds. */ + + if (lower == NULL && upper == NULL) + yyerror("Lower and upper bounds cannot both be omitted"); + + if (lower != NULL && upper != NULL) + { + if (lower -> module != upper -> module || lower -> line != upper -> line) + yyerror("Lower and upper bounds are from different timelines"); + + if (lower == upper) + yyerror("Lower and upper bounds must be different"); + + if (lower -> order > upper -> order) + yyerror("Later version specified as lower bound"); + } + + /* Go through each slot in the relevant timeline. */ + + if (lower != NULL) + { + mod = lower -> module; + line = lower -> line; + } + else + { + mod = upper -> module; + line = upper -> line; + } + + this = FALSE; + + for (qd = mod -> qualifiers; qd != NULL; qd = qd -> next) + { + if (qd -> qtype != time_qualifier || qd -> line != line) + continue; + + if (lower != NULL && qd -> order < lower -> order) + continue; + + if (upper != NULL && qd -> order >= upper -> order) + continue; + + /* + * This is within the required range so if it is also needed + * then the expression is true. + */ + + if (isNeeded(qd)) + { + this = TRUE; + break; + } + } + + return this; +} + + +/* + * Return the value of an expression involving a single platform or feature. + */ +static int platOrFeature(char *name,int optnot) +{ + int this; + qualDef *qd; + + if ((qd = findQualifier(name)) == NULL || qd -> qtype == time_qualifier) + yyerror("No such platform or feature"); + + /* Assume this sub-expression is false. */ + + this = FALSE; + + if (qd -> qtype == feature_qualifier) + { + if (!excludedFeature(excludedQualifiers,qd)) + this = TRUE; + } + else if (isNeeded(qd)) + this = TRUE; + + if (optnot) + this = !this; + + return this; +} + + +/* + * Return TRUE if the given qualifier is excluded. + */ +int excludedFeature(stringList *xsl,qualDef *qd) +{ + while (xsl != NULL) + { + if (strcmp(qd -> name,xsl -> s) == 0) + return TRUE; + + xsl = xsl -> next; + } + + return FALSE; +} + + +/* + * Return TRUE if the given qualifier is needed. + */ +static int isNeeded(qualDef *qd) +{ + stringList *sl; + + for (sl = neededQualifiers; sl != NULL; sl = sl -> next) + if (strcmp(qd -> name,sl -> s) == 0) + return TRUE; + + return FALSE; +} + + +/* + * Return the current scope. currentScope() is only valid if notSkipping() + * returns non-zero. + */ +static classDef *currentScope(void) +{ + return (currentScopeIdx > 0 ? scopeStack[currentScopeIdx - 1] : NULL); +} + + +/* + * Create a new qualifier. + */ +static void newQualifier(moduleDef *mod, int line, int order, char *name, + qualType qt) +{ + qualDef *qd; + + /* Check it doesn't already exist. */ + + if (findQualifier(name) != NULL) + yyerror("Version is already defined"); + + qd = sipMalloc(sizeof (qualDef)); + qd->name = name; + qd->qtype = qt; + qd->module = mod; + qd->line = line; + qd->order = order; + qd->next = mod -> qualifiers; + mod->qualifiers = qd; +} + + +/* + * Create a new imported module. + */ +static void newImport(char *filename) +{ + moduleDef *from, *mod; + moduleListDef *mld; + + /* Create a new module if it has not already been defined. */ + for (mod = currentSpec->modules; mod != NULL; mod = mod->next) + if (strcmp(mod->file, filename) == 0) + break; + + from = currentModule; + + if (mod == NULL) + { + newModule(NULL, filename); + mod = currentModule; + } + else if (from->encoding == no_type) + { + /* Import any defaults from the already parsed module. */ + from->encoding = mod->encoding; + } + + /* Add the new import unless it has already been imported. */ + for (mld = from->imports; mld != NULL; mld = mld->next) + if (mld->module == mod) + return; + + mld = sipMalloc(sizeof (moduleListDef)); + mld->module = mod; + mld->next = from->imports; + + from->imports = mld; +} + + +/* + * Set up pointers to hook names. + */ +static void getHooks(optFlags *optflgs,char **pre,char **post) +{ + optFlag *of; + + if ((of = findOptFlag(optflgs,"PreHook",name_flag)) != NULL) + *pre = of -> fvalue.sval; + else + *pre = NULL; + + if ((of = findOptFlag(optflgs,"PostHook",name_flag)) != NULL) + *post = of -> fvalue.sval; + else + *post = NULL; +} + + +/* + * Get the /Transfer/ option flag. + */ +static int getTransfer(optFlags *optflgs) +{ + return (findOptFlag(optflgs, "Transfer", bool_flag) != NULL); +} + + +/* + * Get the /ReleaseGIL/ option flag. + */ +static int getReleaseGIL(optFlags *optflgs) +{ + return (findOptFlag(optflgs, "ReleaseGIL", bool_flag) != NULL); +} + + +/* + * Get the /HoldGIL/ option flag. + */ +static int getHoldGIL(optFlags *optflgs) +{ + return (findOptFlag(optflgs, "HoldGIL", bool_flag) != NULL); +} + + +/* + * Get the /Deprecated/ option flag. + */ +static int getDeprecated(optFlags *optflgs) +{ + return (findOptFlag(optflgs, "Deprecated", bool_flag) != NULL); +} + + +/* + * Get the /AllowNone/ option flag. + */ +static int getAllowNone(optFlags *optflgs) +{ + return (findOptFlag(optflgs, "AllowNone", bool_flag) != NULL); +} + + +/* + * Get the /DocType/ option flag. + */ +static const char *getDocType(optFlags *optflgs) +{ + optFlag *of = findOptFlag(optflgs, "DocType", string_flag); + + if (of == NULL) + return NULL; + + return of->fvalue.sval; +} + + +/* + * Get the /DocValue/ option flag. + */ +static const char *getDocValue(optFlags *optflgs) +{ + optFlag *of = findOptFlag(optflgs, "DocValue", string_flag); + + if (of == NULL) + return NULL; + + return of->fvalue.sval; +} + + +/* + * Return TRUE if the PyQt3 plugin was specified. + */ +int pluginPyQt3(sipSpec *pt) +{ + return stringFind(pt->plugins, "PyQt3"); +} + + +/* + * Return TRUE if the PyQt4 plugin was specified. + */ +int pluginPyQt4(sipSpec *pt) +{ + return stringFind(pt->plugins, "PyQt4"); +} + + +/* + * Return TRUE if a list of strings contains a given entry. + */ +static int stringFind(stringList *sl, const char *s) +{ + while (sl != NULL) + { + if (strcmp(sl->s, s) == 0) + return TRUE; + + sl = sl->next; + } + + return FALSE; +} + + +/* + * Set the name of a module. + */ +static void setModuleName(sipSpec *pt, moduleDef *mod, const char *fullname) +{ + mod->fullname = cacheName(pt, fullname); + + if (inMainModule()) + setIsUsedName(mod->fullname); + + if ((mod->name = strrchr(fullname, '.')) != NULL) + mod->name++; + else + mod->name = fullname; +} + + +/* + * Define a new class and set its name. + */ +static void defineClass(scopedNameDef *snd, classList *supers, optFlags *of) +{ + classDef *cd, *c_scope = currentScope(); + + cd = newClass(currentSpec, class_iface, getAPIRange(of), + scopeScopedName((c_scope != NULL ? c_scope->iff : NULL), snd)); + cd->supers = supers; + + pushScope(cd); +} + + +/* + * Complete the definition of a class. + */ +static classDef *completeClass(scopedNameDef *snd, optFlags *of, int has_def) +{ + classDef *cd = currentScope(); + + /* See if the class was defined or just declared. */ + if (has_def) + { + if (snd->next != NULL) + yyerror("A scoped name cannot be given in a class/struct definition"); + + } + else if (cd->supers != NULL) + yyerror("Class/struct has super-classes but no definition"); + else + setIsOpaque(cd); + + finishClass(currentSpec, currentModule, cd, of); + popScope(); + + /* + * Check that external classes have only been declared at the global scope. + */ + if (isExternal(cd) && currentScope() != NULL) + yyerror("External classes/structs can only be declared in the global scope"); + + return cd; +} + + +/* + * Add a variable to the list so that the list remains sorted. + */ +static void addVariable(sipSpec *pt, varDef *vd) +{ + varDef **at = &pt->vars; + + while (*at != NULL) + { + if (strcmp(vd->pyname->text, (*at)->pyname->text) < 0) + break; + + at = &(*at)->next; + } + + vd->next = *at; + *at = vd; +} + + +/* + * Update a type according to optional flags. + */ +static void applyTypeFlags(moduleDef *mod, argDef *ad, optFlags *flags) +{ + ad->doctype = getDocType(flags); + + if (ad->atype == string_type && !isArray(ad) && !isReference(ad)) + { + optFlag *of; + + if ((of = findOptFlag(flags, "Encoding", string_flag)) == NULL) + { + if (mod->encoding != no_type) + ad->atype = mod->encoding; + else + ad->atype = string_type; + } + else if ((ad->atype = convertEncoding(of->fvalue.sval)) == no_type) + yyerror("The value of the /Encoding/ annotation must be one of \"ASCII\", \"Latin-1\", \"UTF-8\" or \"None\""); + } +} + + +/* + * Return the argument type for a string with the given encoding or no_type if + * the encoding was invalid. + */ +static argType convertEncoding(const char *encoding) +{ + if (strcmp(encoding, "ASCII") == 0) + return ascii_string_type; + + if (strcmp(encoding, "Latin-1") == 0) + return latin1_string_type; + + if (strcmp(encoding, "UTF-8") == 0) + return utf8_string_type; + + if (strcmp(encoding, "None") == 0) + return string_type; + + return no_type; +} + + +/* + * Get the /API/ option flag. + */ +static apiVersionRangeDef *getAPIRange(optFlags *optflgs) +{ + optFlag *of; + + if ((of = findOptFlag(optflgs, "API", api_range_flag)) == NULL) + return NULL; + + return of->fvalue.aval; +} + + +/* + * Return the API range structure and version number corresponding to the + * given API range. + */ +static apiVersionRangeDef *convertAPIRange(moduleDef *mod, nameDef *name, + int from, int to) +{ + int index; + apiVersionRangeDef *avd, **avdp; + + /* Handle the trivial case. */ + if (from == 0 && to == 0) + return NULL; + + for (index = 0, avdp = &mod->api_ranges; (*avdp) != NULL; avdp = &(*avdp)->next, ++index) + { + avd = *avdp; + + if (avd->api_name == name && avd->from == from && avd->to == to) + return avd; + } + + /* The new one must be appended so that version numbers remain valid. */ + avd = sipMalloc(sizeof (apiVersionRangeDef)); + + avd->api_name = name; + avd->from = from; + avd->to = to; + avd->index = index; + + avd->next = NULL; + *avdp = avd; + + return avd; +} + + +/* + * Return TRUE if a signature with annotations uses keyword arguments. + */ +static int usesKeywordArgs(optFlags *optflgs, signatureDef *sd) +{ + int kwd_args_anno, no_kwd_args_anno; + + kwd_args_anno = (findOptFlag(optflgs, "KeywordArgs", bool_flag) != NULL); + no_kwd_args_anno = (findOptFlag(optflgs, "NoKeywordArgs", bool_flag) != NULL); + + /* + * An ellipsis cannot be used with keyword arguments. Only complain if it + * has been explicitly requested. + */ + if (kwd_args_anno && sd->nrArgs > 0 && sd->args[sd->nrArgs - 1].atype == ellipsis_type) + yyerror("/KeywordArgs/ cannot be specified for calls with a variable number of arguments"); + + if ((defaultKwdArgs || kwd_args_anno) && !no_kwd_args_anno) + { + int a, is_name = FALSE; + + /* + * Mark argument names as being used and check there is at least one. + */ + for (a = 0; a < sd->nrArgs; ++a) + { + nameDef *nd = sd->args[a].name; + + if (sd->args[a].name != NULL) + { + setIsUsedName(nd); + is_name = TRUE; + } + } + + return is_name; + } + + return FALSE; +} + + +/* + * Extract the version of a string value optionally associated with a + * particular feature. + */ +static char *convertFeaturedString(char *fs) +{ + while (fs != NULL) + { + char *next, *value; + + /* Individual values are ';' separated. */ + if ((next = strchr(fs, ';')) != NULL) + *next++ = '\0'; + + /* Features and values are ':' separated. */ + if ((value = strchr(fs, ':')) == NULL) + { + /* This is an unconditional value so just return it. */ + return strip(fs); + } + + *value++ = '\0'; + + if (isEnabledFeature(strip(fs))) + return strip(value); + + fs = next; + } + + /* No value was enabled. */ + return NULL; +} + + +/* + * Return the stripped version of a string. + */ +static char *strip(char *s) +{ + while (*s == ' ') + ++s; + + if (*s != '\0') + { + char *cp = &s[strlen(s) - 1]; + + while (*cp == ' ') + *cp-- = '\0'; + } + + return s; +} + + +/* + * Return TRUE if the given feature is enabled. + */ +static int isEnabledFeature(const char *name) +{ + qualDef *qd; + + if ((qd = findQualifier(name)) == NULL || qd->qtype != feature_qualifier) + yyerror("No such feature"); + + return !excludedFeature(excludedQualifiers, qd); +} + diff --git a/sipgen/parser.h b/sipgen/parser.h new file mode 100644 index 0000000..1d3c05a --- /dev/null +++ b/sipgen/parser.h @@ -0,0 +1,309 @@ + +/* A Bison parser, made by GNU Bison 2.4.1. */ + +/* Skeleton interface for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + TK_API = 258, + TK_DEFENCODING = 259, + TK_PLUGIN = 260, + TK_DOCSTRING = 261, + TK_DOC = 262, + TK_EXPORTEDDOC = 263, + TK_MAKEFILE = 264, + TK_ACCESSCODE = 265, + TK_GETCODE = 266, + TK_SETCODE = 267, + TK_PREINITCODE = 268, + TK_INITCODE = 269, + TK_POSTINITCODE = 270, + TK_UNITCODE = 271, + TK_MODCODE = 272, + TK_TYPECODE = 273, + TK_PREPYCODE = 274, + TK_COPYING = 275, + TK_MAPPEDTYPE = 276, + TK_CODELINE = 277, + TK_IF = 278, + TK_END = 279, + TK_NAME = 280, + TK_PATHNAME = 281, + TK_STRING = 282, + TK_VIRTUALCATCHERCODE = 283, + TK_TRAVERSECODE = 284, + TK_CLEARCODE = 285, + TK_GETBUFFERCODE = 286, + TK_RELEASEBUFFERCODE = 287, + TK_READBUFFERCODE = 288, + TK_WRITEBUFFERCODE = 289, + TK_SEGCOUNTCODE = 290, + TK_CHARBUFFERCODE = 291, + TK_PICKLECODE = 292, + TK_METHODCODE = 293, + TK_FROMTYPE = 294, + TK_TOTYPE = 295, + TK_TOSUBCLASS = 296, + TK_INCLUDE = 297, + TK_OPTINCLUDE = 298, + TK_IMPORT = 299, + TK_EXPHEADERCODE = 300, + TK_MODHEADERCODE = 301, + TK_TYPEHEADERCODE = 302, + TK_MODULE = 303, + TK_CMODULE = 304, + TK_CONSMODULE = 305, + TK_COMPOMODULE = 306, + TK_CLASS = 307, + TK_STRUCT = 308, + TK_PUBLIC = 309, + TK_PROTECTED = 310, + TK_PRIVATE = 311, + TK_SIGNALS = 312, + TK_SIGNAL_METHOD = 313, + TK_SLOTS = 314, + TK_SLOT_METHOD = 315, + TK_BOOL = 316, + TK_SHORT = 317, + TK_INT = 318, + TK_LONG = 319, + TK_FLOAT = 320, + TK_DOUBLE = 321, + TK_CHAR = 322, + TK_WCHAR_T = 323, + TK_VOID = 324, + TK_PYOBJECT = 325, + TK_PYTUPLE = 326, + TK_PYLIST = 327, + TK_PYDICT = 328, + TK_PYCALLABLE = 329, + TK_PYSLICE = 330, + TK_PYTYPE = 331, + TK_VIRTUAL = 332, + TK_ENUM = 333, + TK_SIGNED = 334, + TK_UNSIGNED = 335, + TK_SCOPE = 336, + TK_LOGICAL_OR = 337, + TK_CONST = 338, + TK_STATIC = 339, + TK_SIPSIGNAL = 340, + TK_SIPSLOT = 341, + TK_SIPANYSLOT = 342, + TK_SIPRXCON = 343, + TK_SIPRXDIS = 344, + TK_SIPSLOTCON = 345, + TK_SIPSLOTDIS = 346, + TK_NUMBER = 347, + TK_REAL = 348, + TK_TYPEDEF = 349, + TK_NAMESPACE = 350, + TK_TIMELINE = 351, + TK_PLATFORMS = 352, + TK_FEATURE = 353, + TK_LICENSE = 354, + TK_QCHAR = 355, + TK_TRUE = 356, + TK_FALSE = 357, + TK_NULL = 358, + TK_OPERATOR = 359, + TK_THROW = 360, + TK_QOBJECT = 361, + TK_EXCEPTION = 362, + TK_RAISECODE = 363, + TK_EXPLICIT = 364, + TK_TEMPLATE = 365, + TK_ELLIPSIS = 366, + TK_DEFMETATYPE = 367, + TK_DEFSUPERTYPE = 368 + }; +#endif +/* Tokens. */ +#define TK_API 258 +#define TK_DEFENCODING 259 +#define TK_PLUGIN 260 +#define TK_DOCSTRING 261 +#define TK_DOC 262 +#define TK_EXPORTEDDOC 263 +#define TK_MAKEFILE 264 +#define TK_ACCESSCODE 265 +#define TK_GETCODE 266 +#define TK_SETCODE 267 +#define TK_PREINITCODE 268 +#define TK_INITCODE 269 +#define TK_POSTINITCODE 270 +#define TK_UNITCODE 271 +#define TK_MODCODE 272 +#define TK_TYPECODE 273 +#define TK_PREPYCODE 274 +#define TK_COPYING 275 +#define TK_MAPPEDTYPE 276 +#define TK_CODELINE 277 +#define TK_IF 278 +#define TK_END 279 +#define TK_NAME 280 +#define TK_PATHNAME 281 +#define TK_STRING 282 +#define TK_VIRTUALCATCHERCODE 283 +#define TK_TRAVERSECODE 284 +#define TK_CLEARCODE 285 +#define TK_GETBUFFERCODE 286 +#define TK_RELEASEBUFFERCODE 287 +#define TK_READBUFFERCODE 288 +#define TK_WRITEBUFFERCODE 289 +#define TK_SEGCOUNTCODE 290 +#define TK_CHARBUFFERCODE 291 +#define TK_PICKLECODE 292 +#define TK_METHODCODE 293 +#define TK_FROMTYPE 294 +#define TK_TOTYPE 295 +#define TK_TOSUBCLASS 296 +#define TK_INCLUDE 297 +#define TK_OPTINCLUDE 298 +#define TK_IMPORT 299 +#define TK_EXPHEADERCODE 300 +#define TK_MODHEADERCODE 301 +#define TK_TYPEHEADERCODE 302 +#define TK_MODULE 303 +#define TK_CMODULE 304 +#define TK_CONSMODULE 305 +#define TK_COMPOMODULE 306 +#define TK_CLASS 307 +#define TK_STRUCT 308 +#define TK_PUBLIC 309 +#define TK_PROTECTED 310 +#define TK_PRIVATE 311 +#define TK_SIGNALS 312 +#define TK_SIGNAL_METHOD 313 +#define TK_SLOTS 314 +#define TK_SLOT_METHOD 315 +#define TK_BOOL 316 +#define TK_SHORT 317 +#define TK_INT 318 +#define TK_LONG 319 +#define TK_FLOAT 320 +#define TK_DOUBLE 321 +#define TK_CHAR 322 +#define TK_WCHAR_T 323 +#define TK_VOID 324 +#define TK_PYOBJECT 325 +#define TK_PYTUPLE 326 +#define TK_PYLIST 327 +#define TK_PYDICT 328 +#define TK_PYCALLABLE 329 +#define TK_PYSLICE 330 +#define TK_PYTYPE 331 +#define TK_VIRTUAL 332 +#define TK_ENUM 333 +#define TK_SIGNED 334 +#define TK_UNSIGNED 335 +#define TK_SCOPE 336 +#define TK_LOGICAL_OR 337 +#define TK_CONST 338 +#define TK_STATIC 339 +#define TK_SIPSIGNAL 340 +#define TK_SIPSLOT 341 +#define TK_SIPANYSLOT 342 +#define TK_SIPRXCON 343 +#define TK_SIPRXDIS 344 +#define TK_SIPSLOTCON 345 +#define TK_SIPSLOTDIS 346 +#define TK_NUMBER 347 +#define TK_REAL 348 +#define TK_TYPEDEF 349 +#define TK_NAMESPACE 350 +#define TK_TIMELINE 351 +#define TK_PLATFORMS 352 +#define TK_FEATURE 353 +#define TK_LICENSE 354 +#define TK_QCHAR 355 +#define TK_TRUE 356 +#define TK_FALSE 357 +#define TK_NULL 358 +#define TK_OPERATOR 359 +#define TK_THROW 360 +#define TK_QOBJECT 361 +#define TK_EXCEPTION 362 +#define TK_RAISECODE 363 +#define TK_EXPLICIT 364 +#define TK_TEMPLATE 365 +#define TK_ELLIPSIS 366 +#define TK_DEFMETATYPE 367 +#define TK_DEFSUPERTYPE 368 + + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ + +/* Line 1676 of yacc.c */ +#line 147 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.y" + + char qchar; + char *text; + long number; + double real; + argDef memArg; + signatureDef signature; + signatureDef *optsignature; + throwArgs *throwlist; + codeBlock *codeb; + valueDef value; + valueDef *valp; + optFlags optflags; + optFlag flag; + scopedNameDef *scpvalp; + fcallDef fcall; + int boolean; + exceptionDef exceptionbase; + classDef *klass; + + + +/* Line 1676 of yacc.c */ +#line 301 "/home/phil/hg/sip/sip-4.10.5/sipgen/parser.h" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +extern YYSTYPE yylval; + + diff --git a/sipgen/parser.y b/sipgen/parser.y new file mode 100644 index 0000000..4000e7d --- /dev/null +++ b/sipgen/parser.y @@ -0,0 +1,6385 @@ +/* + * The SIP parser. + * + * Copyright (c) 2010 Riverbank Computing Limited <info@riverbankcomputing.com> + * + * This file is part of SIP. + * + * This copy of SIP is licensed for use under the terms of the SIP License + * Agreement. See the file LICENSE for more details. + * + * This copy of SIP may also used under the terms of the GNU General Public + * License v2 or v3 as published by the Free Software Foundation which can be + * found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package. + * + * SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + +%{ +#include <stdlib.h> +#include <string.h> +#include <ctype.h> + +#include "sip.h" + + +#define MAX_NESTED_IF 10 +#define MAX_NESTED_SCOPE 10 + +#define inMainModule() (currentSpec->module == currentModule || currentModule->container != NULL) + + +static sipSpec *currentSpec; /* The current spec being parsed. */ +static stringList *neededQualifiers; /* The list of required qualifiers. */ +static stringList *excludedQualifiers; /* The list of excluded qualifiers. */ +static moduleDef *currentModule; /* The current module being parsed. */ +static mappedTypeDef *currentMappedType; /* The current mapped type. */ +static enumDef *currentEnum; /* The current enum being parsed. */ +static int sectionFlags; /* The current section flags. */ +static int currentOverIsVirt; /* Set if the overload is virtual. */ +static int currentCtorIsExplicit; /* Set if the ctor is explicit. */ +static int currentIsStatic; /* Set if the current is static. */ +static int currentIsSignal; /* Set if the current is Q_SIGNAL. */ +static int currentIsSlot; /* Set if the current is Q_SLOT. */ +static int currentIsTemplate; /* Set if the current is a template. */ +static char *previousFile; /* The file just parsed. */ +static parserContext currentContext; /* The current context. */ +static int skipStackPtr; /* The skip stack pointer. */ +static int skipStack[MAX_NESTED_IF]; /* Stack of skip flags. */ +static classDef *scopeStack[MAX_NESTED_SCOPE]; /* The scope stack. */ +static int sectFlagsStack[MAX_NESTED_SCOPE]; /* The section flags stack. */ +static int currentScopeIdx; /* The scope stack index. */ +static int currentTimelineOrder; /* The current timeline order. */ +static classList *currentSupers; /* The current super-class list. */ +static int defaultKwdArgs; /* Support keyword arguments by default. */ +static int makeProtPublic; /* Treat protected items as public. */ + + +static const char *getPythonName(optFlags *optflgs, const char *cname); +static classDef *findClass(sipSpec *pt, ifaceFileType iftype, + apiVersionRangeDef *api_range, scopedNameDef *fqname); +static classDef *findClassWithInterface(sipSpec *pt, ifaceFileDef *iff); +static classDef *newClass(sipSpec *pt, ifaceFileType iftype, + apiVersionRangeDef *api_range, scopedNameDef *snd); +static void finishClass(sipSpec *, moduleDef *, classDef *, optFlags *); +static exceptionDef *findException(sipSpec *pt, scopedNameDef *fqname, int new); +static mappedTypeDef *newMappedType(sipSpec *,argDef *, optFlags *); +static enumDef *newEnum(sipSpec *pt, moduleDef *mod, mappedTypeDef *mt_scope, + char *name, optFlags *of, int flags); +static void instantiateClassTemplate(sipSpec *pt, moduleDef *mod, classDef *scope, scopedNameDef *fqname, classTmplDef *tcd, templateDef *td); +static void newTypedef(sipSpec *, moduleDef *, char *, argDef *, optFlags *); +static void newVar(sipSpec *, moduleDef *, char *, int, argDef *, optFlags *, + codeBlock *, codeBlock *, codeBlock *); +static void newCtor(char *, int, signatureDef *, optFlags *, codeBlock *, + throwArgs *, signatureDef *, int, codeBlock *); +static void newFunction(sipSpec *, moduleDef *, classDef *, mappedTypeDef *, + int, int, int, int, int, char *, signatureDef *, int, int, optFlags *, + codeBlock *, codeBlock *, throwArgs *, signatureDef *, codeBlock *); +static optFlag *findOptFlag(optFlags *,char *,flagType); +static memberDef *findFunction(sipSpec *, moduleDef *, classDef *, + mappedTypeDef *, const char *, int, int, int); +static void checkAttributes(sipSpec *, moduleDef *, classDef *, + mappedTypeDef *, const char *, int); +static void newModule(FILE *fp, char *filename); +static moduleDef *allocModule(); +static void parseFile(FILE *fp, char *name, moduleDef *prevmod, int optional); +static void handleEOF(void); +static void handleEOM(void); +static qualDef *findQualifier(const char *name); +static scopedNameDef *text2scopedName(ifaceFileDef *scope, char *text); +static scopedNameDef *scopeScopedName(ifaceFileDef *scope, + scopedNameDef *name); +static void pushScope(classDef *); +static void popScope(void); +static classDef *currentScope(void); +static void newQualifier(moduleDef *,int,int,char *,qualType); +static void newImport(char *filename); +static int timePeriod(char *,char *); +static int platOrFeature(char *,int); +static int isNeeded(qualDef *); +static int notSkipping(void); +static void getHooks(optFlags *,char **,char **); +static int getTransfer(optFlags *optflgs); +static int getReleaseGIL(optFlags *optflgs); +static int getHoldGIL(optFlags *optflgs); +static int getDeprecated(optFlags *optflgs); +static int getAllowNone(optFlags *optflgs); +static const char *getDocType(optFlags *optflgs); +static const char *getDocValue(optFlags *optflgs); +static void templateSignature(signatureDef *sd, int result, classTmplDef *tcd, templateDef *td, classDef *ncd); +static void templateType(argDef *ad, classTmplDef *tcd, templateDef *td, classDef *ncd); +static int search_back(const char *end, const char *start, const char *target); +static char *type2string(argDef *ad); +static char *scopedNameToString(scopedNameDef *name); +static void addUsedFromCode(sipSpec *pt, ifaceFileList **used, const char *sname); +static int sameName(scopedNameDef *snd, const char *sname); +static int stringFind(stringList *sl, const char *s); +static void setModuleName(sipSpec *pt, moduleDef *mod, const char *fullname); +static int foundInScope(scopedNameDef *fq_name, scopedNameDef *rel_name); +static void defineClass(scopedNameDef *snd, classList *supers, optFlags *of); +static classDef *completeClass(scopedNameDef *snd, optFlags *of, int has_def); +static memberDef *instantiateTemplateMethods(memberDef *tmd, moduleDef *mod); +static void instantiateTemplateEnums(sipSpec *pt, classTmplDef *tcd, + templateDef *td, classDef *cd, ifaceFileList **used, + scopedNameDef *type_names, scopedNameDef *type_values); +static void instantiateTemplateVars(sipSpec *pt, classTmplDef *tcd, + templateDef *td, classDef *cd, ifaceFileList **used, + scopedNameDef *type_names, scopedNameDef *type_values); +static overDef *instantiateTemplateOverloads(sipSpec *pt, overDef *tod, + memberDef *tmethods, memberDef *methods, classTmplDef *tcd, + templateDef *td, classDef *cd, ifaceFileList **used, + scopedNameDef *type_names, scopedNameDef *type_values); +static void resolveAnyTypedef(sipSpec *pt, argDef *ad); +static void addVariable(sipSpec *pt, varDef *vd); +static void applyTypeFlags(moduleDef *mod, argDef *ad, optFlags *flags); +static argType convertEncoding(const char *encoding); +static apiVersionRangeDef *getAPIRange(optFlags *optflgs); +static apiVersionRangeDef *convertAPIRange(moduleDef *mod, nameDef *name, + int from, int to); +static char *convertFeaturedString(char *fs); +static scopedNameDef *text2scopePart(char *text); +static int usesKeywordArgs(optFlags *optflgs, signatureDef *sd); +static char *strip(char *s); +static int isEnabledFeature(const char *name); +%} + +%union { + char qchar; + char *text; + long number; + double real; + argDef memArg; + signatureDef signature; + signatureDef *optsignature; + throwArgs *throwlist; + codeBlock *codeb; + valueDef value; + valueDef *valp; + optFlags optflags; + optFlag flag; + scopedNameDef *scpvalp; + fcallDef fcall; + int boolean; + exceptionDef exceptionbase; + classDef *klass; +} + +%token TK_API +%token TK_DEFENCODING +%token TK_PLUGIN +%token TK_DOCSTRING +%token TK_DOC +%token TK_EXPORTEDDOC +%token TK_MAKEFILE +%token TK_ACCESSCODE +%token TK_GETCODE +%token TK_SETCODE +%token TK_PREINITCODE +%token TK_INITCODE +%token TK_POSTINITCODE +%token TK_UNITCODE +%token TK_MODCODE +%token TK_TYPECODE +%token TK_PREPYCODE +%token TK_COPYING +%token TK_MAPPEDTYPE +%token <codeb> TK_CODELINE +%token TK_IF +%token TK_END +%token <text> TK_NAME +%token <text> TK_PATHNAME +%token <text> TK_STRING +%token TK_VIRTUALCATCHERCODE +%token TK_TRAVERSECODE +%token TK_CLEARCODE +%token TK_GETBUFFERCODE +%token TK_RELEASEBUFFERCODE +%token TK_READBUFFERCODE +%token TK_WRITEBUFFERCODE +%token TK_SEGCOUNTCODE +%token TK_CHARBUFFERCODE +%token TK_PICKLECODE +%token TK_METHODCODE +%token TK_FROMTYPE +%token TK_TOTYPE +%token TK_TOSUBCLASS +%token TK_INCLUDE +%token TK_OPTINCLUDE +%token TK_IMPORT +%token TK_EXPHEADERCODE +%token TK_MODHEADERCODE +%token TK_TYPEHEADERCODE +%token TK_MODULE +%token TK_CMODULE +%token TK_CONSMODULE +%token TK_COMPOMODULE +%token TK_CLASS +%token TK_STRUCT +%token TK_PUBLIC +%token TK_PROTECTED +%token TK_PRIVATE +%token TK_SIGNALS +%token TK_SIGNAL_METHOD +%token TK_SLOTS +%token TK_SLOT_METHOD +%token TK_BOOL +%token TK_SHORT +%token TK_INT +%token TK_LONG +%token TK_FLOAT +%token TK_DOUBLE +%token TK_CHAR +%token TK_WCHAR_T +%token TK_VOID +%token TK_PYOBJECT +%token TK_PYTUPLE +%token TK_PYLIST +%token TK_PYDICT +%token TK_PYCALLABLE +%token TK_PYSLICE +%token TK_PYTYPE +%token TK_VIRTUAL +%token TK_ENUM +%token TK_SIGNED +%token TK_UNSIGNED +%token TK_SCOPE +%token TK_LOGICAL_OR +%token TK_CONST +%token TK_STATIC +%token TK_SIPSIGNAL +%token TK_SIPSLOT +%token TK_SIPANYSLOT +%token TK_SIPRXCON +%token TK_SIPRXDIS +%token TK_SIPSLOTCON +%token TK_SIPSLOTDIS +%token <number> TK_NUMBER +%token <real> TK_REAL +%token TK_TYPEDEF +%token TK_NAMESPACE +%token TK_TIMELINE +%token TK_PLATFORMS +%token TK_FEATURE +%token TK_LICENSE +%token <qchar> TK_QCHAR +%token TK_TRUE +%token TK_FALSE +%token TK_NULL +%token TK_OPERATOR +%token TK_THROW +%token TK_QOBJECT +%token TK_EXCEPTION +%token TK_RAISECODE +%token TK_EXPLICIT +%token TK_TEMPLATE +%token TK_ELLIPSIS +%token TK_DEFMETATYPE +%token TK_DEFSUPERTYPE + +%type <memArg> argvalue +%type <memArg> argtype +%type <memArg> cpptype +%type <memArg> basetype +%type <signature> template +%type <signature> arglist +%type <signature> rawarglist +%type <signature> cpptypelist +%type <optsignature> optsig +%type <optsignature> optctorsig +%type <throwlist> optexceptions +%type <throwlist> exceptionlist +%type <number> optslot +%type <number> optref +%type <number> optconst +%type <number> optvirtual +%type <number> optabstract +%type <number> deref +%type <number> optnumber +%type <value> simplevalue +%type <valp> value +%type <valp> expr +%type <valp> optassign +%type <codeb> optaccesscode +%type <codeb> optgetcode +%type <codeb> optsetcode +%type <codeb> exphdrcode +%type <codeb> modhdrcode +%type <codeb> typehdrcode +%type <codeb> opttypehdrcode +%type <codeb> travcode +%type <codeb> clearcode +%type <codeb> getbufcode +%type <codeb> releasebufcode +%type <codeb> readbufcode +%type <codeb> writebufcode +%type <codeb> segcountcode +%type <codeb> charbufcode +%type <codeb> picklecode +%type <codeb> modcode +%type <codeb> typecode +%type <codeb> codeblock +%type <codeb> codelines +%type <codeb> virtualcatchercode +%type <codeb> methodcode +%type <codeb> raisecode +%type <codeb> docstring +%type <codeb> optdocstring +%type <text> operatorname +%type <text> optfilename +%type <text> optname +%type <text> dottedname +%type <optflags> optflags +%type <optflags> flaglist +%type <flag> flag +%type <flag> flagvalue +%type <qchar> optunop +%type <qchar> binop +%type <scpvalp> scopepart +%type <scpvalp> scopedname +%type <fcall> exprlist +%type <boolean> qualifiers +%type <boolean> oredqualifiers +%type <boolean> modlang +%type <boolean> optclassbody +%type <exceptionbase> baseexception +%type <klass> class + +%% + +specification: statement + | specification statement + ; + +statement: { + /* + * We don't do these in parserEOF() because the parser is reading + * ahead and that would be too early. + */ + + if (previousFile != NULL) + { + handleEOF(); + + if (currentContext.prevmod != NULL) + handleEOM(); + + free(previousFile); + previousFile = NULL; + } + } modstatement + ; + +modstatement: module + | consmodule + | compmodule + | plugin + | copying + | include + | optinclude + | import + | api + | timeline + | platforms + | feature + | license + | defencoding + | defmetatype + | defsupertype + | exphdrcode { + if (notSkipping()) + appendCodeBlock(¤tSpec->exphdrcode, $1); + } + | modhdrcode { + if (notSkipping()) + appendCodeBlock(¤tModule->hdrcode, $1); + } + | modcode { + if (notSkipping()) + appendCodeBlock(¤tModule->cppcode, $1); + } + | preinitcode + | initcode + | postinitcode + | unitcode + | prepycode + | doc + | exporteddoc + | makefile + | mappedtype + | mappedtypetmpl + | nsstatement + ; + +nsstatement: ifstart + | ifend + | namespace + | struct + | class + | classtmpl + | exception + | typedef + | enum + | function + | variable + | typehdrcode { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope == NULL) + yyerror("%TypeHeaderCode can only be used in a namespace, class or mapped type"); + + appendCodeBlock(&scope->iff->hdrcode, $1); + } + } + ; + +defencoding: TK_DEFENCODING TK_STRING { + if (notSkipping()) + { + if ((currentModule->encoding = convertEncoding($2)) == no_type) + yyerror("The value of %DefaultEncoding must be one of \"ASCII\", \"Latin-1\", \"UTF-8\" or \"None\""); + } + } + ; + +plugin: TK_PLUGIN TK_NAME { + appendString(¤tSpec->plugins, $2); + } + ; + +api: TK_API TK_NAME TK_NUMBER { + if (notSkipping()) + { + apiVersionRangeDef *avd; + + if (findAPI(currentSpec, $2) != NULL) + yyerror("The API name in the %API directive has already been defined"); + + if ($3 < 1) + yyerror("The version number in the %API directive must be greater than or equal to 1"); + + avd = sipMalloc(sizeof (apiVersionRangeDef)); + + avd->api_name = cacheName(currentSpec, $2); + avd->from = $3; + avd->to = -1; + + avd->next = currentModule->api_versions; + currentModule->api_versions = avd; + + if (inMainModule()) + setIsUsedName(avd->api_name); + } + } + ; + +exception: TK_EXCEPTION scopedname baseexception optflags '{' opttypehdrcode raisecode '}' ';' { + if (notSkipping()) + { + exceptionDef *xd; + const char *pyname; + + if (currentSpec->genc) + yyerror("%Exception not allowed in a C module"); + + pyname = getPythonName(&$4, scopedNameTail($2)); + + checkAttributes(currentSpec, currentModule, NULL, NULL, + pyname, FALSE); + + xd = findException(currentSpec, $2, TRUE); + + if (xd->cd != NULL) + yyerror("%Exception name has already been seen as a class name - it must be defined before being used"); + + if (xd->iff->module != NULL) + yyerror("The %Exception has already been defined"); + + /* Complete the definition. */ + xd->iff->module = currentModule; + xd->iff->hdrcode = $6; + xd->pyname = pyname; + xd->bibase = $3.bibase; + xd->base = $3.base; + xd->raisecode = $7; + + if (findOptFlag(&$4, "Default", bool_flag) != NULL) + currentModule->defexception = xd; + + if (xd->bibase != NULL || xd->base != NULL) + xd->exceptionnr = currentModule->nrexceptions++; + } + } + ; + +baseexception: { + $$.bibase = NULL; + $$.base = NULL; + } + | '(' scopedname ')' { + exceptionDef *xd; + + $$.bibase = NULL; + $$.base = NULL; + + /* See if it is a defined exception. */ + for (xd = currentSpec->exceptions; xd != NULL; xd = xd->next) + if (compareScopedNames(xd->iff->fqcname, $2) == 0) + { + $$.base = xd; + break; + } + + if (xd == NULL && $2->next == NULL && strncmp($2->name, "SIP_", 4) == 0) + { + /* See if it is a builtin exception. */ + + static char *builtins[] = { + "Exception", + "StopIteration", + "StandardError", + "ArithmeticError", + "LookupError", + "AssertionError", + "AttributeError", + "EOFError", + "FloatingPointError", + "EnvironmentError", + "IOError", + "OSError", + "ImportError", + "IndexError", + "KeyError", + "KeyboardInterrupt", + "MemoryError", + "NameError", + "OverflowError", + "RuntimeError", + "NotImplementedError", + "SyntaxError", + "IndentationError", + "TabError", + "ReferenceError", + "SystemError", + "SystemExit", + "TypeError", + "UnboundLocalError", + "UnicodeError", + "UnicodeEncodeError", + "UnicodeDecodeError", + "UnicodeTranslateError", + "ValueError", + "ZeroDivisionError", + "WindowsError", + "VMSError", + NULL + }; + + char **cp; + + for (cp = builtins; *cp != NULL; ++cp) + if (strcmp($2->name + 4, *cp) == 0) + { + $$.bibase = *cp; + break; + } + } + + if ($$.bibase == NULL && $$.base == NULL) + yyerror("Unknown exception base type"); + } + ; + +raisecode: TK_RAISECODE codeblock { + $$ = $2; + } + ; + +mappedtype: TK_MAPPEDTYPE basetype optflags { + if (notSkipping()) + currentMappedType = newMappedType(currentSpec, &$2, &$3); + } mtdefinition + ; + +mappedtypetmpl: template TK_MAPPEDTYPE basetype optflags { + int a; + + if (currentSpec->genc) + yyerror("%MappedType templates not allowed in a C module"); + + /* Check the template arguments are basic types or simple names. */ + for (a = 0; a < $1.nrArgs; ++a) + { + argDef *ad = &$1.args[a]; + + if (ad->atype == defined_type && ad->u.snd->next != NULL) + yyerror("%MappedType template arguments must be simple names"); + } + + if ($3.atype != template_type) + yyerror("%MappedType template must map a template type"); + + if (notSkipping()) + { + mappedTypeTmplDef *mtt; + ifaceFileDef *iff; + + /* Check a template hasn't already been provided. */ + for (mtt = currentSpec->mappedtypetemplates; mtt != NULL; mtt = mtt->next) + if (compareScopedNames(mtt->mt->type.u.td->fqname, $3.u.td->fqname) == 0 && sameTemplateSignature(&mtt->mt->type.u.td->types, &$3.u.td->types, TRUE)) + yyerror("%MappedType template for this type has already been defined"); + + $3.nrderefs = 0; + $3.argflags = 0; + + mtt = sipMalloc(sizeof (mappedTypeTmplDef)); + + mtt->sig = $1; + mtt->mt = allocMappedType(currentSpec, &$3); + mtt->mt->doctype = getDocType(&$4); + mtt->next = currentSpec->mappedtypetemplates; + + currentSpec->mappedtypetemplates = mtt; + + currentMappedType = mtt->mt; + + /* Create a dummy interface file. */ + iff = sipMalloc(sizeof (ifaceFileDef)); + iff->hdrcode = NULL; + mtt->mt->iff = iff; + } + } mtdefinition + ; + +mtdefinition: '{' mtbody '}' ';' { + if (notSkipping()) + { + if (currentMappedType->convfromcode == NULL) + yyerror("%MappedType must have a %ConvertFromTypeCode directive"); + + if (currentMappedType->convtocode == NULL) + yyerror("%MappedType must have a %ConvertToTypeCode directive"); + + currentMappedType = NULL; + } + } + ; + +mtbody: mtline + | mtbody mtline + ; + +mtline: typehdrcode { + if (notSkipping()) + appendCodeBlock(¤tMappedType->iff->hdrcode, $1); + } + | TK_FROMTYPE codeblock { + if (notSkipping()) + { + if (currentMappedType -> convfromcode != NULL) + yyerror("%MappedType has more than one %ConvertFromTypeCode directive"); + + currentMappedType -> convfromcode = $2; + } + } + | TK_TOTYPE codeblock { + if (notSkipping()) + { + if (currentMappedType -> convtocode != NULL) + yyerror("%MappedType has more than one %ConvertToTypeCode directive"); + + currentMappedType -> convtocode = $2; + } + } + | enum + | mtfunction + ; + +mtfunction: TK_STATIC cpptype TK_NAME '(' arglist ')' optconst optexceptions optflags optsig ';' optdocstring methodcode { + if (notSkipping()) + { + applyTypeFlags(currentModule, &$2, &$9); + + $5.result = $2; + + newFunction(currentSpec, currentModule, NULL, + currentMappedType, 0, TRUE, FALSE, FALSE, FALSE, $3, + &$5, $7, FALSE, &$9, $13, NULL, $8, $10, $12); + } + } + ; + +namespace: TK_NAMESPACE TK_NAME { + if (currentSpec -> genc) + yyerror("namespace definition not allowed in a C module"); + + if (notSkipping()) + { + classDef *ns, *c_scope; + ifaceFileDef *scope; + + if ((c_scope = currentScope()) != NULL) + scope = c_scope->iff; + else + scope = NULL; + + ns = newClass(currentSpec, namespace_iface, NULL, + text2scopedName(scope, $2)); + + pushScope(ns); + + sectionFlags = 0; + } + } '{' nsbody '}' ';' { + if (notSkipping()) + { + if (inMainModule()) + { + classDef *ns = currentScope(); + + setIsUsedName(ns->iff->name); + setIsUsedName(ns->pyname); + } + + popScope(); + } + } + ; + +nsbody: nsstatement + | nsbody nsstatement + ; + +platforms: TK_PLATFORMS { + qualDef *qd; + + for (qd = currentModule -> qualifiers; qd != NULL; qd = qd -> next) + if (qd -> qtype == platform_qualifier) + yyerror("%Platforms has already been defined for this module"); + } + '{' platformlist '}' { + qualDef *qd; + int nrneeded; + + /* + * Check that exactly one platform in the set was + * requested. + */ + + nrneeded = 0; + + for (qd = currentModule -> qualifiers; qd != NULL; qd = qd -> next) + if (qd -> qtype == platform_qualifier && isNeeded(qd)) + ++nrneeded; + + if (nrneeded > 1) + yyerror("No more than one of these %Platforms must be specified with the -t flag"); + } + ; + +platformlist: platform + | platformlist platform + ; + +platform: TK_NAME { + newQualifier(currentModule,-1,-1,$1,platform_qualifier); + } + ; + +feature: TK_FEATURE TK_NAME { + newQualifier(currentModule,-1,-1,$2,feature_qualifier); + } + ; + +timeline: TK_TIMELINE { + currentTimelineOrder = 0; + } + '{' qualifierlist '}' { + qualDef *qd; + int nrneeded; + + /* + * Check that exactly one time slot in the set was + * requested. + */ + + nrneeded = 0; + + for (qd = currentModule -> qualifiers; qd != NULL; qd = qd -> next) + if (qd -> qtype == time_qualifier && isNeeded(qd)) + ++nrneeded; + + if (nrneeded > 1) + yyerror("At most one of this %Timeline must be specified with the -t flag"); + + currentModule -> nrtimelines++; + } + ; + +qualifierlist: qualifiername + | qualifierlist qualifiername + ; + +qualifiername: TK_NAME { + newQualifier(currentModule,currentModule -> nrtimelines,currentTimelineOrder++,$1,time_qualifier); + } + ; + +ifstart: TK_IF '(' qualifiers ')' { + if (skipStackPtr >= MAX_NESTED_IF) + yyerror("Internal error: increase the value of MAX_NESTED_IF"); + + /* Nested %Ifs are implicit logical ands. */ + + if (skipStackPtr > 0) + $3 = ($3 && skipStack[skipStackPtr - 1]); + + skipStack[skipStackPtr++] = $3; + } + ; + +oredqualifiers: TK_NAME { + $$ = platOrFeature($1,FALSE); + } + | '!' TK_NAME { + $$ = platOrFeature($2,TRUE); + } + | oredqualifiers TK_LOGICAL_OR TK_NAME { + $$ = (platOrFeature($3,FALSE) || $1); + } + | oredqualifiers TK_LOGICAL_OR '!' TK_NAME { + $$ = (platOrFeature($4,TRUE) || $1); + } + ; + +qualifiers: oredqualifiers + | optname '-' optname { + $$ = timePeriod($1,$3); + } + ; + +ifend: TK_END { + if (skipStackPtr-- <= 0) + yyerror("Too many %End directives"); + } + ; + +license: TK_LICENSE optflags { + optFlag *of; + + if ($2.nrFlags == 0) + yyerror("%License details not specified"); + + if ((of = findOptFlag(&$2,"Type",string_flag)) == NULL) + yyerror("%License type not specified"); + + currentModule -> license = sipMalloc(sizeof (licenseDef)); + + currentModule -> license -> type = of -> fvalue.sval; + + currentModule -> license -> licensee = + ((of = findOptFlag(&$2,"Licensee",string_flag)) != NULL) + ? of -> fvalue.sval : NULL; + + currentModule -> license -> timestamp = + ((of = findOptFlag(&$2,"Timestamp",string_flag)) != NULL) + ? of -> fvalue.sval : NULL; + + currentModule -> license -> sig = + ((of = findOptFlag(&$2,"Signature",string_flag)) != NULL) + ? of -> fvalue.sval : NULL; + } + ; + +defmetatype:TK_DEFMETATYPE dottedname { + if (notSkipping()) + { + if (currentModule->defmetatype != NULL) + yyerror("%DefaultMetatype has already been defined for this module"); + + currentModule->defmetatype = cacheName(currentSpec, $2); + } + } + ; + +defsupertype: TK_DEFSUPERTYPE dottedname { + if (notSkipping()) + { + if (currentModule->defsupertype != NULL) + yyerror("%DefaultSupertype has already been defined for this module"); + + currentModule->defsupertype = cacheName(currentSpec, $2); + } + } + ; + +consmodule: TK_CONSMODULE dottedname { + /* Make sure this is the first mention of a module. */ + if (currentSpec->module != currentModule) + yyerror("A %ConsolidatedModule cannot be %Imported"); + + if (currentModule->fullname != NULL) + yyerror("%ConsolidatedModule must appear before any %Module or %CModule directive"); + + setModuleName(currentSpec, currentModule, $2); + setIsConsolidated(currentModule); + } + ; + +compmodule: TK_COMPOMODULE dottedname { + /* Make sure this is the first mention of a module. */ + if (currentSpec->module != currentModule) + yyerror("A %CompositeModule cannot be %Imported"); + + if (currentModule->fullname != NULL) + yyerror("%CompositeModule must appear before any %Module or %CModule directive"); + + setModuleName(currentSpec, currentModule, $2); + setIsComposite(currentModule); + } + ; + +module: modlang dottedname optnumber { + /* Check the module hasn't already been defined. */ + + moduleDef *mod; + + for (mod = currentSpec->modules; mod != NULL; mod = mod->next) + if (mod->fullname != NULL && strcmp(mod->fullname->text, $2) == 0) + yyerror("Module is already defined"); + + /* + * If we are in a container module then create a component module + * and make it current. + */ + if (isContainer(currentModule) || currentModule->container != NULL) + { + mod = allocModule(); + + mod->file = currentContext.filename; + mod->container = (isContainer(currentModule) ? currentModule : currentModule->container); + + currentModule = mod; + } + + setModuleName(currentSpec, currentModule, $2); + currentModule->version = $3; + + if (currentSpec->genc < 0) + currentSpec->genc = $1; + else if (currentSpec->genc != $1) + yyerror("Cannot mix C and C++ modules"); + } + ; + +modlang: TK_MODULE { + $$ = FALSE; + } + | TK_CMODULE { + $$ = TRUE; + } + ; + +dottedname: TK_NAME + | TK_PATHNAME { + /* + * The grammar design is a bit broken and this is the easiest way + * to allow periods in names. + */ + + char *cp; + + for (cp = $1; *cp != '\0'; ++cp) + if (*cp != '.' && *cp != '_' && !isalnum(*cp)) + yyerror("Invalid character in name"); + + $$ = $1; + } + ; + +optnumber: { + $$ = -1; + } + | TK_NUMBER + ; + +include: TK_INCLUDE TK_PATHNAME { + parseFile(NULL, $2, NULL, FALSE); + } + ; + +optinclude: TK_OPTINCLUDE TK_PATHNAME { + parseFile(NULL, $2, NULL, TRUE); + } + ; + +import: TK_IMPORT TK_PATHNAME { + newImport($2); + } + ; + +optaccesscode: { + $$ = NULL; + } + | TK_ACCESSCODE codeblock { + $$ = $2; + } + ; + +optgetcode: { + $$ = NULL; + } + | TK_GETCODE codeblock { + $$ = $2; + } + ; + +optsetcode: { + $$ = NULL; + } + | TK_SETCODE codeblock { + $$ = $2; + } + ; + +copying: TK_COPYING codeblock { + appendCodeBlock(¤tModule->copying, $2); + } + ; + +exphdrcode: TK_EXPHEADERCODE codeblock { + $$ = $2; + } + ; + +modhdrcode: TK_MODHEADERCODE codeblock { + $$ = $2; + } + ; + +typehdrcode: TK_TYPEHEADERCODE codeblock { + $$ = $2; + } + ; + +opttypehdrcode: { + $$ = NULL; + } + | typehdrcode + ; + +travcode: TK_TRAVERSECODE codeblock { + $$ = $2; + } + ; + +clearcode: TK_CLEARCODE codeblock { + $$ = $2; + } + ; + +getbufcode: TK_GETBUFFERCODE codeblock { + $$ = $2; + } + ; + +releasebufcode: TK_RELEASEBUFFERCODE codeblock { + $$ = $2; + } + ; + +readbufcode: TK_READBUFFERCODE codeblock { + $$ = $2; + } + ; + +writebufcode: TK_WRITEBUFFERCODE codeblock { + $$ = $2; + } + ; + +segcountcode: TK_SEGCOUNTCODE codeblock { + $$ = $2; + } + ; + +charbufcode: TK_CHARBUFFERCODE codeblock { + $$ = $2; + } + ; + +picklecode: TK_PICKLECODE codeblock { + $$ = $2; + } + ; + +modcode: TK_MODCODE codeblock { + $$ = $2; + } + ; + +typecode: TK_TYPECODE codeblock { + $$ = $2; + } + ; + +preinitcode: TK_PREINITCODE codeblock { + if (notSkipping()) + appendCodeBlock(¤tModule->preinitcode, $2); + } + ; + +initcode: TK_INITCODE codeblock { + if (notSkipping()) + appendCodeBlock(¤tModule->initcode, $2); + } + ; + +postinitcode: TK_POSTINITCODE codeblock { + if (notSkipping()) + appendCodeBlock(¤tModule->postinitcode, $2); + } + ; + +unitcode: TK_UNITCODE codeblock { + if (notSkipping()) + appendCodeBlock(¤tModule->unitcode, $2); + } + ; + +prepycode: TK_PREPYCODE codeblock { + /* + * This is a no-op and is retained for compatibility + * until the last use of it (by SIP v3) can be removed + * from PyQt. + */ + } + ; + +doc: TK_DOC codeblock { + if (inMainModule()) + appendCodeBlock(¤tSpec -> docs,$2); + } + ; + +exporteddoc: TK_EXPORTEDDOC codeblock { + appendCodeBlock(¤tSpec -> docs,$2); + } + ; + +makefile: TK_MAKEFILE TK_PATHNAME optfilename codeblock { + if (inMainModule()) + yywarning("%Makefile is ignored, please use the -b flag instead"); + } + ; + +codeblock: codelines TK_END + ; + +codelines: TK_CODELINE + | codelines TK_CODELINE { + $$ = $1; + + append(&$$->frag, $2->frag); + + free($2->frag); + free((char *)$2->filename); + free($2); + } + ; + +enum: TK_ENUM optname optflags { + if (notSkipping()) + { + if (sectionFlags != 0 && (sectionFlags & ~(SECT_IS_PUBLIC | SECT_IS_PROT)) != 0) + yyerror("Class enums must be in the public or protected sections"); + + currentEnum = newEnum(currentSpec, currentModule, + currentMappedType, $2, &$3, sectionFlags); + } + } '{' optenumbody '}' ';' + ; + +optfilename: { + $$ = NULL; + } + | TK_PATHNAME { + $$ = $1; + } + ; + +optname: { + $$ = NULL; + } + | TK_NAME { + $$ = $1; + } + ; + +optenumbody: + | enumbody + ; + +enumbody: enumline + | enumbody enumline + ; + +enumline: ifstart + | ifend + | TK_NAME optenumassign optflags optcomma { + if (notSkipping()) + { + enumMemberDef *emd, **tail; + + /* Note that we don't use the assigned value. */ + emd = sipMalloc(sizeof (enumMemberDef)); + + emd -> pyname = cacheName(currentSpec, getPythonName(&$3, $1)); + emd -> cname = $1; + emd -> ed = currentEnum; + emd -> next = NULL; + + checkAttributes(currentSpec, currentModule, emd->ed->ecd, + emd->ed->emtd, emd->pyname->text, FALSE); + + /* Append to preserve the order. */ + for (tail = ¤tEnum->members; *tail != NULL; tail = &(*tail)->next) + ; + + *tail = emd; + + if (inMainModule()) + setIsUsedName(emd -> pyname); + } + } + ; + +optcomma: + | ',' + ; + +optenumassign: + | '=' value + ; + +optassign: { + $$ = NULL; + } + | '=' expr { + $$ = $2; + } + ; + +expr: value + | expr binop value { + valueDef *vd; + + if ($1 -> vtype == string_value || $3 -> vtype == string_value) + yyerror("Invalid binary operator for string"); + + /* Find the last value in the existing expression. */ + + for (vd = $1; vd -> next != NULL; vd = vd -> next) + ; + + vd -> vbinop = $2; + vd -> next = $3; + + $$ = $1; + } + ; + +binop: '-' { + $$ = '-'; + } + | '+' { + $$ = '+'; + } + | '*' { + $$ = '*'; + } + | '/' { + $$ = '/'; + } + | '&' { + $$ = '&'; + } + | '|' { + $$ = '|'; + } + ; + +optunop: { + $$ = '\0'; + } + | '!' { + $$ = '!'; + } + | '~' { + $$ = '~'; + } + | '-' { + $$ = '-'; + } + | '+' { + $$ = '+'; + } + ; + +value: optunop simplevalue { + if ($1 != '\0' && $2.vtype == string_value) + yyerror("Invalid unary operator for string"); + + /* + * Convert the value to a simple expression on the + * heap. + */ + + $$ = sipMalloc(sizeof (valueDef)); + + *$$ = $2; + $$ -> vunop = $1; + $$ -> vbinop = '\0'; + $$ -> next = NULL; + } + ; + +scopedname: scopepart + | scopedname TK_SCOPE scopepart { + if (currentSpec -> genc) + yyerror("Scoped names are not allowed in a C module"); + + appendScopedName(&$1,$3); + } + ; + +scopepart: TK_NAME { + $$ = text2scopePart($1); + } + ; + +simplevalue: scopedname { + /* + * We let the C++ compiler decide if the value is a valid one - no + * point in building a full C++ parser here. + */ + + $$.vtype = scoped_value; + $$.u.vscp = $1; + } + | basetype '(' exprlist ')' { + fcallDef *fcd; + + fcd = sipMalloc(sizeof (fcallDef)); + *fcd = $3; + fcd -> type = $1; + + $$.vtype = fcall_value; + $$.u.fcd = fcd; + } + | TK_REAL { + $$.vtype = real_value; + $$.u.vreal = $1; + } + | TK_NUMBER { + $$.vtype = numeric_value; + $$.u.vnum = $1; + } + | TK_TRUE { + $$.vtype = numeric_value; + $$.u.vnum = 1; + } + | TK_FALSE { + $$.vtype = numeric_value; + $$.u.vnum = 0; + } + | TK_NULL { + $$.vtype = numeric_value; + $$.u.vnum = 0; + } + | TK_STRING { + $$.vtype = string_value; + $$.u.vstr = $1; + } + | TK_QCHAR { + $$.vtype = qchar_value; + $$.u.vqchar = $1; + } + ; + +exprlist: { + /* No values. */ + + $$.nrArgs = 0; + } + | expr { + /* The single or first expression. */ + + $$.args[0] = $1; + $$.nrArgs = 1; + } + | exprlist ',' expr { + /* Check that it wasn't ...(,expression...). */ + + if ($$.nrArgs == 0) + yyerror("First argument to function call is missing"); + + /* Check there is room. */ + + if ($1.nrArgs == MAX_NR_ARGS) + yyerror("Too many arguments to function call"); + + $$ = $1; + + $$.args[$$.nrArgs] = $3; + $$.nrArgs++; + } + ; + +typedef: TK_TYPEDEF cpptype TK_NAME optflags ';' { + if (notSkipping()) + { + applyTypeFlags(currentModule, &$2, &$4); + newTypedef(currentSpec, currentModule, $3, &$2, &$4); + } + } + | TK_TYPEDEF cpptype '(' deref TK_NAME ')' '(' cpptypelist ')' optflags ';' { + if (notSkipping()) + { + signatureDef *sig; + argDef ftype; + + applyTypeFlags(currentModule, &$2, &$10); + + memset(&ftype, 0, sizeof (argDef)); + + /* Create the full signature on the heap. */ + sig = sipMalloc(sizeof (signatureDef)); + *sig = $8; + sig->result = $2; + + /* Create the full type. */ + ftype.atype = function_type; + ftype.nrderefs = $4; + ftype.u.sa = sig; + + newTypedef(currentSpec, currentModule, $5, &ftype, &$10); + } + } + ; + +struct: TK_STRUCT scopedname { + if (currentSpec -> genc && $2->next != NULL) + yyerror("Namespaces not allowed in a C module"); + + if (notSkipping()) + currentSupers = NULL; + } superclasses optflags { + if (notSkipping()) + { + if (currentSpec->genc && currentSupers != NULL) + yyerror("Super-classes not allowed in a C module struct"); + + defineClass($2, currentSupers, &$5); + sectionFlags = SECT_IS_PUBLIC; + } + } optclassbody ';' { + if (notSkipping()) + completeClass($2, &$5, $7); + } + ; + +classtmpl: template {currentIsTemplate = TRUE;} class { + if (currentSpec->genc) + yyerror("Class templates not allowed in a C module"); + + if (notSkipping()) + { + classTmplDef *tcd; + + /* + * Make sure there is room for the extra class name argument. + */ + if ($1.nrArgs == MAX_NR_ARGS) + yyerror("Internal error - increase the value of MAX_NR_ARGS"); + + tcd = sipMalloc(sizeof (classTmplDef)); + tcd->sig = $1; + tcd->cd = $3; + tcd->next = currentSpec->classtemplates; + + currentSpec->classtemplates = tcd; + } + + currentIsTemplate = FALSE; + } + ; + +template: TK_TEMPLATE '<' cpptypelist '>' { + $$ = $3; + } + ; + +class: TK_CLASS scopedname { + if (currentSpec->genc) + yyerror("Class definition not allowed in a C module"); + + if (notSkipping()) + currentSupers = NULL; + } superclasses optflags { + if (notSkipping()) + { + defineClass($2, currentSupers, &$5); + sectionFlags = SECT_IS_PRIVATE; + } + } optclassbody ';' { + if (notSkipping()) + $$ = completeClass($2, &$5, $7); + } + ; + +superclasses: + | ':' superlist + ; + +superlist: superclass + | superlist ',' superclass + ; + +superclass: scopedname { + if (notSkipping()) + { + argDef ad; + classDef *super; + scopedNameDef *snd = $1; + + /* + * This is a hack to allow typedef'ed classes to be used before + * we have resolved the typedef definitions. Unlike elsewhere, + * we require that the typedef is defined before being used. + */ + for (;;) + { + ad.atype = no_type; + ad.argflags = 0; + ad.nrderefs = 0; + ad.original_type = NULL; + + searchTypedefs(currentSpec, snd, &ad); + + if (ad.atype != defined_type) + break; + + if (ad.nrderefs != 0 || isConstArg(&ad) || isReference(&ad)) + break; + + snd = ad.u.snd; + } + + if (ad.atype != no_type) + yyerror("Super-class list contains an invalid type"); + + super = findClass(currentSpec, class_iface, NULL, snd); + appendToClassList(¤tSupers, super); + } + } + ; + +optclassbody: { + $$ = FALSE; + } + | '{' classbody '}' { + $$ = TRUE; + } + ; + +classbody: classline + | classbody classline + ; + +classline: ifstart + | ifend + | namespace + | struct + | class + | exception + | typedef + | enum + | docstring { + if (notSkipping()) + { + classDef *scope = currentScope(); + + /* Make sure this is before any ctor docstrings. */ + $1->next = scope->docstring; + scope->docstring = $1; + } + } + | typecode { + if (notSkipping()) + appendCodeBlock(¤tScope()->cppcode, $1); + } + | typehdrcode { + if (notSkipping()) + appendCodeBlock(¤tScope()->iff->hdrcode, $1); + } + | travcode { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->travcode != NULL) + yyerror("%GCTraverseCode already given for class"); + + scope->travcode = $1; + } + } + | clearcode { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->clearcode != NULL) + yyerror("%GCClearCode already given for class"); + + scope->clearcode = $1; + } + } + | getbufcode { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->getbufcode != NULL) + yyerror("%BIGetBufferCode already given for class"); + + scope->getbufcode = $1; + } + } + | releasebufcode { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->releasebufcode != NULL) + yyerror("%BIReleaseBufferCode already given for class"); + + scope->releasebufcode = $1; + } + } + | readbufcode { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->readbufcode != NULL) + yyerror("%BIGetReadBufferCode already given for class"); + + scope->readbufcode = $1; + } + } + | writebufcode { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->writebufcode != NULL) + yyerror("%BIGetWriteBufferCode already given for class"); + + scope->writebufcode = $1; + } + } + | segcountcode { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->segcountcode != NULL) + yyerror("%BIGetSegCountCode already given for class"); + + scope->segcountcode = $1; + } + } + | charbufcode { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->charbufcode != NULL) + yyerror("%BIGetCharBufferCode already given for class"); + + scope->charbufcode = $1; + } + } + | picklecode { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->picklecode != NULL) + yyerror("%PickleCode already given for class"); + + scope->picklecode = $1; + } + } + | ctor + | dtor + | varmember + | TK_TOSUBCLASS codeblock { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->convtosubcode != NULL) + yyerror("Class has more than one %ConvertToSubClassCode directive"); + + scope->convtosubcode = $2; + } + } + | TK_TOTYPE codeblock { + if (notSkipping()) + { + classDef *scope = currentScope(); + + if (scope->convtocode != NULL) + yyerror("Class has more than one %ConvertToTypeCode directive"); + + scope->convtocode = $2; + } + } + | TK_PUBLIC optslot ':' { + if (currentSpec -> genc) + yyerror("public section not allowed in a C module"); + + if (notSkipping()) + sectionFlags = SECT_IS_PUBLIC | $2; + } + | TK_PROTECTED optslot ':' { + if (currentSpec -> genc) + yyerror("protected section not allowed in a C module"); + + if (notSkipping()) + sectionFlags = SECT_IS_PROT | $2; + } + | TK_PRIVATE optslot ':' { + if (currentSpec -> genc) + yyerror("private section not allowed in a C module"); + + if (notSkipping()) + sectionFlags = SECT_IS_PRIVATE | $2; + } + | TK_SIGNALS ':' { + if (currentSpec -> genc) + yyerror("signals section not allowed in a C module"); + + if (notSkipping()) + sectionFlags = SECT_IS_SIGNAL; + } + ; + +optslot: { + $$ = 0; + } + | TK_SLOTS { + $$ = SECT_IS_SLOT; + } + ; + +dtor: optvirtual '~' TK_NAME '(' ')' optexceptions optabstract optflags ';' methodcode virtualcatchercode { + /* Note that we allow non-virtual dtors in C modules. */ + + if (notSkipping()) + { + classDef *cd = currentScope(); + + if (strcmp(classBaseName(cd),$3) != 0) + yyerror("Destructor doesn't have the same name as its class"); + + if (isDtor(cd)) + yyerror("Destructor has already been defined"); + + if (currentSpec -> genc && $10 == NULL) + yyerror("Destructor in C modules must include %MethodCode"); + + cd -> dealloccode = $10; + cd -> dtorcode = $11; + cd -> dtorexceptions = $6; + + /* + * Note that we don't apply the protected/public hack to dtors + * as it (I think) may change the behaviour of the wrapped API. + */ + cd->classflags |= sectionFlags; + + if ($7) + { + if (!$1) + yyerror("Abstract destructor must be virtual"); + + setIsAbstractClass(cd); + } + + /* + * The class has a shadow if we have a virtual dtor or some + * dtor code. + */ + if ($1 || $11 != NULL) + { + if (currentSpec -> genc) + yyerror("Virtual destructor or %VirtualCatcherCode not allowed in a C module"); + + setHasShadow(cd); + } + + if (getReleaseGIL(&$8)) + setIsReleaseGILDtor(cd); + else if (getHoldGIL(&$8)) + setIsHoldGILDtor(cd); + } + } + ; + +ctor: TK_EXPLICIT {currentCtorIsExplicit = TRUE;} simplector + | simplector + ; + +simplector: TK_NAME '(' arglist ')' optexceptions optflags optctorsig ';' optdocstring methodcode { + /* Note that we allow ctors in C modules. */ + + if (notSkipping()) + { + if (currentSpec -> genc) + { + if ($10 == NULL && $3.nrArgs != 0) + yyerror("Constructors with arguments in C modules must include %MethodCode"); + + if (currentCtorIsExplicit) + yyerror("Explicit constructors not allowed in a C module"); + } + + if ((sectionFlags & (SECT_IS_PUBLIC | SECT_IS_PROT | SECT_IS_PRIVATE)) == 0) + yyerror("Constructor must be in the public, private or protected sections"); + + newCtor($1, sectionFlags, &$3, &$6, $10, $5, $7, + currentCtorIsExplicit, $9); + } + + free($1); + + currentCtorIsExplicit = FALSE; + } + ; + +optctorsig: { + $$ = NULL; + } + | '[' '(' arglist ')' ']' { + $$ = sipMalloc(sizeof (signatureDef)); + + *$$ = $3; + } + ; + +optsig: { + $$ = NULL; + } + | '[' cpptype '(' arglist ')' ']' { + $$ = sipMalloc(sizeof (signatureDef)); + + *$$ = $4; + $$ -> result = $2; + } + ; + +optvirtual: { + $$ = FALSE; + } + | TK_VIRTUAL { + $$ = TRUE; + } + ; + +function: cpptype TK_NAME '(' arglist ')' optconst optexceptions optabstract optflags optsig ';' optdocstring methodcode virtualcatchercode { + if (notSkipping()) + { + applyTypeFlags(currentModule, &$1, &$9); + + $4.result = $1; + + newFunction(currentSpec, currentModule, currentScope(), NULL, + sectionFlags, currentIsStatic, currentIsSignal, + currentIsSlot, currentOverIsVirt, $2, &$4, $6, $8, &$9, + $13, $14, $7, $10, $12); + } + + currentIsStatic = FALSE; + currentIsSignal = FALSE; + currentIsSlot = FALSE; + currentOverIsVirt = FALSE; + } + | cpptype TK_OPERATOR '=' '(' cpptype ')' ';' { + /* + * It looks like an assignment operator (though we don't bother to + * check the types) so make sure it is private. + */ + if (notSkipping()) + { + classDef *cd = currentScope(); + + if (cd == NULL || !(sectionFlags & SECT_IS_PRIVATE)) + yyerror("Assignment operators may only be defined as private"); + + setCannotAssign(cd); + } + + currentIsStatic = FALSE; + currentIsSignal = FALSE; + currentIsSlot = FALSE; + currentOverIsVirt = FALSE; + } + | cpptype TK_OPERATOR operatorname '(' arglist ')' optconst optexceptions optabstract optflags optsig ';' methodcode virtualcatchercode { + if (notSkipping()) + { + classDef *cd = currentScope(); + + applyTypeFlags(currentModule, &$1, &$10); + + /* Handle the unary '+' and '-' operators. */ + if ((cd != NULL && $5.nrArgs == 0) || (cd == NULL && $5.nrArgs == 1)) + { + if (strcmp($3, "__add__") == 0) + $3 = "__pos__"; + else if (strcmp($3, "__sub__") == 0) + $3 = "__neg__"; + } + + $5.result = $1; + + newFunction(currentSpec, currentModule, cd, NULL, + sectionFlags, currentIsStatic, currentIsSignal, + currentIsSlot, currentOverIsVirt, $3, &$5, $7, $9, + &$10, $13, $14, $8, $11, NULL); + } + + currentIsStatic = FALSE; + currentIsSignal = FALSE; + currentIsSlot = FALSE; + currentOverIsVirt = FALSE; + } + | TK_OPERATOR cpptype '(' arglist ')' optconst optexceptions optabstract optflags optsig ';' methodcode virtualcatchercode { + if (notSkipping()) + { + char *sname; + classDef *scope = currentScope(); + + if (scope == NULL || $4.nrArgs != 0) + yyerror("Operator casts must be specified in a class and have no arguments"); + + applyTypeFlags(currentModule, &$2, &$9); + + switch ($2.atype) + { + case defined_type: + sname = NULL; + break; + + case bool_type: + case cbool_type: + case short_type: + case ushort_type: + case int_type: + case cint_type: + case uint_type: + sname = "__int__"; + break; + + case long_type: + case ulong_type: + case longlong_type: + case ulonglong_type: + sname = "__long__"; + break; + + case float_type: + case cfloat_type: + case double_type: + case cdouble_type: + sname = "__float__"; + break; + + default: + yyerror("Unsupported operator cast"); + } + + if (sname != NULL) + { + $4.result = $2; + + newFunction(currentSpec, currentModule, scope, NULL, + sectionFlags, currentIsStatic, currentIsSignal, + currentIsSlot, currentOverIsVirt, sname, &$4, $6, + $8, &$9, $12, $13, $7, $10, NULL); + } + else + { + argList *al; + + /* Check it doesn't already exist. */ + for (al = scope->casts; al != NULL; al = al->next) + if (compareScopedNames($2.u.snd, al->arg.u.snd) == 0) + yyerror("This operator cast has already been specified in this class"); + + al = sipMalloc(sizeof (argList)); + al->arg = $2; + al->next = scope->casts; + + scope->casts = al; + } + } + + currentIsStatic = FALSE; + currentIsSignal = FALSE; + currentIsSlot = FALSE; + currentOverIsVirt = FALSE; + } + ; + +operatorname: '+' {$$ = "__add__";} + | '-' {$$ = "__sub__";} + | '*' {$$ = "__mul__";} + | '/' {$$ = "__div__";} + | '%' {$$ = "__mod__";} + | '&' {$$ = "__and__";} + | '|' {$$ = "__or__";} + | '^' {$$ = "__xor__";} + | '<' '<' {$$ = "__lshift__";} + | '>' '>' {$$ = "__rshift__";} + | '+' '=' {$$ = "__iadd__";} + | '-' '=' {$$ = "__isub__";} + | '*' '=' {$$ = "__imul__";} + | '/' '=' {$$ = "__idiv__";} + | '%' '=' {$$ = "__imod__";} + | '&' '=' {$$ = "__iand__";} + | '|' '=' {$$ = "__ior__";} + | '^' '=' {$$ = "__ixor__";} + | '<' '<' '=' {$$ = "__ilshift__";} + | '>' '>' '=' {$$ = "__irshift__";} + | '~' {$$ = "__invert__";} + | '(' ')' {$$ = "__call__";} + | '[' ']' {$$ = "__getitem__";} + | '<' {$$ = "__lt__";} + | '<' '=' {$$ = "__le__";} + | '=' '=' {$$ = "__eq__";} + | '!' '=' {$$ = "__ne__";} + | '>' {$$ = "__gt__";} + | '>' '=' {$$ = "__ge__";} + ; + +optconst: { + $$ = FALSE; + } + | TK_CONST { + $$ = TRUE; + } + ; + +optabstract: { + $$ = 0; + } + | '=' TK_NUMBER { + if ($2 != 0) + yyerror("Abstract virtual function '= 0' expected"); + + $$ = TRUE; + } + ; + +optflags: { + $$.nrFlags = 0; + } + | '/' flaglist '/' { + $$ = $2; + } + ; + + +flaglist: flag { + $$.flags[0] = $1; + $$.nrFlags = 1; + } + | flaglist ',' flag { + /* Check there is room. */ + + if ($1.nrFlags == MAX_NR_FLAGS) + yyerror("Too many optional flags"); + + $$ = $1; + + $$.flags[$$.nrFlags++] = $3; + } + ; + +flag: TK_NAME { + $$.ftype = bool_flag; + $$.fname = $1; + } + | TK_NAME '=' flagvalue { + $$ = $3; + $$.fname = $1; + } + ; + +flagvalue: dottedname { + $$.ftype = (strchr($1, '.') != NULL) ? dotted_name_flag : name_flag; + $$.fvalue.sval = $1; + } + | TK_NAME ':' optnumber '-' optnumber { + apiVersionRangeDef *avd; + int from, to; + + $$.ftype = api_range_flag; + + /* Check that the API is known. */ + if ((avd = findAPI(currentSpec, $1)) == NULL) + yyerror("unknown API name in API annotation"); + + if (inMainModule()) + setIsUsedName(avd->api_name); + + /* Unbounded values are represented by 0. */ + if ((from = $3) < 0) + from = 0; + + if ((to = $5) < 0) + to = 0; + + $$.fvalue.aval = convertAPIRange(currentModule, avd->api_name, + from, to); + } + | TK_STRING { + $$.ftype = string_flag; + $$.fvalue.sval = convertFeaturedString($1); + } + | TK_NUMBER { + $$.ftype = integer_flag; + $$.fvalue.ival = $1; + } + ; + +docstring: TK_DOCSTRING codeblock { + $$ = $2; + } + ; + +optdocstring: { + $$ = NULL; + } + | docstring + ; + +methodcode: { + $$ = NULL; + } + | TK_METHODCODE codeblock { + $$ = $2; + } + ; + +virtualcatchercode: { + $$ = NULL; + } + | TK_VIRTUALCATCHERCODE codeblock { + $$ = $2; + } + ; + +arglist: rawarglist { + int a, nrrxcon, nrrxdis, nrslotcon, nrslotdis, nrarray, nrarraysize; + + nrrxcon = nrrxdis = nrslotcon = nrslotdis = nrarray = nrarraysize = 0; + + for (a = 0; a < $1.nrArgs; ++a) + { + argDef *ad = &$1.args[a]; + + switch (ad -> atype) + { + case rxcon_type: + ++nrrxcon; + break; + + case rxdis_type: + ++nrrxdis; + break; + + case slotcon_type: + ++nrslotcon; + break; + + case slotdis_type: + ++nrslotdis; + break; + } + + if (isArray(ad)) + ++nrarray; + + if (isArraySize(ad)) + ++nrarraysize; + } + + if (nrrxcon != nrslotcon || nrrxcon > 1) + yyerror("SIP_RXOBJ_CON and SIP_SLOT_CON must both be given and at most once"); + + if (nrrxdis != nrslotdis || nrrxdis > 1) + yyerror("SIP_RXOBJ_DIS and SIP_SLOT_DIS must both be given and at most once"); + + if (nrarray != nrarraysize || nrarray > 1) + yyerror("/Array/ and /ArraySize/ must both be given and at most once"); + + $$ = $1; + } + ; + +rawarglist: { + /* No arguments. */ + + $$.nrArgs = 0; + } + | argvalue { + /* The single or first argument. */ + + $$.args[0] = $1; + $$.nrArgs = 1; + } + | rawarglist ',' argvalue { + /* Check that it wasn't ...(,arg...). */ + if ($1.nrArgs == 0) + yyerror("First argument of the list is missing"); + + /* Check there is nothing after an ellipsis. */ + if ($1.args[$1.nrArgs - 1].atype == ellipsis_type) + yyerror("An ellipsis must be at the end of the argument list"); + + /* + * If this argument has no default value, then the + * previous one mustn't either. + */ + if ($3.defval == NULL && $1.args[$1.nrArgs - 1].defval != NULL) + yyerror("Compulsory argument given after optional argument"); + + /* Check there is room. */ + if ($1.nrArgs == MAX_NR_ARGS) + yyerror("Internal error - increase the value of MAX_NR_ARGS"); + + $$ = $1; + + $$.args[$$.nrArgs] = $3; + $$.nrArgs++; + } + ; + +argvalue: TK_SIPSIGNAL optname optflags optassign { + $$.atype = signal_type; + $$.argflags = ARG_IS_CONST; + $$.nrderefs = 0; + $$.name = cacheName(currentSpec, $2); + $$.defval = $4; + + currentSpec -> sigslots = TRUE; + } + | TK_SIPSLOT optname optflags optassign { + $$.atype = slot_type; + $$.argflags = ARG_IS_CONST; + $$.nrderefs = 0; + $$.name = cacheName(currentSpec, $2); + $$.defval = $4; + + currentSpec -> sigslots = TRUE; + } + | TK_SIPANYSLOT optname optflags optassign { + $$.atype = anyslot_type; + $$.argflags = ARG_IS_CONST; + $$.nrderefs = 0; + $$.name = cacheName(currentSpec, $2); + $$.defval = $4; + + currentSpec -> sigslots = TRUE; + } + | TK_SIPRXCON optname optflags { + $$.atype = rxcon_type; + $$.argflags = 0; + $$.nrderefs = 0; + $$.name = cacheName(currentSpec, $2); + + if (findOptFlag(&$3, "SingleShot", bool_flag) != NULL) + $$.argflags |= ARG_SINGLE_SHOT; + + currentSpec -> sigslots = TRUE; + } + | TK_SIPRXDIS optname optflags { + $$.atype = rxdis_type; + $$.argflags = 0; + $$.nrderefs = 0; + $$.name = cacheName(currentSpec, $2); + + currentSpec -> sigslots = TRUE; + } + | TK_SIPSLOTCON '(' arglist ')' optname optflags { + $$.atype = slotcon_type; + $$.argflags = ARG_IS_CONST; + $$.nrderefs = 0; + $$.name = cacheName(currentSpec, $5); + + memset(&$3.result, 0, sizeof (argDef)); + $3.result.atype = void_type; + + $$.u.sa = sipMalloc(sizeof (signatureDef)); + *$$.u.sa = $3; + + currentSpec -> sigslots = TRUE; + } + | TK_SIPSLOTDIS '(' arglist ')' optname optflags { + $$.atype = slotdis_type; + $$.argflags = ARG_IS_CONST; + $$.nrderefs = 0; + $$.name = cacheName(currentSpec, $5); + + memset(&$3.result, 0, sizeof (argDef)); + $3.result.atype = void_type; + + $$.u.sa = sipMalloc(sizeof (signatureDef)); + *$$.u.sa = $3; + + currentSpec -> sigslots = TRUE; + } + | TK_QOBJECT optname optflags { + $$.atype = qobject_type; + $$.argflags = 0; + $$.nrderefs = 0; + $$.name = cacheName(currentSpec, $2); + } + | argtype optassign { + $$ = $1; + $$.defval = $2; + } + ; + +varmember: + TK_SIGNAL_METHOD {currentIsSignal = TRUE;} simple_varmem + | TK_SLOT_METHOD {currentIsSlot = TRUE;} simple_varmem + | simple_varmem + ; + +simple_varmem: + TK_STATIC {currentIsStatic = TRUE;} varmem + | varmem + ; + +varmem: + member + | variable + ; + +member: + TK_VIRTUAL {currentOverIsVirt = TRUE;} function + | function + ; + +variable: cpptype TK_NAME optflags ';' optaccesscode optgetcode optsetcode { + if (notSkipping()) + { + /* Check the section. */ + + if (sectionFlags != 0) + { + if ((sectionFlags & SECT_IS_PUBLIC) == 0) + yyerror("Class variables must be in the public section"); + + if (!currentIsStatic && $5 != NULL) + yyerror("%AccessCode cannot be specified for non-static class variables"); + } + + if (currentIsStatic && currentSpec -> genc) + yyerror("Cannot have static members in a C structure"); + + applyTypeFlags(currentModule, &$1, &$3); + + if ($6 != NULL || $7 != NULL) + { + if ($5 != NULL) + yyerror("Cannot mix %AccessCode and %GetCode or %SetCode"); + + if (currentScope() == NULL) + yyerror("Cannot specify %GetCode or %SetCode for global variables"); + } + + newVar(currentSpec,currentModule,$2,currentIsStatic,&$1,&$3,$5,$6,$7); + } + + currentIsStatic = FALSE; + } + ; + +cpptype: TK_CONST basetype deref optref { + $$ = $2; + $$.nrderefs += $3; + $$.argflags |= ARG_IS_CONST | $4; + } + | basetype deref optref { + $$ = $1; + $$.nrderefs += $2; + $$.argflags |= $3; + } + ; + +argtype: cpptype optname optflags { + $$ = $1; + $$.name = cacheName(currentSpec, $2); + + if (getAllowNone(&$3)) + $$.argflags |= ARG_ALLOW_NONE; + + if (findOptFlag(&$3,"GetWrapper",bool_flag) != NULL) + $$.argflags |= ARG_GET_WRAPPER; + + if (findOptFlag(&$3,"Array",bool_flag) != NULL) + $$.argflags |= ARG_ARRAY; + + if (findOptFlag(&$3,"ArraySize",bool_flag) != NULL) + $$.argflags |= ARG_ARRAY_SIZE; + + if (getTransfer(&$3)) + $$.argflags |= ARG_XFERRED; + + if (findOptFlag(&$3,"TransferThis",bool_flag) != NULL) + $$.argflags |= ARG_THIS_XFERRED; + + if (findOptFlag(&$3,"TransferBack",bool_flag) != NULL) + $$.argflags |= ARG_XFERRED_BACK; + + if (findOptFlag(&$3, "KeepReference", bool_flag) != NULL) + { + $$.argflags |= ARG_KEEP_REF; + $$.key = currentModule->next_key++; + } + + if (findOptFlag(&$3,"In",bool_flag) != NULL) + $$.argflags |= ARG_IN; + + if (findOptFlag(&$3,"Out",bool_flag) != NULL) + $$.argflags |= ARG_OUT; + + if (findOptFlag(&$3, "ResultSize", bool_flag) != NULL) + $$.argflags |= ARG_RESULT_SIZE; + + if (findOptFlag(&$3, "NoCopy", bool_flag) != NULL) + $$.argflags |= ARG_NO_COPY; + + if (findOptFlag(&$3,"Constrained",bool_flag) != NULL) + { + $$.argflags |= ARG_CONSTRAINED; + + switch ($$.atype) + { + case bool_type: + $$.atype = cbool_type; + break; + + case int_type: + $$.atype = cint_type; + break; + + case float_type: + $$.atype = cfloat_type; + break; + + case double_type: + $$.atype = cdouble_type; + break; + } + } + + applyTypeFlags(currentModule, &$$, &$3); + $$.docval = getDocValue(&$3); + } + ; + +optref: { + $$ = 0; + } + | '&' { + if (currentSpec -> genc) + yyerror("References not allowed in a C module"); + + $$ = ARG_IS_REF; + } + ; + +deref: { + $$ = 0; + } + | deref '*' { + $$ = $1 + 1; + } + ; + +basetype: scopedname { + memset(&$$, 0, sizeof (argDef)); + $$.atype = defined_type; + $$.u.snd = $1; + + /* Try and resolve typedefs as early as possible. */ + resolveAnyTypedef(currentSpec, &$$); + } + | scopedname '<' cpptypelist '>' { + templateDef *td; + + td = sipMalloc(sizeof(templateDef)); + td->fqname = $1; + td->types = $3; + + memset(&$$, 0, sizeof (argDef)); + $$.atype = template_type; + $$.u.td = td; + } + | TK_STRUCT scopedname { + memset(&$$, 0, sizeof (argDef)); + + /* In a C module all structures must be defined. */ + if (currentSpec -> genc) + { + $$.atype = defined_type; + $$.u.snd = $2; + } + else + { + $$.atype = struct_type; + $$.u.sname = $2; + } + } + | TK_UNSIGNED TK_SHORT { + memset(&$$, 0, sizeof (argDef)); + $$.atype = ushort_type; + } + | TK_SHORT { + memset(&$$, 0, sizeof (argDef)); + $$.atype = short_type; + } + | TK_UNSIGNED { + memset(&$$, 0, sizeof (argDef)); + $$.atype = uint_type; + } + | TK_UNSIGNED TK_INT { + memset(&$$, 0, sizeof (argDef)); + $$.atype = uint_type; + } + | TK_INT { + memset(&$$, 0, sizeof (argDef)); + $$.atype = int_type; + } + | TK_LONG { + memset(&$$, 0, sizeof (argDef)); + $$.atype = long_type; + } + | TK_UNSIGNED TK_LONG { + memset(&$$, 0, sizeof (argDef)); + $$.atype = ulong_type; + } + | TK_LONG TK_LONG { + memset(&$$, 0, sizeof (argDef)); + $$.atype = longlong_type; + } + | TK_UNSIGNED TK_LONG TK_LONG { + memset(&$$, 0, sizeof (argDef)); + $$.atype = ulonglong_type; + } + | TK_FLOAT { + memset(&$$, 0, sizeof (argDef)); + $$.atype = float_type; + } + | TK_DOUBLE { + memset(&$$, 0, sizeof (argDef)); + $$.atype = double_type; + } + | TK_BOOL { + memset(&$$, 0, sizeof (argDef)); + $$.atype = bool_type; + } + | TK_SIGNED TK_CHAR { + memset(&$$, 0, sizeof (argDef)); + $$.atype = sstring_type; + } + | TK_UNSIGNED TK_CHAR { + memset(&$$, 0, sizeof (argDef)); + $$.atype = ustring_type; + } + | TK_CHAR { + memset(&$$, 0, sizeof (argDef)); + $$.atype = string_type; + } + | TK_WCHAR_T { + memset(&$$, 0, sizeof (argDef)); + $$.atype = wstring_type; + } + | TK_VOID { + memset(&$$, 0, sizeof (argDef)); + $$.atype = void_type; + } + | TK_PYOBJECT { + memset(&$$, 0, sizeof (argDef)); + $$.atype = pyobject_type; + } + | TK_PYTUPLE { + memset(&$$, 0, sizeof (argDef)); + $$.atype = pytuple_type; + } + | TK_PYLIST { + memset(&$$, 0, sizeof (argDef)); + $$.atype = pylist_type; + } + | TK_PYDICT { + memset(&$$, 0, sizeof (argDef)); + $$.atype = pydict_type; + } + | TK_PYCALLABLE { + memset(&$$, 0, sizeof (argDef)); + $$.atype = pycallable_type; + } + | TK_PYSLICE { + memset(&$$, 0, sizeof (argDef)); + $$.atype = pyslice_type; + } + | TK_PYTYPE { + memset(&$$, 0, sizeof (argDef)); + $$.atype = pytype_type; + } + | TK_ELLIPSIS { + memset(&$$, 0, sizeof (argDef)); + $$.atype = ellipsis_type; + } + ; + +cpptypelist: cpptype { + /* The single or first type. */ + + $$.args[0] = $1; + $$.nrArgs = 1; + } + | cpptypelist ',' cpptype { + /* Check there is nothing after an ellipsis. */ + if ($1.args[$1.nrArgs - 1].atype == ellipsis_type) + yyerror("An ellipsis must be at the end of the argument list"); + + /* Check there is room. */ + if ($1.nrArgs == MAX_NR_ARGS) + yyerror("Internal error - increase the value of MAX_NR_ARGS"); + + $$ = $1; + + $$.args[$$.nrArgs] = $3; + $$.nrArgs++; + } + ; + +optexceptions: { + $$ = NULL; + } + | TK_THROW '(' exceptionlist ')' { + if (currentSpec->genc) + yyerror("Exceptions not allowed in a C module"); + + $$ = $3; + } + ; + +exceptionlist: { + /* Empty list so use a blank. */ + + $$ = sipMalloc(sizeof (throwArgs)); + $$ -> nrArgs = 0; + } + | scopedname { + /* The only or first exception. */ + + $$ = sipMalloc(sizeof (throwArgs)); + $$ -> nrArgs = 1; + $$ -> args[0] = findException(currentSpec, $1, FALSE); + } + | exceptionlist ',' scopedname { + /* Check that it wasn't ...(,arg...). */ + + if ($1 -> nrArgs == 0) + yyerror("First exception of throw specifier is missing"); + + /* Check there is room. */ + + if ($1 -> nrArgs == MAX_NR_ARGS) + yyerror("Internal error - increase the value of MAX_NR_ARGS"); + + $$ = $1; + $$ -> args[$$ -> nrArgs++] = findException(currentSpec, $3, FALSE); + } + ; + +%% + + +/* + * Parse the specification. + */ +void parse(sipSpec *spec, FILE *fp, char *filename, stringList *tsl, + stringList *xfl, int kwdArgs, int protHack) +{ + classTmplDef *tcd; + + /* Initialise the spec. */ + + spec->modules = NULL; + spec->namecache = NULL; + spec->ifacefiles = NULL; + spec->classes = NULL; + spec->classtemplates = NULL; + spec->exceptions = NULL; + spec->mappedtypes = NULL; + spec->mappedtypetemplates = NULL; + spec->enums = NULL; + spec->vars = NULL; + spec->typedefs = NULL; + spec->exphdrcode = NULL; + spec->docs = NULL; + spec->sigslots = FALSE; + spec->genc = -1; + spec->plugins = NULL; + + currentSpec = spec; + neededQualifiers = tsl; + excludedQualifiers = xfl; + currentModule = NULL; + currentMappedType = NULL; + currentOverIsVirt = FALSE; + currentCtorIsExplicit = FALSE; + currentIsStatic = FALSE; + currentIsSignal = FALSE; + currentIsSlot = FALSE; + currentIsTemplate = FALSE; + previousFile = NULL; + skipStackPtr = 0; + currentScopeIdx = 0; + sectionFlags = 0; + defaultKwdArgs = kwdArgs; + makeProtPublic = protHack; + + newModule(fp, filename); + spec->module = currentModule; + + yyparse(); + + handleEOF(); + handleEOM(); + + /* + * Go through each template class and remove it from the list of classes. + */ + for (tcd = spec->classtemplates; tcd != NULL; tcd = tcd->next) + { + classDef **cdp; + + for (cdp = &spec->classes; *cdp != NULL; cdp = &(*cdp)->next) + if (*cdp == tcd->cd) + { + ifaceFileDef **ifdp; + + /* Remove the interface file as well. */ + for (ifdp = &spec->ifacefiles; *ifdp != NULL; ifdp = &(*ifdp)->next) + if (*ifdp == tcd->cd->iff) + { + *ifdp = (*ifdp)->next; + break; + } + + *cdp = (*cdp)->next; + break; + } + } +} + + +/* + * Tell the parser that a complete file has now been read. + */ +void parserEOF(char *name, parserContext *pc) +{ + previousFile = sipStrdup(name); + currentContext = *pc; +} + + +/* + * Append a class definition to a class list if it doesn't already appear. + * Append is needed specifically for the list of super-classes because the + * order is important to Python. + */ +void appendToClassList(classList **clp,classDef *cd) +{ + classList *new; + + /* Find the end of the list. */ + + while (*clp != NULL) + { + if ((*clp) -> cd == cd) + return; + + clp = &(*clp) -> next; + } + + new = sipMalloc(sizeof (classList)); + + new -> cd = cd; + new -> next = NULL; + + *clp = new; +} + + +/* + * Create a new module for the current specification and make it current. + */ +static void newModule(FILE *fp, char *filename) +{ + moduleDef *mod; + + parseFile(fp, filename, currentModule, FALSE); + + mod = allocModule(); + mod->file = filename; + + if (currentModule != NULL) + mod->defexception = currentModule->defexception; + + currentModule = mod; +} + + +/* + * Allocate and initialise the memory for a new module. + */ +static moduleDef *allocModule() +{ + moduleDef *newmod, **tailp; + + newmod = sipMalloc(sizeof (moduleDef)); + + newmod->version = -1; + newmod->encoding = no_type; + newmod->qobjclass = -1; + newmod->nrvirthandlers = -1; + newmod->next_key = 1; + + /* + * The consolidated module support needs these to be in order that they + * appeared. + */ + for (tailp = ¤tSpec->modules; *tailp != NULL; tailp = &(*tailp)->next) + ; + + *tailp = newmod; + + return newmod; +} + + +/* + * Switch to parsing a new file. + */ +static void parseFile(FILE *fp, char *name, moduleDef *prevmod, int optional) +{ + parserContext pc; + + pc.filename = name; + pc.ifdepth = skipStackPtr; + pc.prevmod = prevmod; + + if (setInputFile(fp, &pc, optional)) + currentContext = pc; +} + + +/* + * Find an interface file, or create a new one. + */ +ifaceFileDef *findIfaceFile(sipSpec *pt, moduleDef *mod, scopedNameDef *fqname, + ifaceFileType iftype, apiVersionRangeDef *api_range, argDef *ad) +{ + ifaceFileDef *iff, *first_alt = NULL; + + /* See if the name is already used. */ + + for (iff = pt->ifacefiles; iff != NULL; iff = iff->next) + { + if (compareScopedNames(iff->fqcname, fqname) != 0) + continue; + + /* + * If they are both versioned then assume the user knows what they are + * doing. + */ + if (iff->api_range != NULL && api_range != NULL && iff->module == mod) + { + /* Remember the first of the alternate APIs. */ + if ((first_alt = iff->first_alt) == NULL) + first_alt = iff; + + break; + } + + /* + * They must be the same type except that we allow a class if we want + * an exception. This is because we allow classes to be used before + * they are defined. + */ + if (iff->type != iftype) + if (iftype != exception_iface || iff->type != class_iface) + yyerror("A class, exception, namespace or mapped type has already been defined with the same name"); + + /* Ignore an external class declared in another module. */ + if (iftype == class_iface && iff->module != mod) + { + classDef *cd; + + for (cd = pt->classes; cd != NULL; cd = cd->next) + if (cd->iff == iff) + break; + + if (cd != NULL && iff->module != NULL && isExternal(cd)) + continue; + } + + /* + * If this is a mapped type with the same name defined in a different + * module, then check that this type isn't the same as any of the + * mapped types defined in that module. + */ + if (iftype == mappedtype_iface && iff->module != mod) + { + mappedTypeDef *mtd; + + /* + * This is a bit of a cheat. With consolidated modules it's + * possible to have two implementations of a mapped type in + * different branches of the module hierarchy. We assume that, if + * there really are multiple implementations in the same branch, + * then it will be picked up in a non-consolidated build. + */ + if (isConsolidated(pt->module)) + continue; + + for (mtd = pt->mappedtypes; mtd != NULL; mtd = mtd->next) + { + if (mtd->iff != iff) + continue; + + if (ad->atype != template_type || + mtd->type.atype != template_type || + sameBaseType(ad, &mtd->type)) + yyerror("Mapped type has already been defined in another module"); + } + + /* + * If we got here then we have a mapped type based on an existing + * template, but with unique parameters. We don't want to use + * interface files from other modules, so skip this one. + */ + + continue; + } + + /* Ignore a namespace defined in another module. */ + if (iftype == namespace_iface && iff->module != mod) + continue; + + return iff; + } + + iff = sipMalloc(sizeof (ifaceFileDef)); + + iff->name = cacheName(pt, scopedNameToString(fqname)); + iff->api_range = api_range; + + if (first_alt != NULL) + { + iff->first_alt = first_alt; + iff->next_alt = first_alt->next_alt; + + first_alt->next_alt = iff; + } + else + { + /* This is the first alternate so point to itself. */ + iff->first_alt = iff; + } + + iff->type = iftype; + iff->ifacenr = -1; + iff->fqcname = fqname; + iff->module = NULL; + iff->hdrcode = NULL; + iff->used = NULL; + iff->next = pt->ifacefiles; + + pt->ifacefiles = iff; + + return iff; +} + + +/* + * Find a class definition in a parse tree. + */ +static classDef *findClass(sipSpec *pt, ifaceFileType iftype, + apiVersionRangeDef *api_range, scopedNameDef *fqname) +{ + return findClassWithInterface(pt, findIfaceFile(pt, currentModule, fqname, iftype, api_range, NULL)); +} + + +/* + * Find a class definition given an existing interface file. + */ +static classDef *findClassWithInterface(sipSpec *pt, ifaceFileDef *iff) +{ + classDef *cd; + + for (cd = pt -> classes; cd != NULL; cd = cd -> next) + if (cd -> iff == iff) + return cd; + + /* Create a new one. */ + cd = sipMalloc(sizeof (classDef)); + + cd->iff = iff; + cd->pyname = cacheName(pt, classBaseName(cd)); + cd->next = pt->classes; + + pt->classes = cd; + + return cd; +} + + +/* + * Add an interface file to an interface file list if it isn't already there. + */ +void addToUsedList(ifaceFileList **ifflp, ifaceFileDef *iff) +{ + /* Make sure we don't try to add an interface file to its own list. */ + if (&iff->used != ifflp) + { + ifaceFileList *iffl; + + while ((iffl = *ifflp) != NULL) + { + /* Don't bother if it is already there. */ + if (iffl->iff == iff) + return; + + ifflp = &iffl -> next; + } + + iffl = sipMalloc(sizeof (ifaceFileList)); + + iffl->iff = iff; + iffl->next = NULL; + + *ifflp = iffl; + } +} + + +/* + * Find an undefined (or create a new) exception definition in a parse tree. + */ +static exceptionDef *findException(sipSpec *pt, scopedNameDef *fqname, int new) +{ + exceptionDef *xd, **tail; + ifaceFileDef *iff; + classDef *cd; + + iff = findIfaceFile(pt, currentModule, fqname, exception_iface, NULL, NULL); + + /* See if it is an existing one. */ + for (xd = pt->exceptions; xd != NULL; xd = xd->next) + if (xd->iff == iff) + return xd; + + /* + * If it is an exception interface file then we have never seen this + * name before. We require that exceptions are defined before being + * used, but don't make the same requirement of classes (for reasons of + * backwards compatibility). Therefore the name must be reinterpreted + * as a (as yet undefined) class. + */ + if (new) + { + if (iff->type == exception_iface) + cd = NULL; + else + yyerror("There is already a class with the same name or the exception has been used before being defined"); + } + else + { + if (iff->type == exception_iface) + iff->type = class_iface; + + cd = findClassWithInterface(pt, iff); + } + + /* Create a new one. */ + xd = sipMalloc(sizeof (exceptionDef)); + + xd->exceptionnr = -1; + xd->iff = iff; + xd->pyname = NULL; + xd->cd = cd; + xd->bibase = NULL; + xd->base = NULL; + xd->raisecode = NULL; + xd->next = NULL; + + /* Append it to the list. */ + for (tail = &pt->exceptions; *tail != NULL; tail = &(*tail)->next) + ; + + *tail = xd; + + return xd; +} + + +/* + * Find an undefined (or create a new) class definition in a parse tree. + */ +static classDef *newClass(sipSpec *pt, ifaceFileType iftype, + apiVersionRangeDef *api_range, scopedNameDef *fqname) +{ + int flags; + classDef *cd, *scope; + codeBlock *hdrcode; + + if (sectionFlags & SECT_IS_PRIVATE) + yyerror("Classes, structs and namespaces must be in the public or protected sections"); + + flags = 0; + + if ((scope = currentScope()) != NULL) + { + if (sectionFlags & SECT_IS_PROT && !makeProtPublic) + { + flags = CLASS_IS_PROTECTED; + + if (scope->iff->type == class_iface) + setHasShadow(scope); + } + + /* Header code from outer scopes is also included. */ + hdrcode = scope->iff->hdrcode; + } + else + hdrcode = NULL; + + if (pt -> genc) + { + /* C structs are always global types. */ + while (fqname -> next != NULL) + fqname = fqname -> next; + + scope = NULL; + } + + cd = findClass(pt, iftype, api_range, fqname); + + /* Check it hasn't already been defined. */ + if (iftype != namespace_iface && cd->iff->module != NULL) + yyerror("The struct/class has already been defined"); + + /* Complete the initialisation. */ + cd->classflags |= flags; + cd->ecd = scope; + cd->iff->module = currentModule; + + if (currentIsTemplate) + setIsTemplateClass(cd); + + appendCodeBlock(&cd->iff->hdrcode, hdrcode); + + /* See if it is a namespace extender. */ + if (iftype == namespace_iface) + { + classDef *ns; + + for (ns = pt->classes; ns != NULL; ns = ns->next) + { + if (ns == cd) + continue; + + if (ns->iff->type != namespace_iface) + continue; + + if (compareScopedNames(ns->iff->fqcname, fqname) != 0) + continue; + + cd->real = ns; + break; + } + } + + return cd; +} + + +/* + * Tidy up after finishing a class definition. + */ +static void finishClass(sipSpec *pt, moduleDef *mod, classDef *cd, + optFlags *of) +{ + const char *pyname; + optFlag *flg; + + /* Get the Python name and see if it is different to the C++ name. */ + pyname = getPythonName(of, classBaseName(cd)); + + cd->pyname = NULL; + checkAttributes(pt, mod, cd->ecd, NULL, pyname, FALSE); + cd->pyname = cacheName(pt, pyname); + + if ((flg = findOptFlag(of, "Metatype", dotted_name_flag)) != NULL) + cd->metatype = cacheName(pt, flg->fvalue.sval); + + if ((flg = findOptFlag(of, "Supertype", dotted_name_flag)) != NULL) + cd->supertype = cacheName(pt, flg->fvalue.sval); + + if ((flg = findOptFlag(of, "PyQt4Flags", integer_flag)) != NULL) + cd->pyqt4_flags = flg->fvalue.ival; + + if (findOptFlag(of, "PyQt4NoQMetaObject", bool_flag) != NULL) + setPyQt4NoQMetaObject(cd); + + if (isOpaque(cd)) + { + if (findOptFlag(of, "External", bool_flag) != NULL) + setIsExternal(cd); + } + else + { + int seq_might, seq_not; + memberDef *md; + + if (findOptFlag(of, "NoDefaultCtors", bool_flag) != NULL) + setNoDefaultCtors(cd); + + if (cd -> ctors == NULL) + { + if (!noDefaultCtors(cd)) + { + /* Provide a default ctor. */ + + cd->ctors = sipMalloc(sizeof (ctorDef)); + + cd->ctors->ctorflags = SECT_IS_PUBLIC; + cd->ctors->pysig.result.atype = void_type; + cd->ctors->cppsig = &cd->ctors->pysig; + + cd->defctor = cd->ctors; + + setCanCreate(cd); + } + } + else if (cd -> defctor == NULL) + { + ctorDef *ct, *last = NULL; + + for (ct = cd -> ctors; ct != NULL; ct = ct -> next) + { + if (!isPublicCtor(ct)) + continue; + + if (ct -> pysig.nrArgs == 0 || ct -> pysig.args[0].defval != NULL) + { + cd -> defctor = ct; + break; + } + + if (last == NULL) + last = ct; + } + + /* The last resort is the first public ctor. */ + if (cd->defctor == NULL) + cd->defctor = last; + } + + if (getDeprecated(of)) + setIsDeprecatedClass(cd); + + if (cd->convtocode != NULL && getAllowNone(of)) + setClassHandlesNone(cd); + + if (findOptFlag(of,"Abstract",bool_flag) != NULL) + { + setIsAbstractClass(cd); + setIsIncomplete(cd); + resetCanCreate(cd); + } + + /* We assume a public dtor if nothing specific was provided. */ + if (!isDtor(cd)) + setIsPublicDtor(cd); + + if (findOptFlag(of, "DelayDtor", bool_flag) != NULL) + { + setIsDelayedDtor(cd); + setHasDelayedDtors(mod); + } + + /* + * There are subtle differences between the add and concat methods and + * the multiply and repeat methods. The number versions can have their + * operands swapped and may return NotImplemented. If the user has + * used the /Numeric/ annotation or there are other numeric operators + * then we use add/multiply. Otherwise, if there are indexing + * operators then we use concat/repeat. + */ + seq_might = seq_not = FALSE; + + for (md = cd -> members; md != NULL; md = md -> next) + switch (md -> slot) + { + case getitem_slot: + case setitem_slot: + case delitem_slot: + /* This might be a sequence. */ + seq_might = TRUE; + break; + + case sub_slot: + case isub_slot: + case div_slot: + case idiv_slot: + case mod_slot: + case imod_slot: + case floordiv_slot: + case ifloordiv_slot: + case truediv_slot: + case itruediv_slot: + case pos_slot: + case neg_slot: + /* This is definately not a sequence. */ + seq_not = TRUE; + break; + } + + if (!seq_not && seq_might) + for (md = cd -> members; md != NULL; md = md -> next) + { + /* Ignore if the user has been explicit. */ + if (isNumeric(md)) + continue; + + switch (md -> slot) + { + case add_slot: + md -> slot = concat_slot; + break; + + case iadd_slot: + md -> slot = iconcat_slot; + break; + + case mul_slot: + md -> slot = repeat_slot; + break; + + case imul_slot: + md -> slot = irepeat_slot; + break; + } + } + } + + if (inMainModule()) + { + setIsUsedName(cd->iff->name); + setIsUsedName(cd->pyname); + } +} + + +/* + * Return the encoded name of a template (ie. including its argument types) as + * a scoped name. + */ +scopedNameDef *encodedTemplateName(templateDef *td) +{ + int a; + scopedNameDef *snd; + + snd = copyScopedName(td->fqname); + + for (a = 0; a < td->types.nrArgs; ++a) + { + char buf[50]; + int flgs; + scopedNameDef *arg_snd; + argDef *ad = &td->types.args[a]; + + flgs = 0; + + if (isConstArg(ad)) + flgs += 1; + + if (isReference(ad)) + flgs += 2; + + /* We use numbers so they don't conflict with names. */ + sprintf(buf, "%02d%d%d", ad->atype, flgs, ad->nrderefs); + + switch (ad->atype) + { + case defined_type: + arg_snd = copyScopedName(ad->u.snd); + break; + + case template_type: + arg_snd = encodedTemplateName(ad->u.td); + break; + + case struct_type: + arg_snd = copyScopedName(ad->u.sname); + break; + + default: + arg_snd = NULL; + } + + /* + * Replace the first element of the argument name with a copy with the + * encoding prepended. + */ + if (arg_snd != NULL) + arg_snd->name = concat(buf, arg_snd->name, NULL); + else + arg_snd = text2scopePart(sipStrdup(buf)); + + appendScopedName(&snd, arg_snd); + } + + return snd; +} + + +/* + * Create a new mapped type. + */ +static mappedTypeDef *newMappedType(sipSpec *pt, argDef *ad, optFlags *of) +{ + mappedTypeDef *mtd; + scopedNameDef *snd; + ifaceFileDef *iff; + const char *cname; + + /* Check that the type is one we want to map. */ + switch (ad->atype) + { + case defined_type: + snd = ad->u.snd; + cname = scopedNameTail(snd); + break; + + case template_type: + snd = encodedTemplateName(ad->u.td); + cname = NULL; + break; + + case struct_type: + snd = ad->u.sname; + cname = scopedNameTail(snd); + break; + + default: + yyerror("Invalid type for %MappedType"); + } + + iff = findIfaceFile(pt, currentModule, snd, mappedtype_iface, + getAPIRange(of), ad); + + /* Check it hasn't already been defined. */ + for (mtd = pt->mappedtypes; mtd != NULL; mtd = mtd->next) + if (mtd->iff == iff) + { + /* + * We allow types based on the same template but with different + * arguments. + */ + if (ad->atype != template_type || sameBaseType(ad, &mtd->type)) + yyerror("Mapped type has already been defined in this module"); + } + + /* The module may not have been set yet. */ + iff->module = currentModule; + + /* Create a new mapped type. */ + mtd = allocMappedType(pt, ad); + + if (cname != NULL) + mtd->pyname = cacheName(pt, getPythonName(of, cname)); + + if (findOptFlag(of, "NoRelease", bool_flag) != NULL) + setNoRelease(mtd); + + if (getAllowNone(of)) + setHandlesNone(mtd); + + mtd->doctype = getDocType(of); + + mtd->iff = iff; + mtd->next = pt->mappedtypes; + + pt->mappedtypes = mtd; + + if (inMainModule()) + { + setIsUsedName(mtd->cname); + + if (mtd->pyname) + setIsUsedName(mtd->pyname); + } + + return mtd; +} + + +/* + * Allocate, intialise and return a mapped type structure. + */ +mappedTypeDef *allocMappedType(sipSpec *pt, argDef *type) +{ + mappedTypeDef *mtd; + + mtd = sipMalloc(sizeof (mappedTypeDef)); + + mtd->type = *type; + mtd->type.argflags = 0; + mtd->type.nrderefs = 0; + + mtd->cname = cacheName(pt, type2string(&mtd->type)); + + return mtd; +} + + +/* + * Create a new enum. + */ +static enumDef *newEnum(sipSpec *pt, moduleDef *mod, mappedTypeDef *mt_scope, + char *name, optFlags *of, int flags) +{ + enumDef *ed, *first_alt, *next_alt; + classDef *c_scope; + ifaceFileDef *scope; + + if (mt_scope != NULL) + { + scope = mt_scope->iff; + c_scope = NULL; + } + else + { + if ((c_scope = currentScope()) != NULL) + scope = c_scope->iff; + else + scope = NULL; + } + + ed = sipMalloc(sizeof (enumDef)); + + /* Assume the enum isn't versioned. */ + first_alt = ed; + next_alt = NULL; + + if (name != NULL) + { + ed->pyname = cacheName(pt, getPythonName(of, name)); + checkAttributes(pt, mod, c_scope, mt_scope, ed->pyname->text, FALSE); + + ed->fqcname = text2scopedName(scope, name); + ed->cname = cacheName(pt, scopedNameToString(ed->fqcname)); + + if (inMainModule()) + { + setIsUsedName(ed->pyname); + setIsUsedName(ed->cname); + } + + /* If the scope is versioned then look for any alternate. */ + if (scope != NULL && scope->api_range != NULL) + { + enumDef *alt; + + for (alt = pt->enums; alt != NULL; alt = alt->next) + { + if (alt->module != mod || alt->fqcname == NULL) + continue; + + if (compareScopedNames(alt->fqcname, ed->fqcname) == 0) + { + first_alt = alt->first_alt; + next_alt = first_alt->next_alt; + first_alt->next_alt = ed; + + break; + } + } + } + } + else + { + ed->pyname = NULL; + ed->fqcname = NULL; + ed->cname = NULL; + } + + if (flags & SECT_IS_PROT && makeProtPublic) + { + flags &= ~SECT_IS_PROT; + flags |= SECT_IS_PUBLIC; + } + + ed->enumflags = flags; + ed->enumnr = -1; + ed->ecd = c_scope; + ed->emtd = mt_scope; + ed->first_alt = first_alt; + ed->next_alt = next_alt; + ed->module = mod; + ed->members = NULL; + ed->slots = NULL; + ed->overs = NULL; + ed->next = pt -> enums; + + pt->enums = ed; + + return ed; +} + + +/* + * Get the type values and (optionally) the type names for substitution in + * handwritten code. + */ +void appendTypeStrings(scopedNameDef *ename, signatureDef *patt, signatureDef *src, signatureDef *known, scopedNameDef **names, scopedNameDef **values) +{ + int a; + + for (a = 0; a < patt->nrArgs; ++a) + { + argDef *pad = &patt->args[a]; + + if (pad->atype == defined_type) + { + char *nam = NULL, *val; + argDef *sad; + + /* + * If the type names are already known then check that this is one + * of them. + */ + if (known == NULL) + nam = scopedNameTail(pad->u.snd); + else if (pad->u.snd->next == NULL) + { + int k; + + for (k = 0; k < known->nrArgs; ++k) + { + /* Skip base types. */ + if (known->args[k].atype != defined_type) + continue; + + if (strcmp(pad->u.snd->name, known->args[k].u.snd->name) == 0) + { + nam = pad->u.snd->name; + break; + } + } + } + + if (nam == NULL) + continue; + + /* Add the name. */ + appendScopedName(names, text2scopePart(nam)); + + /* + * Add the corresponding value. For defined types we don't want + * any indirection or references. + */ + sad = &src->args[a]; + + if (sad->atype == defined_type) + val = scopedNameToString(sad->u.snd); + else + val = type2string(sad); + + appendScopedName(values, text2scopePart(val)); + } + else if (pad->atype == template_type) + { + argDef *sad = &src->args[a]; + + /* These checks shouldn't be necessary, but... */ + if (sad->atype == template_type && pad->u.td->types.nrArgs == sad->u.td->types.nrArgs) + appendTypeStrings(ename, &pad->u.td->types, &sad->u.td->types, known, names, values); + } + } +} + + +/* + * Convert a type to a string on the heap. The string will use the minimum + * whitespace while still remaining valid C++. + */ +static char *type2string(argDef *ad) +{ + int i, on_heap = FALSE; + int nr_derefs = ad->nrderefs; + int is_reference = isReference(ad); + char *s; + + /* Use the original type if possible. */ + if (ad->original_type != NULL && !noTypeName(ad->original_type)) + { + s = scopedNameToString(ad->original_type->fqname); + on_heap = TRUE; + + nr_derefs -= ad->original_type->type.nrderefs; + + if (isReference(&ad->original_type->type)) + is_reference = FALSE; + } + else + switch (ad->atype) + { + case template_type: + { + templateDef *td = ad->u.td; + + s = scopedNameToString(td->fqname); + append(&s, "<"); + + for (i = 0; i < td->types.nrArgs; ++i) + { + char *sub_type = type2string(&td->types.args[i]); + + if (i > 0) + append(&s, ","); + + append(&s, sub_type); + free(sub_type); + } + + if (s[strlen(s) - 1] == '>') + append(&s, " >"); + else + append(&s, ">"); + + on_heap = TRUE; + break; + } + + case struct_type: + s = scopedNameToString(ad->u.sname); + on_heap = TRUE; + break; + + case defined_type: + s = scopedNameToString(ad->u.snd); + on_heap = TRUE; + break; + + case ustring_type: + s = "unsigned char"; + break; + + case ascii_string_type: + case latin1_string_type: + case utf8_string_type: + case string_type: + s = "char"; + break; + + case sstring_type: + s = "signed char"; + break; + + case wstring_type: + s = "wchar_t"; + break; + + case ushort_type: + s = "unsigned short"; + break; + + case short_type: + s = "short"; + break; + + case uint_type: + s = "unsigned int"; + break; + + case int_type: + case cint_type: + s = "int"; + break; + + case ulong_type: + s = "unsigned long"; + break; + + case long_type: + s = "long"; + break; + + case ulonglong_type: + s = "unsigned long long"; + break; + + case longlong_type: + s = "long long"; + break; + + case float_type: + case cfloat_type: + s = "float"; + break; + + case double_type: + case cdouble_type: + s = "double"; + break; + + case bool_type: + case cbool_type: + s = "bool"; + break; + + default: + fatal("Unsupported type argument to type2string(): %d\n", ad->atype); + } + + /* Make sure the string is on the heap. */ + if (!on_heap) + s = sipStrdup(s); + + while (nr_derefs-- > 0) + append(&s, "*"); + + if (is_reference) + append(&s, "&"); + + return s; +} + + +/* + * Convert a scoped name to a string on the heap. + */ +static char *scopedNameToString(scopedNameDef *name) +{ + static const char scope_string[] = "::"; + size_t len; + scopedNameDef *snd; + char *s, *dp; + + /* Work out the length of buffer needed. */ + len = 0; + + for (snd = name; snd != NULL; snd = snd->next) + { + len += strlen(snd->name); + + if (snd->next != NULL) + { + /* Ignore the encoded part of template names. */ + if (isdigit(snd->next->name[0])) + break; + + len += strlen(scope_string); + } + } + + /* Allocate and populate the buffer. */ + dp = s = sipMalloc(len + 1); + + for (snd = name; snd != NULL; snd = snd->next) + { + strcpy(dp, snd->name); + dp += strlen(snd->name); + + if (snd->next != NULL) + { + /* Ignore the encoded part of template names. */ + if (isdigit(snd->next->name[0])) + break; + + strcpy(dp, scope_string); + dp += strlen(scope_string); + } + } + + return s; +} + + +/* + * Instantiate a class template. + */ +static void instantiateClassTemplate(sipSpec *pt, moduleDef *mod, + classDef *scope, scopedNameDef *fqname, classTmplDef *tcd, + templateDef *td) +{ + scopedNameDef *type_names, *type_values; + classDef *cd; + ctorDef *oct, **cttail; + argDef *ad; + ifaceFileList *iffl, **used; + + type_names = type_values = NULL; + appendTypeStrings(classFQCName(tcd->cd), &tcd->sig, &td->types, NULL, &type_names, &type_values); + + /* + * Add a mapping from the template name to the instantiated name. If we + * have got this far we know there is room for it. + */ + ad = &tcd->sig.args[tcd->sig.nrArgs++]; + memset(ad, 0, sizeof (argDef)); + ad->atype = defined_type; + ad->u.snd = classFQCName(tcd->cd); + + appendScopedName(&type_names, text2scopePart(scopedNameTail(classFQCName(tcd->cd)))); + appendScopedName(&type_values, text2scopePart(scopedNameToString(fqname))); + + /* Create the new class. */ + cd = sipMalloc(sizeof (classDef)); + + /* Start with a shallow copy. */ + *cd = *tcd->cd; + + resetIsTemplateClass(cd); + cd->pyname = cacheName(pt, scopedNameTail(fqname)); + cd->td = td; + + /* Handle the interface file. */ + cd->iff = findIfaceFile(pt, mod, fqname, class_iface, + (scope != NULL ? scope->iff->api_range : NULL), NULL); + cd->iff->module = mod; + + /* Make a copy of the used list and add the enclosing scope. */ + used = &cd->iff->used; + + for (iffl = tcd->cd->iff->used; iffl != NULL; iffl = iffl->next) + addToUsedList(used, iffl->iff); + + /* Include any scope header code. */ + if (scope != NULL) + appendCodeBlock(&cd->iff->hdrcode, scope->iff->hdrcode); + + if (inMainModule()) + { + setIsUsedName(cd->iff->name); + setIsUsedName(cd->pyname); + } + + cd->ecd = currentScope(); + + /* Handle the enums. */ + instantiateTemplateEnums(pt, tcd, td, cd, used, type_names, type_values); + + /* Handle the variables. */ + instantiateTemplateVars(pt, tcd, td, cd, used, type_names, type_values); + + /* Handle the ctors. */ + cd->ctors = NULL; + cttail = &cd->ctors; + + for (oct = tcd->cd->ctors; oct != NULL; oct = oct->next) + { + ctorDef *nct = sipMalloc(sizeof (ctorDef)); + + /* Start with a shallow copy. */ + *nct = *oct; + + templateSignature(&nct->pysig, FALSE, tcd, td, cd); + + if (oct->cppsig == NULL) + nct->cppsig = NULL; + else if (oct->cppsig == &oct->pysig) + nct->cppsig = &nct->pysig; + else + { + nct->cppsig = sipMalloc(sizeof (signatureDef)); + + *nct->cppsig = *oct->cppsig; + + templateSignature(nct->cppsig, FALSE, tcd, td, cd); + } + + nct->methodcode = templateCode(pt, used, nct->methodcode, type_names, type_values); + + nct->next = NULL; + *cttail = nct; + cttail = &nct->next; + + /* Handle the default ctor. */ + if (tcd->cd->defctor == oct) + cd->defctor = nct; + } + + cd->dealloccode = templateCode(pt, used, cd->dealloccode, type_names, type_values); + cd->dtorcode = templateCode(pt, used, cd->dtorcode, type_names, type_values); + + /* Handle the methods. */ + cd->members = instantiateTemplateMethods(tcd->cd->members, mod); + cd->overs = instantiateTemplateOverloads(pt, tcd->cd->overs, + tcd->cd->members, cd->members, tcd, td, cd, used, type_names, + type_values); + + cd->cppcode = templateCode(pt, used, cd->cppcode, type_names, type_values); + cd->iff->hdrcode = templateCode(pt, used, cd->iff->hdrcode, type_names, type_values); + cd->convtosubcode = templateCode(pt, used, cd->convtosubcode, type_names, type_values); + cd->convtocode = templateCode(pt, used, cd->convtocode, type_names, type_values); + cd->travcode = templateCode(pt, used, cd->travcode, type_names, type_values); + cd->clearcode = templateCode(pt, used, cd->clearcode, type_names, type_values); + cd->getbufcode = templateCode(pt, used, cd->getbufcode, type_names, type_values); + cd->releasebufcode = templateCode(pt, used, cd->releasebufcode, type_names, type_values); + cd->readbufcode = templateCode(pt, used, cd->readbufcode, type_names, type_values); + cd->writebufcode = templateCode(pt, used, cd->writebufcode, type_names, type_values); + cd->segcountcode = templateCode(pt, used, cd->segcountcode, type_names, type_values); + cd->charbufcode = templateCode(pt, used, cd->charbufcode, type_names, type_values); + cd->picklecode = templateCode(pt, used, cd->picklecode, type_names, type_values); + cd->next = pt->classes; + + pt->classes = cd; + + tcd->sig.nrArgs--; + + freeScopedName(type_names); + freeScopedName(type_values); +} + + +/* + * Instantiate the methods of a template class. + */ +static memberDef *instantiateTemplateMethods(memberDef *tmd, moduleDef *mod) +{ + memberDef *md, *methods, **mdtail; + + methods = NULL; + mdtail = &methods; + + for (md = tmd; md != NULL; md = md->next) + { + memberDef *nmd = sipMalloc(sizeof (memberDef)); + + /* Start with a shallow copy. */ + *nmd = *md; + + nmd->module = mod; + + if (inMainModule()) + setIsUsedName(nmd->pyname); + + nmd->next = NULL; + *mdtail = nmd; + mdtail = &nmd->next; + } + + return methods; +} + + +/* + * Instantiate the overloads of a template class. + */ +static overDef *instantiateTemplateOverloads(sipSpec *pt, overDef *tod, + memberDef *tmethods, memberDef *methods, classTmplDef *tcd, + templateDef *td, classDef *cd, ifaceFileList **used, + scopedNameDef *type_names, scopedNameDef *type_values) +{ + overDef *od, *overloads, **odtail; + + overloads = NULL; + odtail = &overloads; + + for (od = tod; od != NULL; od = od->next) + { + overDef *nod = sipMalloc(sizeof (overDef)); + memberDef *nmd, *omd; + + /* Start with a shallow copy. */ + *nod = *od; + + for (nmd = methods, omd = tmethods; omd != NULL; omd = omd->next, nmd = nmd->next) + if (omd == od->common) + { + nod->common = nmd; + break; + } + + templateSignature(&nod->pysig, TRUE, tcd, td, cd); + + if (od->cppsig == &od->pysig) + nod->cppsig = &nod->pysig; + else + { + nod->cppsig = sipMalloc(sizeof (signatureDef)); + + *nod->cppsig = *od->cppsig; + + templateSignature(nod->cppsig, TRUE, tcd, td, cd); + } + + nod->methodcode = templateCode(pt, used, nod->methodcode, type_names, type_values); + + /* Handle any virtual handler. */ + if (od->virthandler != NULL) + { + moduleDef *mod = cd->iff->module; + + nod->virthandler = sipMalloc(sizeof (virtHandlerDef)); + + /* Start with a shallow copy. */ + *nod->virthandler = *od->virthandler; + + if (od->virthandler->cppsig == &od->pysig) + nod->virthandler->cppsig = &nod->pysig; + else + { + nod->virthandler->cppsig = sipMalloc(sizeof (signatureDef)); + + *nod->virthandler->cppsig = *od->virthandler->cppsig; + + templateSignature(nod->virthandler->cppsig, TRUE, tcd, td, cd); + } + + nod->virthandler->module = mod; + nod->virthandler->virtcode = templateCode(pt, used, nod->virthandler->virtcode, type_names, type_values); + nod->virthandler->next = mod->virthandlers; + + mod->virthandlers = nod->virthandler; + } + + nod->next = NULL; + *odtail = nod; + odtail = &nod->next; + } + + return overloads; +} + + +/* + * Instantiate the enums of a template class. + */ +static void instantiateTemplateEnums(sipSpec *pt, classTmplDef *tcd, + templateDef *td, classDef *cd, ifaceFileList **used, + scopedNameDef *type_names, scopedNameDef *type_values) +{ + enumDef *ted; + moduleDef *mod = cd->iff->module; + + for (ted = pt->enums; ted != NULL; ted = ted->next) + if (ted->ecd == tcd->cd) + { + enumDef *ed; + enumMemberDef *temd; + + ed = sipMalloc(sizeof (enumDef)); + + /* Start with a shallow copy. */ + *ed = *ted; + + if (ed->fqcname != NULL) + { + ed->fqcname = text2scopedName(cd->iff, + scopedNameTail(ed->fqcname)); + ed->cname = cacheName(pt, scopedNameToString(ed->fqcname)); + } + + if (inMainModule()) + { + if (ed->pyname != NULL) + setIsUsedName(ed->pyname); + + if (ed->cname != NULL) + setIsUsedName(ed->cname); + } + + ed->ecd = cd; + ed->first_alt = ed; + ed->module = mod; + ed->members = NULL; + + for (temd = ted->members; temd != NULL; temd = temd->next) + { + enumMemberDef *emd; + + emd = sipMalloc(sizeof (enumMemberDef)); + + /* Start with a shallow copy. */ + *emd = *temd; + emd->ed = ed; + + emd->next = ed->members; + ed->members = emd; + } + + ed->slots = instantiateTemplateMethods(ted->slots, mod); + ed->overs = instantiateTemplateOverloads(pt, ted->overs, + ted->slots, ed->slots, tcd, td, cd, used, type_names, + type_values); + + ed->next = pt->enums; + pt->enums = ed; + } +} + + +/* + * Instantiate the variables of a template class. + */ +static void instantiateTemplateVars(sipSpec *pt, classTmplDef *tcd, + templateDef *td, classDef *cd, ifaceFileList **used, + scopedNameDef *type_names, scopedNameDef *type_values) +{ + varDef *tvd; + + for (tvd = pt->vars; tvd != NULL; tvd = tvd->next) + if (tvd->ecd == tcd->cd) + { + varDef *vd; + + vd = sipMalloc(sizeof (varDef)); + + /* Start with a shallow copy. */ + *vd = *tvd; + + if (inMainModule()) + setIsUsedName(vd->pyname); + + vd->fqcname = text2scopedName(cd->iff, + scopedNameTail(vd->fqcname)); + vd->ecd = cd; + vd->module = cd->iff->module; + + templateType(&vd->type, tcd, td, cd); + + vd->accessfunc = templateCode(pt, used, vd->accessfunc, type_names, type_values); + vd->getcode = templateCode(pt, used, vd->getcode, type_names, type_values); + vd->setcode = templateCode(pt, used, vd->setcode, type_names, type_values); + + addVariable(pt, vd); + } +} + + +/* + * Replace any template arguments in a signature. + */ +static void templateSignature(signatureDef *sd, int result, classTmplDef *tcd, templateDef *td, classDef *ncd) +{ + int a; + + if (result) + templateType(&sd->result, tcd, td, ncd); + + for (a = 0; a < sd->nrArgs; ++a) + templateType(&sd->args[a], tcd, td, ncd); +} + + +/* + * Replace any template arguments in a type. + */ +static void templateType(argDef *ad, classTmplDef *tcd, templateDef *td, classDef *ncd) +{ + int a; + char *name; + + /* Descend into any sub-templates. */ + if (ad->atype == template_type) + { + templateDef *new_td = sipMalloc(sizeof (templateDef)); + + /* Make a deep copy of the template definition. */ + *new_td = *ad->u.td; + ad->u.td = new_td; + + templateSignature(&ad->u.td->types, FALSE, tcd, td, ncd); + + return; + } + + /* Ignore if it isn't an unscoped name. */ + if (ad->atype != defined_type || ad->u.snd->next != NULL) + return; + + name = ad->u.snd->name; + + for (a = 0; a < tcd->sig.nrArgs - 1; ++a) + if (strcmp(name, scopedNameTail(tcd->sig.args[a].u.snd)) == 0) + { + argDef *tad = &td->types.args[a]; + + ad->atype = tad->atype; + + /* We take the constrained flag from the real type. */ + resetIsConstrained(ad); + + if (isConstrained(tad)) + setIsConstrained(ad); + + ad->u = tad->u; + + return; + } + + /* Handle the class name itself. */ + if (strcmp(name, scopedNameTail(classFQCName(tcd->cd))) == 0) + { + ad->atype = class_type; + ad->u.cd = ncd; + ad->original_type = NULL; + } +} + + +/* + * Replace any template arguments in a literal code block. + */ +codeBlock *templateCode(sipSpec *pt, ifaceFileList **used, codeBlock *ocb, + scopedNameDef *names, scopedNameDef *values) +{ + codeBlock *ncb = NULL, **tail = &ncb; + + while (ocb != NULL) + { + char *at = ocb->frag; + + do + { + char *first = NULL; + codeBlock *cb; + scopedNameDef *nam, *val, *nam_first, *val_first; + + /* + * Go through the rest of this fragment looking for each of the + * types and the name of the class itself. + */ + nam = names; + val = values; + + while (nam != NULL && val != NULL) + { + char *cp; + + if ((cp = strstr(at, nam->name)) != NULL) + if (first == NULL || first > cp) + { + nam_first = nam; + val_first = val; + first = cp; + } + + nam = nam->next; + val = val->next; + } + + /* Create the new fragment. */ + cb = sipMalloc(sizeof (codeBlock)); + + if (at == ocb->frag) + { + cb->filename = ocb->filename; + cb->linenr = ocb->linenr; + } + else + cb->filename = NULL; + + cb->next = NULL; + *tail = cb; + tail = &cb->next; + + /* See if anything was found. */ + if (first == NULL) + { + /* We can just point to this. */ + cb->frag = at; + + /* All done with this one. */ + at = NULL; + } + else + { + static char *gen_names[] = { + "sipType_", + "sipClass_", + "sipEnum_", + "sipException_", + NULL + }; + + char *dp, *sp, **gn; + int genname = FALSE; + + /* + * If the context in which the text is used is in the name of a + * SIP generated object then translate any "::" scoping to "_". + */ + for (gn = gen_names; *gn != NULL; ++gn) + if (search_back(first, at, *gn)) + { + addUsedFromCode(pt, used, val_first->name); + genname = TRUE; + break; + } + + /* Fragment the fragment. */ + cb->frag = sipMalloc(first - at + strlen(val_first->name) + 1); + + strncpy(cb->frag, at, first - at); + + dp = &cb->frag[first - at]; + sp = val_first->name; + + if (genname) + { + char gch; + + while ((gch = *sp++) != '\0') + if (gch == ':' && *sp == ':') + { + *dp++ = '_'; + ++sp; + } + else + *dp++ = gch; + + *dp = '\0'; + } + else + strcpy(dp, sp); + + /* Move past the replaced text. */ + at = first + strlen(nam_first->name); + } + } + while (at != NULL && *at != '\0'); + + ocb = ocb->next; + } + + return ncb; +} + + +/* + * Return TRUE if the text at the end of a string matches the target string. + */ +static int search_back(const char *end, const char *start, const char *target) +{ + size_t tlen = strlen(target); + + if (start + tlen >= end) + return FALSE; + + return (strncmp(end - tlen, target, tlen) == 0); +} + + +/* + * Add any needed interface files based on handwritten code. + */ +static void addUsedFromCode(sipSpec *pt, ifaceFileList **used, const char *sname) +{ + ifaceFileDef *iff; + enumDef *ed; + + for (iff = pt->ifacefiles; iff != NULL; iff = iff->next) + { + if (iff->type != class_iface && iff->type != exception_iface) + continue; + + if (sameName(iff->fqcname, sname)) + { + addToUsedList(used, iff); + return; + } + } + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + if (ed->ecd == NULL) + continue; + + if (sameName(ed->fqcname, sname)) + { + addToUsedList(used, ed->ecd->iff); + return; + } + } +} + + +/* + * Compare a scoped name with its string equivalent. + */ +static int sameName(scopedNameDef *snd, const char *sname) +{ + while (snd != NULL && *sname != '\0') + { + const char *sp = snd->name; + + while (*sp != '\0' && *sname != ':' && *sname != '\0') + if (*sp++ != *sname++) + return FALSE; + + if (*sp != '\0' || (*sname != ':' && *sname != '\0')) + return FALSE; + + snd = snd->next; + + if (*sname == ':') + sname += 2; + } + + return (snd == NULL && *sname == '\0'); +} + + +/* + * Compare a (possibly) relative scoped name with a fully qualified scoped name + * while taking the current scope into account. + */ +static int foundInScope(scopedNameDef *fq_name, scopedNameDef *rel_name) +{ + classDef *scope; + + for (scope = currentScope(); scope != NULL; scope = scope->ecd) + { + scopedNameDef *snd; + int found; + + snd = copyScopedName(classFQCName(scope)); + appendScopedName(&snd, copyScopedName(rel_name)); + + found = (compareScopedNames(fq_name, snd) == 0); + + freeScopedName(snd); + + if (found) + return TRUE; + } + + return compareScopedNames(fq_name, rel_name) == 0; +} + + +/* + * Create a new typedef. + */ +static void newTypedef(sipSpec *pt, moduleDef *mod, char *name, argDef *type, + optFlags *optflgs) +{ + typedefDef *td, **tdp; + scopedNameDef *fqname; + classDef *scope; + + scope = currentScope(); + fqname = text2scopedName((scope != NULL ? scope->iff : NULL), name); + + /* See if we are instantiating a template class. */ + if (type->atype == template_type) + { + classTmplDef *tcd; + templateDef *td = type->u.td; + + for (tcd = pt->classtemplates; tcd != NULL; tcd = tcd->next) + if (foundInScope(tcd->cd->iff->fqcname, td->fqname) && + sameTemplateSignature(&tcd->sig, &td->types, FALSE)) + { + instantiateClassTemplate(pt, mod, scope, fqname, tcd, td); + + /* All done. */ + return; + } + } + + /* + * Check it doesn't already exist and find the position in the sorted list + * where it should be put. + */ + for (tdp = &pt->typedefs; *tdp != NULL; tdp = &(*tdp)->next) + { + int res = compareScopedNames((*tdp)->fqname, fqname); + + if (res == 0) + { + fatalScopedName(fqname); + fatal(" already defined\n"); + } + + if (res > 0) + break; + } + + td = sipMalloc(sizeof (typedefDef)); + + td->tdflags = 0; + td->fqname = fqname; + td->ecd = scope; + td->module = mod; + td->type = *type; + + td->next = *tdp; + *tdp = td; + + if (findOptFlag(optflgs, "NoTypeName", bool_flag) != NULL) + setNoTypeName(td); + + mod->nrtypedefs++; +} + + +/* + * Speculatively try and resolve any typedefs. In some cases (eg. when + * comparing template signatures) it helps to use the real type if it is known. + * Note that this wouldn't be necessary if we required that all types be known + * before they are used. + */ +static void resolveAnyTypedef(sipSpec *pt, argDef *ad) +{ + argDef orig = *ad; + + while (ad->atype == defined_type) + { + ad->atype = no_type; + searchTypedefs(pt, ad->u.snd, ad); + + /* + * Don't resolve to a template type as it may be superceded later on + * by a more specific mapped type. + */ + if (ad->atype == no_type || ad->atype == template_type) + { + *ad = orig; + break; + } + } +} + + +/* + * Return TRUE if the template signatures are the same. A deep comparison is + * used for mapped type templates where we want to recurse into any nested + * templates. + */ +int sameTemplateSignature(signatureDef *tmpl_sd, signatureDef *args_sd, + int deep) +{ + int a; + + if (tmpl_sd->nrArgs != args_sd->nrArgs) + return FALSE; + + for (a = 0; a < tmpl_sd->nrArgs; ++a) + { + argDef *tmpl_ad = &tmpl_sd->args[a]; + argDef *args_ad = &args_sd->args[a]; + + /* + * If we are doing a shallow comparision (ie. for class templates) then + * a type name in the template signature matches anything in the + * argument signature. + */ + if (tmpl_ad->atype == defined_type && !deep) + continue; + + /* + * For type names only compare the references and pointers, and do the + * same for any nested templates. + */ + if (tmpl_ad->atype == defined_type && args_ad->atype == defined_type) + { + if (isReference(tmpl_ad) != isReference(args_ad) || tmpl_ad->nrderefs != args_ad->nrderefs) + return FALSE; + } + else if (tmpl_ad->atype == template_type && args_ad->atype == template_type) + { + if (!sameTemplateSignature(&tmpl_ad->u.td->types, &args_ad->u.td->types, deep)) + return FALSE; + } + else if (!sameBaseType(tmpl_ad, args_ad)) + return FALSE; + } + + return TRUE; +} + + +/* + * Create a new variable. + */ +static void newVar(sipSpec *pt,moduleDef *mod,char *name,int isstatic, + argDef *type,optFlags *of,codeBlock *acode,codeBlock *gcode, + codeBlock *scode) +{ + varDef *var; + classDef *escope = currentScope(); + nameDef *nd = cacheName(pt,getPythonName(of,name)); + + if (inMainModule()) + setIsUsedName(nd); + + checkAttributes(pt, mod, escope, NULL, nd->text, FALSE); + + var = sipMalloc(sizeof (varDef)); + + var->pyname = nd; + var->fqcname = text2scopedName((escope != NULL ? escope->iff : NULL), + name); + var->ecd = escope; + var->module = mod; + var->varflags = 0; + var->type = *type; + var->accessfunc = acode; + var->getcode = gcode; + var->setcode = scode; + + if (isstatic || (escope != NULL && escope->iff->type == namespace_iface)) + setIsStaticVar(var); + + addVariable(pt, var); +} + + +/* + * Create a new ctor. + */ +static void newCtor(char *name, int sectFlags, signatureDef *args, + optFlags *optflgs, codeBlock *methodcode, throwArgs *exceptions, + signatureDef *cppsig, int explicit, codeBlock *docstring) +{ + ctorDef *ct, **ctp; + classDef *cd = currentScope(); + + /* Check the name of the constructor. */ + if (strcmp(classBaseName(cd), name) != 0) + yyerror("Constructor doesn't have the same name as its class"); + + if (docstring != NULL) + appendCodeBlock(&cd->docstring, docstring); + + /* Add to the list of constructors. */ + ct = sipMalloc(sizeof (ctorDef)); + + if (sectFlags & SECT_IS_PROT && makeProtPublic) + { + sectFlags &= ~SECT_IS_PROT; + sectFlags |= SECT_IS_PUBLIC; + } + + /* Allow the signature to be used like an function signature. */ + memset(&args->result, 0, sizeof (argDef)); + args->result.atype = void_type; + + ct->ctorflags = sectFlags; + ct->api_range = getAPIRange(optflgs); + ct->pysig = *args; + ct->cppsig = (cppsig != NULL ? cppsig : &ct->pysig); + ct->exceptions = exceptions; + ct->methodcode = methodcode; + + if (!isPrivateCtor(ct)) + setCanCreate(cd); + + if (isProtectedCtor(ct)) + setHasShadow(cd); + + if (explicit) + setIsExplicitCtor(ct); + + getHooks(optflgs, &ct->prehook, &ct->posthook); + + if (getReleaseGIL(optflgs)) + setIsReleaseGILCtor(ct); + else if (getHoldGIL(optflgs)) + setIsHoldGILCtor(ct); + + if (getTransfer(optflgs)) + setIsResultTransferredCtor(ct); + + if (getDeprecated(optflgs)) + setIsDeprecatedCtor(ct); + + if (!isPrivateCtor(ct) && usesKeywordArgs(optflgs, &ct->pysig)) + setUseKeywordArgsCtor(ct); + + if (findOptFlag(optflgs, "NoDerived", bool_flag) != NULL) + { + if (cppsig != NULL) + yyerror("The /NoDerived/ annotation cannot be used with a C++ signature"); + + if (methodcode == NULL) + yyerror("The /NoDerived/ annotation must be used with %MethodCode"); + + ct->cppsig = NULL; + } + + if (findOptFlag(optflgs, "Default", bool_flag) != NULL) + { + if (cd->defctor != NULL) + yyerror("A constructor with the /Default/ annotation has already been defined"); + + cd->defctor = ct; + } + + /* Append to the list. */ + for (ctp = &cd->ctors; *ctp != NULL; ctp = &(*ctp)->next) + ; + + *ctp = ct; +} + + +/* + * Create a new function. + */ +static void newFunction(sipSpec *pt, moduleDef *mod, classDef *c_scope, + mappedTypeDef *mt_scope, int sflags, int isstatic, int issignal, + int isslot, int isvirt, char *name, signatureDef *sig, int isconst, + int isabstract, optFlags *optflgs, codeBlock *methodcode, + codeBlock *vcode, throwArgs *exceptions, signatureDef *cppsig, + codeBlock *docstring) +{ + int factory, xferback, no_arg_parser; + overDef *od, **odp, **headp; + optFlag *of; + virtHandlerDef *vhd; + + /* Extra checks for a C module. */ + if (pt->genc) + { + if (c_scope != NULL) + yyerror("Function declaration not allowed in a struct in a C module"); + + if (isstatic) + yyerror("Static functions not allowed in a C module"); + + if (exceptions != NULL) + yyerror("Exceptions not allowed in a C module"); + } + + if (mt_scope != NULL) + headp = &mt_scope->overs; + else if (c_scope != NULL) + headp = &c_scope->overs; + else + headp = &mod->overs; + + /* See if it is a factory method. */ + if (findOptFlag(optflgs, "Factory", bool_flag) != NULL) + factory = TRUE; + else + { + int a; + + factory = FALSE; + + /* Check /TransferThis/ wasn't specified. */ + if (c_scope == NULL || isstatic) + for (a = 0; a < sig->nrArgs; ++a) + if (isThisTransferred(&sig->args[a])) + yyerror("/TransferThis/ may only be specified in constructors and class methods"); + } + + /* See if the result is to be returned to Python ownership. */ + xferback = (findOptFlag(optflgs, "TransferBack", bool_flag) != NULL); + + if (factory && xferback) + yyerror("/TransferBack/ and /Factory/ cannot both be specified"); + + /* Create a new overload definition. */ + + od = sipMalloc(sizeof (overDef)); + + /* Set the overload flags. */ + + if ((sflags & SECT_IS_PROT) && makeProtPublic) + { + sflags &= ~SECT_IS_PROT; + sflags |= SECT_IS_PUBLIC | OVER_REALLY_PROT; + } + + od->overflags = sflags; + + if (issignal) + { + resetIsSlot(od); + setIsSignal(od); + } + else if (isslot) + { + resetIsSignal(od); + setIsSlot(od); + } + + if (factory) + setIsFactory(od); + + if (xferback) + setIsResultTransferredBack(od); + + if (getTransfer(optflgs)) + setIsResultTransferred(od); + + if (findOptFlag(optflgs, "TransferThis", bool_flag) != NULL) + setIsThisTransferredMeth(od); + + if (isProtected(od)) + setHasShadow(c_scope); + + if ((isSlot(od) || isSignal(od)) && !isPrivate(od)) + { + if (isSignal(od)) + setHasShadow(c_scope); + + pt->sigslots = TRUE; + } + + if (isSignal(od) && (methodcode != NULL || vcode != NULL)) + yyerror("Cannot provide code for signals"); + + if (isstatic) + { + if (isSignal(od)) + yyerror("Static functions cannot be signals"); + + if (isvirt) + yyerror("Static functions cannot be virtual"); + + setIsStatic(od); + } + + if (isconst) + setIsConst(od); + + if (isabstract) + { + if (sflags == 0) + yyerror("Non-class function specified as abstract"); + + setIsAbstract(od); + } + + if ((of = findOptFlag(optflgs, "AutoGen", opt_name_flag)) != NULL) + { + if (of->fvalue.sval == NULL || isEnabledFeature(of->fvalue.sval)) + setIsAutoGen(od); + } + + if (isvirt) + { + if (isSignal(od) && pluginPyQt3(pt)) + yyerror("Virtual signals aren't supported"); + + setIsVirtual(od); + setHasShadow(c_scope); + + vhd = sipMalloc(sizeof (virtHandlerDef)); + + vhd->virthandlernr = -1; + vhd->vhflags = 0; + vhd->pysig = &od->pysig; + vhd->cppsig = (cppsig != NULL ? cppsig : &od->pysig); + vhd->virtcode = vcode; + + if (factory || xferback) + setIsTransferVH(vhd); + + /* + * Only add it to the module's virtual handlers if we are not in a + * class template. + */ + if (!currentIsTemplate) + { + vhd->module = mod; + + vhd->next = mod->virthandlers; + mod->virthandlers = vhd; + } + } + else + { + if (vcode != NULL) + yyerror("%VirtualCatcherCode provided for non-virtual function"); + + vhd = NULL; + } + + od->cppname = name; + od->pysig = *sig; + od->cppsig = (cppsig != NULL ? cppsig : &od->pysig); + od->exceptions = exceptions; + od->methodcode = methodcode; + od->virthandler = vhd; + + no_arg_parser = (findOptFlag(optflgs, "NoArgParser", bool_flag) != NULL); + + if (no_arg_parser) + { + if (methodcode == NULL) + yyerror("%MethodCode must be supplied if /NoArgParser/ is specified"); + } + + if (findOptFlag(optflgs, "NoCopy", bool_flag) != NULL) + setNoCopy(&od->pysig.result); + + od->common = findFunction(pt, mod, c_scope, mt_scope, + getPythonName(optflgs, name), (methodcode != NULL), sig->nrArgs, + no_arg_parser); + + if (docstring != NULL) + appendCodeBlock(&od->common->docstring, docstring); + + od->api_range = getAPIRange(optflgs); + + if (od->api_range == NULL) + setNotVersioned(od->common); + + if (findOptFlag(optflgs, "Numeric", bool_flag) != NULL) + setIsNumeric(od->common); + + /* Methods that run in new threads must be virtual. */ + if (findOptFlag(optflgs, "NewThread", bool_flag) != NULL) + { + argDef *res; + + if (!isvirt) + yyerror("/NewThread/ may only be specified for virtual functions"); + + /* + * This is an arbitary limitation to make the code generator slightly + * easier - laziness on my part. + */ + res = &od->cppsig->result; + + if (res->atype != void_type || res->nrderefs != 0) + yyerror("/NewThread/ may only be specified for void functions"); + + setIsNewThread(od); + } + + getHooks(optflgs, &od->prehook, &od->posthook); + + if (getReleaseGIL(optflgs)) + setIsReleaseGIL(od); + else if (getHoldGIL(optflgs)) + setIsHoldGIL(od); + + if (getDeprecated(optflgs)) + setIsDeprecated(od); + + if (!isPrivate(od) && !isSignal(od) && od->common->slot == no_slot && usesKeywordArgs(optflgs, &od->pysig)) + { + setUseKeywordArgs(od); + setUseKeywordArgsFunction(od->common); + } + + /* See if we want to auto-generate a __len__() method. */ + if (findOptFlag(optflgs, "__len__", bool_flag) != NULL) + { + overDef *len; + + len = sipMalloc(sizeof (overDef)); + + len->cppname = "__len__"; + len->overflags = SECT_IS_PUBLIC; + len->pysig.result.atype = ssize_type; + len->pysig.nrArgs = 0; + len->cppsig = &len->pysig; + + len->common = findFunction(pt, mod, c_scope, mt_scope, len->cppname, + TRUE, 0, FALSE); + + if ((len->methodcode = od->methodcode) == NULL) + { + char *buf = sipStrdup(" sipRes = (SIP_SSIZE_T)sipCpp->"); + codeBlock *code; + + append(&buf, od->cppname); + append(&buf, "();\n"); + + code = sipMalloc(sizeof (codeBlock)); + + code->frag = buf; + code->filename = "Auto-generated"; + code->linenr = 0; + code->next = NULL; + + len->methodcode = code; + } + + len->next = NULL; + + od->next = len; + } + else + { + od->next = NULL; + } + + /* Append to the list. */ + for (odp = headp; *odp != NULL; odp = &(*odp)->next) + ; + + *odp = od; +} + + +/* + * Return the Python name based on the C/C++ name and any /PyName/ annotation. + */ +static const char *getPythonName(optFlags *optflgs, const char *cname) +{ + const char *pname; + optFlag *of; + + if ((of = findOptFlag(optflgs, "PyName", name_flag)) != NULL) + pname = of->fvalue.sval; + else + pname = cname; + + return pname; +} + + +/* + * Cache a name in a module. Entries in the cache are stored in order of + * decreasing length. + */ +nameDef *cacheName(sipSpec *pt, const char *name) +{ + nameDef *nd, **ndp; + size_t len; + + /* Allow callers to be lazy about checking if there is really a name. */ + if (name == NULL) + return NULL; + + /* Skip entries that are too large. */ + ndp = &pt->namecache; + len = strlen(name); + + while (*ndp != NULL && (*ndp)->len > len) + ndp = &(*ndp)->next; + + /* Check entries that are the right length. */ + for (nd = *ndp; nd != NULL && nd->len == len; nd = nd->next) + if (memcmp(nd->text, name, len) == 0) + return nd; + + /* Create a new one. */ + nd = sipMalloc(sizeof (nameDef)); + + nd->nameflags = 0; + nd->text = name; + nd->len = len; + nd->next = *ndp; + + *ndp = nd; + + return nd; +} + + +/* + * Find (or create) an overloaded function name. + */ +static memberDef *findFunction(sipSpec *pt, moduleDef *mod, classDef *c_scope, + mappedTypeDef *mt_scope, const char *pname, int hwcode, int nrargs, + int no_arg_parser) +{ + static struct slot_map { + const char *name; /* The slot name. */ + slotType type; /* The corresponding type. */ + int needs_hwcode; /* Set if handwritten code is required. */ + int nrargs; /* Nr. of arguments. */ + } slot_table[] = { + {"__str__", str_slot, TRUE, 0}, + {"__unicode__", unicode_slot, TRUE, 0}, + {"__int__", int_slot, FALSE, 0}, + {"__long__", long_slot, FALSE, 0}, + {"__float__", float_slot, FALSE, 0}, + {"__len__", len_slot, TRUE, 0}, + {"__contains__", contains_slot, TRUE, 1}, + {"__add__", add_slot, FALSE, 1}, + {"__sub__", sub_slot, FALSE, 1}, + {"__mul__", mul_slot, FALSE, 1}, + {"__div__", div_slot, FALSE, 1}, + {"__mod__", mod_slot, FALSE, 1}, + {"__floordiv__", floordiv_slot, TRUE, 1}, + {"__truediv__", truediv_slot, FALSE, 1}, + {"__and__", and_slot, FALSE, 1}, + {"__or__", or_slot, FALSE, 1}, + {"__xor__", xor_slot, FALSE, 1}, + {"__lshift__", lshift_slot, FALSE, 1}, + {"__rshift__", rshift_slot, FALSE, 1}, + {"__iadd__", iadd_slot, FALSE, 1}, + {"__isub__", isub_slot, FALSE, 1}, + {"__imul__", imul_slot, FALSE, 1}, + {"__idiv__", idiv_slot, FALSE, 1}, + {"__imod__", imod_slot, FALSE, 1}, + {"__ifloordiv__", ifloordiv_slot, TRUE, 1}, + {"__itruediv__", itruediv_slot, FALSE, 1}, + {"__iand__", iand_slot, FALSE, 1}, + {"__ior__", ior_slot, FALSE, 1}, + {"__ixor__", ixor_slot, FALSE, 1}, + {"__ilshift__", ilshift_slot, FALSE, 1}, + {"__irshift__", irshift_slot, FALSE, 1}, + {"__invert__", invert_slot, FALSE, 0}, + {"__call__", call_slot, FALSE, -1}, + {"__getitem__", getitem_slot, FALSE, 1}, + {"__setitem__", setitem_slot, TRUE, 2}, + {"__delitem__", delitem_slot, TRUE, 1}, + {"__lt__", lt_slot, FALSE, 1}, + {"__le__", le_slot, FALSE, 1}, + {"__eq__", eq_slot, FALSE, 1}, + {"__ne__", ne_slot, FALSE, 1}, + {"__gt__", gt_slot, FALSE, 1}, + {"__ge__", ge_slot, FALSE, 1}, + {"__cmp__", cmp_slot, FALSE, 1}, + {"__bool__", bool_slot, TRUE, 0}, + {"__nonzero__", bool_slot, TRUE, 0}, + {"__neg__", neg_slot, FALSE, 0}, + {"__pos__", pos_slot, FALSE, 0}, + {"__abs__", abs_slot, TRUE, 0}, + {"__repr__", repr_slot, TRUE, 0}, + {"__hash__", hash_slot, TRUE, 0}, + {"__index__", index_slot, TRUE, 0}, + {"__iter__", iter_slot, TRUE, 0}, + {"__next__", next_slot, TRUE, 0}, + {NULL} + }; + + memberDef *md, **flist; + struct slot_map *sm; + slotType st; + + /* Get the slot type. */ + st = no_slot; + + for (sm = slot_table; sm->name != NULL; ++sm) + if (strcmp(sm->name, pname) == 0) + { + if (sm->needs_hwcode && !hwcode) + yyerror("This Python slot requires %MethodCode"); + + if (sm->nrargs >= 0) + { + if (mt_scope == NULL && c_scope == NULL) + { + /* Global operators need one extra argument. */ + if (sm -> nrargs + 1 != nrargs) + yyerror("Incorrect number of arguments to global operator"); + } + else if (sm->nrargs != nrargs) + yyerror("Incorrect number of arguments to Python slot"); + } + + st = sm->type; + + break; + } + + /* Check there is no name clash. */ + checkAttributes(pt, mod, c_scope, mt_scope, pname, TRUE); + + /* See if it already exists. */ + if (mt_scope != NULL) + flist = &mt_scope->members; + else if (c_scope != NULL) + flist = &c_scope->members; + else + flist = &mod->othfuncs; + + for (md = *flist; md != NULL; md = md->next) + if (strcmp(md->pyname->text, pname) == 0 && md->module == mod) + break; + + if (md == NULL) + { + /* Create a new one. */ + md = sipMalloc(sizeof (memberDef)); + + md->pyname = cacheName(pt, pname); + md->memberflags = 0; + md->slot = st; + md->module = mod; + md->next = *flist; + + *flist = md; + + if (inMainModule()) + setIsUsedName(md->pyname); + + if (no_arg_parser) + setNoArgParser(md); + } + else if (noArgParser(md)) + yyerror("Another overload has already been defined that is annotated as /NoArgParser/"); + + /* Global operators are a subset. */ + if (mt_scope == NULL && c_scope == NULL && st != no_slot && st != neg_slot && st != pos_slot && !isNumberSlot(md) && !isRichCompareSlot(md)) + yyerror("Global operators must be either numeric or comparison operators"); + + return md; +} + + +/* + * Search a set of flags for a particular one and check its type. + */ +static optFlag *findOptFlag(optFlags *flgs,char *name,flagType ft) +{ + int f; + + for (f = 0; f < flgs -> nrFlags; ++f) + { + optFlag *of = &flgs -> flags[f]; + + if (strcmp(of -> fname,name) == 0) + { + /* + * An optional name can look like a boolean or a name. + */ + + if (ft == opt_name_flag) + { + if (of -> ftype == bool_flag) + { + of -> ftype = opt_name_flag; + of -> fvalue.sval = NULL; + } + else if (of -> ftype == name_flag) + of -> ftype = opt_name_flag; + } + + if (ft != of -> ftype) + yyerror("Optional flag has a value of the wrong type"); + + return of; + } + } + + return NULL; +} + + +/* + * A name is going to be used as a Python attribute name within a Python scope + * (ie. a Python dictionary), so check against what we already know is going in + * the same scope in case there is a clash. + */ +static void checkAttributes(sipSpec *pt, moduleDef *mod, classDef *py_c_scope, + mappedTypeDef *py_mt_scope, const char *attr, int isfunc) +{ + enumDef *ed; + varDef *vd; + classDef *cd; + + /* Check the enums. */ + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + enumMemberDef *emd; + + if (ed->pyname == NULL) + continue; + + if (py_c_scope != NULL) + { + if (ed->ecd != py_c_scope) + continue; + } + else if (py_mt_scope != NULL) + { + if (ed->emtd != py_mt_scope) + continue; + } + else if (ed->ecd != NULL || ed->emtd != NULL) + { + continue; + } + + if (strcmp(ed->pyname->text, attr) == 0) + yyerror("There is already an enum in scope with the same Python name"); + + for (emd = ed->members; emd != NULL; emd = emd->next) + if (strcmp(emd->pyname->text, attr) == 0) + yyerror("There is already an enum member in scope with the same Python name"); + } + + /* + * Only check the members if this attribute isn't a member because we + * can handle members with the same name in the same scope. + */ + if (!isfunc) + { + memberDef *md, *membs; + overDef *overs; + + if (py_mt_scope != NULL) + { + membs = py_mt_scope->members; + overs = py_mt_scope->overs; + } + else if (py_c_scope != NULL) + { + membs = py_c_scope->members; + overs = py_c_scope->overs; + } + else + { + membs = mod->othfuncs; + overs = mod->overs; + } + + for (md = membs; md != NULL; md = md->next) + { + overDef *od; + + if (strcmp(md->pyname->text, attr) != 0) + continue; + + /* Check for a conflict with all overloads. */ + for (od = overs; od != NULL; od = od->next) + { + if (od->common != md) + continue; + + yyerror("There is already a function in scope with the same Python name"); + } + } + } + + /* If the scope was a mapped type then that's all we have to check. */ + if (py_mt_scope != NULL) + return; + + /* Check the variables. */ + for (vd = pt->vars; vd != NULL; vd = vd->next) + { + if (vd->ecd != py_c_scope) + continue; + + if (strcmp(vd->pyname->text,attr) == 0) + yyerror("There is already a variable in scope with the same Python name"); + } + + /* Check the classes. */ + for (cd = pt->classes; cd != NULL; cd = cd->next) + { + if (cd->ecd != py_c_scope || cd->pyname == NULL) + continue; + + if (strcmp(cd->pyname->text, attr) == 0 && !isExternal(cd)) + yyerror("There is already a class or namespace in scope with the same Python name"); + } + + /* Check the exceptions. */ + if (py_c_scope == NULL) + { + exceptionDef *xd; + + for (xd = pt->exceptions; xd != NULL; xd = xd->next) + if (xd->pyname != NULL && strcmp(xd->pyname, attr) == 0) + yyerror("There is already an exception with the same Python name"); + } +} + + +/* + * Append a code block to a list of them. Append is needed to give the + * specifier easy control over the order of the documentation. + */ +void appendCodeBlock(codeBlock **headp, codeBlock *new) +{ + while (*headp != NULL) + headp = &(*headp)->next; + + *headp = new; +} + + +/* + * Handle the end of a fully parsed a file. + */ +static void handleEOF() +{ + /* + * Check that the number of nested if's is the same as when we started + * the file. + */ + + if (skipStackPtr > currentContext.ifdepth) + fatal("Too many %%If statements in %s\n", previousFile); + + if (skipStackPtr < currentContext.ifdepth) + fatal("Too many %%End statements in %s\n", previousFile); +} + + +/* + * Handle the end of a fully parsed a module. + */ +static void handleEOM() +{ + moduleDef *from; + + /* Check it has been named. */ + if (currentModule->name == NULL) + fatal("No %%Module has been specified for module defined in %s\n", + previousFile); + + from = currentContext.prevmod; + + if (from != NULL && from->encoding == no_type) + from->encoding = currentModule->encoding; + + /* The previous module is now current. */ + currentModule = from; +} + + +/* + * Find an existing qualifier. + */ +static qualDef *findQualifier(const char *name) +{ + moduleDef *mod; + + for (mod = currentSpec->modules; mod != NULL; mod = mod->next) + { + qualDef *qd; + + for (qd = mod->qualifiers; qd != NULL; qd = qd->next) + if (strcmp(qd->name, name) == 0) + return qd; + } + + return NULL; +} + + +/* + * Find an existing API. + */ +apiVersionRangeDef *findAPI(sipSpec *pt, const char *name) +{ + moduleDef *mod; + + for (mod = pt->modules; mod != NULL; mod = mod->next) + { + apiVersionRangeDef *avd; + + for (avd = mod->api_versions; avd != NULL; avd = avd->next) + if (strcmp(avd->api_name->text, name) == 0) + return avd; + } + + return NULL; +} + + +/* + * Return a copy of a scoped name. + */ +scopedNameDef *copyScopedName(scopedNameDef *snd) +{ + scopedNameDef *head; + + head = NULL; + + while (snd != NULL) + { + appendScopedName(&head,text2scopePart(snd -> name)); + snd = snd -> next; + } + + return head; +} + + +/* + * Append a name to a list of scopes. + */ +void appendScopedName(scopedNameDef **headp,scopedNameDef *newsnd) +{ + while (*headp != NULL) + headp = &(*headp) -> next; + + *headp = newsnd; +} + + +/* + * Free a scoped name - but not the text itself. + */ +void freeScopedName(scopedNameDef *snd) +{ + while (snd != NULL) + { + scopedNameDef *next = snd -> next; + + free(snd); + + snd = next; + } +} + + +/* + * Convert a text string to a scope part structure. + */ +static scopedNameDef *text2scopePart(char *text) +{ + scopedNameDef *snd; + + snd = sipMalloc(sizeof (scopedNameDef)); + + snd->name = text; + snd->next = NULL; + + return snd; +} + + +/* + * Convert a text string to a fully scoped name. + */ +static scopedNameDef *text2scopedName(ifaceFileDef *scope, char *text) +{ + return scopeScopedName(scope, text2scopePart(text)); +} + + +/* + * Prepend any current scope to a scoped name. + */ +static scopedNameDef *scopeScopedName(ifaceFileDef *scope, scopedNameDef *name) +{ + scopedNameDef *snd; + + snd = (scope != NULL ? copyScopedName(scope->fqcname) : NULL); + + appendScopedName(&snd, name); + + return snd; +} + + +/* + * Return a pointer to the tail part of a scoped name. + */ +char *scopedNameTail(scopedNameDef *snd) +{ + if (snd == NULL) + return NULL; + + while (snd -> next != NULL) + snd = snd -> next; + + return snd -> name; +} + + +/* + * Push the given scope onto the scope stack. + */ +static void pushScope(classDef *scope) +{ + if (currentScopeIdx >= MAX_NESTED_SCOPE) + fatal("Internal error: increase the value of MAX_NESTED_SCOPE\n"); + + scopeStack[currentScopeIdx] = scope; + sectFlagsStack[currentScopeIdx] = sectionFlags; + + ++currentScopeIdx; +} + + +/* + * Pop the scope stack. + */ +static void popScope(void) +{ + if (currentScopeIdx > 0) + sectionFlags = sectFlagsStack[--currentScopeIdx]; +} + + +/* + * Return non-zero if the current input should be parsed rather than be + * skipped. + */ +static int notSkipping() +{ + return (skipStackPtr == 0 ? TRUE : skipStack[skipStackPtr - 1]); +} + + +/* + * Return the value of an expression involving a time period. + */ +static int timePeriod(char *lname,char *uname) +{ + int this, line; + qualDef *qd, *lower, *upper; + moduleDef *mod; + + if (lname == NULL) + lower = NULL; + else if ((lower = findQualifier(lname)) == NULL || lower -> qtype != time_qualifier) + yyerror("Lower bound is not a time version"); + + if (uname == NULL) + upper = NULL; + else if ((upper = findQualifier(uname)) == NULL || upper -> qtype != time_qualifier) + yyerror("Upper bound is not a time version"); + + /* Sanity checks on the bounds. */ + + if (lower == NULL && upper == NULL) + yyerror("Lower and upper bounds cannot both be omitted"); + + if (lower != NULL && upper != NULL) + { + if (lower -> module != upper -> module || lower -> line != upper -> line) + yyerror("Lower and upper bounds are from different timelines"); + + if (lower == upper) + yyerror("Lower and upper bounds must be different"); + + if (lower -> order > upper -> order) + yyerror("Later version specified as lower bound"); + } + + /* Go through each slot in the relevant timeline. */ + + if (lower != NULL) + { + mod = lower -> module; + line = lower -> line; + } + else + { + mod = upper -> module; + line = upper -> line; + } + + this = FALSE; + + for (qd = mod -> qualifiers; qd != NULL; qd = qd -> next) + { + if (qd -> qtype != time_qualifier || qd -> line != line) + continue; + + if (lower != NULL && qd -> order < lower -> order) + continue; + + if (upper != NULL && qd -> order >= upper -> order) + continue; + + /* + * This is within the required range so if it is also needed + * then the expression is true. + */ + + if (isNeeded(qd)) + { + this = TRUE; + break; + } + } + + return this; +} + + +/* + * Return the value of an expression involving a single platform or feature. + */ +static int platOrFeature(char *name,int optnot) +{ + int this; + qualDef *qd; + + if ((qd = findQualifier(name)) == NULL || qd -> qtype == time_qualifier) + yyerror("No such platform or feature"); + + /* Assume this sub-expression is false. */ + + this = FALSE; + + if (qd -> qtype == feature_qualifier) + { + if (!excludedFeature(excludedQualifiers,qd)) + this = TRUE; + } + else if (isNeeded(qd)) + this = TRUE; + + if (optnot) + this = !this; + + return this; +} + + +/* + * Return TRUE if the given qualifier is excluded. + */ +int excludedFeature(stringList *xsl,qualDef *qd) +{ + while (xsl != NULL) + { + if (strcmp(qd -> name,xsl -> s) == 0) + return TRUE; + + xsl = xsl -> next; + } + + return FALSE; +} + + +/* + * Return TRUE if the given qualifier is needed. + */ +static int isNeeded(qualDef *qd) +{ + stringList *sl; + + for (sl = neededQualifiers; sl != NULL; sl = sl -> next) + if (strcmp(qd -> name,sl -> s) == 0) + return TRUE; + + return FALSE; +} + + +/* + * Return the current scope. currentScope() is only valid if notSkipping() + * returns non-zero. + */ +static classDef *currentScope(void) +{ + return (currentScopeIdx > 0 ? scopeStack[currentScopeIdx - 1] : NULL); +} + + +/* + * Create a new qualifier. + */ +static void newQualifier(moduleDef *mod, int line, int order, char *name, + qualType qt) +{ + qualDef *qd; + + /* Check it doesn't already exist. */ + + if (findQualifier(name) != NULL) + yyerror("Version is already defined"); + + qd = sipMalloc(sizeof (qualDef)); + qd->name = name; + qd->qtype = qt; + qd->module = mod; + qd->line = line; + qd->order = order; + qd->next = mod -> qualifiers; + mod->qualifiers = qd; +} + + +/* + * Create a new imported module. + */ +static void newImport(char *filename) +{ + moduleDef *from, *mod; + moduleListDef *mld; + + /* Create a new module if it has not already been defined. */ + for (mod = currentSpec->modules; mod != NULL; mod = mod->next) + if (strcmp(mod->file, filename) == 0) + break; + + from = currentModule; + + if (mod == NULL) + { + newModule(NULL, filename); + mod = currentModule; + } + else if (from->encoding == no_type) + { + /* Import any defaults from the already parsed module. */ + from->encoding = mod->encoding; + } + + /* Add the new import unless it has already been imported. */ + for (mld = from->imports; mld != NULL; mld = mld->next) + if (mld->module == mod) + return; + + mld = sipMalloc(sizeof (moduleListDef)); + mld->module = mod; + mld->next = from->imports; + + from->imports = mld; +} + + +/* + * Set up pointers to hook names. + */ +static void getHooks(optFlags *optflgs,char **pre,char **post) +{ + optFlag *of; + + if ((of = findOptFlag(optflgs,"PreHook",name_flag)) != NULL) + *pre = of -> fvalue.sval; + else + *pre = NULL; + + if ((of = findOptFlag(optflgs,"PostHook",name_flag)) != NULL) + *post = of -> fvalue.sval; + else + *post = NULL; +} + + +/* + * Get the /Transfer/ option flag. + */ +static int getTransfer(optFlags *optflgs) +{ + return (findOptFlag(optflgs, "Transfer", bool_flag) != NULL); +} + + +/* + * Get the /ReleaseGIL/ option flag. + */ +static int getReleaseGIL(optFlags *optflgs) +{ + return (findOptFlag(optflgs, "ReleaseGIL", bool_flag) != NULL); +} + + +/* + * Get the /HoldGIL/ option flag. + */ +static int getHoldGIL(optFlags *optflgs) +{ + return (findOptFlag(optflgs, "HoldGIL", bool_flag) != NULL); +} + + +/* + * Get the /Deprecated/ option flag. + */ +static int getDeprecated(optFlags *optflgs) +{ + return (findOptFlag(optflgs, "Deprecated", bool_flag) != NULL); +} + + +/* + * Get the /AllowNone/ option flag. + */ +static int getAllowNone(optFlags *optflgs) +{ + return (findOptFlag(optflgs, "AllowNone", bool_flag) != NULL); +} + + +/* + * Get the /DocType/ option flag. + */ +static const char *getDocType(optFlags *optflgs) +{ + optFlag *of = findOptFlag(optflgs, "DocType", string_flag); + + if (of == NULL) + return NULL; + + return of->fvalue.sval; +} + + +/* + * Get the /DocValue/ option flag. + */ +static const char *getDocValue(optFlags *optflgs) +{ + optFlag *of = findOptFlag(optflgs, "DocValue", string_flag); + + if (of == NULL) + return NULL; + + return of->fvalue.sval; +} + + +/* + * Return TRUE if the PyQt3 plugin was specified. + */ +int pluginPyQt3(sipSpec *pt) +{ + return stringFind(pt->plugins, "PyQt3"); +} + + +/* + * Return TRUE if the PyQt4 plugin was specified. + */ +int pluginPyQt4(sipSpec *pt) +{ + return stringFind(pt->plugins, "PyQt4"); +} + + +/* + * Return TRUE if a list of strings contains a given entry. + */ +static int stringFind(stringList *sl, const char *s) +{ + while (sl != NULL) + { + if (strcmp(sl->s, s) == 0) + return TRUE; + + sl = sl->next; + } + + return FALSE; +} + + +/* + * Set the name of a module. + */ +static void setModuleName(sipSpec *pt, moduleDef *mod, const char *fullname) +{ + mod->fullname = cacheName(pt, fullname); + + if (inMainModule()) + setIsUsedName(mod->fullname); + + if ((mod->name = strrchr(fullname, '.')) != NULL) + mod->name++; + else + mod->name = fullname; +} + + +/* + * Define a new class and set its name. + */ +static void defineClass(scopedNameDef *snd, classList *supers, optFlags *of) +{ + classDef *cd, *c_scope = currentScope(); + + cd = newClass(currentSpec, class_iface, getAPIRange(of), + scopeScopedName((c_scope != NULL ? c_scope->iff : NULL), snd)); + cd->supers = supers; + + pushScope(cd); +} + + +/* + * Complete the definition of a class. + */ +static classDef *completeClass(scopedNameDef *snd, optFlags *of, int has_def) +{ + classDef *cd = currentScope(); + + /* See if the class was defined or just declared. */ + if (has_def) + { + if (snd->next != NULL) + yyerror("A scoped name cannot be given in a class/struct definition"); + + } + else if (cd->supers != NULL) + yyerror("Class/struct has super-classes but no definition"); + else + setIsOpaque(cd); + + finishClass(currentSpec, currentModule, cd, of); + popScope(); + + /* + * Check that external classes have only been declared at the global scope. + */ + if (isExternal(cd) && currentScope() != NULL) + yyerror("External classes/structs can only be declared in the global scope"); + + return cd; +} + + +/* + * Add a variable to the list so that the list remains sorted. + */ +static void addVariable(sipSpec *pt, varDef *vd) +{ + varDef **at = &pt->vars; + + while (*at != NULL) + { + if (strcmp(vd->pyname->text, (*at)->pyname->text) < 0) + break; + + at = &(*at)->next; + } + + vd->next = *at; + *at = vd; +} + + +/* + * Update a type according to optional flags. + */ +static void applyTypeFlags(moduleDef *mod, argDef *ad, optFlags *flags) +{ + ad->doctype = getDocType(flags); + + if (ad->atype == string_type && !isArray(ad) && !isReference(ad)) + { + optFlag *of; + + if ((of = findOptFlag(flags, "Encoding", string_flag)) == NULL) + { + if (mod->encoding != no_type) + ad->atype = mod->encoding; + else + ad->atype = string_type; + } + else if ((ad->atype = convertEncoding(of->fvalue.sval)) == no_type) + yyerror("The value of the /Encoding/ annotation must be one of \"ASCII\", \"Latin-1\", \"UTF-8\" or \"None\""); + } +} + + +/* + * Return the argument type for a string with the given encoding or no_type if + * the encoding was invalid. + */ +static argType convertEncoding(const char *encoding) +{ + if (strcmp(encoding, "ASCII") == 0) + return ascii_string_type; + + if (strcmp(encoding, "Latin-1") == 0) + return latin1_string_type; + + if (strcmp(encoding, "UTF-8") == 0) + return utf8_string_type; + + if (strcmp(encoding, "None") == 0) + return string_type; + + return no_type; +} + + +/* + * Get the /API/ option flag. + */ +static apiVersionRangeDef *getAPIRange(optFlags *optflgs) +{ + optFlag *of; + + if ((of = findOptFlag(optflgs, "API", api_range_flag)) == NULL) + return NULL; + + return of->fvalue.aval; +} + + +/* + * Return the API range structure and version number corresponding to the + * given API range. + */ +static apiVersionRangeDef *convertAPIRange(moduleDef *mod, nameDef *name, + int from, int to) +{ + int index; + apiVersionRangeDef *avd, **avdp; + + /* Handle the trivial case. */ + if (from == 0 && to == 0) + return NULL; + + for (index = 0, avdp = &mod->api_ranges; (*avdp) != NULL; avdp = &(*avdp)->next, ++index) + { + avd = *avdp; + + if (avd->api_name == name && avd->from == from && avd->to == to) + return avd; + } + + /* The new one must be appended so that version numbers remain valid. */ + avd = sipMalloc(sizeof (apiVersionRangeDef)); + + avd->api_name = name; + avd->from = from; + avd->to = to; + avd->index = index; + + avd->next = NULL; + *avdp = avd; + + return avd; +} + + +/* + * Return TRUE if a signature with annotations uses keyword arguments. + */ +static int usesKeywordArgs(optFlags *optflgs, signatureDef *sd) +{ + int kwd_args_anno, no_kwd_args_anno; + + kwd_args_anno = (findOptFlag(optflgs, "KeywordArgs", bool_flag) != NULL); + no_kwd_args_anno = (findOptFlag(optflgs, "NoKeywordArgs", bool_flag) != NULL); + + /* + * An ellipsis cannot be used with keyword arguments. Only complain if it + * has been explicitly requested. + */ + if (kwd_args_anno && sd->nrArgs > 0 && sd->args[sd->nrArgs - 1].atype == ellipsis_type) + yyerror("/KeywordArgs/ cannot be specified for calls with a variable number of arguments"); + + if ((defaultKwdArgs || kwd_args_anno) && !no_kwd_args_anno) + { + int a, is_name = FALSE; + + /* + * Mark argument names as being used and check there is at least one. + */ + for (a = 0; a < sd->nrArgs; ++a) + { + nameDef *nd = sd->args[a].name; + + if (sd->args[a].name != NULL) + { + setIsUsedName(nd); + is_name = TRUE; + } + } + + return is_name; + } + + return FALSE; +} + + +/* + * Extract the version of a string value optionally associated with a + * particular feature. + */ +static char *convertFeaturedString(char *fs) +{ + while (fs != NULL) + { + char *next, *value; + + /* Individual values are ';' separated. */ + if ((next = strchr(fs, ';')) != NULL) + *next++ = '\0'; + + /* Features and values are ':' separated. */ + if ((value = strchr(fs, ':')) == NULL) + { + /* This is an unconditional value so just return it. */ + return strip(fs); + } + + *value++ = '\0'; + + if (isEnabledFeature(strip(fs))) + return strip(value); + + fs = next; + } + + /* No value was enabled. */ + return NULL; +} + + +/* + * Return the stripped version of a string. + */ +static char *strip(char *s) +{ + while (*s == ' ') + ++s; + + if (*s != '\0') + { + char *cp = &s[strlen(s) - 1]; + + while (*cp == ' ') + *cp-- = '\0'; + } + + return s; +} + + +/* + * Return TRUE if the given feature is enabled. + */ +static int isEnabledFeature(const char *name) +{ + qualDef *qd; + + if ((qd = findQualifier(name)) == NULL || qd->qtype != feature_qualifier) + yyerror("No such feature"); + + return !excludedFeature(excludedQualifiers, qd); +} diff --git a/sipgen/sip.h b/sipgen/sip.h new file mode 100644 index 0000000..624a1ee --- /dev/null +++ b/sipgen/sip.h @@ -0,0 +1,1180 @@ +/* + * The main header file for SIP. + * + * Copyright (c) 2010 Riverbank Computing Limited <info@riverbankcomputing.com> + * + * This file is part of SIP. + * + * This copy of SIP is licensed for use under the terms of the SIP License + * Agreement. See the file LICENSE for more details. + * + * This copy of SIP may also used under the terms of the GNU General Public + * License v2 or v3 as published by the Free Software Foundation which can be + * found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package. + * + * SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + + +#ifndef SIP_H +#define SIP_H + +#include <stdio.h> +#include <sys/types.h> + + +#ifdef TRUE +#undef TRUE +#endif + +#ifdef FALSE +#undef FALSE +#endif + +#define TRUE 1 +#define FALSE 0 + + +#define DEFAULT_OFILE_EXT ".o" /* Default object file extension. */ + +#define MAX_NR_ARGS 20 /* Max. nr. args. to a function or template. */ + + +/* For convenience. */ + +#define classBaseName(cd) scopedNameTail((cd)->iff->fqcname) +#define classFQCName(cd) ((cd)->iff->fqcname) + + +/* Handle module flags. */ + +#define MOD_HAS_DELAYED_DTORS 0x0001 /* It has a class with a delayed dtor. */ +#define MOD_IS_CONSOLIDATED 0x0002 /* It is a consolidated module. */ +#define MOD_IS_COMPOSITE 0x0004 /* It is a composite module. */ +#define MOD_IS_TRANSFORMED 0x0008 /* It's types have been transformed. */ + +#define hasDelayedDtors(m) ((m)->modflags & MOD_HAS_DELAYED_DTORS) +#define setHasDelayedDtors(m) ((m)->modflags |= MOD_HAS_DELAYED_DTORS) +#define isConsolidated(m) ((m)->modflags & MOD_IS_CONSOLIDATED) +#define setIsConsolidated(m) ((m)->modflags |= MOD_IS_CONSOLIDATED) +#define isComposite(m) ((m)->modflags & MOD_IS_COMPOSITE) +#define setIsComposite(m) ((m)->modflags |= MOD_IS_COMPOSITE) +#define isContainer(m) ((m)->modflags & (MOD_IS_CONSOLIDATED | MOD_IS_COMPOSITE)) +#define setIsTransformed(m) ((m)->modflags |= MOD_IS_TRANSFORMED) +#define isTransformed(m) ((m)->modflags & MOD_IS_TRANSFORMED) + + +/* Handle section flags. */ + +#define SECT_IS_PUBLIC 0x01 /* It is public. */ +#define SECT_IS_PROT 0x02 /* It is protected. */ +#define SECT_IS_PRIVATE 0x04 /* It is private. */ +#define SECT_IS_SLOT 0x08 /* It is a slot. */ +#define SECT_IS_SIGNAL 0x10 /* It is a signal. */ +#define SECT_MASK 0x1f /* The mask of all flags. */ + + +/* Handle class flags. These are combined with the section flags. */ + +#define CLASS_HAS_SIGSLOTS 0x00000200 /* It has signals or slots. */ +#define CLASS_IS_ABSTRACT 0x00000400 /* It is an abstract class. */ +#define CLASS_HAS_SHADOW 0x00000800 /* It is has a shadow class. */ +#define CLASS_IS_OPAQUE 0x00001000 /* It is opaque. */ +#define CLASS_HAS_VAR_HANDLERS 0x00002000 /* It has variable handlers. */ +#define CLASS_DTOR_RELEASE_GIL 0x00004000 /* The dtor releases the GIL. */ +#define CLASS_IS_PROTECTED 0x00008000 /* It is protected. */ +#define CLASS_IS_PROTECTED_SAV 0x00010000 /* It is protected (saved). */ +#define CLASS_IS_INCOMPLETE 0x00020000 /* The specification is incomplete. */ +#define CLASS_CAN_CREATE 0x00040000 /* It has usable ctors. */ +#define CLASS_IS_EXTERNAL 0x00080000 /* It is external. */ +#define CLASS_IS_DELAYED_DTOR 0x00100000 /* The dtor is delayed. */ +#define CLASS_NO_DEFAULT_CTORS 0x00200000 /* Don't create default ctors. */ +#define CLASS_QOBJECT_SUB 0x00400000 /* It is derived from QObject. */ +#define CLASS_DTOR_HOLD_GIL 0x00800000 /* The dtor holds the GIL. */ +#define CLASS_ASSIGN_HELPER 0x01000000 /* Generate an assignment helper. */ +#define CLASS_NO_QMETAOBJECT 0x02000000 /* It has no QMetaObject. */ +#define CLASS_IS_TEMPLATE 0x04000000 /* It is a template class. */ +#define CLASS_IS_DEPRECATED 0x08000000 /* It is deprecated. */ +#define CLASS_CANNOT_COPY 0x10000000 /* It cannot be copied. */ +#define CLASS_CANNOT_ASSIGN 0x20000000 /* It cannot be assigned. */ +#define CLASS_ALLOW_NONE 0x40000000 /* The class will handle None. */ + +#define hasSigSlots(cd) ((cd)->classflags & CLASS_HAS_SIGSLOTS) +#define setHasSigSlots(cd) ((cd)->classflags |= CLASS_HAS_SIGSLOTS) +#define isAbstractClass(cd) ((cd)->classflags & CLASS_IS_ABSTRACT) +#define setIsAbstractClass(cd) ((cd)->classflags |= CLASS_IS_ABSTRACT) +#define hasShadow(cd) ((cd)->classflags & CLASS_HAS_SHADOW) +#define setHasShadow(cd) ((cd)->classflags |= CLASS_HAS_SHADOW) +#define resetHasShadow(cd) ((cd)->classflags &= ~CLASS_HAS_SHADOW) +#define isOpaque(cd) ((cd)->classflags & CLASS_IS_OPAQUE) +#define setIsOpaque(cd) ((cd)->classflags |= CLASS_IS_OPAQUE) +#define hasVarHandlers(cd) ((cd)->classflags & CLASS_HAS_VAR_HANDLERS) +#define setHasVarHandlers(cd) ((cd)->classflags |= CLASS_HAS_VAR_HANDLERS) +#define isProtectedClass(cd) ((cd)->classflags & CLASS_IS_PROTECTED) +#define setIsProtectedClass(cd) ((cd)->classflags |= CLASS_IS_PROTECTED) +#define resetIsProtectedClass(cd) ((cd)->classflags &= ~CLASS_IS_PROTECTED) +#define wasProtectedClass(cd) ((cd)->classflags & CLASS_IS_PROTECTED_SAV) +#define setWasProtectedClass(cd) ((cd)->classflags |= CLASS_IS_PROTECTED_SAV) +#define resetWasProtectedClass(cd) ((cd)->classflags &= ~CLASS_IS_PROTECTED_SAV) +#define isReleaseGILDtor(cd) ((cd)->classflags & CLASS_DTOR_RELEASE_GIL) +#define setIsReleaseGILDtor(cd) ((cd)->classflags |= CLASS_DTOR_RELEASE_GIL) +#define isIncomplete(cd) ((cd)->classflags & CLASS_IS_INCOMPLETE) +#define setIsIncomplete(cd) ((cd)->classflags |= CLASS_IS_INCOMPLETE) +#define canCreate(cd) ((cd)->classflags & CLASS_CAN_CREATE) +#define setCanCreate(cd) ((cd)->classflags |= CLASS_CAN_CREATE) +#define resetCanCreate(cd) ((cd)->classflags &= ~CLASS_CAN_CREATE) +#define isExternal(cd) ((cd)->classflags & CLASS_IS_EXTERNAL) +#define setIsExternal(cd) ((cd)->classflags |= CLASS_IS_EXTERNAL) +#define isDelayedDtor(cd) ((cd)->classflags & CLASS_IS_DELAYED_DTOR) +#define setIsDelayedDtor(cd) ((cd)->classflags |= CLASS_IS_DELAYED_DTOR) +#define noDefaultCtors(cd) ((cd)->classflags & CLASS_NO_DEFAULT_CTORS) +#define setNoDefaultCtors(cd) ((cd)->classflags |= CLASS_NO_DEFAULT_CTORS) +#define isQObjectSubClass(cd) ((cd)->classflags & CLASS_QOBJECT_SUB) +#define setIsQObjectSubClass(cd) ((cd)->classflags |= CLASS_QOBJECT_SUB) +#define isHoldGILDtor(cd) ((cd)->classflags & CLASS_DTOR_HOLD_GIL) +#define setIsHoldGILDtor(cd) ((cd)->classflags |= CLASS_DTOR_HOLD_GIL) +#define assignmentHelper(cd) ((cd)->classflags & CLASS_ASSIGN_HELPER) +#define setAssignmentHelper(cd) ((cd)->classflags |= CLASS_ASSIGN_HELPER) +#define noPyQt4QMetaObject(cd) ((cd)->classflags & CLASS_NO_QMETAOBJECT) +#define setPyQt4NoQMetaObject(cd) ((cd)->classflags |= CLASS_NO_QMETAOBJECT) +#define isTemplateClass(cd) ((cd)->classflags & CLASS_IS_TEMPLATE) +#define setIsTemplateClass(cd) ((cd)->classflags |= CLASS_IS_TEMPLATE) +#define resetIsTemplateClass(cd) ((cd)->classflags &= ~CLASS_IS_TEMPLATE) +#define isDeprecatedClass(cd) ((cd)->classflags & CLASS_IS_DEPRECATED) +#define setIsDeprecatedClass(cd) ((cd)->classflags |= CLASS_IS_DEPRECATED) +#define cannotCopy(cd) ((cd)->classflags & CLASS_CANNOT_COPY) +#define setCannotCopy(cd) ((cd)->classflags |= CLASS_CANNOT_COPY) +#define cannotAssign(cd) ((cd)->classflags & CLASS_CANNOT_ASSIGN) +#define setCannotAssign(cd) ((cd)->classflags |= CLASS_CANNOT_ASSIGN) +#define classHandlesNone(cd) ((cd)->classflags & CLASS_ALLOW_NONE) +#define setClassHandlesNone(cd) ((cd)->classflags |= CLASS_ALLOW_NONE) + +#define isPublicDtor(cd) ((cd)->classflags & SECT_IS_PUBLIC) +#define setIsPublicDtor(cd) ((cd)->classflags |= SECT_IS_PUBLIC) +#define isProtectedDtor(cd) ((cd)->classflags & SECT_IS_PROT) +#define isPrivateDtor(cd) ((cd)->classflags & SECT_IS_PRIVATE) + +#define isDtor(cd) ((cd)->classflags & (SECT_IS_PUBLIC | SECT_IS_PROT | SECT_IS_PRIVATE)) + + +/* Handle ctor flags. These are combined with the section flags. */ + +#define CTOR_RELEASE_GIL 0x00000100 /* The ctor releases the GIL. */ +#define CTOR_EXPLICIT 0x00000200 /* The ctor is explicit. */ +#define CTOR_CAST 0x00000400 /* The ctor is a cast. */ +#define CTOR_HOLD_GIL 0x00000800 /* The ctor holds the GIL. */ +#define CTOR_XFERRED 0x00001000 /* Ownership is transferred. */ +#define CTOR_IS_DEPRECATED 0x00002000 /* The ctor is deprecated. */ +#define CTOR_KEYWORD_ARGS 0x00004000 /* The ctor allows keyword arguments. */ + +#define isPublicCtor(c) ((c)->ctorflags & SECT_IS_PUBLIC) +#define setIsPublicCtor(c) ((c)->ctorflags |= SECT_IS_PUBLIC) +#define isProtectedCtor(c) ((c)->ctorflags & SECT_IS_PROT) +#define setIsProtectedCtor(c) ((c)->ctorflags |= SECT_IS_PROT) +#define isPrivateCtor(c) ((c)->ctorflags & SECT_IS_PRIVATE) +#define setIsPrivateCtor(c) ((c)->ctorflags |= SECT_IS_PRIVATE) + +#define isReleaseGILCtor(c) ((c)->ctorflags & CTOR_RELEASE_GIL) +#define setIsReleaseGILCtor(c) ((c)->ctorflags |= CTOR_RELEASE_GIL) +#define isExplicitCtor(c) ((c)->ctorflags & CTOR_EXPLICIT) +#define setIsExplicitCtor(c) ((c)->ctorflags |= CTOR_EXPLICIT) +#define isCastCtor(c) ((c)->ctorflags & CTOR_CAST) +#define isHoldGILCtor(c) ((c)->ctorflags & CTOR_HOLD_GIL) +#define setIsHoldGILCtor(c) ((c)->ctorflags |= CTOR_HOLD_GIL) +#define isResultTransferredCtor(c) ((c)->ctorflags & CTOR_XFERRED) +#define setIsResultTransferredCtor(c) ((c)->ctorflags |= CTOR_XFERRED) +#define isDeprecatedCtor(c) ((c)->ctorflags & CTOR_IS_DEPRECATED) +#define setIsDeprecatedCtor(c) ((c)->ctorflags |= CTOR_IS_DEPRECATED) +#define useKeywordArgsCtor(c) ((c)->ctorflags & CTOR_KEYWORD_ARGS) +#define setUseKeywordArgsCtor(c) ((c)->ctorflags |= CTOR_KEYWORD_ARGS) + + +/* Handle member flags. */ + +#define MEMBR_NUMERIC 0x0001 /* It is a numeric slot. */ +#define MEMBR_NO_ARG_PARSER 0x0002 /* Don't generate an argument parser. */ +#define MEMBR_NOT_VERSIONED 0x0004 /* There is an unversioned overload. */ +#define MEMBR_KEYWORD_ARGS 0x0008 /* It allows keyword arguments. */ + +#define isNumeric(m) ((m)->memberflags & MEMBR_NUMERIC) +#define setIsNumeric(m) ((m)->memberflags |= MEMBR_NUMERIC) +#define noArgParser(m) ((m)->memberflags & MEMBR_NO_ARG_PARSER) +#define setNoArgParser(m) ((m)->memberflags |= MEMBR_NO_ARG_PARSER) +#define notVersioned(m) ((m)->memberflags & MEMBR_NOT_VERSIONED) +#define setNotVersioned(m) ((m)->memberflags |= MEMBR_NOT_VERSIONED) +#define useKeywordArgsFunction(m) ((m)->memberflags & MEMBR_KEYWORD_ARGS) +#define setUseKeywordArgsFunction(m) ((m)->memberflags |= MEMBR_KEYWORD_ARGS) + + +/* Handle enum flags. These are combined with the section flags. */ + +#define ENUM_WAS_PROT 0x00000100 /* It was defined as protected. */ + +#define isProtectedEnum(e) ((e)->enumflags & SECT_IS_PROT) +#define setIsProtectedEnum(e) ((e)->enumflags |= SECT_IS_PROT) +#define resetIsProtectedEnum(e) ((e)->enumflags &= ~SECT_IS_PROT) + +#define wasProtectedEnum(e) ((e)->enumflags & ENUM_WAS_PROT) +#define setWasProtectedEnum(e) ((e)->enumflags |= ENUM_WAS_PROT) +#define resetWasProtectedEnum(e) ((e)->enumflags &= ~ENUM_WAS_PROT) + + +/* Handle hierarchy flags. */ + +#define HIER_IS_DUPLICATE 0x0001 /* It is a super class duplicate. */ +#define HIER_HAS_DUPLICATE 0x0002 /* It has a super class duplicate. */ +#define HIER_BEING_SET 0x0004 /* The MRO is being set. */ + +#define isDuplicateSuper(m) ((m)->mroflags & HIER_IS_DUPLICATE) +#define setIsDuplicateSuper(m) ((m)->mroflags |= HIER_IS_DUPLICATE) +#define hasDuplicateSuper(m) ((m)->mroflags & HIER_HAS_DUPLICATE) +#define setHasDuplicateSuper(m) ((m)->mroflags |= HIER_HAS_DUPLICATE) +#define hierBeingSet(m) ((m)->mroflags & HIER_BEING_SET) +#define setHierBeingSet(m) ((m)->mroflags |= HIER_BEING_SET) +#define resetHierBeingSet(m) ((m)->mroflags &= ~HIER_BEING_SET) + + +/* Handle overload flags. These are combined with the section flags. */ + +#define OVER_IS_VIRTUAL 0x00000100 /* It is virtual. */ +#define OVER_IS_ABSTRACT 0x00000200 /* It is abstract. */ +#define OVER_IS_CONST 0x00000400 /* It is a const function. */ +#define OVER_IS_STATIC 0x00000800 /* It is a static function. */ +#define OVER_IS_AUTOGEN 0x00001000 /* It is auto-generated. */ +#define OVER_IS_NEW_THREAD 0x00002000 /* It is in a new thread. */ +#define OVER_IS_FACTORY 0x00004000 /* It is a factory method. */ +#define OVER_XFERRED_BACK 0x00008000 /* Ownership is transferred back. */ +#define OVER_XFERRED 0x00010000 /* Ownership is transferred. */ +#define OVER_IS_VIRTUAL_REIMP 0x00020000 /* It is a re-implementation of a virtual. */ +#define OVER_DONT_DEREF_SELF 0x00040000 /* For comparison operators, don't dereference self. */ +#define OVER_HOLD_GIL 0x00080000 /* The function holds the GIL. */ +#define OVER_RELEASE_GIL 0x00100000 /* The function releases the GIL. */ +#define OVER_THIS_XFERRED 0x00200000 /* Ownership of this is transferred. */ +#define OVER_IS_GLOBAL 0x00400000 /* It is a global operator. */ +#define OVER_IS_COMPLEMENTARY 0x00800000 /* It is a complementary operator. */ +#define OVER_IS_DEPRECATED 0x01000000 /* It is deprecated. */ +#define OVER_KEYWORD_ARGS 0x02000000 /* It allows keyword arguments. */ +#define OVER_REALLY_PROT 0x04000000 /* It really is protected. */ + +#define isPublic(o) ((o)->overflags & SECT_IS_PUBLIC) +#define setIsPublic(o) ((o)->overflags |= SECT_IS_PUBLIC) +#define isProtected(o) ((o)->overflags & SECT_IS_PROT) +#define setIsProtected(o) ((o)->overflags |= SECT_IS_PROT) +#define isPrivate(o) ((o)->overflags & SECT_IS_PRIVATE) +#define setIsPrivate(o) ((o)->overflags |= SECT_IS_PRIVATE) +#define isSlot(o) ((o)->overflags & SECT_IS_SLOT) +#define setIsSlot(o) ((o)->overflags |= SECT_IS_SLOT) +#define resetIsSlot(o) ((o)->overflags &= ~SECT_IS_SLOT) +#define isSignal(o) ((o)->overflags & SECT_IS_SIGNAL) +#define setIsSignal(o) ((o)->overflags |= SECT_IS_SIGNAL) +#define resetIsSignal(o) ((o)->overflags &= ~SECT_IS_SIGNAL) + +#define isVirtual(o) ((o)->overflags & OVER_IS_VIRTUAL) +#define setIsVirtual(o) ((o)->overflags |= OVER_IS_VIRTUAL) +#define resetIsVirtual(o) ((o)->overflags &= ~OVER_IS_VIRTUAL) +#define isAbstract(o) ((o)->overflags & OVER_IS_ABSTRACT) +#define setIsAbstract(o) ((o)->overflags |= OVER_IS_ABSTRACT) +#define isConst(o) ((o)->overflags & OVER_IS_CONST) +#define setIsConst(o) ((o)->overflags |= OVER_IS_CONST) +#define isStatic(o) ((o)->overflags & OVER_IS_STATIC) +#define setIsStatic(o) ((o)->overflags |= OVER_IS_STATIC) +#define isAutoGen(o) ((o)->overflags & OVER_IS_AUTOGEN) +#define setIsAutoGen(o) ((o)->overflags |= OVER_IS_AUTOGEN) +#define resetIsAutoGen(o) ((o)->overflags &= ~OVER_IS_AUTOGEN) +#define isNewThread(o) ((o)->overflags & OVER_IS_NEW_THREAD) +#define setIsNewThread(o) ((o)->overflags |= OVER_IS_NEW_THREAD) +#define isFactory(o) ((o)->overflags & OVER_IS_FACTORY) +#define setIsFactory(o) ((o)->overflags |= OVER_IS_FACTORY) +#define isResultTransferredBack(o) ((o)->overflags & OVER_XFERRED_BACK) +#define setIsResultTransferredBack(o) ((o)->overflags |= OVER_XFERRED_BACK) +#define isResultTransferred(o) ((o)->overflags & OVER_XFERRED) +#define setIsResultTransferred(o) ((o)->overflags |= OVER_XFERRED) +#define isVirtualReimp(o) ((o)->overflags & OVER_IS_VIRTUAL_REIMP) +#define setIsVirtualReimp(o) ((o)->overflags |= OVER_IS_VIRTUAL_REIMP) +#define dontDerefSelf(o) ((o)->overflags & OVER_DONT_DEREF_SELF) +#define setDontDerefSelf(o) ((o)->overflags |= OVER_DONT_DEREF_SELF) +#define isHoldGIL(o) ((o)->overflags & OVER_HOLD_GIL) +#define setIsHoldGIL(o) ((o)->overflags |= OVER_HOLD_GIL) +#define isReleaseGIL(o) ((o)->overflags & OVER_RELEASE_GIL) +#define setIsReleaseGIL(o) ((o)->overflags |= OVER_RELEASE_GIL) +#define isThisTransferredMeth(o) ((o)->overflags & OVER_THIS_XFERRED) +#define setIsThisTransferredMeth(o) ((o)->overflags |= OVER_THIS_XFERRED) +#define isGlobal(o) ((o)->overflags & OVER_IS_GLOBAL) +#define setIsGlobal(o) ((o)->overflags |= OVER_IS_GLOBAL) +#define isComplementary(o) ((o)->overflags & OVER_IS_COMPLEMENTARY) +#define setIsComplementary(o) ((o)->overflags |= OVER_IS_COMPLEMENTARY) +#define isDeprecated(o) ((o)->overflags & OVER_IS_DEPRECATED) +#define setIsDeprecated(o) ((o)->overflags |= OVER_IS_DEPRECATED) +#define useKeywordArgs(o) ((o)->overflags & OVER_KEYWORD_ARGS) +#define setUseKeywordArgs(o) ((o)->overflags |= OVER_KEYWORD_ARGS) +#define isReallyProtected(o) ((o)->overflags & OVER_REALLY_PROT) +#define setIsReallyProtected(o) ((o)->overflags |= OVER_REALLY_PROT) + + +/* Handle variable flags. */ + +#define VAR_IS_STATIC 0x01 /* It is a static variable. */ +#define VAR_NEEDS_HANDLER 0x02 /* It the variable needs a handler. */ + +#define isStaticVar(v) ((v)->varflags & VAR_IS_STATIC) +#define setIsStaticVar(v) ((v)->varflags |= VAR_IS_STATIC) +#define needsHandler(v) ((v)->varflags & VAR_NEEDS_HANDLER) +#define setNeedsHandler(v) ((v)->varflags |= VAR_NEEDS_HANDLER) + + +/* Handle argument flags. */ + +#define ARG_IS_REF 0x0001 /* It is a reference. */ +#define ARG_IS_CONST 0x0002 /* It is a const. */ +#define ARG_XFERRED 0x0004 /* Ownership is transferred. */ +#define ARG_THIS_XFERRED 0x0008 /* Ownership of this is transferred. */ +#define ARG_XFERRED_BACK 0x0010 /* Ownership is transferred back. */ +#define ARG_ARRAY 0x0020 /* Used as an array. */ +#define ARG_ARRAY_SIZE 0x0040 /* Used as an array size. */ +#define ARG_ALLOW_NONE 0x0080 /* Allow None as a value. */ +#define ARG_GET_WRAPPER 0x0100 /* Get the wrapper object. */ +#define ARG_IN 0x0200 /* It passes an argument. */ +#define ARG_OUT 0x0400 /* It returns a result. */ +#define ARG_CONSTRAINED 0x0800 /* Suppress type conversion. */ +#define ARG_SINGLE_SHOT 0x1000 /* The slot is only ever fired once. */ +#define ARG_RESULT_SIZE 0x2000 /* It defines the result size. */ +#define ARG_KEEP_REF 0x4000 /* Keep a reference. */ +#define ARG_NO_COPY 0x8000 /* Disable copying of const references. */ + +#define isReference(a) ((a)->argflags & ARG_IS_REF) +#define setIsReference(a) ((a)->argflags |= ARG_IS_REF) +#define resetIsReference(a) ((a)->argflags &= ~ARG_IS_REF) +#define isConstArg(a) ((a)->argflags & ARG_IS_CONST) +#define setIsConstArg(a) ((a)->argflags |= ARG_IS_CONST) +#define resetIsConstArg(a) ((a)->argflags &= ~ARG_IS_CONST) +#define isTransferred(a) ((a)->argflags & ARG_XFERRED) +#define setIsTransferred(a) ((a)->argflags |= ARG_XFERRED) +#define isThisTransferred(a) ((a)->argflags & ARG_THIS_XFERRED) +#define setIsThisTransferred(a) ((a)->argflags |= ARG_THIS_XFERRED) +#define isTransferredBack(a) ((a)->argflags & ARG_XFERRED_BACK) +#define setIsTransferredBack(a) ((a)->argflags |= ARG_XFERRED_BACK) +#define isArray(a) ((a)->argflags & ARG_ARRAY) +#define setArray(a) ((a)->argflags |= ARG_ARRAY) +#define isArraySize(a) ((a)->argflags & ARG_ARRAY_SIZE) +#define setArraySize(a) ((a)->argflags |= ARG_ARRAY_SIZE) +#define isAllowNone(a) ((a)->argflags & ARG_ALLOW_NONE) +#define setAllowNone(a) ((a)->argflags |= ARG_ALLOW_NONE) +#define isGetWrapper(a) ((a)->argflags & ARG_GET_WRAPPER) +#define setGetWrapper(a) ((a)->argflags |= ARG_GET_WRAPPER) +#define isInArg(a) ((a)->argflags & ARG_IN) +#define setIsInArg(a) ((a)->argflags |= ARG_IN) +#define isOutArg(a) ((a)->argflags & ARG_OUT) +#define setIsOutArg(a) ((a)->argflags |= ARG_OUT) +#define isConstrained(a) ((a)->argflags & ARG_CONSTRAINED) +#define setIsConstrained(a) ((a)->argflags |= ARG_CONSTRAINED) +#define resetIsConstrained(a) ((a)->argflags &= ~ARG_CONSTRAINED) +#define isSingleShot(a) ((a)->argflags & ARG_SINGLE_SHOT) +#define isResultSize(a) ((a)->argflags & ARG_RESULT_SIZE) +#define setResultSize(a) ((a)->argflags |= ARG_RESULT_SIZE) +#define keepReference(a) ((a)->argflags & ARG_KEEP_REF) +#define setKeepReference(a) ((a)->argflags |= ARG_KEEP_REF) +#define noCopy(a) ((a)->argflags & ARG_NO_COPY) +#define setNoCopy(a) ((a)->argflags |= ARG_NO_COPY) + + +/* Handle name flags. */ + +#define NAME_IS_USED 0x01 /* It is used in the main module. */ +#define NAME_IS_SUBSTR 0x02 /* It is a substring of another. */ + +#define isUsedName(n) ((n)->nameflags & NAME_IS_USED) +#define setIsUsedName(n) ((n)->nameflags |= NAME_IS_USED) +#define resetIsUsedName(n) ((n)->nameflags &= ~NAME_IS_USED) +#define isSubstring(n) ((n)->nameflags & NAME_IS_SUBSTR) +#define setIsSubstring(n) ((n)->nameflags |= NAME_IS_SUBSTR) + + +/* Handle virtual handler flags. */ + +#define VH_IS_DUPLICATE 0x01 /* It is a duplicate. */ +#define VH_TRANSFERS 0x02 /* It transfers ownership of the result. */ + +#define isDuplicateVH(vh) ((vh)->vhflags & VH_IS_DUPLICATE) +#define setIsDuplicateVH(vh) ((vh)->vhflags |= VH_IS_DUPLICATE) +#define resetIsDuplicateVH(vh) ((vh)->vhflags &= ~VH_IS_DUPLICATE) +#define isTransferVH(vh) ((vh)->vhflags & VH_TRANSFERS) +#define setIsTransferVH(vh) ((vh)->vhflags |= VH_TRANSFERS) + + +/* Handle mapped type flags. */ + +#define MT_NO_RELEASE 0x01 /* Do not generate a release function. */ +#define MT_ALLOW_NONE 0x02 /* The mapped type will handle None. */ + +#define noRelease(mt) ((mt)->mtflags & MT_NO_RELEASE) +#define setNoRelease(mt) ((mt)->mtflags |= MT_NO_RELEASE) +#define handlesNone(mt) ((mt)->mtflags & MT_ALLOW_NONE) +#define setHandlesNone(mt) ((mt)->mtflags |= MT_ALLOW_NONE) + + +/* Handle typedef flags. */ + +#define TD_NO_TYPE_NAME 0x01 /* Do not use the typedef name. */ + +#define noTypeName(td) ((td)->tdflags & TD_NO_TYPE_NAME) +#define setNoTypeName(td) ((td)->tdflags |= TD_NO_TYPE_NAME) + + +/* Slot types. */ + +typedef enum { + str_slot, + unicode_slot, + int_slot, + long_slot, + float_slot, + len_slot, + contains_slot, + add_slot, + concat_slot, + sub_slot, + mul_slot, + repeat_slot, + div_slot, + mod_slot, + floordiv_slot, + truediv_slot, + and_slot, + or_slot, + xor_slot, + lshift_slot, + rshift_slot, + iadd_slot, + iconcat_slot, + isub_slot, + imul_slot, + irepeat_slot, + idiv_slot, + imod_slot, + ifloordiv_slot, + itruediv_slot, + iand_slot, + ior_slot, + ixor_slot, + ilshift_slot, + irshift_slot, + invert_slot, + call_slot, + getitem_slot, + setitem_slot, + delitem_slot, + lt_slot, + le_slot, + eq_slot, + ne_slot, + gt_slot, + ge_slot, + cmp_slot, + bool_slot, + neg_slot, + pos_slot, + abs_slot, + repr_slot, + hash_slot, + index_slot, + iter_slot, + next_slot, + no_slot +} slotType; + + +/* + * Argument types. Always add new ones at the end because the numeric values + * can appear in generated code. + */ +typedef enum { + no_type, + defined_type, + class_type, + struct_type, + void_type, + enum_type, + template_type, + signal_type, + slot_type, + rxcon_type, + rxdis_type, + slotcon_type, + slotdis_type, + ustring_type, + string_type, + short_type, + ushort_type, + cint_type, + int_type, + uint_type, + long_type, + ulong_type, + float_type, + cfloat_type, + double_type, + cdouble_type, + bool_type, + mapped_type, + pyobject_type, + pytuple_type, + pylist_type, + pydict_type, + pycallable_type, + pyslice_type, + qobject_type, + function_type, + pytype_type, + ellipsis_type, + longlong_type, + ulonglong_type, + anyslot_type, + cbool_type, + sstring_type, + wstring_type, + fake_void_type, + ssize_type, + ascii_string_type, + latin1_string_type, + utf8_string_type +} argType; + + +/* Value types. */ + +typedef enum { + qchar_value, + string_value, + numeric_value, + real_value, + scoped_value, + fcall_value +} valueType; + + +/* Version types. */ + +typedef enum { + time_qualifier, + platform_qualifier, + feature_qualifier +} qualType; + + +/* Interface file types. */ + +typedef enum { + exception_iface, + mappedtype_iface, + namespace_iface, + class_iface +} ifaceFileType; + + +/* A software license. */ + +typedef struct { + char *type; /* The license type. */ + char *licensee; /* The licensee. */ + char *timestamp; /* The timestamp. */ + char *sig; /* The signature. */ +} licenseDef; + + +/* A version qualifier. */ + +typedef struct _qualDef { + char *name; /* The qualifier name. */ + qualType qtype; /* The qualifier type. */ + struct _moduleDef *module; /* The defining module. */ + int line; /* Timeline if it is a time. */ + int order; /* Order if it is a time. */ + struct _qualDef *next; /* Next in the list. */ +} qualDef; + + +/* A scoped name. */ + +typedef struct _scopedNameDef { + char *name; /* The name. */ + struct _scopedNameDef *next; /* Next in the scope list. */ +} scopedNameDef; + + +/* A name. */ + +typedef struct _nameDef { + int nameflags; /* The name flags. */ + const char *text; /* The text of the name. */ + size_t len; /* The length of the name. */ + size_t offset; /* The offset in the string pool. */ + struct _nameDef *next; /* Next in the list. */ +} nameDef; + + +/* A literal code block. */ + +typedef struct _codeBlock { + char *frag; /* The code itself. */ + const char *filename; /* The original file. */ + int linenr; /* The line in the file. */ + struct _codeBlock *next; /* Next in the list. */ +} codeBlock; + + +/* The arguments to a throw specifier. */ + +typedef struct _throwArgs { + int nrArgs; /* The number of arguments. */ + struct _exceptionDef *args[MAX_NR_ARGS]; /* The arguments. */ +} throwArgs; + + +/* An exception. */ + +typedef struct _exceptionDef { + int exceptionnr; /* The exception number. */ + struct _ifaceFileDef *iff; /* The interface file. */ + const char *pyname; /* The exception Python name. */ + struct _classDef *cd; /* The exception class. */ + char *bibase; /* The builtin base exception. */ + struct _exceptionDef *base; /* The defined base exception. */ + codeBlock *raisecode; /* Raise exception code. */ + struct _exceptionDef *next; /* The next in the list. */ +} exceptionDef; + + +/* A value. */ + +typedef struct _valueDef { + valueType vtype; /* The type. */ + char vunop; /* Any unary operator. */ + char vbinop; /* Any binary operator. */ + union { + char vqchar; /* Quoted character value. */ + long vnum; /* Numeric value. */ + double vreal; /* Real value. */ + char *vstr; /* String value. */ + scopedNameDef *vscp; /* Scoped value. */ + struct _fcallDef *fcd; /* Function call. */ + } u; + struct _valueDef *next; /* Next in the expression. */ +} valueDef; + + +/* A member function argument (or result). */ + +typedef struct { + argType atype; /* The type. */ + nameDef *name; /* The name. */ + const char *doctype; /* The documented type. */ + int argflags; /* The argument flags. */ + int nrderefs; /* Nr. of dereferences. */ + valueDef *defval; /* The default value. */ + const char *docval; /* The documented value. */ + int key; /* The optional /KeepReference/ key. */ + struct _typedefDef *original_type; /* The original type if typedef'd. */ + union { + struct _signatureDef *sa; /* If it is a function. */ + struct _templateDef *td; /* If it is a template. */ + struct _scopedNameDef *snd; /* If it is a defined type. */ + struct _classDef *cd; /* If it is a class. */ + struct _enumDef *ed; /* If it is an enum. */ + struct _scopedNameDef *sname; /* If it is a struct. */ + struct _mappedTypeDef *mtd; /* If it is a mapped type. */ + } u; +} argDef; + + + +/* An entry in a linked argument list. */ +typedef struct _argList { + argDef arg; /* The argument itself. */ + struct _argList *next; /* Next in the list. */ +} argList; + + +/* A function call. */ + +typedef struct _fcallDef { + argDef type; /* The type. */ + int nrArgs; /* The number of arguments. */ + struct _valueDef *args[MAX_NR_ARGS]; /* The arguments. */ +} fcallDef; + + +/* An API version range definition. */ +typedef struct _apiVersionRangeDef { + nameDef *api_name; /* The API name. */ + int from; /* The lower bound. */ + int to; /* The upper bound. */ + int index; /* The range index. */ + struct _apiVersionRangeDef *next; /* The next in the list. */ +} apiVersionRangeDef; + + +/* A module definition. */ +typedef struct _moduleDef { + nameDef *fullname; /* The full module name. */ + const char *name; /* The module base name. */ + int version; /* The module version. */ + apiVersionRangeDef *api_versions; /* The defined APIs. */ + apiVersionRangeDef *api_ranges; /* The list of API version ranges. */ + int modflags; /* The module flags. */ + int qobjclass; /* QObject class, -1 if none. */ + struct _memberDef *othfuncs; /* List of other functions. */ + struct _overDef *overs; /* Global overloads. */ + argType encoding; /* The default string encoding. */ + nameDef *defmetatype; /* The optional default meta-type. */ + nameDef *defsupertype; /* The optional default super-type. */ + struct _exceptionDef *defexception; /* The default exception. */ + codeBlock *hdrcode; /* Header code. */ + codeBlock *cppcode; /* Global C++ code. */ + codeBlock *copying; /* Software license. */ + codeBlock *preinitcode; /* Pre-initialisation code. */ + codeBlock *initcode; /* Initialisation code. */ + codeBlock *postinitcode; /* Post-initialisation code. */ + codeBlock *unitcode; /* Compilation unit code. */ + int parts; /* The number of parts generated. */ + char *file; /* The filename. */ + qualDef *qualifiers; /* The list of qualifiers. */ + argDef *types; /* The array of numbered types. */ + int nrtypes; /* The number of numbered types. */ + int nrtimelines; /* The nr. of timelines. */ + int nrexceptions; /* The nr. of exceptions. */ + int nrtypedefs; /* The nr. of typedefs. */ + int nrvirthandlers; /* The nr. of virtual handlers. */ + int next_key; /* The next key to allocate. */ + struct _virtHandlerDef *virthandlers; /* The virtual handlers. */ + licenseDef *license; /* The software license. */ + struct _classDef *proxies; /* The list of proxy classes. */ + struct _moduleDef *container; /* The container module, if any. */ + struct _ifaceFileList *used; /* Interface files used. */ + struct _moduleListDef *allimports; /* The list of all imports. */ + struct _moduleListDef *imports; /* The list of direct imports. */ + struct _moduleDef *next; /* Next in the list. */ +} moduleDef; + + +/* An entry in a linked module list. */ +typedef struct _moduleListDef { + moduleDef *module; /* The module itself. */ + struct _moduleListDef *next; /* The next in the list. */ +} moduleListDef; + + +/* An interface file definition. */ + +typedef struct _ifaceFileDef { + nameDef *name; /* The name. */ + apiVersionRangeDef *api_range; /* The optional API version range. */ + struct _ifaceFileDef *first_alt; /* The first alternate API. */ + struct _ifaceFileDef *next_alt; /* The next alternate API. */ + ifaceFileType type; /* Interface file type. */ + int ifacenr; /* The index into the types table. */ + scopedNameDef *fqcname; /* The fully qualified C++ name. */ + moduleDef *module; /* The owning module. */ + codeBlock *hdrcode; /* Header code. */ + struct _ifaceFileList *used; /* Interface files used. */ + struct _ifaceFileDef *next; /* Next in the list. */ +} ifaceFileDef; + + +/* An entry in a linked interface file list. */ + +typedef struct _ifaceFileList { + ifaceFileDef *iff; /* The interface file itself. */ + struct _ifaceFileList *next; /* Next in the list. */ +} ifaceFileList; + + +/* A mapped type. */ + +typedef struct _mappedTypeDef { + int mtflags; /* The mapped type flags. */ + argDef type; /* The type being mapped. */ + nameDef *pyname; /* The Python name. */ + nameDef *cname; /* The C/C++ name. */ + const char *doctype; /* The documented type. */ + ifaceFileDef *iff; /* The interface file. */ + struct _memberDef *members; /* The static member functions. */ + struct _overDef *overs; /* The static overloads. */ + codeBlock *convfromcode; /* Convert from C++ code. */ + codeBlock *convtocode; /* Convert to C++ code. */ + struct _mappedTypeDef *next; /* Next in the list. */ +} mappedTypeDef; + + +/* A function signature. */ + +typedef struct _signatureDef { + argDef result; /* The result. */ + int nrArgs; /* The number of arguments. */ + argDef args[MAX_NR_ARGS]; /* The arguments. */ +} signatureDef; + + +/* A list of function signatures. */ + +typedef struct _signatureList { + struct _signatureDef *sd; /* The signature. */ + struct _signatureList *next; /* Next in the list. */ +} signatureList; + + +/* A template type. */ + +typedef struct _templateDef { + scopedNameDef *fqname; /* The name. */ + signatureDef types; /* The types. */ +} templateDef; + + +/* A list of virtual handlers. */ + +typedef struct _virtHandlerDef { + int virthandlernr; /* The nr. of the virtual handler. */ + int vhflags; /* The virtual handler flags. */ + signatureDef *pysig; /* The Python signature. */ + signatureDef *cppsig; /* The C++ signature. */ + struct _moduleDef *module; /* The defining module. */ + codeBlock *virtcode; /* Virtual handler code. */ + struct _virtHandlerDef *next; /* Next in the list. */ +} virtHandlerDef; + + +/* A typedef definition. */ + +typedef struct _typedefDef { + int tdflags; /* The typedef flags. */ + scopedNameDef *fqname; /* The fully qualified name. */ + struct _classDef *ecd; /* The enclosing class. */ + moduleDef *module; /* The owning module. */ + argDef type; /* The actual type. */ + struct _typedefDef *next; /* Next in the list. */ +} typedefDef; + + +/* A variable definition. */ + +typedef struct _varDef { + nameDef *pyname; /* The variable Python name. */ + scopedNameDef *fqcname; /* The fully qualified C/C++ name. */ + struct _classDef *ecd; /* The enclosing class. */ + moduleDef *module; /* The owning module. */ + int varflags; /* The variable flags. */ + argDef type; /* The actual type. */ + codeBlock *accessfunc; /* The access function. */ + codeBlock *getcode; /* The get code. */ + codeBlock *setcode; /* The set code. */ + struct _varDef *next; /* Next in the list. */ +} varDef; + + +/* An overloaded member function definition. */ + +typedef struct _overDef { + char *cppname; /* The C++ name. */ + int overflags; /* The overload flags. */ + struct _memberDef *common; /* Common parts. */ + apiVersionRangeDef *api_range; /* The optional API version range. */ + signatureDef pysig; /* The Python signature. */ + signatureDef *cppsig; /* The C++ signature. */ + throwArgs *exceptions; /* The exceptions. */ + codeBlock *methodcode; /* Method code. */ + virtHandlerDef *virthandler; /* The virtual handler. */ + char *prehook; /* The pre-hook name. */ + char *posthook; /* The post-hook name. */ + struct _overDef *next; /* Next in the list. */ +} overDef; + + +/* An overloaded constructor definition. */ + +typedef struct _ctorDef { + int ctorflags; /* The ctor flags. */ + apiVersionRangeDef *api_range; /* The optional API version range. */ + signatureDef pysig; /* The Python signature. */ + signatureDef *cppsig; /* The C++ signature, NULL if /NoDerived/. */ + throwArgs *exceptions; /* The exceptions. */ + codeBlock *methodcode; /* Method code. */ + char *prehook; /* The pre-hook name. */ + char *posthook; /* The post-hook name. */ + struct _ctorDef *next; /* Next in the list. */ +} ctorDef; + + +/* An enumerated type member definition. */ + +typedef struct _enumMemberDef { + nameDef *pyname; /* The Python name. */ + char *cname; /* The C/C++ name. */ + struct _enumDef *ed; /* The enclosing enum. */ + struct _enumMemberDef *next; /* Next in the list. */ +} enumMemberDef; + + +/* An enumerated type definition. */ + +typedef struct _enumDef { + int enumflags; /* The enum flags. */ + nameDef *pyname; /* The Python name (may be NULL). */ + scopedNameDef *fqcname; /* The C/C++ name (may be NULL). */ + nameDef *cname; /* The C/C++ name (may be NULL). */ + struct _enumDef *first_alt; /* The first alternate API. */ + struct _enumDef *next_alt; /* The next alternate API. */ + int enumnr; /* The enum number. */ + int enum_idx; /* The enum index within the module. */ + struct _classDef *ecd; /* The enclosing class, if any. */ + struct _mappedTypeDef *emtd; /* The enclosing mapped type, if any. */ + moduleDef *module; /* The owning module. */ + enumMemberDef *members; /* The list of members. */ + struct _memberDef *slots; /* The list of slots. */ + struct _overDef *overs; /* The list of slot overloads. */ + struct _enumDef *next; /* Next in the list. */ +} enumDef; + + +/* An member function definition. */ + +typedef struct _memberDef { + nameDef *pyname; /* The Python name. */ + int memberflags; /* The member flags. */ + int membernr; /* The index in the method table. */ + slotType slot; /* The slot type. */ + moduleDef *module; /* The owning module. */ + codeBlock *docstring; /* The overloads docstrings. */ + struct _memberDef *next; /* Next in the list. */ +} memberDef; + + +/* A list of visible member functions. */ + +typedef struct _visibleList { + memberDef *m; /* The member definition. */ + struct _classDef *cd; /* The class. */ + struct _visibleList *next; /* Next in the list. */ +} visibleList; + + +/* An entry in a linked class list. */ + +typedef struct _classList { + struct _classDef *cd; /* The class itself. */ + struct _classList *next; /* Next in the list. */ +} classList; + + +/* A virtual overload definition. */ + +typedef struct _virtOverDef { + overDef o; /* The overload. */ + struct _classDef *scope; /* The overload scope. */ + struct _virtOverDef *next; /* Next in the list. */ +} virtOverDef; + + +/* A class that appears in a class's hierarchy. */ + +typedef struct _mroDef { + struct _classDef *cd; /* The class. */ + int mroflags; /* The hierarchy flags. */ + struct _mroDef *next; /* The next in the list. */ +} mroDef; + + +/* A class definition. */ + +typedef struct _classDef { + int classflags; /* The class flags. */ + int pyqt4_flags; /* The PyQt4 specific flags. */ + nameDef *pyname; /* The Python name. */ + ifaceFileDef *iff; /* The interface file. */ + struct _classDef *ecd; /* The enclosing scope. */ + struct _classDef *real; /* The real class if this is a proxy or extender. */ + classList *supers; /* The parent classes. */ + mroDef *mro; /* The super-class hierarchy. */ + nameDef *metatype; /* The meta-type. */ + nameDef *supertype; /* The super-type. */ + templateDef *td; /* The instantiated template. */ + ctorDef *ctors; /* The constructors. */ + ctorDef *defctor; /* The default ctor. */ + codeBlock *dealloccode; /* Handwritten dealloc code. */ + codeBlock *dtorcode; /* Handwritten dtor code. */ + throwArgs *dtorexceptions; /* The dtor exceptions. */ + memberDef *members; /* The member functions. */ + overDef *overs; /* The overloads. */ + argList *casts; /* The operator casts. */ + virtOverDef *vmembers; /* The virtual members. */ + visibleList *visible; /* The visible members. */ + codeBlock *cppcode; /* Class C++ code. */ + codeBlock *convtosubcode; /* Convert to sub C++ code. */ + struct _classDef *subbase; /* Sub-class base class. */ + codeBlock *docstring; /* Ctor docstrings. */ + codeBlock *convtocode; /* Convert to C++ code. */ + codeBlock *travcode; /* Traverse code. */ + codeBlock *clearcode; /* Clear code. */ + codeBlock *getbufcode; /* Get buffer code (Python v3). */ + codeBlock *releasebufcode; /* Release buffer code (Python v3). */ + codeBlock *readbufcode; /* Read buffer code (Python v2). */ + codeBlock *writebufcode; /* Write buffer code (Python v2). */ + codeBlock *segcountcode; /* Segment count code (Python v2). */ + codeBlock *charbufcode; /* Character buffer code (Python v2). */ + codeBlock *picklecode; /* Pickle code. */ + struct _classDef *next; /* Next in the list. */ +} classDef; + + +/* A class template definition. */ + +typedef struct _classTmplDef { + signatureDef sig; /* The template arguments. */ + classDef *cd; /* The class itself. */ + struct _classTmplDef *next; /* The next in the list. */ +} classTmplDef; + + +/* A mapped type template definition. */ + +typedef struct _mappedTypeTmplDef { + signatureDef sig; /* The template arguments. */ + mappedTypeDef *mt; /* The mapped type itself. */ + struct _mappedTypeTmplDef *next; /* The next in the list. */ +} mappedTypeTmplDef; + + +/* The parse tree corresponding to the specification file. */ + +typedef struct { + moduleDef *module; /* The module being generated. */ + moduleDef *modules; /* The list of modules. */ + nameDef *namecache; /* The name cache. */ + ifaceFileDef *ifacefiles; /* The list of interface files. */ + classDef *classes; /* The list of classes. */ + classTmplDef *classtemplates; /* The list of class templates. */ + exceptionDef *exceptions; /* The list of exceptions. */ + mappedTypeDef *mappedtypes; /* The mapped types. */ + mappedTypeTmplDef *mappedtypetemplates; /* The list of mapped type templates. */ + enumDef *enums; /* List of enums. */ + varDef *vars; /* List of variables. */ + typedefDef *typedefs; /* List of typedefs. */ + codeBlock *exphdrcode; /* Exported header code. */ + codeBlock *docs; /* Documentation. */ + int sigslots; /* Set if signals or slots are used. */ + int genc; /* Set if we are generating C code. */ + struct _stringList *plugins; /* The list of plugins. */ +} sipSpec; + + +/* A list of strings. */ + +typedef struct _stringList { + const char *s; /* The string. */ + struct _stringList *next; /* The next in the list. */ +} stringList; + + +/* File specific context information for the parser. */ + +typedef struct _parserContext { + const char *filename; /* The %Import or %Include filename. */ + int ifdepth; /* The depth of nested if's. */ + moduleDef *prevmod; /* The previous module. */ +} parserContext; + + +extern char *sipVersion; /* The version of SIP. */ +extern stringList *includeDirList; /* The include directory list for SIP files. */ + + +void parse(sipSpec *, FILE *, char *, stringList *, stringList *, int, int); +void parserEOF(char *,parserContext *); +void transform(sipSpec *); +void generateCode(sipSpec *, char *, char *, char *, const char *, int, int, + int, int, stringList *, const char *, int); +void generateAPI(sipSpec *pt, moduleDef *mod, const char *apiFile); +void generateXML(sipSpec *pt, moduleDef *mod, const char *xmlFile); +void generateExpression(valueDef *vd, int in_str, FILE *fp); +void warning(char *,...); +void fatal(char *,...); +void fatalScopedName(scopedNameDef *); +int setInputFile(FILE *open_fp, parserContext *pc, int optional); +void *sipMalloc(size_t n); +void *sipCalloc(size_t nr, size_t n); +char *sipStrdup(const char *); +char *concat(const char *, ...); +void append(char **, const char *); +void addToUsedList(ifaceFileList **, ifaceFileDef *); +int excludedFeature(stringList *,qualDef *); +int sameSignature(signatureDef *,signatureDef *,int); +int sameTemplateSignature(signatureDef *tmpl_sd, signatureDef *args_sd, + int deep); +int compareScopedNames(scopedNameDef *snd1, scopedNameDef *snd2); +int sameBaseType(argDef *,argDef *); +char *scopedNameTail(scopedNameDef *); +scopedNameDef *copyScopedName(scopedNameDef *); +void appendScopedName(scopedNameDef **,scopedNameDef *); +void freeScopedName(scopedNameDef *); +void appendToClassList(classList **,classDef *); +void appendCodeBlock(codeBlock **headp, codeBlock *new); +void prcode(FILE *fp, const char *fmt, ...); +void prOverloadName(FILE *fp, overDef *od); +void prOverloadDecl(FILE *fp, ifaceFileDef *scope, overDef *od, int defval); +void prScopedPythonName(FILE *fp, classDef *scope, const char *pyname); +int prPythonSignature(sipSpec *pt, FILE *fp, signatureDef *sd, int sec, + int names, int defaults, int in_str, int is_signal); +void searchTypedefs(sipSpec *pt, scopedNameDef *snd, argDef *ad); +int isIntReturnSlot(memberDef *md); +int isSSizeReturnSlot(memberDef *md); +int isLongReturnSlot(memberDef *md); +int isVoidReturnSlot(memberDef *md); +int isNumberSlot(memberDef *md); +int isRichCompareSlot(memberDef *md); +mappedTypeDef *allocMappedType(sipSpec *pt, argDef *type); +void appendString(stringList **headp, const char *s); +void appendTypeStrings(scopedNameDef *ename, signatureDef *patt, signatureDef *src, signatureDef *known, scopedNameDef **names, scopedNameDef **values); +codeBlock *templateCode(sipSpec *pt, ifaceFileList **used, codeBlock *ocb, scopedNameDef *names, scopedNameDef *values); +ifaceFileDef *findIfaceFile(sipSpec *pt, moduleDef *mod, + scopedNameDef *fqname, ifaceFileType iftype, + apiVersionRangeDef *api_range, argDef *ad); +int pluginPyQt3(sipSpec *pt); +int pluginPyQt4(sipSpec *pt); +void yywarning(char *); +nameDef *cacheName(sipSpec *pt, const char *name); +scopedNameDef *encodedTemplateName(templateDef *td); +apiVersionRangeDef *findAPI(sipSpec *pt, const char *name); + + +/* These are only here because bison publically references them. */ + +/* Represent a set of option flags. */ + +#define MAX_NR_FLAGS 5 + +typedef enum { + bool_flag, + string_flag, + name_flag, + opt_name_flag, + dotted_name_flag, + integer_flag, + api_range_flag +} flagType; + +typedef struct { + char *fname; /* The flag name. */ + flagType ftype; /* The flag type. */ + union { /* The flag value. */ + char *sval; /* A string value. */ + long ival; /* An integer value. */ + apiVersionRangeDef *aval; /* An API range value. */ + } fvalue; +} optFlag; + +typedef struct { + int nrFlags; /* The number of flags. */ + optFlag flags[MAX_NR_FLAGS]; /* Each flag. */ +} optFlags; + +#endif diff --git a/sipgen/sipgen.sbf b/sipgen/sipgen.sbf new file mode 100644 index 0000000..3542663 --- /dev/null +++ b/sipgen/sipgen.sbf @@ -0,0 +1,19 @@ +# This is the build file for the code generator. +# +# Copyright (c) 2010 Riverbank Computing Limited <info@riverbankcomputing.com> +# +# This file is part of SIP. +# +# This copy of SIP is licensed for use under the terms of the SIP License +# Agreement. See the file LICENSE for more details. +# +# This copy of SIP may also used under the terms of the GNU General Public +# License v2 or v3 as published by the Free Software Foundation which can be +# found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package. +# +# SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +target = sip +sources = main.c transform.c gencode.c export.c heap.c parser.c lexer.c +headers = sip.h parser.h diff --git a/sipgen/transform.c b/sipgen/transform.c new file mode 100644 index 0000000..d24260f --- /dev/null +++ b/sipgen/transform.c @@ -0,0 +1,3445 @@ +/* + * The parse tree transformation module for SIP. + * + * Copyright (c) 2010 Riverbank Computing Limited <info@riverbankcomputing.com> + * + * This file is part of SIP. + * + * This copy of SIP is licensed for use under the terms of the SIP License + * Agreement. See the file LICENSE for more details. + * + * This copy of SIP may also used under the terms of the GNU General Public + * License v2 or v3 as published by the Free Software Foundation which can be + * found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package. + * + * SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + + +#include <stddef.h> +#include <string.h> +#include <stdlib.h> + +#include "sip.h" + + +static int samePythonSignature(signatureDef *sd1, signatureDef *sd2); +static int nextSignificantArg(signatureDef *sd, int a); +static int sameArgType(argDef *a1, argDef *a2, int strict); +static int supportedType(classDef *,overDef *,argDef *,int); +static int sameOverload(overDef *od1, overDef *od2); +static int sameVirtualHandler(virtHandlerDef *vhd1,virtHandlerDef *vhd2); +static int isSubClass(classDef *cc,classDef *pc); +static void setAllImports(moduleDef *mod); +static void addUniqueModule(moduleDef *mod, moduleDef *imp); +static void ensureInput(classDef *,overDef *,argDef *); +static void defaultInput(argDef *); +static void defaultOutput(argDef *ad); +static void createSortedNumberedTypesTable(sipSpec *pt, moduleDef *mod); +static int compareTypes(const void *t1, const void *t2); +static void addAutoOverload(sipSpec *,classDef *,overDef *); +static void ifaceFileIsUsed(ifaceFileList **used, argDef *ad); +static void ifaceFilesAreUsedByOverload(ifaceFileList **used, overDef *od); +static void ifaceFilesAreUsedBySignature(ifaceFileList **used, + signatureDef *sd); +static void scopeDefaultValue(sipSpec *,classDef *,argDef *); +static void setHierarchy(sipSpec *,classDef *,classDef *,classList **); +static void transformModules(sipSpec *pt, moduleDef *mod); +static void transformCtors(sipSpec *,classDef *); +static void transformCasts(sipSpec *,classDef *); +static void addDefaultCopyCtor(classDef *); +static void transformScopeOverloads(sipSpec *pt, classDef *c_scope, + mappedTypeDef *mt_scope, overDef *overs); +static void transformVariableList(sipSpec *pt, moduleDef *mod); +static void transformMappedTypes(sipSpec *pt, moduleDef *mod); +static void getVisibleMembers(sipSpec *,classDef *); +static void getVirtuals(sipSpec *pt,classDef *cd); +static void getClassVirtuals(classDef *,classDef *); +static void transformTypedefs(sipSpec *pt, moduleDef *mod); +static void resolveMappedTypeTypes(sipSpec *,mappedTypeDef *); +static void resolveCtorTypes(sipSpec *,classDef *,ctorDef *); +static void resolveFuncTypes(sipSpec *pt, moduleDef *mod, classDef *c_scope, + mappedTypeDef *mt_scope, overDef *od); +static void resolvePySigTypes(sipSpec *,moduleDef *,classDef *,overDef *,signatureDef *,int); +static void resolveVariableType(sipSpec *,varDef *); +static void fatalNoDefinedType(scopedNameDef *); +static void getBaseType(sipSpec *,moduleDef *,classDef *,argDef *); +static void searchClassScope(sipSpec *,classDef *,scopedNameDef *,argDef *); +static void searchMappedTypes(sipSpec *,moduleDef *,scopedNameDef *,argDef *); +static void searchEnums(sipSpec *,scopedNameDef *,argDef *); +static void searchClasses(sipSpec *,moduleDef *mod,scopedNameDef *,argDef *); +static void appendToMRO(mroDef *,mroDef ***,classDef *); +static void moveMainModuleCastsSlots(sipSpec *pt, moduleDef *mod); +static void moveClassCasts(sipSpec *pt, moduleDef *mod, classDef *cd); +static void moveGlobalSlot(sipSpec *pt, moduleDef *mod, memberDef *gmd); +static classDef *findAltClassImplementation(sipSpec *pt, mappedTypeDef *mtd); +static void filterMainModuleVirtualHandlers(moduleDef *mod); +static void filterModuleVirtualHandlers(moduleDef *mod); +static ifaceFileDef *getIfaceFile(argDef *ad); +static mappedTypeDef *instantiateMappedTypeTemplate(sipSpec *pt, moduleDef *mod, mappedTypeTmplDef *mtt, argDef *type); +static classDef *getProxy(moduleDef *mod, classDef *cd); +static int generatingCodeForModule(sipSpec *pt, moduleDef *mod); +static void checkAssignmentHelper(sipSpec *pt, classDef *cd); +static void addComplementarySlots(sipSpec *pt, classDef *cd); +static void addComplementarySlot(sipSpec *pt, classDef *cd, memberDef *md, + slotType cslot, const char *cslot_name); +static void resolveInstantiatedClassTemplate(sipSpec *pt, argDef *type); +static void setStringPoolOffsets(sipSpec *pt); +static const char *templateString(const char *src, scopedNameDef *names, + scopedNameDef *values); + + +/* + * Transform the parse tree. + */ + +void transform(sipSpec *pt) +{ + moduleDef *mod; + classDef *cd, *rev, **tail; + classList *newl; + overDef *od; + + /* + * The class list has the main module's classes at the front and the ones + * from the module at the most nested %Import at the end. This affects + * some of the following algorithms. We have to have consistency whenever + * a module is used. To achieve this we reverse the order of the classes. + */ + rev = NULL; + cd = pt -> classes; + + while (cd != NULL) + { + classDef *next = cd -> next; + + cd -> next = rev; + rev = cd; + + /* + * Mark any QObject class. This flag will ripple through all derived + * classes when we set the hierarchy. + */ + if (strcmp(classBaseName(cd), "QObject") == 0) + setIsQObjectSubClass(cd); + + cd = next; + } + + pt -> classes = rev; + + /* + * Build the list of all imports for each module and check each has been + * named. + */ + for (mod = pt->modules; mod != NULL; mod = mod->next) + { + if (mod->name == NULL) + fatal("A module is missing a %%Module or %%CModule directive\n"); + + setAllImports(mod); + } + + /* + * Set the default meta-type for the main module if it doesn't have one + * explicitly set. + */ + if (pt->module->defmetatype == NULL) + { + moduleListDef *mld; + + for (mld = pt->module->allimports; mld != NULL; mld = mld->next) + { + if (mld->module->defmetatype == NULL) + continue; + + if (pt->module->defmetatype == NULL) + pt->module->defmetatype = mld->module->defmetatype; + else if (pt->module->defmetatype != mld->module->defmetatype) + fatal("The %s module has imported different default meta-types %s and %s\n", + pt->module->fullname->text, + pt->module->defmetatype->text, + mld->module->defmetatype->text); + } + } + + /* Check each class has been defined. */ + for (cd = pt -> classes; cd != NULL; cd = cd -> next) + if (cd -> iff -> module == NULL) + { + fatalScopedName(classFQCName(cd)); + fatal(" has not been defined\n"); + } + + /* + * Set the super-class hierarchy for each class and re-order the list of + * classes so that no class appears before a super class or an enclosing + * scope class. + */ + newl = NULL; + + for (cd = pt -> classes; cd != NULL; cd = cd -> next) + setHierarchy(pt,cd,cd,&newl); + + /* Replace the old list with the new one. */ + tail = &pt -> classes; + + while (newl != NULL) + { + classList *cl = newl; + + *tail = cl -> cd; + tail = &cl -> cd -> next; + + newl = cl -> next; + free(cl); + } + + *tail = NULL; + + /* Transform the various types in the modules. */ + if (isConsolidated(pt->module)) + { + /* Transform the modules included by the consolidated module. */ + for (mod = pt->modules->next; mod != NULL; mod = mod->next) + transformModules(pt, mod); + } + else + { + transformModules(pt, pt->modules); + } + + /* Handle default ctors now that the argument types are resolved. */ + if (!pt->genc) + for (cd = pt->classes; cd != NULL; cd = cd->next) + if (!noDefaultCtors(cd) && !isOpaque(cd) && cd->iff->type != namespace_iface) + addDefaultCopyCtor(cd); + + /* Create the array of numbered types sorted by type name. */ + for (mod = pt->modules; mod != NULL; mod = mod->next) + createSortedNumberedTypesTable(pt, mod); + + /* Add any automatically generated methods. */ + for (cd = pt -> classes; cd != NULL; cd = cd -> next) + for (od = cd -> overs; od != NULL; od = od -> next) + if (isAutoGen(od)) + addAutoOverload(pt,cd,od); + + /* + * Move casts and slots around to their correct classes (if in the same + * module) or create proxies for them (if cross-module). + */ + if (!pt->genc) + for (mod = pt->modules; mod != NULL; mod = mod->next) + if (generatingCodeForModule(pt, mod)) + moveMainModuleCastsSlots(pt, mod); + + /* Automatically generate missing complementary slots. */ + if (!pt->genc) + { + for (cd = pt->classes; cd != NULL; cd = cd->next) + addComplementarySlots(pt, cd); + + for (mod = pt->modules; mod != NULL; mod = mod->next) + if (generatingCodeForModule(pt, mod)) + for (cd = mod->proxies; cd != NULL; cd = cd->next) + addComplementarySlots(pt, cd); + } + + /* Generate the different class views. */ + for (cd = pt->classes; cd != NULL; cd = cd->next) + if (cd->iff->type == class_iface) + { + /* Get the list of visible member functions. */ + getVisibleMembers(pt, cd); + + /* Get the virtual members. */ + if (hasShadow(cd)) + getVirtuals(pt, cd); + } + else if (cd->iff->type == namespace_iface) + for (od = cd->overs; od != NULL; od = od->next) + ifaceFilesAreUsedByOverload(&cd->iff->used, od); + + /* + * Filter the virtuals of all component modules (if consolidated) or the + * main module (if not). + */ + for (mod = pt->modules; mod != NULL; mod = mod->next) + { + if (generatingCodeForModule(pt, mod)) + { + filterMainModuleVirtualHandlers(mod); + + for (od = mod->overs; od != NULL; od = od->next) + ifaceFilesAreUsedByOverload(&mod->used, od); + } + + /* Update proxies with some information from the real classes. */ + for (cd = mod->proxies; cd != NULL; cd = cd->next) + cd->iff->ifacenr = cd->real->iff->ifacenr; + } + + /* Mark classes that can have an assignment helper. */ + for (cd = pt->classes; cd != NULL; cd = cd->next) + checkAssignmentHelper(pt, cd); + + setStringPoolOffsets(pt); +} + + +/* + * Transform a module and the modules it imports. + */ +static void transformModules(sipSpec *pt, moduleDef *mod) +{ + classDef *cd; + moduleListDef *mld; + + /* Handle the trivial case. */ + if (isTransformed(mod)) + return; + + /* + * The modules on which this one depends must be done first because they + * might generate new template-based types and they must be defined in the + * right module. + */ + for (mld = mod->imports; mld != NULL; mld = mld->next) + transformModules(pt, mld->module); + + /* Transform typedefs, variables and global functions. */ + transformTypedefs(pt, mod); + transformVariableList(pt, mod); + transformScopeOverloads(pt, NULL, NULL, mod->overs); + + /* Transform class ctors, functions and casts. */ + for (cd = pt->classes; cd != NULL; cd = cd->next) + { + if (cd->iff->module == mod) + { + transformCtors(pt, cd); + + if (!pt->genc) + { + transformScopeOverloads(pt, cd, NULL, cd->overs); + transformCasts(pt, cd); + } + } + } + + /* Transform mapped types based on templates. */ + transformMappedTypes(pt, mod); + + setIsTransformed(mod); +} + + +/* + * Set the offset into the string pool for every used name. + */ +static void setStringPoolOffsets(sipSpec *pt) +{ + nameDef *nd; + size_t offset = 0; + + for (nd = pt->namecache; nd != NULL; nd = nd->next) + { + size_t len; + nameDef *prev; + + if (!isUsedName(nd)) + continue; + + /* See if the tail of a previous used name could be used instead. */ + len = nd->len; + + for (prev = pt->namecache; prev->len > len; prev = prev->next) + { + size_t pos; + + if (!isUsedName(prev) || isSubstring(prev)) + continue; + + pos = prev->len - len; + + if (memcmp(&prev->text[pos], nd->text, len) == 0) + { + setIsSubstring(nd); + nd->offset = prev->offset + pos; + break; + } + } + + if (!isSubstring(nd)) + { + nd->offset = offset; + offset += len + 1; + } + } +} + + +/* + * Add any missing complementary slots to a class. This emulates the C++ + * behaviour of automatically interpreting (for example) >= as !<. + */ +static void addComplementarySlots(sipSpec *pt, classDef *cd) +{ + memberDef *md; + + for (md = cd->members; md != NULL; md = md->next) + switch (md->slot) + { + case lt_slot: + addComplementarySlot(pt, cd, md, ge_slot, "__ge__"); + break; + + case le_slot: + addComplementarySlot(pt, cd, md, gt_slot, "__gt__"); + break; + + case gt_slot: + addComplementarySlot(pt, cd, md, le_slot, "__le__"); + break; + + case ge_slot: + addComplementarySlot(pt, cd, md, lt_slot, "__lt__"); + break; + + case eq_slot: + addComplementarySlot(pt, cd, md, ne_slot, "__ne__"); + break; + + case ne_slot: + addComplementarySlot(pt, cd, md, eq_slot, "__eq__"); + break; + } +} + + +/* + * Add a complementary slot if it is missing. + */ +static void addComplementarySlot(sipSpec *pt, classDef *cd, memberDef *md, + slotType cslot, const char *cslot_name) +{ + overDef *od1; + memberDef *md2 = NULL; + + for (od1 = cd->overs; od1 != NULL; od1 = od1->next) + { + overDef *od2; + + if (od1->common != md || isComplementary(od1) || od1->methodcode != NULL) + continue; + + /* Try and find an existing complementary slot. */ + for (od2 = cd->overs; od2 != NULL; od2 = od2->next) + if (od2->common->slot == cslot && sameSignature(&od1->pysig, &od2->pysig, TRUE)) + break; + + /* + * If there is an explicit complementary slot then there is nothing to + * do. + */ + if (od2 != NULL) + continue; + + /* Create a new member if needed. */ + if (md2 == NULL) + { + for (md2 = cd->members; md2 != NULL; md2 = md2->next) + if (md2->slot == cslot) + break; + + if (md2 == NULL) + { + md2 = sipMalloc(sizeof (memberDef)); + + md2->pyname = cacheName(pt, cslot_name); + md2->memberflags = md->memberflags; + md2->slot = cslot; + md2->module = md->module; + + md2->next = cd->members; + cd->members = md2; + + if (isUsedName(md->pyname)) + setIsUsedName(md2->pyname); + } + } + + /* Create the complementary slot. */ + od2 = sipMalloc(sizeof (overDef)); + + *od2 = *od1; + resetIsVirtual(od2); + setIsComplementary(od2); + od2->common = md2; + + od2->next = cd->overs; + cd->overs = od2; + } +} + + +/* + * See if a class supports an assignment helper. + */ +static void checkAssignmentHelper(sipSpec *pt, classDef *cd) +{ + int pub_def_ctor, pub_copy_ctor; + ctorDef *ct; + + /* + * We register types with Qt if the class is not abstract, doesn't have a + * private assignment operator, has a public default ctor, a public copy + * ctor and a public dtor. + */ + if (isAbstractClass(cd)) + return; + + if (cannotAssign(cd)) + return; + + if (!isPublicDtor(cd)) + return; + + pub_def_ctor = pub_copy_ctor = FALSE; + + for (ct = cd->ctors; ct != NULL; ct = ct->next) + { + if (ct->cppsig == NULL || !isPublicCtor(ct)) + continue; + + if (ct->cppsig->nrArgs == 0 || ct->cppsig->args[0].defval != NULL) + { + /* + * The ctor either has no arguments or all arguments have defaults. + */ + pub_def_ctor = TRUE; + } + else if (ct->cppsig->nrArgs == 1) + { + argDef *ad = &ct->cppsig->args[0]; + classDef *arg_cd; + + if (ad->atype == class_type) + arg_cd = ad->u.cd; + else if (ad->atype == mapped_type) + arg_cd = findAltClassImplementation(pt, ad->u.mtd); + else + arg_cd = NULL; + + if (arg_cd == cd && isReference(ad) && isConstArg(ad) && + ad->nrderefs == 0 && ad->defval == NULL) + pub_copy_ctor = TRUE; + } + } + + if (pub_def_ctor && pub_copy_ctor) + { + setAssignmentHelper(cd); + addToUsedList(&cd->iff->module->used, cd->iff); + } +} + + +/* + * Set the list of all imports for a module. The list is ordered so that a + * module appears before any module that imports it. + */ +static void setAllImports(moduleDef *mod) +{ + moduleListDef *mld; + + /* + * Handle the trivial case where there are no imports, or the list has + * already been done. + */ + if (mod->imports == NULL || mod->allimports != NULL) + return; + + /* Make sure all the direct imports are done first. */ + for (mld = mod->imports; mld != NULL; mld = mld->next) + setAllImports(mld->module); + + /* + * Now build the list from our direct imports lists but ignoring + * duplicates. + */ + for (mld = mod->imports; mld != NULL; mld = mld->next) + { + moduleListDef *amld; + + for (amld = mld->module->allimports; amld != NULL; amld = amld->next) + addUniqueModule(mod, amld->module); + + addUniqueModule(mod, mld->module); + } +} + + +/* + * Append a module to the list of all imported modules if it isn't already + * there. + */ +static void addUniqueModule(moduleDef *mod, moduleDef *imp) +{ + moduleListDef **tail; + + for (tail = &mod->allimports; *tail != NULL; tail = &(*tail)->next) + if ((*tail)->module == imp) + return; + + *tail = sipMalloc(sizeof (moduleListDef)); + + (*tail)->module = imp; + (*tail)->next = NULL; +} + + +/* + * Move the casts and slots to the correct place for a main module (ie. one we + * are generating code for). + */ +static void moveMainModuleCastsSlots(sipSpec *pt, moduleDef *mod) +{ + classDef *cd; + memberDef *md; + + for (cd = pt->classes; cd != NULL; cd = cd->next) + if (cd->iff->module == mod) + moveClassCasts(pt, mod, cd); + + for (md = mod->othfuncs; md != NULL; md = md->next) + if (md->slot != no_slot && md->module == mod) + moveGlobalSlot(pt, mod, md); +} + + +/* + * Move any class casts to its correct class, or publish as a ctor extender. + */ +static void moveClassCasts(sipSpec *pt, moduleDef *mod, classDef *cd) +{ + argList *al; + + for (al = cd->casts; al != NULL; al = al->next) + { + classDef *dcd = al->arg.u.cd; + ctorDef *ct, **ctp; + argDef *ad; + + if (al->arg.atype == class_type) + dcd = al->arg.u.cd; + else + /* Previous error checking means this will always work. */ + dcd = findAltClassImplementation(pt, al->arg.u.mtd); + + /* + * If the destination class is in a different module then use + * a proxy. + */ + if (dcd->iff->module != mod) + dcd = getProxy(mod, dcd); + + /* Create the new ctor. */ + ct = sipMalloc(sizeof (ctorDef)); + + ct->ctorflags = SECT_IS_PUBLIC | CTOR_CAST; + ct->cppsig = &ct->pysig; + + /* Add the source class as the only argument. */ + ct->pysig.result.atype = void_type; + ad = &ct->pysig.args[0]; + + ad->atype = class_type; + ad->name = NULL; + ad->argflags = ARG_IN | (al->arg.argflags & (ARG_IS_REF | ARG_IS_CONST)); + ad->nrderefs = al->arg.nrderefs; + ad->defval = NULL; + ad->u.cd = cd; + + ifaceFileIsUsed(&dcd->iff->used, ad); + + ct->pysig.nrArgs = 1; + + /* Append it to the list. */ + for (ctp = &dcd->ctors; *ctp != NULL; ctp = &(*ctp)->next) + if (sameSignature(&(*ctp)->pysig, &ct->pysig, FALSE)) + { + fatal("operator "); + fatalScopedName(classFQCName(dcd)); + fatal("::"); + fatalScopedName(classFQCName(dcd)); + fatal("("); + fatalScopedName(classFQCName(cd)); + fatal(") already defined\n"); + } + + *ctp = ct; + } +} + + +/* + * If possible, move a global slot to its correct class. + */ +static void moveGlobalSlot(sipSpec *pt, moduleDef *mod, memberDef *gmd) +{ + overDef **odp = &mod->overs, *od; + + while ((od = *odp) != NULL) + { + int second; + argDef *arg0, *arg1; + memberDef *md, **mdhead; + overDef **odhead; + moduleDef *mod; + nameDef *nd; + + if (od->common != gmd) + { + odp = &od->next; + continue; + } + + /* + * We know that the slot has the right number of arguments, but the + * first or second one needs to be a class or enum defined in the same + * module. Otherwise we leave it as it is and publish it as a slot + * extender. + */ + arg0 = &od->pysig.args[0]; + arg1 = &od->pysig.args[1]; + + mdhead = NULL; + second = FALSE; + nd = NULL; + + if (arg0->atype == class_type) + { + mdhead = &arg0->u.cd->members; + odhead = &arg0->u.cd->overs; + mod = arg0->u.cd->iff->module; + } + else if (arg0->atype == mapped_type) + { + classDef *cd = findAltClassImplementation(pt, arg0->u.mtd); + + if (cd != NULL) + { + mdhead = &cd->members; + odhead = &cd->overs; + mod = cd->iff->module; + } + } + else if (arg0->atype == enum_type) + { + mdhead = &arg0->u.ed->slots; + odhead = &arg0->u.ed->overs; + mod = arg0->u.ed->module; + nd = arg0->u.ed->pyname; + } + else if (arg1->atype == class_type) + { + mdhead = &arg1->u.cd->members; + odhead = &arg1->u.cd->overs; + mod = arg1->u.cd->iff->module; + second = TRUE; + } + else if (arg1->atype == mapped_type) + { + classDef *cd = findAltClassImplementation(pt, arg1->u.mtd); + + if (cd != NULL) + { + mdhead = &cd->members; + odhead = &cd->overs; + mod = cd->iff->module; + second = TRUE; + } + } + else if (arg1->atype == enum_type) + { + mdhead = &arg1->u.ed->slots; + odhead = &arg1->u.ed->overs; + mod = arg1->u.ed->module; + nd = arg1->u.ed->pyname; + second = TRUE; + } + + if (mdhead == NULL) + { + fatal("One of the arguments of "); + prOverloadName(stderr, od); + fatal(" must be a class or enum\n"); + } + + /* + * For rich comparisons the first argument must be a class or an enum. + * For cross-module slots then it may only be a class. (This latter + * limitation is artificial, but is unlikely to be a problem in + * practice.) + */ + if (isRichCompareSlot(gmd)) + { + if (second) + { + fatal("The first argument of "); + prOverloadName(stderr, od); + fatal(" must be a class or enum\n"); + } + + if (mod != gmd->module && arg0->atype == enum_type) + { + fatal("The first argument of "); + prOverloadName(stderr, od); + fatal(" must be a class\n"); + } + } + + if (mod != gmd->module) + { + if (isRichCompareSlot(gmd)) + { + classDef *pcd = getProxy(mod, arg0->u.cd); + memberDef *pmd; + overDef *pod; + + /* Create a new proxy member if needed. */ + for (pmd = pcd->members; pmd != NULL; pmd = pmd->next) + if (pmd->slot == gmd->slot) + break; + + if (pmd == NULL) + { + pmd = sipMalloc(sizeof (memberDef)); + + pmd->pyname = gmd->pyname; + pmd->memberflags = 0; + pmd->slot = gmd->slot; + pmd->module = mod; + pmd->next = pcd->members; + + pcd->members = pmd; + } + + /* Add the proxy overload. */ + pod = sipMalloc(sizeof (overDef)); + + *pod = *od; + pod->common = pmd; + pod->next = pcd->overs; + + pcd->overs = pod; + + /* Remove the first argument. */ + pod->pysig.args[0] = pod->pysig.args[1]; + pod->pysig.nrArgs = 1; + + /* Remove from the list. */ + *odp = od->next; + } + else + odp = &od->next; + + continue; + } + + /* Remove from the list. */ + *odp = od->next; + + /* The only time we need the name of an enum is when it has slots. */ + if (nd != NULL) + setIsUsedName(nd); + + /* See if there is already a member or create a new one. */ + for (md = *mdhead; md != NULL; md = md->next) + if (md->slot == gmd->slot) + break; + + if (md == NULL) + { + md = sipMalloc(sizeof (memberDef)); + + *md = *gmd; + + md->module = mod; + md->next = *mdhead; + + *mdhead = md; + } + + /* Move the overload to the end of the destination list. */ + setIsPublic(od); + setIsGlobal(od); + od->common = md; + od->next = NULL; + + while (*odhead != NULL) + odhead = &(*odhead)->next; + + *odhead = od; + + /* Remove the first argument of comparison operators. */ + if (isRichCompareSlot(md)) + { + /* Remember if the argument was a pointer. */ + if (arg0->nrderefs > 0) + setDontDerefSelf(od); + + *arg0 = *arg1; + od->pysig.nrArgs = 1; + } + } +} + + +/* + * Return an alternative class implementation of a mapped type if there is + * one. Note that we cheat as we assume there is one going to be one (as + * there will be in PyQt at the moment). + */ +static classDef *findAltClassImplementation(sipSpec *pt, mappedTypeDef *mtd) +{ + ifaceFileDef *iff = mtd->iff->first_alt; + + while (iff != NULL) + { + if (iff->type == class_iface) + { + classDef *cd; + + for (cd = pt->classes; cd != NULL; cd = cd->next) + if (cd->iff == iff) + return cd; + } + + iff = iff->next_alt; + } + + return NULL; +} + + +/* + * Create a proxy for a class if it doesn't already exist. Proxies are used as + * containers for cross-module extenders. + */ +static classDef *getProxy(moduleDef *mod, classDef *cd) +{ + classDef *pcd; + + for (pcd = mod->proxies; pcd != NULL; pcd = pcd->next) + if (pcd->iff == cd->iff) + return pcd; + + pcd = sipMalloc(sizeof (classDef)); + + pcd->pyname = cd->pyname; + pcd->iff = cd->iff; + pcd->ecd = cd->ecd; + pcd->real = cd; + pcd->supers = cd->supers; + pcd->mro = cd->mro; + pcd->next = mod->proxies; + + mod->proxies = pcd; + + return pcd; +} + + +/* + * Filter the virtual handlers for a main module (ie. one we are generating + * code for. + */ +static void filterMainModuleVirtualHandlers(moduleDef *mod) +{ + moduleListDef *mld; + virtHandlerDef *vhd; + + /* + * Remove redundant virtual handlers. It's important that earlier, ie. + * those at the deepest level of %Import, are done first. + */ + for (mld = mod->allimports; mld != NULL; mld = mld->next) + filterModuleVirtualHandlers(mld->module); + + filterModuleVirtualHandlers(mod); + + /* + * Make sure we have the interface files for all types from other modules + * that are used in virtual handlers implemented in this module. + */ + for (vhd = mod->virthandlers; vhd != NULL; vhd = vhd->next) + if (!isDuplicateVH(vhd)) + ifaceFilesAreUsedBySignature(&mod->used, vhd->cppsig); +} + + +/* + * Go through the virtual handlers filtering those that can duplicate earlier + * ones. Make sure each virtual is numbered within its module, and according + * to their position in the list (ignoring duplicates). + */ +static void filterModuleVirtualHandlers(moduleDef *mod) +{ + virtHandlerDef *vhd; + + /* See if it has already been done for this module. */ + if (mod->nrvirthandlers >= 0) + return; + + mod->nrvirthandlers = 0; + + for (vhd = mod->virthandlers; vhd != NULL; vhd = vhd->next) + { + virtHandlerDef *best, *best_thismod, *hd; + + best = best_thismod = NULL; + + /* + * If this has handwritten code then we will want to use it. + * Otherwise, look for a handler in earlier modules. + */ + if (vhd->virtcode == NULL) + { + moduleListDef *mld; + + for (mld = mod->allimports; mld != NULL && mld->module != mod; mld = mld->next) + { + for (hd = mld->module->virthandlers; hd != NULL; hd = hd->next) + if (sameVirtualHandler(vhd, hd)) + { + best = hd; + break; + } + + /* + * No need to check later modules as this will either be the + * right one, or a duplicate of the right one. + */ + if (best != NULL) + break; + } + } + + /* + * Find the best candidate in this module in case we want to give it + * our handwritten code. + */ + for (hd = mod->virthandlers; hd != vhd; hd = hd->next) + if (sameVirtualHandler(vhd, hd)) + { + best_thismod = hd; + break; + } + + /* + * We don't use this one if it doesn't have virtual code and there is + * an alternative, or if it does have virtual code and there is already + * an alternative in the same module which doesn't have virtual code. + */ + if ((vhd->virtcode == NULL && (best != NULL || best_thismod != NULL)) || + (vhd->virtcode != NULL && best_thismod != NULL && best_thismod->virtcode == NULL)) + { + virtHandlerDef *saved; + + /* + * If the alternative is in the same module and we have virtual + * code then give it to the alternative. Note that there is a bug + * here. If there are three handlers, the first without code and + * the second and third with code then which code is transfered to + * the first is down to luck. We should really only transfer code + * to methods that are known to be re-implementations - just having + * the same signature isn't enough. + */ + if (best_thismod != NULL) + { + if (best_thismod->virtcode == NULL && vhd->virtcode != NULL) + { + best_thismod->virtcode = vhd->virtcode; + resetIsDuplicateVH(best_thismod); + } + + best = best_thismod; + } + + /* Use the better one in place of this one. */ + saved = vhd->next; + *vhd = *best; + setIsDuplicateVH(vhd); + vhd->next = saved; + } + else + vhd->virthandlernr = mod->nrvirthandlers++; + } +} + + +/* + * Add an overload that is automatically generated (typically by Qt's moc). + */ +static void addAutoOverload(sipSpec *pt,classDef *autocd,overDef *autood) +{ + classDef *cd; + + /* Find every class that has this one in its hierarchy. */ + + for (cd = pt -> classes; cd != NULL; cd = cd -> next) + { + mroDef *mro; + + if (cd == autocd) + continue; + + for (mro = cd -> mro; mro != NULL; mro = mro -> next) + if (mro -> cd == autocd) + { + memberDef *md; + overDef *od; + + /* Another overload may already exist. */ + + for (md = cd -> members; md != NULL; md = md -> next) + if (md -> pyname == autood -> common -> pyname) + break; + + if (md == NULL) + { + md = sipMalloc(sizeof (memberDef)); + + md -> pyname = autood -> common -> pyname; + md -> memberflags = autood -> common -> memberflags; + md -> slot = autood -> common -> slot; + md -> module = cd -> iff -> module; + md -> next = cd -> members; + cd -> members = md; + } + + od = sipMalloc(sizeof (overDef)); + + *od = *autood; + od -> common = md; + od -> next = cd -> overs; + cd -> overs = od; + + resetIsAutoGen(od); + + if (generatingCodeForModule(pt, cd->iff->module)) + setIsUsedName(md -> pyname); + + break; + } + } +} + + +/* + * Set the complete hierarchy for a class. + */ +static void setHierarchy(sipSpec *pt, classDef *base, classDef *cd, + classList **head) +{ + mroDef **tailp = &cd->mro; + + /* See if it has already been done. */ + if (cd->mro != NULL) + return; + + if (cd->ecd != NULL) + { + setHierarchy(pt, base, cd->ecd, head); + + if (isDeprecatedClass(cd->ecd)) + setIsDeprecatedClass(cd); + } + + if (cd->iff->type == class_iface) + { + classList *cl; + + /* The first thing is itself. */ + appendToMRO(cd->mro, &tailp, cd); + + if (cd->convtosubcode != NULL) + cd->subbase = cd; + + /* Now do it's superclasses. */ + setHierBeingSet(cd->mro); + + for (cl = cd->supers; cl != NULL; cl = cl->next) + { + mroDef *mro; + + if (cl->cd->mro != NULL && hierBeingSet(cl->cd->mro)) + { + fatal("Recursive class hierarchy detected: "); + fatalScopedName(classFQCName(cd)); + fatal(" and "); + fatalScopedName(classFQCName(cl->cd)); + fatal("\n"); + } + + /* Make sure the super-class's hierarchy has been done. */ + setHierarchy(pt, base, cl->cd, head); + + /* Append the super-classes hierarchy. */ + for (mro = cl->cd->mro; mro != NULL; mro = mro->next) + { + appendToMRO(cd->mro, &tailp, mro->cd); + + if (isDeprecatedClass(mro->cd)) + setIsDeprecatedClass(cd); + + /* + * If the super-class is a QObject sub-class then this one is + * as well. + */ + if (isQObjectSubClass(mro->cd)) + setIsQObjectSubClass(cd); + + /* + * If the super-class can't be assigned to then this one + * cannot either. + */ + if (cannotAssign(mro->cd)) + setCannotAssign(cd); + + /* + * If the super-class has a shadow then this one should have + * one as well. + */ + if (hasShadow(mro->cd)) + setHasShadow(cd); + + /* + * Ensure that the sub-class base class is the furthest up the + * hierarchy. + */ + if (mro->cd->subbase != NULL) + cd->subbase = mro->cd->subbase; + } + } + + resetHierBeingSet(cd->mro); + + /* + * If the class doesn't have an explicit meta-type then inherit from + * the module's default. + */ + if (cd->metatype == NULL && cd->supers == NULL) + cd->metatype = cd->iff->module->defmetatype; + + if (cd->metatype != NULL && generatingCodeForModule(pt, cd->iff->module)) + setIsUsedName(cd->metatype); + + /* + * If the class doesn't have an explicit super-type then inherit from + * the module's default. + */ + if (cd->supertype == NULL && cd->supers == NULL) + cd->supertype = cd->iff->module->defsupertype; + + if (cd->supertype != NULL && strcmp(cd->supertype->text, "sip.wrapper") == 0) + cd->supertype = NULL; + + if (cd->supertype != NULL && generatingCodeForModule(pt, cd->iff->module)) + setIsUsedName(cd->supertype); + } + + /* + * Make sure that the module in which a sub-class convertor will be created + * knows about the base class. + */ + if (cd->subbase != NULL) + addToUsedList(&cd->iff->module->used, cd->subbase->iff); + + /* + * We can't have a shadow if the specification is incomplete, there is + * a private dtor, there are no none-private ctors or there are private + * abstract methods. + */ + if (isIncomplete(cd) || isPrivateDtor(cd) || !canCreate(cd)) + resetHasShadow(cd); + else + { + overDef *od; + + /* + * Note that we should be able to provide better support for + * abstract private methods than we do at the moment. + */ + for (od = cd->overs; od != NULL; od = od->next) + if (isAbstract(od) && isPrivate(od)) + { + resetHasShadow(cd); + + /* + * It also means we cannot create an instance + * from Python. + */ + resetCanCreate(cd); + + break; + } + } + + /* Add it to the new list. */ + appendToClassList(head,cd); +} + + +/* + * Append a class definition to an mro list + */ +static void appendToMRO(mroDef *head,mroDef ***tailp,classDef *cd) +{ + mroDef *mro, *new; + + new = sipMalloc(sizeof (mroDef)); + + new -> cd = cd; + new -> mroflags = 0; + new -> next = NULL; + + /* See if it is a duplicate. */ + + for (mro = head; mro != NULL; mro = mro -> next) + if (mro -> cd == cd) + { + setIsDuplicateSuper(new); + + if (!isDuplicateSuper(mro)) + setHasDuplicateSuper(mro); + + break; + } + + /* Append to the list and update the tail pointer. */ + **tailp = new; + *tailp = &new -> next; +} + + +/* + * Get the base types for all typedefs of a module. + */ +static void transformTypedefs(sipSpec *pt, moduleDef *mod) +{ + typedefDef *td; + + for (td = pt->typedefs; td != NULL; td = td->next) + if (td->module == mod) + getBaseType(pt, td->module, td->ecd, &td->type); +} + + +/* + * Transform the data types for mapped types based on a template. + */ +static void transformMappedTypes(sipSpec *pt, moduleDef *mod) +{ + mappedTypeDef *mt; + + for (mt = pt->mappedtypes; mt != NULL; mt = mt->next) + { + if (mt->iff->module == mod) + { + if (mt->type.atype == template_type) + resolveMappedTypeTypes(pt, mt); + else + transformScopeOverloads(pt, NULL, mt, mt->overs); + } + } +} + + +/* + * Transform the data types for a list of ctors. + */ +static void transformCtors(sipSpec *pt, classDef *cd) +{ + ctorDef *ct; + + for (ct = cd->ctors; ct != NULL; ct = ct->next) + { + ctorDef *prev; + + resolveCtorTypes(pt, cd, ct); + + /* + * Now check that the Python signature doesn't conflict with an + * earlier one. + */ + for (prev = cd->ctors; prev != ct; prev = prev->next) + if (samePythonSignature(&prev->pysig, &ct->pysig)) + { + fatalScopedName(classFQCName(cd)); + fatal(" has ctors with the same Python signature\n"); + } + + if (isDeprecatedClass(cd)) + setIsDeprecatedCtor(ct); + } +} + + +/* + * Transform the data type for a list of casts. + */ +static void transformCasts(sipSpec *pt, classDef *cd) +{ + argList *al; + + for (al = cd->casts; al != NULL; al = al->next) + { + classDef *dcd; + + getBaseType(pt, cd->iff->module, cd, &al->arg); + + if (al->arg.atype == class_type) + dcd = al->arg.u.cd; + else if (al->arg.atype == mapped_type) + dcd = findAltClassImplementation(pt, al->arg.u.mtd); + else + dcd = NULL; + + if (dcd == NULL) + { + fatalScopedName(classFQCName(cd)); + fatal(" operator cast must be to a class\n"); + } + } +} + + +/* + * Add a default copy ctor if required. + */ +static void addDefaultCopyCtor(classDef *cd) +{ + ctorDef *copyct, **tailp; + mroDef *mro; + + /* See if there is a private copy ctor in the hierarchy. */ + for (mro = cd->mro; mro != NULL; mro = mro->next) + { + ctorDef *ct; + + if (isDuplicateSuper(mro)) + continue; + + for (ct = mro->cd->ctors; ct != NULL; ct = ct->next) + { + argDef *ad = &ct -> pysig.args[0]; + + /* See if is a copy ctor. */ + if (ct->pysig.nrArgs == 1 && ad->nrderefs == 0 && isReference(ad)) + { + ifaceFileDef *iff; + + /* To check the type we have to look at all versions. */ + if (ad->atype == class_type) + iff = ad->u.cd->iff; + else if (ad->atype == mapped_type) + iff = ad->u.mtd->iff; + else + continue; + + for (iff = iff->first_alt; iff != NULL; iff = iff->next_alt) + if (mro->cd->iff == iff) + break; + + if (iff != NULL) + break; + } + } + + if (ct != NULL) + { + /* If the copy ctor is private then the class can't be copied. */ + if (isPrivateCtor(ct)) + { + setCannotCopy(cd); + return; + } + + /* + * If the ctor is in the class itself then there is nothing to do. + */ + if (mro == cd->mro) + return; + + /* Otherwise we need to create a default. */ + break; + } + } + + /* Create a default public copy ctor. */ + copyct = sipMalloc(sizeof (ctorDef)); + + copyct->ctorflags = SECT_IS_PUBLIC; + copyct->pysig.nrArgs = 1; + copyct->pysig.result.atype = void_type; + copyct->pysig.args[0].atype = class_type; + copyct->pysig.args[0].u.cd = cd; + copyct->pysig.args[0].argflags = (ARG_IS_REF | ARG_IS_CONST | ARG_IN); + copyct->pysig.args[0].nrderefs = 0; + copyct->pysig.args[0].defval = NULL; + + copyct->cppsig = ©ct->pysig; + + if (isDeprecatedClass(cd)) + setIsDeprecatedCtor(copyct); + + /* Append it to the list. */ + for (tailp = &cd->ctors; *tailp != NULL; tailp = &(*tailp)->next) + ; + + *tailp = copyct; +} + + +/* + * Transform the data types for a list of overloads. + */ +static void transformScopeOverloads(sipSpec *pt, classDef *c_scope, + mappedTypeDef *mt_scope, overDef *overs) +{ + overDef *od; + + for (od = overs; od != NULL; od = od->next) + { + overDef *prev; + + resolveFuncTypes(pt, od->common->module, c_scope, mt_scope, od); + + /* + * Now check that the Python signature doesn't conflict with an earlier + * one. + */ + for (prev = overs; prev != od; prev = prev->next) + { + if (prev->common != od->common) + continue; + + /* They can only conflict if one is unversioned. */ + if (prev->api_range != NULL && od->api_range != NULL) + continue; + + if (samePythonSignature(&prev->pysig, &od->pysig)) + { + ifaceFileDef *iff; + + if (mt_scope != NULL) + iff = mt_scope->iff; + else if (c_scope != NULL) + iff = c_scope->iff; + else + iff = NULL; + + if (iff != NULL) + { + fatalScopedName(iff->fqcname); + fatal("::"); + } + + fatal("%s() has overloaded functions with the same Python signature\n", od->common->pyname->text); + } + } + + if (c_scope != NULL && isDeprecatedClass(c_scope)) + setIsDeprecated(od); + } +} + + +/* + * Transform the data types for the variables of a module. + */ +static void transformVariableList(sipSpec *pt, moduleDef *mod) +{ + varDef *vd; + + for (vd = pt->vars; vd != NULL; vd = vd->next) + if (vd->module == mod) + if (vd->ecd == NULL || !isTemplateClass(vd->ecd)) + resolveVariableType(pt, vd); +} + + +/* + * Set the list of visible member functions for a class. + */ +static void getVisibleMembers(sipSpec *pt, classDef *cd) +{ + mroDef *mro; + + cd->visible = NULL; + + for (mro = cd->mro; mro != NULL; mro = mro->next) + { + memberDef *md; + classDef *mrocd; + + if (isDuplicateSuper(mro)) + continue; + + mrocd = mro->cd; + + for (md = mrocd->members; md != NULL; md = md->next) + { + visibleList *vl; + + /* + * See if it is already in the list. This has the desired side + * effect of eliminating any functions that have an implementation + * closer to this class in the hierarchy. This is the only reason + * to define private functions. + */ + for (vl = cd->visible; vl != NULL; vl = vl->next) + if (vl->m->pyname == md->pyname) + break; + + /* See if it is a new member function. */ + if (vl == NULL) + { + overDef *od; + + vl = sipMalloc(sizeof (visibleList)); + + vl->m = md; + vl->cd = mrocd; + vl->next = cd->visible; + + cd->visible = vl; + + for (od = mrocd->overs; od != NULL; od = od->next) + if (od->common == md) + { + if (isAbstract(od)) + setIsAbstractClass(cd); + + ifaceFilesAreUsedByOverload(&cd->iff->used, od); + + /* See if we need the name. */ + if (!generatingCodeForModule(pt, cd->iff->module)) + continue; + + if (isProtected(od) || (isSignal(od) && pluginPyQt3(pt))) + setIsUsedName(md->pyname); + + /* Make we have any API name. */ + if (od->api_range != NULL) + setIsUsedName(od->api_range->api_name); + } + } + } + } +} + + +/* + * Get all the virtuals for a particular class. + */ +static void getVirtuals(sipSpec *pt, classDef *cd) +{ + mroDef *mro; + virtOverDef *vod; + + for (mro = cd->mro; mro != NULL; mro = mro->next) + { + if (isDuplicateSuper(mro)) + continue; + + getClassVirtuals(cd, mro->cd); + } + + /* + * Identify any re-implementations of virtuals. We have to do this for all + * classes, not just those in the module we are generating code for. + */ + for (vod = cd->vmembers; vod != NULL; vod = vod->next) + { + overDef *od; + + for (od = cd->overs; od != NULL; od = od->next) + { + if (isVirtual(od)) + continue; + + if (strcmp(vod->o.cppname, od->cppname) == 0 && sameOverload(&vod->o, od)) + { + setIsVirtualReimp(od); + break; + } + } + + /* + * If this class is defined in the main module make sure we get the API + * files for all the visible virtuals. + */ + if (generatingCodeForModule(pt, cd->iff->module)) + { + /* Make sure we get the name. */ + setIsUsedName(vod->o.common->pyname); + } + } +} + + +/* + * Get the list of visible virtual functions for a class. + */ +static void getClassVirtuals(classDef *base, classDef *cd) +{ + overDef *od; + + for (od = cd->overs; od != NULL; od = od->next) + { + virtOverDef **tailp, *vod; + + if (!isVirtual(od) || isPrivate(od)) + continue; + + /* + * See if a virtual of this name and signature is already in the list. + */ + for (tailp = &base->vmembers; (vod = *tailp) != NULL; tailp = &vod->next) + if (strcmp(vod->o.cppname, od->cppname) == 0 && sameOverload(&vod->o, od)) + break; + + if (vod == NULL) + { + /* + * See if there is a non-virtual reimplementation nearer in the + * class hierarchy. + */ + + mroDef *mro; + classDef *scope = NULL; + overDef *eod; + + for (mro = base->mro; mro->cd != cd; mro = mro->next) + { + if (isDuplicateSuper(mro)) + continue; + + /* + * Ignore classes that are on a different branch of the class + * hierarchy. + */ + if (!isSubClass(mro->cd, cd)) + continue; + + for (eod = mro->cd->overs; eod != NULL; eod = eod->next) + if (strcmp(eod->cppname, od->cppname) == 0 && sameSignature(eod->cppsig, od->cppsig, TRUE) && isConst(eod) == isConst(od) && !isAbstract(eod)) + { + scope = mro->cd; + break; + } + + if (scope != NULL) + break; + } + + vod = sipMalloc(sizeof (virtOverDef)); + + vod->o = *od; + vod->scope = (scope != NULL ? scope : cd); + vod->next = NULL; + + *tailp = vod; + + /* + * If there was a nearer reimplementation then we use its + * protection and abstract flags. + */ + if (scope != NULL) + { + vod->o.overflags &= ~(SECT_MASK | OVER_IS_ABSTRACT); + vod->o.overflags |= (SECT_MASK | OVER_IS_ABSTRACT) & eod->overflags; + } + } + } +} + + +/* + * Return TRUE is a class is derived from another. + */ +static int isSubClass(classDef *cc,classDef *pc) +{ + mroDef *mro; + + /* + * In other words, does the parent class appear in the child class's + * MRO list. + */ + for (mro = cc -> mro; mro != NULL; mro = mro -> next) + if (mro -> cd == pc) + return TRUE; + + return FALSE; +} + + +/* + * Resolve the types of a mapped type based on a template. + */ +static void resolveMappedTypeTypes(sipSpec *pt, mappedTypeDef *mt) +{ + int a; + signatureDef *sd = &mt->type.u.td->types; + + for (a = 0; a < sd->nrArgs; ++a) + { + argDef *ad = &sd->args[a]; + + /* Leave templates as they are. */ + if (ad->atype != template_type) + getBaseType(pt, mt->iff->module, NULL, ad); + } + + /* Make sure that the signature result won't cause problems. */ + sd->result.atype = no_type; + + ifaceFilesAreUsedBySignature(&mt->iff->used, sd); +} + + +/* + * Resolve the types of a ctor. + */ +static void resolveCtorTypes(sipSpec *pt,classDef *scope,ctorDef *ct) +{ + int a; + + /* Handle any C++ signature. */ + if (ct->cppsig != NULL && ct->cppsig != &ct->pysig) + for (a = 0; a < ct -> cppsig -> nrArgs; ++a) + getBaseType(pt, scope->iff->module, scope, &ct->cppsig->args[a]); + + /* Handle the Python signature. */ + for (a = 0; a < ct -> pysig.nrArgs; ++a) + { + argDef *ad = &ct -> pysig.args[a]; + + getBaseType(pt, scope->iff->module, scope, ad); + + if (!supportedType(scope,NULL,ad,FALSE) && (ct -> cppsig == &ct -> pysig || ct -> methodcode == NULL)) + { + fatalScopedName(classFQCName(scope)); + fatal(" unsupported ctor argument type - provide %%MethodCode and a C++ signature\n"); + } + + ifaceFileIsUsed(&scope->iff->used, ad); + scopeDefaultValue(pt, scope, ad); + } +} + + +/* + * Resolve the types of a function. + */ +static void resolveFuncTypes(sipSpec *pt, moduleDef *mod, classDef *c_scope, + mappedTypeDef *mt_scope, overDef *od) +{ + argDef *res; + + /* Handle any C++ signature. */ + if (od->cppsig != &od->pysig) + { + int a; + + getBaseType(pt,mod, c_scope, &od->cppsig->result); + + for (a = 0; a < od->cppsig->nrArgs; ++a) + getBaseType(pt, mod, c_scope, &od->cppsig->args[a]); + } + + /* Handle the Python signature. */ + resolvePySigTypes(pt, mod, c_scope, od, &od->pysig, isSignal(od)); + + res = &od->pysig.result; + + /* These slots must return SIP_SSIZE_T (or int - deprecated). */ + if (isSSizeReturnSlot(od->common)) + if ((res->atype != ssize_type && res->atype != int_type) || res->nrderefs != 0 || + isReference(res) || isConstArg(res)) + fatal("%s slots must return SIP_SSIZE_T\n", + od->common->pyname->text); + + /* These slots must return int. */ + if (isIntReturnSlot(od->common)) + if (res->atype != int_type || res->nrderefs != 0 || + isReference(res) || isConstArg(res)) + fatal("%s slots must return int\n", od->common->pyname->text); + + /* These slots must return void. */ + if (isVoidReturnSlot(od->common)) + if (res->atype != void_type || res->nrderefs != 0 || + isReference(res) || isConstArg(res)) + fatal("%s slots must return void\n", od->common->pyname->text); + + /* These slots must return long. */ + if (isLongReturnSlot(od->common)) + if (res->atype != long_type || res->nrderefs != 0 || + isReference(res) || isConstArg(res)) + fatal("%s slots must return long\n", od->common->pyname->text); +} + + +/* + * Resolve the types of a Python signature. + */ +static void resolvePySigTypes(sipSpec *pt, moduleDef *mod, classDef *scope, + overDef *od, signatureDef *pysig, int issignal) +{ + int a; + argDef *res = &pysig -> result; + + if (res -> atype != void_type || res -> nrderefs != 0) + { + if (issignal) + { + if (scope != NULL) + { + fatalScopedName(classFQCName(scope)); + fatal("::"); + } + + fatal("%s() signals must return void\n",od -> cppname); + } + + getBaseType(pt, mod, scope, res); + + /* Results must be simple. */ + if (!supportedType(scope,od,res,FALSE) && (od -> cppsig == &od -> pysig || od -> methodcode == NULL)) + { + if (scope != NULL) + { + fatalScopedName(classFQCName(scope)); + fatal("::"); + } + + fatal("%s() unsupported function return type - provide %%MethodCode and a %s signature\n",od -> cppname,(pt -> genc ? "C" : "C++")); + } + } + + for (a = 0; a < pysig -> nrArgs; ++a) + { + argDef *ad = &pysig -> args[a]; + + getBaseType(pt, mod, scope, ad); + + if (ad -> atype == slotcon_type) + resolvePySigTypes(pt, mod, scope, od, ad->u.sa, TRUE); + + /* + * Note signal arguments are restricted in their types because we don't + * (yet) support handwritten code for them. + */ + if (issignal) + { + if (!supportedType(scope,od,ad,FALSE)) + { + if (scope != NULL) + { + fatalScopedName(classFQCName(scope)); + fatal("::"); + } + + fatal("%s() unsupported signal argument type\n", od->cppname); + } + } + else if (!supportedType(scope,od,ad,TRUE) && (od -> cppsig == &od -> pysig || od -> methodcode == NULL || (isVirtual(od) && od -> virthandler -> virtcode == NULL))) + { + if (scope != NULL) + { + fatalScopedName(classFQCName(scope)); + fatal("::"); + } + + if (isVirtual(od)) + fatal("%s() unsupported function argument type - provide %%MethodCode, a valid %%VirtualCatcherCode and a valid C++ signature\n",od -> cppname); + + fatal("%s() unsupported function argument type - provide %%MethodCode and a valid %s signature\n",od -> cppname,(pt -> genc ? "C" : "C++")); + } + + if (scope != NULL) + scopeDefaultValue(pt,scope,ad); + } +} + + +/* + * Resolve the type of a variable. + */ +static void resolveVariableType(sipSpec *pt, varDef *vd) +{ + int bad = TRUE; + argDef *vtype = &vd->type; + + getBaseType(pt, vd->module, vd->ecd, vtype); + + switch (vtype->atype) + { + case mapped_type: + case class_type: + /* Class, Class & and Class * are supported. */ + + if (vtype->nrderefs <= 1) + bad = FALSE; + break; + + case ascii_string_type: + case latin1_string_type: + case utf8_string_type: + case sstring_type: + case ustring_type: + case string_type: + case wstring_type: + /* + * (signed/unsigned) char, (signed/unsigned) char *, wchar_t, wchar_t * + * are supported. + */ + + if (!isReference(vtype) && vtype->nrderefs <= 1) + bad = FALSE; + break; + + case cfloat_type: + case float_type: + case cdouble_type: + case double_type: + case enum_type: + case bool_type: + case cbool_type: + case ushort_type: + case short_type: + case uint_type: + case cint_type: + case int_type: + case ulong_type: + case long_type: + case ulonglong_type: + case longlong_type: + case ssize_type: + case pyobject_type: + case pytuple_type: + case pylist_type: + case pydict_type: + case pycallable_type: + case pyslice_type: + case pytype_type: + /* These are supported without pointers or references. */ + + if (!isReference(vtype) && vtype->nrderefs == 0) + bad = FALSE; + break; + + case struct_type: + case void_type: + /* A simple pointer is supported. */ + + if (!isReference(vtype) && vtype->nrderefs == 1) + bad = FALSE; + break; + } + + if (bad && (vd->getcode == NULL || vd->setcode == NULL)) + { + fatalScopedName(vd->fqcname); + fatal(" has an unsupported type - provide %%GetCode and %%SetCode\n"); + } + + if (vtype->atype != class_type && vd->accessfunc != NULL) + { + fatalScopedName(vd->fqcname); + fatal(" has %%AccessCode but isn't a class instance\n"); + } + + if (vd->ecd != NULL) + ifaceFileIsUsed(&vd->ecd->iff->used, vtype); + else + ifaceFileIsUsed(&vd->module->used, vtype); + + /* Scoped variables need a handler unless they have %AccessCode. */ + if (vd->ecd != NULL && vd->accessfunc == NULL) + { + setNeedsHandler(vd); + setHasVarHandlers(vd->ecd); + } +} + + +/* + * See if a type is supported by the generated code. + */ +static int supportedType(classDef *cd,overDef *od,argDef *ad,int outputs) +{ + switch (ad -> atype) + { + case anyslot_type: + /* + * This must be an input, and must also have handwritten code. + */ + + ensureInput(cd,od,ad); + return FALSE; + + case signal_type: + case slot_type: + case rxcon_type: + case rxdis_type: + case slotcon_type: + case slotdis_type: + case qobject_type: + case ellipsis_type: + /* These can only appear in argument lists without * or &. */ + + ensureInput(cd,od,ad); + return TRUE; + + case ascii_string_type: + case latin1_string_type: + case utf8_string_type: + case sstring_type: + case ustring_type: + case string_type: + case wstring_type: + if (isReference(ad)) + { + if (outputs && ad -> nrderefs <= 1) + { + defaultOutput(ad); + return TRUE; + } + } + else if (ad -> nrderefs == 0) + { + ensureInput(cd,od,ad); + return TRUE; + } + else if (ad -> nrderefs == 1) + { + if (outputs) + defaultInput(ad); + else + ensureInput(cd,od,ad); + + return TRUE; + } + else if (ad -> nrderefs == 2 && outputs) + { + defaultOutput(ad); + return TRUE; + } + + break; + + case cfloat_type: + case float_type: + case cdouble_type: + case double_type: + case enum_type: + case bool_type: + case cbool_type: + case ushort_type: + case short_type: + case uint_type: + case cint_type: + case int_type: + case ulong_type: + case long_type: + case ulonglong_type: + case longlong_type: + case ssize_type: + case pyobject_type: + case pytuple_type: + case pylist_type: + case pydict_type: + case pycallable_type: + case pyslice_type: + case pytype_type: + if (isReference(ad)) + { + if (ad -> nrderefs == 0 && outputs) + { + defaultOutput(ad); + return TRUE; + } + } + else if (ad -> nrderefs == 0) + { + ensureInput(cd,od,ad); + return TRUE; + } + else if (ad -> nrderefs == 1 && outputs) + { + defaultOutput(ad); + return TRUE; + } + + break; + + case mapped_type: + case class_type: + if (isReference(ad)) + { + if (ad -> nrderefs == 0) + { + defaultInput(ad); + return TRUE; + } + else if (ad -> nrderefs == 1 && outputs) + { + defaultOutput(ad); + return TRUE; + } + } + else if (ad -> nrderefs == 0) + { + ensureInput(cd,od,ad); + return TRUE; + } + else if (ad -> nrderefs == 1) + { + if (outputs) + defaultInput(ad); + else + ensureInput(cd,od,ad); + + return TRUE; + } + else if (ad -> nrderefs == 2 && outputs) + { + defaultOutput(ad); + return TRUE; + } + + break; + + case struct_type: + case void_type: + if (isReference(ad)) + { + if (ad -> nrderefs == 1 && outputs) + { + defaultOutput(ad); + return TRUE; + } + } + else if (ad -> nrderefs == 1) + { + ensureInput(cd,od,ad); + return TRUE; + } + else if (ad -> nrderefs == 2 && outputs) + { + defaultOutput(ad); + return TRUE; + } + + break; + } + + /* Unsupported if we got this far. */ + return FALSE; +} + + +/* + * Ensure the direction of an argument is an input. + */ +static void ensureInput(classDef *cd,overDef *od,argDef *ad) +{ + if (isOutArg(ad)) + { + if (cd != NULL) + { + fatalScopedName(classFQCName(cd)); + fatal("::"); + } + + if (od != NULL) + fatal("%s",od -> cppname); + + fatal("() invalid argument type for /Out/\n"); + } + + setIsInArg(ad); +} + + +/* + * Default the direction of an argument to an input. + */ +static void defaultInput(argDef *ad) +{ + if (!isInArg(ad) && !isOutArg(ad)) + setIsInArg(ad); +} + + +/* + * Default the direction of an argument to an output unless the argument is + * const. + */ +static void defaultOutput(argDef *ad) +{ + if (!isOutArg(ad) && !isInArg(ad)) + { + if (isConstArg(ad)) + setIsInArg(ad); + else + setIsOutArg(ad); + } +} + + +/* + * Put a scoped name to stderr. + */ +void fatalScopedName(scopedNameDef *snd) +{ + while (snd != NULL) + { + fatal("%s",snd -> name); + + snd = snd -> next; + + if (snd != NULL) + fatal("::"); + } +} + + +/* + * Compare two overloads and return TRUE if they are the same. + */ +static int sameOverload(overDef *od1, overDef *od2) +{ + /* They must both be enabled for the same API. */ + if (od1->api_range != od2->api_range) + return FALSE; + + /* They must both be const, or both not. */ + if (isConst(od1) != isConst(od2)) + return FALSE; + + return sameSignature(&od1->pysig, &od2->pysig, TRUE); +} + + +/* + * Compare two virtual handlers and return TRUE if they are the same. + */ +static int sameVirtualHandler(virtHandlerDef *vhd1,virtHandlerDef *vhd2) +{ + int a; + + if (isTransferVH(vhd1) != isTransferVH(vhd2)) + return FALSE; + + if (!sameArgType(&vhd1->pysig->result, &vhd2->pysig->result, TRUE)) + return FALSE; + + if (!sameSignature(vhd1->pysig, vhd2->pysig, TRUE)) + return FALSE; + + /* Take into account the argument directions in the Python signatures. */ + for (a = 0; a < vhd1->pysig->nrArgs; ++a) + { + int dir1 = (vhd1->pysig->args[a].argflags & (ARG_IN | ARG_OUT)); + int dir2 = (vhd2->pysig->args[a].argflags & (ARG_IN | ARG_OUT)); + + if (dir1 != dir2) + return FALSE; + } + + if (vhd1->pysig == vhd1->cppsig && vhd2->pysig == vhd2->cppsig) + return TRUE; + + if (!sameArgType(&vhd1->cppsig->result, &vhd2->cppsig->result, TRUE)) + return FALSE; + + return sameSignature(vhd1->cppsig, vhd2->cppsig, TRUE); +} + + +/* + * Compare two signatures and return TRUE if they are the same. + */ +int sameSignature(signatureDef *sd1,signatureDef *sd2,int strict) +{ + int a; + + if (strict) + { + /* The number of arguments must be the same. */ + if (sd1 -> nrArgs != sd2 -> nrArgs) + return FALSE; + } + else + { + int na1, na2; + + /* We only count the compulsory arguments. */ + na1 = 0; + + for (a = 0; a < sd1 -> nrArgs; ++a) + { + if (sd1 -> args[a].defval != NULL) + break; + + ++na1; + } + + na2 = 0; + + for (a = 0; a < sd2 -> nrArgs; ++a) + { + if (sd2 -> args[a].defval != NULL) + break; + + ++na2; + } + + if (na1 != na2) + return FALSE; + } + + /* The arguments must be the same. */ + for (a = 0; a < sd1 -> nrArgs; ++a) + { + if (!strict && sd1 -> args[a].defval != NULL) + break; + + if (!sameArgType(&sd1 -> args[a],&sd2 -> args[a],strict)) + return FALSE; + } + + /* Must be the same if we've got this far. */ + return TRUE; +} + + +#define pyAsString(t) ((t) == ustring_type || (t) == sstring_type || \ + (t) == string_type || (t) == ascii_string_type || \ + (t) == latin1_string_type || (t) == utf8_string_type) +#define pyAsFloat(t) ((t) == cfloat_type || (t) == float_type || \ + (t) == cdouble_type || (t) == double_type) +#define pyAsInt(t) ((t) == bool_type || (t) == ssize_type || \ + (t) == short_type || (t) == ushort_type || \ + (t) == cint_type || (t) == int_type || (t) == uint_type) +#define pyAsLong(t) ((t) == long_type || (t) == longlong_type) +#define pyAsULong(t) ((t) == ulong_type || (t) == ulonglong_type) +#define pyAsAuto(t) ((t) == bool_type || \ + (t) == short_type || (t) == ushort_type || \ + (t) == int_type || (t) == uint_type || \ + (t) == float_type || (t) == double_type) +#define pyIsConstrained(t) ((t) == cbool_type || (t) == cint_type || \ + (t) == cfloat_type || (t) == cdouble_type) + +/* + * Compare two argument types and return TRUE if they are the same. "strict" + * means as C++ would see it, rather than Python. + */ +static int sameArgType(argDef *a1, argDef *a2, int strict) +{ + /* The references must be the same. */ + if (isReference(a1) != isReference(a2) || a1->nrderefs != a2->nrderefs) + return FALSE; + + if (strict) + { + /* The const should be the same. */ + if (isConstArg(a1) != isConstArg(a2)) + return FALSE; + + return sameBaseType(a1,a2); + } + + /* If both are constrained fundamental types then the types must match. */ + if (pyIsConstrained(a1->atype) && pyIsConstrained(a2->atype)) + return (a1->atype == a2->atype); + + /* An unconstrained enum also acts as a (very) constrained int. */ + if ((pyAsInt(a1->atype) && a2->atype == enum_type && !isConstrained(a2)) || + (a1->atype == enum_type && !isConstrained(a1) && pyAsInt(a2->atype))) + return TRUE; + + /* Python will see all these as strings. */ + if (pyAsString(a1->atype) && pyAsString(a2->atype)) + return TRUE; + + /* Python will see all these as floats. */ + if (pyAsFloat(a1->atype) && pyAsFloat(a2->atype)) + return TRUE; + + /* Python will see all these as ints. */ + if (pyAsInt(a1->atype) && pyAsInt(a2->atype)) + return TRUE; + + /* Python will see all these as longs. */ + if (pyAsLong(a1->atype) && pyAsLong(a2->atype)) + return TRUE; + + /* Python will see all these as unsigned longs. */ + if (pyAsULong(a1->atype) && pyAsULong(a2->atype)) + return TRUE; + + /* Python will automatically convert between these. */ + if (pyAsAuto(a1->atype) && pyAsAuto(a2->atype)) + return TRUE; + + /* All the special cases have been handled. */ + return sameBaseType(a1, a2); +} + + +/* + * Compare two basic types and return TRUE if they are the same. + */ +int sameBaseType(argDef *a1, argDef *a2) +{ + /* The types must be the same. */ + if (a1->atype != a2->atype) + { + /* + * If we are comparing a template with those that have already been + * used to instantiate a class or mapped type then we need to compare + * with the class or mapped type name. + */ + if (a1->atype == class_type && a2->atype == defined_type) + return compareScopedNames(a1->u.cd->iff->fqcname, a2->u.snd) == 0; + + if (a1->atype == defined_type && a2->atype == class_type) + return compareScopedNames(a1->u.snd, a2->u.cd->iff->fqcname) == 0; + + if (a1->atype == mapped_type && a2->atype == defined_type) + return compareScopedNames(a1->u.mtd->iff->fqcname, a2->u.snd) == 0; + + if (a1->atype == defined_type && a2->atype == mapped_type) + return compareScopedNames(a1->u.snd, a2->u.mtd->iff->fqcname) == 0; + + return FALSE; + } + + switch (a1->atype) + { + case class_type: + if (a1->u.cd != a2->u.cd) + return FALSE; + + break; + + case enum_type: + if (a1->u.ed != a2->u.ed) + return FALSE; + + break; + + case slotcon_type: + case slotdis_type: + if (!sameSignature(a1->u.sa, a2->u.sa, TRUE)) + return FALSE; + + break; + + case template_type: + { + int a; + templateDef *td1, *td2; + + td1 = a1->u.td; + td2 = a2->u.td; + + if (compareScopedNames(td1->fqname, td2->fqname) != 0 || + td1->types.nrArgs != td2->types.nrArgs) + return FALSE; + + for (a = 0; a < td1->types.nrArgs; ++a) + if (!sameBaseType(&td1->types.args[a], &td2->types.args[a])) + return FALSE; + + break; + } + + case struct_type: + if (compareScopedNames(a1->u.sname, a2->u.sname) != 0) + return FALSE; + + break; + + case defined_type: + if (compareScopedNames(a1->u.snd, a2->u.snd) != 0) + return FALSE; + + break; + + case mapped_type: + if (a1->u.mtd != a2->u.mtd) + return FALSE; + + break; + } + + /* Must be the same if we've got this far. */ + return TRUE; +} + + +/* + * See if two Python signatures are the same as far as Python is concerned. + */ +static int samePythonSignature(signatureDef *sd1, signatureDef *sd2) +{ + int a1, a2; + + a1 = a2 = -1; + + for (;;) + { + a1 = nextSignificantArg(sd1, a1); + a2 = nextSignificantArg(sd2, a2); + + if (a1 < 0 || a2 < 0) + break; + + if (!sameArgType(&sd1->args[a1], &sd2->args[a2], FALSE)) + return FALSE; + } + + return (a1 < 0 && a2 < 0); + +} + + +/* + * Return the next significant argument from a Python signature (ie. one that + * is not optional or an output only argument. Return -1 if there isn't one. + */ +static int nextSignificantArg(signatureDef *sd, int a) +{ + while (++a < sd->nrArgs) + { + if (sd->args[a].defval != NULL) + break; + + if (isInArg(&sd->args[a])) + return a; + } + + return -1; +} + + +/* + * The equivalent of strcmp() for scoped names. + */ +int compareScopedNames(scopedNameDef *snd1, scopedNameDef *snd2) +{ + while (snd1 != NULL && snd2 != NULL) + { + int res = strcmp(snd1->name, snd2->name); + + if (res != 0) + return res; + + snd1 = snd1->next; + snd2 = snd2->next; + } + + if (snd1 == NULL) + return (snd2 == NULL ? 0 : -1); + + return 1; +} + + +/* + * Add an explicit scope to the default value of an argument if possible. + */ + +static void scopeDefaultValue(sipSpec *pt,classDef *cd,argDef *ad) +{ + valueDef *vd, **tailp, *newvd; + + /* + * We do a quick check to see if we need to do anything. This means + * we can limit the times we need to copy the default value. It needs + * to be copied because it will be shared by class versions that have + * been created on the fly and it may need to be scoped differently for + * each of those versions. + */ + + for (vd = ad -> defval; vd != NULL; vd = vd -> next) + if (vd -> vtype == scoped_value && vd -> u.vscp -> next == NULL) + break; + + if (vd == NULL) + return; + + /* + * It's not certain that we will do anything, but we assume we will and + * start copying. + */ + + newvd = NULL; + tailp = &newvd; + + for (vd = ad -> defval; vd != NULL; vd = vd -> next) + { + mroDef *mro; + scopedNameDef *origname; + valueDef *new; + + /* Make the copy. */ + + new = sipMalloc(sizeof (valueDef)); + + *new = *vd; + *tailp = new; + tailp = &new -> next; + + /* + * Skip this part of the expression if it isn't a named value + * or it already has a scope. + */ + + if (vd -> vtype != scoped_value || vd -> u.vscp -> next != NULL) + continue; + + /* + * Search the class hierarchy for an enum value with the same + * name. If we don't find one, leave it as it is (the compiler + * will find out if this is a problem). + */ + + origname = vd -> u.vscp; + + for (mro = cd -> mro; mro != NULL; mro = mro -> next) + { + enumDef *ed; + + if (isDuplicateSuper(mro)) + continue; + + for (ed = pt -> enums; ed != NULL; ed = ed -> next) + { + enumMemberDef *emd; + + if (ed -> ecd != mro -> cd) + continue; + + for (emd = ed -> members; emd != NULL; emd = emd -> next) + if (strcmp(emd -> cname,origname -> name) == 0) + { + scopedNameDef *snd; + + /* + * Take the scope from the + * class that the enum was + * defined in. + */ + + snd = copyScopedName(mro -> cd -> iff -> fqcname); + appendScopedName(&snd,origname); + + new -> u.vscp = snd; + + /* Nothing more to do. */ + + break; + } + + if (emd != NULL) + break; + } + + if (ed != NULL) + break; + } + } + + ad -> defval = newvd; +} + + +/* + * Make sure a type is a base type. + */ +static void getBaseType(sipSpec *pt, moduleDef *mod, classDef *c_scope, + argDef *type) +{ + /* Loop until we've got to a base type. */ + while (type->atype == defined_type) + { + scopedNameDef *snd = type->u.snd; + + type->atype = no_type; + + if (c_scope != NULL) + searchClassScope(pt, c_scope, snd,type); + + if (type->atype == no_type) + searchMappedTypes(pt, mod, snd, type); + + if (type->atype == no_type) + searchTypedefs(pt, snd, type); + + if (type->atype == no_type) + searchEnums(pt, snd, type); + + if (type->atype == no_type) + searchClasses(pt, mod, snd, type); + + if (type->atype == no_type) + fatalNoDefinedType(snd); + } + + /* Get the base type of any slot arguments. */ + if (type->atype == slotcon_type || type->atype == slotdis_type) + { + int sa; + + for (sa = 0; sa < type->u.sa->nrArgs; ++sa) + getBaseType(pt, mod, c_scope, &type->u.sa->args[sa]); + } + + /* See if the type refers to an instantiated template. */ + resolveInstantiatedClassTemplate(pt, type); + + /* Replace the base type if it has been mapped. */ + if (type->atype == struct_type || type->atype == template_type) + { + searchMappedTypes(pt, mod, NULL, type); + + /* + * If we still have a template then see if we need to automatically + * instantiate it. + */ + if (type->atype == template_type) + { + mappedTypeTmplDef *mtt; + + for (mtt = pt->mappedtypetemplates; mtt != NULL; mtt = mtt->next) + if (compareScopedNames(type->u.td->fqname, mtt->mt->type.u.td->fqname) == 0 && sameTemplateSignature(&mtt->mt->type.u.td->types, &type->u.td->types, TRUE)) + { + type->u.mtd = instantiateMappedTypeTemplate(pt, mod, mtt, type); + type->atype = mapped_type; + + break; + } + } + } +} + + +/* + * If the type corresponds to a previously instantiated class template then + * replace it with the class that was created. + */ +static void resolveInstantiatedClassTemplate(sipSpec *pt, argDef *type) +{ + int a; + classDef *cd; + templateDef *td; + signatureDef *sd; + + if (type->atype != template_type) + return; + + td = type->u.td; + sd = &td->types; + + for (a = 0; a < sd->nrArgs; ++a) + resolveInstantiatedClassTemplate(pt, &sd->args[a]); + + for (cd = pt->classes; cd != NULL; cd = cd->next) + if (cd->td != NULL && + compareScopedNames(cd->td->fqname, td->fqname) == 0 && + sameSignature(&cd->td->types, sd, TRUE)) + { + type->atype = class_type; + type->u.cd = cd; + + break; + } +} + + +/* + * Instantiate a mapped type template and return it. + */ +static mappedTypeDef *instantiateMappedTypeTemplate(sipSpec *pt, moduleDef *mod, mappedTypeTmplDef *mtt, argDef *type) +{ + scopedNameDef *type_names, *type_values; + mappedTypeDef *mtd; + + type_names = type_values = NULL; + appendTypeStrings(type->u.td->fqname, &mtt->mt->type.u.td->types, &type->u.td->types, &mtt->sig, &type_names, &type_values); + + mtd = allocMappedType(pt, type); + + if (generatingCodeForModule(pt, mod)) + setIsUsedName(mtd->cname); + + mtd->iff = findIfaceFile(pt, mod, encodedTemplateName(type->u.td), + mappedtype_iface, NULL, type); + mtd->iff->module = mod; + + mtd->doctype = templateString(mtt->mt->doctype, type_names, type_values); + + appendCodeBlock(&mtd->iff->hdrcode, templateCode(pt, &mtd->iff->used, mtt->mt->iff->hdrcode, type_names, type_values)); + mtd->convfromcode = templateCode(pt, &mtd->iff->used, mtt->mt->convfromcode, type_names, type_values); + mtd->convtocode = templateCode(pt, &mtd->iff->used, mtt->mt->convtocode, type_names, type_values); + + mtd->next = pt->mappedtypes; + pt->mappedtypes = mtd; + + if (type_names != NULL) + freeScopedName(type_names); + + if (type_values != NULL) + freeScopedName(type_values); + + return mtd; +} + + +/* + * Return a string based on an original with names replaced by corresponding + * values. + */ +static const char *templateString(const char *src, scopedNameDef *names, + scopedNameDef *values) +{ + char *dst; + + /* Handle the trivial case. */ + if (src == NULL) + return NULL; + + dst = sipStrdup(src); + + while (names != NULL && values != NULL) + { + char *cp, *vname = values->name; + size_t name_len, value_len; + + name_len = strlen(names->name); + value_len = strlen(vname); + + /* Translate any C++ scoping to Python. */ + while ((cp = strstr(vname, "::")) != NULL) + { + char *new_vname = sipMalloc(value_len); + size_t pos = cp - vname; + + memcpy(new_vname, vname, pos); + new_vname[pos] = '.'; + strcpy(new_vname + pos + 1, cp + 2); + + if (vname != values->name) + free(vname); + + vname = new_vname; + --value_len; + } + + while ((cp = strstr(dst, names->name)) != NULL) + { + char *new_dst = sipMalloc(strlen(dst) - name_len + value_len + 1); + + memcpy(new_dst, dst, cp - dst); + memcpy(new_dst + (cp - dst), vname, value_len); + strcpy(new_dst + (cp - dst) + value_len, cp + name_len); + + free(dst); + dst = new_dst; + } + + if (vname != values->name) + free(vname); + + names = names->next; + values = values->next; + } + + return dst; +} + + +/* + * Search for a name in a scope and return the corresponding type. + */ +static void searchClassScope(sipSpec *pt, classDef *c_scope, + scopedNameDef *snd, argDef *ad) +{ + scopedNameDef *tmpsnd = NULL; + mroDef *mro; + + for (mro = c_scope->mro; mro != NULL; mro = mro->next) + { + if (isDuplicateSuper(mro)) + continue; + + /* Append the name to the scope and see if it exists. */ + tmpsnd = copyScopedName(classFQCName(mro->cd)); + appendScopedName(&tmpsnd, copyScopedName(snd)); + + searchMappedTypes(pt, mro->cd->iff->module, tmpsnd, ad); + + if (ad->atype != no_type) + break; + + searchTypedefs(pt, tmpsnd, ad); + + if (ad->atype != no_type) + break; + + searchEnums(pt, tmpsnd, ad); + + if (ad->atype != no_type) + break; + + searchClasses(pt, mro->cd->iff->module, tmpsnd, ad); + + if (ad->atype != no_type) + break; + + freeScopedName(tmpsnd); + tmpsnd = NULL; + } + + if (tmpsnd != NULL) + freeScopedName(tmpsnd); +} + + +/* + * Search the mapped types for a name and return the type. + */ + +static void searchMappedTypes(sipSpec *pt, moduleDef *context, + scopedNameDef *snd, argDef *ad) +{ + mappedTypeDef *mtd; + scopedNameDef *oname; + + /* Patch back to defined types so we can use sameBaseType(). */ + if (snd != NULL) + { + oname = ad->u.snd; + ad->u.snd = snd; + ad->atype = defined_type; + } + + for (mtd = pt->mappedtypes; mtd != NULL; mtd = mtd->next) + if (sameBaseType(ad, &mtd->type)) + { + /* + * If we a building a consolidated module and this mapped type is + * defined in a different module then see if that other module is + * in a different branch of the module hierarchy. + */ + if (isConsolidated(pt->module) && context != mtd->iff->module) + { + moduleListDef *mld; + + for (mld = context->allimports; mld != NULL; mld = mld->next) + if (mld->module == mtd->iff->module) + break; + + /* If it's in a different branch then we ignore it. */ + if (mld == NULL) + continue; + } + + /* Copy the type. */ + ad->atype = mapped_type; + ad->u.mtd = mtd; + + return; + } + + /* Restore because we didn't find anything. */ + if (snd != NULL) + { + ad->u.snd = oname; + ad->atype = no_type; + } +} + + +/* + * Search the typedefs for a name and return the type. + */ +void searchTypedefs(sipSpec *pt, scopedNameDef *snd, argDef *ad) +{ + typedefDef *td; + + for (td = pt->typedefs; td != NULL; td = td->next) + { + int res = compareScopedNames(td->fqname, snd); + + if (res == 0) + { + /* Copy the type. */ + ad->atype = td->type.atype; + ad->argflags |= td->type.argflags; + ad->nrderefs += td->type.nrderefs; + ad->doctype = td->type.doctype; + ad->u = td->type.u; + + if (ad->original_type == NULL) + ad->original_type = td; + + break; + } + + /* The list is sorted so stop if we have gone too far. */ + if (res > 0) + break; + } +} + + +/* + * Search the enums for a name and return the type. + */ +static void searchEnums(sipSpec *pt, scopedNameDef *snd, argDef *ad) +{ + enumDef *ed; + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + if (ed->fqcname == NULL) + continue; + + if (compareScopedNames(ed->fqcname, snd) == 0) + { + ad->atype = enum_type; + ad->u.ed = ed; + + break; + } + } +} + + +/* + * Search the classes for one with a particular name and return it as a type. + */ +static void searchClasses(sipSpec *pt, moduleDef *context, + scopedNameDef *cname, argDef *ad) +{ + classDef *cd; + + for (cd = pt->classes; cd != NULL; cd = cd->next) + { + /* + * Ignore an external class unless it was declared in the same context + * (ie. module) as the name is being used. + */ + if (isExternal(cd) && cd->iff->module != context) + continue; + + if (compareScopedNames(classFQCName(cd), cname) == 0) + { + ad->atype = class_type; + ad->u.cd = cd; + + break; + } + } +} + + +/* + * Print an error message describing an undefined type to stderr and terminate. + */ + +static void fatalNoDefinedType(scopedNameDef *snd) +{ + fatalScopedName(snd); + fatal(" is undefined\n"); +} + + +/* + * Make sure all interface files for a signature are used. + */ +static void ifaceFilesAreUsedBySignature(ifaceFileList **used, signatureDef *sd) +{ + int a; + + ifaceFileIsUsed(used, &sd->result); + + for (a = 0; a < sd->nrArgs; ++a) + ifaceFileIsUsed(used, &sd->args[a]); +} + + +/* + * Make sure all interface files for a function are used. + */ +static void ifaceFilesAreUsedByOverload(ifaceFileList **used, overDef *od) +{ + throwArgs *ta; + + ifaceFilesAreUsedBySignature(used, &od->pysig); + + if (od->cppsig != &od->pysig) + ifaceFilesAreUsedBySignature(used, od->cppsig); + + if ((ta = od->exceptions) != NULL) + { + int a; + + for (a = 0; a < ta->nrArgs; ++a) + addToUsedList(used, ta->args[a]->iff); + } +} + + +/* + * If a type has an interface file then add it to the the given list of used + * interface files so that the header file is #included in the generated code. + */ +static void ifaceFileIsUsed(ifaceFileList **used, argDef *ad) +{ + ifaceFileDef *iff; + + if ((iff = getIfaceFile(ad)) != NULL) + { + addToUsedList(used, iff); + + /* + * For mapped type templates we also need the template arguments. + * These will be in the mapped type's used list (which itself will be + * empty for non-template mapped types). + */ + if (ad->atype == mapped_type) + { + ifaceFileList *iffl = iff->used; + + for (iffl = iff->used; iffl != NULL; iffl = iffl->next) + addToUsedList(used, iffl->iff); + } + } +} + + +/* + * Return the interface file for a type, or NULL if it doesn't have one. + */ +static ifaceFileDef *getIfaceFile(argDef *ad) +{ + ifaceFileDef *iff; + + switch (ad->atype) + { + case class_type: + iff = ad->u.cd->iff; + break; + + case mapped_type: + iff = ad->u.mtd->iff; + break; + + case enum_type: + if (ad->u.ed->fqcname != NULL) + { + if (ad->u.ed->ecd != NULL) + { + iff = ad->u.ed->ecd->iff; + break; + } + + if (ad->u.ed->emtd != NULL) + { + iff = ad->u.ed->emtd->iff; + break; + } + } + + /* Drop through. */ + + default: + iff = NULL; + } + + return iff; +} + + +/* + * Create the sorted array of numbered types for a module. + */ +static void createSortedNumberedTypesTable(sipSpec *pt, moduleDef *mod) +{ + classDef *cd; + mappedTypeDef *mtd; + enumDef *ed; + argDef *ad; + int i; + + /* Count the how many types there are. */ + mod->nrtypes = 0; + + for (cd = pt->classes; cd != NULL; cd = cd->next) + { + if (cd->iff->module != mod) + continue; + + if (cd->iff->first_alt != cd->iff) + continue; + + mod->nrtypes++; + } + + for (mtd = pt->mappedtypes; mtd != NULL; mtd = mtd->next) + { + if (mtd->iff->module != mod) + continue; + + if (mtd->iff->first_alt != mtd->iff) + continue; + + mod->nrtypes++; + } + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + if (ed->module != mod) + continue; + + if (ed->fqcname == NULL) + continue; + + if (ed->ecd != NULL && isTemplateClass(ed->ecd)) + continue; + + if (ed->first_alt != ed) + continue; + + mod->nrtypes++; + } + + if (mod->nrtypes == 0) + return; + + /* Allocate and populate the table. */ + ad = mod->types = sipCalloc(mod->nrtypes, sizeof (argDef)); + + for (cd = pt->classes; cd != NULL; cd = cd->next) + { + if (cd->iff->module != mod) + continue; + + if (cd->iff->first_alt != cd->iff) + continue; + + ad->atype = class_type; + ad->u.cd = cd; + ad->name = cd->iff->name; + + ++ad; + } + + for (mtd = pt->mappedtypes; mtd != NULL; mtd = mtd->next) + { + if (mtd->iff->module != mod) + continue; + + if (mtd->iff->first_alt != mtd->iff) + continue; + + ad->atype = mapped_type; + ad->u.mtd = mtd; + ad->name = mtd->cname; + + ++ad; + } + + for (ed = pt->enums; ed != NULL; ed = ed->next) + { + if (ed->module != mod) + continue; + + if (ed->fqcname == NULL) + continue; + + if (ed->ecd != NULL && isTemplateClass(ed->ecd)) + continue; + + if (ed->first_alt != ed) + continue; + + ad->atype = enum_type; + ad->u.ed = ed; + ad->name = ed->cname; + + ++ad; + } + + /* Sort the table and assign type numbers. */ + qsort(mod->types, mod->nrtypes, sizeof (argDef), compareTypes); + + for (ad = mod->types, i = 0; i < mod->nrtypes; ++i, ++ad) + { + switch (ad->atype) + { + case class_type: + ad->u.cd->iff->ifacenr = i; + + /* If we find a class called QObject, assume it's Qt. */ + if (strcmp(ad->name->text, "QObject") == 0) + mod->qobjclass = i; + + break; + + case mapped_type: + ad->u.mtd->iff->ifacenr = i; + break; + + case enum_type: + ad->u.ed->enumnr = i; + break; + } + } +} + + +/* + * The qsort helper to compare two generated type names. + */ +static int compareTypes(const void *t1, const void *t2) +{ + return strcmp(((argDef *)t1)->name->text, ((argDef *)t2)->name->text); +} + + +/* + * Return TRUE if we are generating code for a module, ie. we are a component + * of a consolidated module, or the main module where there is no consolidated + * module. + */ +static int generatingCodeForModule(sipSpec *pt, moduleDef *mod) +{ + if (isConsolidated(pt->module)) + return (pt->module == mod->container); + + return (pt->module == mod); +} |