static void idl_typedefOpenClose( idl_scope scope, const char *name, idl_typeDef defSpec, void *userData) { c_char spaces[20]; idl_tmplExp te; /* QAC EXPECT 3416; No unexpected side effects here */ if ((idl_typeSpecType(idl_typeDefRefered(defSpec)) == idl_tstruct || idl_typeSpecType(idl_typeDefRefered(defSpec)) == idl_tunion) && idl_keyResolve(idl_keyDefDefGet(), scope, name) != NULL) { /* keylist defined for this typedef of struct or union */ te = idl_tmplExpNew(idlpp_macroSet); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("type_name", idl_scopeStack(scope, "_", name))); snprintf(spaces, (size_t)sizeof(spaces), "%d", idlpp_indent_level*4); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("spaces", spaces)); idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib); idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur()); idl_streamInFree(idlpp_inStream); idl_tmplExpFree(te); } }
static void idl_typedefOpenClose( idl_scope scope, const char *name, idl_typeDef defSpec, void *userData) { c_char spaces[20]; idl_tmplExp te; OS_UNUSED_ARG(userData); if ((idl_typeSpecType(idl_typeDefRefered(defSpec)) == idl_tstruct || (idl_typeSpecType(idl_typeDefRefered(defSpec)) == idl_tunion)) && (idl_streamsResolve(idl_streamsDefDefGet(), scope, name))) { /* keylist defined for this typedef of struct or union */ te = idl_tmplExpNew(idlpp_macroSet); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("namescope", idl_cxxId(idl_scopeElementName(idl_scopeCur(scope))))); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("typename", idl_cxxId(name))); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scopedtypename", idl_scopeStack(scope, "::", name))); snprintf(spaces, sizeof(spaces), "%d", idlpp_indent_level*4); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("spaces", spaces)); idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib); idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur()); idl_streamInFree(idlpp_inStream); idl_tmplExpFree(te); } }
/* @brief function to find out whether the elements of an array * require initialization. * * idl_arrayElementsNeedInitialization is a local support function to find out * whether the specified array is of a type for which all elements need to be * initialized individually. If the array is of a primitive type, this is never * necessary, but if the array contains a reference type and no underlying * sequences (which will be initialized to 0 elements) then for loops will * need to be created to explicitly initialize all of these attributes. * * @param typeSpec Specifies the attribute type that needs to be investigated. */ static int idl_arrayElementsNeedInitialization( idl_typeArray typeArray) { int initRequired = FALSE; /* Obtain the type of the array. */ idl_typeSpec typeSpec = idl_typeArrayType(typeArray); /* Resolve potential typedefs. */ while (idl_typeSpecType(typeSpec) == idl_ttypedef) { typeSpec = idl_typeDefRefered(idl_typeDef(typeSpec)); } if (idl_typeSpecType(typeSpec) == idl_tarray) { initRequired = idl_arrayElementsNeedInitialization(idl_typeArray(typeSpec)); } else if ( idl_typeSpecType(typeSpec) == idl_tstruct || idl_typeSpecType(typeSpec) == idl_tunion || idl_typeSpecType(typeSpec) == idl_tenum || ( idl_typeSpecType(typeSpec) == idl_tbasic && idl_typeBasicType(idl_typeBasic (typeSpec)) == idl_string) ) { initRequired = TRUE; } return initRequired; }
static void idl_typedefOpenClose( idl_scope scope, const char *name, idl_typeDef defSpec, void *userData) { idl_tmplExp te; if ((idl_typeSpecType(idl_typeDefRefered(defSpec)) == idl_tstruct || idl_typeSpecType(idl_typeDefRefered(defSpec)) == idl_tunion) && idl_keyResolve(idl_keyDefDefGet(), scope, name) != NULL) { /* keylist defined for this typedef of struct or union */ te = idl_tmplExpNew(idlpp_macroSet); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scope", idl_scopeStackCxx(scope, "::", NULL))); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("typename", idl_cxxId(name))); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scopedtypename", idl_scopeStack(scope, "::", name))); idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib); idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur()); idl_streamInFree(idlpp_inStream); idl_tmplExpFree(te); } }
/* @brief generate dimension of an array or a sequence * * java_arrayDimensions is a local support function to generate * the dimensions of a java Array representing an IDL sequence or * array. Since Sequences will always be initialized to 0 elements, * its dimensions will always be assigned 0. Arrays will be assigned * their IDL dimensions. * * @param typeSeq Specifies the type of the sequence */ static void java_arrayDimensions( idl_typeSpec typeSpec) { while (idl_typeSpecType(typeSpec) == idl_ttypedef) { typeSpec = idl_typeDefRefered(idl_typeDef(typeSpec)); } if (idl_typeSpecType(typeSpec) == idl_tarray) { idl_typeArray typeArray = idl_typeArray(typeSpec); idl_fileOutPrintf (idl_fileCur(), "[%d]", idl_typeArraySize(typeArray)); java_arrayDimensions(idl_typeArrayType(typeArray)); } else if (idl_typeSpecType(typeSpec) == idl_tseq) { idl_fileOutPrintf(idl_fileCur(), "[0]"); java_arrayDimensions(idl_typeSeqType(idl_typeSeq(typeSpec))); } }
/* @brief generate initialization of array elements. * * idl_ifArrayInitializeElements is a local support function to initialize * the elements of non-primitive array types, if appropriate. * * @param typeSpec Type of the attribute that might need to be initialized. * @param elementName Name of the attribute that might need to be initialized. */ static void idl_ifArrayInitializeElements( idl_typeSpec typeSpec, const char *elementName) { int dimCount = 1; int indent = 8; while (idl_typeSpecType(typeSpec) == idl_ttypedef) { typeSpec = idl_typeDefRefered(idl_typeDef(typeSpec)); } if ( idl_typeSpecType(typeSpec) == idl_tarray) { if (idl_arrayElementsNeedInitialization(idl_typeArray(typeSpec))) { idl_arrayElementInit( typeSpec, elementName, dimCount, indent); } } }
/* Return the scoped actual type specification where for the user types, scopes are separated by "_" chracters. IDL strings (bounded and unbounded) are mapped on: c_string, other basic types are mapped on corresponding splice types IDL structures are identified by: struct <scoped-struct-name> IDL unions are identified by: struct <scoped-union-name> becuase the union mapping is: struct <union-name> { <tag-type> _d; union { <union-case-specifications> } _u; } IDL enumerations are identified by: enum <scoped-enum-name> IDL typedefs are formed by the scoped type name IDL sequences are mapped on: c_sequence */ static c_char * idl_scopedSacSequenceElementTypeIdent ( const idl_typeSpec typeSpec) { c_char scopedTypeIdent[256]; /* QAC EXPECT 3416; No unexpected side effects here */ if (idl_typeSpecType(typeSpec) == idl_tbasic) { switch (idl_typeBasicType(idl_typeBasic(typeSpec))) { case idl_short: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "DDS_short"); break; case idl_ushort: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "DDS_unsigned_short"); break; case idl_long: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "DDS_long"); break; case idl_ulong: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "DDS_unsigned_long"); break; case idl_longlong: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "DDS_long_long"); break; case idl_ulonglong: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "DDS_unsigned_long_long"); break; case idl_float: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "DDS_float"); break; case idl_double: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "DDS_double"); break; case idl_char: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "DDS_char"); break; case idl_string: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "DDS_string"); break; case idl_boolean: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "DDS_boolean"); break; case idl_octet: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "DDS_octet"); break; default: os_strncpy (scopedTypeIdent, "", (size_t)sizeof(scopedTypeIdent)); } } else if (idl_typeSpecType(typeSpec) == idl_tstruct || idl_typeSpecType(typeSpec) == idl_tunion || idl_typeSpecType(typeSpec) == idl_tenum) { /* QAC EXPECT 3416; No unexpected side effects here */ snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "%s", idl_sacTypeFromTypeSpec(idl_typeSpec(typeSpec))); /* QAC EXPECT 3416; No unexpected side effects here */ } else if (idl_typeSpecType(typeSpec) == idl_ttypedef) { switch (idl_typeSpecType(idl_typeDefRefered (idl_typeDef(typeSpec)))) { case idl_tarray: case idl_tseq: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "%s", idl_sacTypeFromTypeSpec(typeSpec)); break; case idl_ttypedef: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "%s", idl_scopedSacSequenceTypeIdent(idl_typeDefRefered (idl_typeDef(typeSpec)))); break; default: snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "%s", idl_sacTypeFromTypeSpec(idl_typeDefActual(idl_typeDef(typeSpec)))); } /* QAC EXPECT 3416; No unexpected side effects here */ } else if (idl_typeSpecType(typeSpec) == idl_tarray) { snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "%s", idl_scopedSacSequenceTypeIdent (idl_typeArrayActual(idl_typeArray(typeSpec)))); } else if (idl_typeSpecType(typeSpec) == idl_tseq) { snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "%s", idl_sequenceIdent(idl_typeSeq(typeSpec))); } else { /* Do nothing, only to prevent dangling else-ifs QAC messages */ } return os_strdup(scopedTypeIdent); }
/** @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(); } }
/** @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) { struct idl_genSACPPData *arg = (struct idl_genSACPPData *)userData; idl_typeSpec actualType; idl_typeSpec refType; const char *refName; char *scopedName; actualType = idl_typeDefActual(defSpec); refType = idl_typeDefRefered(defSpec); refName = idl_typeSpecName(refType); scopedName = idl_corbaCxxTypeFromTypeSpec(idl_typeSpec(defSpec)); if (idl_typeSpecType(refType) == idl_tarray) { /* ex. typedef long myArr[22]; */ idl_arrayTypeImpl(idl_typeArray(refType), scopedName, arg); } else { if (idl_typeSpecType(actualType) == idl_tarray) { /* Generate implementation _alloc() method */ idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"%s_slice *%s_alloc()\n", scopedName, scopedName); idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"{\n"); idl_printIndent(arg->indent_level+1); idl_fileOutPrintf(idl_fileCur(),"return (%s_slice *)%s_alloc();\n", scopedName, refName); idl_printIndent(arg->indent_level+1); idl_fileOutPrintf(idl_fileCur(),"}\n\n"); /* Generate implementation _free() method: * Implementation is independent of the actual type. */ idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"void %s_free(%s_slice *s)\n", scopedName, scopedName); idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"{\n"); idl_printIndent(arg->indent_level+1); idl_fileOutPrintf(idl_fileCur(),"%s_free(s);\n", refName); idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"}\n\n"); /* Generate implementation _copy() method */ idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"void *%s_copy(%s_slice *to, const %s_slice *from)\n", scopedName, scopedName, scopedName); idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"{\n"); idl_printIndent(arg->indent_level+1); idl_fileOutPrintf(idl_fileCur(),"%s_copy(to, from);\n", refName); idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"}\n\n"); /* Generate implementation _dup() method */ idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"%s_slice *%s_dup(const %s_slice *from)\n", scopedName, scopedName); idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"{\n"); arg->indent_level++; idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"%s_slice *to = %s_alloc();\n", scopedName, scopedName); idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"%s_copy(to, from);\n", refName); idl_printIndent(arg->indent_level); idl_fileOutPrintf(idl_fileCur(),"return to;\n"); arg->indent_level--; idl_fileOutPrintf(idl_fileCur(),"}\n\n"); } } os_free(scopedName); }
/** @brief callback function called on closure of a union in the IDL input file. * * Generate code for the following IDL construct: * @verbatim union <union-name> switch(<switch-type>) { case label1.1; .. case label1.n; <union-case-1>; case label2.1; .. case label2.n; ... ... case labeln.1; .. case labeln.n; <union-case-n>; default: <union-case-m>; => }; @endverbatim * * The union is closed: * @verbatim } _u; }; @endverbatim * @param name Name of the union */ static void idl_unionClose( const char *name, void *userData) { idl_mapIter mapIter; idl_typeSpec typeSpec; char *memberName; mapIter = idl_mapFirst(map); typeSpec = idl_mapIterObject(mapIter); memberName = idl_mapIterKey(mapIter); idl_fileOutPrintf(idl_fileCur(), " public %s () {\n", idl_javaId(name)); while (idl_typeSpecType(typeSpec) == idl_ttypedef) { typeSpec = idl_typeDefRefered(idl_typeDef(typeSpec)); } if (idl_typeSpecType(typeSpec) == idl_tbasic) { if (idl_typeBasicType(idl_typeBasic (typeSpec)) == idl_string) { idl_fileOutPrintf( idl_fileCur(), " __%s = \"\";\n", idl_javaId(memberName)); } else if (idl_typeBasicType(idl_typeBasic (typeSpec)) == idl_boolean) { idl_fileOutPrintf( idl_fileCur(), " __%s = false;\n", idl_javaId(memberName)); } else if (idl_typeBasicType(idl_typeBasic (typeSpec)) == idl_char) { idl_fileOutPrintf( idl_fileCur(), " __%s = '\\0';\n", idl_javaId(memberName)); } else { idl_fileOutPrintf( idl_fileCur(), " __%s = 0;\n", idl_javaId(memberName)); } } else if (idl_typeSpecType(typeSpec) == idl_tseq || idl_typeSpecType(typeSpec) == idl_tarray) { int __memberNameLength; char *__memberName; __memberNameLength = strlen(memberName) + 2 + 1; __memberName = os_malloc(__memberNameLength); snprintf(__memberName, __memberNameLength, "__%s", memberName); idl_fileOutPrintf( idl_fileCur(), " __%s = new %s", idl_javaId(memberName), idl_corbaJavaTypeFromTypeSpec(typeSpec)); java_arrayDimensions(typeSpec); idl_fileOutPrintf(idl_fileCur(), ";\n"); idl_ifArrayInitializeElements(typeSpec, __memberName); os_free(__memberName); } else if (idl_typeSpecType(typeSpec) == idl_tstruct || idl_typeSpecType(typeSpec) == idl_tunion) { idl_fileOutPrintf( idl_fileCur(), " __%s = new %s();\n", idl_javaId(memberName), idl_corbaJavaTypeFromTypeSpec(typeSpec)); } else if (idl_typeSpecType(typeSpec) == idl_tenum) { idl_fileOutPrintf( idl_fileCur(), " __%s = %s.from_int(0);\n", idl_javaId(memberName), idl_corbaJavaTypeFromTypeSpec(typeSpec)); } idl_fileOutPrintf(idl_fileCur(), " _d = (%s)%s;\n", unionSwitchType, union1stCaseValue); idl_fileOutPrintf(idl_fileCur(), " }\n"); idl_mapIterFree(mapIter); idl_mapFree(map); union1stCaseValue = NULL; /* close class */ idl_fileOutPrintf(idl_fileCur(), "}\n"); /* close file */ idl_closeJavaPackage(); }
/** @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)); } }
/* @brief generate initialization of array elements. * * idl_arrayElementInit generates for-loops that initialize * each attribute of an array explicitly. * * @param typeArray Specifies the type of the array */ static void idl_arrayElementInit( idl_typeSpec typeSpec, const char *elementName, int dimCount, int indent) { while (idl_typeSpecType(typeSpec) == idl_ttypedef) { typeSpec = idl_typeDefRefered(idl_typeDef(typeSpec)); } if (idl_typeSpecType(typeSpec) == idl_tarray) { idl_fileOutPrintf( idl_fileCur(), "%*sfor(int i%d = 0; i%d < %d; i%d++) {\n", indent, "", dimCount, dimCount, idl_typeArraySize(idl_typeArray(typeSpec)), dimCount); idl_arrayElementInit( idl_typeArrayType(idl_typeArray(typeSpec)), elementName, dimCount + 1, indent + 4); idl_fileOutPrintf( idl_fileCur(), "%*s}\n", indent, ""); } else { int j; idl_fileOutPrintf( idl_fileCur(), "%*s%s", indent, "", elementName); for (j = 1; j < dimCount; j++) { idl_fileOutPrintf(idl_fileCur(), "[i%d]", j); } if ( idl_typeSpecType(typeSpec) == idl_tbasic && idl_typeBasicType(idl_typeBasic(typeSpec)) == idl_string) { idl_fileOutPrintf( idl_fileCur(), " = \"\";\n"); } else if ( idl_typeSpecType(typeSpec) == idl_tunion || idl_typeSpecType(typeSpec) == idl_tstruct ) { idl_fileOutPrintf( idl_fileCur(), " = new %s();\n", idl_corbaJavaTypeFromTypeSpec(typeSpec)); } else if (idl_typeSpecType(typeSpec) == idl_tenum) { idl_fileOutPrintf( idl_fileCur(), " = %s.from_int(0);\n", idl_corbaJavaTypeFromTypeSpec(typeSpec)); } } }
/** @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 * * This function generates a prototype for the helper function to * load the typedef metadata if the typedef is defined * within the global scope or the scope of a module. * The name of the metadata load function is: * @verbatim __<scope-elements>_<name>__load @endverbatim * If the type specification is idl_tbasic a standard mapping will be applied: * @verbatim typedef <basic-type-mapping> <scope-elements>_<name>; @endverbatim * If the type specification is a user defined idl_ttypedef, idl_tenum, * idl_tstruct or idl_tunion a scoped name mapping will be generated. * @verbatim <typedef-name> <name>; => typedef enum <scope-elements>_<typedef-name> <scope-elements>_<name>; <enum-name> <name>; => typedef enum <scope-elements>_<enum-name> <scope-elements>_<name>; <struct-name> <name>; => typedef struct <scope-elements>_<structure-name> <scope-elements>_<name>; <union-name> <name>; => typedef struct <scope-elements>_<union-name> <scope-elements>_<name>; @endverbatim * If the type specification is idl_tarray then generate a scoped name * with the array specifiers: * @verbatim <other-usertype-name> <name>[n1]..[nn]; => typedef <scope-elements>_<other-usertype-name> <scope-elements>_<name>[n1]..[nn]; <basic-type> <name>[n1]..[nn]; => typedef <basic-type-mapping> <scope-elements>_<name>[n1]..[nn]; sequence<spec> <name>[n1]..[nn]; => typedef c_array <scope-elements>_<name>[n1]..[nn]; sequence<spec,length> <name>[n1]..[nn]; => typedef c_array <scope-elements>_<name>[n1]..[nn]; @endverbatim * If the type specification is idl_tseq then generate a mapping on c_sequence: * @verbatim sequence<spec> <name>; => typedef c_sequence <scope-elements>_<name>; sequence<spec,length> <name>; => typedef c_sequence <scope-elements>_<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) { if (idl_scopeStackSize(scope) == 0 || idl_scopeElementType (idl_scopeCur(scope)) == idl_tModule) { idl_fileOutPrintf( idl_fileCur(), "extern c_metaObject __%s__load (c_base base);\n", idl_scopeStack(scope, "_", name)); if (idl_typeSpecType(idl_typeDefActual(defSpec)) == idl_tstruct || idl_typeSpecType(idl_typeDefActual(defSpec)) == idl_tunion) { /* If this is a typedef of a struct or union */ /* define the prototype of the function for querying the keys */ idl_fileOutPrintf( idl_fileCur(), "extern const char * __%s__keys (void);\n", idl_scopeStack(scope, "_", name)); /* define the prototype of the function for querying scoped structure name */ idl_fileOutPrintf( idl_fileCur(), "extern const char * __%s__name (void);\n", idl_scopeStack(scope, "_", name)); } } if (idl_typeSpecType(idl_typeSpec(idl_typeDefRefered(defSpec))) == idl_ttypedef || idl_typeSpecType(idl_typeSpec(idl_typeDefRefered(defSpec))) == idl_tenum || idl_typeSpecType(idl_typeSpec(idl_typeDefRefered(defSpec))) == idl_tstruct || idl_typeSpecType(idl_typeSpec(idl_typeDefRefered(defSpec))) == idl_tunion || idl_typeSpecType(idl_typeSpec(idl_typeDefRefered(defSpec))) == idl_tbasic) { /* generate code for a standard mapping or a typedef, enum, struct or union user-type mapping */ idl_printIndent(indent_level); idl_fileOutPrintf( idl_fileCur(), "typedef %s _%s;\n\n", idl_scopedSplTypeIdent(idl_typeSpec(idl_typeDefRefered(defSpec))), idl_scopeStack (scope, "_", name)); } else if (idl_typeSpecType(idl_typeSpec(idl_typeDefRefered(defSpec))) == idl_tarray) { /* generate code for an array mapping */ idl_printIndent(indent_level); idl_fileOutPrintf( idl_fileCur(), "typedef %s _%s", idl_scopedSplTypeIdent(idl_typeArrayActual (idl_typeArray(idl_typeDefRefered(defSpec)))), idl_scopeStack(scope, "_", name)); idl_arrayDimensions(idl_typeArray(idl_typeDefRefered(defSpec)), OS_FALSE); idl_fileOutPrintf(idl_fileCur(), ";\n\n"); } else if (idl_typeSpecType(idl_typeSpec(idl_typeDefRefered(defSpec))) == idl_tseq) { /* generate code for a sequence mapping */ idl_printIndent(indent_level); if (idl_typeSeqMaxSize (idl_typeSeq(idl_typeDefRefered(defSpec))) == 0) { /* unbounded sequence */ idl_fileOutPrintf( idl_fileCur(), "typedef c_sequence _%s", idl_scopeStack (scope, "_", name)); } else { /* bounded sequence */ idl_fileOutPrintf( idl_fileCur(), "typedef c_sequence _%s", idl_scopeStack(scope, "_", name)); } idl_fileOutPrintf (idl_fileCur(), ";\n\n"); } else { printf("idl_typedefOpenClose: Unsupported typedef type (typename = %s, type = %s)\n", name, idl_scopedTypeName(idl_typeSpec(defSpec))); } }