Chromium Code Reviews| Index: Source/bindings/scripts/idl_definitions.py |
| diff --git a/Source/bindings/scripts/idl_definitions.py b/Source/bindings/scripts/idl_definitions.py |
| index 2230c8f6e207153d8145a7d7dca1560077f1bf7b..13b063ff997a0c392d994c3a76193129411b28df 100644 |
| --- a/Source/bindings/scripts/idl_definitions.py |
| +++ b/Source/bindings/scripts/idl_definitions.py |
| @@ -394,6 +394,59 @@ class IdlConstant(TypedObject): |
| ################################################################################ |
| +# Literals |
| +################################################################################ |
| + |
| +class IdlLiteral(object): |
| + def __init__(self, idl_type, value): |
| + self.idl_type = idl_type |
| + self.value = value |
| + self.is_null = False |
| + |
| + def __str__(self): |
| + if self.idl_type == 'DOMString': |
| + return 'String("%s")' % self.value |
| + if self.idl_type == 'integer': |
| + return '%d' % self.value |
| + if self.idl_type == 'float': |
| + return '%g' % self.value |
| + if self.idl_type == 'boolean': |
| + return 'true' if self.value else 'false' |
| + raise ValueError('Unsupported literal type: %s' % self.idl_type) |
| + |
| + |
| +class IdlLiteralNull(IdlLiteral): |
| + def __init__(self): |
| + self.idl_type = 'NULL' |
| + self.value = None |
| + self.is_null = True |
| + |
| + def __str__(self): |
| + return 'nullptr' |
| + |
| + |
| +def default_node_to_idl_literal(node): |
| + # FIXME: This code is unnecessarily complicated due to the rather |
| + # inconsistent way the upstream IDL parser outputs default values. |
| + # http://crbug.com/374178 |
| + idl_type = node.GetProperty('TYPE') |
| + if idl_type == 'DOMString': |
| + value = node.GetProperty('NAME') |
|
haraken
2014/06/13 13:46:52
Shouldn't this be node.GetProperty('VALUE') ?
Jens Widell
2014/06/13 14:14:52
The use of NAME/VALUE here is entirely dictated by
|
| + if '"' in value or '\\' in value: |
| + raise ValueError('Unsupported string value: %r' % value) |
| + return IdlLiteral(idl_type, value) |
| + if idl_type == 'integer': |
| + return IdlLiteral(idl_type, int(node.GetProperty('NAME'))) |
|
haraken
2014/06/13 13:46:52
Shouldn't this be int(node.GetProperty('VALUE') ?
|
| + elif idl_type == 'float': |
|
Nils Barth (inactive)
2014/06/16 09:18:17
No else after return: these can all be |if|
|
| + return IdlLiteral(idl_type, float(node.GetProperty('VALUE'))) |
| + elif idl_type == 'boolean': |
| + return IdlLiteral(idl_type, node.GetProperty('VALUE')) |
| + elif idl_type == 'NULL': |
| + return IdlLiteralNull() |
| + raise ValueError('Unrecognized default value type: %s' % idl_type) |
| + |
| + |
| +################################################################################ |
| # Operations |
| ################################################################################ |
| @@ -475,6 +528,7 @@ class IdlArgument(TypedObject): |
| self.is_optional = node.GetProperty('OPTIONAL') # syntax: (optional T) |
| self.is_variadic = False # syntax: (T...) |
| self.name = node.GetName() |
| + self.default_value = None |
| children = node.GetChildren() |
| for child in children: |
| @@ -488,6 +542,8 @@ class IdlArgument(TypedObject): |
| if child_name != '...': |
| raise ValueError('Unrecognized Argument node; expected "...", got "%s"' % child_name) |
| self.is_variadic = child.GetProperty('ELLIPSIS') or False |
| + elif child_class == 'Default': |
| + self.default_value = default_node_to_idl_literal(child) |
| else: |
| raise ValueError('Unrecognized node class: %s' % child_class) |