From 95fd17b874910184cc0fcd33b287fa4e205d9d7a Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 24 Nov 2022 11:17:08 -0500 Subject: [PATCH] Remove traits that have a single implementation (#2363) --- bindgen/codegen/mod.rs | 13 +-------- bindgen/ir/comp.rs | 2 +- bindgen/ir/context.rs | 1 - bindgen/ir/enum_ty.rs | 2 +- bindgen/ir/function.rs | 4 +-- bindgen/ir/item.rs | 20 ++++++------- bindgen/ir/objc.rs | 1 - bindgen/ir/template.rs | 1 - bindgen/ir/ty.rs | 2 +- bindgen/ir/var.rs | 4 +-- bindgen/lib.rs | 2 +- bindgen/parse.rs | 64 +----------------------------------------- 12 files changed, 17 insertions(+), 99 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index e201578e..b4050637 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2406,18 +2406,7 @@ impl CodeGenerator for CompInfo { } } -trait MethodCodegen { - fn codegen_method( - &self, - ctx: &BindgenContext, - methods: &mut Vec, - method_names: &mut HashSet, - result: &mut CodegenResult<'_>, - parent: &CompInfo, - ); -} - -impl MethodCodegen for Method { +impl Method { fn codegen_method( &self, ctx: &BindgenContext, diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 039742a4..18a4291c 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -12,7 +12,7 @@ use super::ty::RUST_DERIVE_IN_ARRAY_LIMIT; use crate::clang; use crate::codegen::struct_layout::{align_to, bytes_from_bits_pow2}; use crate::ir::derive::CanDeriveCopy; -use crate::parse::{ClangItemParser, ParseError}; +use crate::parse::ParseError; use crate::HashMap; use crate::NonCopyUnionStyle; use peeking_take_while::PeekableExt; diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 4623b253..3cc30f1c 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -20,7 +20,6 @@ use super::template::{TemplateInstantiation, TemplateParameters}; use super::traversal::{self, Edge, ItemTraversal}; use super::ty::{FloatKind, Type, TypeKind}; use crate::clang::{self, Cursor}; -use crate::parse::ClangItemParser; use crate::BindgenOptions; use crate::{Entry, HashMap, HashSet}; use cexpr; diff --git a/bindgen/ir/enum_ty.rs b/bindgen/ir/enum_ty.rs index 39677e93..63871fd4 100644 --- a/bindgen/ir/enum_ty.rs +++ b/bindgen/ir/enum_ty.rs @@ -6,7 +6,7 @@ use super::item::Item; use super::ty::{Type, TypeKind}; use crate::clang; use crate::ir::annotations::Annotations; -use crate::parse::{ClangItemParser, ParseError}; +use crate::parse::ParseError; use crate::regex_set::RegexSet; /// An enum representing custom handling that can be given to a variant. diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 7dbbb8f8..ecb3202f 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -7,9 +7,7 @@ use super::item::Item; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::TypeKind; use crate::clang::{self, Attribute}; -use crate::parse::{ - ClangItemParser, ClangSubItemParser, ParseError, ParseResult, -}; +use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use clang_sys::{self, CXCallingConv}; use proc_macro2; use quote; diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 5e9aff91..40f6f7d9 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -18,9 +18,7 @@ use super::template::{AsTemplateParam, TemplateParameters}; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::{Type, TypeKind}; use crate::clang; -use crate::parse::{ - ClangItemParser, ClangSubItemParser, ParseError, ParseResult, -}; +use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use clang_sys; use lazycell::LazyCell; use regex; @@ -1307,8 +1305,8 @@ fn visit_child( } } -impl ClangItemParser for Item { - fn builtin_type( +impl Item { + pub(crate) fn builtin_type( kind: TypeKind, is_const: bool, ctx: &mut BindgenContext, @@ -1333,7 +1331,7 @@ impl ClangItemParser for Item { id.as_type_id_unchecked() } - fn parse( + pub(crate) fn parse( cursor: clang::Cursor, parent_id: Option, ctx: &mut BindgenContext, @@ -1479,7 +1477,7 @@ impl ClangItemParser for Item { } } - fn from_ty_or_ref( + pub(crate) fn from_ty_or_ref( ty: clang::Type, location: clang::Cursor, parent_id: Option, @@ -1499,7 +1497,7 @@ impl ClangItemParser for Item { /// /// Typerefs are resolved once parsing is completely done, see /// `BindgenContext::resolve_typerefs`. - fn from_ty_or_ref_with_id( + pub(crate) fn from_ty_or_ref_with_id( potential_id: ItemId, ty: clang::Type, location: clang::Cursor, @@ -1554,7 +1552,7 @@ impl ClangItemParser for Item { potential_id.as_type_id_unchecked() } - fn from_ty( + pub(crate) fn from_ty( ty: &clang::Type, location: clang::Cursor, parent_id: Option, @@ -1572,7 +1570,7 @@ impl ClangItemParser for Item { /// critical some times to obtain information, an optional parent item id, /// that will, if it's `None`, become the current module id, and the /// context. - fn from_ty_with_id( + pub(crate) fn from_ty_with_id( id: ItemId, ty: &clang::Type, location: clang::Cursor, @@ -1742,7 +1740,7 @@ impl ClangItemParser for Item { /// A named type is a template parameter, e.g., the "T" in Foo. They're /// always local so it's the only exception when there's no declaration for /// a type. - fn type_param( + pub(crate) fn type_param( with_id: Option, location: clang::Cursor, ctx: &mut BindgenContext, diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index 7afa959b..4f340f6f 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -6,7 +6,6 @@ use super::item::Item; use super::traversal::{Trace, Tracer}; use super::ty::TypeKind; use crate::clang; -use crate::parse::ClangItemParser; use clang_sys::CXChildVisit_Continue; use clang_sys::CXCursor_ObjCCategoryDecl; use clang_sys::CXCursor_ObjCClassMethodDecl; diff --git a/bindgen/ir/template.rs b/bindgen/ir/template.rs index 8b06748e..e3ef6a9c 100644 --- a/bindgen/ir/template.rs +++ b/bindgen/ir/template.rs @@ -31,7 +31,6 @@ use super::context::{BindgenContext, ItemId, TypeId}; use super::item::{IsOpaque, Item, ItemAncestors}; use super::traversal::{EdgeKind, Trace, Tracer}; use crate::clang; -use crate::parse::ClangItemParser; /// Template declaration (and such declaration's template parameters) related /// methods. diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index fd6108f7..ed3331ad 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -14,7 +14,7 @@ use super::template::{ }; use super::traversal::{EdgeKind, Trace, Tracer}; use crate::clang::{self, Cursor}; -use crate::parse::{ClangItemParser, ParseError, ParseResult}; +use crate::parse::{ParseError, ParseResult}; use std::borrow::Cow; use std::io; diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index c86742ff..610b9dfa 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -10,9 +10,7 @@ use super::ty::{FloatKind, TypeKind}; use crate::callbacks::MacroParsingBehavior; use crate::clang; use crate::clang::ClangToken; -use crate::parse::{ - ClangItemParser, ClangSubItemParser, ParseError, ParseResult, -}; +use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use cexpr; use std::io; use std::num::Wrapping; diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 4402dfc7..3068d14e 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -90,7 +90,7 @@ pub use crate::features::{ use crate::ir::context::{BindgenContext, ItemId}; pub use crate::ir::function::Abi; use crate::ir::item::Item; -use crate::parse::{ClangItemParser, ParseError}; +use crate::parse::ParseError; use crate::regex_set::RegexSet; use std::borrow::Cow; diff --git a/bindgen/parse.rs b/bindgen/parse.rs index f60de431..1fd83cdd 100644 --- a/bindgen/parse.rs +++ b/bindgen/parse.rs @@ -1,8 +1,7 @@ //! Common traits and types related to parsing our IR from Clang cursors. use crate::clang; -use crate::ir::context::{BindgenContext, ItemId, TypeId}; -use crate::ir::ty::TypeKind; +use crate::ir::context::{BindgenContext, ItemId}; /// Not so much an error in the traditional sense, but a control flow message /// when walking over Clang's AST with a cursor. @@ -39,64 +38,3 @@ pub trait ClangSubItemParser: Sized { context: &mut BindgenContext, ) -> Result, ParseError>; } - -/// An intermediate representation item that can be parsed from a Clang cursor. -pub trait ClangItemParser: Sized { - /// Parse this item from the given Clang cursor. - fn parse( - cursor: clang::Cursor, - parent: Option, - context: &mut BindgenContext, - ) -> Result; - - /// Parse this item from the given Clang type. - fn from_ty( - ty: &clang::Type, - location: clang::Cursor, - parent: Option, - ctx: &mut BindgenContext, - ) -> Result; - - /// Identical to `from_ty`, but use the given `id` as the `ItemId` for the - /// newly parsed item. - fn from_ty_with_id( - id: ItemId, - ty: &clang::Type, - location: clang::Cursor, - parent: Option, - ctx: &mut BindgenContext, - ) -> Result; - - /// 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. - fn from_ty_or_ref( - ty: clang::Type, - location: clang::Cursor, - parent_id: Option, - context: &mut BindgenContext, - ) -> TypeId; - - /// Identical to `from_ty_or_ref`, but use the given `potential_id` as the - /// `ItemId` for the newly parsed item. - fn from_ty_or_ref_with_id( - potential_id: ItemId, - ty: clang::Type, - location: clang::Cursor, - parent_id: Option, - context: &mut BindgenContext, - ) -> TypeId; - - /// Create a named template type. - fn type_param( - with_id: Option, - location: clang::Cursor, - ctx: &mut BindgenContext, - ) -> Option; - - /// Create a builtin type. - fn builtin_type( - kind: TypeKind, - is_const: bool, - context: &mut BindgenContext, - ) -> TypeId; -}