Exemple #1
0
c_iter
c_bindAttributes(
    c_metaObject scope,
    c_iter declarations,
    c_type type,
    c_bool isReadOnly)
{
    c_iter attributes;
    c_declarator d;
    c_metaObject o;

    if (isReadOnly) {
        /* suppress warnings */
    }
    attributes = NULL;
    d = (c_declarator)c_iterTakeFirst(declarations);
    while (d != NULL) {
        o = c_metaDefine(scope,M_ATTRIBUTE);
        c_property(o)->type = c_declaratorType(d,type);
        c_metaFinalize(o);
        c_metaBind(scope,d->name,o);
        attributes = c_iterInsert(attributes,o);
        os_free(d);
        d = (c_declarator)c_iterTakeFirst(declarations);
    }
    c_iterFree(declarations);
    return attributes;
}
Exemple #2
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;

}
Exemple #3
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;
}
Exemple #4
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;
}
Exemple #5
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;
}
Exemple #6
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;
}
Exemple #7
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;
}
Exemple #8
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;
}