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

Side by Side Diff: mojo/public/tools/bindings/generators/mojom_cpp_generator.py

Issue 1527183003: Change mojo enums to be scoped enums in the generated C++ bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-binding-equals
Patch Set: rebase Created 4 years, 11 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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 """Generates C++ source files from a mojom.Module.""" 5 """Generates C++ source files from a mojom.Module."""
6 6
7 import mojom.generate.generator as generator 7 import mojom.generate.generator as generator
8 import mojom.generate.module as mojom 8 import mojom.generate.module as mojom
9 import mojom.generate.pack as pack 9 import mojom.generate.pack as pack
10 from mojom.generate.template_expander import UseJinja 10 from mojom.generate.template_expander import UseJinja
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if isinstance(token, mojom.NamedValue): 327 if isinstance(token, mojom.NamedValue):
328 # Both variable and enum constants are constructed like: 328 # Both variable and enum constants are constructed like:
329 # Namespace::Struct::CONSTANT_NAME 329 # Namespace::Struct::CONSTANT_NAME
330 # For enums, CONSTANT_NAME is ENUM_NAME_ENUM_VALUE. 330 # For enums, CONSTANT_NAME is ENUM_NAME_ENUM_VALUE.
331 name = [] 331 name = []
332 if token.imported_from: 332 if token.imported_from:
333 name.extend(NamespaceToArray(token.namespace)) 333 name.extend(NamespaceToArray(token.namespace))
334 if token.parent_kind: 334 if token.parent_kind:
335 name.append(token.parent_kind.name) 335 name.append(token.parent_kind.name)
336 if isinstance(token, mojom.EnumValue): 336 if isinstance(token, mojom.EnumValue):
337 name.append( 337 name.extend([token.enum.name, token.name])
338 "%s_%s" % (generator.CamelCaseToAllCaps(token.enum.name), token.name))
339 else: 338 else:
340 name.append(token.name) 339 name.append(token.name)
341 return "::".join(name) 340 return "::".join(name)
342 341
343 if isinstance(token, mojom.BuiltinValue): 342 if isinstance(token, mojom.BuiltinValue):
344 if token.value == "double.INFINITY" or token.value == "float.INFINITY": 343 if token.value == "double.INFINITY" or token.value == "float.INFINITY":
345 return "INFINITY"; 344 return "INFINITY";
346 if token.value == "double.NEGATIVE_INFINITY" or \ 345 if token.value == "double.NEGATIVE_INFINITY" or \
347 token.value == "float.NEGATIVE_INFINITY": 346 token.value == "float.NEGATIVE_INFINITY":
348 return "-INFINITY"; 347 return "-INFINITY";
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 "is_map_kind": mojom.IsMapKind, 455 "is_map_kind": mojom.IsMapKind,
457 "is_nullable_kind": mojom.IsNullableKind, 456 "is_nullable_kind": mojom.IsNullableKind,
458 "is_object_kind": mojom.IsObjectKind, 457 "is_object_kind": mojom.IsObjectKind,
459 "is_string_kind": mojom.IsStringKind, 458 "is_string_kind": mojom.IsStringKind,
460 "is_struct_kind": mojom.IsStructKind, 459 "is_struct_kind": mojom.IsStructKind,
461 "is_typemapped_kind": IsTypemappedKind, 460 "is_typemapped_kind": IsTypemappedKind,
462 "is_union_kind": mojom.IsUnionKind, 461 "is_union_kind": mojom.IsUnionKind,
463 "passes_associated_kinds": mojom.PassesAssociatedKinds, 462 "passes_associated_kinds": mojom.PassesAssociatedKinds,
464 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, 463 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE,
465 "stylize_method": generator.StudlyCapsToCamel, 464 "stylize_method": generator.StudlyCapsToCamel,
466 "to_all_caps": generator.CamelCaseToAllCaps,
467 "under_to_camel": generator.UnderToCamel, 465 "under_to_camel": generator.UnderToCamel,
468 } 466 }
469 467
470 def GetExtraHeaders(self): 468 def GetExtraHeaders(self):
471 extra_headers = set() 469 extra_headers = set()
472 for name, entry in self.typemap.iteritems(): 470 for name, entry in self.typemap.iteritems():
473 extra_headers.update(entry["headers"]) 471 extra_headers.update(entry["headers"])
474 return list(extra_headers) 472 return list(extra_headers)
475 473
476 def GetJinjaExports(self): 474 def GetJinjaExports(self):
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 def GenerateFiles(self, args): 509 def GenerateFiles(self, args):
512 global _current_typemap 510 global _current_typemap
513 _current_typemap = self.typemap 511 _current_typemap = self.typemap
514 suffix = "-%s" % self.variant if self.variant else "" 512 suffix = "-%s" % self.variant if self.variant else ""
515 self.Write(self.GenerateModuleHeader(), 513 self.Write(self.GenerateModuleHeader(),
516 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) 514 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix)))
517 self.Write(self.GenerateModuleInternalHeader(), 515 self.Write(self.GenerateModuleInternalHeader(),
518 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) 516 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix)))
519 self.Write(self.GenerateModuleSource(), 517 self.Write(self.GenerateModuleSource(),
520 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) 518 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix)))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698