[Lldb-commits] [lldb] r242769 - [lldb-mi] Simplify MICmnMIResultRecord implementation.
Bruce Mitchener
bruce.mitchener at gmail.com
Tue Jul 21 04:30:39 PDT 2015
Author: brucem
Date: Tue Jul 21 06:30:39 2015
New Revision: 242769
URL: http://llvm.org/viewvc/llvm-project?rev=242769&view=rev
Log:
[lldb-mi] Simplify MICmnMIResultRecord implementation.
Summary:
* Remove extraneous members that were just storing temporary
values.
* ResultClass_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 BuildRecordResult 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.
* Don't need (void) parameter lists in C++.
Reviewers: abidh, ki.stfu, domipheus
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D11052
Modified:
lldb/trunk/tools/lldb-mi/MICmnMIResultRecord.cpp
lldb/trunk/tools/lldb-mi/MICmnMIResultRecord.h
Modified: lldb/trunk/tools/lldb-mi/MICmnMIResultRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnMIResultRecord.cpp?rev=242769&r1=242768&r2=242769&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnMIResultRecord.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnMIResultRecord.cpp Tue Jul 21 06:30:39 2015
@@ -11,14 +11,46 @@
#include "MICmnMIResultRecord.h"
#include "MICmnResources.h"
-// Instantiations:
-CMICmnMIResultRecord::MapResultClassToResultClassText_t ms_MapResultClassToResultClassText = {
- {CMICmnMIResultRecord::eResultClass_Done, "done"},
- {CMICmnMIResultRecord::eResultClass_Running, "running"},
- {CMICmnMIResultRecord::eResultClass_Connected, "connected"},
- {CMICmnMIResultRecord::eResultClass_Error, "error"},
- {CMICmnMIResultRecord::eResultClass_Exit, "exit"}};
-const CMIUtilString CMICmnMIResultRecord::ms_constStrResultRecordHat("^");
+//++ ------------------------------------------------------------------------------------
+// Details: Map a result class to the corresponding string.
+// Args: veType - (R) A MI result class enumeration.
+// Return: const char* - The string corresponding to the result class.
+// Throws: None.
+//--
+static const char*
+MapResultClassToResultClassText(CMICmnMIResultRecord::ResultClass_e veType)
+{
+ switch (veType)
+ {
+ case CMICmnMIResultRecord::eResultClass_Done:
+ return "done";
+ case CMICmnMIResultRecord::eResultClass_Running:
+ return "running";
+ case CMICmnMIResultRecord::eResultClass_Connected:
+ return "connected";
+ case CMICmnMIResultRecord::eResultClass_Error:
+ return "error";
+ case CMICmnMIResultRecord::eResultClass_Exit:
+ return "exit";
+ }
+ assert(false && "unknown CMICmnMIResultRecord::ResultClass_e");
+ return NULL;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Build the result record's mandatory data part. The part up to the first
+// (additional) result i.e. result-record ==> [ token ] "^" result-class.
+// Args: vrToken - (R) The command's transaction ID or token.
+// veType - (R) A MI result class enumeration.
+// Return: CMIUtilString & - MI result record mandatory data
+// Throws: None.
+//--
+static const CMIUtilString
+BuildResultRecord(const CMIUtilString &vrToken, CMICmnMIResultRecord::ResultClass_e veType)
+{
+ const char *pStrResultRecord = MapResultClassToResultClassText(veType);
+ return CMIUtilString::Format("%s^%s", vrToken.c_str(), pStrResultRecord);
+}
//++ ------------------------------------------------------------------------------------
// Details: CMICmnMIResultRecord constructor.
@@ -27,7 +59,7 @@ const CMIUtilString CMICmnMIResultRecord
// Return: None.
// Throws: None.
//--
-CMICmnMIResultRecord::CMICmnMIResultRecord(void)
+CMICmnMIResultRecord::CMICmnMIResultRecord()
: m_strResultRecord(MIRSRC(IDS_CMD_ERR_CMD_RUN_BUT_NO_ACTION))
{
}
@@ -40,12 +72,9 @@ CMICmnMIResultRecord::CMICmnMIResultReco
// Return: None.
// Throws: None.
//--
-CMICmnMIResultRecord::CMICmnMIResultRecord(const CMIUtilString &vrToken, const ResultClass_e veType)
- : m_strResultRecordToken(vrToken)
- , m_eResultRecordResultClass(veType)
- , m_strResultRecord(MIRSRC(IDS_CMD_ERR_CMD_RUN_BUT_NO_ACTION))
+CMICmnMIResultRecord::CMICmnMIResultRecord(const CMIUtilString &vrToken, ResultClass_e veType)
+ : m_strResultRecord(BuildResultRecord(vrToken, veType))
{
- BuildResultRecord();
}
//++ ------------------------------------------------------------------------------------
@@ -57,14 +86,10 @@ CMICmnMIResultRecord::CMICmnMIResultReco
// Return: None.
// Throws: None.
//--
-CMICmnMIResultRecord::CMICmnMIResultRecord(const CMIUtilString &vrToken, const ResultClass_e veType, const CMICmnMIValueResult &vValue)
- : m_strResultRecordToken(vrToken)
- , m_eResultRecordResultClass(veType)
- , m_strResultRecord(MIRSRC(IDS_CMD_ERR_CMD_RUN_BUT_NO_ACTION))
- , m_partResult(vValue)
+CMICmnMIResultRecord::CMICmnMIResultRecord(const CMIUtilString &vrToken, ResultClass_e veType, const CMICmnMIValueResult &vValue)
+ : m_strResultRecord(BuildResultRecord(vrToken, veType))
{
- BuildResultRecord();
- Add(m_partResult);
+ Add(vValue);
}
//++ ------------------------------------------------------------------------------------
@@ -74,7 +99,7 @@ CMICmnMIResultRecord::CMICmnMIResultReco
// Return: None.
// Throws: None.
//--
-CMICmnMIResultRecord::~CMICmnMIResultRecord(void)
+CMICmnMIResultRecord::~CMICmnMIResultRecord()
{
}
@@ -89,32 +114,12 @@ CMICmnMIResultRecord::~CMICmnMIResultRec
// Throws: None.
//--
const CMIUtilString &
-CMICmnMIResultRecord::GetString(void) const
+CMICmnMIResultRecord::GetString() const
{
return m_strResultRecord;
}
//++ ------------------------------------------------------------------------------------
-// Details: Build the result record's mandatory data part. The part up to the first
-// (additional) result i.e. result-record ==> [ token ] "^" result-class.
-// Type: Method.
-// Args: None.
-// Return: MIstatus::success - Functional succeeded.
-// MIstatus::failure - Functional failed.
-// Throws: None.
-//--
-bool
-CMICmnMIResultRecord::BuildResultRecord(void)
-{
- const char *pFormat = "%s%s%s";
- const CMIUtilString &rStrResultRecord(ms_MapResultClassToResultClassText[m_eResultRecordResultClass]);
- m_strResultRecord =
- CMIUtilString::Format(pFormat, m_strResultRecordToken.c_str(), ms_constStrResultRecordHat.c_str(), rStrResultRecord.c_str());
-
- return MIstatus::success;
-}
-
-//++ ------------------------------------------------------------------------------------
// Details: Add to *this result record additional information.
// Type: Method.
// Args: vMIValue - (R) A MI value derived object.
Modified: lldb/trunk/tools/lldb-mi/MICmnMIResultRecord.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnMIResultRecord.h?rev=242769&r1=242768&r2=242769&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnMIResultRecord.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnMIResultRecord.h Tue Jul 21 06:30:39 2015
@@ -9,9 +9,6 @@
#pragma once
-// Third party headers:
-#include <map>
-
// In-house headers:
#include "MICmnBase.h"
#include "MIUtilString.h"
@@ -56,39 +53,24 @@ class CMICmnMIResultRecord : public CMIC
eResultClass_Running,
eResultClass_Connected,
eResultClass_Error,
- eResultClass_Exit,
- eResultClass_count // Always the last one
+ eResultClass_Exit
};
- // Typedefs:
- public:
- typedef std::map<ResultClass_e, CMIUtilString> MapResultClassToResultClassText_t;
-
// Methods:
public:
- /* ctor */ CMICmnMIResultRecord(void);
- /* ctor */ CMICmnMIResultRecord(const CMIUtilString &vrToken, const ResultClass_e veType);
- /* ctor */ CMICmnMIResultRecord(const CMIUtilString &vrToken, const ResultClass_e veType, const CMICmnMIValueResult &vValue);
+ /* ctor */ CMICmnMIResultRecord();
+ /* ctor */ CMICmnMIResultRecord(const CMIUtilString &vrToken, ResultClass_e veType);
+ /* ctor */ CMICmnMIResultRecord(const CMIUtilString &vrToken, ResultClass_e veType, const CMICmnMIValueResult &vValue);
//
- const CMIUtilString &GetString(void) const;
+ const CMIUtilString &GetString() const;
bool Add(const CMICmnMIValue &vMIValue);
// Overridden:
public:
// From CMICmnBase
- /* dtor */ ~CMICmnMIResultRecord(void) override;
-
- // Methods:
- private:
- bool BuildResultRecord(void);
+ /* dtor */ ~CMICmnMIResultRecord() override;
// Attributes:
private:
- static const CMIUtilString ms_constStrResultRecordHat;
- static MapResultClassToResultClassText_t ms_constMapResultClassToResultClassText;
- //
- CMIUtilString m_strResultRecordToken;
- ResultClass_e m_eResultRecordResultClass;
CMIUtilString m_strResultRecord; // Holds the text version of the result record to date
- CMICmnMIValueResult m_partResult;
};
More information about the lldb-commits
mailing list