gccjit/
parameter.rs

1use std::marker::PhantomData;
2use std::fmt;
3use context::Context;
4use object::{ToObject, Object};
5use object;
6use rvalue::{RValue, ToRValue};
7use rvalue;
8use lvalue::{LValue, ToLValue};
9use lvalue;
10
11/// Parameter represents a parameter to a function. A series of parameteres
12/// can be combined to form a function signature.
13#[derive(Copy, Clone, PartialEq)]
14pub struct Parameter<'ctx> {
15    marker: PhantomData<&'ctx Context<'ctx>>,
16    ptr: *mut gccjit_sys::gcc_jit_param
17}
18
19impl<'ctx> ToObject<'ctx> for Parameter<'ctx> {
20    fn to_object(&self) -> Object<'ctx> {
21        unsafe {
22            object::from_ptr(gccjit_sys::gcc_jit_param_as_object(self.ptr))
23        }
24    }
25}
26
27impl<'ctx> fmt::Debug for Parameter<'ctx> {
28    fn fmt<'a>(&self, fmt: &mut fmt::Formatter<'a>) -> Result<(), fmt::Error> {
29        let obj = self.to_object();
30        obj.fmt(fmt)
31    }
32}
33
34impl<'ctx> ToRValue<'ctx> for Parameter<'ctx> {
35    fn to_rvalue(&self) -> RValue<'ctx> {
36        unsafe {
37            let ptr = gccjit_sys::gcc_jit_param_as_rvalue(self.ptr);
38            rvalue::from_ptr(ptr)
39        }
40    }
41}
42
43impl<'ctx> ToLValue<'ctx> for Parameter<'ctx> {
44    fn to_lvalue(&self) -> LValue<'ctx> {
45        unsafe {
46            let ptr = gccjit_sys::gcc_jit_param_as_lvalue(self.ptr);
47            lvalue::from_ptr(ptr)
48        }
49    }
50}
51
52
53pub unsafe fn from_ptr<'ctx>(ptr: *mut gccjit_sys::gcc_jit_param) -> Parameter<'ctx> {
54    Parameter {
55        marker: PhantomData,
56        ptr
57    }
58}
59
60pub unsafe fn get_ptr<'ctx>(loc: &Parameter<'ctx>) -> *mut gccjit_sys::gcc_jit_param {
61    loc.ptr
62}
63