/// Pretty-print the leading pragmas and extern crate declarations
Pretty-print the leading pragmas and extern crate declarations
Pretty - print the leading pragmas and extern crate declarations
fn print_header(s: &mut State, t: &Translation) -> io::Result<()> {
    if t.tcfg.emit_module {
        s.print_item(&mk().use_item(vec!["libc"], None as Option<Ident>))?;
    } else {
        let mut features = vec!["libc"];
        features.extend(t.features.borrow().iter());
        features.extend(t.type_converter.borrow().features_used());
        let mut pragmas: Vec<(&str, Vec<&str>)> =
            vec![("allow", vec!["non_upper_case_globals", "non_camel_case_types", "non_snake_case",
                                "dead_code", "mutable_transmutes", "unused_mut"])];
        if t.tcfg.cross_checks {
            features.append(&mut vec!["plugin", "custom_attribute"]);
            pragmas.push(("cross_check", vec!["yes"]));
        }
        pragmas.push(("feature", features));
        for (key, mut values) in pragmas {
            values.sort();
            let value_attr_vec = values.into_iter()
                .map(|value|
                    mk().nested_meta_item(
                        mk().meta_item(vec![value], MetaItemKind::Word)))
                .collect::<Vec<_>>();
            let item = mk().meta_item(
                vec![key],
                MetaItemKind::List(value_attr_vec),
            );
            for attr in mk().meta_item_attr(AttrStyle::Inner, item).as_inner_attrs() {
                s.print_attribute(&attr)?;
            }
        }
        if t.tcfg.cross_checks {
            let mut xcheck_plugin_args: Vec<NestedMetaItem> = vec![];
            for config_file in &t.tcfg.cross_check_configs {
                let file_lit = mk().str_lit(config_file);
                let file_item = mk().meta_item(vec!["config_file"],file_lit.into_inner());
                xcheck_plugin_args.push(mk().nested_meta_item(file_item));
            }
            let xcheck_plugin_item = mk().meta_item(
                vec!["cross_check_plugin"],
                MetaItemKind::List(xcheck_plugin_args),
            );
            let plugin_args = vec![mk().nested_meta_item(xcheck_plugin_item)];
            let plugin_item = mk().meta_item(
                vec!["plugin"],
                MetaItemKind::List(plugin_args),
            );
            for attr in mk().meta_item_attr(AttrStyle::Inner, plugin_item).as_inner_attrs() {
                s.print_attribute(&attr)?;
            }
        }
        // Add `extern crate libc` to the top of the file
        s.print_item(&mk().extern_crate_item("libc", None))?;
        if t.tcfg.cross_checks {
            s.print_item(&mk().single_attr("macro_use")
                .extern_crate_item("cross_check_derive", None))?;
            s.print_item(&mk().single_attr("macro_use")
                .extern_crate_item("cross_check_runtime", None))?;
        }
    }
    Ok(())
}
fn print_header ( s : & mut State , t : & Translation ) -> io :: Result < ( ) > { if t . tcfg . emit_module { s . print_item ( & mk ( ) . use_item ( vec ! [ " " ] , None as Option < Ident > ) ) ? ; } else { let mut features = vec ! [ " " ] ; features . extend ( t . features . borrow ( ) . iter ( ) ) ; features . extend ( t . type_converter . borrow ( ) . features_used ( ) ) ; let mut pragmas : Vec < ( & str , Vec < & str > ) > = vec ! [ ( " " vec [ " " " " " " " " " " " " ] ) ] ; if t . tcfg . cross_checks { features . append ( & mut vec ! [ " " " " ] ) ; pragmas . push ( ( " " , vec ! [ " " ] ) ) ; } pragmas . push ( ( " " , features ) ) ; for ( key , mut values ) in pragmas { values . sort ( ) ; let value_attr_vec = values . into_iter ( ) . map ( | value | mk ( ) . nested_meta_item ( mk ( ) . meta_item ( vec ! [ value ] , MetaItemKind :: Word ) ) ) . collect :: < Vec < _ > > ( ) ; let item = mk ( ) . meta_item ( vec ! [ key ] , MetaItemKind :: List ( value_attr_vec ) , ) ; for attr in mk ( ) . meta_item_attr ( AttrStyle :: Inner , item ) . as_inner_attrs ( ) { s . print_attribute ( & attr ) ? ; } } if t . tcfg . cross_checks { let mut xcheck_plugin_args : Vec < NestedMetaItem > = vec ! [ ] ; for config_file in & t . tcfg . cross_check_configs { let file_lit = mk ( ) . str_lit ( config_file ) ; let file_item = mk ( ) . meta_item ( vec ! [ " " ] , file_lit . into_inner ( ) ) ; xcheck_plugin_args . push ( mk ( ) . nested_meta_item ( file_item ) ) ; } let xcheck_plugin_item = mk ( ) . meta_item ( vec ! [ " " ] , MetaItemKind :: List ( xcheck_plugin_args ) , ) ; let plugin_args = vec ! [ mk ( ) nested_meta_item ( xcheck_plugin_item ) ] ; let plugin_item = mk ( ) . meta_item ( vec ! [ " " ] , MetaItemKind :: List ( plugin_args ) , ) ; for attr in mk ( ) . meta_item_attr ( AttrStyle :: Inner , plugin_item ) . as_inner_attrs ( ) { s . print_attribute ( & attr ) ? ; } } // Add `extern crate libc` to the top of the file s . print_item ( & mk ( ) . extern_crate_item ( " " , None ) ) ? ; if t . tcfg . cross_checks { s . print_item ( & mk ( ) . single_attr ( " " ) . extern_crate_item ( " " , None ) ) ? ; s . print_item ( & mk ( ) . single_attr ( " " ) . extern_crate_item ( " " , None ) ) ? ; } } Ok ( ( ) ) }
Pretty-print the leading pragmas and extern crate declarations
Pretty - print the leading pragmas and extern crate declarations
s
&mut State
t
&Translation