Skip to content

Commit

Permalink
Remove traits that have a single implementation (#2363)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdrz authored Nov 24, 2022
1 parent 73f33e5 commit 95fd17b
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 99 deletions.
13 changes: 1 addition & 12 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2406,18 +2406,7 @@ impl CodeGenerator for CompInfo {
}
}

trait MethodCodegen {
fn codegen_method(
&self,
ctx: &BindgenContext,
methods: &mut Vec<proc_macro2::TokenStream>,
method_names: &mut HashSet<String>,
result: &mut CodegenResult<'_>,
parent: &CompInfo,
);
}

impl MethodCodegen for Method {
impl Method {
fn codegen_method(
&self,
ctx: &BindgenContext,
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/enum_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 9 additions & 11 deletions bindgen/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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<ItemId>,
ctx: &mut BindgenContext,
Expand Down Expand Up @@ -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<ItemId>,
Expand All @@ -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,
Expand Down Expand Up @@ -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<ItemId>,
Expand All @@ -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,
Expand Down Expand Up @@ -1742,7 +1740,7 @@ impl ClangItemParser for Item {
/// A named type is a template parameter, e.g., the "T" in Foo<T>. 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<ItemId>,
location: clang::Cursor,
ctx: &mut BindgenContext,
Expand Down
1 change: 0 additions & 1 deletion bindgen/ir/objc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion bindgen/ir/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions bindgen/ir/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
64 changes: 1 addition & 63 deletions bindgen/parse.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -39,64 +38,3 @@ pub trait ClangSubItemParser: Sized {
context: &mut BindgenContext,
) -> Result<ParseResult<Self>, 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<ItemId>,
context: &mut BindgenContext,
) -> Result<ItemId, ParseError>;

/// Parse this item from the given Clang type.
fn from_ty(
ty: &clang::Type,
location: clang::Cursor,
parent: Option<ItemId>,
ctx: &mut BindgenContext,
) -> Result<TypeId, ParseError>;

/// 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<ItemId>,
ctx: &mut BindgenContext,
) -> 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.
fn from_ty_or_ref(
ty: clang::Type,
location: clang::Cursor,
parent_id: Option<ItemId>,
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<ItemId>,
context: &mut BindgenContext,
) -> TypeId;

/// Create a named template type.
fn type_param(
with_id: Option<ItemId>,
location: clang::Cursor,
ctx: &mut BindgenContext,
) -> Option<TypeId>;

/// Create a builtin type.
fn builtin_type(
kind: TypeKind,
is_const: bool,
context: &mut BindgenContext,
) -> TypeId;
}

0 comments on commit 95fd17b

Please sign in to comment.