// Returns a tuple of (1) type_metadata_stub of the variant, (2) the llvm_type
// of the variant, and (3) a MemberDescriptionFactory for producing the
// descriptions of the fields of the variant. This is a rudimentary version of a
// full RecursiveTypeDescription.
Returns a tuple of (1) type_metadata_stub of the variant, (2) the llvm_type
of the variant, and (3) a MemberDescriptionFactory for producing the
descriptions of the fields of the variant. This is a rudimentary version of a
full RecursiveTypeDescription.
Returns a tuple of ( 1 ) type_metadata_stub of the variant ( 2 ) the llvm_type of the variant and ( 3 ) a MemberDescriptionFactory for producing the descriptions of the fields of the variant . This is a rudimentary version of a full RecursiveTypeDescription .
fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
                                   enum_type: Ty<'tcx>,
                                   struct_def: &adt::Struct<'tcx>,
                                   variant: ty::VariantDef<'tcx>,
                                   discriminant_info: EnumDiscriminantInfo,
                                   containing_scope: DIScope,
                                   span: Span)
                                   -> (DICompositeType, Type, MemberDescriptionFactory<'tcx>) {
    let variant_llvm_type =
        Type::struct_(cx, &struct_def.fields
                                    .iter()
                                    .map(|&t| type_of::type_of(cx, t))
                                    .collect::<Vec<_>>()
                                    ,
                      struct_def.packed);
    // Could do some consistency checks here: size, align, field count, discr type
    let variant_name = variant.name.as_str();
    let unique_type_id = debug_context(cx).type_map
                                          .borrow_mut()
                                          .get_unique_type_id_of_enum_variant(
                                              cx,
                                              enum_type,
                                              &variant_name);
    let metadata_stub = create_struct_stub(cx,
                                           variant_llvm_type,
                                           &variant_name,
                                           unique_type_id,
                                           containing_scope);
    // Get the argument names from the enum variant info
    let mut arg_names: Vec<_> = match variant.kind {
        ty::VariantKind::Unit => vec![],
        ty::VariantKind::Tuple => {
            variant.fields
                   .iter()
                   .enumerate()
                   .map(|(i, _)| format!("__{}", i))
                   .collect()
        }
        ty::VariantKind::Struct => {
            variant.fields
                   .iter()
                   .map(|f| f.name.to_string())
                   .collect()
        }
    };
    // If this is not a univariant enum, there is also the discriminant field.
    match discriminant_info {
        RegularDiscriminant(_) => arg_names.insert(0, "RUST$ENUM$DISR".to_string()),
        _ => { /* do nothing */ }
    };
    // Build an array of (field name, field type) pairs to be captured in the factory closure.
    let args: Vec<(String, Ty)> = arg_names.iter()
        .zip(&struct_def.fields)
        .map(|(s, &t)| (s.to_string(), t))
        .collect();
    let member_description_factory =
        VariantMDF(VariantMemberDescriptionFactory {
            args: args,
            discriminant_type_metadata: match discriminant_info {
                RegularDiscriminant(discriminant_type_metadata) => {
                    Some(discriminant_type_metadata)
                }
                _ => None
            },
            span: span,
        });
    (metadata_stub, variant_llvm_type, member_description_factory)
}
fn describe_enum_variant < ' a , ' tcx > ( cx : & CrateContext < ' a , ' tcx > , enum_type : Ty < ' tcx > , struct_def : & adt :: Struct < ' tcx > , variant : ty :: VariantDef < ' tcx > , discriminant_info : EnumDiscriminantInfo , containing_scope : DIScope , span : Span ) -> ( DICompositeType , Type , MemberDescriptionFactory < ' tcx > ) { let variant_llvm_type = Type :: struct_ ( cx , & struct_def . fields . iter ( ) . map ( | & t | type_of :: type_of ( cx , t ) ) . collect :: < Vec < _ > > ( ) , struct_def . packed ) ; // Could do some consistency checks here: size, align, field count, discr type let variant_name = variant . name . as_str ( ) ; let unique_type_id = debug_context ( cx ) . type_map . borrow_mut ( ) . get_unique_type_id_of_enum_variant ( cx , enum_type , & variant_name ) ; let metadata_stub = create_struct_stub ( cx , variant_llvm_type , & variant_name , unique_type_id , containing_scope ) ; // Get the argument names from the enum variant info let mut arg_names : Vec < _ > = match variant . kind { ty :: VariantKind :: Unit => vec ! [ ] , ty :: VariantKind :: Tuple => { variant . fields . iter ( ) . enumerate ( ) . map ( | ( i , _ ) | format ! ( " " i ) ) . collect ( ) } ty :: VariantKind :: Struct => { variant . fields . iter ( ) . map ( | f | f . name . to_string ( ) ) . collect ( ) } } ; // If this is not a univariant enum, there is also the discriminant field. match discriminant_info { RegularDiscriminant ( _ ) => arg_names . insert ( 0 , " " . to_string ( ) ) , _ => { /* do nothing */ } } ; // Build an array of (field name, field type) pairs to be captured in the factory closure. let args : Vec < ( String , Ty ) > = arg_names . iter ( ) . zip ( & struct_def . fields ) . map ( | ( s , & t ) | ( s . to_string ( ) , t ) ) . collect ( ) ; let member_description_factory = VariantMDF ( VariantMemberDescriptionFactory { args : args , discriminant_type_metadata : match discriminant_info { RegularDiscriminant ( discriminant_type_metadata ) => { Some ( discriminant_type_metadata ) } _ => None } , span : span , } ) ; ( metadata_stub , variant_llvm_type , member_description_factory ) }
Returns a tuple of (1) type_metadata_stub of the variant, (2) the llvm_type
of the variant, and (3) a MemberDescriptionFactory for producing the
descriptions of the fields of the variant.
Returns a tuple of ( 1 ) type_metadata_stub of the variant ( 2 ) the llvm_type of the variant and ( 3 ) a MemberDescriptionFactory for producing the descriptions of the fields of the variant .
cx
&CrateContext<'a, 'tcx>
enum_type
Ty<'tcx>
struct_def
&adt::Struct<'tcx>
variant
ty::VariantDef<'tcx>
discriminant_info
EnumDiscriminantInfo
containing_scope
DIScope
span
Span