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

Side by Side Diff: mojo/public/tools/bindings/generators/mojom_dart_generator.py

Issue 1964193002: Dart: Refactors Proxies (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address comments Created 4 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 import sys 11 import sys
12 12
13 import mojom.fileutil as fileutil 13 import mojom.fileutil as fileutil
14 import mojom.generate.constant_resolver as resolver 14 import mojom.generate.constant_resolver as resolver
15 import mojom.generate.generator as generator 15 import mojom.generate.generator as generator
16 import mojom.generate.module as mojom 16 import mojom.generate.module as mojom
17 import mojom.generate.pack as pack 17 import mojom.generate.pack as pack
18 from mojom.generate.template_expander import UseJinja 18 from mojom.generate.template_expander import UseJinja
19 19
20 GENERATOR_PREFIX = 'dart' 20 GENERATOR_PREFIX = 'dart'
21 21
22 # CAUTION: To generate Dart-style names, and to avoid generating reserved words 22 # CAUTION: To generate Dart-style names, and to avoid generating reserved words
23 # for identifiers. The template files should generate names using 23 # for identifiers, the template files should generate names using
24 # {{element|name}}, not {{element.name}}. 24 # {{element|name}}, not {{element.name}}.
25 25
26 # Dart reserved words from: 26 # Dart reserved words from:
27 # http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-408.pdf 27 # http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-408.pdf
28 # We must not generated reserved words for identifiers. 28 # We must not generate reserved words for identifiers.
29 # NB: async, await, and yield are not technically reserved words, but since 29 # NB: async, await, and yield are not technically reserved words, but since
30 # they are not valid identifiers in all contexts, we include them here as well. 30 # they are not valid identifiers in all contexts, we include them here as well.
31 _dart_reserved_words = [ 31 _dart_reserved_words = [
32 "assert", 32 "assert",
33 "async", 33 "async",
34 "await", 34 "await",
35 "break", 35 "break",
36 "case", 36 "case",
37 "catch", 37 "catch",
38 "class", 38 "class",
(...skipping 21 matching lines...) Expand all
60 "throw", 60 "throw",
61 "true", 61 "true",
62 "try", 62 "try",
63 "var", 63 "var",
64 "void", 64 "void",
65 "while", 65 "while",
66 "with", 66 "with",
67 "yield", 67 "yield",
68 ] 68 ]
69 69
70 # These names are the class fields and methods of the Proxy class in
71 # lib/src/proxy.dart of Dart's mojo package. If these names appear in a .mojom
72 # they must be mangled to avoid name conflicts. They are mangled by appending
73 # an underscore ('_'), which is banned on names in mojom interfaces.
70 _reserved_words = _dart_reserved_words + [ 74 _reserved_words = _dart_reserved_words + [
75 "close",
76 "connectToService",
77 "ctrl",
78 "fromEndpoint",
79 "fromHandle",
80 "newFromEndpoint",
81 "responseOrError",
71 "serviceName", 82 "serviceName",
83 "unbound",
72 ] 84 ]
73 85
74 _kind_to_dart_default_value = { 86 _kind_to_dart_default_value = {
75 mojom.BOOL: "false", 87 mojom.BOOL: "false",
76 mojom.INT8: "0", 88 mojom.INT8: "0",
77 mojom.UINT8: "0", 89 mojom.UINT8: "0",
78 mojom.INT16: "0", 90 mojom.INT16: "0",
79 mojom.UINT16: "0", 91 mojom.UINT16: "0",
80 mojom.INT32: "0", 92 mojom.INT32: "0",
81 mojom.UINT32: "0", 93 mojom.UINT32: "0",
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 interface_to_import[name] = each_import["unique_name"] + "." + name 644 interface_to_import[name] = each_import["unique_name"] + "." + name
633 return interface_to_import 645 return interface_to_import
634 646
635 def ImportedFrom(self): 647 def ImportedFrom(self):
636 interface_to_import = {} 648 interface_to_import = {}
637 for each_import in self.module.imports: 649 for each_import in self.module.imports:
638 for each_interface in each_import["module"].interfaces: 650 for each_interface in each_import["module"].interfaces:
639 name = each_interface.name 651 name = each_interface.name
640 interface_to_import[name] = each_import["unique_name"] + "." 652 interface_to_import[name] = each_import["unique_name"] + "."
641 return interface_to_import 653 return interface_to_import
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698