This brings us into accordance with the official Python style guide (http://www.python.org/dev/peps/pep-0008/#indentation).
To preserve the indentation of the c code that is generated by these scripts, I've avoided re-indenting triple-quoted strings (unless those strings appear to be docstrings). --- I'm about to start doing some work on the Python code generation scripts in src/mapi/glapi/gen, and I'd like to use the standard Python style of 4-space indentation. Several of us have talked about switching to the standard style for a long time, and one of the chief stumbling blocks was not wanting to deal with a transitional period where the indentation was inconsistent. So yesterday I wrote a script to automate the conversion process (https://github.com/stereotype441/mesa-tools/blob/master/fix-indentation.py). This patch is the result of applying that script to the python files in src/mapi/glapi/gen only. I would be happy to apply the script to other python files in Mesa (or Piglit) if there is interest. I based the algorithm on the Python line structure analysis rules (documented in http://docs.python.org/reference/lexical_analysis.html#line-structure) so I believe it should not alter any semantics. The diff is over 400k, so I've included just two of the smaller python files as representative examples. The complete patch can be found at git://github.com/stereotype441/mesa.git in branch "reindent-glapi". src/mapi/glapi/gen/extension_helper.py | 330 +++---- src/mapi/glapi/gen/glX_XML.py | 936 ++++++++++---------- src/mapi/glapi/gen/glX_doc.py | 464 +++++----- src/mapi/glapi/gen/glX_proto_common.py | 88 +- src/mapi/glapi/gen/glX_proto_recv.py | 976 ++++++++++----------- src/mapi/glapi/gen/glX_proto_send.py | 1468 ++++++++++++++++---------------- src/mapi/glapi/gen/glX_proto_size.py | 1138 ++++++++++++------------- src/mapi/glapi/gen/glX_server_table.py | 686 +++++++-------- src/mapi/glapi/gen/gl_SPARC_asm.py | 440 +++++----- src/mapi/glapi/gen/gl_XML.py | 1408 +++++++++++++++--------------- src/mapi/glapi/gen/gl_apitemp.py | 418 ++++----- src/mapi/glapi/gen/gl_enums.py | 192 ++--- src/mapi/glapi/gen/gl_gentable.py | 76 +- src/mapi/glapi/gen/gl_offsets.py | 138 +-- src/mapi/glapi/gen/gl_procs.py | 300 +++---- src/mapi/glapi/gen/gl_table.py | 392 ++++----- src/mapi/glapi/gen/gl_x86-64_asm.py | 546 ++++++------ src/mapi/glapi/gen/gl_x86_asm.py | 412 ++++----- src/mapi/glapi/gen/mesadef.py | 302 +++---- src/mapi/glapi/gen/remap_helper.py | 308 +++---- src/mapi/glapi/gen/typeexpr.py | 378 ++++---- 21 files changed, 5698 insertions(+), 5698 deletions(-) diff --git a/src/mapi/glapi/gen/glX_proto_common.py b/src/mapi/glapi/gen/glX_proto_common.py index 6f094e2..86d9189 100644 --- a/src/mapi/glapi/gen/glX_proto_common.py +++ b/src/mapi/glapi/gen/glX_proto_common.py @@ -30,66 +30,66 @@ import string class glx_proto_item_factory(glX_XML.glx_item_factory): - """Factory to create GLX protocol oriented objects derived from gl_item.""" - - def create_item(self, name, element, context): - if name == "type": - return glx_proto_type(element, context) - else: - return glX_XML.glx_item_factory.create_item(self, name, element, context) + """Factory to create GLX protocol oriented objects derived from gl_item.""" + + def create_item(self, name, element, context): + if name == "type": + return glx_proto_type(element, context) + else: + return glX_XML.glx_item_factory.create_item(self, name, element, context) class glx_proto_type(gl_XML.gl_type): - def __init__(self, element, context): - gl_XML.gl_type.__init__(self, element, context) + def __init__(self, element, context): + gl_XML.gl_type.__init__(self, element, context) - self.glx_name = element.nsProp( "glx_name", None ) - return + self.glx_name = element.nsProp( "glx_name", None ) + return class glx_print_proto(gl_XML.gl_print_base): - def size_call(self, func, outputs_also = 0): - """Create C code to calculate 'compsize'. + def size_call(self, func, outputs_also = 0): + """Create C code to calculate 'compsize'. + + Creates code to calculate 'compsize'. If the function does + not need 'compsize' to be calculated, None will be + returned.""" - Creates code to calculate 'compsize'. If the function does - not need 'compsize' to be calculated, None will be - returned.""" - - compsize = None + compsize = None - for param in func.parameterIterator(): - if outputs_also or not param.is_output: - if param.is_image(): - [dim, w, h, d, junk] = param.get_dimensions() + for param in func.parameterIterator(): + if outputs_also or not param.is_output: + if param.is_image(): + [dim, w, h, d, junk] = param.get_dimensions() - compsize = '__glImageSize(%s, %s, %s, %s, %s, %s)' % (w, h, d, param.img_format, param.img_type, param.img_target) - if not param.img_send_null: - compsize = '(%s != NULL) ? %s : 0' % (param.name, compsize) + compsize = '__glImageSize(%s, %s, %s, %s, %s, %s)' % (w, h, d, param.img_format, param.img_type, param.img_target) + if not param.img_send_null: + compsize = '(%s != NULL) ? %s : 0' % (param.name, compsize) - return compsize + return compsize - elif len(param.count_parameter_list): - parameters = string.join( param.count_parameter_list, "," ) - compsize = "__gl%s_size(%s)" % (func.name, parameters) + elif len(param.count_parameter_list): + parameters = string.join( param.count_parameter_list, "," ) + compsize = "__gl%s_size(%s)" % (func.name, parameters) - return compsize + return compsize - return None + return None - def emit_packet_size_calculation(self, f, bias): - # compsize is only used in the command size calculation if - # the function has a non-output parameter that has a non-empty - # counter_parameter_list. + def emit_packet_size_calculation(self, f, bias): + # compsize is only used in the command size calculation if + # the function has a non-output parameter that has a non-empty + # counter_parameter_list. - compsize = self.size_call(f) - if compsize: - print ' const GLuint compsize = %s;' % (compsize) + compsize = self.size_call(f) + if compsize: + print ' const GLuint compsize = %s;' % (compsize) - if bias: - print ' const GLuint cmdlen = %s - %u;' % (f.command_length(), bias) - else: - print ' const GLuint cmdlen = %s;' % (f.command_length()) + if bias: + print ' const GLuint cmdlen = %s - %u;' % (f.command_length(), bias) + else: + print ' const GLuint cmdlen = %s;' % (f.command_length()) - #print '' - return compsize + #print '' + return compsize diff --git a/src/mapi/glapi/gen/gl_gentable.py b/src/mapi/glapi/gen/gl_gentable.py index 5657e32..9e84dea 100644 --- a/src/mapi/glapi/gen/gl_gentable.py +++ b/src/mapi/glapi/gen/gl_gentable.py @@ -138,65 +138,65 @@ body_template = """ class PrintCode(gl_XML.gl_print_base): - def __init__(self): - gl_XML.gl_print_base.__init__(self) + def __init__(self): + gl_XML.gl_print_base.__init__(self) - self.name = "gl_gen_table.py (from Mesa)" - self.license = license.bsd_license_template % ( \ + self.name = "gl_gen_table.py (from Mesa)" + self.license = license.bsd_license_template % ( \ """Copyright (C) 1999-2001 Brian Paul All Rights Reserved. (C) Copyright IBM Corporation 2004, 2005 (C) Copyright Apple Inc 2011""", "BRIAN PAUL, IBM") - return + return - def get_stack_size(self, f): - size = 0 - for p in f.parameterIterator(): - if p.is_padding: - continue + def get_stack_size(self, f): + size = 0 + for p in f.parameterIterator(): + if p.is_padding: + continue - size += p.get_stack_size() + size += p.get_stack_size() - return size + return size - def printRealHeader(self): - print header - return + def printRealHeader(self): + print header + return - def printRealFooter(self): - print footer - return + def printRealFooter(self): + print footer + return - def printBody(self, api): - for f in api.functionIterateByOffset(): - for entry_point in f.entry_points: - vars = { 'entry_point' : entry_point, - 'name' : f.name } + def printBody(self, api): + for f in api.functionIterateByOffset(): + for entry_point in f.entry_points: + vars = { 'entry_point' : entry_point, + 'name' : f.name } - print body_template % vars - return + print body_template % vars + return def show_usage(): - print "Usage: %s [-f input_file_name]" % sys.argv[0] - sys.exit(1) + print "Usage: %s [-f input_file_name]" % sys.argv[0] + sys.exit(1) if __name__ == '__main__': - file_name = "gl_API.xml" + file_name = "gl_API.xml" - try: - (args, trail) = getopt.getopt(sys.argv[1:], "m:f:") - except Exception,e: - show_usage() + try: + (args, trail) = getopt.getopt(sys.argv[1:], "m:f:") + except Exception,e: + show_usage() - for (arg,val) in args: - if arg == "-f": - file_name = val + for (arg,val) in args: + if arg == "-f": + file_name = val - printer = PrintCode() + printer = PrintCode() - api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) - printer.Print(api) + api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) + printer.Print(api) -- 1.7.12.2 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev