From b9c1b51e45b845debb76d8658edabca70ca56079 Mon Sep 17 00:00:00 2001 From: Kate Stone Date: Tue, 6 Sep 2016 20:57:50 +0000 Subject: =?UTF-8?q?***=20This=20commit=20represents=20a=20complete=20refor?= =?UTF-8?q?matting=20of=20the=20LLDB=20source=20code=20***=20to=20conform?= =?UTF-8?q?=20to=20clang-format=E2=80=99s=20LLVM=20style.=20=20This=20kind?= =?UTF-8?q?=20of=20mass=20change=20has=20***=20two=20obvious=20implication?= =?UTF-8?q?s:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751 --- lldb/scripts/Python/modify-python-lldb.py | 118 +++++++++++++++++------------- 1 file changed, 66 insertions(+), 52 deletions(-) (limited to 'lldb/scripts/Python/modify-python-lldb.py') diff --git a/lldb/scripts/Python/modify-python-lldb.py b/lldb/scripts/Python/modify-python-lldb.py index 56323d6..cb911ee 100644 --- a/lldb/scripts/Python/modify-python-lldb.py +++ b/lldb/scripts/Python/modify-python-lldb.py @@ -22,7 +22,8 @@ # # System modules -import sys, re +import sys +import re if sys.version_info.major >= 3: import io as StringIO else: @@ -45,7 +46,7 @@ else: # # Version string -# +# version_line = "swig_version = %s" # @@ -60,6 +61,7 @@ doxygen_comment_start = re.compile("^\s*(/// ?)") # When bracketed by the lines, the CLEANUP_DOCSTRING state (see below) is ON. toggle_docstring_cleanup_line = ' """' + def char_to_str_xform(line): """This transforms the 'char', i.e, 'char *' to 'str', Python string.""" line = line.replace(' char', ' str') @@ -74,7 +76,9 @@ def char_to_str_xform(line): # TWO_SPACES = ' ' * 2 EIGHT_SPACES = ' ' * 8 -one_liner_docstring_pattern = re.compile('^(%s|%s)""".*"""$' % (TWO_SPACES, EIGHT_SPACES)) +one_liner_docstring_pattern = re.compile( + '^(%s|%s)""".*"""$' % + (TWO_SPACES, EIGHT_SPACES)) # # lldb_helpers and lldb_iter() should appear before our first SB* class definition. @@ -226,47 +230,48 @@ symbol_in_section_iter_def = ''' # # This dictionary defines a mapping from classname to (getsize, getelem) tuple. # -d = { 'SBBreakpoint': ('GetNumLocations', 'GetLocationAtIndex'), - 'SBCompileUnit': ('GetNumLineEntries', 'GetLineEntryAtIndex'), - 'SBDebugger': ('GetNumTargets', 'GetTargetAtIndex'), - 'SBModule': ('GetNumSymbols', 'GetSymbolAtIndex'), - 'SBProcess': ('GetNumThreads', 'GetThreadAtIndex'), - 'SBSection': ('GetNumSubSections', 'GetSubSectionAtIndex'), - 'SBThread': ('GetNumFrames', 'GetFrameAtIndex'), - - 'SBInstructionList': ('GetSize', 'GetInstructionAtIndex'), - 'SBStringList': ('GetSize', 'GetStringAtIndex',), - 'SBSymbolContextList': ('GetSize', 'GetContextAtIndex'), - 'SBTypeList': ('GetSize', 'GetTypeAtIndex'), - 'SBValueList': ('GetSize', 'GetValueAtIndex'), - - 'SBType': ('GetNumberChildren', 'GetChildAtIndex'), - 'SBValue': ('GetNumChildren', 'GetChildAtIndex'), - - # SBTarget needs special processing, see below. - 'SBTarget': {'module': ('GetNumModules', 'GetModuleAtIndex'), - 'breakpoint': ('GetNumBreakpoints', 'GetBreakpointAtIndex'), - 'watchpoint': ('GetNumWatchpoints', 'GetWatchpointAtIndex') - }, - - # SBModule has an additional section_iter(), see below. - 'SBModule-section': ('GetNumSections', 'GetSectionAtIndex'), - # And compile_unit_iter(). - 'SBModule-compile-unit': ('GetNumCompileUnits', 'GetCompileUnitAtIndex'), - # As well as symbol_in_section_iter(). - 'SBModule-symbol-in-section': symbol_in_section_iter_def - } +d = {'SBBreakpoint': ('GetNumLocations', 'GetLocationAtIndex'), + 'SBCompileUnit': ('GetNumLineEntries', 'GetLineEntryAtIndex'), + 'SBDebugger': ('GetNumTargets', 'GetTargetAtIndex'), + 'SBModule': ('GetNumSymbols', 'GetSymbolAtIndex'), + 'SBProcess': ('GetNumThreads', 'GetThreadAtIndex'), + 'SBSection': ('GetNumSubSections', 'GetSubSectionAtIndex'), + 'SBThread': ('GetNumFrames', 'GetFrameAtIndex'), + + 'SBInstructionList': ('GetSize', 'GetInstructionAtIndex'), + 'SBStringList': ('GetSize', 'GetStringAtIndex',), + 'SBSymbolContextList': ('GetSize', 'GetContextAtIndex'), + 'SBTypeList': ('GetSize', 'GetTypeAtIndex'), + 'SBValueList': ('GetSize', 'GetValueAtIndex'), + + 'SBType': ('GetNumberChildren', 'GetChildAtIndex'), + 'SBValue': ('GetNumChildren', 'GetChildAtIndex'), + + # SBTarget needs special processing, see below. + 'SBTarget': {'module': ('GetNumModules', 'GetModuleAtIndex'), + 'breakpoint': ('GetNumBreakpoints', 'GetBreakpointAtIndex'), + 'watchpoint': ('GetNumWatchpoints', 'GetWatchpointAtIndex') + }, + + # SBModule has an additional section_iter(), see below. + 'SBModule-section': ('GetNumSections', 'GetSectionAtIndex'), + # And compile_unit_iter(). + 'SBModule-compile-unit': ('GetNumCompileUnits', 'GetCompileUnitAtIndex'), + # As well as symbol_in_section_iter(). + 'SBModule-symbol-in-section': symbol_in_section_iter_def + } # # This dictionary defines a mapping from classname to equality method name(s). # -e = { 'SBAddress': ['GetFileAddress', 'GetModule'], - 'SBBreakpoint': ['GetID'], - 'SBWatchpoint': ['GetID'], - 'SBFileSpec': ['GetFilename', 'GetDirectory'], - 'SBModule': ['GetFileSpec', 'GetUUIDString'], - 'SBType': ['GetByteSize', 'GetName'] - } +e = {'SBAddress': ['GetFileAddress', 'GetModule'], + 'SBBreakpoint': ['GetID'], + 'SBWatchpoint': ['GetID'], + 'SBFileSpec': ['GetFilename', 'GetDirectory'], + 'SBModule': ['GetFileSpec', 'GetUUIDString'], + 'SBType': ['GetByteSize', 'GetName'] + } + def list_to_frag(list): """Transform a list to equality program fragment. @@ -284,30 +289,37 @@ def list_to_frag(list): frag.write("self.{0}() == other.{0}()".format(list[i])) return frag.getvalue() + class NewContent(StringIO.StringIO): """Simple facade to keep track of the previous line to be committed.""" + def __init__(self): StringIO.StringIO.__init__(self) self.prev_line = None + def add_line(self, a_line): """Add a line to the content, if there is a previous line, commit it.""" - if self.prev_line != None: + if self.prev_line is not None: self.write(self.prev_line + "\n") self.prev_line = a_line + def del_line(self): """Forget about the previous line, do not commit it.""" self.prev_line = None + def del_blank_line(self): """Forget about the previous line if it is a blank line.""" - if self.prev_line != None and not self.prev_line.strip(): + if self.prev_line is not None and not self.prev_line.strip(): self.prev_line = None + def finish(self): """Call this when you're finished with populating content.""" - if self.prev_line != None: + if self.prev_line is not None: self.write(self.prev_line + "\n") self.prev_line = None -# The new content will have the iteration protocol defined for our lldb objects. +# The new content will have the iteration protocol defined for our lldb +# objects. new_content = NewContent() with open(output_name, 'r') as f_in: @@ -333,7 +345,7 @@ DEFINING_EQUALITY = 4 CLEANUP_DOCSTRING = 8 # The lldb_iter_def only needs to be inserted once. -lldb_iter_defined = False; +lldb_iter_defined = False # Our FSM begins its life in the NORMAL state, and transitions to the # DEFINING_ITERATOR and/or DEFINING_EQUALITY state whenever it encounters the @@ -361,7 +373,7 @@ for line in content.splitlines(): # # If ' """' is the sole line, prepare to transition to the # CLEANUP_DOCSTRING state or out of it. - + if line == toggle_docstring_cleanup_line: if state & CLEANUP_DOCSTRING: # Special handling of the trailing blank line right before the '"""' @@ -379,7 +391,8 @@ for line in content.splitlines(): v = match.group(1) swig_version_tuple = tuple(map(int, (v.split(".")))) elif not line.startswith('#'): - # This is the first non-comment line after the header. Inject the version + # This is the first non-comment line after the header. Inject the + # version new_line = version_line % str(swig_version_tuple) new_content.add_line(new_line) state = NORMAL @@ -424,11 +437,13 @@ for line in content.splitlines(): new_content.add_line(eq_def % (cls, list_to_frag(e[cls]))) new_content.add_line(ne_def) - # SBModule has extra SBSection, SBCompileUnit iterators and symbol_in_section_iter()! + # SBModule has extra SBSection, SBCompileUnit iterators and + # symbol_in_section_iter()! if cls == "SBModule": - new_content.add_line(section_iter % d[cls+'-section']) - new_content.add_line(compile_unit_iter % d[cls+'-compile-unit']) - new_content.add_line(d[cls+'-symbol-in-section']) + new_content.add_line(section_iter % d[cls + '-section']) + new_content.add_line(compile_unit_iter % + d[cls + '-compile-unit']) + new_content.add_line(d[cls + '-symbol-in-section']) # This special purpose iterator is for SBValue only!!! if cls == "SBValue": @@ -483,4 +498,3 @@ target = SBTarget() process = SBProcess() thread = SBThread() frame = SBFrame()''') - -- cgit v1.1