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: tools/json_schema_compiler/cc_generator.py

Issue 273323002: Convert snakecase enum names to camelcase when stringified. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from code import Code 5 from code import Code
6 from model import PropertyType 6 from model import PropertyType
7 import cpp_util 7 import cpp_util
8 import re
8 import schema_util 9 import schema_util
9 import util_cc_helper 10 import util_cc_helper
10 11
11 class CCGenerator(object): 12 class CCGenerator(object):
12 def __init__(self, type_generator, cpp_namespace): 13 def __init__(self, type_generator, cpp_namespace):
13 self._type_generator = type_generator 14 self._type_generator = type_generator
14 self._cpp_namespace = cpp_namespace 15 self._cpp_namespace = cpp_namespace
15 16
16 def Generate(self, namespace): 17 def Generate(self, namespace):
17 return _Generator(namespace, 18 return _Generator(namespace,
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name)) 884 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name))
884 885
885 if cpp_namespace is not None: 886 if cpp_namespace is not None:
886 c.Append('// static') 887 c.Append('// static')
887 maybe_namespace = '' if cpp_namespace is None else '%s::' % cpp_namespace 888 maybe_namespace = '' if cpp_namespace is None else '%s::' % cpp_namespace
888 889
889 c.Sblock('std::string %sToString(%s enum_param) {' % 890 c.Sblock('std::string %sToString(%s enum_param) {' %
890 (maybe_namespace, classname)) 891 (maybe_namespace, classname))
891 c.Sblock('switch (enum_param) {') 892 c.Sblock('switch (enum_param) {')
892 for enum_value in self._type_helper.FollowRef(type_).enum_values: 893 for enum_value in self._type_helper.FollowRef(type_).enum_values:
894 name = enum_value.name
895 if 'camel_case_enum_to_string' in self._namespace.compiler_options:
896 name = re.sub("_\S",
not at google - send to devlin 2014/05/13 18:36:35 I don't know the re library well enough to tell wh
David Tseng 2014/05/13 20:10:17 I re-wrote this without re. Hopefully that's clear
897 lambda m: m.string[m.start() + 1 : m.end()].upper(),
898 enum_value.name)
893 (c.Append('case %s: ' % self._type_helper.GetEnumValue(type_, enum_value)) 899 (c.Append('case %s: ' % self._type_helper.GetEnumValue(type_, enum_value))
894 .Append(' return "%s";' % enum_value.name)) 900 .Append(' return "%s";' % name))
895 (c.Append('case %s:' % self._type_helper.GetEnumNoneValue(type_)) 901 (c.Append('case %s:' % self._type_helper.GetEnumNoneValue(type_))
896 .Append(' return "";') 902 .Append(' return "";')
897 .Eblock('}') 903 .Eblock('}')
898 .Append('NOTREACHED();') 904 .Append('NOTREACHED();')
899 .Append('return "";') 905 .Append('return "";')
900 .Eblock('}') 906 .Eblock('}')
901 ) 907 )
902 return c 908 return c
903 909
904 def _GenerateEnumFromString(self, cpp_namespace, type_): 910 def _GenerateEnumFromString(self, cpp_namespace, type_):
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 if self._generate_error_messages: 1016 if self._generate_error_messages:
1011 params = list(params) + ['base::string16* error'] 1017 params = list(params) + ['base::string16* error']
1012 return ', '.join(str(p) for p in params) 1018 return ', '.join(str(p) for p in params)
1013 1019
1014 def _GenerateArgs(self, args): 1020 def _GenerateArgs(self, args):
1015 """Builds the argument list for a function, given an array of arguments. 1021 """Builds the argument list for a function, given an array of arguments.
1016 """ 1022 """
1017 if self._generate_error_messages: 1023 if self._generate_error_messages:
1018 args = list(args) + ['error'] 1024 args = list(args) + ['error']
1019 return ', '.join(str(a) for a in args) 1025 return ', '.join(str(a) for a in args)
OLDNEW
« no previous file with comments | « no previous file | tools/json_schema_compiler/idl_schema.py » ('j') | tools/json_schema_compiler/idl_schema.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698