示例#1
0
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;
}
示例#2
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
 *
 * 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));
    }
}