diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index ac28244c54..e4928a452f 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -20,7 +20,7 @@ use ir::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault, CanDerivePartialEq, CanDeriveEq, CannotDeriveReason}; use ir::dot; use ir::enum_ty::{Enum, EnumVariant, EnumVariantValue}; -use ir::function::{Abi, Function, FunctionSig}; +use ir::function::{Abi, Function, FunctionSig, Linkage}; use ir::int::IntKind; use ir::item::{IsOpaque, Item, ItemCanonicalName, ItemCanonicalPath}; use ir::item_kind::ItemKind; @@ -3127,6 +3127,13 @@ impl CodeGenerator for Function { debug!("::codegen: item = {:?}", item); debug_assert!(item.is_enabled_for_codegen(ctx)); + // We can't currently do anything with Internal functions so just + // avoid generating anything for them. + match self.linkage() { + Linkage::Internal => return, + Linkage::External => {} + } + // Similar to static member variables in a class template, we can't // generate bindings to template functions, because the set of // instantiations is open ended and we have no way of knowing which diff --git a/src/ir/comp.rs b/src/ir/comp.rs index c77834ee36..46f895da01 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -62,9 +62,9 @@ impl Method { /// Construct a new `Method`. pub fn new(kind: MethodKind, signature: FunctionId, is_const: bool) -> Self { Method { - kind: kind, - signature: signature, - is_const: is_const, + kind, + signature, + is_const, } } @@ -311,7 +311,7 @@ impl Bitfield { assert!(raw.bitfield_width().is_some()); Bitfield { - offset_into_unit: offset_into_unit, + offset_into_unit, data: raw.0, getter_name: None, setter_name: None, @@ -420,13 +420,13 @@ impl RawField { offset: Option, ) -> RawField { RawField(FieldData { - name: name, - ty: ty, - comment: comment, + name, + ty, + comment, annotations: annotations.unwrap_or_default(), - bitfield_width: bitfield_width, - mutable: mutable, - offset: offset, + bitfield_width, + mutable, + offset, }) } } diff --git a/src/ir/context.rs b/src/ir/context.rs index 560f6ec247..a108fa1094 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -491,7 +491,7 @@ impl<'ctx> WhitelistedItemsTraversal<'ctx> { R: IntoIterator, { WhitelistedItemsTraversal { - ctx: ctx, + ctx, traversal: ItemTraversal::new(ctx, roots, predicate), } } diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 3006ec7fd5..d096851585 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -37,8 +37,8 @@ impl Enum { /// Construct a new `Enum` with the given representation and variants. pub fn new(repr: Option, variants: Vec) -> Self { Enum { - repr: repr, - variants: variants, + repr, + variants, } } @@ -204,10 +204,10 @@ impl EnumVariant { custom_behavior: Option, ) -> Self { EnumVariant { - name: name, - comment: comment, - val: val, - custom_behavior: custom_behavior, + name, + comment, + val, + custom_behavior, } } diff --git a/src/ir/function.rs b/src/ir/function.rs index 2eab663835..60a7effd77 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -49,6 +49,15 @@ impl FunctionKind { } } +/// The style of linkage +#[derive(Debug, Clone, Copy)] +pub enum Linkage { + /// Externally visible and can be linked against + External, + /// Not exposed externally. 'static inline' functions will have this kind of linkage + Internal +} + /// A function declaration, with a signature, arguments, and argument names. /// /// The argument names vector must be the same length as the ones in the @@ -69,6 +78,9 @@ pub struct Function { /// The kind of function this is. kind: FunctionKind, + + /// The linkage of the function. + linkage: Linkage, } impl Function { @@ -76,16 +88,18 @@ impl Function { pub fn new( name: String, mangled_name: Option, - sig: TypeId, + signature: TypeId, comment: Option, kind: FunctionKind, + linkage: Linkage ) -> Self { Function { - name: name, - mangled_name: mangled_name, - signature: sig, - comment: comment, - kind: kind, + name, + mangled_name, + signature, + comment, + kind, + linkage, } } @@ -108,6 +122,12 @@ impl Function { pub fn kind(&self) -> FunctionKind { self.kind } + + /// Get this function's linkage. + pub fn linkage(&self) -> Linkage { + self.linkage + } + } impl DotAttributes for Function { @@ -477,11 +497,11 @@ impl ClangSubItemParser for Function { } let linkage = cursor.linkage(); - if linkage != CXLinkage_External && - linkage != CXLinkage_UniqueExternal - { - return Err(ParseError::Continue); - } + let linkage = match linkage { + CXLinkage_External | CXLinkage_UniqueExternal => Linkage::External, + CXLinkage_Internal => Linkage::Internal, + _ => return Err(ParseError::Continue) + }; // Grab the signature using Item::from_ty. let sig = @@ -511,7 +531,7 @@ impl ClangSubItemParser for Function { let comment = cursor.raw_comment(); - let function = Self::new(name, mangled_name, sig, comment, kind); + let function = Self::new(name, mangled_name, sig, comment, kind, linkage); Ok(ParseResult::New(function, Some(cursor))) } } diff --git a/src/ir/layout.rs b/src/ir/layout.rs index 0d9c123f74..ac875ca42b 100644 --- a/src/ir/layout.rs +++ b/src/ir/layout.rs @@ -33,8 +33,8 @@ impl Layout { /// packed. pub fn new(size: usize, align: usize) -> Self { Layout { - size: size, - align: align, + size, + align, packed: false, } } diff --git a/src/ir/template.rs b/src/ir/template.rs index f5cc015234..11a799f4f6 100644 --- a/src/ir/template.rs +++ b/src/ir/template.rs @@ -214,16 +214,13 @@ pub struct TemplateInstantiation { impl TemplateInstantiation { /// Construct a new template instantiation from the given parts. - pub fn new( - template_definition: TypeId, - template_args: I, - ) -> TemplateInstantiation + pub fn new(definition: TypeId, args: I) -> TemplateInstantiation where I: IntoIterator, { TemplateInstantiation { - definition: template_definition, - args: template_args.into_iter().collect(), + definition, + args: args.into_iter().collect(), } } diff --git a/src/ir/traversal.rs b/src/ir/traversal.rs index f55acc10de..b9b3179a00 100644 --- a/src/ir/traversal.rs +++ b/src/ir/traversal.rs @@ -21,8 +21,8 @@ impl Edge { /// Construct a new edge whose referent is `to` and is of the given `kind`. pub fn new(to: ItemId, kind: EdgeKind) -> Edge { Edge { - to: to, - kind: kind, + to, + kind, } } } diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 0db913852d..12ecbc6609 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -69,10 +69,10 @@ impl Type { is_const: bool, ) -> Self { Type { - name: name, - layout: layout, - kind: kind, - is_const: is_const, + name, + layout, + kind, + is_const, } } diff --git a/src/ir/var.rs b/src/ir/var.rs index 3abc44cf87..9d6c1452b3 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -46,18 +46,18 @@ impl Var { /// Construct a new `Var`. pub fn new( name: String, - mangled: Option, + mangled_name: Option, ty: TypeId, val: Option, is_const: bool, ) -> Var { assert!(!name.is_empty()); Var { - name: name, - mangled_name: mangled, - ty: ty, - val: val, - is_const: is_const, + name, + mangled_name, + ty, + val, + is_const, } }