예제 #1
0
MOF_Instance_Decl* MOF_Instance_Decl::find_by_alias(
    char* alias,
    bool fix_case)
{
    MOF_Instance_Decl* p;

    if (!alias)
        return 0;

    for (p = MOF_Instance_Decl::list; p; p = (MOF_Instance_Decl*)p->next)
    {
        if (p->alias && MOF_stricmp(p->alias, alias) == 0)
        {
            if (fix_case && strcmp(p->alias, alias) != 0)
            {
#if 0
                MOF_warning_printf("changing case of \"%s\" to \"%s\"",
                    alias, p->alias);
#endif
                strcpy(alias, p->alias);
            }
            return p;
        }
    }

    return 0;
}
static MOF_mask _make_qual_mask(
    MOF_Qualifier_Info* qual_info_list,
    bool prop,
    bool param)
{
    MOF_Qualifier_Info* p;
    MOF_mask mask = 0;
    size_t i;

    /*
     * Set bits for qualifiers whose default is true.
     */

    if (prop)
        mask |= MOF_QT_READ;

    if (param)
        mask |= MOF_QT_IN;

    /*
     * Iterate over qualifier list and either set or clear the corresponding
     * qualifier bit.
     */

    for (p = qual_info_list; p != 0; p = (MOF_Qualifier_Info*)p->next)
    {
        for (i = 0; i < NUM_PAIRS; i++)
        {
            if (MOF_stricmp(_pairs[i].name, p->qualifier->name) == 0)
            {
                MOF_Literal* lit = p->qualifier->params;
                bool flag = true;

                /*
                 * Ignore errors (these are checked elsewhere).
                 */

                if (lit && (lit->next || lit->value_type != TOK_BOOL_VALUE))
                    continue;

                if (lit && !lit->bool_value)
                    flag = false;

                if (flag)
                    mask |= _pairs[i].mask;
                else
                    mask &= ~_pairs[i].mask;
            }
        }
    }

    return mask;
}
예제 #3
0
static void _check_duplicate_properties(
    MOF_Instance_Decl* inst_decl)
{
    MOF_Property* p;
    MOF_Property* q;
    
    for (p = inst_decl->properties; p; p = (MOF_Property*)p->next)
    {
        for (q = inst_decl->properties; q != p; q = (MOF_Property*)q->next)
        {
            if (MOF_stricmp(p->name, q->name) == 0)
                MOF_error_printf("duplicate property: \"%s\"", p->name);
        }
    }
}
예제 #4
0
static void _check_undefined_properties(
    const MOF_Class_Decl* class_decl, 
    MOF_Instance_Decl* inst_decl)
{
    MOF_Property* p;

    /* 
     * First check that all instance properties are declared in class
     * and that the types are consistent.
     */

    for (p = inst_decl->properties; p; p = (MOF_Property*)p->next)
    {
        bool found;
        MOF_Feature_Info* q;

        found = false;

        for (q = class_decl->all_features; q; q = (MOF_Feature_Info*)q->next)
        {
            MOF_Feature* feature = q->feature;

            if (MOF_stricmp(p->name, feature->name) == 0)
            {
                MOF_fix_case(p->name, feature->name);

                if (feature->type != MOF_FEATURE_METHOD)
                    found = true;

                break;
            }
        }

        if (!found)
        {
            MOF_error_printf("no such property found in class: \"%s\"",
                p->name);
            return;
        }
    }
}
예제 #5
0
static void _build_all_features_list(
    const MOF_Class_Decl* class_decl, 
    MOF_Instance_Decl* inst_decl)
{
    MOF_Feature_Info* p;
    MOF_Feature_Info* all_features = 0;
    MOF_Property* q;

    /*
     * Iterate the properties in the class and build the all-properties list.
     */

    for (p = class_decl->all_features; p; p = (MOF_Feature_Info*)p->next)
    {
        MOF_Feature* feature = p->feature;
        MOF_Feature_Info* new_feature_info;
        MOF_Property* inst_prop = 0;

        /*
         * First, search for this feature in the instance declaration.
         */

        for (q = inst_decl->properties; q; q = (MOF_Property*)q->next)
        {
            if (MOF_stricmp(feature->name, q->name) == 0)
            {
                inst_prop = q;
                break;
            }
        }

        /*
         * Create a new MOF_Feature_Info object.
         */

        if ((new_feature_info = new MOF_Feature_Info()) == 0)
        {
            MOF_error("out of memory");
            return;
        } 

        /*
         * If instance contains a property with this name:
         */

        if (inst_prop)
        {
            if (feature->type == MOF_FEATURE_PROP)
            {
                MOF_Property_Decl* prop_decl;

                /*
                 * Clone the feature (and initialize).
                 */

                prop_decl = (MOF_Property_Decl*)
                    ((MOF_Property_Decl*)feature)->clone();

                if (prop_decl == 0)
                {
                    MOF_error("out of memory");
                    return;
                }

                prop_decl->qualifiers = inst_prop->qualifiers;
                prop_decl->all_qualifiers = 0;
                prop_decl->qual_mask = 0;
                prop_decl->initializer = inst_prop->initializer;

                /*
                 * Initialize the new_feature_info structure:
                 */

                new_feature_info->feature = (MOF_Feature*)prop_decl;
                new_feature_info->class_origin = p->class_origin;
                new_feature_info->propagated = p->propagated;

                /*
                 * Build the all qualifiers list
                 */

                prop_decl->all_qualifiers = 
                    MOF_Qualifier_Info::make_all_qualifiers(
                        class_decl->name, 
                        0, 
                        inst_prop->name, 
                        0,
                        prop_decl->qualifiers, 
                        feature->all_qualifiers,
                        &prop_decl->qual_mask,
                        true); /* prop */

                /*
                 * Validate the initializer (if any).
                 */

                if (inst_prop->initializer)
                {
                    inst_prop->initializer->validate("property", 
                        inst_prop->name, prop_decl->data_type, 
                        prop_decl->array_index);
                }
            }
            else if (feature->type == MOF_FEATURE_REF)
            {
                MOF_Reference_Decl* ref_decl;

                /*
                 * Clone the feature (and initialize).
                 */

                ref_decl = (MOF_Reference_Decl*)
                    ((MOF_Reference_Decl*)feature)->clone();

                if (ref_decl == 0)
                {
                    MOF_error("out of memory");
                    return;
                }

                ref_decl->qualifiers = inst_prop->qualifiers;
                ref_decl->all_qualifiers = 0;
                ref_decl->qual_mask = 0;
                ref_decl->alias = 0;

                /*
                 * Initialize the new_feature_info structure:
                 */

                new_feature_info->feature = (MOF_Feature*)ref_decl;
                new_feature_info->class_origin = p->class_origin;
                new_feature_info->propagated = p->propagated;

                /*
                 * Build the all qualifiers list
                 */

                ref_decl->all_qualifiers = 
                    MOF_Qualifier_Info::make_all_qualifiers(
                    class_decl->name, 
                    0, 
                    inst_prop->name, 
                    0,
                    ref_decl->qualifiers, 
                    feature->all_qualifiers,
                    &ref_decl->qual_mask,
                    false); /* prop */

                /*
                 * Validate the alias (ATTN) OR object reference.
                 */

                if (inst_prop->initializer)
                {
                    MOF_Object_Reference* obj_ref = 0;

                    /*
                     * Since it's a reference, we expect a string initializer.
                     */

                    if (inst_prop->initializer->value_type != TOK_STRING_VALUE)
                    {
                        MOF_error_printf(
                            "bad ref initializer for property: \"%s\"",
                            inst_prop->name);
                        return;
                    }

                    /*
                     * Parse the object reference string:
                     */

                    if (REF_parse(
                        inst_prop->initializer->string_value, &obj_ref) != 0)
                    {
                        MOF_error_printf(
                            "bad ref initializer for property: \"%s\"",
                            inst_prop->name);
                        return;
                    }

                    /*
                     * Validate and normalize new object reference.
                     */

                    obj_ref->validate();
                    obj_ref->normalize();

                    /*
                     * Be sure the class of the initializer is a sub-class 
                     * of the class of the class's ref decl.
                     */

                    ref_decl->validate_obj_ref(obj_ref);
                    ref_decl->obj_ref = obj_ref;
                }
                else if (inst_prop->alias)
                {
                    MOF_Object_Reference* obj_ref = 
                        MOF_Instance_Decl::alias_to_obj_ref(inst_prop->alias);

                    /*
                     * Be sure the class of the initializer is a sub-class 
                     * of the class of the class's ref decl.
                     */

                    ref_decl->validate_obj_ref(obj_ref);
                    ref_decl->obj_ref = obj_ref;
                }
            }
        }
        else
        {
            /*
             * Propagate feature from class.
             */

            new_feature_info->feature = p->feature;
            new_feature_info->class_origin = p->class_origin;
            new_feature_info->propagated = true;
        }

        /*
         * Append to list:
         */

        if (all_features)
            all_features->append(new_feature_info);
        else
            all_features = new_feature_info;
    }

    inst_decl->all_features = all_features;
}
예제 #6
0
void MOF_Qualifier::validate()
{
    MOF_Qualifier_Decl* qual_decl;

    /*
     * Find qualifier declaration:
     */

    if ((qual_decl = MOF_Qualifier_Decl::find(name)) == 0)
        MOF_error_printf("undefined qualifier: \"%s\"\n", name);

    /*
     * The presence of a scalar boolean qualifier without arguments implies
     * true.
     */

    if (qual_decl->data_type == TOK_BOOLEAN &&
        qual_decl->array_index == 0 &&
        (params == 0 || params->value_type == TOK_NULL_VALUE))
    {
        params->delete_list();
        params = new MOF_Literal();
        params->value_type = TOK_BOOL_VALUE;
        params->bool_value = true;
    }

    /*
     * Check the qualifier params (if any):
     */

    if (params)
    {
        params->validate("qualifier", name, qual_decl->data_type,
            qual_decl->array_index);
    }

    /*
     * Free descriptions:
     */

#if 0
    /*
     * Release descriptions (to see how much memory they take).
     */

    if (MOF_stricmp(name, "description") == 0)
    {
        if (params && params->u.string_value)
        {
            free (params->u.string_value);
            params->u.string_value = 0;

            free (params);
            params = 0;
        }

        free (name);
        name = (char*)DESCRIPTION;
    }

#endif

}