Exemple #1
0
status_t
BListValueNode::CreateChildrenInRange(TeamTypeInformation* info,
	int32 lowIndex, int32 highIndex)
{
	if (fLocationResolutionState != B_OK)
		return fLocationResolutionState;

	if (lowIndex < 0)
		lowIndex = 0;
	if (highIndex >= fItemCount)
		highIndex = fItemCount - 1;

	if (!fCountChildCreated && fItemCountType != NULL) {
		BListItemCountNodeChild* countChild = new(std::nothrow)
			BListItemCountNodeChild(fItemCountLocation, this, fItemCountType);

		if (countChild == NULL)
			return B_NO_MEMORY;

		fCountChildCreated = true;
		countChild->SetContainer(fContainer);
		fChildren.AddItem(countChild);
	}

	BReference<Type> addressTypeRef;
	Type* type = NULL;
	CompoundType* objectType = dynamic_cast<CompoundType*>(fType);
	if (objectType->CountTemplateParameters() != 0) {
		AddressType* addressType = NULL;
		status_t result = objectType->TemplateParameterAt(0)->GetType()
			->CreateDerivedAddressType(DERIVED_TYPE_POINTER, addressType);
		if (result != B_OK)
			return result;

		type = addressType;
		addressTypeRef.SetTo(type, true);
	} else {
		BString typeName;
		TypeLookupConstraints constraints;
		constraints.SetTypeKind(TYPE_ADDRESS);
		constraints.SetBaseTypeName("void");
		status_t result = info->LookupTypeByName(typeName, constraints,
			type);
		if (result != B_OK)
			return result;
	}

	for (int32 i = lowIndex; i <= highIndex; i++)
	{
		BListElementNodeChild* child =
			new(std::nothrow) BListElementNodeChild(this, i, type);
		if (child == NULL)
			return B_NO_MEMORY;
		child->SetContainer(fContainer);
		fChildren.AddItem(child);
	}

	fChildrenCreated = true;

	if (fContainer != NULL)
		fContainer->NotifyValueNodeChildrenCreated(this);

	return B_OK;
}
Exemple #2
0
status_t
BListValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader,
	ValueLocation*& _location, Value*& _value)
{
	// get the location
	ValueLocation* location = NodeChild()->Location();
	if (location == NULL)
		return B_BAD_VALUE;


	// get the value type
	type_code valueType;
	if (valueLoader->GetArchitecture()->AddressSize() == 4) {
		valueType = B_UINT32_TYPE;
		TRACE_LOCALS("    -> 32 bit\n");
	} else {
		valueType = B_UINT64_TYPE;
		TRACE_LOCALS("    -> 64 bit\n");
	}

	// load the value data

	status_t error = B_OK;
	_location = location;
	_value = NULL;

	ValueLocation* memberLocation = NULL;
	CompoundType* baseType = dynamic_cast<CompoundType*>(fType);

	if (baseType->CountTemplateParameters() != 0) {
		// for BObjectList we need to walk up
		// the hierarchy: BObjectList -> _PointerList_ -> BList
		if (baseType->CountBaseTypes() == 0)
			return B_BAD_DATA;

		baseType = dynamic_cast<CompoundType*>(baseType->BaseTypeAt(0)
			->GetType());
		if (baseType == NULL || baseType->Name() != "_PointerList_")
			return B_BAD_DATA;

		if (baseType->CountBaseTypes() == 0)
			return B_BAD_DATA;

		baseType = dynamic_cast<CompoundType*>(baseType->BaseTypeAt(0)
			->GetType());
		if (baseType == NULL || baseType->Name() != "BList")
			return B_BAD_DATA;

	}

	for (int32 i = 0; i < baseType->CountDataMembers(); i++) {
		DataMember* member = baseType->DataMemberAt(i);
		if (strcmp(member->Name(), "fObjectList") == 0) {
			error = baseType->ResolveDataMemberLocation(member,
				*location, memberLocation);
			BReference<ValueLocation> locationRef(memberLocation, true);
			if (error != B_OK) {
				TRACE_LOCALS(
					"BListValueNode::ResolvedLocationAndValue(): "
					"failed to resolve location of header member: %s\n",
					strerror(error));
				return error;
			}

			error = valueLoader->LoadValue(memberLocation, valueType,
				false, fDataLocation);
			if (error != B_OK)
				return error;
		} else if (strcmp(member->Name(), "fItemCount") == 0) {
			error = baseType->ResolveDataMemberLocation(member,
				*location, memberLocation);
			BReference<ValueLocation> locationRef(memberLocation, true);
			if (error != B_OK) {
				TRACE_LOCALS(
					"BListValueNode::ResolvedLocationAndValue(): "
					"failed to resolve location of header member: %s\n",
					strerror(error));
				return error;
			}

			fItemCountType = member->GetType();
			fItemCountType->AcquireReference();

			fItemCountLocation = memberLocation->PieceAt(0).address;

			BVariant listSize;
			error = valueLoader->LoadValue(memberLocation, valueType,
				false, listSize);
			if (error != B_OK)
				return error;

			fItemCount = listSize.ToInt32();
			TRACE_LOCALS(
				"BListValueNode::ResolvedLocationAndValue(): "
				"detected list size %" B_PRId32 "\n",
				fItemCount);
		}
		memberLocation = NULL;
	}

	return B_OK;
}