| 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 """Code shared by the various language-specific code generators.""" | 5 """Code shared by the various language-specific code generators.""" |
| 6 | 6 |
| 7 from functools import partial | 7 from functools import partial |
| 8 import os.path | 8 import os.path |
| 9 | 9 |
| 10 import module as mojom | 10 import module as mojom |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 def IsStringKind(kind): | 37 def IsStringKind(kind): |
| 38 return kind.spec == 's' | 38 return kind.spec == 's' |
| 39 | 39 |
| 40 def IsEnumKind(kind): | 40 def IsEnumKind(kind): |
| 41 return isinstance(kind, mojom.Enum) | 41 return isinstance(kind, mojom.Enum) |
| 42 | 42 |
| 43 def IsObjectKind(kind): | 43 def IsObjectKind(kind): |
| 44 return isinstance(kind, (mojom.Struct, mojom.Array)) or IsStringKind(kind) | 44 return isinstance(kind, (mojom.Struct, mojom.Array)) or IsStringKind(kind) |
| 45 | 45 |
| 46 def IsHandleKind(kind): | 46 def IsHandleKind(kind): |
| 47 return kind.spec.startswith('h') or isinstance(kind, mojom.Interface) | 47 return kind.spec.startswith('h') or \ |
| 48 isinstance(kind, mojom.Interface) or \ |
| 49 isinstance(kind, mojom.InterfaceRequest) |
| 48 | 50 |
| 49 def IsInterfaceKind(kind): | 51 def IsInterfaceKind(kind): |
| 50 return isinstance(kind, mojom.Interface) | 52 return isinstance(kind, mojom.Interface) |
| 51 | 53 |
| 54 def IsInterfaceRequestKind(kind): |
| 55 return isinstance(kind, mojom.InterfaceRequest) |
| 56 |
| 52 def IsMoveOnlyKind(kind): | 57 def IsMoveOnlyKind(kind): |
| 53 return IsObjectKind(kind) or IsHandleKind(kind) | 58 return IsObjectKind(kind) or IsHandleKind(kind) |
| 54 | 59 |
| 55 def StudlyCapsToCamel(studly): | 60 def StudlyCapsToCamel(studly): |
| 56 return studly[0].lower() + studly[1:] | 61 return studly[0].lower() + studly[1:] |
| 57 | 62 |
| 58 def VerifyTokenType(token, expected): | 63 def VerifyTokenType(token, expected): |
| 59 """Used to check that arrays and objects are used correctly as default | 64 """Used to check that arrays and objects are used correctly as default |
| 60 values. Arrays are tokens that look like ('ARRAY', element0, element1...). | 65 values. Arrays are tokens that look like ('ARRAY', element0, element1...). |
| 61 See mojom_parser.py for their representation. | 66 See mojom_parser.py for their representation. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 101 |
| 97 def Write(self, contents, filename): | 102 def Write(self, contents, filename): |
| 98 if self.output_dir is None: | 103 if self.output_dir is None: |
| 99 print contents | 104 print contents |
| 100 return | 105 return |
| 101 with open(os.path.join(self.output_dir, filename), "w+") as f: | 106 with open(os.path.join(self.output_dir, filename), "w+") as f: |
| 102 f.write(contents) | 107 f.write(contents) |
| 103 | 108 |
| 104 def GenerateFiles(self, args): | 109 def GenerateFiles(self, args): |
| 105 raise NotImplementedError("Subclasses must override/implement this method") | 110 raise NotImplementedError("Subclasses must override/implement this method") |
| OLD | NEW |