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

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/utilities.py

Issue 1975993003: Reland: Generate separate files for union type containers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 """Utility functions (file reading, simple IDL parsing by regexes) for IDL build . 5 """Utility functions (file reading, simple IDL parsing by regexes) for IDL build .
6 6
7 Design doc: http://www.chromium.org/developers/design-documents/idl-build 7 Design doc: http://www.chromium.org/developers/design-documents/idl-build
8 """ 8 """
9 9
10 import os 10 import os
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 @property 82 @property
83 def typedefs(self): 83 def typedefs(self):
84 return {} 84 return {}
85 85
86 @property 86 @property
87 def union_types(self): 87 def union_types(self):
88 return set() 88 return set()
89 89
90 @property 90 @property
91 def include_path_for_union_types(self): 91 def include_path_for_union_types(self, union_type):
92 return None 92 return None
93 93
94 94
95 class ComponentInfoProviderCore(ComponentInfoProvider): 95 class ComponentInfoProviderCore(ComponentInfoProvider):
96 def __init__(self, interfaces_info, component_info): 96 def __init__(self, interfaces_info, component_info):
97 super(ComponentInfoProviderCore, self).__init__() 97 super(ComponentInfoProviderCore, self).__init__()
98 self._interfaces_info = interfaces_info 98 self._interfaces_info = interfaces_info
99 self._component_info = component_info 99 self._component_info = component_info
100 100
101 @property 101 @property
102 def interfaces_info(self): 102 def interfaces_info(self):
103 return self._interfaces_info 103 return self._interfaces_info
104 104
105 @property 105 @property
106 def component_info(self): 106 def component_info(self):
107 return self._component_info 107 return self._component_info
108 108
109 @property 109 @property
110 def enumerations(self): 110 def enumerations(self):
111 return self._component_info['enumerations'] 111 return self._component_info['enumerations']
112 112
113 @property 113 @property
114 def typedefs(self): 114 def typedefs(self):
115 return self._component_info['typedefs'] 115 return self._component_info['typedefs']
116 116
117 @property 117 @property
118 def union_types(self): 118 def union_types(self):
119 return self._component_info['union_types'] 119 return self._component_info['union_types']
120 120
121 @property 121 def include_path_for_union_types(self, union_type):
122 def include_path_for_union_types(self): 122 name = shorten_union_name(union_type)
123 return 'bindings/core/v8/UnionTypesCore.h' 123 return 'bindings/core/v8/%s.h' % name
124 124
125 @property 125 @property
126 def specifier_for_export(self): 126 def specifier_for_export(self):
127 return 'CORE_EXPORT ' 127 return 'CORE_EXPORT '
128 128
129 @property 129 @property
130 def include_path_for_export(self): 130 def include_path_for_export(self):
131 return 'core/CoreExport.h' 131 return 'core/CoreExport.h'
132 132
133 133
(...skipping 24 matching lines...) Expand all
158 typedefs = self._component_info_core['typedefs'].copy() 158 typedefs = self._component_info_core['typedefs'].copy()
159 typedefs.update(self._component_info_modules['typedefs']) 159 typedefs.update(self._component_info_modules['typedefs'])
160 return typedefs 160 return typedefs
161 161
162 @property 162 @property
163 def union_types(self): 163 def union_types(self):
164 # Remove duplicate union types from component_info_modules to avoid 164 # Remove duplicate union types from component_info_modules to avoid
165 # generating multiple container generation. 165 # generating multiple container generation.
166 return self._component_info_modules['union_types'] - self._component_inf o_core['union_types'] 166 return self._component_info_modules['union_types'] - self._component_inf o_core['union_types']
167 167
168 @property 168 def include_path_for_union_types(self, union_type):
169 def include_path_for_union_types(self): 169 core_union_type_names = [core_union_type.name for core_union_type
170 return 'bindings/modules/v8/UnionTypesModules.h' 170 in self._component_info_core['union_types']]
171 name = shorten_union_name(union_type)
172 if union_type.name in core_union_type_names:
173 return 'bindings/core/v8/%s.h' % name
174 return 'bindings/modules/v8/%s.h' % name
171 175
172 @property 176 @property
173 def specifier_for_export(self): 177 def specifier_for_export(self):
174 return 'MODULES_EXPORT ' 178 return 'MODULES_EXPORT '
175 179
176 @property 180 @property
177 def include_path_for_export(self): 181 def include_path_for_export(self):
178 return 'modules/ModulesExport.h' 182 return 'modules/ModulesExport.h'
179 183
180 184
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 extended_attributes_string = match.group(1) 381 extended_attributes_string = match.group(1)
378 match = re.search(r'[^=]\bExposed\(([^)]*)\)', file_contents) 382 match = re.search(r'[^=]\bExposed\(([^)]*)\)', file_contents)
379 if not match: 383 if not match:
380 return None 384 return None
381 arguments = [] 385 arguments = []
382 for argument in map(string.strip, match.group(1).split(',')): 386 for argument in map(string.strip, match.group(1).split(',')):
383 exposed, runtime_enabled = argument.split() 387 exposed, runtime_enabled = argument.split()
384 arguments.append({'exposed': exposed, 'runtime_enabled': runtime_enabled }) 388 arguments.append({'exposed': exposed, 'runtime_enabled': runtime_enabled })
385 389
386 return arguments 390 return arguments
391
392
393 # Workaround for http://crbug.com/611437
394 # TODO(bashi): Remove this hack once we resolve too-long generated file names.
395 def shorten_union_name(union_type):
396 aliases = {
397 'CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContext OrImageBitmapRenderingContext': 'RenderingContext',
398 }
399
400 idl_type = union_type
401 if union_type.is_nullable:
402 idl_type = union_type.inner_type
403 name = idl_type.cpp_type or idl_type.name
404 alias = aliases.get(name)
405 if alias:
406 return alias
407 return name
Dirk Pranke 2016/05/17 00:16:49 nit: this could just be `return aliases.get(name,
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698