1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use std::marker::PhantomData;
use std::fmt;
use gccjit_sys;
use context::Context;
use object::{ToObject, Object};
use object;
use rvalue::{RValue, ToRValue};
use rvalue;
use lvalue::{LValue, ToLValue};
use lvalue;

/// Parameter represents a parameter to a function. A series of parameteres
/// can be combined to form a function signature.
#[derive(Copy, Clone)]
pub struct Parameter<'ctx> {
    marker: PhantomData<&'ctx Context<'ctx>>,
    ptr: *mut gccjit_sys::gcc_jit_param
}

impl<'ctx> ToObject<'ctx> for Parameter<'ctx> {
    fn to_object(&self) -> Object<'ctx> {
        unsafe {
            object::from_ptr(gccjit_sys::gcc_jit_param_as_object(self.ptr))
        }
    }
}

impl<'ctx> fmt::Debug for Parameter<'ctx> {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        let obj = self.to_object();
        obj.fmt(fmt)
    }
}

impl<'ctx> ToRValue<'ctx> for Parameter<'ctx> {
    fn to_rvalue(&self) -> RValue<'ctx> {
        unsafe {
            let ptr = gccjit_sys::gcc_jit_param_as_rvalue(self.ptr);
            rvalue::from_ptr(ptr)
        }
    }
}

impl<'ctx> ToLValue<'ctx> for Parameter<'ctx> {
    fn to_lvalue(&self) -> LValue<'ctx> {
        unsafe {
            let ptr = gccjit_sys::gcc_jit_param_as_lvalue(self.ptr);
            lvalue::from_ptr(ptr)
        }
    }
}


pub unsafe fn from_ptr<'ctx>(ptr: *mut gccjit_sys::gcc_jit_param) -> Parameter<'ctx> {
    Parameter {
        marker: PhantomData,
        ptr: ptr
    }
}

pub unsafe fn get_ptr<'ctx>(loc: &Parameter<'ctx>) -> *mut gccjit_sys::gcc_jit_param {
    loc.ptr
}