diff --git a/compiler/back_end/cpp/header_generator.py b/compiler/back_end/cpp/header_generator.py index 392d188e..5860bc82 100644 --- a/compiler/back_end/cpp/header_generator.py +++ b/compiler/back_end/cpp/header_generator.py @@ -418,7 +418,7 @@ def _get_cpp_view_type_for_type_definition( adapted_buffer_type = _get_adapted_cpp_buffer_type_for_field( type_definition, size, buffer_type, byte_order, parent_addressable_unit ) - if type_definition.HasField("external"): + if type_definition.has_field("external"): # Externals do not (yet) support runtime parameters. return ( code_template.format_template( @@ -433,7 +433,7 @@ def _get_cpp_view_type_for_type_definition( ), [], ) - elif type_definition.HasField("structure"): + elif type_definition.has_field("structure"): parameter_types = [] for parameter in type_definition.runtime_parameter: parameter_types.append( @@ -450,7 +450,7 @@ def _get_cpp_view_type_for_type_definition( ), parameter_types, ) - elif type_definition.HasField("enumeration"): + elif type_definition.has_field("enumeration"): return ( code_template.format_template( _TEMPLATES.enum_view_type, @@ -534,7 +534,7 @@ def _get_cpp_view_type_for_physical_type( element_view_parameters, ) else: - assert type_ir.HasField("atomic_type") + assert type_ir.has_field("atomic_type") reference = type_ir.atomic_type.reference referenced_type = ir_util.find_object(reference, ir) if parent_addressable_unit > referenced_type.addressable_unit: @@ -829,13 +829,13 @@ def _render_expression(expression, ir, field_reader=None, subexpressions=None): True, ) elif expression.type.which_type == "boolean": - if expression.type.boolean.HasField("value"): + if expression.type.boolean.has_field("value"): if expression.type.boolean.value: return _ExpressionResult(_maybe_type("bool") + "(true)", True) else: return _ExpressionResult(_maybe_type("bool") + "(false)", True) elif expression.type.which_type == "enumeration": - if expression.type.enumeration.HasField("value"): + if expression.type.enumeration.has_field("value"): return _ExpressionResult( _render_enum_value(expression.type.enumeration, ir), True ) @@ -889,7 +889,7 @@ def _get_cpp_type_reader_of_field( ): """Returns the C++ view type for a field.""" field_size = None - if field_ir.type.HasField("size_in_bits"): + if field_ir.type.has_field("size_in_bits"): field_size = ir_util.constant_value(field_ir.type.size_in_bits) assert field_size is not None elif ir_util.is_constant(field_ir.location.size): @@ -1365,7 +1365,7 @@ def _generate_structure_definition(type_ir, ir, config: Config): units = {1: "Bits", 8: "Bytes"}[type_ir.addressable_unit] for subtype in type_ir.subtype: - if subtype.HasField("enumeration"): + if subtype.has_field("enumeration"): enum_using_statements.append( code_template.format_template( _TEMPLATES.enum_using_statement, @@ -1672,11 +1672,11 @@ def _generate_enum_definition(type_ir, include_traits=True): def _generate_type_definition(type_ir, ir, config: Config): """Generates C++ for an Emboss type.""" - if type_ir.HasField("structure"): + if type_ir.has_field("structure"): return _generate_structure_definition(type_ir, ir, config) - elif type_ir.HasField("enumeration"): + elif type_ir.has_field("enumeration"): return _generate_enum_definition(type_ir, config.include_enum_traits) - elif type_ir.HasField("external"): + elif type_ir.has_field("external"): # TODO(bolms): This should probably generate an #include. return "", "", "" else: diff --git a/compiler/front_end/attribute_checker.py b/compiler/front_end/attribute_checker.py index 9920db48..8da67c10 100644 --- a/compiler/front_end/attribute_checker.py +++ b/compiler/front_end/attribute_checker.py @@ -174,7 +174,7 @@ def _fixed_size_of_struct_or_bits(struct, unit_size): """Returns size of struct in bits or None, if struct is not fixed size.""" size = 0 for field in struct.field: - if not field.HasField("location"): + if not field.has_field("location"): # Virtual fields do not contribute to the physical size of the struct. continue field_start = ir_util.constant_value(field.location.start) @@ -421,7 +421,7 @@ def _verify_requires_attribute_on_field(field, source_file_name, ir, errors): if ir_util.field_is_virtual(field): field_expression_type = field.read_transform.type else: - if not field.type.HasField("atomic_type"): + if not field.type.has_field("atomic_type"): errors.append( [ error.error( diff --git a/compiler/front_end/attribute_checker_test.py b/compiler/front_end/attribute_checker_test.py index 4325ca42..fdab7bd0 100644 --- a/compiler/front_end/attribute_checker_test.py +++ b/compiler/front_end/attribute_checker_test.py @@ -514,12 +514,12 @@ def test_adds_byte_order_attributes_from_default(self): byte_order_attr = ir_util.get_attribute( ir.module[0].type[0].structure.field[0].attribute, _BYTE_ORDER ) - self.assertTrue(byte_order_attr.HasField("string_constant")) + self.assertTrue(byte_order_attr.has_field("string_constant")) self.assertEqual("BigEndian", byte_order_attr.string_constant.text) byte_order_attr = ir_util.get_attribute( ir.module[0].type[0].structure.field[1].attribute, _BYTE_ORDER ) - self.assertTrue(byte_order_attr.HasField("string_constant")) + self.assertTrue(byte_order_attr.has_field("string_constant")) self.assertEqual("LittleEndian", byte_order_attr.string_constant.text) def test_adds_null_byte_order_attributes(self): @@ -537,7 +537,7 @@ def test_adds_null_byte_order_attributes(self): byte_order_attr = ir_util.get_attribute( structure.field[0].attribute, _BYTE_ORDER ) - self.assertTrue(byte_order_attr.HasField("string_constant")) + self.assertTrue(byte_order_attr.has_field("string_constant")) self.assertEqual("Null", byte_order_attr.string_constant.text) self.assertEqual( structure.field[0].source_location, byte_order_attr.source_location @@ -545,12 +545,12 @@ def test_adds_null_byte_order_attributes(self): byte_order_attr = ir_util.get_attribute( structure.field[1].attribute, _BYTE_ORDER ) - self.assertTrue(byte_order_attr.HasField("string_constant")) + self.assertTrue(byte_order_attr.has_field("string_constant")) self.assertEqual("LittleEndian", byte_order_attr.string_constant.text) byte_order_attr = ir_util.get_attribute( structure.field[2].attribute, _BYTE_ORDER ) - self.assertTrue(byte_order_attr.HasField("string_constant")) + self.assertTrue(byte_order_attr.has_field("string_constant")) self.assertEqual("Null", byte_order_attr.string_constant.text) self.assertEqual( structure.field[2].source_location, byte_order_attr.source_location @@ -558,7 +558,7 @@ def test_adds_null_byte_order_attributes(self): byte_order_attr = ir_util.get_attribute( structure.field[3].attribute, _BYTE_ORDER ) - self.assertTrue(byte_order_attr.HasField("string_constant")) + self.assertTrue(byte_order_attr.has_field("string_constant")) self.assertEqual("LittleEndian", byte_order_attr.string_constant.text) def test_disallows_default_byte_order_on_field(self): @@ -631,7 +631,7 @@ def test_adds_byte_order_from_scoped_default(self): byte_order_attr = ir_util.get_attribute( ir.module[0].type[0].structure.field[0].attribute, _BYTE_ORDER ) - self.assertTrue(byte_order_attr.HasField("string_constant")) + self.assertTrue(byte_order_attr.has_field("string_constant")) self.assertEqual("BigEndian", byte_order_attr.string_constant.text) def test_disallows_unknown_byte_order(self): @@ -926,7 +926,7 @@ def test_adds_false_is_signed_attribute(self): self.assertEqual([], attribute_checker.normalize_and_verify(ir)) enum = ir.module[0].type[0] is_signed_attr = ir_util.get_attribute(enum.attribute, _IS_SIGNED) - self.assertTrue(is_signed_attr.expression.HasField("boolean_constant")) + self.assertTrue(is_signed_attr.expression.has_field("boolean_constant")) self.assertFalse(is_signed_attr.expression.boolean_constant.value) def test_leaves_is_signed_attribute(self): @@ -934,7 +934,7 @@ def test_leaves_is_signed_attribute(self): self.assertEqual([], attribute_checker.normalize_and_verify(ir)) enum = ir.module[0].type[0] is_signed_attr = ir_util.get_attribute(enum.attribute, _IS_SIGNED) - self.assertTrue(is_signed_attr.expression.HasField("boolean_constant")) + self.assertTrue(is_signed_attr.expression.has_field("boolean_constant")) self.assertTrue(is_signed_attr.expression.boolean_constant.value) def test_adds_true_is_signed_attribute(self): @@ -942,7 +942,7 @@ def test_adds_true_is_signed_attribute(self): self.assertEqual([], attribute_checker.normalize_and_verify(ir)) enum = ir.module[0].type[0] is_signed_attr = ir_util.get_attribute(enum.attribute, _IS_SIGNED) - self.assertTrue(is_signed_attr.expression.HasField("boolean_constant")) + self.assertTrue(is_signed_attr.expression.has_field("boolean_constant")) self.assertTrue(is_signed_attr.expression.boolean_constant.value) def test_adds_max_bits_attribute(self): @@ -950,7 +950,7 @@ def test_adds_max_bits_attribute(self): self.assertEqual([], attribute_checker.normalize_and_verify(ir)) enum = ir.module[0].type[0] max_bits_attr = ir_util.get_attribute(enum.attribute, _MAX_BITS) - self.assertTrue(max_bits_attr.expression.HasField("constant")) + self.assertTrue(max_bits_attr.expression.has_field("constant")) self.assertEqual("64", max_bits_attr.expression.constant.value) def test_leaves_max_bits_attribute(self): @@ -958,7 +958,7 @@ def test_leaves_max_bits_attribute(self): self.assertEqual([], attribute_checker.normalize_and_verify(ir)) enum = ir.module[0].type[0] max_bits_attr = ir_util.get_attribute(enum.attribute, _MAX_BITS) - self.assertTrue(max_bits_attr.expression.HasField("constant")) + self.assertTrue(max_bits_attr.expression.has_field("constant")) self.assertEqual("32", max_bits_attr.expression.constant.value) def test_rejects_too_small_max_bits(self): diff --git a/compiler/front_end/constraints.py b/compiler/front_end/constraints.py index ae6bb1e5..ab26a814 100644 --- a/compiler/front_end/constraints.py +++ b/compiler/front_end/constraints.py @@ -25,10 +25,10 @@ def _render_type(type_ir, ir): """Returns the human-readable notation of the given type.""" - assert type_ir.HasField( + assert type_ir.has_field( "atomic_type" ), "TODO(bolms): Implement _render_type for array types." - if type_ir.HasField("size_in_bits"): + if type_ir.has_field("size_in_bits"): return _render_atomic_type_name( type_ir, ir, suffix=":" + str(ir_util.constant_value(type_ir.size_in_bits)) ) @@ -37,7 +37,7 @@ def _render_type(type_ir, ir): def _render_atomic_type_name(type_ir, ir, suffix=None): - assert type_ir.HasField( + assert type_ir.has_field( "atomic_type" ), "_render_atomic_type_name() requires an atomic type" if not suffix: @@ -78,7 +78,7 @@ def _check_that_inner_array_dimensions_are_constant(type_ir, source_file_name, e def _check_that_array_base_types_are_fixed_size(type_ir, source_file_name, errors, ir): """Checks that the sizes of array elements are known at compile time.""" - if type_ir.base_type.HasField("array_type"): + if type_ir.base_type.has_field("array_type"): # An array is fixed size if its base_type is fixed size and its array # dimension is constant. This function will be called again on the inner # array, and we do not want to cascade errors if the inner array's base_type @@ -86,8 +86,8 @@ def _check_that_array_base_types_are_fixed_size(type_ir, source_file_name, error # _check_that_inner_array_dimensions_are_constant, which will provide an # appropriate error message for that case. return - assert type_ir.base_type.HasField("atomic_type") - if type_ir.base_type.HasField("size_in_bits"): + assert type_ir.base_type.has_field("atomic_type") + if type_ir.base_type.has_field("size_in_bits"): # If the base_type has a size_in_bits, then it is fixed size. return base_type = ir_util.find_object(type_ir.base_type.atomic_type.reference, ir) @@ -111,11 +111,11 @@ def _check_that_array_base_types_in_structs_are_multiples_of_bytes( ): # TODO(bolms): Remove this limitation. """Checks that the sizes of array elements are multiples of 8 bits.""" - if type_ir.base_type.HasField("array_type"): + if type_ir.base_type.has_field("array_type"): # Only check the innermost array for multidimensional arrays. return - assert type_ir.base_type.HasField("atomic_type") - if type_ir.base_type.HasField("size_in_bits"): + assert type_ir.base_type.has_field("atomic_type") + if type_ir.base_type.has_field("size_in_bits"): assert ir_util.is_constant(type_ir.base_type.size_in_bits) base_type_size = ir_util.constant_value(type_ir.base_type.size_in_bits) else: @@ -209,10 +209,10 @@ def _check_type_requirements_for_field( type_ir, type_definition, field, ir, source_file_name, errors ): """Checks that the `requires` attribute of each field's type is fulfilled.""" - if not type_ir.HasField("atomic_type"): + if not type_ir.has_field("atomic_type"): return - if field.type.HasField("atomic_type"): + if field.type.has_field("atomic_type"): field_min_size = ( int(field.location.size.type.integer.minimum_value) * type_definition.addressable_unit @@ -225,7 +225,7 @@ def _check_type_requirements_for_field( else: field_is_atomic = False - if type_ir.HasField("size_in_bits"): + if type_ir.has_field("size_in_bits"): element_size = ir_util.constant_value(type_ir.size_in_bits) else: element_size = None @@ -333,7 +333,7 @@ def _check_early_type_requirements_for_parameter_type( # bits by default) in expressions, so the physical size would just be # ignored. Integer types do not have "natural" sizes, so the width is # required. - if not physical_type.HasField("size_in_bits"): + if not physical_type.has_field("size_in_bits"): errors.extend( [ [ @@ -346,7 +346,7 @@ def _check_early_type_requirements_for_parameter_type( ] ) elif logical_type.which_type == "enumeration": - if physical_type.HasField("size_in_bits"): + if physical_type.has_field("size_in_bits"): errors.extend( [ [ @@ -399,7 +399,7 @@ def _check_physical_type_requirements( ): """Checks that the given atomic `type_ir` is allowed to be `size` bits.""" referenced_type_definition = ir_util.find_object(type_ir.atomic_type.reference, ir) - if referenced_type_definition.HasField("enumeration"): + if referenced_type_definition.has_field("enumeration"): if size is None: return [ [ @@ -465,7 +465,7 @@ def _check_physical_type_requirements( def _check_allowed_in_bits(type_ir, type_definition, source_file_name, ir, errors): """Verifies that atomic fields have types that are allowed in `bits`.""" - if not type_ir.HasField("atomic_type"): + if not type_ir.has_field("atomic_type"): return referenced_type_definition = ir_util.find_object(type_ir.atomic_type.reference, ir) if ( diff --git a/compiler/front_end/expression_bounds.py b/compiler/front_end/expression_bounds.py index 605ae4d5..64e93fa3 100644 --- a/compiler/front_end/expression_bounds.py +++ b/compiler/front_end/expression_bounds.py @@ -149,7 +149,7 @@ def _compute_constraints_of_field_reference(expression, ir): referrent_type = field.type else: referrent_type = field.physical_type_alias - if referrent_type.HasField("size_in_bits"): + if referrent_type.has_field("size_in_bits"): type_size = ir_util.constant_value(referrent_type.size_in_bits) elif isinstance(field, ir_data.Field): field_size = ir_util.constant_value(field.location.size) @@ -159,7 +159,7 @@ def _compute_constraints_of_field_reference(expression, ir): type_size = field_size * type_definition.addressable_unit else: type_size = None - assert referrent_type.HasField("atomic_type"), field + assert referrent_type.has_field("atomic_type"), field assert not referrent_type.atomic_type.reference.canonical_name.module_file _set_integer_constraints_from_physical_type( expression, referrent_type, type_size @@ -668,7 +668,7 @@ def _compute_constraints_of_choice_operator(expression): """Computes the constraints of a choice operation '?:'.""" condition, if_true, if_false = ir_data_utils.reader(expression).function.args expression = ir_data_utils.builder(expression) - if condition.type.boolean.HasField("value"): + if condition.type.boolean.has_field("value"): # The generated expressions for $size_in_bits and $size_in_bytes look like # # $max((field1_existence_condition ? field1_start + field1_size : 0), diff --git a/compiler/front_end/expression_bounds_test.py b/compiler/front_end/expression_bounds_test.py index e5bc25d5..d6428b7a 100644 --- a/compiler/front_end/expression_bounds_test.py +++ b/compiler/front_end/expression_bounds_test.py @@ -44,7 +44,7 @@ def test_boolean_constant(self): ir = self._make_ir("struct Foo:\n" " if true:\n" " 0 [+1] UInt x\n") self.assertEqual([], expression_bounds.compute_constants(ir)) expression = ir.module[0].type[0].structure.field[0].existence_condition - self.assertTrue(expression.type.boolean.HasField("value")) + self.assertTrue(expression.type.boolean.has_field("value")) self.assertTrue(expression.type.boolean.value) def test_constant_equality(self): @@ -59,9 +59,9 @@ def test_constant_equality(self): structure = ir.module[0].type[0].structure true_condition = structure.field[0].existence_condition false_condition = structure.field[1].existence_condition - self.assertTrue(true_condition.type.boolean.HasField("value")) + self.assertTrue(true_condition.type.boolean.has_field("value")) self.assertTrue(true_condition.type.boolean.value) - self.assertTrue(false_condition.type.boolean.HasField("value")) + self.assertTrue(false_condition.type.boolean.has_field("value")) self.assertFalse(false_condition.type.boolean.value) def test_constant_inequality(self): @@ -76,9 +76,9 @@ def test_constant_inequality(self): structure = ir.module[0].type[0].structure false_condition = structure.field[0].existence_condition true_condition = structure.field[1].existence_condition - self.assertTrue(false_condition.type.boolean.HasField("value")) + self.assertTrue(false_condition.type.boolean.has_field("value")) self.assertFalse(false_condition.type.boolean.value) - self.assertTrue(true_condition.type.boolean.HasField("value")) + self.assertTrue(true_condition.type.boolean.has_field("value")) self.assertTrue(true_condition.type.boolean.value) def test_constant_less_than(self): @@ -96,11 +96,11 @@ def test_constant_less_than(self): greater_than_condition = structure.field[0].existence_condition equal_condition = structure.field[1].existence_condition less_than_condition = structure.field[2].existence_condition - self.assertTrue(greater_than_condition.type.boolean.HasField("value")) + self.assertTrue(greater_than_condition.type.boolean.has_field("value")) self.assertFalse(greater_than_condition.type.boolean.value) - self.assertTrue(equal_condition.type.boolean.HasField("value")) + self.assertTrue(equal_condition.type.boolean.has_field("value")) self.assertFalse(equal_condition.type.boolean.value) - self.assertTrue(less_than_condition.type.boolean.HasField("value")) + self.assertTrue(less_than_condition.type.boolean.has_field("value")) self.assertTrue(less_than_condition.type.boolean.value) def test_constant_less_than_or_equal(self): @@ -118,11 +118,11 @@ def test_constant_less_than_or_equal(self): greater_than_condition = structure.field[0].existence_condition equal_condition = structure.field[1].existence_condition less_than_condition = structure.field[2].existence_condition - self.assertTrue(greater_than_condition.type.boolean.HasField("value")) + self.assertTrue(greater_than_condition.type.boolean.has_field("value")) self.assertFalse(greater_than_condition.type.boolean.value) - self.assertTrue(equal_condition.type.boolean.HasField("value")) + self.assertTrue(equal_condition.type.boolean.has_field("value")) self.assertTrue(equal_condition.type.boolean.value) - self.assertTrue(less_than_condition.type.boolean.HasField("value")) + self.assertTrue(less_than_condition.type.boolean.has_field("value")) self.assertTrue(less_than_condition.type.boolean.value) def test_constant_greater_than(self): @@ -140,11 +140,11 @@ def test_constant_greater_than(self): greater_than_condition = structure.field[0].existence_condition equal_condition = structure.field[1].existence_condition less_than_condition = structure.field[2].existence_condition - self.assertTrue(greater_than_condition.type.boolean.HasField("value")) + self.assertTrue(greater_than_condition.type.boolean.has_field("value")) self.assertTrue(greater_than_condition.type.boolean.value) - self.assertTrue(equal_condition.type.boolean.HasField("value")) + self.assertTrue(equal_condition.type.boolean.has_field("value")) self.assertFalse(equal_condition.type.boolean.value) - self.assertTrue(less_than_condition.type.boolean.HasField("value")) + self.assertTrue(less_than_condition.type.boolean.has_field("value")) self.assertFalse(less_than_condition.type.boolean.value) def test_constant_greater_than_or_equal(self): @@ -162,11 +162,11 @@ def test_constant_greater_than_or_equal(self): greater_than_condition = structure.field[0].existence_condition equal_condition = structure.field[1].existence_condition less_than_condition = structure.field[2].existence_condition - self.assertTrue(greater_than_condition.type.boolean.HasField("value")) + self.assertTrue(greater_than_condition.type.boolean.has_field("value")) self.assertTrue(greater_than_condition.type.boolean.value) - self.assertTrue(equal_condition.type.boolean.HasField("value")) + self.assertTrue(equal_condition.type.boolean.has_field("value")) self.assertTrue(equal_condition.type.boolean.value) - self.assertTrue(less_than_condition.type.boolean.HasField("value")) + self.assertTrue(less_than_condition.type.boolean.has_field("value")) self.assertFalse(less_than_condition.type.boolean.value) def test_constant_and(self): @@ -187,13 +187,13 @@ def test_constant_and(self): true_false_condition = structure.field[1].existence_condition false_true_condition = structure.field[2].existence_condition true_true_condition = structure.field[3].existence_condition - self.assertTrue(false_false_condition.type.boolean.HasField("value")) + self.assertTrue(false_false_condition.type.boolean.has_field("value")) self.assertFalse(false_false_condition.type.boolean.value) - self.assertTrue(true_false_condition.type.boolean.HasField("value")) + self.assertTrue(true_false_condition.type.boolean.has_field("value")) self.assertFalse(true_false_condition.type.boolean.value) - self.assertTrue(false_true_condition.type.boolean.HasField("value")) + self.assertTrue(false_true_condition.type.boolean.has_field("value")) self.assertFalse(false_true_condition.type.boolean.value) - self.assertTrue(true_true_condition.type.boolean.HasField("value")) + self.assertTrue(true_true_condition.type.boolean.has_field("value")) self.assertTrue(true_true_condition.type.boolean.value) def test_constant_or(self): @@ -214,13 +214,13 @@ def test_constant_or(self): true_false_condition = structure.field[1].existence_condition false_true_condition = structure.field[2].existence_condition true_true_condition = structure.field[3].existence_condition - self.assertTrue(false_false_condition.type.boolean.HasField("value")) + self.assertTrue(false_false_condition.type.boolean.has_field("value")) self.assertFalse(false_false_condition.type.boolean.value) - self.assertTrue(true_false_condition.type.boolean.HasField("value")) + self.assertTrue(true_false_condition.type.boolean.has_field("value")) self.assertTrue(true_false_condition.type.boolean.value) - self.assertTrue(false_true_condition.type.boolean.HasField("value")) + self.assertTrue(false_true_condition.type.boolean.has_field("value")) self.assertTrue(false_true_condition.type.boolean.value) - self.assertTrue(true_true_condition.type.boolean.HasField("value")) + self.assertTrue(true_true_condition.type.boolean.has_field("value")) self.assertTrue(true_true_condition.type.boolean.value) def test_enum_constant(self): @@ -276,7 +276,7 @@ def test_non_constant_equality(self): self.assertEqual([], expression_bounds.compute_constants(ir)) structure = ir.module[0].type[0].structure condition = structure.field[0].existence_condition - self.assertFalse(condition.type.boolean.HasField("value")) + self.assertFalse(condition.type.boolean.has_field("value")) def test_constant_addition(self): ir = self._make_ir("struct Foo:\n" " 7+5 [+1] UInt x\n") @@ -864,7 +864,7 @@ def test_constant_false_has(self): self.assertEqual([], expression_bounds.compute_constants(ir)) field = ir.module[0].type[0].structure.field[0] has_func = field.existence_condition - self.assertTrue(has_func.type.boolean.HasField("value")) + self.assertTrue(has_func.type.boolean.has_field("value")) self.assertFalse(has_func.type.boolean.value) def test_variable_has(self): @@ -881,7 +881,7 @@ def test_variable_has(self): self.assertEqual([], expression_bounds.compute_constants(ir)) field = ir.module[0].type[0].structure.field[0] has_func = field.existence_condition - self.assertFalse(has_func.type.boolean.HasField("value")) + self.assertFalse(has_func.type.boolean.has_field("value")) def test_max_of_constants(self): ir = self._make_ir( @@ -1008,7 +1008,7 @@ def test_choice_non_integer_arguments(self): self.assertEqual([], expression_bounds.compute_constants(ir)) expr = ir.module[0].type[0].structure.field[1].existence_condition self.assertEqual("boolean", expr.type.which_type) - self.assertFalse(expr.type.boolean.HasField("value")) + self.assertFalse(expr.type.boolean.has_field("value")) def test_uint_value_range_for_explicit_size(self): ir = self._make_ir( diff --git a/compiler/front_end/module_ir.py b/compiler/front_end/module_ir.py index 633c1b84..28717972 100644 --- a/compiler/front_end/module_ir.py +++ b/compiler/front_end/module_ir.py @@ -1179,10 +1179,10 @@ def _inline_type_field(location, name, abbreviation, body): if abbreviation.list: field.abbreviation.CopyFrom(abbreviation.list[0]) body.source_location = parser_types.merge_source_locations(location, body) - if body.HasField("enumeration"): + if body.has_field("enumeration"): ir_data_utils.builder(body.enumeration).source_location = body.source_location else: - assert body.HasField("structure") + assert body.has_field("structure") ir_data_utils.builder(body.structure).source_location = body.source_location ir_data_utils.builder(body).name.CopyFrom(type_name) field.source_location = parser_types.merge_source_locations(location, body) diff --git a/compiler/front_end/module_ir_test.py b/compiler/front_end/module_ir_test.py index fa8db9cd..f4faeddb 100644 --- a/compiler/front_end/module_ir_test.py +++ b/compiler/front_end/module_ir_test.py @@ -3996,7 +3996,7 @@ def _check_all_source_locations(proto, path="", min_start=None, max_end=None): child_end = None # Only check the source_location value if this proto message actually has a # source_location field. - if proto.HasField("source_location"): + if proto.has_field("source_location"): errors.extend( _check_source_location( proto.source_location, path + "source_location", min_start, max_end @@ -4008,7 +4008,7 @@ def _check_all_source_locations(proto, path="", min_start=None, max_end=None): for name, spec in ir_data_fields.field_specs(proto).items(): if name == "source_location": continue - if not proto.HasField(name): + if not proto.has_field(name): continue field_path = "{}{}".format(path, name) if spec.is_dataclass: diff --git a/compiler/front_end/symbol_resolver.py b/compiler/front_end/symbol_resolver.py index bb3bf5b4..9f46ff34 100644 --- a/compiler/front_end/symbol_resolver.py +++ b/compiler/front_end/symbol_resolver.py @@ -161,7 +161,7 @@ def _add_struct_field_to_scope(field, scope, errors): new_scope = _add_name_to_scope_and_normalize( field.name, scope, _Scope.LOCAL, errors ) - if field.HasField("abbreviation"): + if field.has_field("abbreviation"): _add_name_to_scope( field.abbreviation, scope, new_scope.canonical_name, _Scope.PRIVATE, errors ) @@ -331,7 +331,7 @@ def _resolve_reference( reference, table, current_scope, visible_scopes, source_file_name, errors ): """Sets the canonical name of the given reference.""" - if reference.HasField("canonical_name"): + if reference.has_field("canonical_name"): # This reference has already been resolved by the _resolve_field_reference # pass. return @@ -453,7 +453,7 @@ def _find_target_of_reference( def _resolve_field_reference(field_reference, source_file_name, errors, ir): """Resolves the References inside of a FieldReference.""" - if field_reference.path[-1].HasField("canonical_name"): + if field_reference.path[-1].has_field("canonical_name"): # Already done. return previous_field = ir_util.find_object_or_none(field_reference.path[0], ir) @@ -476,7 +476,7 @@ def _resolve_field_reference(field_reference, source_file_name, errors, ir): # field, then bail. Otherwise we get a cascade of errors, where an # error in `x` leads to errors in anything trying to reach a member of # `x`. - if not previous_field.read_transform.field_reference.path[-1].HasField( + if not previous_field.read_transform.field_reference.path[-1].has_field( "canonical_name" ): return diff --git a/compiler/front_end/symbol_resolver_test.py b/compiler/front_end/symbol_resolver_test.py index ddf7783c..4a50feb0 100644 --- a/compiler/front_end/symbol_resolver_test.py +++ b/compiler/front_end/symbol_resolver_test.py @@ -159,7 +159,7 @@ def test_struct_parameter_resolution(self): self.assertEqual([], symbol_resolver.resolve_symbols(ir)) struct_ir = ir.module[0].type[6].structure size_ir = struct_ir.field[0].location.size - self.assertTrue(size_ir.HasField("field_reference")) + self.assertTrue(size_ir.has_field("field_reference")) self.assertEqual( size_ir.field_reference.path[0].canonical_name.object_path, ["UsesParameter", "x"], @@ -552,8 +552,8 @@ def test_resolution_against_anonymous_bits(self): struct1_byte_field = struct1.structure.field[4] inner_bits = struct1.subtype[0] inner_enum = struct1.subtype[1] - self.assertTrue(inner_bits.HasField("structure")) - self.assertTrue(inner_enum.HasField("enumeration")) + self.assertTrue(inner_bits.has_field("structure")) + self.assertTrue(inner_enum.has_field("enumeration")) self.assertTrue(inner_bits.name.is_anonymous) self.assertFalse(inner_enum.name.is_anonymous) self.assertEqual( diff --git a/compiler/front_end/synthetics.py b/compiler/front_end/synthetics.py index 94688d48..dc231773 100644 --- a/compiler/front_end/synthetics.py +++ b/compiler/front_end/synthetics.py @@ -142,7 +142,7 @@ def _add_anonymous_aliases(structure, type_definition): existence_condition=new_existence_condition, name=ir_data_utils.copy(subfield.name), ) - if subfield.HasField("abbreviation"): + if subfield.has_field("abbreviation"): ir_data_utils.builder(new_alias).abbreviation.CopyFrom( subfield.abbreviation ) @@ -153,7 +153,7 @@ def _add_anonymous_aliases(structure, type_definition): # original field's name(s) as synthetic, to avoid duplicate error # messages. _mark_as_synthetic(subfield.name) - if subfield.HasField("abbreviation"): + if subfield.has_field("abbreviation"): _mark_as_synthetic(subfield.abbreviation) del structure.field[:] structure.field.extend(new_fields) @@ -239,7 +239,7 @@ def _maybe_replace_next_keyword_in_expression( expression_ir, last_location, source_file_name, errors ): """Replaces the `$next` keyword in an expression.""" - if not expression_ir.HasField("builtin_reference"): + if not expression_ir.has_field("builtin_reference"): return if ( ir_data_utils.reader( @@ -270,7 +270,7 @@ def _maybe_replace_next_keyword_in_expression( def _check_for_bad_next_keyword_in_size(expression, source_file_name, errors): - if not expression.HasField("builtin_reference"): + if not expression.has_field("builtin_reference"): return if expression.builtin_reference.canonical_name.object_path[0] != "$next": return diff --git a/compiler/front_end/synthetics_test.py b/compiler/front_end/synthetics_test.py index ac8e6714..7e71bb9c 100644 --- a/compiler/front_end/synthetics_test.py +++ b/compiler/front_end/synthetics_test.py @@ -64,12 +64,12 @@ def test_adds_anonymous_bits_fields(self): self.assertEqual([], synthetics.desugar(ir)) structure = ir.module[0].type[0].structure # The first field should be the anonymous bits structure. - self.assertTrue(structure.field[0].HasField("location")) + self.assertTrue(structure.field[0].has_field("location")) # Then the aliases generated for those structures. self.assertEqual("bar", structure.field[1].name.name.text) self.assertEqual("uint", structure.field[2].name.name.text) # Then the second anonymous bits. - self.assertTrue(structure.field[3].HasField("location")) + self.assertTrue(structure.field[3].has_field("location")) # Then the alias from the second anonymous bits. self.assertEqual("nested_bits", structure.field[4].name.name.text) @@ -145,7 +145,7 @@ def test_adds_correct_abbreviation(self): self.assertEqual([], synthetics.desugar(ir)) bar_alias = ir.module[0].type[0].structure.field[1] baz_alias = ir.module[0].type[0].structure.field[2] - self.assertFalse(bar_alias.HasField("abbreviation")) + self.assertFalse(bar_alias.has_field("abbreviation")) self.assertEqual("qux", baz_alias.abbreviation.text) def test_anonymous_bits_sets_correct_is_synthetic(self): @@ -156,9 +156,9 @@ def test_anonymous_bits_sets_correct_is_synthetic(self): bits_field = ir.module[0].type[0].subtype[0].structure.field[0] alias_field = ir.module[0].type[0].structure.field[1] self.assertFalse(alias_field.name.source_location.is_synthetic) - self.assertTrue(alias_field.HasField("abbreviation")) + self.assertTrue(alias_field.has_field("abbreviation")) self.assertFalse(alias_field.abbreviation.source_location.is_synthetic) - self.assertTrue(alias_field.HasField("read_transform")) + self.assertTrue(alias_field.has_field("read_transform")) read_alias = alias_field.read_transform self.assertTrue(read_alias.source_location.is_synthetic) self.assertTrue(read_alias.field_reference.path[0].source_location.is_synthetic) @@ -265,7 +265,7 @@ def test_replaces_next(self): ) self.assertEqual([], synthetics.desugar(ir)) offset_of_b = ir.module[0].type[0].structure.field[1].location.start - self.assertTrue(offset_of_b.HasField("function")) + self.assertTrue(offset_of_b.has_field("function")) self.assertEqual( offset_of_b.function.function, ir_data.FunctionMapping.ADDITION ) diff --git a/compiler/front_end/type_check.py b/compiler/front_end/type_check.py index ce4155d2..119d8cf4 100644 --- a/compiler/front_end/type_check.py +++ b/compiler/front_end/type_check.py @@ -286,7 +286,7 @@ def _type_check_local_reference(expression, ir, errors): ) ir_data_utils.builder(expression).type.CopyFrom(field.read_transform.type) return - if not field.type.HasField("atomic_type"): + if not field.type.has_field("atomic_type"): ir_data_utils.builder(expression).type.opaque.CopyFrom(ir_data.OpaqueType()) else: _set_expression_type_from_physical_type_reference( @@ -313,7 +313,7 @@ def unbounded_expression_type_for_physical_type(type_definition): elif tuple(type_definition.name.canonical_name.object_path) == ("Flag",): # This is a hack: the Flag type should say that it is a boolean. return ir_data.ExpressionType(boolean=ir_data.BooleanType()) - elif type_definition.HasField("enumeration"): + elif type_definition.has_field("enumeration"): return ir_data.ExpressionType( enumeration=ir_data.EnumType( name=ir_data.Reference( diff --git a/compiler/front_end/type_check_test.py b/compiler/front_end/type_check_test.py index 766f9e89..dfa5663f 100644 --- a/compiler/front_end/type_check_test.py +++ b/compiler/front_end/type_check_test.py @@ -410,7 +410,7 @@ def test_choice_of_enums(self): expression = ir.module[0].type[0].structure.field[1].location.size self.assertEqual([], error.filter_errors(type_check.annotate_types(ir))) self.assertEqual("enumeration", expression.type.which_type) - self.assertFalse(expression.type.enumeration.HasField("value")) + self.assertFalse(expression.type.enumeration.has_field("value")) self.assertEqual( "m.emb", expression.type.enumeration.name.canonical_name.module_file ) diff --git a/compiler/front_end/write_inference.py b/compiler/front_end/write_inference.py index 4af5ba14..d50b62b4 100644 --- a/compiler/front_end/write_inference.py +++ b/compiler/front_end/write_inference.py @@ -213,7 +213,7 @@ def _add_write_method(field, ir): Returns: None """ - if field.HasField("write_method"): + if field.has_field("write_method"): # Do not recompute anything. return diff --git a/compiler/front_end/write_inference_test.py b/compiler/front_end/write_inference_test.py index f4ea8bf3..3db22f0c 100644 --- a/compiler/front_end/write_inference_test.py +++ b/compiler/front_end/write_inference_test.py @@ -46,7 +46,7 @@ def test_adds_alias_write_method_to_alias_of_physical_field(self): ir = self._make_ir("struct Foo:\n" " let x = y\n" " 0 [+1] UInt y\n") self.assertEqual([], write_inference.set_write_methods(ir)) field = ir.module[0].type[0].structure.field[0] - self.assertTrue(field.write_method.HasField("alias")) + self.assertTrue(field.write_method.has_field("alias")) self.assertEqual( "y", field.write_method.alias.path[0].canonical_name.object_path[-1] ) @@ -57,7 +57,7 @@ def test_adds_alias_write_method_to_alias_of_alias_of_physical_field(self): ) self.assertEqual([], write_inference.set_write_methods(ir)) field = ir.module[0].type[0].structure.field[0] - self.assertTrue(field.write_method.HasField("alias")) + self.assertTrue(field.write_method.has_field("alias")) self.assertEqual( "z", field.write_method.alias.path[0].canonical_name.object_path[-1] ) diff --git a/compiler/util/attribute_util.py b/compiler/util/attribute_util.py index d20f1913..506459c0 100644 --- a/compiler/util/attribute_util.py +++ b/compiler/util/attribute_util.py @@ -40,7 +40,7 @@ def _attribute_name_for_errors(attr): # Attribute type checkers def _is_constant_boolean(attr, module_source_file): """Checks if the given attr is a constant boolean.""" - if not attr.value.expression.type.boolean.HasField("value"): + if not attr.value.expression.type.boolean.has_field("value"): return [ [ error.error( @@ -75,7 +75,7 @@ def _is_boolean(attr, module_source_file): def _is_constant_integer(attr, module_source_file): """Checks if the given attr is an integer constant expression.""" if ( - not attr.value.HasField("expression") + not attr.value.has_field("expression") or attr.value.expression.type.which_type != "integer" ): return [ @@ -106,7 +106,7 @@ def _is_constant_integer(attr, module_source_file): def _is_string(attr, module_source_file): """Checks if the given attr is a string.""" - if not attr.value.HasField("string_constant"): + if not attr.value.has_field("string_constant"): return [ [ error.error( @@ -217,7 +217,7 @@ def check_module(module, errors): ) def check_type_definition(type_definition, source_file_name, errors): - if type_definition.HasField("structure"): + if type_definition.has_field("structure"): if type_definition.addressable_unit == ir_data.AddressableUnit.BYTE: errors.extend( _check_attributes( @@ -244,7 +244,7 @@ def check_type_definition(type_definition, source_file_name, errors): assert False, "Unexpected addressable_unit '{}'".format( type_definition.addressable_unit ) - elif type_definition.HasField("enumeration"): + elif type_definition.has_field("enumeration"): errors.extend( _check_attributes( type_definition.attribute, @@ -255,7 +255,7 @@ def check_type_definition(type_definition, source_file_name, errors): source_file_name, ) ) - elif type_definition.HasField("external"): + elif type_definition.has_field("external"): errors.extend( _check_attributes( type_definition.attribute, diff --git a/compiler/util/ir_data.py b/compiler/util/ir_data.py index d37c48a8..7c9bf217 100644 --- a/compiler/util/ir_data.py +++ b/compiler/util/ir_data.py @@ -103,8 +103,7 @@ def __setattr__(self, name: str, value) -> None: ) object.__setattr__(self, name, value) - # Non-PEP8 name to mimic the Google Protobuf interface. - def HasField(self, name): # pylint:disable=invalid-name + def has_field(self, name): """Indicates if this class has the given field defined and it is set.""" return getattr(self, name, None) is not None diff --git a/compiler/util/ir_data_utils.py b/compiler/util/ir_data_utils.py index f4c9575a..529c9a4d 100644 --- a/compiler/util/ir_data_utils.py +++ b/compiler/util/ir_data_utils.py @@ -283,7 +283,7 @@ def __getattribute__(self, name: str) -> Any: if ir is None: return object.__getattribute__(self, name) - if name in ("HasField",): + if name in ("has_field",): return getattr(ir, name) field_spec = field_specs(ir).get(name) @@ -366,7 +366,7 @@ def __getattribute__( spec = field_specs(field_type).get(name) if not spec: if isinstance(ir_or_spec, ir_data_fields.FieldSpec): - if name == "HasField": + if name == "has_field": return lambda x: False # This *should* be limited to only the `which_` attributes that # correspond to real oneofs, but that would add complexity and diff --git a/compiler/util/ir_data_utils_test.py b/compiler/util/ir_data_utils_test.py index 2cadf060..8475e01d 100644 --- a/compiler/util/ir_data_utils_test.py +++ b/compiler/util/ir_data_utils_test.py @@ -255,7 +255,7 @@ def test_ir_data_builder(self): """Tests that basic builder chains work.""" # We start with an empty type type_def = ir_data.TypeDefinition() - self.assertFalse(type_def.HasField("name")) + self.assertFalse(type_def.has_field("name")) self.assertIsNone(type_def.name) # Now setup a builder @@ -282,7 +282,7 @@ def test_ir_data_builder_sequence(self): """Tests that sequences are properly wrapped.""" # We start with an empty type type_def = ir_data.TypeDefinition() - self.assertTrue(type_def.HasField("attribute")) + self.assertTrue(type_def.has_field("attribute")) self.assertEmpty(type_def.attribute) # Now setup a builder @@ -296,7 +296,7 @@ def test_ir_data_builder_sequence(self): builder.attribute.append(attribute) self.assertEqual(builder.attribute, [attribute]) - self.assertTrue(type_def.HasField("attribute")) + self.assertTrue(type_def.has_field("attribute")) self.assertLen(type_def.attribute, 1) self.assertEqual(type_def.attribute[0], attribute) @@ -392,7 +392,7 @@ def test_ir_data_builder_sequence_scalar(self): builder.fields_in_dependency_order.append(12) builder.fields_in_dependency_order.append(11) - self.assertTrue(structure.HasField("fields_in_dependency_order")) + self.assertTrue(structure.has_field("fields_in_dependency_order")) self.assertLen(structure.fields_in_dependency_order, 2) self.assertEqual(structure.fields_in_dependency_order[0], 12) self.assertEqual(structure.fields_in_dependency_order[1], 11) @@ -406,7 +406,7 @@ def test_ir_data_builder_oneof(self): expression=ir_data.Expression(boolean_constant=ir_data.BooleanConstant()) ) builder = ir_data_utils.builder(value) - self.assertTrue(builder.HasField("expression")) + self.assertTrue(builder.has_field("expression")) self.assertFalse(builder.expression.boolean_constant.value) builder.expression.boolean_constant.value = True self.assertTrue(builder.expression.boolean_constant.value) @@ -580,12 +580,12 @@ def test_basic_wrapper(self): # Scalar field should pass through self.assertEqual(field_checker.non_union_field, 10) - # Make sure HasField works - self.assertTrue(field_checker.HasField("opaque")) - self.assertFalse(field_checker.HasField("integer")) - self.assertTrue(field_checker.HasField("boolean")) - self.assertFalse(field_checker.HasField("enumeration")) - self.assertTrue(field_checker.HasField("non_union_field")) + # Make sure has_field works + self.assertTrue(field_checker.has_field("opaque")) + self.assertFalse(field_checker.has_field("integer")) + self.assertTrue(field_checker.has_field("boolean")) + self.assertFalse(field_checker.has_field("enumeration")) + self.assertTrue(field_checker.has_field("non_union_field")) def test_construct_from_field_checker(self): """Tests that constructing from another field checker works.""" @@ -604,12 +604,12 @@ def test_construct_from_field_checker(self): # Scalar field should pass through self.assertEqual(field_checker.non_union_field, 10) - # Make sure HasField works - self.assertTrue(field_checker.HasField("opaque")) - self.assertFalse(field_checker.HasField("integer")) - self.assertTrue(field_checker.HasField("boolean")) - self.assertFalse(field_checker.HasField("enumeration")) - self.assertTrue(field_checker.HasField("non_union_field")) + # Make sure has_field works + self.assertTrue(field_checker.has_field("opaque")) + self.assertFalse(field_checker.has_field("integer")) + self.assertTrue(field_checker.has_field("boolean")) + self.assertFalse(field_checker.has_field("enumeration")) + self.assertTrue(field_checker.has_field("non_union_field")) def test_read_only(self) -> None: """Tests that the read only wrapper really is read only.""" diff --git a/compiler/util/ir_util.py b/compiler/util/ir_util.py index c1de244c..e8e8b8fd 100644 --- a/compiler/util/ir_util.py +++ b/compiler/util/ir_util.py @@ -49,7 +49,7 @@ def get_boolean_attribute(attribute_list, name, default_value=None): requested attribute is not found or has a non-boolean value. """ attribute_value = get_attribute(attribute_list, name) - if not attribute_value or not attribute_value.expression.HasField( + if not attribute_value or not attribute_value.expression.has_field( "boolean_constant" ): return default_value @@ -88,8 +88,8 @@ def is_constant_type(expression_type): expression_type = ir_data_utils.reader(expression_type) return ( expression_type.integer.modulus == "infinity" - or expression_type.boolean.HasField("value") - or expression_type.enumeration.HasField("value") + or expression_type.boolean.has_field("value") + or expression_type.enumeration.has_field("value") ) @@ -108,10 +108,10 @@ def constant_value(expression, bindings=None): assert expression.type.integer.modulus == "infinity" return int(expression.type.integer.modular_value) elif expression.type.which_type == "boolean": - assert expression.type.boolean.HasField("value") + assert expression.type.boolean.has_field("value") return expression.type.boolean.value elif expression.type.which_type == "enumeration": - assert expression.type.enumeration.HasField("value") + assert expression.type.enumeration.has_field("value") return int(expression.type.enumeration.value) else: assert False, "Unexpected expression type {}".format( @@ -239,7 +239,7 @@ def hashable_form_of_field_reference(field_reference): def is_array(type_ir): """Returns true if type_ir is an array type.""" - return type_ir.HasField("array_type") + return type_ir.has_field("array_type") def _find_path_in_structure_field(path, field): @@ -265,7 +265,7 @@ def _find_path_in_enumeration(path, type_definition): def _find_path_in_parameters(path, type_definition): - if len(path) > 1 or not type_definition.HasField("runtime_parameter"): + if len(path) > 1 or not type_definition.has_field("runtime_parameter"): return None for parameter in type_definition.runtime_parameter: if ir_data_utils.reader(parameter).name.name.text == path[0]: @@ -280,9 +280,9 @@ def _find_path_in_type_definition(path, type_definition): obj = _find_path_in_parameters(path, type_definition) if obj: return obj - if type_definition.HasField("structure"): + if type_definition.has_field("structure"): obj = _find_path_in_structure(path, type_definition) - elif type_definition.HasField("enumeration"): + elif type_definition.has_field("enumeration"): obj = _find_path_in_enumeration(path, type_definition) if obj: return obj @@ -348,9 +348,9 @@ def get_base_type(type_ir): type_ir corresponds to an array type (like "UInt:8[12]" or "Square[8][8]"), returns the type after stripping off the array types ("UInt" or "Square"). """ - while type_ir.HasField("array_type"): + while type_ir.has_field("array_type"): type_ir = type_ir.array_type.base_type - assert type_ir.HasField("atomic_type"), "Unknown kind of type {}".format(type_ir) + assert type_ir.has_field("atomic_type"), "Unknown kind of type {}".format(type_ir) return type_ir @@ -365,7 +365,7 @@ def fixed_size_of_type_in_bits(type_ir, ir): size if the size of the type can be determined, otherwise None. """ array_multiplier = 1 - while type_ir.HasField("array_type"): + while type_ir.has_field("array_type"): if type_ir.array_type.which_size == "automatic": return None else: @@ -377,12 +377,12 @@ def fixed_size_of_type_in_bits(type_ir, ir): return None else: array_multiplier *= constant_value(element_count) - assert not type_ir.HasField( + assert not type_ir.has_field( "size_in_bits" ), "TODO(bolms): implement explicitly-sized arrays" type_ir = type_ir.array_type.base_type - assert type_ir.HasField("atomic_type"), "Unexpected type!" - if type_ir.HasField("size_in_bits"): + assert type_ir.has_field("atomic_type"), "Unexpected type!" + if type_ir.has_field("size_in_bits"): size = constant_value(type_ir.size_in_bits) else: type_definition = find_object(type_ir.atomic_type.reference, ir) @@ -397,7 +397,7 @@ def field_is_virtual(field_ir): """Returns true if the field is virtual.""" # TODO(bolms): Should there be a more explicit indicator that a field is # virtual? - return not field_ir.HasField("location") + return not field_ir.has_field("location") def field_is_read_only(field_ir): diff --git a/compiler/util/test_util.py b/compiler/util/test_util.py index f0a7a9c7..23ffa784 100644 --- a/compiler/util/test_util.py +++ b/compiler/util/test_util.py @@ -51,7 +51,7 @@ def proto_is_superset(proto, expected_values, path=""): name = spec.name field_path = "{}{}".format(path, name) value = getattr(proto, name) - if expected_values.HasField(name) and not proto.HasField(name): + if expected_values.has_field(name) and not proto.has_field(name): return False, "{} missing".format(field_path) if spec.is_dataclass: if spec.is_sequence: diff --git a/compiler/util/traverse_ir.py b/compiler/util/traverse_ir.py index bf83392a..7423e634 100644 --- a/compiler/util/traverse_ir.py +++ b/compiler/util/traverse_ir.py @@ -158,7 +158,7 @@ def _fast_traverse_proto_top_down( type(proto), new_pattern[0] ] for member_name in singular_fields: - if proto.HasField(member_name): + if proto.has_field(member_name): _fast_traverse_proto_top_down( getattr(proto, member_name), incidental_actions, diff --git a/compiler/util/traverse_ir_test.py b/compiler/util/traverse_ir_test.py index 504eb88e..05214fe5 100644 --- a/compiler/util/traverse_ir_test.py +++ b/compiler/util/traverse_ir_test.py @@ -205,11 +205,11 @@ def _record_location_parameter_and_constant(constant, constant_list, location=No def _record_kind_and_constant(constant, constant_list, type_definition): - if type_definition.HasField("enumeration"): + if type_definition.has_field("enumeration"): constant_list.append(("enumeration", int(constant.value))) - elif type_definition.HasField("structure"): + elif type_definition.has_field("structure"): constant_list.append(("structure", int(constant.value))) - elif type_definition.HasField("external"): + elif type_definition.has_field("external"): constant_list.append(("external", int(constant.value))) else: assert False, "Shouldn't be here." diff --git a/doc/design.md b/doc/design.md index 13e4b94b..017fe5cf 100644 --- a/doc/design.md +++ b/doc/design.md @@ -8,9 +8,9 @@ this document. The Emboss compiler is divided into separate "front end" and "back end" programs. The front end parses Emboss files (`.emb` files) and produces a stable intermediate representation (IR), which is consumed by the back ends. -This IR is defined in [public/ir_data.py][ir_pb2_py]. +This IR is defined in [public/ir_data.py][ir_data]. -[ir_pb2_py]: public/ir_data.py +[ir_data]: public/ir_data.py The back ends read the IR and emit code to view and manipulate Emboss-defined data structures. Currently, only a C++ back-end exists.