/** @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 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)); } }
/** @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; }
/** @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)); } }
/** @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))); } }
/** @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 * * 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,length>; @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) { 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) { os_boolean catsRequested = OS_FALSE; os_boolean stacRequested = OS_FALSE; idl_typeSpec baseTypeDereffered = NULL; idl_typeSpec typeDereffered; /* is a stac pragma defined for this member? */ stacRequested = idl_stacDef_isStacDefined(scope, name, typeSpec, &baseTypeDereffered); if(!stacRequested) { /* Cats and stac def can not be defined over the same member as * one excepts string types and the other char (array) types */ catsRequested = idl_catsDef_isCatsDefined(scope, name, typeSpec); } if(catsRequested) { assert(!stacRequested); typeDereffered = idl_typeDefResolveFully(typeSpec); idl_structureMemberOpenClose(scope, name, typeDereffered, userData); } else if(stacRequested) { assert(baseTypeDereffered); typeDereffered = idl_typeDefResolveFully(typeSpec); idl_printIndent(indent_level); idl_fileOutPrintf(idl_fileCur(), "c_char %s", idl_languageId (name)); /* potential array bounds */ if((idl_typeSpecType(typeDereffered) == idl_tarray)) { idl_arrayDimensions(idl_typeArray(typeDereffered), OS_TRUE); } idl_fileOutPrintf(idl_fileCur(), "[%d];\n", idl_typeBasicMaxlen(idl_typeBasic(baseTypeDereffered))+1); } else { /* 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 */ os_boolean catsRequested = OS_FALSE; os_boolean stacRequested = OS_FALSE; idl_typeSpec baseTypeDereffered = NULL; /* is a stac pragma defined for this member? */ stacRequested = idl_stacDef_isStacDefined(scope, name, typeSpec, &baseTypeDereffered); if(!stacRequested) { /* Cats and stac def can not be defined over the same member as * one excepts string types and the other char (array) types */ catsRequested = idl_catsDef_isCatsDefined(scope, name, typeSpec); } if(catsRequested) { assert(!stacRequested); idl_printIndent(indent_level); idl_fileOutPrintf(idl_fileCur(), "c_string %s;\n", idl_languageId(name)); } else if(stacRequested) { assert(!catsRequested); idl_printIndent(indent_level); idl_fileOutPrintf( idl_fileCur(), "c_char %s", idl_languageId(name)); idl_arrayDimensions(idl_typeArray(typeSpec), OS_TRUE); idl_fileOutPrintf(idl_fileCur(),"[%d]", idl_typeBasicMaxlen(idl_typeBasic(baseTypeDereffered))+1); idl_fileOutPrintf(idl_fileCur(), ";\n"); } else { 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_structureMemberOpenClose: Unsupported structure member type (member name = %s, type name = %s)\n", name, idl_scopedTypeName(typeSpec)); } }