summaryrefslogtreecommitdiff
path: root/src/mir/mir_ptr.hpp
blob: 27dd6b22dbf99a150ccf5350f2354b7079f87cd5 (plain)
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
/*
 * MRustC - Rust Compiler
 * - By John Hodge (Mutabah/thePowersGang)
 *
 * mir/mir_ptr.hpp
 * - Pointer to a blob of MIR
 */
#pragma once

namespace MIR {

class Function;

class FunctionPointer
{
    ::MIR::Function*    ptr;
public:
    FunctionPointer(): ptr(nullptr) {}
    FunctionPointer(::MIR::Function* p): ptr(p) {}
    FunctionPointer(FunctionPointer&& x): ptr(x.ptr) { x.ptr = nullptr; }

    ~FunctionPointer() {
        reset();
    }
    FunctionPointer& operator=(FunctionPointer&& x) {
        reset();
        ptr = x.ptr;
        x.ptr = nullptr;
        return *this;
    }

    void reset();

          ::MIR::Function* operator->()       { if(!ptr) throw ""; return ptr; }
    const ::MIR::Function* operator->() const { if(!ptr) throw ""; return ptr; }
          ::MIR::Function& operator*()       { if(!ptr) throw ""; return *ptr; }
    const ::MIR::Function& operator*() const { if(!ptr) throw ""; return *ptr; }

    operator bool() const { return ptr != nullptr; }
};

}