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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 return "INFINITY"; | 247 return "INFINITY"; |
248 if token.value == "double.NEGATIVE_INFINITY" or \ | 248 if token.value == "double.NEGATIVE_INFINITY" or \ |
249 token.value == "float.NEGATIVE_INFINITY": | 249 token.value == "float.NEGATIVE_INFINITY": |
250 return "-INFINITY"; | 250 return "-INFINITY"; |
251 if token.value == "double.NAN" or token.value == "float.NAN": | 251 if token.value == "double.NAN" or token.value == "float.NAN": |
252 return "NAN"; | 252 return "NAN"; |
253 | 253 |
254 if (kind is not None and mojom.IsFloatKind(kind)): | 254 if (kind is not None and mojom.IsFloatKind(kind)): |
255 return token if token.isdigit() else token + "f"; | 255 return token if token.isdigit() else token + "f"; |
256 | 256 |
| 257 # Per C++11, 2.14.2, the type of an integer literal is the first of the |
| 258 # corresponding list in Table 6 in which its value can be represented. In this |
| 259 # case, the list for decimal constants with no suffix is: |
| 260 # int, long int, long long int |
| 261 # The standard considers a program ill-formed if it contains an integer |
| 262 # literal that cannot be represented by any of the allowed types. |
| 263 # |
| 264 # As it turns out, MSVC doesn't bother trying to fall back to long long int, |
| 265 # so the integral constant -2147483648 causes it grief: it decides to |
| 266 # represent 2147483648 as an unsigned integer, and then warns that the unary |
| 267 # minus operator doesn't make sense on unsigned types. Doh! |
| 268 if kind == mojom.INT32 and token == '-2147483648': |
| 269 return '(-%d - 1) /* %s */' % ( |
| 270 2**31 - 1, 'Workaround for MSVC bug; see https://crbug.com/445618') |
| 271 |
257 return '%s%s' % (token, _kind_to_cpp_literal_suffix.get(kind, '')) | 272 return '%s%s' % (token, _kind_to_cpp_literal_suffix.get(kind, '')) |
258 | 273 |
259 def ExpressionToText(value, kind=None): | 274 def ExpressionToText(value, kind=None): |
260 return TranslateConstants(value, kind) | 275 return TranslateConstants(value, kind) |
261 | 276 |
262 def ShouldInlineStruct(struct): | 277 def ShouldInlineStruct(struct): |
263 # TODO(darin): Base this on the size of the wrapper class. | 278 # TODO(darin): Base this on the size of the wrapper class. |
264 if len(struct.fields) > 4: | 279 if len(struct.fields) > 4: |
265 return False | 280 return False |
266 for field in struct.fields: | 281 for field in struct.fields: |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 def GenerateModuleSource(self): | 378 def GenerateModuleSource(self): |
364 return self.GetJinjaExports() | 379 return self.GetJinjaExports() |
365 | 380 |
366 def GenerateFiles(self, args): | 381 def GenerateFiles(self, args): |
367 self.Write(self.GenerateModuleHeader(), | 382 self.Write(self.GenerateModuleHeader(), |
368 self.MatchMojomFilePath("%s.h" % self.module.name)) | 383 self.MatchMojomFilePath("%s.h" % self.module.name)) |
369 self.Write(self.GenerateModuleInternalHeader(), | 384 self.Write(self.GenerateModuleInternalHeader(), |
370 self.MatchMojomFilePath("%s-internal.h" % self.module.name)) | 385 self.MatchMojomFilePath("%s-internal.h" % self.module.name)) |
371 self.Write(self.GenerateModuleSource(), | 386 self.Write(self.GenerateModuleSource(), |
372 self.MatchMojomFilePath("%s.cc" % self.module.name)) | 387 self.MatchMojomFilePath("%s.cc" % self.module.name)) |
OLD | NEW |