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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 isinstance(kind, mojom.Interface) |
48 | 48 |
49 def IsInterfaceKind(kind): | 49 def IsInterfaceKind(kind): |
50 return isinstance(kind, mojom.Interface) | 50 return isinstance(kind, mojom.Interface) |
51 | 51 |
| 52 def IsMoveOnlyKind(kind): |
| 53 return IsObjectKind(kind) or IsHandleKind(kind) or IsInterfaceKind(kind) |
| 54 |
52 def StudlyCapsToCamel(studly): | 55 def StudlyCapsToCamel(studly): |
53 return studly[0].lower() + studly[1:] | 56 return studly[0].lower() + studly[1:] |
54 | 57 |
55 def VerifyTokenType(token, expected): | 58 def VerifyTokenType(token, expected): |
56 """Used to check that arrays and objects are used correctly as default | 59 """Used to check that arrays and objects are used correctly as default |
57 values. Arrays are tokens that look like ('ARRAY', element0, element1...). | 60 values. Arrays are tokens that look like ('ARRAY', element0, element1...). |
58 See mojom_parser.py for their representation. | 61 See mojom_parser.py for their representation. |
59 """ | 62 """ |
60 if not isinstance(token, tuple): | 63 if not isinstance(token, tuple): |
61 raise Exception("Expected token type '%s'. Invalid token '%s'." % | 64 raise Exception("Expected token type '%s'. Invalid token '%s'." % |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 96 |
94 def Write(self, contents, filename): | 97 def Write(self, contents, filename): |
95 if self.output_dir is None: | 98 if self.output_dir is None: |
96 print contents | 99 print contents |
97 return | 100 return |
98 with open(os.path.join(self.output_dir, filename), "w+") as f: | 101 with open(os.path.join(self.output_dir, filename), "w+") as f: |
99 f.write(contents) | 102 f.write(contents) |
100 | 103 |
101 def GenerateFiles(self, args): | 104 def GenerateFiles(self, args): |
102 raise NotImplementedError("Subclasses must override/implement this method") | 105 raise NotImplementedError("Subclasses must override/implement this method") |
OLD | NEW |