Skip to main content

TypeRepr

Enum TypeRepr 

Source
pub enum TypeRepr {
    CType {
        specs: CTypeSpecs,
        derived: Vec<CDerivedType>,
        source: CTypeSource,
    },
    RustType {
        repr: RustTypeRepr,
        source: RustTypeSource,
    },
    Inferred(InferredType),
}
Expand description

型表現(出所情報を含む)

Variants§

§

CType

C 言語の型(CHeader, Apidoc, InlineFn 共通)

Fields

§specs: CTypeSpecs

型指定子(int, char, struct X, など)

§derived: Vec<CDerivedType>

派生型(ポインタ、配列など)

§source: CTypeSource

出所(デバッグ用)

§

RustType

Rust バインディングからの型(syn::Type 由来)

Fields

§repr: RustTypeRepr

型表現

§source: RustTypeSource

出所(関数名など)

§

Inferred(InferredType)

推論で導出

Implementations§

Source§

impl TypeRepr

Source

pub fn source_display(&self) -> &'static str

出所の表示用文字列を取得

Source

pub fn is_fn_param_source(&self) -> bool

void 型かどうかを判定

ポインタを含まない void 型の場合に true を返す。 void * は false を返す(有効なポインタ型のため)。 bindings.rs の FnParam ソースかどうか

Source

pub fn confidence_tier(&self) -> u8

型情報の確度 Tier を返す

  • Tier 1: bindings.rs (bindgen生成、変更不可)
  • Tier 2: C ヘッダー宣言 / inline 関数パラメータ (変更不可)
  • Tier 3: apidoc (embed.fnc 等、参考情報)
  • Tier 4: 推論結果 (変更可能)
Source

pub fn is_void(&self) -> bool

Source

pub fn make_outer_pointer_mut(&mut self)

最外ポインタの is_const を true に変更する 最外ポインタの is_const を false に変更する(must-mut 用)

Source

pub fn make_outer_pointer_const(&mut self)

Source

pub fn is_pointer_type(&self) -> bool

ポインタ型かどうか (has_outer_pointer のエイリアス)。

Inferred ラッパは resolved_type() を経由して中身を再帰参照する点で has_outer_pointer と挙動が異なる (本メソッドは構造的「実体型」判定に 使う)。has_outer_pointer 自体は既存の使用箇所が Inferred を別扱い しているため挙動を変えない。

Source

pub fn is_void_pointer(&self) -> bool

void * / *mut c_void / *const c_void かどうかを 構造的に 判定する。

文字列 contains("void") ではなく specs/derived の構造で判定するので、 *mut struct void_table のような偽陽性に引っかからない。 Inferred ラッパは resolved_type() 経由で中身を再帰参照する。

Source

pub fn is_concrete_pointer(&self) -> bool

具体的なポインタ (void * ではないポインタ型) かどうか

Source

pub fn has_outer_pointer(&self) -> bool

最外ポインタを持つかどうか

既存呼出側の挙動を変えないため Inferred は false を返す (再帰判定が必要な場合は is_pointer_type を使うこと)。

Source

pub fn from_apidoc_string(s: &str, interner: &StringInterner) -> Self

Apidoc の型文字列から TypeRepr を作成

Source

pub fn from_rust_string(s: &str) -> Self

Rust 形式の型文字列から TypeRepr を作成

*mut T, *const T, c_int などの Rust 形式の型文字列をパースする。 rust_decl.rs からの型情報の読み込みに使用する。

Source

pub fn from_unified_type(ut: &UnifiedType, interner: &StringInterner) -> Self

構造ベース: UnifiedType から TypeRepr を直接構築する。

bindings.rs (syn::File) → RustField.uty (UnifiedType) で得た 構造化情報を、文字列を経由せず TypeRepr に変換する。 Pointer / Array / Named / 基本型は CType として表現し、 FnPtr / Verbatim / Unknown は表現できないので RustTypeUnknown(canonical_string) にフォールバックする。

Source は CTypeSource::Apidoc { raw } で記録する (tier 3 相当)。 bindings は本来 tier 1 だが、本メソッドの呼出元 (anonymous union メンバ解決) は元の C-side フィールド型を補完する用途なので、tier 3 で十分。tier 1 が必要な経路ができたら別 source variant を追加する。

Source

pub fn from_decl( specs: &DeclSpecs, declarator: &Declarator, _interner: &StringInterner, ) -> Self

DeclSpecs と Declarator から TypeRepr を作成

C ヘッダーのパース結果から直接 TypeRepr を生成する。 fields_dict.rs でのフィールド型収集に使用する。

Source

pub fn from_type_name(type_name: &TypeName, interner: &StringInterner) -> Self

TypeName (パーサー出力) から TypeRepr を作成

parser::parse_type_from_string の結果から TypeRepr を生成する。 from_apidoc_string の代替として使用し、完全な C パーサーを活用する。

Source

pub fn from_c_type_string( s: &str, interner: &StringInterner, files: &FileRegistry, typedefs: &HashSet<InternedStr>, ) -> Self

C 型文字列から TypeRepr を作成(パーサー版)

parser.rsparse_type_from_string を使用して完全な C パーサーで解析する。 filestypedefs が必要なため、SemanticAnalyzer など型情報が揃っている コンテキストでの使用を推奨。

パースに失敗した場合は from_apidoc_string と同じ簡易パーサーにフォールバックする。

Source

pub fn to_display_string(&self, interner: &StringInterner) -> String

後方互換: 文字列に変換(デバッグ用)

Source

pub fn to_rust_string(&self, interner: &StringInterner) -> String

Rust コード生成用の型文字列に変換

Source§

impl TypeRepr

Source

pub fn pointee_name(&self) -> Option<InternedStr>

ポインタ型の参照先の構造体/typedef 名を InternedStr で取得

PtrMember (->) の base 型から構造体名を抽出するために使用。 例: *mut SVSome(SV), XPVHV *Some(XPVHV)

Source

pub fn type_name(&self) -> Option<InternedStr>

非ポインタ型の構造体/typedef 名を InternedStr で取得

Member (.) の base 型から構造体名を抽出するために使用。 例: union _xhvnameuSome(_xhvnameu), SVSome(SV)

Trait Implementations§

Source§

impl Clone for TypeRepr

Source§

fn clone(&self) -> TypeRepr

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TypeRepr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.