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

Unified Diff: mojo/public/tools/bindings/generators/mojom_cpp_generator.py

Issue 819083005: Update the generator to work around a MSVC limitation. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: With comment Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/js/struct_unittests.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/tools/bindings/generators/mojom_cpp_generator.py
diff --git a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
index a2618a47514f6719158775c72743fac3904f5e0a..34bba30e69be34948f5bd666dc76fbfc94388e61 100644
--- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
@@ -254,6 +254,21 @@ def TranslateConstants(token, kind):
if (kind is not None and mojom.IsFloatKind(kind)):
return token if token.isdigit() else token + "f";
+ # Per C++11, 2.14.2, the type of an integer literal is the first of the
+ # corresponding list in Table 6 in which its value can be represented. In this
+ # case, the list for decimal constants with no suffix is:
+ # int, long int, long long int
+ # The standard considers a program ill-formed if it contains an integer
+ # literal that cannot be represented by any of the allowed types.
+ #
+ # As it turns out, MSVC doesn't bother trying to fall back to long long int,
+ # so the integral constant -2147483648 causes it grief: it decides to
+ # represent 2147483648 as an unsigned integer, and then warns that the unary
+ # minus operator doesn't make sense on unsigned types. Doh!
+ if kind == mojom.INT32 and token == '-2147483648':
+ return '(-%d - 1) /* %s */' % (
+ 2**31 - 1, 'Workaround for MSVC bug; see https://crbug.com/445618')
+
return '%s%s' % (token, _kind_to_cpp_literal_suffix.get(kind, ''))
def ExpressionToText(value, kind=None):
« no previous file with comments | « mojo/public/js/struct_unittests.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698