OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 dart source files from a mojom.Module.""" | 5 """Generates dart source files from a mojom.Module.""" |
6 | 6 |
7 import errno | 7 import errno |
8 import os | 8 import os |
9 import re | 9 import re |
10 import shutil | 10 import shutil |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 return GetDartType(kind) | 236 return GetDartType(kind) |
237 if mojom.IsUnionKind(kind): | 237 if mojom.IsUnionKind(kind): |
238 return GetDartType(kind) | 238 return GetDartType(kind) |
239 if mojom.IsArrayKind(kind): | 239 if mojom.IsArrayKind(kind): |
240 array_type = DartDeclType(kind.kind) | 240 array_type = DartDeclType(kind.kind) |
241 return "List<" + array_type + ">" | 241 return "List<" + array_type + ">" |
242 if mojom.IsMapKind(kind): | 242 if mojom.IsMapKind(kind): |
243 key_type = DartDeclType(kind.key_kind) | 243 key_type = DartDeclType(kind.key_kind) |
244 value_type = DartDeclType(kind.value_kind) | 244 value_type = DartDeclType(kind.value_kind) |
245 return "Map<"+ key_type + ", " + value_type + ">" | 245 return "Map<"+ key_type + ", " + value_type + ">" |
246 if mojom.IsInterfaceKind(kind) or \ | 246 if mojom.IsInterfaceKind(kind): |
247 mojom.IsInterfaceRequestKind(kind): | 247 return ("%sInterface" % GetDartType(kind)) |
248 return "Object" | 248 if mojom.IsInterfaceRequestKind(kind): |
| 249 return ("%sInterfaceRequest" % GetDartType(kind.kind)) |
249 if mojom.IsEnumKind(kind): | 250 if mojom.IsEnumKind(kind): |
250 return GetDartType(kind) | 251 return GetDartType(kind) |
251 | 252 |
252 def NameToComponent(name): | 253 def NameToComponent(name): |
253 # insert '_' between anything and a Title name (e.g, HTTPEntry2FooBar -> | 254 # insert '_' between anything and a Title name (e.g, HTTPEntry2FooBar -> |
254 # HTTP_Entry2_FooBar). Numbers terminate a string of lower-case characters. | 255 # HTTP_Entry2_FooBar). Numbers terminate a string of lower-case characters. |
255 name = re.sub('([^_])([A-Z][^A-Z1-9_]+)', r'\1_\2', name) | 256 name = re.sub('([^_])([A-Z][^A-Z1-9_]+)', r'\1_\2', name) |
256 # insert '_' between non upper and start of upper blocks (e.g., | 257 # insert '_' between non upper and start of upper blocks (e.g., |
257 # HTTP_Entry2_FooBar -> HTTP_Entry2_Foo_Bar). | 258 # HTTP_Entry2_FooBar -> HTTP_Entry2_Foo_Bar). |
258 name = re.sub('([^A-Z_])([A-Z])', r'\1_\2', name) | 259 name = re.sub('([^A-Z_])([A-Z])', r'\1_\2', name) |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 interface_to_import[name] = each_import["unique_name"] + "." + name | 647 interface_to_import[name] = each_import["unique_name"] + "." + name |
647 return interface_to_import | 648 return interface_to_import |
648 | 649 |
649 def ImportedFrom(self): | 650 def ImportedFrom(self): |
650 interface_to_import = {} | 651 interface_to_import = {} |
651 for each_import in self.module.imports: | 652 for each_import in self.module.imports: |
652 for each_interface in each_import["module"].interfaces: | 653 for each_interface in each_import["module"].interfaces: |
653 name = each_interface.name | 654 name = each_interface.name |
654 interface_to_import[name] = each_import["unique_name"] + "." | 655 interface_to_import[name] = each_import["unique_name"] + "." |
655 return interface_to_import | 656 return interface_to_import |
OLD | NEW |