/* Return the C++ specific type identifier for the specified type specification */ c_char * idl_corbaCxxTypeFromTypeSpec( idl_typeSpec typeSpec) { c_char *typeName; /* QAC EXPECT 3416; No side effects here */ if (idl_typeSpecType(typeSpec) == idl_tbasic) { /* if the specified type is a basic type */ if (idl_getCorbaMode() == IDL_MODE_STANDALONE) { typeName = standaloneTypeFromTypeSpec(idl_typeBasic(typeSpec)); } else { typeName = corbaTypeFromTypeSpec(idl_typeBasic(typeSpec)); } } else if ((idl_typeSpecType(typeSpec) == idl_tseq) || (idl_typeSpecType(typeSpec) == idl_tarray)) { /* sequence does not have an identification */ typeName = os_strdup (""); printf ("idl_corbaCxxTypeFromTypeSpec: Unexpected type handled\n"); assert(0); } else { /* if a user type is specified build it from its scope and its name. The type should be one of idl_ttypedef, idl_tenum, idl_tstruct, idl_tunion. */ typeName = idl_scopeStackCxx( idl_typeUserScope(idl_typeUser(typeSpec)), "::", idl_typeSpecName(typeSpec)); } return typeName; /* QAC EXPECT 5101; The switch statement is simple, therefor the total complexity is low */ }
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); } }
/* Return the scoped type name where for the user types, scopes are separated by "_" chracters. */ c_char * idl_scopedTypeName ( const idl_typeSpec typeSpec) { const char *scopedTypeName; /* QAC EXPECT 3416; No unexpected side effects here */ if (idl_typeSpecType(typeSpec) == idl_tseq) { /* Sequences map to c_sequence */ scopedTypeName = "c_sequence"; /* QAC EXPECT 3416; No unexpected side effects here */ } else if (idl_typeSpecType(typeSpec) == idl_tbasic) { /* For basic types take the corresponding type name supported by the splice database */ /* QAC EXPECT 3416; No unexpected side effects here */ if (idl_typeBasicType(idl_typeBasic(typeSpec)) == idl_string) { /* in case of bounded string the type name must become c_string */ /* type name is of form "C_STRING<xx>" */ scopedTypeName = "c_string"; } else { scopedTypeName = idl_typeSpecName(idl_typeSpec(typeSpec)); } } else { /* Build a name for user types from scope and its own name */ scopedTypeName = idl_scopeStack ( idl_typeUserScope(idl_typeUser(typeSpec)), "_", idl_typeSpecName(idl_typeSpec(typeSpec))); } return os_strdup(scopedTypeName); }
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 generate dimension of an array slice * * arraySliceDimensions is a local support function to generate * the array dimensions of an array slice * * @param typeArray Specifies the type of the array */ static void idl_arraySliceDimensions( idl_typeArray typeArray) { idl_fileOutPrintf(idl_fileCur(), "[%d]", idl_typeArraySize(typeArray)); if (idl_typeSpecType(idl_typeArrayType(typeArray)) == idl_tarray && idl_typeSpecType(idl_typeArrayType(idl_typeArray(idl_typeArrayType(typeArray)))) == idl_tarray) { idl_arraySliceDimensions(idl_typeArray(idl_typeArrayType(typeArray))); } }
/** @brief callback function called on definition 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 * * This function generates prototypes for the helper functions to * load the unions metadata, to determine the unions keys and the * scoped name of the union if the union is defined in the global * scope or within a module. * The name of the metadata load function is: * @verbatim __<scope-elements>_<structure-name>__load @endverbatim * The name of the key query function is: * @verbatim __<scope-elements>_<union-name>__keys @endverbatim * The name of the name query function is: * @verbatim __<scope-elements>_<union-name>__name @endverbatim * If the union is defined within another union or within a * struct, no key nor its name can be queried. Such a union * can not be communicated via Splice as a separate entity. * IDL unions are mapped onto C structs for Splice in the * following manner: * @verbatim struct <union-name> { <switch-type> _d; union { <union-case-1>; ... ... <union-case-m>; } _u; }; @endverbatim * The union definition is opened: * @verbatim struct <scope-elements>_<name> { @endverbatim * Then depending on the type of the switch (integral type is required) any of the following: * @verbatim enum <enum-type> _d; // for an enumeration <scope-elements>_<typedef-name> _d; // for an typedeffed enum or basic type <basic-type-mapping> _d; // for an integral basic type @endverbatim * Then open the union part: * @verbatim union { @endverbatim * * @param scope Current scope * @param name Name of the union * @param unionSpec Specifies the number of union cases and the union switch type * @return Next action for this union (idl_explore) */ static idl_action idl_unionOpen( idl_scope scope, const char *name, idl_typeUnion unionSpec, void *userData) { if (idl_scopeStackSize(scope) == 0 || idl_scopeElementType (idl_scopeCur(scope)) == idl_tModule) { /* define the prototype of the function for metadata load */ idl_fileOutPrintf(idl_fileCur(), "extern c_metaObject __%s__load (c_base base);\n", idl_scopeStack(scope, "_", name)); /* 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 union name */ idl_fileOutPrintf(idl_fileCur(), "extern const char * __%s__name (void);\n", idl_scopeStack(scope, "_", name)); } /* open the struct */ idl_printIndent(indent_level); idl_fileOutPrintf(idl_fileCur(), "struct _%s {\n", idl_scopeStack(scope, "_", name)); indent_level++; /* generate code for the switch */ if (idl_typeSpecType(idl_typeUnionSwitchKind(unionSpec)) == idl_tbasic) { idl_printIndent(indent_level); idl_fileOutPrintf (idl_fileCur(), "%s _d;\n", idl_scopedTypeName(idl_typeUnionSwitchKind(unionSpec))); } else if (idl_typeSpecType(idl_typeUnionSwitchKind(unionSpec)) == idl_tenum) { idl_printIndent(indent_level); idl_fileOutPrintf(idl_fileCur(), "%s _d;\n", idl_scopedSplTypeName(idl_typeUnionSwitchKind(unionSpec))); } else if (idl_typeSpecType(idl_typeUnionSwitchKind(unionSpec)) == idl_ttypedef) { switch (idl_typeSpecType(idl_typeDefActual(idl_typeDef(idl_typeUnionSwitchKind(unionSpec))))) { case idl_tbasic: case idl_tenum: idl_printIndent(indent_level); idl_fileOutPrintf (idl_fileCur(), "%s _d;\n", idl_scopedSplTypeName(idl_typeUnionSwitchKind(unionSpec))); break; default: printf ("idl_unionOpen: Unsupported switchkind\n"); } } else { printf ("idl_unionOpen: Unsupported switchkind\n"); } /* open the union */ idl_printIndent(indent_level); idl_fileOutPrintf(idl_fileCur(), "union {\n"); indent_level++; /* return idl_explore to indicate that the rest of the union needs to be processed */ return idl_explore; }
static void idl_typedefOpenClose( idl_scope scope, const char *name, idl_typeDef defSpec, void *userData) { if ((idl_typeSpecType(idl_typeDefActual (defSpec)) == idl_tstruct) || (idl_typeSpecType(idl_typeDefActual (defSpec)) == idl_tunion)) { if (idl_keyResolve(idl_keyDefDefGet(), scope, name) != NULL) { newMeta(scope, name, idl_typeSpec(defSpec)); } } }
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); }
os_boolean idl_stacDef_isStacDefined( idl_scope scope, const char *name, idl_typeSpec typeSpec, idl_typeSpec* baseStringTypeDereffered) { os_boolean isStacDefined = OS_FALSE; idl_typeSpec typeDereffered; idl_typeSpec subType; idl_scope tmpScope; os_char* containingElement; idl_basicType basic; c_ulong maxlen; /* resolve any type defs */ typeDereffered = idl_typeDefResolveFully(typeSpec); if(idl_typeSpecType(typeDereffered) == idl_tarray) { /* If this is an array, then get the sub type and recurse deeper into this * operation. Arrays of bounded strings are allowed for pragma stac */ subType = idl_typeArrayActual(idl_typeArray(typeDereffered)); isStacDefined = idl_stacDef_isStacDefined(scope, name, subType, baseStringTypeDereffered); } else if(idl_typeSpecType(typeDereffered) == idl_tbasic) { /* Get the basic type to see if it is a string */ basic = idl_typeBasicType(idl_typeBasic(typeDereffered)); if(basic == idl_string) { /* If this is indeed a string, then get the 'maxLen' attribute of the * string type. If it is not 0, then this is a bounded string */ maxlen = idl_typeBasicMaxlen(idl_typeBasic(typeDereffered)); if(maxlen != 0) { tmpScope = idl_scopeDup(scope); containingElement = idl_scopeElementName(idl_scopeCur (scope)); idl_scopePop(tmpScope); isStacDefined = idl_stacListItemIsDefined (idl_stacDefDefGet(), tmpScope, containingElement, name); if(isStacDefined && baseStringTypeDereffered) { *baseStringTypeDereffered = typeDereffered; } } /* else stac define status not relevant for this member */ } /* else stac define status not relevant for this member */ } /* else stac define status not relevant for this member */ return isStacDefined; }
/* @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 callback function called on definition of a union case 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 * * @param scope Current scope (the union the union case is defined in) * @param name Name of the union case * @param typeSpec Specifies the type of the union case */ static void idl_unionCaseOpenClose( idl_scope scope, const char *name, idl_typeSpec typeSpec, void *userData) { struct idl_genSACPPData *arg = (struct idl_genSACPPData *)userData; char *seqName; switch (idl_typeSpecType(typeSpec)) { case idl_tbasic: case idl_tenum: case idl_ttypedef: case idl_tstruct: case idl_tunion: break; case idl_tarray: /* generate code for an array mapping */ snprintf(arg->buffer,MAX_BUFFER,"_%s_array", name); seqName = os_strdup(arg->buffer); idl_arrayTypeImpl(idl_typeArray(typeSpec),seqName,arg); os_free(seqName); break; case idl_tseq: break; default: printf("idl_unionCaseOpenClose: Unsupported union member type (member name = %s, type name = %s)\n", name, idl_scopedTypeName(typeSpec)); } }
/* @brief generate dimension of an array * * arrayDimensions is a local support function to generate * the array dimensions of an array * * @param typeArray Specifies the type of the array */ static void idl_arrayDimensions ( idl_typeArray typeArray, os_boolean resolveTypedefs) { idl_typeSpec subType; idl_fileOutPrintf(idl_fileCur(), "[%d]", idl_typeArraySize(typeArray)); subType = idl_typeArrayType(typeArray); while(resolveTypedefs && idl_typeSpecType(subType) == idl_ttypedef) { subType = idl_typeDefResolveFully(subType); } if (idl_typeSpecType(subType) == idl_tarray) { idl_arrayDimensions (idl_typeArray(subType), resolveTypedefs); } }
static void idl_typedefOpenClose( idl_scope scope, const char *name, idl_typeDef defSpec, void *userData) { if ((idl_typeSpecType(idl_typeDefActual (defSpec)) == idl_tstruct) || (idl_typeSpecType (idl_typeDefActual (defSpec)) == idl_tunion)) { if (idl_keyResolve(idl_keyDefDefGet(), scope, name) != NULL) { idl_genInterface(scope, name, "TypeSupport", idl_typeSpec(defSpec), FALSE); idl_genInterface(scope, name, "DataReader", idl_typeSpec(defSpec), TRUE); idl_genInterface(scope, name, "DataReaderView", idl_typeSpec(defSpec), TRUE); idl_genInterface(scope, name, "DataWriter", idl_typeSpec(defSpec), TRUE); idl_genTypeSeqHolder(scope, name, idl_typeDefActual(defSpec)); } } }
/* Return the scoped type name where for the user types, scopes are separated by "_" chracters. */ c_char * idl_scopedSplTypeName ( const idl_typeSpec typeSpec) { char scopedTypeName[256]; /* QAC EXPECT 3416; No unexpected side effects here */ if (idl_typeSpecType(typeSpec) == idl_tseq) { /* Sequences map to c_sequence */ os_strncpy (scopedTypeName, "c_sequence", sizeof(scopedTypeName)); /* QAC EXPECT 3416; No unexpected side effects here */ } else if (idl_typeSpecType(typeSpec) == idl_tbasic) { /* For basic types take the corresponding type name supported by the splice database */ /* QAC EXPECT 3416; No unexpected side effects here */ if (idl_typeBasicType(idl_typeBasic(typeSpec)) == idl_string) { /* in case of bounded string the type name must become c_string */ /* type name is of form "C_STRING<xx>" */ os_strncpy (scopedTypeName, "c_string", sizeof(scopedTypeName)); } else { os_strncpy (scopedTypeName, idl_typeSpecName(idl_typeSpec(typeSpec)), sizeof(scopedTypeName)); } } else if (idl_typeSpecType(typeSpec) == idl_tstruct || idl_typeSpecType(typeSpec) == idl_tunion) { snprintf (scopedTypeName, (size_t)sizeof(scopedTypeName), "struct _%s", idl_scopeStack ( idl_typeUserScope(idl_typeUser(typeSpec)), "_", idl_typeSpecName(idl_typeSpec(typeSpec)))); } else if (idl_typeSpecType(typeSpec) == idl_tenum) { snprintf (scopedTypeName, (size_t)sizeof(scopedTypeName), "enum _%s", idl_scopeStack ( idl_typeUserScope(idl_typeUser(typeSpec)), "_", idl_typeSpecName(idl_typeSpec(typeSpec)))); } else { snprintf (scopedTypeName, (size_t)sizeof(scopedTypeName), "_%s", idl_scopeStack ( idl_typeUserScope(idl_typeUser(typeSpec)), "_", idl_typeSpecName(idl_typeSpec(typeSpec)))); } return os_strdup(scopedTypeName); }
/** @brief callback function called on definition of a union case 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 * * If the type specification is idl_tbasic a standard mapping can be generated: * @verbatim string <name>; => c_string <name>; string <name,length>; => c_string <name>; char <name>; => c_char <name>; octet <name>; => c_octet <name>; short <name>; => c_short <name>; unsigned short <name>; => c_ushort <name>; long <name>; => c_long <name>; unsigned long <name>; => c_ulong <name>; long long <name>; => c_longlong <name>; unsigned long long <name>; => c_ulonglong <name>; float <name>; => c_float <name>; double <name>; => c_double <name>; boolean <name>; => c_bool <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>; => enum <scope-elements>_<typedef-name> <name>; <enum-name> <name>; => enum <scope-elements>_<enum-name> <name>; <struct-name> <name>; => struct <scope-elements>_<structure-name> <name>; <union-name> <name>; => struct <scope-elements>_<union-name> <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]; => <scope-elements>_<other-usertype-name> <name>[n1]..[nn]; <basic-type> <name>[n1]..[nn]; => <basic-type-mapping> <name>[n1]..[nn]; sequence<spec> <name>[n1]..[nn]; => c_array <name>[n1]..[nn]; sequence<spec,length> <name>[n1]..[nn]; => c_array <name>[n1]..[nn]; @endverbatim * If the type specification is idl_tseq then generate a mapping on c_sequence: * @verbatim sequence<spec> <name>; => c_sequence <name>; sequence<spec,length> <name>; => c_sequence <name>; @endverbatim * * @param scope Current scope (the union the union case is defined in) * @param name Name of the union case * @param typeSpec Specifies the type of the union case */ static void idl_unionCaseOpenClose( idl_scope scope, const char *name, idl_typeSpec typeSpec, void *userData) { if (idl_typeSpecType(typeSpec) == idl_ttypedef || idl_typeSpecType(typeSpec) == idl_tenum || idl_typeSpecType(typeSpec) == idl_tstruct || idl_typeSpecType(typeSpec) == idl_tunion || idl_typeSpecType(typeSpec) == 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(), "%s %s;\n", idl_scopedSplTypeIdent(typeSpec), idl_languageId(name)); } else if (idl_typeSpecType(typeSpec) == idl_tarray) { /* generate code for an array mapping */ idl_printIndent(indent_level); if (idl_typeSpecType(idl_typeArrayActual (idl_typeArray(typeSpec))) != idl_tseq) { idl_fileOutPrintf( idl_fileCur(), "%s %s", idl_scopedSplTypeIdent(idl_typeArrayActual (idl_typeArray(typeSpec))), idl_languageId (name)); } else { idl_fileOutPrintf( idl_fileCur(), "c_array %s", idl_languageId(name)); } idl_arrayDimensions(idl_typeArray(typeSpec), OS_FALSE); idl_fileOutPrintf(idl_fileCur(), ";\n"); } else if (idl_typeSpecType(typeSpec) == idl_tseq) { /* generate code for a sequence mapping */ idl_printIndent(indent_level); if (idl_typeSeqMaxSize (idl_typeSeq(typeSpec)) == 0) { /* unbounded sequence */ idl_fileOutPrintf(idl_fileCur(), "c_sequence %s", idl_languageId (name)); } else { /* bounded sequence */ idl_fileOutPrintf(idl_fileCur(), "c_sequence %s", idl_languageId (name)); } idl_fileOutPrintf(idl_fileCur(), ";\n"); } else { printf("idl_unionCaseOpenClose: Unsupported union case type (case name = %s, type = %s)\n", name, idl_scopedTypeName(typeSpec)); } }
/* Return the scoped 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 */ c_char * idl_scopedSacTypeIdent ( const idl_typeSpec typeSpec) { c_char scopedTypeIdent[256]; /* QAC EXPECT 3416; No unexpected side effects here */ if (idl_typeSpecType(typeSpec) == idl_tbasic || 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) { snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), "%s", idl_scopeStack ( idl_typeUserScope(idl_typeUser(typeSpec)), "_", idl_typeSpecName(idl_typeSpec(typeSpec)))); /* QAC EXPECT 3416; No unexpected side effects here */ } else if (idl_typeSpecType(typeSpec) == idl_tseq) { snprintf (scopedTypeIdent, (size_t)sizeof(scopedTypeIdent), idl_sequenceIdent(idl_typeSeq(typeSpec))); } else { /* Do nothing, only to prevent dangling else-ifs QAC messages */ } return os_strdup(scopedTypeIdent); }
/* @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; }
/* @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); } } }
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); } }
static c_ulong idl_genArrayTotalDimension( idl_typeArray typeArray) { c_ulong result = 0; idl_typeSpec ptr; result = (c_ulong)idl_typeArraySize(typeArray); ptr = idl_typeArrayType(typeArray); while (idl_typeSpecType(ptr) == idl_tarray) { result = result * (c_ulong)idl_typeArraySize(idl_typeArray(ptr)); ptr = idl_typeArrayType(idl_typeArray(ptr)); } return result; }
/* Return the C++ specific type identifier for the specified type specification */ c_char * idl_ISOCxx2TypeFromTypeSpec( idl_typeSpec typeSpec) { c_char *typeName = NULL; c_char *subType; const char *template; size_t size; c_ulong arrSize; switch(idl_typeSpecType(typeSpec)) { case idl_tbasic: /* if the specified type is a basic type */ typeName = standaloneTypeFromTypeSpec(idl_typeBasic(typeSpec)); break; case idl_tseq:
char * idl_sequenceElementIdent ( const idl_typeSpec typeSpec) { char *sequenceType; char *sequenceName; int len; if (idl_typeSpecType(typeSpec) == idl_tseq) { sequenceType = idl_sequenceSubElementIdent (idl_typeSeqType (idl_typeSeq(typeSpec))); len = strlen(sequenceType) + strlen ("DDS_sequence_") + 1; sequenceName = os_malloc (len); snprintf (sequenceName, len, "%s%s", "DDS_sequence_", sequenceType); } else { sequenceName = idl_scopedSacSequenceElementTypeIdent(typeSpec); } return sequenceName; }
/* typedefOpen callback A typedef of a structure or union is a type that can be communicated via the DCPS API. For the typedef the following helper functions are defined: - a function to query the typedef scoped type name - a function to query the typedef key list The name of the functions are: __<scope-elements>_<typedef-name>__name and __<scope-elements>_<typedef-name>__keys respectively. */ static void idl_typedefOpenClose ( idl_scope scope, const char *name, idl_typeDef defSpec, void *userData) { switch (idl_typeSpecType(idl_typeDefActual(defSpec))) { case idl_tstruct: idl_structureOpen(scope, name, idl_typeStruct(idl_typeDefActual(defSpec)), userData); break; case idl_tunion: idl_unionOpen(scope, name, idl_typeUnion(idl_typeDefActual(defSpec)), userData); break; default: /* Empty statement to satisfy QAC */ idl_null(); break; } }
static void newMeta( idl_scope scope, const char *name, idl_typeSpec typeSpec) { idl_meta meta; meta = os_malloc(C_SIZEOF(idl_meta)); if (meta) { meta->scope = idl_scopeDup(scope); meta->name = os_strdup(name); if (idl_typeSpecType(typeSpec) == idl_ttypedef) { meta->actual_name = idl_typeSpecName(idl_typeDefActual(idl_typeDef(typeSpec))); } else { meta->actual_name = idl_typeSpecName(typeSpec); } meta->type = idl_typeSpecDef(typeSpec); } idlpp_metaList = os_iterAppend(idlpp_metaList, meta); }
/** @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) { struct idl_genSACPPData *arg = (struct idl_genSACPPData *)userData; char *memberName; char *scopedName; char *seqName; switch (idl_typeSpecType(typeSpec)) { case idl_tbasic: case idl_tenum: case idl_ttypedef: case idl_tstruct: case idl_tunion: case idl_tseq: /* nothing todo */ break; case idl_tarray: /* generate implementation code for the array mapping */ memberName = idl_cxxId(name); snprintf(arg->buffer,MAX_BUFFER,"_%s_array",memberName); seqName = os_strdup(arg->buffer); scopedName = idl_scopeStackCxx(scope, "::", seqName); idl_arrayTypeImpl(idl_typeArray(typeSpec), scopedName,arg); snprintf(arg->buffer, MAX_BUFFER, "_%s_array %s;\n", memberName, memberName); os_free(seqName); os_free(scopedName); os_free(memberName); break; default: printf("idl_structureMemberOpenClose: Unsupported structure member type (member name = %s, type name = %s)\n", name, idl_scopedTypeName(typeSpec)); } }
static void idl_constantOpenClose( idl_scope scope, idl_constSpec constantSpec, void *userData) { /* Open file for used scope, if needed create the directories */ idl_openJavaPackage(scope, idl_javaId(idl_constSpecName(constantSpec))); /* Write package name */ #if 0 idl_fileOutPrintf(idl_fileCur(), "/*\n"); idl_fileOutPrintf(idl_fileCur(), " * Generated by OpenSpliceDDS "OSPL_VERSION_STR"\n"); idl_fileOutPrintf(idl_fileCur(), " */\n\n"); #endif 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 interface %s {\n", idl_constSpecName(constantSpec)); if (idl_typeSpecType(idl_constSpecTypeGet(constantSpec)) == idl_tbasic && idl_typeBasicType(idl_typeBasic(idl_constSpecTypeGet(constantSpec))) == idl_string) { idl_fileOutPrintf( idl_fileCur(), " public static final %s value = %s;\n", idl_corbaJavaTypeFromTypeSpec(idl_constSpecTypeGet(constantSpec)), idl_constSpecImage (constantSpec)); } else { idl_fileOutPrintf( idl_fileCur(), " public static final %s value = (%s)(%s);\n", idl_corbaJavaTypeFromTypeSpec(idl_constSpecTypeGet(constantSpec)), idl_corbaJavaTypeFromTypeSpec(idl_constSpecTypeGet(constantSpec)), idl_constSpecImage(constantSpec)); } idl_fileOutPrintf(idl_fileCur(), "}\n"); }
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; }
/* Return the standalone C specific type identifier for the specified type specification */ c_char * idl_sacTypeFromTypeSpec ( const idl_typeSpec typeSpec) { c_char *typeName; /* QAC EXPECT 3416; No side effects here */ if (idl_typeSpecType(typeSpec) == idl_tbasic) { /* if the specified type is a basic type */ switch (idl_typeBasicType(idl_typeBasic(typeSpec))) { case idl_short: typeName = os_strdup("DDS_short"); break; case idl_ushort: typeName = os_strdup("DDS_unsigned_short"); break; case idl_long: typeName = os_strdup("DDS_long"); break; case idl_ulong: typeName = os_strdup("DDS_unsigned_long"); break; case idl_longlong: typeName = os_strdup("DDS_long_long"); break; case idl_ulonglong: typeName = os_strdup("DDS_unsigned_long_long"); break; case idl_float: typeName = os_strdup("DDS_float"); break; case idl_double: typeName = os_strdup("DDS_double"); break; case idl_char: typeName = os_strdup("DDS_char"); break; case idl_string: typeName = os_strdup("DDS_string"); break; case idl_boolean: typeName = os_strdup("DDS_boolean"); break; case idl_octet: typeName = os_strdup("DDS_octet"); break; default: /* No processing required, empty statement to satisfy QAC */ break; /* QAC EXPECT 2016; Default case must be empty here */ } /* QAC EXPECT 3416; No side effects here */ } else if (idl_typeSpecType(typeSpec) == idl_tseq) { /* sequence does not have an identification */ typeName = os_strdup (""); printf ("idl_sacTypeFromTypeSpec: Unexpected sequence type handled\n"); } else if (idl_typeSpecType(typeSpec) == idl_tarray) { typeName = os_strdup (""); printf ("idl_sacTypeFromTypeSpec: Unexpected array type handled\n"); } else { /* if a user type is specified build it from its scope and its name. The type should be one of idl_ttypedef, idl_tenum, idl_tstruct, idl_tunion. */ typeName = idl_scopeStackC ( idl_typeUserScope(idl_typeUser(typeSpec)), "_", idl_typeSpecName(typeSpec)); } return typeName; /* QAC EXPECT 5101; The switch statement is simple, therefor the total complexity is low */ }
/* 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(); } }