Exemplo n.º 1
0
static char *
idl_unionCaseTypeFromTypeSpec(
    idl_typeSpec typeSpec)
{
    char typeName[512];

    if (idl_typeSpecType(typeSpec) == idl_tbasic) {
        snprintf(typeName, sizeof(typeName), "%s",
            idl_corbaJavaTypeFromTypeSpec(typeSpec));
    } else if (idl_typeSpecType(typeSpec) == idl_tseq) {
        snprintf (typeName, sizeof(typeName), "%s%s",
            idl_corbaJavaTypeFromTypeSpec(idl_typeSeqActual(idl_typeSeq(typeSpec))),
            idl_sequenceIndexString (idl_typeSeq(typeSpec)));
    } else if (idl_typeSpecType(typeSpec) == idl_tarray) {
        snprintf(typeName, sizeof(typeName), "%s%s",
            idl_corbaJavaTypeFromTypeSpec(idl_typeArrayActual(idl_typeArray(typeSpec))),
            idl_arrayJavaIndexString(idl_typeArray(typeSpec)));
    } else if (idl_typeSpecType(typeSpec) == idl_ttypedef) {
        return idl_unionCaseTypeFromTypeSpec(idl_typeDefActual(idl_typeDef(typeSpec)));
    } else {
        if ((idl_typeSpecType(typeSpec) == idl_tstruct) ||
            (idl_typeSpecType (typeSpec) == idl_tunion) ||
            (idl_typeSpecType (typeSpec) == idl_tenum)) {
            snprintf(typeName, sizeof(typeName), "%s",
                idl_corbaJavaTypeFromTypeSpec(typeSpec));
        } else {
            printf ("idl_unionCaseTypeFromTypeSpec: Unexpected type %d\n",
                idl_typeSpecType(typeSpec));
        }
    }
    return os_strdup(typeName);
}
Exemplo n.º 2
0
c_char *
idl_arrayJavaIndexString (
    idl_typeArray typeArray)
{
    c_char *arrayString;
    os_size_t arrayStringLen;
    c_char *arrayStringPrev;

    if (idl_typeSpecType(idl_typeArrayType(typeArray)) == idl_tarray) {
        arrayStringPrev = idl_arrayJavaIndexString(idl_typeArray(idl_typeArrayType(typeArray)));
        arrayStringLen = strlen(arrayStringPrev) + 3;
        arrayString = os_malloc(arrayStringLen);
        snprintf(arrayString, arrayStringLen, "[]%s", arrayStringPrev);
    } else if (idl_typeSpecType(idl_typeArrayType(typeArray)) == idl_tseq) {
        arrayStringPrev = idl_sequenceIndexString(idl_typeSeq(idl_typeArrayType (typeArray)));
        arrayStringLen = strlen(arrayStringPrev) + 3;
        arrayString = os_malloc(arrayStringLen);
        snprintf(arrayString, arrayStringLen, "[]%s", arrayStringPrev);
    } else if (idl_typeSpecType(idl_typeArrayType(typeArray)) == idl_ttypedef &&
	idl_typeSpecType(idl_typeDefActual(idl_typeDef(idl_typeArrayType(typeArray)))) == idl_tarray) {
        arrayStringPrev = idl_arrayJavaIndexString(idl_typeArray(idl_typeDefActual(idl_typeDef(idl_typeArrayType(typeArray)))));
        arrayStringLen = strlen(arrayStringPrev) + 3;
        arrayString = os_malloc(arrayStringLen);
        snprintf(arrayString, arrayStringLen, "[]%s", arrayStringPrev);
    } else if (idl_typeSpecType(idl_typeArrayType(typeArray)) == idl_ttypedef &&
	idl_typeSpecType(idl_typeDefActual(idl_typeDef(idl_typeArrayType(typeArray)))) == idl_tseq) {
        arrayStringPrev = idl_sequenceIndexString(idl_typeSeq(idl_typeDefActual(idl_typeDef(idl_typeArrayType(typeArray)))));
        arrayStringLen = strlen(arrayStringPrev) + 3;
        arrayString = os_malloc(arrayStringLen);
        snprintf(arrayString, arrayStringLen, "[]%s", arrayStringPrev);
    } else {
        arrayString = os_malloc(3);
        snprintf(arrayString, 3, "[]");
    }
    return arrayString;
}
Exemplo n.º 3
0
/** @brief callback function called on definition of a named type in the IDL input file.
 *
 * Generate code for the following IDL construct:
 * @verbatim
   =>   typedef <type-name> <name>;
   @endverbatim
 *
 * @param scope Current scope
 * @param name Specifies the name of the type
 * @param defSpec Specifies the type of the named type
 */
static void
idl_typedefOpenClose(
    idl_scope scope,
    const char *name,
    idl_typeDef defSpec,
    void *userData)
{
    int nameLen = strlen(idl_javaId(name)) + strlen("Holder") + 1;
    char *holderName;


    if (idl_typeSpecType(idl_typeDefRefered (defSpec)) == idl_tseq) {
        holderName = os_malloc(nameLen);
        snprintf(holderName, nameLen, "%sHolder", idl_javaId(name));
        /* Open file for used scope, if needed create the directories */
        idl_openJavaPackage(scope, holderName);
        if (idl_fileCur() == NULL) {
            return;
        }
        if (idl_scopeStackSize(scope) > 0) {
            idl_fileOutPrintf(
                idl_fileCur(),
                "package %s;\n",
                idl_scopeStackJava(scope, ".", NULL));
            idl_fileOutPrintf(idl_fileCur(), "\n");
        }
        idl_fileOutPrintf(idl_fileCur(), "public final class %s\n{\n\n", holderName);
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s%s value = null;\n\n",
            idl_corbaJavaTypeFromTypeSpec(idl_typeSeqActual(idl_typeSeq(idl_typeDefRefered(defSpec)))),
            idl_sequenceIndexString (idl_typeSeq (idl_typeDefRefered (defSpec))));
        idl_fileOutPrintf(idl_fileCur(), "    public %s () { }\n\n", holderName);
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s (%s%s initialValue)\n",
            holderName,
            idl_corbaJavaTypeFromTypeSpec(idl_typeSeqActual(idl_typeSeq(idl_typeDefRefered(defSpec)))),
            idl_sequenceIndexString(idl_typeSeq (idl_typeDefRefered (defSpec))));
        idl_fileOutPrintf(idl_fileCur(), "    {\n");
        idl_fileOutPrintf(idl_fileCur(), "        value = initialValue;\n");
        idl_fileOutPrintf(idl_fileCur(), "    }\n\n");
        idl_fileOutPrintf(idl_fileCur(), "}\n");
        /* close file */
        idl_closeJavaPackage();
    } else if (idl_typeSpecType(idl_typeDefRefered (defSpec)) == idl_tarray) {
        holderName = os_malloc(nameLen);
        snprintf(holderName, nameLen, "%sHolder", idl_javaId(name));
        /* Open file for used scope, if needed create the directories */
        idl_openJavaPackage(scope, holderName);
        if (idl_fileCur() == NULL) {
            return;
        }
        if (idl_scopeStackSize(scope) > 0) {
            idl_fileOutPrintf(
                idl_fileCur(),
                "package %s;\n",
                idl_scopeStackJava(scope, ".", NULL));
            idl_fileOutPrintf(idl_fileCur(), "\n");
        }
        idl_fileOutPrintf(idl_fileCur(), "public final class %s\n{\n\n", holderName);
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s%s value = null;\n\n",
            idl_corbaJavaTypeFromTypeSpec(idl_typeArrayActual(idl_typeArray(idl_typeDefRefered(defSpec)))),
            idl_arrayJavaIndexString (idl_typeArray (idl_typeDefRefered (defSpec))));
        idl_fileOutPrintf(idl_fileCur(), "    public %s () { }\n\n", holderName);
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s (%s%s initialValue)\n",
            holderName,
            idl_corbaJavaTypeFromTypeSpec(idl_typeArrayActual(idl_typeArray(idl_typeDefRefered(defSpec)))),
            idl_arrayJavaIndexString(idl_typeArray (idl_typeDefRefered (defSpec))));
        idl_fileOutPrintf(idl_fileCur(), "    {\n");
        idl_fileOutPrintf(idl_fileCur(), "        value = initialValue;\n");
        idl_fileOutPrintf(idl_fileCur(), "    }\n\n");
        idl_fileOutPrintf(idl_fileCur(), "}\n");
        /* close file */
        idl_closeJavaPackage();
    }
}
Exemplo n.º 4
0
/** @brief callback function called on definition of a structure member in the IDL input file.
 *
 * Generate code for the following IDL construct:
 * @verbatim
        struct <structure-name> {
   =>       <structure-member-1>;
   =>       ...              ...
   =>       <structure-member-n>;
        };
   @endverbatim
 *
 * @param scope Current scope
 * @param name Name of the structure member
 * @param typeSpec Type specification of the structure member
 */
static void
idl_structureMemberOpenClose(
    idl_scope scope,
    const char *name,
    idl_typeSpec typeSpec,
    void *userData)
{
    /* Dereference possible typedefs first. */
    while (idl_typeSpecType(typeSpec) == idl_ttypedef) {
        typeSpec = idl_typeDefRefered(idl_typeDef(typeSpec));
    }

    /* generate type-name and field-name attribute */
    if ((idl_typeSpecType(typeSpec) == idl_tbasic)) {
        /* store type-name and field-name in iterator (append) */
        idl_mapAdd(map, idl_javaId(name), typeSpec);
        if (idl_typeBasicType(idl_typeBasic (typeSpec)) == idl_string) {
            idl_fileOutPrintf(
                idl_fileCur(),
                "    public %s %s = \"\";\n",
                idl_corbaJavaTypeFromTypeSpec(typeSpec),
                idl_javaId(name));
        } else {
            idl_fileOutPrintf(
                idl_fileCur(),
                "    public %s %s;\n",
                idl_corbaJavaTypeFromTypeSpec(typeSpec),
                idl_javaId(name));
        }
    } else if (idl_typeSpecType(typeSpec) == idl_tseq) {
        /* store type-name and field-name in iterator (append) */
        idl_mapAdd(map, idl_javaId(name), typeSpec);
        /* Inline sequence definition */
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s%s %s = new %s",
            idl_corbaJavaTypeFromTypeSpec(typeSpec),
            idl_sequenceIndexString(idl_typeSeq(typeSpec)),
            idl_javaId(name),
            idl_corbaJavaTypeFromTypeSpec(typeSpec));
        java_arrayDimensions(typeSpec);
        idl_fileOutPrintf (idl_fileCur(), ";\n");
    } else if (idl_typeSpecType(typeSpec) == idl_tarray) {
        /* store type-name and field-name in iterator (append) */
        idl_mapAdd(map, idl_javaId(name), typeSpec);
        /* Inline array definition */
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s%s %s = new %s",
            idl_corbaJavaTypeFromTypeSpec (typeSpec),
            idl_arrayJavaIndexString(idl_typeArray(typeSpec)),
            idl_javaId(name),
            idl_corbaJavaTypeFromTypeSpec (typeSpec));
        java_arrayDimensions(typeSpec);
        idl_fileOutPrintf (idl_fileCur(), ";\n");
    } else if (idl_typeSpecType(typeSpec) == idl_tstruct) {
        /* store type-name and field-name in iterator (append) */
        idl_mapAdd(map, idl_javaId(name), typeSpec);
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s %s = new %s();\n",
            idl_corbaJavaTypeFromTypeSpec(typeSpec),
            idl_javaId(name),
            idl_corbaJavaTypeFromTypeSpec(typeSpec));
    } else if (idl_typeSpecType(typeSpec) == idl_tenum) {
        /* store type-name and field-name in iterator (append) */
        idl_mapAdd(map, idl_javaId(name), typeSpec);
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s %s = %s.from_int(0);\n",
            idl_corbaJavaTypeFromTypeSpec(typeSpec),
            idl_javaId(name),
            idl_corbaJavaTypeFromTypeSpec(typeSpec));
    } else if (idl_typeSpecType (typeSpec) == idl_tunion) {
        /* store type-name and field-name in iterator (append) */
        idl_mapAdd(map, idl_javaId(name), typeSpec);
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s %s = new %s();\n",
            idl_corbaJavaTypeFromTypeSpec(typeSpec),
            idl_javaId(name),
            idl_corbaJavaTypeFromTypeSpec(typeSpec));
    } else {
        printf("idl_genSajType.c:idl_structureMemberOpenClose: Unexpected type %d\n",
            idl_typeSpecType(typeSpec));
    }
}
Exemplo n.º 5
0
/** @brief callback function called on end of a structure definition in the IDL input file.
 *
 * Generate code for the following IDL construct:
 * @verbatim
        struct <structure-name> {
            <structure-member-1>
            ...              ...
            <structure-member-n>
   =>   };
   @endverbatim
 *
 * The structure is closed:
 * @verbatim
        };
   @endverbatim
 *
 * @param name Name of the structure (not used)
 */
static void
idl_structureClose(
    const char *name,
    void *userData)
{
    idl_mapIter mapIter;
    idl_typeSpec typeSpec;
    char *memberName;

    /* build constructor <type-name> () {} */
    idl_fileOutPrintf(idl_fileCur(), "\n");
    idl_fileOutPrintf(idl_fileCur(), "    public %s() {\n", idl_javaId(name));

    mapIter = idl_mapFirst(map);
    while (idl_mapIterObject(mapIter)) {
        typeSpec = idl_mapIterObject(mapIter);
        memberName = idl_mapIterKey(mapIter);
        idl_ifArrayInitializeElements(typeSpec, memberName);
        idl_mapIterNext(mapIter);
    }
    idl_fileOutPrintf(idl_fileCur(), "    }\n\n");

    /* build constructor <type-name> (<arglist>) { <assignment-list> } */
    idl_fileOutPrintf(idl_fileCur(), "    public %s(\n", idl_javaId(name));
    mapIter = idl_mapFirst(map);
    while (idl_mapIterObject(mapIter)) {
        typeSpec = idl_mapIterObject(mapIter);
        memberName = idl_mapIterKey(mapIter);
        if (idl_typeSpecType(typeSpec) == idl_tbasic) {
            idl_fileOutPrintf(
                idl_fileCur(),
                "        %s _%s",
                idl_corbaJavaTypeFromTypeSpec(typeSpec),
                memberName);
        } else if (idl_typeSpecType(typeSpec) == idl_tseq) {
            idl_fileOutPrintf(
                idl_fileCur(),
                "        %s%s _%s",
                idl_corbaJavaTypeFromTypeSpec(typeSpec),
                idl_sequenceIndexString(idl_typeSeq(typeSpec)),
                memberName);
        } else if (idl_typeSpecType(typeSpec) == idl_tarray) {
            idl_fileOutPrintf(
                idl_fileCur(),
                "        %s%s _%s",
                idl_corbaJavaTypeFromTypeSpec(typeSpec),
                idl_arrayJavaIndexString(idl_typeArray(typeSpec)),
                memberName);
        } else {
            if (idl_typeSpecType(typeSpec) == idl_ttypedef) {
                if (idl_typeSpecType(idl_typeDefActual(idl_typeDef(typeSpec))) == idl_tbasic) {
                    idl_fileOutPrintf(
                        idl_fileCur(),
                        "        %s _%s",
                        idl_corbaJavaTypeFromTypeSpec(idl_typeDefActual(idl_typeDef(typeSpec))),
                        memberName);
                } else if (idl_typeSpecType(idl_typeDefActual(idl_typeDef(typeSpec))) == idl_tseq) {
                    idl_fileOutPrintf(
                        idl_fileCur(),
                        "        %s%s _%s",
                        idl_corbaJavaTypeFromTypeSpec(typeSpec),
                        idl_sequenceIndexString(idl_typeSeq(idl_typeDefActual(idl_typeDef(typeSpec)))),
                        memberName);
                } else if (idl_typeSpecType(idl_typeDefActual(idl_typeDef(typeSpec))) == idl_tarray) {
                    idl_fileOutPrintf(
                        idl_fileCur(),
                        "        %s%s _%s",
                        idl_corbaJavaTypeFromTypeSpec(typeSpec),
                        idl_arrayJavaIndexString(idl_typeArray(idl_typeDefActual(idl_typeDef(typeSpec)))),
                        memberName);
                } else {
                    if ((idl_typeSpecType(idl_typeDefActual(idl_typeDef(typeSpec))) == idl_tstruct) ||
                        (idl_typeSpecType(idl_typeDefActual(idl_typeDef(typeSpec))) == idl_tunion) ||
                        (idl_typeSpecType(idl_typeDefActual(idl_typeDef(typeSpec))) == idl_tenum)) {
                        idl_fileOutPrintf(
                            idl_fileCur(),
                            "        %s _%s",
                            idl_corbaJavaTypeFromTypeSpec(idl_typeDefActual(idl_typeDef(typeSpec))),
                            idl_javaId(memberName));
                    } else {
                        printf("idl_genSajType.c:idl_structureClose: Unexpected type %d\n",
                            idl_typeSpecType (typeSpec));
                    }
                }
            } else {
                if ((idl_typeSpecType(typeSpec) == idl_tstruct) ||
                    (idl_typeSpecType(typeSpec) == idl_tunion) ||
                    (idl_typeSpecType(typeSpec) == idl_tenum)) {
                    idl_fileOutPrintf(
                        idl_fileCur(),
                        "        %s _%s",
                        idl_corbaJavaTypeFromTypeSpec(typeSpec),
                        idl_javaId(memberName));
                } else {
                    printf("idl_genSajType.c:idl_structureClose: Unexpected type %d\n",
                        idl_typeSpecType(typeSpec));
                }
            }
        }
        idl_mapIterNext(mapIter);
        if (idl_mapIterObject(mapIter)) {
            idl_fileOutPrintf(idl_fileCur(), ",\n");
        } else {
            idl_fileOutPrintf(idl_fileCur(), ")\n");
        }
    }
    idl_mapIterFree(mapIter);
    idl_fileOutPrintf(idl_fileCur(), "    {\n");
    mapIter = idl_mapFirst(map);
    while (idl_mapIterObject(mapIter)) {
        idl_fileOutPrintf(
            idl_fileCur(),
            "        %s = _%s;\n",
            idl_mapIterKey(mapIter),
            idl_mapIterKey(mapIter));
            idl_mapIterNext (mapIter);
    }
    idl_mapIterFree(mapIter);
    idl_fileOutPrintf(idl_fileCur(), "    }\n\n");
    /* close class */
    idl_fileOutPrintf(idl_fileCur(), "}\n");
    /* close file */
    idl_closeJavaPackage();
    /* remove iterator */
    idl_mapFree(map);
}