示例#1
0
status_t
VariablesView::VariableTableModel::_AddNode(Variable* variable,
	ModelNode* parent, ValueNodeChild* nodeChild, bool isPresentationNode)
{
	// Don't create nodes for unspecified types -- we can't get/show their
	// value anyway.
	Type* nodeChildRawType = nodeChild->GetType()->ResolveRawType(false);
	if (nodeChildRawType->Kind() == TYPE_UNSPECIFIED)
		return B_OK;

	ModelNode* node = new(std::nothrow) ModelNode(parent, variable, nodeChild,
		isPresentationNode);
	BReference<ModelNode> nodeReference(node, true);
	if (node == NULL || node->Init() != B_OK)
		return B_NO_MEMORY;

	int32 childIndex;

	if (parent != NULL) {
		childIndex = parent->CountChildren();

		if (!parent->AddChild(node))
			return B_NO_MEMORY;
		// the parent has a reference, now
	} else {
		childIndex = fNodes.CountItems();

		if (!fNodes.AddItem(node))
			return B_NO_MEMORY;
		nodeReference.Detach();
			// the fNodes list has a reference, now
	}

	fNodeTable.Insert(node);

	// mark a compound type child of a address type parent hidden
	if (parent != NULL) {
		ValueNode* parentValueNode = parent->NodeChild()->Node();
		if (parentValueNode != NULL
			&& parentValueNode->GetType()->ResolveRawType(false)->Kind()
				== TYPE_ADDRESS
			&& nodeChildRawType->Kind() == TYPE_COMPOUND) {
			node->SetHidden(true);
		}
	}

	// notify table model listeners
	if (!node->IsHidden()) {
		TreeTablePath path;
		if (parent == NULL || _GetTreePath(parent, path))
			NotifyNodesAdded(path, childIndex, 1);
	}

	// if the node is hidden, add its children
	if (node->IsHidden())
		_AddChildNodes(nodeChild);

	return B_OK;
}
	void SetImageDebugInfo(ImageDebugInfo* imageDebugInfo)
	{
		// unset old functions
		if (fSourceFileIndices != NULL) {
			NotifyNodesRemoved(TreeTablePath(), 0, fSourceFileCount);

			delete[] fFunctions;
			fFunctions = NULL;
			fFunctionCount = 0;

			delete[] fSourceFileIndices;
			fSourceFileIndices = NULL;
			fSourceFileCount = 0;
		}

		fImageDebugInfo = imageDebugInfo;

		// set new functions
		if (fImageDebugInfo == NULL || fImageDebugInfo->CountFunctions() == 0)
			return;

		// create an array with the functions
		int32 functionCount = fImageDebugInfo->CountFunctions();
		FunctionInstance** functions
			= new(std::nothrow) FunctionInstance*[functionCount];
		if (functions == NULL)
			return;
		ArrayDeleter<FunctionInstance*> functionsDeleter(functions);

		for (int32 i = 0; i < functionCount; i++)
			functions[i] = fImageDebugInfo->FunctionAt(i);

		// sort them
		std::sort(functions, functions + functionCount, &_FunctionLess);

		// eliminate duplicate function instances
		if (functionCount > 0) {
			Function* previousFunction = functions[0]->GetFunction();
			int32 removed = 0;
			for (int32 i = 1; i < functionCount; i++) {
				if (functions[i]->GetFunction() == previousFunction) {
					removed++;
				} else {
					functions[i - removed] = functions[i];
					previousFunction = functions[i]->GetFunction();
				}
			}

			functionCount -= removed;
				// The array might now be too large, but we can live with that.
		}

		// count the different source files
		int32 sourceFileCount = 1;
		for (int32 i = 1; i < functionCount; i++) {
			if (_CompareSourceFileNames(functions[i - 1]->SourceFile(),
					functions[i]->SourceFile()) != 0) {
				sourceFileCount++;
			}
		}

		// allocate and init the indices for the source files
		fSourceFileIndices = new(std::nothrow) int32[sourceFileCount];
		if (fSourceFileIndices == NULL)
			return;
		fSourceFileCount = sourceFileCount;

		fSourceFileIndices[0] = 0;

		int32 sourceFileIndex = 1;
		for (int32 i = 1; i < functionCount; i++) {
			if (_CompareSourceFileNames(functions[i - 1]->SourceFile(),
					functions[i]->SourceFile()) != 0) {
				fSourceFileIndices[sourceFileIndex++] = i;
			}
		}

		fFunctions = functionsDeleter.Detach();
		fFunctionCount = functionCount;

		NotifyNodesAdded(TreeTablePath(), 0, fSourceFileCount);
	}