Skip to content

Greatly improve API #36

@GuillaumeGomez

Description

@GuillaumeGomez

In gccjit, a lot of objects inherit (in the C++ meaning) from one or more parents, which is not reflected in this crate. For example, LValue should have access to all RValue methods since it inherits from it.

We could make the implementation as such:

impl RValueTrait {
    fn get_type(&self) -> Type<'ctx> {
        get_rvalue_type(self)
    }

    fn as_rvalue(&self) -> RValue<'tcx>; // la seule methode a implem
}

fn get_rvalue_type<T: RValueTrait>(t: &T) -> Type<'tcx> {
    t.as_rvalue().get_type()
}

impl RValueTrait for LValue {
    fn as_rvalue(&self) -> RValue<'ctx> {
        gcc_jit_lvalue_as_rvalue(self.ptr)
    }
}

It has the advantage that the logic is only in one place and all objects inheriting from RValue can just implement the trait and the as_rvalue method to have access to all its methods.

Waiting for @antoyo approval before making the implementation.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions