about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRicho Healey <richo@psych0tik.net>2014-11-20 17:24:18 -0800
committerRicho Healey <richo@psych0tik.net>2014-11-21 11:20:02 -0800
commit7191cd92c1f0ef3d1373e9b494575cb336b5e4c7 (patch)
tree29b86065d5ba827208b68662c905595b895ed713
parent0ab01048d5c3bed1f3e8e1d00a33d8d597fc449e (diff)
lldb: Clean up struct printing
-rw-r--r--src/etc/lldb_rust_formatters.py36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/etc/lldb_rust_formatters.py b/src/etc/lldb_rust_formatters.py
index dba9ca6153f..642235ed4e3 100644
--- a/src/etc/lldb_rust_formatters.py
+++ b/src/etc/lldb_rust_formatters.py
@@ -71,39 +71,33 @@ def print_struct_val_starting_from(field_start_index, val, internal_dict):
   t = val.GetType()
   has_field_names = type_has_field_names(t)
   type_name = extract_type_name(t.GetName())
-  output = ""
-
-  if not type_name.startswith("("):
-    # this is a tuple, so don't print the type name
-    output += type_name
 
   if has_field_names:
-    output += " { \n"
+      template = "%(type_name)s {\n%(body)s\n}"
+      separator = ", \n"
   else:
-    output += "("
+      template = "%(type_name)s(%(body)s)"
+      separator = ", "
+
+  if type_name.startswith("("):
+    # this is a tuple, so don't print the type name
+    type_name = ""
 
   num_children = val.num_children
 
-  for child_index in range(field_start_index, num_children):
+  def render_child(child_index):
+    this = ""
     if has_field_names:
       field_name = t.GetFieldAtIndex(child_index).GetName()
-      output += field_name + ": "
+      this += field_name + ": "
 
     field_val = val.GetChildAtIndex(child_index)
-    output += print_val(field_val, internal_dict)
+    return this + print_val(field_val, internal_dict)
 
-    if child_index != num_children - 1:
-      output += ", "
+  body = separator.join([render_child(idx) for idx in range(field_start_index, num_children)])
 
-    if has_field_names:
-      output += "\n"
-
-  if has_field_names:
-    output += "}"
-  else:
-    output += ")"
-
-  return output
+  return template % {"type_name": type_name,
+                     "body": body}
 
 
 def print_enum_val(val, internal_dict):