Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: gpu/command_buffer/build_gles2_cmd_buffer.py

Issue 1159493007: Refactor word splitting in gles2 command generator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """code generator for GLES2 command buffers.""" 6 """code generator for GLES2 command buffers."""
7 7
8 import itertools 8 import itertools
9 import os 9 import os
10 import os.path 10 import os.path
(...skipping 3880 matching lines...) Expand 10 before | Expand all | Expand 10 after
3891 } 3891 }
3892 3892
3893 3893
3894 def Grouper(n, iterable, fillvalue=None): 3894 def Grouper(n, iterable, fillvalue=None):
3895 """Collect data into fixed-length chunks or blocks""" 3895 """Collect data into fixed-length chunks or blocks"""
3896 args = [iter(iterable)] * n 3896 args = [iter(iterable)] * n
3897 return itertools.izip_longest(fillvalue=fillvalue, *args) 3897 return itertools.izip_longest(fillvalue=fillvalue, *args)
3898 3898
3899 3899
3900 def SplitWords(input_string): 3900 def SplitWords(input_string):
3901 """Transforms a input_string into a list of lower-case components. 3901 """Split by '_' if found, otherwise split at uppercase/numeric chars.
3902 3902
3903 Args: 3903 Will split "some_TEXT" into ["some", "TEXT"], "CamelCase" into ["Camel",
3904 input_string: the input string. 3904 "Case"], and "Vector3" into ["Vector", "3"].
3905
3906 Returns:
3907 a list of lower-case words.
3908 """ 3905 """
3909 if input_string.find('_') > -1: 3906 if input_string.find('_') > -1:
3910 # 'some_TEXT_' -> 'some text' 3907 # 'some_TEXT_' -> 'some TEXT'
3911 return input_string.replace('_', ' ').strip().lower().split() 3908 return input_string.replace('_', ' ').strip().split()
3912 else: 3909 else:
3913 if re.search('[A-Z]', input_string) and re.search('[a-z]', input_string): 3910 if re.search('[A-Z]', input_string) and re.search('[a-z]', input_string):
3914 # mixed case. 3911 # mixed case.
3915 # look for capitalization to cut input_strings 3912 # look for capitalization to cut input_strings
3916 # 'SomeText' -> 'Some Text' 3913 # 'SomeText' -> 'Some Text'
3917 input_string = re.sub('([A-Z])', r' \1', input_string).strip() 3914 input_string = re.sub('([A-Z])', r' \1', input_string).strip()
3918 # 'Vector3' -> 'Vector 3' 3915 # 'Vector3' -> 'Vector 3'
3919 input_string = re.sub('([^0-9])([0-9])', r'\1 \2', input_string) 3916 input_string = re.sub('([^0-9])([0-9])', r'\1 \2', input_string)
3920 return input_string.lower().split() 3917 return input_string.split()
3921
3922
3923 def Lower(words):
3924 """Makes a lower-case identifier from words.
3925
3926 Args:
3927 words: a list of lower-case words.
3928
3929 Returns:
3930 the lower-case identifier.
3931 """
3932 return '_'.join(words)
3933
3934 3918
3935 def ToUnderscore(input_string): 3919 def ToUnderscore(input_string):
3936 """converts CamelCase to camel_case.""" 3920 """converts CamelCase to camel_case."""
3937 words = SplitWords(input_string) 3921 words = SplitWords(input_string)
3938 return Lower(words) 3922 return '_'.join([word.lower() for word in words])
3939 3923
3940 def CachedStateName(item): 3924 def CachedStateName(item):
3941 if item.get('cached', False): 3925 if item.get('cached', False):
3942 return 'cached_' + item['name'] 3926 return 'cached_' + item['name']
3943 return item['name'] 3927 return item['name']
3944 3928
3945 def ToGLExtensionString(extension_flag): 3929 def ToGLExtensionString(extension_flag):
3946 """Returns GL-type extension string of a extension flag.""" 3930 """Returns GL-type extension string of a extension flag."""
3947 if extension_flag == "oes_compressed_etc1_rgb8_texture": 3931 if extension_flag == "oes_compressed_etc1_rgb8_texture":
3948 return "OES_compressed_ETC1_RGB8_texture" # Fixup inconsitency with rgb8, 3932 return "OES_compressed_ETC1_RGB8_texture" # Fixup inconsitency with rgb8,
(...skipping 7075 matching lines...) Expand 10 before | Expand all | Expand 10 after
11024 Format(gen.generated_cpp_filenames) 11008 Format(gen.generated_cpp_filenames)
11025 11009
11026 if gen.errors > 0: 11010 if gen.errors > 0:
11027 print "%d errors" % gen.errors 11011 print "%d errors" % gen.errors
11028 return 1 11012 return 1
11029 return 0 11013 return 0
11030 11014
11031 11015
11032 if __name__ == '__main__': 11016 if __name__ == '__main__':
11033 sys.exit(main(sys.argv[1:])) 11017 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698