| OLD | NEW |
| 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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 # minus operator doesn't make sense on unsigned types. Doh! | 361 # minus operator doesn't make sense on unsigned types. Doh! |
| 362 if kind == mojom.INT32 and token == "-2147483648": | 362 if kind == mojom.INT32 and token == "-2147483648": |
| 363 return "(-%d - 1) /* %s */" % ( | 363 return "(-%d - 1) /* %s */" % ( |
| 364 2**31 - 1, "Workaround for MSVC bug; see https://crbug.com/445618") | 364 2**31 - 1, "Workaround for MSVC bug; see https://crbug.com/445618") |
| 365 | 365 |
| 366 return "%s%s" % (token, _kind_to_cpp_literal_suffix.get(kind, "")) | 366 return "%s%s" % (token, _kind_to_cpp_literal_suffix.get(kind, "")) |
| 367 | 367 |
| 368 def ExpressionToText(value, kind=None): | 368 def ExpressionToText(value, kind=None): |
| 369 return TranslateConstants(value, kind) | 369 return TranslateConstants(value, kind) |
| 370 | 370 |
| 371 def RequiresContextForDataView(struct): | 371 def RequiresContextForDataView(kind): |
| 372 for field in struct.fields: | 372 for field in kind.fields: |
| 373 if mojom.IsReferenceKind(field.kind): | 373 if mojom.IsReferenceKind(field.kind): |
| 374 return True | 374 return True |
| 375 return False | 375 return False |
| 376 | 376 |
| 377 def ShouldInlineStruct(struct): | 377 def ShouldInlineStruct(struct): |
| 378 # TODO(darin): Base this on the size of the wrapper class. | 378 # TODO(darin): Base this on the size of the wrapper class. |
| 379 if len(struct.fields) > 4: | 379 if len(struct.fields) > 4: |
| 380 return False | 380 return False |
| 381 for field in struct.fields: | 381 for field in struct.fields: |
| 382 if mojom.IsReferenceKind(field.kind) and not mojom.IsStringKind(field.kind): | 382 if mojom.IsReferenceKind(field.kind) and not mojom.IsStringKind(field.kind): |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 _use_new_wrapper_types = self.use_new_wrapper_types | 536 _use_new_wrapper_types = self.use_new_wrapper_types |
| 537 global _variant | 537 global _variant |
| 538 _variant = self.variant | 538 _variant = self.variant |
| 539 suffix = "-%s" % self.variant if self.variant else "" | 539 suffix = "-%s" % self.variant if self.variant else "" |
| 540 self.Write(self.GenerateModuleHeader(), | 540 self.Write(self.GenerateModuleHeader(), |
| 541 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) | 541 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) |
| 542 self.Write(self.GenerateModuleInternalHeader(), | 542 self.Write(self.GenerateModuleInternalHeader(), |
| 543 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) | 543 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) |
| 544 self.Write(self.GenerateModuleSource(), | 544 self.Write(self.GenerateModuleSource(), |
| 545 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) | 545 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) |
| OLD | NEW |