int Trick::MemoryManager::ref_var( REF2* R, char* name) { ALLOC_INFO *alloc_info; VARIABLE_MAP::iterator pos; pthread_mutex_lock(&mm_mutex); pos = variable_map.find( name); if (pos != variable_map.end()) { alloc_info = pos->second; R->attr = make_reference_attr( alloc_info); R->address = alloc_info->start; if ( R->create_add_path ) { ADDRESS_NODE * address_node ; address_node = new ADDRESS_NODE ; address_node->operator_ = AO_ADDRESS ; address_node->operand.address = R->address ; DLL_AddTail(address_node , R->address_path) ; } pthread_mutex_unlock(&mm_mutex); return (MM_OK); } else { // ERROR. } pthread_mutex_unlock(&mm_mutex); return (MM_UNDEFINED_REFERENCE); }
int Trick::MemoryManager::ref_name(REF2 * R, char *name) { int ii; char *addr; ATTRIBUTES *attr; attr = (ATTRIBUTES*)(R->attr->attr); if (attr == NULL) { return (MM_PARAMETER_NAME); } if (R->address == NULL) { std::stringstream message; message << "ref_name: Because the address of \"" << R->reference << "\" is NULL, a legitimate address can't be calculated for \"" << R->reference << "." << name << "\"."; emitError(message.str()); return (MM_PARAMETER_NAME); } /* Find the parameter name at this level in the parameter list, 'ii' is the index to the parameter in the list. */ ii = 0; while (strcmp(name, attr[ii].name)) { if (attr[ii].name[0] == '\0') return (MM_PARAMETER_NAME); ii++; } attr = &(attr[ii]); // R->deprecated |= (attr->mods & 0x80000000); /* Set error_attr just in case we have an error */ // R->error_attr = attr; /* If the variable is a static var, offset is the absolute address */ if (attr->mods & 2) { addr = (char *) attr->offset; if ( R->create_add_path ) { DLLPOS list_pos ; ADDRESS_NODE * address_node ; list_pos = DLL_GetHeadPosition(R->address_path) ; while ( (list_pos != NULL) && (address_node = (ADDRESS_NODE *)DLL_GetNext(&list_pos, R->address_path)) != NULL ) { if ( (list_pos != NULL) && (list_pos->info != NULL) ) { delete (ADDRESS_NODE *)(list_pos->info) ; } } DLL_RemoveAll(R->address_path) ; address_node = new ADDRESS_NODE ; address_node->operator_ = AO_ADDRESS ; address_node->operand.address = addr ; DLL_AddTail(address_node , R->address_path) ; } } else { addr = (char *)R->address + attr->offset; if ( R->create_add_path ) { ADDRESS_NODE * address_node ; if ( attr->offset != 0 ) { address_node = (ADDRESS_NODE *)DLL_GetAt(DLL_GetTailPosition(R->address_path), R->address_path) ; switch ( address_node->operator_ ) { case AO_ADDRESS: address_node->operand.address = (void *)((char *)address_node->operand.address + attr->offset) ; break ; case AO_DEREFERENCE: address_node = new ADDRESS_NODE ; address_node->operator_ = AO_OFFSET ; address_node->operand.offset = attr->offset ; DLL_AddTail(address_node , R->address_path) ; break ; case AO_OFFSET: address_node->operand.offset += attr->offset ; break ; } } } } /* Save the address and next attributes in the REF structure */ R->attr = attr; R->address = addr; return (MM_OK); }