[Lldb-commits] [lldb] r139444 - in /lldb/trunk: include/lldb/Utility/Utils.h lldb.xcodeproj/project.pbxproj source/Interpreter/OptionGroupArchitecture.cpp source/Interpreter/OptionGroupFormat.cpp source/Interpreter/OptionGroupOutputFile.cpp source/Interpreter/OptionGroupPlatform.cpp source/Interpreter/OptionGroupUUID.cpp source/Interpreter/OptionGroupValueObjectDisplay.cpp source/Interpreter/OptionGroupWatchpoint.cpp

Johnny Chen johnny.chen at apple.com
Fri Sep 9 17:48:33 PDT 2011


Author: johnny
Date: Fri Sep  9 19:48:33 2011
New Revision: 139444

URL: http://llvm.org/viewvc/llvm-project?rev=139444&view=rev
Log:
Refactoring: replace a bunch of static array size computation or hardcoded constant
with a template function 'arraysize(static_array)', defined in Utils.h.

Added:
    lldb/trunk/include/lldb/Utility/Utils.h
Modified:
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Interpreter/OptionGroupArchitecture.cpp
    lldb/trunk/source/Interpreter/OptionGroupFormat.cpp
    lldb/trunk/source/Interpreter/OptionGroupOutputFile.cpp
    lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp
    lldb/trunk/source/Interpreter/OptionGroupUUID.cpp
    lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp
    lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp

Added: lldb/trunk/include/lldb/Utility/Utils.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Utils.h?rev=139444&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Utility/Utils.h (added)
+++ lldb/trunk/include/lldb/Utility/Utils.h Fri Sep  9 19:48:33 2011
@@ -0,0 +1,19 @@
+//===-- Utils.h -------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef utility_Utils_h_
+#define utility_Utils_h_
+
+namespace lldb_private {
+
+template <typename T, unsigned size>
+inline unsigned arraysize(T (&v)[size]) { return size; }
+
+} // namespace lldb_private
+#endif // utility_Utils

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=139444&r1=139443&r2=139444&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Fri Sep  9 19:48:33 2011
@@ -1298,6 +1298,7 @@
 		B23DD24F12EDFAC1000C3894 /* ARMUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ARMUtils.h; path = Utility/ARMUtils.h; sourceTree = "<group>"; };
 		B2462246141AD37D00F3D409 /* OptionGroupWatchpoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OptionGroupWatchpoint.cpp; path = source/Interpreter/OptionGroupWatchpoint.cpp; sourceTree = "<group>"; };
 		B2462248141AD39B00F3D409 /* OptionGroupWatchpoint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = OptionGroupWatchpoint.h; path = include/lldb/Interpreter/OptionGroupWatchpoint.h; sourceTree = "<group>"; };
+		B2462249141AE62200F3D409 /* Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Utils.h; path = include/lldb/Utility/Utils.h; sourceTree = "<group>"; };
 		B27318411416AC12006039C8 /* WatchpointLocationList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WatchpointLocationList.cpp; path = source/Breakpoint/WatchpointLocationList.cpp; sourceTree = "<group>"; };
 		B27318431416AC43006039C8 /* WatchpointLocationList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WatchpointLocationList.h; path = include/lldb/Breakpoint/WatchpointLocationList.h; sourceTree = "<group>"; };
 		B28058A0139988B0002D96D0 /* InferiorCallPOSIX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = InferiorCallPOSIX.cpp; path = Utility/InferiorCallPOSIX.cpp; sourceTree = "<group>"; };
@@ -1841,6 +1842,7 @@
 				2682F16A115EDA0D00CCFF99 /* PseudoTerminal.cpp */,
 				94031A9F13CF5B3D00DCFF3C /* PriorityPointerPair.h */,
 				94EBAC8313D9EE26009BA64E /* PythonPointer.h */,
+				B2462249141AE62200F3D409 /* Utils.h */,
 			);
 			name = Utility;
 			sourceTree = "<group>";

Modified: lldb/trunk/source/Interpreter/OptionGroupArchitecture.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupArchitecture.cpp?rev=139444&r1=139443&r2=139444&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupArchitecture.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupArchitecture.cpp Fri Sep  9 19:48:33 2011
@@ -13,6 +13,7 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
+#include "lldb/Utility/Utils.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -29,15 +30,13 @@
 static OptionDefinition
 g_option_table[] =
 {
-{ LLDB_OPT_SET_1 , false, "arch"    , 'a', required_argument, NULL, 0, eArgTypeArchitecture , "Specify the architecture for the target."},
+    { LLDB_OPT_SET_1 , false, "arch"    , 'a', required_argument, NULL, 0, eArgTypeArchitecture , "Specify the architecture for the target."},
 };
 
-const uint32_t k_num_file_options = sizeof(g_option_table)/sizeof(OptionDefinition);
-
 uint32_t
 OptionGroupArchitecture::GetNumDefinitions ()
 {
-    return k_num_file_options;
+    return arraysize(g_option_table);
 }
 
 const OptionDefinition *

Modified: lldb/trunk/source/Interpreter/OptionGroupFormat.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupFormat.cpp?rev=139444&r1=139443&r2=139444&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupFormat.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupFormat.cpp Fri Sep  9 19:48:33 2011
@@ -13,6 +13,7 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
+#include "lldb/Utility/Utils.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -35,14 +36,13 @@
 static OptionDefinition 
 g_option_table[] =
 {
-{ LLDB_OPT_SET_1 , false, "format", 'f', required_argument, NULL, 0, eArgTypeFormat , "Specify a format to be used for display."},
+    { LLDB_OPT_SET_1 , false, "format", 'f', required_argument, NULL, 0, eArgTypeFormat , "Specify a format to be used for display."},
 };
-const uint32_t k_num_file_options = sizeof(g_option_table)/sizeof(OptionDefinition);
 
 uint32_t
 OptionGroupFormat::GetNumDefinitions ()
 {
-    return k_num_file_options;
+    return arraysize(g_option_table);
 }
 
 const OptionDefinition *

Modified: lldb/trunk/source/Interpreter/OptionGroupOutputFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupOutputFile.cpp?rev=139444&r1=139443&r2=139444&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupOutputFile.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupOutputFile.cpp Fri Sep  9 19:48:33 2011
@@ -13,6 +13,7 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
+#include "lldb/Utility/Utils.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -30,16 +31,14 @@
 static OptionDefinition
 g_option_table[] =
 {
-{ LLDB_OPT_SET_1 , false, "outfile", 'o', required_argument, NULL, 0, eArgTypePath , "Specify a path for capturing command output."},
-{ LLDB_OPT_SET_1 , false, "append-outfile" , 'A', no_argument, NULL, 0, eArgTypeNone , "Append to the the file specified with '--outfile <path>'."},
+    { LLDB_OPT_SET_1 , false, "outfile", 'o', required_argument, NULL, 0, eArgTypePath , "Specify a path for capturing command output."},
+    { LLDB_OPT_SET_1 , false, "append-outfile" , 'A', no_argument, NULL, 0, eArgTypeNone , "Append to the the file specified with '--outfile <path>'."},
 };
 
-const uint32_t k_num_file_options = sizeof(g_option_table)/sizeof(OptionDefinition);
-
 uint32_t
 OptionGroupOutputFile::GetNumDefinitions ()
 {
-    return k_num_file_options;
+    return arraysize(g_option_table);
 }
 
 const OptionDefinition *

Modified: lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp?rev=139444&r1=139443&r2=139444&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp Fri Sep  9 19:48:33 2011
@@ -15,6 +15,7 @@
 // Project includes
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Target/Platform.h"
+#include "lldb/Utility/Utils.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -67,8 +68,6 @@
     { LLDB_OPT_SET_ALL, false, "sysroot" , 's', required_argument, NULL, 0, eArgTypeFilename, "Specify the SDK root directory that contains a root of all remote system files." }
 };
 
-static const uint32_t k_option_table_size = sizeof(g_option_table)/sizeof (OptionDefinition);
-
 const OptionDefinition*
 OptionGroupPlatform::GetDefinitions ()
 {
@@ -81,8 +80,8 @@
 OptionGroupPlatform::GetNumDefinitions ()
 {
     if (m_include_platform_option)
-        return k_option_table_size;
-    return k_option_table_size - 1;
+        return arraysize(g_option_table);
+    return arraysize(g_option_table) - 1;
 }
 
 

Modified: lldb/trunk/source/Interpreter/OptionGroupUUID.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupUUID.cpp?rev=139444&r1=139443&r2=139444&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupUUID.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupUUID.cpp Fri Sep  9 19:48:33 2011
@@ -13,6 +13,7 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
+#include "lldb/Utility/Utils.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -29,15 +30,13 @@
 static OptionDefinition
 g_option_table[] =
 {
-{ LLDB_OPT_SET_1 , false, "uuid", 'u', required_argument, NULL, 0, eArgTypeNone, "A module UUID value."},
+    { LLDB_OPT_SET_1 , false, "uuid", 'u', required_argument, NULL, 0, eArgTypeNone, "A module UUID value."},
 };
 
-const uint32_t k_num_file_options = sizeof(g_option_table)/sizeof(OptionDefinition);
-
 uint32_t
 OptionGroupUUID::GetNumDefinitions ()
 {
-    return k_num_file_options;
+    return arraysize(g_option_table);
 }
 
 const OptionDefinition *

Modified: lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp?rev=139444&r1=139443&r2=139444&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp Fri Sep  9 19:48:33 2011
@@ -15,6 +15,7 @@
 // Project includes
 #include "lldb/Target/Target.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Utility/Utils.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -45,12 +46,10 @@
     { 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
 };
 
-const uint32_t k_num_file_options = sizeof(g_option_table)/sizeof(OptionDefinition);
-
 uint32_t
 OptionGroupValueObjectDisplay::GetNumDefinitions ()
 {
-    return k_num_file_options;
+    return arraysize(g_option_table);
 }
 
 const OptionDefinition *

Modified: lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp?rev=139444&r1=139443&r2=139444&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp Fri Sep  9 19:48:33 2011
@@ -15,6 +15,7 @@
 // Project includes
 #include "lldb/lldb-enumerations.h"
 #include "lldb/Interpreter/Args.h"
+#include "lldb/Utility/Utils.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -84,7 +85,5 @@
 uint32_t
 OptionGroupWatchpoint::GetNumDefinitions ()
 {
-    return 1;
+    return arraysize(g_option_table);
 }
-
-





More information about the lldb-commits mailing list