diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2017-09-29 17:42:29 -0700 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2017-10-02 11:34:57 -0700 |
commit | 9ad1e6aac88880170d5c4486c7e9ac1c877c46f7 (patch) | |
tree | c804220cdc24ee9636352ee503c52bbca1d52c92 | |
parent | 5e753975ce8685c22ce78fb993c0db1819de2dfb (diff) |
A bunch of parsing things should return TypeId
-rw-r--r-- | src/codegen/mod.rs | 4 | ||||
-rw-r--r-- | src/ir/analysis/derive_hash.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/derive_partial_eq_or_partial_ord.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/has_destructor.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/has_float.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/has_type_param_in_array.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/template_params.rs | 2 | ||||
-rw-r--r-- | src/ir/comp.rs | 10 | ||||
-rw-r--r-- | src/ir/context.rs | 58 | ||||
-rw-r--r-- | src/ir/enum_ty.rs | 4 | ||||
-rw-r--r-- | src/ir/function.rs | 30 | ||||
-rw-r--r-- | src/ir/item.rs | 48 | ||||
-rw-r--r-- | src/ir/template.rs | 20 | ||||
-rw-r--r-- | src/ir/ty.rs | 36 | ||||
-rw-r--r-- | src/ir/var.rs | 8 | ||||
-rw-r--r-- | src/parse.rs | 14 |
16 files changed, 122 insertions, 122 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 3d07e1d0..ce5054c9 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -690,7 +690,7 @@ impl CodeGenerator for Type { let params: Vec<_> = params.into_iter() .filter_map(|p| p.as_template_param(ctx, &())) .collect(); - if params.iter().any(|p| ctx.resolve_type(p.as_type_id_unchecked()).is_invalid_type_param()) { + if params.iter().any(|p| ctx.resolve_type(*p).is_invalid_type_param()) { warn!( "Item contained invalid template \ parameter: {:?}", @@ -1674,7 +1674,7 @@ impl CodeGenerator for CompInfo { let mut param_names = vec![]; for (idx, ty) in params.iter().enumerate() { - let param = ctx.resolve_type(ty.as_type_id_unchecked()); + let param = ctx.resolve_type(*ty); let name = param.name().unwrap(); let ident = ctx.rust_ident(name); param_names.push(ident.clone()); diff --git a/src/ir/analysis/derive_hash.rs b/src/ir/analysis/derive_hash.rs index 8e23f73f..569c7246 100644 --- a/src/ir/analysis/derive_hash.rs +++ b/src/ir/analysis/derive_hash.rs @@ -312,7 +312,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> { TypeKind::TemplateInstantiation(ref template) => { let args_cannot_derive = template.template_arguments().iter().any(|arg| { - self.cannot_derive_hash.contains(&arg) + self.cannot_derive_hash.contains(&arg.into()) }); if args_cannot_derive { trace!( diff --git a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs index ccdbbb69..7efce6e5 100644 --- a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs +++ b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs @@ -334,7 +334,7 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> { TypeKind::TemplateInstantiation(ref template) => { let args_cannot_derive = template.template_arguments().iter().any(|arg| { - self.cannot_derive_partialeq_or_partialord.contains(&arg) + self.cannot_derive_partialeq_or_partialord.contains(&arg.into()) }); if args_cannot_derive { trace!( diff --git a/src/ir/analysis/has_destructor.rs b/src/ir/analysis/has_destructor.rs index 729910be..c87b7e25 100644 --- a/src/ir/analysis/has_destructor.rs +++ b/src/ir/analysis/has_destructor.rs @@ -144,7 +144,7 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> { self.have_destructor.contains(&inst.template_definition().into()) || inst.template_arguments().iter().any(|arg| { - self.have_destructor.contains(arg) + self.have_destructor.contains(&arg.into()) }); if definition_or_arg_destructor { self.insert(id) diff --git a/src/ir/analysis/has_float.rs b/src/ir/analysis/has_float.rs index 05dd3b4a..193862c0 100644 --- a/src/ir/analysis/has_float.rs +++ b/src/ir/analysis/has_float.rs @@ -198,7 +198,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> { TypeKind::TemplateInstantiation(ref template) => { let args_have = template.template_arguments() .iter() - .any(|arg| self.has_float.contains(&arg)); + .any(|arg| self.has_float.contains(&arg.into())); if args_have { trace!(" template args have float, so \ insantiation also has float"); diff --git a/src/ir/analysis/has_type_param_in_array.rs b/src/ir/analysis/has_type_param_in_array.rs index 238ffe60..aa8d34be 100644 --- a/src/ir/analysis/has_type_param_in_array.rs +++ b/src/ir/analysis/has_type_param_in_array.rs @@ -207,7 +207,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> { TypeKind::TemplateInstantiation(ref template) => { let args_have = template.template_arguments().iter().any(|arg| { - self.has_type_parameter_in_array.contains(&arg) + self.has_type_parameter_in_array.contains(&arg.into()) }); if args_have { trace!( diff --git a/src/ir/analysis/template_params.rs b/src/ir/analysis/template_params.rs index 52986243..24ab4f26 100644 --- a/src/ir/analysis/template_params.rs +++ b/src/ir/analysis/template_params.rs @@ -294,7 +294,7 @@ impl<'ctx> UsedTemplateParameters<'ctx> { param ); - if used_by_def.contains(param) { + if used_by_def.contains(¶m.into()) { trace!(" param is used by template definition"); let arg = arg.into_resolver() diff --git a/src/ir/comp.rs b/src/ir/comp.rs index d0641a2b..c193acab 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -825,7 +825,7 @@ pub struct CompInfo { /// concrete template arguments, and should always be a /// `Type(TypeKind::TypeParam(name))`. For concrete template arguments, see /// `TypeKind::TemplateInstantiation`. - template_params: Vec<ItemId>, + template_params: Vec<TypeId>, /// The method declarations inside this class, if in C++ mode. methods: Vec<Method>, @@ -1105,7 +1105,7 @@ impl CompInfo { let name = if name.is_empty() { None } else { Some(name) }; let field = RawField::new(name, - field_type.as_type_id_unchecked(), + field_type, comment, annotations, bit_width, @@ -1193,7 +1193,7 @@ impl CompInfo { let type_id = Item::from_ty_or_ref(cur.cur_type(), cur, None, ctx); ci.base_members.push(Base { - ty: type_id.as_type_id_unchecked(), + ty: type_id, kind: kind, field_name: field_name, }); @@ -1465,7 +1465,7 @@ impl TemplateParameters for CompInfo { fn self_template_params( &self, _ctx: &BindgenContext, - ) -> Option<Vec<ItemId>> { + ) -> Option<Vec<TypeId>> { if self.template_params.is_empty() { None } else { @@ -1483,7 +1483,7 @@ impl Trace for CompInfo { { let params = item.all_template_params(context).unwrap_or(vec![]); for p in params { - tracer.visit_kind(p, EdgeKind::TemplateParameterDefinition); + tracer.visit_kind(p.into(), EdgeKind::TemplateParameterDefinition); } for &ty in self.inner_types() { diff --git a/src/ir/context.rs b/src/ir/context.rs index 2f2a6346..a48b145f 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -185,11 +185,11 @@ pub struct BindgenContext { /// Clang USR to type map. This is needed to be able to associate types with /// item ids during parsing. - types: HashMap<TypeKey, ItemId>, + types: HashMap<TypeKey, TypeId>, /// Maps from a cursor to the item id of the named template type parameter /// for that cursor. - type_params: HashMap<clang::Cursor, ItemId>, + type_params: HashMap<clang::Cursor, TypeId>, /// A cursor to module map. Similar reason than above. modules: HashMap<Cursor, ItemId>, @@ -597,7 +597,7 @@ impl BindgenContext { TypeKey::Declaration(declaration) }; - let old = self.types.insert(key, id); + let old = self.types.insert(key, id.as_type_id_unchecked()); debug_assert_eq!(old, None); } } @@ -664,7 +664,7 @@ impl BindgenContext { "should not have already associated an item with the given id" ); - let old_named_ty = self.type_params.insert(definition, id); + let old_named_ty = self.type_params.insert(definition, id.as_type_id_unchecked()); assert!( old_named_ty.is_none(), "should not have already associated a named type with this id" @@ -673,7 +673,7 @@ impl BindgenContext { /// Get the named type defined at the given cursor location, if we've /// already added one. - pub fn get_type_param(&self, definition: &clang::Cursor) -> Option<ItemId> { + pub fn get_type_param(&self, definition: &clang::Cursor) -> Option<TypeId> { assert_eq!( definition.kind(), clang_sys::CXCursor_TemplateTypeParameter @@ -821,7 +821,7 @@ impl BindgenContext { let item = self.items.get_mut(&id).unwrap(); *item.kind_mut().as_type_mut().unwrap().kind_mut() = - TypeKind::ResolvedTypeRef(resolved.as_type_id_unchecked()); + TypeKind::ResolvedTypeRef(resolved); resolved }; @@ -1166,7 +1166,7 @@ impl BindgenContext { used_params.entry(id).or_insert( id.self_template_params(self).map_or( Default::default(), - |params| params.into_iter().collect(), + |params| params.into_iter().map(|p| p.into()).collect(), ), ); } @@ -1191,7 +1191,7 @@ impl BindgenContext { pub fn uses_template_parameter( &self, item: ItemId, - template_param: ItemId, + template_param: TypeId, ) -> bool { assert!( self.in_codegen_phase(), @@ -1340,7 +1340,7 @@ impl BindgenContext { fn get_declaration_info_for_template_instantiation( &self, instantiation: &Cursor, - ) -> Option<(Cursor, ItemId, usize)> { + ) -> Option<(Cursor, TypeId, usize)> { instantiation .cur_type() .canonical_declaration(Some(instantiation)) @@ -1428,7 +1428,7 @@ impl BindgenContext { template: TypeId, ty: &clang::Type, location: clang::Cursor, - ) -> Option<ItemId> { + ) -> Option<TypeId> { use clang_sys; let num_expected_args = match self.resolve_type(template) @@ -1525,14 +1525,14 @@ impl BindgenContext { return None; } - let mut sub_args: Vec<_> = args.drain( - args_len - num_expected_template_args.., - ).collect(); + let mut sub_args: Vec<_> = args + .drain(args_len - num_expected_template_args..) + .collect(); sub_args.reverse(); let sub_name = Some(template_decl_cursor.spelling()); let sub_inst = TemplateInstantiation::new( - template_decl_id.as_type_id_unchecked(), + template_decl_id, sub_args, ); let sub_kind = @@ -1564,7 +1564,7 @@ impl BindgenContext { self.add_item_to_module(&sub_item); debug_assert!(sub_id == sub_item.id()); self.items.insert(sub_id, sub_item); - args.push(sub_id); + args.push(sub_id.as_type_id_unchecked()); } } _ => { @@ -1624,7 +1624,7 @@ impl BindgenContext { self.add_item_to_module(&item); debug_assert!(with_id == item.id()); self.items.insert(with_id, item); - Some(with_id) + Some(with_id.as_type_id_unchecked()) } /// If we have already resolved the type for the given type declaration, @@ -1632,7 +1632,7 @@ impl BindgenContext { pub fn get_resolved_type( &self, decl: &clang::CanonicalTypeDeclaration, - ) -> Option<ItemId> { + ) -> Option<TypeId> { self.types .get(&TypeKey::Declaration(*decl.cursor())) .or_else(|| { @@ -1651,7 +1651,7 @@ impl BindgenContext { parent_id: Option<ItemId>, ty: &clang::Type, location: Option<clang::Cursor>, - ) -> Option<ItemId> { + ) -> Option<TypeId> { use clang_sys::{CXCursor_TypeAliasTemplateDecl, CXCursor_TypeRef}; debug!( "builtin_or_resolved_ty: {:?}, {:?}, {:?}", @@ -1699,7 +1699,7 @@ impl BindgenContext { return None; } - return self.instantiate_template(with_id, id.as_type_id_unchecked(), ty, location) + return self.instantiate_template(with_id, id, ty, location) .or_else(|| Some(id)); } @@ -1722,14 +1722,14 @@ impl BindgenContext { pub fn build_ty_wrapper( &mut self, with_id: ItemId, - wrapped_id: ItemId, + wrapped_id: TypeId, parent_id: Option<ItemId>, ty: &clang::Type, - ) -> ItemId { + ) -> TypeId { let spelling = ty.spelling(); let is_const = ty.is_const(); let layout = ty.fallible_layout().ok(); - let type_kind = TypeKind::ResolvedTypeRef(wrapped_id.as_type_id_unchecked()); + let type_kind = TypeKind::ResolvedTypeRef(wrapped_id); let ty = Type::new(Some(spelling), layout, type_kind, is_const); let item = Item::new( with_id, @@ -1739,7 +1739,7 @@ impl BindgenContext { ItemKind::Type(ty), ); self.add_builtin_item(item); - with_id + with_id.as_type_id_unchecked() } /// Returns the next item id to be used for an item. @@ -1749,7 +1749,7 @@ impl BindgenContext { ret } - fn build_builtin_ty(&mut self, ty: &clang::Type) -> Option<ItemId> { + fn build_builtin_ty(&mut self, ty: &clang::Type) -> Option<TypeId> { use clang_sys::*; let type_kind = match ty.kind() { CXType_NullPtr => TypeKind::NullPtr, @@ -1801,7 +1801,7 @@ impl BindgenContext { let item = Item::new(id, None, None, self.root_module, ItemKind::Type(ty)); self.add_builtin_item(item); - Some(id) + Some(id.as_type_id_unchecked()) } /// Get the current Clang translation unit that is being processed. @@ -2390,13 +2390,13 @@ impl ItemResolver { #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct PartialType { decl: Cursor, - id: ItemId, + id: TypeId, } impl PartialType { /// Construct a new `PartialType`. pub fn new<Id: Into<ItemId>>(decl: Cursor, id: Id) -> PartialType { - let id = id.into(); + let id = id.into().as_type_id_unchecked(); // assert!(decl == decl.canonical()); PartialType { decl: decl, @@ -2411,7 +2411,7 @@ impl PartialType { /// The item ID allocated for this type. This is *NOT* a key for an entry in /// the context's item set yet! - pub fn id(&self) -> ItemId { + pub fn id(&self) -> TypeId { self.id } } @@ -2420,7 +2420,7 @@ impl TemplateParameters for PartialType { fn self_template_params( &self, _ctx: &BindgenContext, - ) -> Option<Vec<ItemId>> { + ) -> Option<Vec<TypeId>> { // Maybe at some point we will eagerly parse named types, but for now we // don't and this information is unavailable. None diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index a23b6491..3006ec7f 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -72,7 +72,7 @@ impl Enum { // Assume signedness since the default type by the C standard is an int. let is_signed = repr.and_then( - |r| ctx.resolve_type(r.as_type_id_unchecked()).safe_canonical_type(ctx), + |r| ctx.resolve_type(r).safe_canonical_type(ctx), ).map_or(true, |ty| match *ty.kind() { TypeKind::Int(ref int_kind) => int_kind.is_signed(), ref other => { @@ -125,7 +125,7 @@ impl Enum { } CXChildVisit_Continue }); - Ok(Enum::new(repr.map(|r| r.as_type_id_unchecked()), variants)) + Ok(Enum::new(repr, variants)) } /// Whether the enum should be a bitfield diff --git a/src/ir/function.rs b/src/ir/function.rs index 5fcd21ea..990fbaff 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -1,7 +1,7 @@ //! Intermediate representation for C/C++ functions and methods. use super::comp::MethodKind; -use super::context::{BindgenContext, ItemId}; +use super::context::{BindgenContext, TypeId}; use super::dot::DotAttributes; use super::item::Item; use super::traversal::{EdgeKind, Trace, Tracer}; @@ -62,7 +62,7 @@ pub struct Function { mangled_name: Option<String>, /// The id pointing to the current function signature. - signature: ItemId, + signature: TypeId, /// The doc comment on the function, if any. comment: Option<String>, @@ -76,7 +76,7 @@ impl Function { pub fn new( name: String, mangled_name: Option<String>, - sig: ItemId, + sig: TypeId, comment: Option<String>, kind: FunctionKind, ) -> Self { @@ -99,8 +99,8 @@ impl Function { self.mangled_name.as_ref().map(|n| &**n) } - /// Get this function's signature. - pub fn signature(&self) -> ItemId { + /// Get this function's signature type. + pub fn signature(&self) -> TypeId { self.signature } @@ -180,11 +180,11 @@ impl quote::ToTokens for Abi { #[derive(Debug)] pub struct FunctionSig { /// The return type of the function. - return_type: ItemId, + return_type: TypeId, /// The type of the arguments, optionally with the name of the argument when /// declared. - argument_types: Vec<(Option<String>, ItemId)>, + argument_types: Vec<(Option<String>, TypeId)>, /// Whether this function is variadic. is_variadic: bool, @@ -287,8 +287,8 @@ pub fn cursor_mangling( impl FunctionSig { /// Construct a new function signature. pub fn new( - return_type: ItemId, - arguments: Vec<(Option<String>, ItemId)>, + return_type: TypeId, + arguments: Vec<(Option<String>, TypeId)>, is_variadic: bool, abi: Abi, ) -> Self { @@ -390,7 +390,7 @@ impl FunctionSig { } else if is_virtual { let void = Item::builtin_type(TypeKind::Void, false, ctx); let ptr = - Item::builtin_type(TypeKind::Pointer(void.as_type_id_unchecked()), false, ctx); + Item::builtin_type(TypeKind::Pointer(void), false, ctx); args.insert(0, (Some("this".into()), ptr)); } } @@ -412,16 +412,16 @@ impl FunctionSig { warn!("Unknown calling convention: {:?}", call_conv); } - Ok(Self::new(ret, args, ty.is_variadic(), abi)) + Ok(Self::new(ret.into(), args, ty.is_variadic(), abi)) } /// Get this function signature's return type. - pub fn return_type(&self) -> ItemId { + pub fn return_type(&self) -> TypeId { self.return_type } /// Get this function signature's argument (name, type) pairs. - pub fn argument_types(&self) -> &[(Option<String>, ItemId)] { + pub fn argument_types(&self) -> &[(Option<String>, TypeId)] { &self.argument_types } @@ -535,10 +535,10 @@ impl Trace for FunctionSig { where T: Tracer, { - tracer.visit_kind(self.return_type(), EdgeKind::FunctionReturn); + tracer.visit_kind(self.return_type().into(), EdgeKind::FunctionReturn); for &(_, ty) in self.argument_types() { - tracer.visit_kind(ty, EdgeKind::FunctionParameter); + tracer.visit_kind(ty.into(), EdgeKind::FunctionParameter); } } } diff --git a/src/ir/item.rs b/src/ir/item.rs index 27c08fa0..825b9bc4 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -4,7 +4,7 @@ use super::analysis::HasVtable; use super::annotations::Annotations; use super::comment; use super::comp::MethodKind; -use super::context::{BindgenContext, ItemId, PartialType}; +use super::context::{BindgenContext, ItemId, PartialType, TypeId}; use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault, CanDeriveHash, CanDerivePartialOrd, CanDeriveOrd, CanDerivePartialEq, CanDeriveEq}; @@ -165,7 +165,7 @@ where &self, ctx: &BindgenContext, _: &(), - ) -> Option<ItemId> { + ) -> Option<TypeId> { ctx.resolve_item((*self).into()).as_template_param(ctx, &()) } } @@ -177,7 +177,7 @@ impl AsTemplateParam for Item { &self, ctx: &BindgenContext, _: &(), - ) -> Option<ItemId> { + ) -> Option<TypeId> { self.kind.as_template_param(ctx, self) } } @@ -189,7 +189,7 @@ impl AsTemplateParam for ItemKind { &self, ctx: &BindgenContext, item: &Item, - ) -> Option<ItemId> { + ) -> Option<TypeId> { match *self { ItemKind::Type(ref ty) => ty.as_template_param(ctx, item), ItemKind::Module(..) | @@ -299,7 +299,7 @@ impl Trace for Item { ItemKind::Function(ref fun) => { // Just the same way, it has not real meaning for a function to // be opaque, so we trace across it. - tracer.visit(fun.signature()); + tracer.visit(fun.signature().into()); } ItemKind::Var(ref var) => { tracer.visit_kind(var.ty().into(), EdgeKind::VarType); @@ -462,12 +462,12 @@ impl Item { with_id: ItemId, ty: &clang::Type, ctx: &mut BindgenContext, - ) -> ItemId { + ) -> TypeId { let ty = Opaque::from_clang_ty(ty); let kind = ItemKind::Type(ty); let parent = ctx.root_module(); ctx.add_item(Item::new(with_id, None, None, parent, kind), None, None); - with_id + with_id.as_type_id_unchecked() } /// Get this `Item`'s identifier. @@ -1086,7 +1086,7 @@ where fn self_template_params( &self, ctx: &BindgenContext, - ) -> Option<Vec<ItemId>> { + ) -> Option<Vec<TypeId>> { ctx.resolve_item_fallible(*self).and_then(|item| { item.self_template_params(ctx) }) @@ -1097,7 +1097,7 @@ impl TemplateParameters for Item { fn self_template_params( &self, ctx: &BindgenContext, - ) -> Option<Vec<ItemId>> { + ) -> Option<Vec<TypeId>> { self.kind.self_template_params(ctx) } } @@ -1106,7 +1106,7 @@ impl TemplateParameters for ItemKind { fn self_template_params( &self, ctx: &BindgenContext, - ) -> Option<Vec<ItemId>> { + ) -> Option<Vec<TypeId>> { match *self { ItemKind::Type(ref ty) => ty.self_template_params(ctx), // If we start emitting bindings to explicitly instantiated @@ -1126,7 +1126,7 @@ fn visit_child( ty: &clang::Type, parent_id: Option<ItemId>, ctx: &mut BindgenContext, - result: &mut Result<ItemId, ParseError>, + result: &mut Result<TypeId, ParseError>, ) -> clang_sys::CXChildVisitResult { use clang_sys::*; if result.is_ok() { @@ -1150,7 +1150,7 @@ impl ClangItemParser for Item { kind: TypeKind, is_const: bool, ctx: &mut BindgenContext, - ) -> ItemId { + ) -> TypeId { // Feel free to add more here, I'm just lazy. match kind { TypeKind::Void | @@ -1168,7 +1168,7 @@ impl ClangItemParser for Item { None, None, ); - id + id.as_type_id_unchecked() } @@ -1242,7 +1242,7 @@ impl ClangItemParser for Item { cursor, parent_id, ctx, - )); + ).into()); } ctx.known_semantic_parent(definition) .or(parent_id) @@ -1257,7 +1257,7 @@ impl ClangItemParser for Item { Some(relevant_parent_id), ctx, ) { - Ok(ty) => return Ok(ty), + Ok(ty) => return Ok(ty.into()), Err(ParseError::Recurse) => return Err(ParseError::Recurse), Err(ParseError::Continue) => {} } @@ -1304,7 +1304,7 @@ impl ClangItemParser for Item { location: clang::Cursor, parent_id: Option<ItemId>, ctx: &mut BindgenContext, - ) -> ItemId { + ) -> TypeId { let id = ctx.next_item_id(); Self::from_ty_or_ref_with_id(id, ty, location, parent_id, ctx) } @@ -1325,7 +1325,7 @@ impl ClangItemParser for Item { location: clang::Cursor, parent_id: Option<ItemId>, ctx: &mut BindgenContext, - ) -> ItemId { + ) -> TypeId { debug!( "from_ty_or_ref_with_id: {:?} {:?}, {:?}, {:?}", potential_id, @@ -1374,7 +1374,7 @@ impl ClangItemParser for Item { Some(clang::Cursor::null()), None, ); - potential_id + potential_id.as_type_id_unchecked() } fn from_ty( @@ -1382,7 +1382,7 @@ impl ClangItemParser for Item { location: clang::Cursor, parent_id: Option<ItemId>, ctx: &mut BindgenContext, - ) -> Result<ItemId, ParseError> { + ) -> Result<TypeId, ParseError> { let id = ctx.next_item_id(); Item::from_ty_with_id(id, ty, location, parent_id, ctx) } @@ -1401,7 +1401,7 @@ impl ClangItemParser for Item { location: clang::Cursor, parent_id: Option<ItemId>, ctx: &mut BindgenContext, - ) -> Result<ItemId, ParseError> { + ) -> Result<TypeId, ParseError> { use clang_sys::*; debug!( @@ -1485,7 +1485,7 @@ impl ClangItemParser for Item { let result = Type::from_clang_ty(id, ty, location, parent_id, ctx); let relevant_parent_id = parent_id.unwrap_or(current_module); let ret = match result { - Ok(ParseResult::AlreadyResolved(ty)) => Ok(ty), + Ok(ParseResult::AlreadyResolved(ty)) => Ok(ty.as_type_id_unchecked()), Ok(ParseResult::New(item, declaration)) => { ctx.add_item( Item::new( @@ -1498,7 +1498,7 @@ impl ClangItemParser for Item { declaration, Some(location), ); - Ok(id) + Ok(id.as_type_id_unchecked()) } Err(ParseError::Continue) => Err(ParseError::Continue), Err(ParseError::Recurse) => { @@ -1561,7 +1561,7 @@ impl ClangItemParser for Item { with_id: Option<ItemId>, location: clang::Cursor, ctx: &mut BindgenContext, - ) -> Option<ItemId> { + ) -> Option<TypeId> { let ty = location.cur_type(); debug!( @@ -1724,7 +1724,7 @@ impl ClangItemParser for Item { ItemKind::Type(Type::named(name)), ); ctx.add_type_param(item, definition); - Some(id) + Some(id.as_type_id_unchecked()) } } diff --git a/src/ir/template.rs b/src/ir/template.rs index bad3df48..f5cc0152 100644 --- a/src/ir/template.rs +++ b/src/ir/template.rs @@ -109,7 +109,7 @@ pub trait TemplateParameters { /// anything but types, so we must treat them as opaque, and avoid /// instantiating them. fn self_template_params(&self, ctx: &BindgenContext) - -> Option<Vec<ItemId>>; + -> Option<Vec<TypeId>>; /// Get the number of free template parameters this template declaration /// has. @@ -136,7 +136,7 @@ pub trait TemplateParameters { /// how we would fully reference such a member type in C++: /// `Foo<int,char>::Inner`. `Foo` *must* be instantiated with template /// arguments before we can gain access to the `Inner` member type. - fn all_template_params(&self, ctx: &BindgenContext) -> Option<Vec<ItemId>> + fn all_template_params(&self, ctx: &BindgenContext) -> Option<Vec<TypeId>> where Self: ItemAncestors, { @@ -159,7 +159,7 @@ pub trait TemplateParameters { /// Get only the set of template parameters that this item uses. This is a /// subset of `all_template_params` and does not necessarily contain any of /// `self_template_params`. - fn used_template_params(&self, ctx: &BindgenContext) -> Option<Vec<ItemId>> + fn used_template_params(&self, ctx: &BindgenContext) -> Option<Vec<TypeId>> where Self: AsRef<ItemId>, { @@ -190,7 +190,7 @@ pub trait AsTemplateParam { &self, ctx: &BindgenContext, extra: &Self::Extra, - ) -> Option<ItemId>; + ) -> Option<TypeId>; /// Is this a named template type parameter? fn is_template_param( @@ -209,7 +209,7 @@ pub struct TemplateInstantiation { definition: TypeId, /// The concrete template arguments, which will be substituted in the /// definition for the generic template parameters. - args: Vec<ItemId>, + args: Vec<TypeId>, } impl TemplateInstantiation { @@ -219,7 +219,7 @@ impl TemplateInstantiation { template_args: I, ) -> TemplateInstantiation where - I: IntoIterator<Item = ItemId>, + I: IntoIterator<Item = TypeId>, { TemplateInstantiation { definition: template_definition, @@ -233,7 +233,7 @@ impl TemplateInstantiation { } /// Get the concrete template arguments used in this instantiation. - pub fn template_arguments(&self) -> &[ItemId] { + pub fn template_arguments(&self) -> &[TypeId] { &self.args[..] } @@ -305,7 +305,7 @@ impl TemplateInstantiation { Item::from_ty_or_ref(definition.cur_type(), definition, None, ctx); Some(TemplateInstantiation::new( - template_definition.as_type_id_unchecked(), + template_definition, template_args, )) } @@ -354,8 +354,8 @@ impl Trace for TemplateInstantiation { T: Tracer, { tracer.visit_kind(self.definition.into(), EdgeKind::TemplateDeclaration); - for &item in self.template_arguments() { - tracer.visit_kind(item, EdgeKind::TemplateArgument); + for arg in self.template_arguments() { + tracer.visit_kind(arg.into(), EdgeKind::TemplateArgument); } } } diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 54d7be6c..a5f3a694 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -383,7 +383,7 @@ impl AsTemplateParam for Type { &self, ctx: &BindgenContext, item: &Item, - ) -> Option<ItemId> { + ) -> Option<TypeId> { self.kind.as_template_param(ctx, item) } } @@ -395,9 +395,9 @@ impl AsTemplateParam for TypeKind { &self, ctx: &BindgenContext, item: &Item, - ) -> Option<ItemId> { + ) -> Option<TypeId> { match *self { - TypeKind::TypeParam => Some(item.id()), + TypeKind::TypeParam => Some(item.id().as_type_id_unchecked()), TypeKind::ResolvedTypeRef(id) => id.as_template_param(ctx, &()), _ => None, } @@ -534,7 +534,7 @@ impl TemplateParameters for Type { fn self_template_params( &self, ctx: &BindgenContext, - ) -> Option<Vec<ItemId>> { + ) -> Option<Vec<TypeId>> { self.kind.self_template_params(ctx) } } @@ -543,7 +543,7 @@ impl TemplateParameters for TypeKind { fn self_template_params( &self, ctx: &BindgenContext, - ) -> Option<Vec<ItemId>> { + ) -> Option<Vec<TypeId>> { match *self { TypeKind::ResolvedTypeRef(id) => { ctx.resolve_type(id).self_template_params(ctx) @@ -630,7 +630,7 @@ pub enum TypeKind { /// A templated alias, pointing to an inner type, just as `Alias`, but with /// template parameters. - TemplateAlias(TypeId, Vec<ItemId>), + TemplateAlias(TypeId, Vec<TypeId>), /// An array of a type and a length. Array(TypeId, usize), @@ -756,7 +756,7 @@ impl Type { ); if let Some(ty) = already_resolved { debug!("{:?} already resolved: {:?}", ty, location); - return Ok(ParseResult::AlreadyResolved(ty)); + return Ok(ParseResult::AlreadyResolved(ty.into())); } } @@ -1001,7 +1001,7 @@ impl Type { } }; - TypeKind::TemplateAlias(inner_type.as_type_id_unchecked(), args) + TypeKind::TemplateAlias(inner_type, args) } CXCursor_TemplateRef => { let referenced = location.referenced().unwrap(); @@ -1036,14 +1036,14 @@ impl Type { referenced_ty ); - let item = Item::from_ty_or_ref_with_id( + let id = Item::from_ty_or_ref_with_id( potential_id, referenced_ty, declaration, parent_id, ctx, ); - return Ok(ParseResult::AlreadyResolved(item)); + return Ok(ParseResult::AlreadyResolved(id.into())); } CXCursor_NamespaceRef => { return Err(ParseError::Continue); @@ -1117,7 +1117,7 @@ impl Type { } let inner = Item::from_ty_or_ref(pointee, location, None, ctx); - TypeKind::Pointer(inner.as_type_id_unchecked()) + TypeKind::Pointer(inner) } CXType_BlockPointer => TypeKind::BlockPointer, // XXX: RValueReference is most likely wrong, but I don't think we @@ -1130,7 +1130,7 @@ impl Type { None, ctx, ); - TypeKind::Reference(inner.as_type_id_unchecked()) + TypeKind::Reference(inner) } // XXX DependentSizedArray is wrong CXType_VariableArray | @@ -1141,7 +1141,7 @@ impl Type { None, ctx, ).expect("Not able to resolve array element?"); - TypeKind::Pointer(inner.as_type_id_unchecked()) + TypeKind::Pointer(inner) } CXType_IncompleteArray => { let inner = Item::from_ty( @@ -1150,7 +1150,7 @@ impl Type { None, ctx, ).expect("Not able to resolve array element?"); - TypeKind::Array(inner.as_type_id_unchecked(), 0) + TypeKind::Array(inner, 0) } CXType_FunctionNoProto | CXType_FunctionProto => { @@ -1162,7 +1162,7 @@ impl Type { let inner = cursor.typedef_type().expect("Not valid Type?"); let inner = Item::from_ty_or_ref(inner, location, None, ctx); - TypeKind::Alias(inner.as_type_id_unchecked()) + TypeKind::Alias(inner) } CXType_Enum => { let enum_ = Enum::from_ty(ty, ctx).expect("Not an enum?"); @@ -1208,7 +1208,7 @@ impl Type { None, ctx, ).expect("Not able to resolve array element?"); - TypeKind::Array(inner.as_type_id_unchecked(), ty.num_elements().unwrap()) + TypeKind::Array(inner, ty.num_elements().unwrap()) } CXType_Elaborated => { return Self::from_clang_ty( @@ -1266,9 +1266,9 @@ impl Trace for Type { } TypeKind::TemplateAlias(inner, ref template_params) => { tracer.visit_kind(inner.into(), EdgeKind::TypeReference); - for &item in template_params { + for param in template_params { tracer.visit_kind( - item, + param.into(), EdgeKind::TemplateParameterDefinition, ); } diff --git a/src/ir/var.rs b/src/ir/var.rs index d66504f6..3abc44cf 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -179,7 +179,7 @@ impl ClangSubItemParser for Var { true, ctx, ); - (TypeKind::Pointer(char_ty.as_type_id_unchecked()), VarType::String(val)) + (TypeKind::Pointer(char_ty), VarType::String(val)) } EvalResult::Int(Wrapping(value)) => { let kind = ctx.parse_callbacks() @@ -203,7 +203,7 @@ impl ClangSubItemParser for Var { let ty = Item::builtin_type(type_kind, true, ctx); Ok(ParseResult::New( - Var::new(name, None, ty.as_type_id_unchecked(), Some(val), true), + Var::new(name, None, ty, Some(val), true), Some(cursor), )) } @@ -236,7 +236,7 @@ impl ClangSubItemParser for Var { // tests/headers/inner_const.hpp // // That's fine because in that case we know it's not a literal. - let canonical_ty = ctx.safe_resolve_type(ty.as_type_id_unchecked()).and_then(|t| { + let canonical_ty = ctx.safe_resolve_type(ty).and_then(|t| { t.safe_canonical_type(ctx) }); @@ -278,7 +278,7 @@ impl ClangSubItemParser for Var { }; let mangling = cursor_mangling(ctx, &cursor); - let var = Var::new(name, mangling, ty.as_type_id_unchecked(), value, is_const); + let var = Var::new(name, mangling, ty, value, is_const); Ok(ParseResult::New(var, Some(cursor))) } diff --git a/src/parse.rs b/src/parse.rs index 5869f302..1a9278b3 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -1,7 +1,7 @@ //! Common traits and types related to parsing our IR from Clang cursors. use clang; -use ir::context::{BindgenContext, ItemId}; +use ir::context::{BindgenContext, ItemId, TypeId}; use ir::ty::TypeKind; /// Not so much an error in the traditional sense, but a control flow message @@ -55,7 +55,7 @@ pub trait ClangItemParser: Sized { location: clang::Cursor, parent: Option<ItemId>, ctx: &mut BindgenContext, - ) -> Result<ItemId, ParseError>; + ) -> Result<TypeId, ParseError>; /// Identical to `from_ty`, but use the given `id` as the `ItemId` for the /// newly parsed item. @@ -65,7 +65,7 @@ pub trait ClangItemParser: Sized { location: clang::Cursor, parent: Option<ItemId>, ctx: &mut BindgenContext, - ) -> Result<ItemId, ParseError>; + ) -> Result<TypeId, ParseError>; /// Parse this item from the given Clang type, or if we haven't resolved all /// the other items this one depends on, an unresolved reference. @@ -74,7 +74,7 @@ pub trait ClangItemParser: Sized { location: clang::Cursor, parent_id: Option<ItemId>, context: &mut BindgenContext, - ) -> ItemId; + ) -> TypeId; /// Identical to `from_ty_or_ref`, but use the given `potential_id` as the /// `ItemId` for the newly parsed item. @@ -84,19 +84,19 @@ pub trait ClangItemParser: Sized { location: clang::Cursor, parent_id: Option<ItemId>, context: &mut BindgenContext, - ) -> ItemId; + ) -> TypeId; /// Create a named template type. fn type_param( with_id: Option<ItemId>, location: clang::Cursor, ctx: &mut BindgenContext, - ) -> Option<ItemId>; + ) -> Option<TypeId>; /// Create a builtin type. fn builtin_type( kind: TypeKind, is_const: bool, context: &mut BindgenContext, - ) -> ItemId; + ) -> TypeId; } |