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

Side by Side Diff: tools/dom/scripts/htmldartgenerator.py

Issue 12964003: Allowing renaming on DOM members on a per-method basis (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « tools/dom/idl/dart/dart.idl ('k') | tools/dom/scripts/htmlrenamer.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 """This module provides shared functionality for the system to generate 6 """This module provides shared functionality for the system to generate
7 dart:html APIs from the IDL database.""" 7 dart:html APIs from the IDL database."""
8 8
9 import emitter 9 import emitter
10 from generator import AnalyzeOperation, ConstantOutputOrder, \ 10 from generator import AnalyzeOperation, ConstantOutputOrder, \
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 self.AddIndexer(self._interface_type_info.list_item_type()) 75 self.AddIndexer(self._interface_type_info.list_item_type())
76 else: 76 else:
77 for parent in self._database.Hierarchy(self._interface): 77 for parent in self._database.Hierarchy(self._interface):
78 if parent == self._interface: 78 if parent == self._interface:
79 continue 79 continue
80 parent_type_info = self._type_registry.TypeInfo(parent.id) 80 parent_type_info = self._type_registry.TypeInfo(parent.id)
81 if parent_type_info.list_item_type(): 81 if parent_type_info.list_item_type():
82 self.AmendIndexer(parent_type_info.list_item_type()) 82 self.AmendIndexer(parent_type_info.list_item_type())
83 break 83 break
84 84
85 # Group overloaded operations by id. 85 # Group overloaded operations by name.
86 operationsById = {} 86 operationsByName = self._OperationsByName(interface)
87 for operation in interface.operations:
88 if operation.id not in operationsById:
89 operationsById[operation.id] = []
90 operationsById[operation.id].append(operation)
91 87
92 # Generate operations. 88 # Generate operations.
93 for id in sorted(operationsById.keys()): 89 for id in sorted(operationsByName.keys()):
94 operations = operationsById[id] 90 operations = operationsByName[id]
95 info = AnalyzeOperation(interface, operations) 91 info = AnalyzeOperation(interface, operations)
96 self.AddOperation(info, declare_only) 92 self.AddOperation(info, declare_only)
97 if ('%s.%s' % (interface.id, info.declared_name) in 93 if ('%s.%s' % (interface.id, info.declared_name) in
98 convert_to_future_members): 94 convert_to_future_members):
99 self.AddOperation(ConvertToFuture(info), declare_only) 95 self.AddOperation(ConvertToFuture(info), declare_only)
100 96
101 def AddSecondaryMembers(self, interface): 97 def AddSecondaryMembers(self, interface):
102 # With multiple inheritance, attributes and operations of non-first 98 # With multiple inheritance, attributes and operations of non-first
103 # interfaces need to be added. Sometimes the attribute or operation is 99 # interfaces need to be added. Sometimes the attribute or operation is
104 # defined in the current interface as well as a parent. In that case we 100 # defined in the current interface as well as a parent. In that case we
105 # avoid making a duplicate definition and pray that the signatures match. 101 # avoid making a duplicate definition and pray that the signatures match.
106 secondary_parents = self._TransitiveSecondaryParents(interface) 102 secondary_parents = self._TransitiveSecondaryParents(interface)
107 for parent_interface in sorted(secondary_parents): 103 for parent_interface in sorted(secondary_parents):
108 if isinstance(parent_interface, str): 104 if isinstance(parent_interface, str):
109 continue 105 continue
110 for attr in sorted(parent_interface.attributes, ConstantOutputOrder): 106 for attr in sorted(parent_interface.attributes, ConstantOutputOrder):
111 if not FindMatchingAttribute(interface, attr): 107 if not FindMatchingAttribute(interface, attr):
112 self.SecondaryContext(parent_interface) 108 self.SecondaryContext(parent_interface)
113 self.AddAttribute(attr) 109 self.AddAttribute(attr)
114 110
115 # Group overloaded operations by id. 111 # Group overloaded operations by name.
116 operationsById = {} 112 operationsByName =self._OperationsByName(parent_interface)
117 for operation in parent_interface.operations:
118 if operation.id not in operationsById:
119 operationsById[operation.id] = []
120 operationsById[operation.id].append(operation)
121 113
122 # Generate operations. 114 # Generate operations.
123 for id in sorted(operationsById.keys()): 115 for id in sorted(operationsByName.keys()):
124 if not any(op.id == id for op in interface.operations): 116 if not any(op.id == id for op in interface.operations):
125 operations = operationsById[id] 117 operations = operationsByName[id]
126 info = AnalyzeOperation(interface, operations) 118 info = AnalyzeOperation(interface, operations)
127 self.SecondaryContext(parent_interface) 119 self.SecondaryContext(parent_interface)
128 self.AddOperation(info) 120 self.AddOperation(info)
129 121
122 def _OperationsByName(self, interface):
123 operationsByName = {}
124 for operation in interface.operations:
125 name = operation.ext_attrs.get('DartName', operation.id)
126 operationsByName.setdefault(name, []).append(operation)
127 return operationsByName
128
130 def AddConstant(self, constant): 129 def AddConstant(self, constant):
131 const_name = self._renamer.RenameMember( 130 const_name = self._renamer.RenameMember(
132 self._interface.id, constant, constant.id, 'get:', dartify_name=False) 131 self._interface.id, constant, constant.id, 'get:', dartify_name=False)
133 if not const_name: 132 if not const_name:
134 return 133 return
135 type = TypeOrNothing(self._DartType(constant.type.id), constant.type.id) 134 type = TypeOrNothing(self._DartType(constant.type.id), constant.type.id)
136 self._members_emitter.Emit('\n static const $TYPE$NAME = $VALUE;\n', 135 self._members_emitter.Emit('\n static const $TYPE$NAME = $VALUE;\n',
137 NAME=const_name, 136 NAME=const_name,
138 TYPE=type, 137 TYPE=type,
139 VALUE=constant.value) 138 VALUE=constant.value)
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 walk(interface.parents) 650 walk(interface.parents)
652 else: 651 else:
653 walk(interface.parents[1:]) 652 walk(interface.parents[1:])
654 return result 653 return result
655 654
656 def _DartType(self, type_name): 655 def _DartType(self, type_name):
657 return self._type_registry.DartType(type_name) 656 return self._type_registry.DartType(type_name)
658 657
659 def _IsPrivate(self, name): 658 def _IsPrivate(self, name):
660 return name.startswith('_') 659 return name.startswith('_')
OLDNEW
« no previous file with comments | « tools/dom/idl/dart/dart.idl ('k') | tools/dom/scripts/htmlrenamer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698