MOF_Instance_Decl* MOF_Instance_Decl::find(const char* inst_name) { MOF_Instance_Decl* p; if (!inst_name) return 0; for (p = MOF_Instance_Decl::list; p; p = (MOF_Instance_Decl*)p->next) { MOF_ASSERT(p->inst_name); if (strcmp(p->inst_name, inst_name) == 0) return p; } return 0; }
void* MOF_Realloc(MOF_Heap* self, void* ptr, size_t size) { MOF_Block* p; if (!self) return NULL; if (!ptr) return MOF_Malloc(self, size); p = (MOF_Block*)ptr - 1; MOF_ASSERT(p->magic == MAGIC); #if 0 /* Fill released part with a non-zero pattern */ if (p->size > size) memset((char*)ptr + size, 0xDD, p->size - size); #endif p = (MOF_Block*)PAL_Realloc(p, sizeof(MOF_Block) + size); if (!p) return NULL; #if 0 /* Fill with a non-zero pattern */ if (size > p->size) memset((char*)(p + 1) + p->size, 0xFF, size - p->size); #endif if (p->prev) p->prev->next = p; else self->head = p; if (p->next) p->next->prev = p; p->size = (unsigned int)size; return p + 1; }
MOF_Object_Reference* MOF_Instance_Decl::alias_to_obj_ref(const char* alias) { /* * Lookup the instance for this alias: */ MOF_Instance_Decl* inst_decl = MOF_Instance_Decl::find_by_alias((char*)alias, false); if (!inst_decl) MOF_error_printf("undefined alias: \"%s\"", alias); /* * Create object reference for this instance: */ MOF_Object_Reference* obj_ref = 0; _make_obj_ref(inst_decl, obj_ref); MOF_ASSERT(obj_ref != 0); return obj_ref; }
void MOF_Free(MOF_Heap* self, void* ptr) { MOF_Block* p; if (!self || !ptr) return; p = (MOF_Block*)ptr - 1; MOF_ASSERT(p->magic == MAGIC); if (p->prev) p->prev->next = p->next; else self->head = p->next; if (p->next) p->next->prev = p->prev; /* Fill released memory with 0xDD characters */ memset(p, 0xDD, sizeof(MOF_Block) + p->size); PAL_Free(p); }
void _make_obj_ref( MOF_Instance_Decl* inst_decl, MOF_Object_Reference*& obj_ref) { MOF_Feature_Info* p; bool found_key = false; /* * Allocate the MOF_Object_Reference object: */ if ((obj_ref = new MOF_Object_Reference()) == 0) { MOF_error("out of memory"); return; } /* * Set class name: */ if ((obj_ref->class_name = strdup(inst_decl->class_name)) == 0) { MOF_error("out of memory"); return; } /* * Iterate the features looking for keys: */ for (p = inst_decl->all_features; p; p = (MOF_Feature_Info*)p->next) { MOF_Feature* feature = p->feature; if (feature->qual_mask & MOF_QT_KEY) { found_key = true; /* * The feature cannot be a method because the the key qualifier * (which we just checked for) only applies to references and * properties. */ MOF_ASSERT(feature->type != MOF_FEATURE_METHOD); /* * Create new MOF_Key_Value_Pair. */ MOF_Key_Value_Pair* pair = new MOF_Key_Value_Pair(); if (pair == 0) { MOF_error("out of memory"); return; } /* * Initialize MOF_Key_Value_Pair object. */ if ((pair->key = strdup(feature->name)) == 0) { MOF_error("out of memory"); return; } /* * If property; else reference. */ if (feature->type == MOF_FEATURE_PROP) { MOF_Property_Decl* prop_decl = (MOF_Property_Decl*)feature; /* * Grab is_array flag. */ pair->is_array = prop_decl->array_index == 0 ? false : true; /* * Clone the initializer. */ if (prop_decl->initializer) { if ((pair->value = (MOF_Literal*) prop_decl->initializer->clone_list()) == 0) { MOF_error("out of memory"); return; } } else pair->value = 0; } else if (feature->type == MOF_FEATURE_REF) { MOF_Reference_Decl* ref_decl = (MOF_Reference_Decl*)feature; /* * It can't be an array if its a reference. */ pair->is_array = false; /* * If the initializer is non-null. */ if (ref_decl->obj_ref) { MOF_Literal* value = new MOF_Literal(); value->value_type = TOK_STRING_VALUE; value->string_value = ref_decl->obj_ref->to_string(); pair->value = value; } else pair->value = 0; } else { /* Logically unreachable. */ MOF_ASSERT(0); } /* * Append to list */ if (obj_ref->pairs) obj_ref->pairs->append(pair); else obj_ref->pairs = pair; } } if (!found_key) MOF_error("instance has no key fields"); obj_ref->validate(); obj_ref->normalize(); }
void MOF_Instance_Decl::handle(MOF_Instance_Decl* inst_decl) { MOF_Class_Decl* class_decl; /* * Does class exist? */ if ((class_decl = MOF_Class_Decl::find( inst_decl->class_name, true)) == 0) { MOF_error_printf("instance refers to undefined class: \"%s\"", inst_decl->class_name); } inst_decl->class_decl = class_decl; /* * Is alias already defined? */ if (inst_decl->alias) { if (MOF_Class_Decl::find_by_alias(inst_decl->alias) || MOF_Instance_Decl::find_by_alias(inst_decl->alias)) { MOF_error_printf( "alias name already defined: \"%s\"", inst_decl->alias); } } /* * Build the all qualifiers list: */ inst_decl->all_qualifiers = MOF_Qualifier_Info::make_all_qualifiers( class_decl->name, 0, 0, 0, inst_decl->qualifiers, class_decl->all_qualifiers, &inst_decl->qual_mask, false); /* prop */ /* * Check for duplicate features: */ _check_duplicate_properties(inst_decl); /* * Validate the properties against the class: */ _check_undefined_properties(class_decl, inst_decl); /* * Build the all-features list: */ _build_all_features_list(class_decl, inst_decl); /* * Create an instance-name for this instance. */ MOF_Object_Reference* tmp_obj_ref = 0; _make_obj_ref(inst_decl, tmp_obj_ref); char* inst_name = tmp_obj_ref->to_string(); delete tmp_obj_ref; /* * Check that the instance name can be reparsed (sanity check). */ { char* tmp = MOF_Object_Reference::normalize(inst_name); MOF_ASSERT(strcmp(inst_name, tmp) == 0); free(tmp); } inst_decl->inst_name = inst_name; // printf("=== new instance: [%s]\n", inst_name); /* * See if instance is already defined: */ if (MOF_Instance_Decl::find(inst_name)) { MOF_error_printf("instance already defined: \"%s\"", inst_name); return; } /* * Append instance to list: */ if (MOF_Instance_Decl::list) MOF_Instance_Decl::list->append(inst_decl); else MOF_Instance_Decl::list = inst_decl; #if 0 _print(inst_decl); #endif }
MOF_Element* MOF_Instance_Decl::clone() const { MOF_ASSERT("not implemented" == 0); return 0; }
MOF_Element* MOF_Feature_Info::clone() const { MOF_ASSERT("not implemented" == 0); return 0; }
MOF_Element* MOF_Qualifier_Info::clone() const { MOF_ASSERT("not implemented" == 0); return 0; }
void MOF_Object_Reference::normalize() { size_t count; /* * Sort the key-value pairs: */ if ((count = pairs->list_size())) { MOF_Key_Value_Pair* p; MOF_Key_Value_Pair** tmp_pairs; size_t i; /* * Allocate an array of pointers to the key-value pairs: */ if ((tmp_pairs = (MOF_Key_Value_Pair**)calloc( 1, sizeof(MOF_Key_Value_Pair*) * count)) == 0) { MOF_error("out of memory"); return; } /* * Initialize the array of pointers and shift key names to lower * case as you go. */ for (p = pairs, i = 0; p; p = (MOF_Key_Value_Pair*)p->next, i++) { tmp_pairs[i] = p; MOF_strtolower(p->key); } /* * Sort the array (in ascending order by key): */ qsort(tmp_pairs, count, sizeof(MOF_Key_Value_Pair*), _compare); /* * Reset the linked list pointers so the linked list is in sorted order. */ for (i = 0; i < count; i++) tmp_pairs[i]->next = 0; for (i = 1; i < count; i++) tmp_pairs[i-1]->append(tmp_pairs[i]); MOF_ASSERT(tmp_pairs[0]->list_size() == count); /* * Set new pairs head: */ pairs = tmp_pairs[0]; /* * Release the temporary array. */ free(tmp_pairs); } /* * Shift the class name to lower case: */ MOF_strtolower(class_name); }