Exemplo n.º 1
0
void jvmcodegen::gen_variable(const ast::node_ptr &node)
{
    auto var = ast::to_variable(node);
    auto sym = m_stack.top()->get(var->name);

    if (sym.c_type() == types::integer) {
        m_out << fmt::sprintf("iload %d\n", sym.local);
    } else if (sym.c_type() == types::string) {
        m_out << fmt::sprintf("aload %d\n", sym.local);
    }
    // TODO: string, booleans, etc...
}
c_bool
__sensor_msgs_msg_dds__CompressedImage___copyIn(
    c_base base,
    struct ::sensor_msgs::msg::dds_::CompressedImage_ *from,
    struct _sensor_msgs_msg_dds__CompressedImage_ *to)
{
    c_bool result = OS_C_TRUE;
    (void) base;

    if(result){
        extern c_bool __std_msgs_msg_dds__Header___copyIn(c_base, ::std_msgs::msg::dds_::Header_ *, _std_msgs_msg_dds__Header_ *);
        result = __std_msgs_msg_dds__Header___copyIn(base, &from->header_, &to->header_);
    }
#ifdef OSPL_BOUNDS_CHECK
    if(from->format_){
        to->format_ = c_stringNew(base, from->format_);
    } else {
        OS_REPORT (OS_ERROR, "copyIn", 0,"Member 'sensor_msgs::msg::dds_::CompressedImage_.format_' of type 'c_string' is NULL.");
        result = OS_C_FALSE;
    }
#else
    to->format_ = c_stringNew(base, from->format_);
#endif
    {
/* Code generated by /home/erle/opensplice/src/tools/idlpp/code/idl_genCorbaCxxCopyin.c at line 774 */

        static c_type type0 = NULL;
        c_type subtype0;
        c_long length0;
        c_octet *dest0;
        ::sensor_msgs::msg::dds_::CompressedImage_::_data__seq *src = &from->data_;

        if (type0 == NULL) {
            subtype0 = c_type(c_metaResolve (c_metaObject(base), "c_octet"));
            type0 = c_metaSequenceTypeNew(c_metaObject(base),"C_SEQUENCE<c_octet>",subtype0,0);
            c_free(subtype0);
        }
        length0 = (c_long)(*src).length();
#ifdef OSPL_BOUNDS_CHECK
         dest0 = (c_octet *)c_newSequence(c_collectionType(type0),length0);
        {
        /* Code generated by /home/erle/opensplice/src/tools/idlpp/code/idl_genCorbaCxxCopyin.c at line 1873 */
                    c_octet *buf0;
            buf0 = (c_octet *)(*src).get_buffer();
            memcpy (dest0,buf0,length0* sizeof(*dest0));
        }
        to->data_ = (c_sequence)dest0;
#else
        dest0 = (c_octet *)c_newSequence(c_collectionType(type0),length0);
        {
        /* Code generated by /home/erle/opensplice/src/tools/idlpp/code/idl_genCorbaCxxCopyin.c at line 1873 */
                    c_octet *buf0;
            buf0 = (c_octet *)(*src).get_buffer();
            memcpy (dest0,buf0,length0* sizeof(*dest0));
        }
        to->data_ = (c_sequence)dest0;
#endif
    }
    return result;
}
Exemplo n.º 3
0
const c_char*
cmx_participantRegisterType(
    const c_char* participant,
    const c_char* type)
{
    sd_serializer serializer;
    sd_serializedData meta_data;
    cmx_entityKernelArg kernelArg;
    c_type topicType;
    cmx_entity ce;
    const c_char* result;
    const c_char* msg;

    ce = cmx_entityClaim(participant);
    if(ce != NULL){
        kernelArg = cmx_entityKernelArg(os_malloc(C_SIZEOF(cmx_entityKernelArg)));
        if (u_observableAction(u_observable(ce->uentity),
                               cmx_entityKernelAction,
                               (c_voidp)kernelArg) == U_RESULT_OK)
        {
            serializer = sd_serializerXMLMetadataNew(c_getBase(c_object(kernelArg->kernel)));

            if(serializer != NULL){
                meta_data = sd_serializerFromString(serializer, type);

                if (meta_data != NULL) {
                    topicType = c_type(sd_serializerDeserialize(serializer, meta_data));

                    if (topicType == NULL) {
                        msg = sd_serializerLastValidationMessage(serializer);
                        OS_REPORT(OS_ERROR,
                                  CM_XML_CONTEXT, 0,
                                  "Data type could not be registered, "
                                  "because it is not valid: %s",
                                  msg);
                        result = CMX_RESULT_FAILED;
                    } else {
                        result = CMX_RESULT_OK;
                    }
                    sd_serializedDataFree(meta_data);
                } else {
                    OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0, "Construction of serialized data failed.");
                    result = CMX_RESULT_FAILED;
                }
                sd_serializerFree(serializer);
            } else {
                OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0, "Serializer could not be initialized");
                result = CMX_RESULT_FAILED;
            }
        } else {
            OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0, "Kernel object could not be retrieved");
            result = CMX_RESULT_FAILED;
        }
        os_free(kernelArg);
        cmx_entityRelease(ce);
    } else {
        result = CMX_RESULT_FAILED;
    }
    return result;
}
Exemplo n.º 4
0
static c_type
createKeyType(
    const c_char *name,
    c_array keyList)
{
    c_base base;
    c_type foundType;
    c_char *typeName;
    c_char keyName[16];
    c_long i, length, sres;
    c_array members;
    c_metaObject o;
    c_field field;

    if (keyList == NULL) {
        return NULL;
    }
    base = c_getBase(keyList);
    length = c_arraySize(keyList);
    if (length == 0) {
        return NULL;
    }
    o = c_metaDefine(c_metaObject(base),M_STRUCTURE);
    members = c_arrayNew(c_member_t(base),length);

    for (i=0;i<length;i++) {
        field = keyList[i];
        assert(field != NULL);
        members[i] = (c_voidp)c_metaDefine(c_metaObject(base),M_MEMBER);
            sprintf(keyName,"field%d",i);
            c_specifier(members[i])->name = c_stringNew(base,keyName);
            c_specifier(members[i])->type = c_keep(c_fieldType(field));
    }
    c_structure(o)->members = members;
    c_metaObject(o)->definedIn = c_metaObject(base);
    c_metaFinalize(o);
#define KEY_NAME   "<Key>"
#define KEY_FORMAT "%s<Key>"

    if (name != NULL) {
        length = sizeof(KEY_NAME) + strlen(name);
        typeName = os_malloc(length);
        sres = snprintf(typeName,length,KEY_FORMAT,name);
        assert(sres == (length-1));
    } else {
        assert(FALSE);
        length = 100;
        typeName = os_malloc(length);
        os_sprintf(typeName,PA_ADDRFMT KEY_NAME,(c_address)o);
    }
#undef KEY_NAME
#undef KEY_FORMAT
    foundType = c_type(c_metaBind(c_metaObject(base),typeName,o));

    c_free(o);
    os_free(typeName);

    return foundType;

}
Exemplo n.º 5
0
os_boolean
idl_stacDefCanStacBeAppliedToMember(
    c_type memberType)
{
    os_boolean stacCanBeApplied = OS_FALSE;
    c_type dereffedType;

    dereffedType = c_typeActualType(c_type(idl_stacDefResolveTypeDef(c_baseObject(memberType))));
    if(c_baseObject(dereffedType)->kind == M_COLLECTION)
    {
        /* Can be a string or an array or a sequence */
        if(c_collectionType(dereffedType)->kind == OSPL_C_STRING)
        {
            if((c_collectionType(dereffedType)->maxSize != 0))
            {
                /* The string is bounded, stac can be applied */
                stacCanBeApplied = OS_TRUE;
            }
        }
        else if(c_collectionType(dereffedType)->kind == OSPL_C_ARRAY)
        {
            /* bounded string embedded within arrays are allowed, recurse deeper */
            stacCanBeApplied = idl_stacDefCanStacBeAppliedToMember(c_collectionType(dereffedType)->subType);
        } /* else let memberIsStacOk remain false */
    }
    return stacCanBeApplied;
}
Exemplo n.º 6
0
void
q_dispose(
    q_expr expr)
{
    c_type t;

    if (expr == NULL) return;
    switch (expr->kind) {
    case T_ID:
    case T_STR:
        os_free(expr->info.string);
    break;
    case T_TYP:
    break;
    case T_FNC:
        if (expr->info.function->tag == Q_EXPR_CALLBACK) {

            /* The first parameter is not of type q_expr but is of type c_type.      */
            /* It specifies the result type of the callback function.                */
            t = c_type(q_getTyp(q_swapPar(expr,0,NULL)));
            c_free(t);
            q_swapPar(expr,1,NULL);
            q_dispose((q_expr)q_swapPar(expr,2,NULL));
        }
        q_listDispose(expr->info.function->params);
        os_free(expr->info.function);
    break;
    default:
    break;
    }
    if(expr->text) os_free(expr->text);
    os_free(expr);
}
Exemplo n.º 7
0
static void
extractReferences(
    c_type type,
    c_object o,
    c_voidp data)
{
    switch (c_baseObject(type)->kind) {
    case M_STRUCTURE:
    case M_EXCEPTION:
        extractStructReferences(c_structure(type),o,data);
    break;
    case M_CLASS:
        if (c_class(type)->extends != NULL) {
            extractReferences(c_type(c_class(type)->extends),o,data);
        }
    case M_INTERFACE:
        extractInterfaceReferences(c_interface(type),o,data);
    break;
    case M_UNION:
    break;
    default:
    break;
    }

}
Exemplo n.º 8
0
c_object
c_checkType (
    c_object o,
    const c_char *name)
{
    c_type type;
    c_string str;
    c_bool found = FALSE;
    c_bool stop = FALSE;

    if (o == NULL) {
        return NULL;
    }
    c_assertValidDatabaseObject(o);
    assert(c_refCount(o) > 0);
    assert(name != NULL);
    type = c__getType(o);
    while (!found && !stop) {
        str = c_metaObject(type)->name;
        if (str == NULL) {
            found = TRUE; /** assume TRUE **/
        } else if (strcmp(str,name) != 0) {
            switch (c_baseObject(type)->kind) {
            case M_CLASS:
                type = c_type(c_class(type)->extends);
                if (type == NULL) {
                    if ((strcmp(str,"c_base") == 0) && (strcmp(name,"c_module") == 0)) {
                        found = TRUE;
                    }
                    stop = TRUE;
                }
            break;
            case M_TYPEDEF:
                type = c_typeDef(type)->alias;
                if (type == NULL) {
                    stop = TRUE;
                }
            break;
            default:
              stop = TRUE;
            }
        } else {
            found = TRUE;
        }
    }
    if (!found) {
#ifndef NDEBUG
        if(o != NULL){
            str = c_metaObject(c__getType(o))->name;
            OS_REPORT_2(OS_ERROR, "Database", 0,
                    "Type mismatch: object type is %s but %s was expected\n",
                    str,name);
        }
#endif

        return NULL;
    }
    return o;
}
Exemplo n.º 9
0
static c_type
createInstanceType(
    c_type messageType,
    d_topicInfo topicInfo)
{
    c_type instanceType, baseType, foundType;
    c_metaObject o;
    c_char *name;
    c_long length,sres;
    c_base base;

    base = c_getBase(messageType);
    baseType = c_resolve(base,"durabilityModule2::d_instanceTemplate");
    assert(baseType != NULL);

    instanceType = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
    c_class(instanceType)->extends = c_class(baseType);

    foundType = createTopicKeyType(messageType, topicInfo->keyExpr);

    if ( foundType != NULL) {
        o = c_metaDeclare(c_metaObject(instanceType),"key",M_ATTRIBUTE);
        c_property(o)->type = foundType;
        c_free(o);
    }
    c_metaObject(instanceType)->definedIn = c_keep(base);
    c_metaFinalize(c_metaObject(instanceType));

#define INSTANCE_NAME "d_instance<d_sample<>>"
#define INSTANCE_FORMAT "d_instance<d_sample<%s>>"

    length = sizeof(INSTANCE_NAME) + strlen(topicInfo->name);
    name = os_malloc(length);
    sres = snprintf(name,length,INSTANCE_FORMAT,topicInfo->name);
    assert(sres == (length-1));
#undef INSTANCE_NAME
#undef INSTANCE_FORMAT

    foundType = c_type(c_metaBind(c_metaObject(base),
                                  name,
                                  c_metaObject(instanceType)));
    os_free(name);
    c_free(instanceType);

    return foundType;
}
Exemplo n.º 10
0
static c_type
createSampleType(
    c_type messageType,
    const c_char* topicName)
{
    c_base base;
    c_type sampleType, baseType, foundType, found;
    c_metaObject o;
    c_char *name;
    c_long length,sres;

    base = c_getBase(messageType);
    baseType = c_resolve(base, "durabilityModule2::d_sample");
    assert(baseType != NULL);

    sampleType = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
    c_class(sampleType)->extends = c_class(baseType);

    o = c_metaDefine(c_metaObject(sampleType),M_ATTRIBUTE);
    c_property(o)->type = c_keep(messageType);
    found = c_type(c_metaBind(c_metaObject(sampleType),"message",o));
    c_free(o);
    c_free(found);

    c_metaObject(sampleType)->definedIn = c_keep(base);
    c_metaFinalize(c_metaObject(sampleType));

#define SAMPLE_NAME   "d_sample<>"
#define SAMPLE_FORMAT "d_sample<%s>"
    /* Create a name and bind type to name */
    /* The sizeof contains \0 */
    length = sizeof(SAMPLE_NAME) + strlen(topicName);
    name = os_malloc(length);
    sres = snprintf(name,length,SAMPLE_FORMAT,topicName);
    assert(sres == (length-1));
#undef SAMPLE_NAME
#undef SAMPLE_FORMAT

    foundType = c_type(c_metaBind(c_metaObject(base),
                                  name,
                                  c_metaObject(sampleType)));
    os_free(name);
    c_free(sampleType);

    return foundType;
}
Exemplo n.º 11
0
static c_type
messageTypeNew(
    c_base base,
    const c_char *typeName)
{
    c_metaObject o;
    c_type baseType,dataType,type, foundType;
    c_char *name;
    c_long length, sres;

    if (base == NULL) {
        return NULL;
    }
    dataType = c_resolve(base,typeName);
    if (dataType == NULL) {
        return NULL;
    }
    baseType = c_resolve(base, "kernelModule::v_message");
    assert(baseType != NULL);

    type = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
    c_class(type)->extends = c_keep(c_class(baseType));
    o = c_metaDeclare(c_metaObject(type),
                      USERDATA_FIELD_NAME,
                      M_ATTRIBUTE);
    c_property(o)->type = dataType;
    c_free(o);
    c_metaObject(type)->definedIn = c_keep(base);
    c_metaFinalize(c_metaObject(type));


#define MESSAGE_FORMAT "v_message<%s>"
#define MESSAGE_NAME "v_message<>"
    length = sizeof(MESSAGE_NAME) + strlen(typeName);
    name = os_malloc(length);
    sres = snprintf(name,length,MESSAGE_FORMAT,typeName);
    assert(sres == (length-1));
#undef MESSAGE_FORMAT
#undef MESSAGE_NAME
    foundType = c_type(c_metaBind(c_metaObject(base),name,c_metaObject(type)));
    os_free(name);
    c_free(type);

    return foundType;
}
Exemplo n.º 12
0
static c_bool
walkProperty(
    c_metaObject object,
    c_metaWalkActionArg actionArg)
{
    toolActionData actionData = (toolActionData)actionArg;
    c_object o;
    c_voidp addr;

    o = c_iterObject(actionData->stack, 0);

    if (c_baseObjectKind(object) == M_ATTRIBUTE) {
        addr = C_DISPLACE(o, (c_address)c_property(object)->offset);
        if (c_typeIsRef(c_property(object)->type)) {
            addr = *(c_voidp *)addr;
            if (c_baseObjectKind(c_property(object)->type) == M_COLLECTION) {
                if (addr) {
                    if (c_iterContains(actionData->stack, addr)) {
                        printf("Ignore cyclic reference 0x"PA_ADDRFMT"\n",
                               (os_address)addr);
                    } else {
                        OBJECT_PUSH(actionData, addr);
                        iprintf("%s ",_METANAME(object));
                        printType(c_property(object)->type, actionData);
                        OBJECT_POP(actionData);
                    }
                } else {
                    iprintf("    %s <0x"PA_ADDRFMT">", _METANAME(object), (os_address)addr);
                }
            } else {
                iprintf("    %s <0x"PA_ADDRFMT">", _METANAME(object), (os_address)addr);
                if (addr) {
                    /* Section for code to print additional type specific info. */
                    if (c_property(object)->type == v_topic_t) {
                        printf(" /* topic name is: %s */", v_topicName(addr));
                    }
                    if (c_property(object)->type == v_partition_t) {
                        printf(" /* Partition: %s */", v_partitionName(addr));
                    }
                    if (c_property(object)->type == c_type_t(c_getBase(object))) {
                        printf(" /* Type: %s */", _METANAME(c_type(addr)));
                    }
                }
            }
            printf("\n");
        } else {
            OBJECT_PUSH(actionData, addr);
            iprintf("%s ",_METANAME(object));
            printType(c_property(object)->type, actionData);
            printf("\n");
            OBJECT_POP(actionData);
        }
    }
    return TRUE;
}
c_bool
__std_msgs_msg_dds__UInt64MultiArray___copyIn(
    c_base base,
    struct ::std_msgs::msg::dds_::UInt64MultiArray_ *from,
    struct _std_msgs_msg_dds__UInt64MultiArray_ *to)
{
    c_bool result = OS_C_TRUE;
    (void) base;

    if(result){
        extern c_bool __std_msgs_msg_dds__MultiArrayLayout___copyIn(c_base, ::std_msgs::msg::dds_::MultiArrayLayout_ *, _std_msgs_msg_dds__MultiArrayLayout_ *);
        result = __std_msgs_msg_dds__MultiArrayLayout___copyIn(base, &from->layout_, &to->layout_);
    }
    {
/* Code generated by /home/erle/opensplice/src/tools/idlpp/code/idl_genCorbaCxxCopyin.c at line 774 */

        static c_type type0 = NULL;
        c_type subtype0;
        c_long length0;
        c_ulonglong *dest0;
        ::std_msgs::msg::dds_::UInt64MultiArray_::_data__seq *src = &from->data_;

        if (type0 == NULL) {
            subtype0 = c_type(c_metaResolve (c_metaObject(base), "c_ulonglong"));
            type0 = c_metaSequenceTypeNew(c_metaObject(base),"C_SEQUENCE<c_ulonglong>",subtype0,0);
            c_free(subtype0);
        }
        length0 = (c_long)(*src).length();
#ifdef OSPL_BOUNDS_CHECK
         dest0 = (c_ulonglong *)c_newSequence(c_collectionType(type0),length0);
        {
        /* Code generated by /home/erle/opensplice/src/tools/idlpp/code/idl_genCorbaCxxCopyin.c at line 1873 */
                    c_ulonglong *buf0;
            buf0 = (c_ulonglong *)(*src).get_buffer();
            memcpy (dest0,buf0,length0* sizeof(*dest0));
        }
        to->data_ = (c_sequence)dest0;
#else
        dest0 = (c_ulonglong *)c_newSequence(c_collectionType(type0),length0);
        {
        /* Code generated by /home/erle/opensplice/src/tools/idlpp/code/idl_genCorbaCxxCopyin.c at line 1873 */
                    c_ulonglong *buf0;
            buf0 = (c_ulonglong *)(*src).get_buffer();
            memcpy (dest0,buf0,length0* sizeof(*dest0));
        }
        to->data_ = (c_sequence)dest0;
#endif
    }
    return result;
}
Exemplo n.º 14
0
void jvmcodegen::gen_assign_stmt(const ast::node_ptr &node)
{
    auto assign = ast::to_assign_stmt(node);
    auto identifier = ast::to_variable(assign->lvalue);

    auto sym = m_stack.top()->get(identifier->name);
    // escopo global?
    if (m_stack.top()->id <= 0) {
    } else {
        gen_node(assign->rvalue);
        switch (sym.c_type()) {
            case types::integer:
                m_out << fmt::sprintf("istore %d\n", sym.local);
                break;
            case types::string:
                m_out << fmt::sprintf("astore %d\n", sym.local);
                break;
            default:
                throw jvmcodegen_error(
                    fmt::sprintf("Tipo de dado nao suportado para atribuicao %d",
                        sym.c_type()));
        }
    }
}
Exemplo n.º 15
0
static void
printStructure(
    c_structure _this,
    toolActionData actionData)
{
    c_object o;
    c_object object;
    c_long i, size;
    c_member member;

    o = c_iterObject(actionData->stack, 0);

    if (o) {
        if (c_iterLength(actionData->stack) == 1) {
            printf("%s ", _METANAME(_this));
        } else {
        }
        printf("{\n");
        size = c_structureMemberCount(_this);
        for (i=0; i<size; i++) {
            member = c_structureMember(_this, i);
            object = C_DISPLACE(o, (c_address)member->offset);
            if (c_typeIsRef(c_memberType(member))) {
                iprintf("    %s <0x"PA_ADDRFMT">\n",
                       c_specifierName(member),
                       *(os_address *)object);
            } else {
                OBJECT_PUSH(actionData, object);
                iprintf("%s ",c_specifierName(member));
                printType(c_memberType(member), actionData);
                printf("\n");
                OBJECT_POP(actionData);
            }
        }
        if (c_iterLength(actionData->stack) == 1) {
            iprintf("};");
        } else {
            iprintf("} %s;", _METANAME(_this));
        }
        if (c_type(_this) == v_handle_t) {
            v_object vo;
            v_handleClaim(*(v_handle *)o,&vo);
            v_handleRelease(*(v_handle *)o);
            printf(" /* Handle's object: <0x"PA_ADDRFMT"> */", (os_address)vo);
        }
    }
}
c_bool
__rcl_interfaces_srv_dds__GetParameterTypes_Response___copyIn(
    c_base base,
    struct ::rcl_interfaces::srv::dds_::GetParameterTypes_Response_ *from,
    struct _rcl_interfaces_srv_dds__GetParameterTypes_Response_ *to)
{
    c_bool result = OS_C_TRUE;
    (void) base;

    {
/* Code generated by /home/erle/opensplice/src/tools/idlpp/code/idl_genCorbaCxxCopyin.c at line 774 */

        static c_type type0 = NULL;
        c_type subtype0;
        c_long length0;
        c_octet *dest0;
        ::rcl_interfaces::srv::dds_::GetParameterTypes_Response_::_types__seq *src = &from->types_;

        if (type0 == NULL) {
            subtype0 = c_type(c_metaResolve (c_metaObject(base), "c_octet"));
            type0 = c_metaSequenceTypeNew(c_metaObject(base),"C_SEQUENCE<c_octet>",subtype0,0);
            c_free(subtype0);
        }
        length0 = (c_long)(*src).length();
#ifdef OSPL_BOUNDS_CHECK
         dest0 = (c_octet *)c_newSequence(c_collectionType(type0),length0);
        {
        /* Code generated by /home/erle/opensplice/src/tools/idlpp/code/idl_genCorbaCxxCopyin.c at line 1873 */
                    c_octet *buf0;
            buf0 = (c_octet *)(*src).get_buffer();
            memcpy (dest0,buf0,length0* sizeof(*dest0));
        }
        to->types_ = (c_sequence)dest0;
#else
        dest0 = (c_octet *)c_newSequence(c_collectionType(type0),length0);
        {
        /* Code generated by /home/erle/opensplice/src/tools/idlpp/code/idl_genCorbaCxxCopyin.c at line 1873 */
                    c_octet *buf0;
            buf0 = (c_octet *)(*src).get_buffer();
            memcpy (dest0,buf0,length0* sizeof(*dest0));
        }
        to->types_ = (c_sequence)dest0;
#endif
    }
    return result;
}
Exemplo n.º 17
0
v_object
v_new(
    v_kernel kernel,
    c_type type)
{
    v_object o;
    c_type t;
    c_long i;

    assert(C_TYPECHECK(kernel,v_kernel));
    assert(C_TYPECHECK(type,c_type));

    if (type == NULL) {
        return NULL;
    }
    o = c_new(type);
    if (o) {
        o->kernel = kernel;
        t = type;
        while (t != NULL) {
            for (i=0;i<K_TYPECOUNT;i++) {
                if (t == kernel->type[i]) {
                    o->kind = i;
                    return o;
                }
            }
            if (c_baseObject(t)->kind == M_CLASS) {
                t = c_type(c_class(t)->extends);
            } else {
                t = NULL;
            }
        }
        o->kind = K_OBJECT;
    } else {
        OS_REPORT(OS_ERROR,
                  "v_new",0,
                  "Failed to create kernel object.");
        assert(FALSE);
    }
    return o;
}
Exemplo n.º 18
0
void jvmcodegen::gen_call(const ast::node_ptr &node)
{
    auto call = ast::to_call(node);
    auto sym = m_stack.top()->get(call->name);

    if (!call->param_list.empty()) {
        size_t i = call->param_list.size() - 1;
        while (true) {
            gen_node(call->param_list[i]);
            if (i == 0)
                break;
            i--;
        }
    }
    m_out << fmt::sprintf("invokestatic ptb/%s\n", sym.signature);
    if (call->is_stmt) {
        // se a função retornar alguma coisa, descarta o resultado
        if (sym.c_type() != types::voidt) {
            m_out << fmt::sprintf("pop\n");
        }
    }
}
Exemplo n.º 19
0
d_storeResult
d_groupInfoDataInject(
    d_groupInfo _this,
    const d_store store,
    d_group group)
{
    d_storeResult result;
    struct d_instanceInjectArg inject;
    c_type mmfMessageType;
    c_char* typeName;

    if(_this && group){
        inject.vgroup = d_groupGetKernelGroup(group);

        mmfMessageType = d_topicInfoGetMessageType(_this->topic);
        typeName = c_metaScopedName(c_metaObject(mmfMessageType));

        inject.messageType = c_type(c_metaResolveType(
                c_metaObject(c_getBase(inject.vgroup)), typeName));

        if(inject.messageType){
            inject.result = D_STORE_RESULT_OK;

            c_tableWalk(_this->instances, d_instanceInject, &inject);

            c_free(inject.messageType);
            result = inject.result;
        } else {
            result = D_STORE_RESULT_PRECONDITION_NOT_MET;
        }
        c_free(inject.vgroup);
        c_free(mmfMessageType);
        os_free(typeName);
    } else {
        result = D_STORE_RESULT_ILL_PARAM;
    }
    return result;
}
Exemplo n.º 20
0
static c_type
cloneType(
    c_base src,
    c_base dst,
    c_type object)
{
    sd_serializer serializer, deserializer;
    sd_serializedData data;
    c_char* xmlData;
    c_type result;

    result = NULL;
    serializer = sd_serializerXMLTypeinfoNew(src, FALSE);
    deserializer = sd_serializerXMLTypeinfoNew(dst, FALSE);

    if(serializer && deserializer){
        data = sd_serializerSerialize(serializer, object);

        if(data){
            xmlData = sd_serializerToString(serializer, data);
            sd_serializedDataFree(data);

            if(xmlData){
                data = sd_serializerFromString(deserializer, xmlData);

                if(data){
                    result = c_type(sd_serializerDeserializeValidated(
                            deserializer, data));
                    sd_serializedDataFree(data);
                }
                os_free(xmlData);
            }
        }
        sd_serializerFree(serializer);
        sd_serializerFree(deserializer);
    }
    return result;
}
Exemplo n.º 21
0
c_unionCase
c_unionCaseNew (
    c_metaObject scope,
    const c_char *name,
    c_type type,
    c_iter labels)
{
    c_unionCase o;
    c_ulong nrOfLabels;
    c_type subType;

    nrOfLabels = c_iterLength(labels);
    o = c_unionCase(c_metaDefine(scope,M_UNIONCASE));
    subType = c_type(c_metaResolve(scope,"c_literal"));
    o->labels = c_arrayNew(subType,nrOfLabels);
    c_free(subType);
    c_iterArray(labels,o->labels);
    c_specifier(o)->name = c_stringNew(c__getBase(scope),name);
    /* Do not keep type as usage expects transferral of refcount.
     * If changed then odlpp and idlpp must be adapted accordingly.
     */
    c_specifier(o)->type = type;
    return o;
}
Exemplo n.º 22
0
static c_bool
display_orc (
    c_object o,
    c_voidp args
)
{
    refLeaf ord = (refLeaf)o;
    monitor_orc trace = (monitor_orc)args;
    regmatch_t match[1];

    if (ord->tr == nullType) {
        if (trace->delta) {
            if (abs(ord->rc - ord->prc) >= trace->extendCountLimit) {
                printf ("%6d                            <undefined>\r\n", (ord->rc - ord->prc));
            }
        } else {
            if (ord->rc >= trace->extendCountLimit) {
                printf ("%6d                            <undefined>\r\n", ord->rc);
            }
        }
    } else {
        switch (c_baseObject(ord->tr)->kind) {
        case M_COLLECTION:
            switch (c_collectionType(ord->tr)->kind) {
            case C_UNDEFINED:
            case C_LIST:
            case C_ARRAY:
            case C_BAG:
            case C_SET:
            case C_MAP:
            case C_DICTIONARY:
            case C_SEQUENCE:
            case C_STRING:
            case C_WSTRING:
            case C_QUERY:
            case C_SCOPE:
            case C_COUNT:
                if (trace->delta) {
                    if (abs(ord->rc - ord->prc) >= trace->extendCountLimit) {
                        if (trace->filterExpression) {
                            if (regexec (&trace->expression, c_metaObject(ord->tr)->name, 1, match, 0) == REG_NOMATCH) {
                                break;
                            }
                        }
                        printf ("%6d (%6d) %6d %10d %-15s %-15s ",
                                ord->rc - ord->prc,
                                ord->rc,
                                (int)c_type(ord->tr)->size,
                                (int)(c_type(ord->tr)->size * (ord->rc - ord->prc)),
                                baseKind[c_baseObject(ord->tr)->kind],
                                collectionKind[c_collectionType(ord->tr)->kind]);
                        printScope (c_metaObject(ord->tr)->definedIn);
                        printf ("::%s\r\n", c_metaObject(ord->tr)->name);
                        trace->totalSizeCount += c_type(ord->tr)->size * (ord->rc - ord->prc);
                        trace->totalObjectCount += ord->rc - ord->prc;
                    }
                } else {
                    if (ord->rc >= trace->extendCountLimit) {
                        if (trace->filterExpression) {
                            if (regexec (&trace->expression, c_metaObject(ord->tr)->name, 1, match, 0) == REG_NOMATCH) {
                                break;
                            }
                        }
                        printf ("%6d %6d %10d %-15s %-15s ",
                                ord->rc,
                                (int)c_type(ord->tr)->size,
                                (int)(c_type(ord->tr)->size * ord->rc),
                                baseKind[c_baseObject(ord->tr)->kind],
                                collectionKind[c_collectionType(ord->tr)->kind]);
                        printScope (c_metaObject(ord->tr)->definedIn);
                        printf ("::%s\r\n", c_metaObject(ord->tr)->name);
                        trace->totalSizeCount += c_type(ord->tr)->size * ord->rc;
                        trace->totalObjectCount += ord->rc;
                    }
                }
                break;
            }
            break;
        case M_PRIMITIVE:
        case M_TYPEDEF:
        case M_ENUMERATION:
        case M_UNION:
        case M_STRUCTURE:
        case M_INTERFACE:
        case M_CLASS:
        case M_EXCEPTION:
        case M_EXTENT:
        case M_EXTENTSYNC:
            if (trace->delta) {
                if (abs(ord->rc - ord->prc) >= trace->extendCountLimit) {
                    if (trace->filterExpression) {
                        if (regexec (&trace->expression, c_metaObject(ord->tr)->name, 1, match, 0) == REG_NOMATCH) {
                            break;
                        }
                    }
                    printf ("%6d (%6d) %6d %10d %-15s ",
                            ord->rc - ord->prc,
                            ord->rc,
                            (int)c_type(ord->tr)->size,
                            (int)(c_type(ord->tr)->size * (ord->rc - ord->prc)),
                            baseKind[c_baseObject(ord->tr)->kind]);
                    printf ("                ");
                    printScope (c_metaObject(ord->tr)->definedIn);
                    printf ("::%s\r\n", c_metaObject(ord->tr)->name);
                    trace->totalSizeCount += c_type(ord->tr)->size * (ord->rc - ord->prc);
                    trace->totalObjectCount += ord->rc - ord->prc;
                }
            } else {
                if (ord->rc >= trace->extendCountLimit) {
                    if (trace->filterExpression) {
                        if (regexec (&trace->expression, c_metaObject(ord->tr)->name, 1, match, 0) == REG_NOMATCH) {
                            break;
                        }
                    }
                    printf ("%6d %6d %10d %-15s ",
                            ord->rc,
                            (int)c_type(ord->tr)->size,
                            (int)(c_type(ord->tr)->size * ord->rc),
                            baseKind[c_baseObject(ord->tr)->kind]);
                    printf ("                ");
                    printScope (c_metaObject(ord->tr)->definedIn);
                    printf ("::%s\r\n", c_metaObject(ord->tr)->name);
                    trace->totalSizeCount += c_type(ord->tr)->size * ord->rc;
                    trace->totalObjectCount += ord->rc;
                }
            }
            break;
        case M_UNDEFINED:
        case M_ATTRIBUTE:
        case M_CONSTANT:
        case M_CONSTOPERAND:
        case M_EXPRESSION:
        case M_LITERAL:
        case M_MEMBER:
        case M_OPERATION:
        case M_PARAMETER:
        case M_RELATION:
        case M_BASE:
        case M_UNIONCASE:
        case M_COUNT:
        case M_MODULE:
            break;
        }
    }
    ord->prc = ord->rc;
    ord->rc = 0;
    return TRUE;
}
Exemplo n.º 23
0
/**************************************************************
 * constructor/destructor
 **************************************************************/
v_serviceState
v_serviceStateNew(
    v_kernel k,
    const c_char *name,
    const c_char *extStateName)
{
    v_serviceState s;
    c_type type;

    assert(C_TYPECHECK(k, v_kernel));

    if (extStateName == NULL) {
        s = v_serviceState(v_objectNew(k, K_SERVICESTATE));
    } else {
        type = c_resolve(c_getBase(c_object(k)), extStateName);
        if (type != NULL) {
#if !defined NDEBUG
            c_type t = type;
            c_bool correctType;
            correctType = FALSE;

            while ((correctType == FALSE) &&
                   (t != NULL) &&
                   (c_baseObject(t)->kind == M_CLASS)) {
                if (strcmp(c_metaObject(t)->name, "v_serviceState") == 0) {
                    correctType = TRUE;
                } else {
                    t = c_type(c_class(t)->extends);
                }
            }

            if ((correctType == FALSE) && (t != NULL)) {
                OS_REPORT(OS_FATAL, "v_serviceState", 0, "Given type not a class");
                assert(0);
            } else {

                if (correctType == FALSE) {
                    OS_REPORT(OS_FATAL, "v_serviceState",
                              0, "Given type does not extend v_serviceState");
                    assert(0);
                }
            }
#endif
            s = v_serviceState(c_new(type));
            if (s) {
                v_objectKind(s) = K_SERVICESTATE;
                v_object(s)->kernel = k;
            } else {
                OS_REPORT(OS_ERROR,
                          "v_serviceStateNew",0,
                          "Failed to allocate v_serviceState object.");
                assert(FALSE);
            }
        } else {
            s = NULL;
        }
    }
    if (s != NULL) {
        v_serviceStateInit(s, name);
    }

    return s;
}
Exemplo n.º 24
0
static void
c_deepwalkUnion(
    c_union v_union,
    c_object *objectPtr,
    c_deepwalkFunc action,
    void *actionArg)
{
    c_type switchType;
    c_type caseType;
    c_unionCase deflt;
    c_unionCase activeCase;
    c_unionCase currentCase;
    c_object unionData;
    c_value switchValue;
    c_literal label;
    int i,j, nCases, nLabels;

    c_long dataOffset;

    /* action for the union itself */
    /* No action, but separate actions for the switch and the data */
    /* action(c_type(v_union), objectPtr, actionArg); */
    /* action for the switch */
    c_deepwalkType(v_union->switchType, objectPtr,
                   action, actionArg);

    switchType = c_typeActualType(v_union->switchType);
    /* Determine value of the switch field */
    switch (c_baseObject(switchType)->kind) {
    case M_PRIMITIVE:
        switch (c_primitive(switchType)->kind) {
#define __CASE__(prim, type) \
        case prim: switchValue = type##Value(*((type *)*objectPtr)); break;
        __CASE__(P_BOOLEAN,c_bool)
        __CASE__(P_CHAR,c_char)
        __CASE__(P_SHORT,c_short)
        __CASE__(P_USHORT,c_ushort)
        __CASE__(P_LONG,c_long)
        __CASE__(P_ULONG,c_ulong)
        __CASE__(P_LONGLONG,c_longlong)
        __CASE__(P_ULONGLONG,c_ulonglong)
#undef __CASE__
        default:
            switchValue = c_undefinedValue();
            assert(FALSE);
        break;
        }
    break;
    case M_ENUMERATION:
        switchValue = c_longValue(*(c_long *)*objectPtr);
    break;
    default:
        switchValue = c_undefinedValue();
        assert(FALSE);
    break;
    }

    /* Determine the label corresponding to this field */

    activeCase = NULL;
    deflt = NULL;
    nCases = c_arraySize(v_union->cases);

    for (i=0; (i<nCases) && !activeCase; i++) {
        currentCase = c_unionCase(v_union->cases[i]);
        nLabels = c_arraySize(currentCase->labels);
        if (nLabels > 0) {
            for (j=0; (j<nLabels) && !activeCase; j++) {
                label = c_literal(currentCase->labels[j]);
                if (c_valueCompare(switchValue, label->value) == C_EQ) {
                    activeCase = currentCase;
                }
            }
        } else {
            deflt = currentCase;
        }
    }
    if (!activeCase) {
        activeCase = deflt;
    }
    assert(activeCase);
    if (activeCase) {
        caseType = c_specifier(activeCase)->type;
        if (c_type(v_union)->alignment >= v_union->switchType->size) {
            dataOffset = c_type(v_union)->alignment;
        } else {
            dataOffset = v_union->switchType->size;
        }
        unionData = C_DISPLACE(*objectPtr, (c_address)dataOffset);
        c_deepwalkType(caseType, &unionData, action, actionArg);
    }
}
Exemplo n.º 25
0
static c_type
createInstanceType (
    v_topic topic,
    c_char *keyExpr,
    c_array *keyListRef)
{
    c_metaObject o;
    c_type instanceType, baseType, foundType;
    c_type sampleType, keyType, keyInstanceType;
    c_base base;
    c_char *name;
    os_size_t length;
    int sres;

    assert(C_TYPECHECK(topic,v_topic));

    foundType = NULL;
    if (keyExpr) {
        keyType = v_topicKeyTypeCreate(topic,keyExpr,keyListRef);
    } else {
        keyExpr = v_topicKeyExpr(topic);
        keyType = v_topicKeyType(topic);
        *keyListRef = c_keep(v_topicMessageKeyList(topic));
    }
    sampleType = sampleTypeNew(topic);
    if (sampleType) {
        base = c_getBase(topic);
        baseType = v_dataReaderInstance_t(base);
        instanceType = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
        if (instanceType != NULL) {
            c_class(instanceType)->extends = c_keep(c_class(baseType));
            o = c_metaDeclare(c_metaObject(instanceType),
                              "sample",M_ATTRIBUTE);
            c_property(o)->type = c_keep(sampleType);
            c_free(o);
            o = c_metaDeclare(c_metaObject(instanceType),
                              "oldest",M_ATTRIBUTE);
            c_property(o)->type = (c_type)c_metaResolveType(c_metaObject(base),
                                                    "c_voidp");
            assert(c_property(o)->type);
            c_free(o);
            c_metaFinalize(c_metaObject(instanceType));
#define INSTANCE_NAME   "v_indexInstance<v_indexSample<>>"
#define INSTANCE_FORMAT "v_indexInstance<v_indexSample<%s>>"
            /* The sizeof contains \0 */
            length = sizeof(INSTANCE_NAME) + strlen(v_topicName(topic));
            name = os_alloca(length);
            sres = snprintf(name,length,INSTANCE_FORMAT,v_topicName(topic));
            assert(sres >= 0 && (os_size_t) sres == (length-1));
            OS_UNUSED_ARG(sres);
#undef INSTANCE_NAME
#undef INSTANCE_FORMAT
            foundType = c_type(c_metaBind(c_metaObject(base),
                                          name,
                                          c_metaObject(instanceType)));
            if (foundType == NULL) {
                OS_REPORT(OS_ERROR,
                        "v_index::createInstanceType",V_RESULT_INTERNAL_ERROR,
                        "Could not create instance type");
            }

            os_freea(name);

            if (keyType != NULL) {
                keyInstanceType = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
                if (keyInstanceType) {
                    c_class(keyInstanceType)->extends = c_keep(c_class(instanceType));
                    o = c_metaDeclare(c_metaObject(keyInstanceType),
                                      "key",M_ATTRIBUTE);
                    c_property(o)->type = c_keep(keyType);
                    c_free(o);
                    c_metaFinalize(c_metaObject(keyInstanceType));
#define INSTANCE_NAME   "v_indexKeyInstance<v_indexSample<>,>"
#define INSTANCE_FORMAT "v_indexKeyInstance<v_indexSample<%s>,%s>"
                    /* The sizeof contains \0 */
                    length = sizeof(INSTANCE_NAME) +
                             strlen(v_topicName(topic)) +
                             strlen(keyExpr);
                    name = os_alloca(length);
                    sres = snprintf(name,
                                    length,
                                    INSTANCE_FORMAT,
                                    v_topicName(topic),
                                    keyExpr);
                    assert(sres >= 0 && (os_size_t) sres == (length-1));
                    OS_UNUSED_ARG(sres);
#undef INSTANCE_NAME
#undef INSTANCE_FORMAT
                    c_free(foundType); /* Will be overwritten, so free */
                    foundType = c_type(c_metaBind(c_metaObject(base),
                                                  name,
                                                  c_metaObject(keyInstanceType)));
                    if (foundType == NULL) {
                        OS_REPORT(OS_ERROR,
                                  "v_index::createInstanceType",V_RESULT_INTERNAL_ERROR,
                                  "Could not create key instance type");
                    }
                    os_freea(name);
                    c_free(keyInstanceType);
                }
                c_free(keyType);
            }
            c_free(instanceType);
            c_free(baseType);
        } else {
            foundType = baseType; /* transfer refCount to caller */
        }
        c_free(sampleType);
    }

    return foundType;
}
Exemplo n.º 26
0
static c_type
sampleTypeNew(
    v_topic topic)
{
    c_metaObject o;
    c_type msgType,sampleType,foundType;
    c_base base;
    c_char *name;
    os_size_t length;
    int sres;

    assert(C_TYPECHECK(topic,v_topic));
    assert(topic);

    name = NULL;
    foundType = NULL;

    if (v_topicName(topic) == NULL) {
        OS_REPORT(OS_ERROR,
                  "v_index::sampleTypeNew failed",V_RESULT_ILL_PARAM,
                  "failed to retreive topic name");
        return NULL;
    }

    base = c_getBase(topic);

    if (base == NULL) {
        OS_REPORT(OS_ERROR,
                  "v_index::sampleTypeNew failed",V_RESULT_ILL_PARAM,
                  "failed to retreive base");
        return NULL;
    }

    msgType = c_keep(v_topicMessageType(topic));

    if (msgType == NULL) {
        OS_REPORT(OS_ERROR,
                  "v_index::sampleTypeNew failed",V_RESULT_ILL_PARAM,
                  "failed to retreive topic message type");
        return NULL;
    }

    sampleType = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
    if (sampleType) {
        c_class(sampleType)->extends = v_dataReaderSample_t(base);
        o = c_metaDeclare(c_metaObject(sampleType),"message",M_ATTRIBUTE);
        if (o) {
            c_property(o)->type = c_keep(msgType);
            c_metaObject(sampleType)->definedIn = c_keep(base);
            c_metaFinalize(c_metaObject(sampleType));

#define SAMPLE_FORMAT "v_indexSample<%s>"
#define SAMPLE_NAME   "v_indexSample<>"
            /* sizeof contains \0 */
            length = sizeof(SAMPLE_NAME) + strlen(v_topicName(topic));
            name = os_malloc(length);
            sres = snprintf(name,length,SAMPLE_FORMAT,v_topicName(topic));
            assert(sres >= 0 && (os_size_t) sres == (length-1));
            OS_UNUSED_ARG(sres);
#undef SAMPLE_FORMAT
#undef SAMPLE_NAME

            foundType = c_type(c_metaBind(c_metaObject(base),
                                          name,
                                          c_metaObject(sampleType)));
            c_free(o);
        } else {
            foundType = NULL;
        }
        c_free(sampleType);
    } else {
        OS_REPORT(OS_ERROR,
                  "v_index::sampleTypeNew failed",V_RESULT_ILL_PARAM,
                  "failed to retreive topic sample type");
    }
    os_free(name);
    c_free(msgType);

    return foundType;
}
Exemplo n.º 27
0
 binding* operator()(const null_t&) const  { return new binding_null(c_type(), sql_type()); }
Exemplo n.º 28
0
void
in_messageDeserializerReadUnion(
    in_messageDeserializer _this,
    c_type type,
    c_voidp data)
{
    c_union utype = c_union(type);
    c_type caseType;
    c_type switchType;
    c_unionCase deflt;
    c_unionCase activeCase;
    c_unionCase currentCase;
    c_value switchValue;
    c_literal label;
    c_voidp o;
    os_uint32 length;
    os_uint32 i;
    os_uint32 j;
    os_uint32 n;

    assert(_this);
    assert(type);
    assert(data);

    /* action for the switch */
    switchType = c_typeActualType(utype->switchType);
    in_messageDeserializerReadType(_this, switchType, data);

    /* Determine value of the switch field */
    switch (c_baseObjectKind(switchType))
    {
    case M_PRIMITIVE:
        switch (c_primitiveKind(switchType))
        {
#define __CASE__(prim, type) \
        case prim: switchValue = type##Value(*((type *)data)); break;
        __CASE__(P_BOOLEAN,c_bool)
        __CASE__(P_CHAR,c_char)
        __CASE__(P_SHORT,c_short)
        __CASE__(P_USHORT,c_ushort)
        __CASE__(P_LONG,c_long)
        __CASE__(P_ULONG,c_ulong)
        __CASE__(P_LONGLONG,c_longlong)
        __CASE__(P_ULONGLONG,c_ulonglong)
#undef __CASE__
        default:
            switchValue = c_undefinedValue();
            assert(FALSE);
        break;
        }
    break;
    case M_ENUMERATION:
        switchValue = c_longValue(*(c_long *)data);
    break;
    default:
        switchValue = c_undefinedValue();
        assert(FALSE);
    break;
    }

    /* Determine the label corresponding to this field */
    activeCase = NULL;
    deflt = NULL;
    length = c_arraySize(utype->cases);

    for (i = 0; (i < length) && !activeCase; i++)
    {
        currentCase = c_unionCase(utype->cases[i]);
        n = c_arraySize(currentCase->labels);
        if (n > 0)
        {
            for (j = 0; (j < n) && !activeCase; j++)
            {
                label = c_literal(currentCase->labels[j]);
                if (c_valueCompare(switchValue, label->value) == C_EQ)
                {
                    activeCase = currentCase;
                }
            }
        } else
        {
            deflt = currentCase;
        }
    }
    if(!activeCase)
    {
        activeCase = deflt;
    }
    assert(activeCase);
    if (activeCase)
    {
        if (c_type(utype)->alignment >= utype->switchType->size)
        {
            length = c_type(utype)->alignment;
        } else
        {
            length = utype->switchType->size;
        }
        o = C_DISPLACE(data, (c_address)length);
        caseType = c_typeActualType(c_specifierType(activeCase));
        in_messageDeserializerReadType(_this, caseType, o);
    }
}
Exemplo n.º 29
0
/*
 * Check if each usage of a char array as a key has a corresponding
 * "#pragma cats" declaration.
 */
static c_bool
idl_checkCatsUsage(
    c_base base,
    const char* filename)
{
    char errorBuffer [IDL_MAX_ERRORSIZE];
    idl_keyDef keyDef = idl_keyDefDefGet();
    c_long keyMapIdx;
    idl_keyMap keyMap;
    c_type type;
    c_structure structure;
    c_iter keysList;
    os_uint32 keysListSize;
    os_uint32 keyIdx;
    c_char* keyName;
    os_uint32 i;
    c_iter keyNameList;
    os_uint32 keyNameListSize;
    c_structure tmpStructure;
    c_specifier sp;
    c_type subType;
    c_string typeName;
    c_type spType;

    if (keyDef != NULL) {
        /* check all key definition list elements */
        for (keyMapIdx = 0; keyMapIdx < c_iterLength(keyDef->keyList); keyMapIdx++) {
            keyMap = c_iterObject(keyDef->keyList, keyMapIdx);
            /* if a keylist is defined for the type */
            if (keyMap->keyList && strlen(keyMap->keyList) > 0) {
                /* find meteobject for the type */
                type = c_type(c_metaResolveType(keyMap->scope, keyMap->typeName));
                if (!type) {
                    snprintf(errorBuffer, IDL_MAX_ERRORSIZE-1, errorText[idl_UndeclaredIdentifier], keyMap->typeName);
                    idl_printError(filename, errorBuffer);
                    return OS_FALSE;
                }
                /* type can be a typedef. Determine the actual type. */
                type = c_typeActualType(type);

                /* type should be a structure */
                if (c_baseObject(type)->kind != M_STRUCTURE) {
                    snprintf(errorBuffer, IDL_MAX_ERRORSIZE-1, errorText[idl_IllegalKeyFields]);
                    idl_printError(filename, errorBuffer);
                    return OS_FALSE;
                }
                structure = c_structure(type);

                /* for each key in keyList, check if type is a char array */
                keysList = c_splitString(keyMap->keyList, ",");
                keysListSize = c_iterLength(keysList);
                for(keyIdx = 0; keyIdx < keysListSize; keyIdx++)
                {
                    keyName = c_iterTakeFirst(keysList);
                    /* We might be dealing with a field of a field definition in
                     * the keylist, so let's split this up
                     */
                    keyNameList = c_splitString(keyName, ".");
                    keyNameListSize = c_iterLength(keyNameList);
                    tmpStructure = structure;
                    for(i = 0; i < keyNameListSize; i++)
                    {

                        keyName = c_iterTakeFirst(keyNameList);
                        /* Now get the actual member defined by the name */
                        sp = c_specifier(c_metaFindByName(
                            c_metaObject(tmpStructure),
                            keyName,
                            CQ_FIXEDSCOPE | CQ_MEMBER | CQ_CASEINSENSITIVE));
                        if(sp)
                        {
                            spType = c_typeActualType(sp->type);
                            /* If the member is a structure, we need to
                             * recurse deeper.
                             */
                            if(c_baseObject(spType)->kind == M_STRUCTURE)
                            {
                                tmpStructure = c_structure(spType);
                            }
                            /* If the member is a collection then we need to
                             * ensure it is not a character array, but if it
                             * is we need to ensure a corresponding CATS pragma
                             * can be located
                             */
                            else if(c_baseObject(spType)->kind == M_COLLECTION && c_collectionType(spType)->kind == C_ARRAY)
                            {
                                subType = c_typeActualType(c_collectionType(spType)->subType);
                                if(c_baseObject(subType)->kind == M_PRIMITIVE &&
                                   c_primitive(subType)->kind == P_CHAR)
                                {

                                    typeName = c_metaName(c_metaObject(tmpStructure));
                                    /* check if there is corresponding catsDef */
                                    if (!idl_isCatsDefFor(c_metaObject(tmpStructure)->definedIn,
                                                          typeName,
                                                          keyName))
                                    {
                                        snprintf(
                                            errorBuffer,
                                            IDL_MAX_ERRORSIZE-1,
                                            errorText[idl_NoCorrespondingCats],
                                            c_metaObject(structure)->name,
                                            keyName);
                                        idl_printError(filename, errorBuffer);
                                        return OS_FALSE;
                                    }
                                    c_free(typeName);
                                }

                            }
                        }
                    }
                }
            }
        }
    }

    return OS_TRUE;
}
Exemplo n.º 30
0
c_type
idl_stacDefConvertStacApprovedMember(
    c_structure structure,
    c_type orgMemberType)
{
    c_type dereffedOrgType;
    c_metaObject o = NULL;
    c_type newType;
    os_char buffer[1024];
    c_metaObject found;

    memset(buffer, 0, 1024);
    dereffedOrgType = c_typeActualType(c_type(idl_stacDefResolveTypeDef(c_baseObject(orgMemberType))));
    if(c_baseObject(dereffedOrgType)->kind == M_COLLECTION)
    {
        o = c_metaObject(c_metaDefine(c_metaObject(structure), M_COLLECTION));
        /* Can be a string or an array or a sequence */
        if(c_collectionType(dereffedOrgType)->kind == OSPL_C_STRING)
        {
            if((c_collectionType(dereffedOrgType)->maxSize != 0))
            {
                c_collectionType(o)->kind = OSPL_C_ARRAY;
                c_collectionType(o)->subType = c_type(c_metaResolve(c_metaObject(structure), "c_char"));
                /* increase maxSize with 1 to accomodate the '\0' char found in strings */
                c_collectionType(o)->maxSize = c_collectionType(dereffedOrgType)->maxSize + 1;
                os_sprintf(
                    buffer,
                    "C_ARRAY<%s,%d>",
                    c_metaObject(c_collectionType(o)->subType)->name,
                    c_collectionType(o)->maxSize/*use maxSize of new c_type, must be the same*/);
            }
            else
            {
                printf("FATAL ERROR | #pragma stac: Trying to apply stac algorithm to listed members of struct %s, but "
                       "encountered an internal error. The conversion algorithm (idl_stacDefConvertStacApprovedMember) "
                       "has become out of synch with the verification algorithm (idl_stacDefCanStacBeAppliedToMember).\n",
                       c_metaScopedName(c_metaObject(structure)));
                assert(0);
                exit(-2);
            }
        }
        else if(c_collectionType(dereffedOrgType)->kind == OSPL_C_ARRAY)
        {
            c_collectionType(o)->kind = OSPL_C_ARRAY;
            /* increase maxSize with 1 to accomodate the '\0' char found in strings */
            c_collectionType(o)->maxSize = c_collectionType(dereffedOrgType)->maxSize;
            c_collectionType(o)->subType = idl_stacDefConvertStacApprovedMember(structure, c_collectionType(dereffedOrgType)->subType);
            os_sprintf(
                buffer,
                "C_ARRAY<%s,%d>",
                c_metaObject(c_collectionType(o)->subType)->name,
                c_collectionType(o)->maxSize/*use maxSize of new c_type, must be the same*/);
        }
        else if(c_collectionType(dereffedOrgType)->kind == OSPL_C_SEQUENCE)
        {
            c_collectionType(o)->kind = OSPL_C_SEQUENCE;
            /* increase maxSize with 1 to accomodate the '\0' char found in strings */
            c_collectionType(o)->maxSize = c_collectionType(dereffedOrgType)->maxSize;
            c_collectionType(o)->subType = idl_stacDefConvertStacApprovedMember(structure, c_collectionType(dereffedOrgType)->subType);
            os_sprintf(
                buffer,
                "C_SEQUENCE<%s,%d>",
                c_metaObject(c_collectionType(o)->subType)->name,
                c_collectionType(o)->maxSize/*use maxSize of new c_type, must be the same*/);
        }
        else
        {
            printf("FATAL ERROR | #pragma stac: Trying to apply stac algorithm to listed members of struct %s, but "
                   "encountered an internal error. The conversion algorithm (idl_stacDefConvertStacApprovedMember) "
                   "has become out of synch with the verification algorithm (idl_stacDefCanStacBeAppliedToMember).\n",
                   c_metaScopedName(c_metaObject(structure)));
            assert(0);
            exit(-2);
        }
    }
    else
    {
        printf("FATAL ERROR | #pragma stac: Trying to apply stac algorithm to listed members of struct %s, but "
               "encountered an internal error. The conversion algorithm (idl_stacDefConvertStacApprovedMember) "
               "has become out of synch with the verification algorithm (idl_stacDefCanStacBeAppliedToMember).\n",
               c_metaScopedName(c_metaObject(structure)));
        assert(0);
        exit(-2);
    }
    if(o)
    {
        c_metaObject(o)->definedIn = c_metaObject(structure);
        c_metaFinalize(o);
        found = c_metaBind(c_metaObject(structure), &buffer[0], o);
        c_free(o);
        newType = c_type(found);
    }
    else
    {
        printf("FATAL ERROR | #pragma stac: Trying to apply stac algorithm to listed members of struct %s, but "
               "encountered an internal error. The conversion algorithm (idl_stacDefConvertStacApprovedMember) "
               "has become out of synch with the verification algorithm (idl_stacDefCanStacBeAppliedToMember).\n",
               c_metaScopedName(c_metaObject(structure)));
        assert(0);
        exit(-2);
    }
    return newType;
}