| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 # TODO(vtl): "data" is a pretty vague name. Rename it? | 5 # TODO(vtl): "data" is a pretty vague name. Rename it? |
| 6 | 6 |
| 7 import copy | 7 import copy |
| 8 | 8 |
| 9 import module as mojom | 9 import module as mojom |
| 10 | 10 |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 prev_value = resolved_enum_values[field.value.name] | 390 prev_value = resolved_enum_values[field.value.name] |
| 391 else: | 391 else: |
| 392 raise Exception("Unresolved enum value.") | 392 raise Exception("Unresolved enum value.") |
| 393 | 393 |
| 394 resolved_enum_values[field.name] = prev_value | 394 resolved_enum_values[field.name] = prev_value |
| 395 field.numeric_value = prev_value | 395 field.numeric_value = prev_value |
| 396 | 396 |
| 397 def EnumFromData(module, data, parent_kind): | 397 def EnumFromData(module, data, parent_kind): |
| 398 enum = mojom.Enum(module=module) | 398 enum = mojom.Enum(module=module) |
| 399 enum.name = data['name'] | 399 enum.name = data['name'] |
| 400 enum.native_only = data['native_only'] |
| 400 name = enum.name | 401 name = enum.name |
| 401 if parent_kind: | 402 if parent_kind: |
| 402 name = parent_kind.name + '.' + name | 403 name = parent_kind.name + '.' + name |
| 403 enum.spec = 'x:%s.%s' % (module.namespace, name) | 404 enum.spec = 'x:%s.%s' % (module.namespace, name) |
| 404 enum.parent_kind = parent_kind | 405 enum.parent_kind = parent_kind |
| 405 enum.fields = map( | 406 enum.fields = map( |
| 406 lambda field: EnumFieldFromData(module, enum, field, parent_kind), | 407 lambda field: EnumFieldFromData(module, enum, field, parent_kind), |
| 407 data['fields']) | 408 data['fields'] if not enum.native_only else []) |
| 408 enum.attributes = data.get('attributes') | 409 enum.attributes = data.get('attributes') |
| 409 ResolveNumericEnumValues(enum.fields) | 410 ResolveNumericEnumValues(enum.fields) |
| 410 | 411 |
| 411 module.kinds[enum.spec] = enum | 412 module.kinds[enum.spec] = enum |
| 413 |
| 414 # Enforce that a [Native=True] attribute is set to make native-only enum |
| 415 # declarations more explicit. |
| 416 if enum.native_only: |
| 417 if not enum.attributes or not enum.attributes.get('Native', False): |
| 418 raise Exception("Native-only enum declarations must include a " + |
| 419 "Native=True attribute.") |
| 420 |
| 412 return enum | 421 return enum |
| 413 | 422 |
| 414 def ConstantFromData(module, data, parent_kind): | 423 def ConstantFromData(module, data, parent_kind): |
| 415 constant = mojom.Constant() | 424 constant = mojom.Constant() |
| 416 constant.name = data['name'] | 425 constant.name = data['name'] |
| 417 if parent_kind: | 426 if parent_kind: |
| 418 scope = (module.namespace, parent_kind.name) | 427 scope = (module.namespace, parent_kind.name) |
| 419 else: | 428 else: |
| 420 scope = (module.namespace, ) | 429 scope = (module.namespace, ) |
| 421 # TODO(mpcomplete): maybe we should only support POD kinds. | 430 # TODO(mpcomplete): maybe we should only support POD kinds. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 502 |
| 494 def OrderedModuleFromData(data): | 503 def OrderedModuleFromData(data): |
| 495 module = ModuleFromData(data) | 504 module = ModuleFromData(data) |
| 496 for interface in module.interfaces: | 505 for interface in module.interfaces: |
| 497 next_ordinal = 0 | 506 next_ordinal = 0 |
| 498 for method in interface.methods: | 507 for method in interface.methods: |
| 499 if method.ordinal is None: | 508 if method.ordinal is None: |
| 500 method.ordinal = next_ordinal | 509 method.ordinal = next_ordinal |
| 501 next_ordinal = method.ordinal + 1 | 510 next_ordinal = method.ordinal + 1 |
| 502 return module | 511 return module |
| OLD | NEW |