From 8c9ad029027758304c48be603a560fd563e03457 Mon Sep 17 00:00:00 2001
From: Rene Gollent <anevilyak@gmail.com>
Date: Sun, 19 May 2013 11:50:11 -0400
Subject: [PATCH] Add "Cast to array" context option.
Implements a simple context shortcut allowing to cast a pointer variable
directly to a 10-element array of the type it points to. Resolves #9778.
---
src/apps/debugger/MessageCodes.h | 1 +
.../gui/team_window/VariablesView.cpp | 55 +++++++++++++++++++-
2 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/src/apps/debugger/MessageCodes.h b/src/apps/debugger/MessageCodes.h
index b5ca5e3..ae81129 100644
a
|
b
|
enum {
|
56 | 56 | MSG_INSPECTOR_WINDOW_CLOSED = 'irwc', |
57 | 57 | MSG_INSPECT_ADDRESS = 'isad', |
58 | 58 | MSG_SHOW_TYPECAST_NODE_PROMPT = 'stnp', |
| 59 | MSG_TYPECAST_TO_ARRAY = 'stta', |
59 | 60 | MSG_TYPECAST_NODE = 'tyno', |
60 | 61 | MSG_SHOW_WATCH_VARIABLE_PROMPT = 'swvp', |
61 | 62 | MSG_SHOW_CONTAINER_RANGE_PROMPT = 'scrp', |
diff --git a/src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp b/src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp
index 2b4b040..f699aac 100644
a
|
b
|
VariablesView::MessageReceived(BMessage* message)
|
1577 | 1577 | break; |
1578 | 1578 | } |
1579 | 1579 | |
| 1580 | BReference<Type> typeRef(type, true); |
1580 | 1581 | ValueNode* valueNode = NULL; |
1581 | 1582 | if (TypeHandlerRoster::Default()->CreateValueNode( |
1582 | | node->NodeChild(), type, valueNode) != B_OK) { |
| 1583 | node->NodeChild(), type, valueNode) != B_OK) { |
1583 | 1584 | break; |
1584 | 1585 | } |
1585 | 1586 | |
| 1587 | typeRef.Detach(); |
1586 | 1588 | node->NodeChild()->SetNode(valueNode); |
1587 | 1589 | node->SetCastedType(type); |
| 1590 | fVariableTableModel->NotifyNodeChanged(node); |
| 1591 | break; |
| 1592 | } |
| 1593 | case MSG_TYPECAST_TO_ARRAY: |
| 1594 | { |
| 1595 | ModelNode* node = NULL; |
| 1596 | if (message->FindPointer("node", reinterpret_cast<void **>(&node)) |
| 1597 | != B_OK) { |
| 1598 | break; |
| 1599 | } |
| 1600 | |
| 1601 | Type* baseType = dynamic_cast<AddressType*>(node->NodeChild() |
| 1602 | ->Node()->GetType())->BaseType(); |
| 1603 | ArrayType* arrayType = NULL; |
| 1604 | if (baseType->CreateDerivedArrayType(0, kMaxArrayElementCount, |
| 1605 | false, arrayType) != B_OK) { |
| 1606 | break; |
| 1607 | } |
| 1608 | |
| 1609 | AddressType* addressType = NULL; |
| 1610 | BReference<Type> typeRef(arrayType, true); |
| 1611 | if (arrayType->CreateDerivedAddressType(DERIVED_TYPE_POINTER, |
| 1612 | addressType) != B_OK) { |
| 1613 | break; |
| 1614 | } |
| 1615 | |
| 1616 | typeRef.Detach(); |
| 1617 | typeRef.SetTo(addressType, true); |
| 1618 | ValueNode* valueNode = NULL; |
| 1619 | if (TypeHandlerRoster::Default()->CreateValueNode( |
| 1620 | node->NodeChild(), addressType, valueNode) != B_OK) { |
| 1621 | break; |
| 1622 | } |
| 1623 | |
| 1624 | typeRef.Detach(); |
| 1625 | node->NodeChild()->SetNode(valueNode); |
| 1626 | node->SetCastedType(addressType); |
| 1627 | fVariableTableModel->NotifyNodeChanged(node); |
1588 | 1628 | break; |
1589 | 1629 | } |
1590 | 1630 | case MSG_SHOW_CONTAINER_RANGE_PROMPT: |
… |
… |
VariablesView::_GetContextActionsForNode(ModelNode* node,
|
1985 | 2025 | message->AddUInt64("address", location->PieceAt(0).address); |
1986 | 2026 | } |
1987 | 2027 | |
| 2028 | ValueNode* valueNode = node->NodeChild()->Node(); |
| 2029 | |
| 2030 | if (valueNode != NULL) { |
| 2031 | AddressType* type = dynamic_cast<AddressType*>(valueNode->GetType()); |
| 2032 | if (type != NULL && type->BaseType() != NULL) { |
| 2033 | result = _AddContextAction("Cast to array", MSG_TYPECAST_TO_ARRAY, |
| 2034 | actions, message); |
| 2035 | if (result != B_OK) |
| 2036 | return result; |
| 2037 | message->AddPointer("node", node); |
| 2038 | } |
| 2039 | } |
1988 | 2040 | |
1989 | 2041 | result = _AddContextAction("Cast as" B_UTF8_ELLIPSIS, |
1990 | 2042 | MSG_SHOW_TYPECAST_NODE_PROMPT, actions, message); |
… |
… |
VariablesView::_GetContextActionsForNode(ModelNode* node,
|
1996 | 2048 | if (result != B_OK) |
1997 | 2049 | return result; |
1998 | 2050 | |
1999 | | ValueNode* valueNode = node->NodeChild()->Node(); |
2000 | 2051 | if (valueNode == NULL) |
2001 | 2052 | return B_OK; |
2002 | 2053 | |