[Lldb-commits] [lldb] r243975 - [lldb-mi] Simplify MICmnMIOutOfBandRecord implementation.
Bruce Mitchener
bruce.mitchener at gmail.com
Tue Aug 4 06:12:31 PDT 2015
Author: brucem
Date: Tue Aug 4 08:12:31 2015
New Revision: 243975
URL: http://llvm.org/viewvc/llvm-project?rev=243975&view=rev
Log:
[lldb-mi] Simplify MICmnMIOutOfBandRecord implementation.
Summary:
* Remove extraneous members that were just storing temporary
values.
* OutOfBand_e parameters don't need to be const as they are
scalars.
* Switch from a map with CMIUtilString values to using a mapping
function. This uses a switch statement which will generate
a warning if a new result class is added.
* Make BuildAsyncRecord a static function rather than a private
member function so that we can construct the result text
correctly and avoid having extra stuff in the header.
Reviewers: abidh, ki.stfu
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D11751
Modified:
lldb/trunk/tools/lldb-mi/MICmnMIOutOfBandRecord.cpp
lldb/trunk/tools/lldb-mi/MICmnMIOutOfBandRecord.h
Modified: lldb/trunk/tools/lldb-mi/MICmnMIOutOfBandRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnMIOutOfBandRecord.cpp?rev=243975&r1=243974&r2=243975&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnMIOutOfBandRecord.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnMIOutOfBandRecord.cpp Tue Aug 4 08:12:31 2015
@@ -12,38 +12,98 @@
#include "MICmnResources.h"
// Instantiations:
-CMICmnMIOutOfBandRecord::MapOutOfBandToOutOfBandText_t ms_MapOutOfBandToOutOfBandText = {
- {CMICmnMIOutOfBandRecord::eOutOfBand_Running, "running"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, "stopped"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointCreated, "breakpoint-created"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointModified, "breakpoint-modified"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_Thread, ""}, // "" Meant to be empty
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupAdded, "thread-group-added"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupExited, "thread-group-exited"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupRemoved, "thread-group-removed"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupStarted, "thread-group-started"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadCreated, "thread-created"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadExited, "thread-exited"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadSelected, "thread-selected"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleLoaded, "library-loaded"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleUnloaded, "library-unloaded"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput, ""}};
-CMICmnMIOutOfBandRecord::MapOutOfBandToOutOfBandText_t ms_constMapAsyncRecordTextToToken = {
- {CMICmnMIOutOfBandRecord::eOutOfBand_Running, "*"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, "*"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointCreated, "="},
- {CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointModified, "="},
- {CMICmnMIOutOfBandRecord::eOutOfBand_Thread, "@"},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupAdded, "="},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupExited, "="},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupRemoved, "="},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupStarted, "="},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadCreated, "="},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadExited, "="},
- {CMICmnMIOutOfBandRecord::eOutOfBand_ThreadSelected, "="},
- {CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleLoaded, "="},
- {CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleUnloaded, "="},
- {CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput, "@"}};
+static const char *
+MapOutOfBandToText(CMICmnMIOutOfBandRecord::OutOfBand_e veType)
+{
+ switch (veType)
+ {
+ case CMICmnMIOutOfBandRecord::eOutOfBand_Running:
+ return "running";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_Stopped:
+ return "stopped";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointCreated:
+ return "breakpoint-created";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointModified:
+ return "breakpoint-modified";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_Thread:
+ return ""; // "" Meant to be empty
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupAdded:
+ return "thread-group-added";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupExited:
+ return "thread-group-exited";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupRemoved:
+ return "thread-group-removed";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupStarted:
+ return "thread-group-started";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadCreated:
+ return "thread-created";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadExited:
+ return "thread-exited";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadSelected:
+ return "thread-selected";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleLoaded:
+ return "library-loaded";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleUnloaded:
+ return "library-unloaded";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput:
+ return "";
+ }
+ assert(false && "unknown CMICmnMIOutofBandRecord::OutOfBand_e");
+ return NULL;
+}
+
+static const char *
+MapOutOfBandToToken(CMICmnMIOutOfBandRecord::OutOfBand_e veType)
+{
+ switch (veType)
+ {
+ case CMICmnMIOutOfBandRecord::eOutOfBand_Running:
+ return "*";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_Stopped:
+ return "*";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointCreated:
+ return "=";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointModified:
+ return "=";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_Thread:
+ return "@";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupAdded:
+ return "=";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupExited:
+ return "=";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupRemoved:
+ return "=";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupStarted:
+ return "=";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadCreated:
+ return "=";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadExited:
+ return "=";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_ThreadSelected:
+ return "=";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleLoaded:
+ return "=";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleUnloaded:
+ return "=";
+ case CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput:
+ return "@";
+ }
+ assert(false && "unknown CMICmnMIOutofBandRecord::OutOfBand_e");
+ return NULL;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Build the Out-of-band record's mandatory data part. The part up to the first
+// (additional) result i.e. async-record ==> "*" type.
+// Args: veType - (R) A MI Out-of-Band enumeration.
+// Return: CMIUtilString - The async record text.
+// Throws: None.
+//--
+static CMIUtilString
+BuildAsyncRecord(CMICmnMIOutOfBandRecord::OutOfBand_e veType)
+{
+ return CMIUtilString::Format("%s%s", MapOutOfBandToToken(veType), MapOutOfBandToText(veType));
+}
//++ ------------------------------------------------------------------------------------
// Details: CMICmnMIOutOfBandRecord constructor.
@@ -64,11 +124,9 @@ CMICmnMIOutOfBandRecord::CMICmnMIOutOfBa
// Return: None.
// Throws: None.
//--
-CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord(const OutOfBand_e veType)
- : m_eResultAsyncRecordClass(veType)
- , m_strAsyncRecord(MIRSRC(IDS_CMD_ERR_EVENT_HANDLED_BUT_NO_ACTION))
+CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord(OutOfBand_e veType)
+ : m_strAsyncRecord(BuildAsyncRecord(veType))
{
- BuildAsyncRecord();
}
//++ ------------------------------------------------------------------------------------
@@ -79,11 +137,9 @@ CMICmnMIOutOfBandRecord::CMICmnMIOutOfBa
// Return: None.
// Throws: None.
//--
-CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord(const OutOfBand_e veType, const CMICmnMIValueConst &vConst)
- : m_eResultAsyncRecordClass(veType)
- , m_strAsyncRecord(MIRSRC(IDS_CMD_ERR_EVENT_HANDLED_BUT_NO_ACTION))
+CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord(OutOfBand_e veType, const CMICmnMIValueConst &vConst)
+ : m_strAsyncRecord(BuildAsyncRecord(veType))
{
- BuildAsyncRecord();
m_strAsyncRecord += vConst.GetString();
}
@@ -95,13 +151,10 @@ CMICmnMIOutOfBandRecord::CMICmnMIOutOfBa
// Return: None.
// Throws: None.
//--
-CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord(const OutOfBand_e veType, const CMICmnMIValueResult &vResult)
- : m_eResultAsyncRecordClass(veType)
- , m_strAsyncRecord(MIRSRC(IDS_CMD_ERR_EVENT_HANDLED_BUT_NO_ACTION))
- , m_partResult(vResult)
+CMICmnMIOutOfBandRecord::CMICmnMIOutOfBandRecord(OutOfBand_e veType, const CMICmnMIValueResult &vResult)
+ : m_strAsyncRecord(BuildAsyncRecord(veType))
{
- BuildAsyncRecord();
- Add(m_partResult);
+ Add(vResult);
}
//++ ------------------------------------------------------------------------------------
@@ -132,23 +185,6 @@ CMICmnMIOutOfBandRecord::GetString() con
}
//++ ------------------------------------------------------------------------------------
-// Details: Build the Out-of-band record's mandatory data part. The part up to the first
-// (additional) result i.e. async-record ==> "*" type.
-// Type: Method.
-// Args: None.
-// Return: None.
-// Throws: None.
-//--
-void
-CMICmnMIOutOfBandRecord::BuildAsyncRecord()
-{
- const char *pFormat = "%s%s";
- const CMIUtilString &rStrAsyncRecord(ms_MapOutOfBandToOutOfBandText[m_eResultAsyncRecordClass]);
- const CMIUtilString &rStrToken(ms_constMapAsyncRecordTextToToken[m_eResultAsyncRecordClass]);
- m_strAsyncRecord = CMIUtilString::Format(pFormat, rStrToken.c_str(), rStrAsyncRecord.c_str());
-}
-
-//++ ------------------------------------------------------------------------------------
// Details: Add to *this Out-of-band record additional information.
// Type: Method.
// Args: vResult - (R) A MI result object.
Modified: lldb/trunk/tools/lldb-mi/MICmnMIOutOfBandRecord.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnMIOutOfBandRecord.h?rev=243975&r1=243974&r2=243975&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnMIOutOfBandRecord.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnMIOutOfBandRecord.h Tue Aug 4 08:12:31 2015
@@ -9,9 +9,6 @@
#pragma once
-// Third party headers:
-#include <map>
-
// In-house headers:
#include "MICmnBase.h"
#include "MIUtilString.h"
@@ -61,21 +58,15 @@ class CMICmnMIOutOfBandRecord : public C
eOutOfBand_ThreadSelected,
eOutOfBand_TargetModuleLoaded,
eOutOfBand_TargetModuleUnloaded,
- eOutOfBand_TargetStreamOutput,
- eOutOfBand_count // Always the last one
+ eOutOfBand_TargetStreamOutput
};
- // Typedefs:
- public:
- typedef std::map<OutOfBand_e, CMIUtilString> MapOutOfBandToOutOfBandText_t;
- typedef std::map<OutOfBand_e, CMIUtilString> MapOutOfBandToToken_t;
-
// Methods:
public:
/* ctor */ CMICmnMIOutOfBandRecord();
- /* ctor */ CMICmnMIOutOfBandRecord(const OutOfBand_e veType);
- /* ctor */ CMICmnMIOutOfBandRecord(const OutOfBand_e veType, const CMICmnMIValueConst &vConst);
- /* ctor */ CMICmnMIOutOfBandRecord(const OutOfBand_e veType, const CMICmnMIValueResult &vResult);
+ /* ctor */ CMICmnMIOutOfBandRecord(OutOfBand_e veType);
+ /* ctor */ CMICmnMIOutOfBandRecord(OutOfBand_e veType, const CMICmnMIValueConst &vConst);
+ /* ctor */ CMICmnMIOutOfBandRecord(OutOfBand_e veType, const CMICmnMIValueResult &vResult);
//
const CMIUtilString &GetString() const;
void Add(const CMICmnMIValueResult &vResult);
@@ -85,16 +76,7 @@ class CMICmnMIOutOfBandRecord : public C
// From CMICmnBase
/* dtor */ ~CMICmnMIOutOfBandRecord() override;
- // Methods:
- private:
- void BuildAsyncRecord();
-
// Attributes:
private:
- static MapOutOfBandToOutOfBandText_t ms_constMapOutOfBandToAsyncRecordText;
- static MapOutOfBandToToken_t ms_constMapOutOfBandTextToToken;
- //
- OutOfBand_e m_eResultAsyncRecordClass;
CMIUtilString m_strAsyncRecord; // Holds the text version of the result record to date
- CMICmnMIValueResult m_partResult;
};
More information about the lldb-commits
mailing list