| 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.") |
| 412 return enum | 420 return enum |
| 413 | 421 |
| 414 def ConstantFromData(module, data, parent_kind): | 422 def ConstantFromData(module, data, parent_kind): |
| 415 constant = mojom.Constant() | 423 constant = mojom.Constant() |
| 416 constant.name = data['name'] | 424 constant.name = data['name'] |
| 417 if parent_kind: | 425 if parent_kind: |
| 418 scope = (module.namespace, parent_kind.name) | 426 scope = (module.namespace, parent_kind.name) |
| 419 else: | 427 else: |
| 420 scope = (module.namespace, ) | 428 scope = (module.namespace, ) |
| 421 # TODO(mpcomplete): maybe we should only support POD kinds. | 429 # TODO(mpcomplete): maybe we should only support POD kinds. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 501 |
| 494 def OrderedModuleFromData(data): | 502 def OrderedModuleFromData(data): |
| 495 module = ModuleFromData(data) | 503 module = ModuleFromData(data) |
| 496 for interface in module.interfaces: | 504 for interface in module.interfaces: |
| 497 next_ordinal = 0 | 505 next_ordinal = 0 |
| 498 for method in interface.methods: | 506 for method in interface.methods: |
| 499 if method.ordinal is None: | 507 if method.ordinal is None: |
| 500 method.ordinal = next_ordinal | 508 method.ordinal = next_ordinal |
| 501 next_ordinal = method.ordinal + 1 | 509 next_ordinal = method.ordinal + 1 |
| 502 return module | 510 return module |
| OLD | NEW |