def StructFieldFromMojom(self, ordinal, mojom_field): """Translates a fidl_types_fidl.StructField to a module.StructField. Args: ordinal: {int} The 0-based ordinal position of the field within the struct. Note that this is not necessarily the same as the lexical order or the packing order. mojom_field: {fidl_types_fidl.StructField} to be translated. Returns: {module.StructField} translated from mojom_field. """ struct_field = module.StructField() self.PopulateCommonFieldValues(struct_field, mojom_field) struct_field.computed_offset = mojom_field.offset struct_field.computed_bit = mojom_field.bit struct_field.computed_min_version = mojom_field.min_version # Note that the |ordinal| attribute of |struct_field| records only the # *declared* ordinal and as such is not defined for every field whereas # the |computed_ordinal| attribute is defined for every field. If # |ordinal| is defined then it is equal to |computed_ordinal|. struct_field.ordinal = self.OrdinalFromMojom(mojom_field) struct_field.computed_ordinal = ordinal struct_field.declaration_order = mojom_field.decl_data.declaration_order if mojom_field.default_value: if (mojom_field.default_value.tag == fidl_types_fidl.DefaultFieldValue.Tags.default_keyword): struct_field.default = 'default' else: struct_field.default = self.ValueFromMojom( mojom_field.default_value.value) return struct_field
def _StructField(module, parsed_field, struct): """ Args: module: {mojom.Module} Module currently being constructed. parsed_field: {ast.StructField} Parsed struct field. struct: {mojom.Struct} Struct this field belongs to. Returns: {mojom.StructField} AST struct field. """ field = mojom.StructField() field.mojom_name = parsed_field.mojom_name field.kind = _Kind(module.kinds, _MapKind(parsed_field.typename), (module.mojom_namespace, struct.mojom_name)) field.ordinal = parsed_field.ordinal.value if parsed_field.ordinal else None field.default = _FixupExpression( module, parsed_field.default_value, (module.mojom_namespace, struct.mojom_name), field.kind) field.attributes = _AttributeListToDict(parsed_field.attribute_list) return field
def StructFieldFromMojom(self, mojom_field): """Translates a mojom_types_mojom.StructField to a module.StructField. Args: mojom_field: {mojom_types_mojom.StructField} to be translated. Returns: {module.StructField} translated from mojom_field. """ struct_field = module.StructField() self.PopulateCommonFieldValues(struct_field, mojom_field) struct_field.ordinal = self.OrdinalFromMojom(mojom_field) if mojom_field.default_value: if (mojom_field.default_value.tag == mojom_types_mojom.DefaultFieldValue.Tags.default_keyword): struct_field.default = 'default' else: struct_field.default = self.ValueFromMojom( mojom_field.default_value.value) return struct_field
def StructFieldFromData(module, data, struct): field = mojom.StructField() PopulateField(field, module, data, struct) return field