Commit 8f120ac4 authored by wjywbs@gmail.com's avatar wjywbs@gmail.com

Fix compile error if both inline and reference enums are used in a type.

The ToString() overloading function of inline and reference enums
will conflict because they exist in both global namespace and local
classes. This patch chooses the correct ToString() function in
different namespaces.

R=kalman@chromium.org
BUG=371042

Review URL: https://codereview.chromium.org/279833002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269969 0039d316-1c4b-4281-b951-d872f2087c98
parent a7de9693
......@@ -497,9 +497,10 @@ class _Generator(object):
vardot = '(%s).' % var
return '%sDeepCopy()' % vardot
elif underlying_type.property_type == PropertyType.ENUM:
classname = cpp_util.Classname(schema_util.StripNamespace(
underlying_type.name))
return 'new base::StringValue(%sToString(%s))' % (classname, var)
maybe_namespace = ''
if type_.property_type == PropertyType.REF:
maybe_namespace = '%s::' % underlying_type.namespace.unix_name
return 'new base::StringValue(%sToString(%s))' % (maybe_namespace, var)
elif underlying_type.property_type == PropertyType.BINARY:
if is_ptr:
vardot = var + '->'
......@@ -888,8 +889,8 @@ class _Generator(object):
c.Append('// static')
maybe_namespace = '' if cpp_namespace is None else '%s::' % cpp_namespace
c.Sblock('std::string %s%sToString(%s enum_param) {' %
(maybe_namespace, classname, classname))
c.Sblock('std::string %sToString(%s enum_param) {' %
(maybe_namespace, classname))
c.Sblock('switch (enum_param) {')
for enum_value in self._type_helper.FollowRef(type_).enum_values:
(c.Append('case %s: ' % self._type_helper.GetEnumValue(type_, enum_value))
......@@ -901,12 +902,6 @@ class _Generator(object):
.Append('return "";')
.Eblock('}')
)
(c.Append()
.Sblock('std::string %sToString(%s enum_param) {' %
(maybe_namespace, classname))
.Append('return %s%sToString(enum_param);' % (maybe_namespace, classname))
.Eblock('}'))
return c
def _GenerateEnumFromString(self, cpp_namespace, type_):
......
......@@ -214,8 +214,6 @@ class _Generator(object):
# static. On the other hand, those declared inline (e.g. in an object) do.
maybe_static = '' if is_toplevel else 'static '
(c.Append()
.Append('%sstd::string %sToString(%s as_enum);' %
(maybe_static, classname, classname))
.Append('%sstd::string ToString(%s as_enum);' %
(maybe_static, classname))
.Append('%s%s Parse%s(const std::string& as_string);' %
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment