Ticket #9778: 0001-Add-Cast-to-array-context-option.patch

File 0001-Add-Cast-to-array-context-option.patch, 3.8 KB (added by anevilyak, 11 years ago)
  • src/apps/debugger/MessageCodes.h

    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 {  
    5656    MSG_INSPECTOR_WINDOW_CLOSED                 = 'irwc',
    5757    MSG_INSPECT_ADDRESS                         = 'isad',
    5858    MSG_SHOW_TYPECAST_NODE_PROMPT               = 'stnp',
     59    MSG_TYPECAST_TO_ARRAY                       = 'stta',
    5960    MSG_TYPECAST_NODE                           = 'tyno',
    6061    MSG_SHOW_WATCH_VARIABLE_PROMPT              = 'swvp',
    6162    MSG_SHOW_CONTAINER_RANGE_PROMPT             = 'scrp',
  • src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp

    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)  
    15771577                break;
    15781578            }
    15791579
     1580            BReference<Type> typeRef(type, true);
    15801581            ValueNode* valueNode = NULL;
    15811582            if (TypeHandlerRoster::Default()->CreateValueNode(
    1582                 node->NodeChild(), type, valueNode) != B_OK) {
     1583                    node->NodeChild(), type, valueNode) != B_OK) {
    15831584                break;
    15841585            }
    15851586
     1587            typeRef.Detach();
    15861588            node->NodeChild()->SetNode(valueNode);
    15871589            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);
    15881628            break;
    15891629        }
    15901630        case MSG_SHOW_CONTAINER_RANGE_PROMPT:
    VariablesView::_GetContextActionsForNode(ModelNode* node,  
    19852025        message->AddUInt64("address", location->PieceAt(0).address);
    19862026    }
    19872027
     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    }
    19882040
    19892041    result = _AddContextAction("Cast as" B_UTF8_ELLIPSIS,
    19902042        MSG_SHOW_TYPECAST_NODE_PROMPT, actions, message);
    VariablesView::_GetContextActionsForNode(ModelNode* node,  
    19962048    if (result != B_OK)
    19972049        return result;
    19982050
    1999     ValueNode* valueNode = node->NodeChild()->Node();
    20002051    if (valueNode == NULL)
    20012052        return B_OK;
    20022053