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

Side by Side Diff: lib/html/scripts/generator.py

Issue 11196017: Remove unnecessary support for default values. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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 | « no previous file | 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 #!/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 systems to generate 6 """This module provides shared functionality for systems to generate
7 Dart APIs from the IDL database.""" 7 Dart APIs from the IDL database."""
8 8
9 import copy 9 import copy
10 import re 10 import re
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 """ 345 """
346 346
347 def ParametersInterfaceDeclaration(self, rename_type): 347 def ParametersInterfaceDeclaration(self, rename_type):
348 """Returns a formatted string declaring the parameters for the interface.""" 348 """Returns a formatted string declaring the parameters for the interface."""
349 def type_function(param): 349 def type_function(param):
350 # TODO(podivilov): replace param.dart_type field with param.is_optional 350 # TODO(podivilov): replace param.dart_type field with param.is_optional
351 dart_type = param.dart_type 351 dart_type = param.dart_type
352 if dart_type != 'Dynamic': 352 if dart_type != 'Dynamic':
353 dart_type = rename_type(dart_type) 353 dart_type = rename_type(dart_type)
354 return TypeOrNothing(dart_type, param.type_id) 354 return TypeOrNothing(dart_type, param.type_id)
355 return self._FormatParams(self.param_infos, None, type_function) 355 return self._FormatParams(self.param_infos, type_function)
356 356
357 def ParametersImplementationDeclaration(self, rename_type): 357 def ParametersImplementationDeclaration(self, rename_type):
358 """Returns a formatted string declaring the parameters for the 358 """Returns a formatted string declaring the parameters for the
359 implementation. 359 implementation.
360 360
361 Args: 361 Args:
362 rename_type: A function that allows the types to be renamed. 362 rename_type: A function that allows the types to be renamed.
363 The function is applied to the parameter's dart_type. 363 The function is applied to the parameter's dart_type.
364 """ 364 """
365 def type_function(param): 365 def type_function(param):
366 # TODO(podivilov): replace param.dart_type field with param.is_optional 366 # TODO(podivilov): replace param.dart_type field with param.is_optional
367 dart_type = param.dart_type 367 dart_type = param.dart_type
368 if dart_type != 'Dynamic': 368 if dart_type != 'Dynamic':
369 dart_type = rename_type(dart_type) 369 dart_type = rename_type(dart_type)
370 return TypeOrNothing(dart_type) 370 return TypeOrNothing(dart_type)
371 return self._FormatParams(self.param_infos, 'null', type_function) 371 return self._FormatParams(self.param_infos, type_function)
372 372
373 def ParametersAsArgumentList(self, parameter_count = None): 373 def ParametersAsArgumentList(self, parameter_count = None):
374 """Returns a string of the parameter names suitable for passing the 374 """Returns a string of the parameter names suitable for passing the
375 parameters as arguments. 375 parameters as arguments.
376 """ 376 """
377 if parameter_count is None: 377 if parameter_count is None:
378 parameter_count = len(self.param_infos) 378 parameter_count = len(self.param_infos)
379 return ', '.join(map( 379 return ', '.join(map(
380 lambda param_info: param_info.name, 380 lambda param_info: param_info.name,
381 self.param_infos[:parameter_count])) 381 self.param_infos[:parameter_count]))
382 382
383 def _FormatParams(self, params, default_value, type_fn): 383 def _FormatParams(self, params, type_fn):
384 def FormatParam(param): 384 def FormatParam(param):
385 """Returns a parameter declaration fragment for an ParamInfo.""" 385 """Returns a parameter declaration fragment for an ParamInfo."""
386 type = type_fn(param) 386 return '%s%s' % (type_fn(param), param.name)
387 if param.is_optional and default_value and default_value != 'null':
388 return '%s%s = %s' % (type, param.name, default_value)
389 return '%s%s' % (type, param.name)
390 387
391 required = [] 388 required = []
392 optional = [] 389 optional = []
393 for param_info in params: 390 for param_info in params:
394 if param_info.is_optional: 391 if param_info.is_optional:
395 optional.append(param_info) 392 optional.append(param_info)
396 else: 393 else:
397 if optional: 394 if optional:
398 raise Exception('Optional parameters cannot precede required ones: ' 395 raise Exception('Optional parameters cannot precede required ones: '
399 + str(params)) 396 + str(params))
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 self._database.GetInterface(type_name)) 1103 self._database.GetInterface(type_name))
1107 else: 1104 else:
1108 dart_interface_name = type_name 1105 dart_interface_name = type_name
1109 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name) 1106 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name)
1110 1107
1111 if type_data.clazz == 'ListLike': 1108 if type_data.clazz == 'ListLike':
1112 return ListLikeIDLTypeInfo(type_name, type_data, self.TypeInfo(type_data.i tem_type)) 1109 return ListLikeIDLTypeInfo(type_name, type_data, self.TypeInfo(type_data.i tem_type))
1113 1110
1114 class_name = '%sIDLTypeInfo' % type_data.clazz 1111 class_name = '%sIDLTypeInfo' % type_data.clazz
1115 return globals()[class_name](type_name, type_data) 1112 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698