llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
use.h
1 // This file if part of the llir-opt project.
2 // Licensing information can be found in the LICENSE file.
3 // (C) 2018 Nandor Licker. All rights reserved.
4 
5 #pragma once
6 
7 #include "core/ref.h"
8 
9 class Use;
10 class User;
11 class Value;
12 
13 
14 
18 class Use final {
19 public:
21  Use() : val_(nullptr), user_(nullptr) {}
23  Use(Ref<Value> val, User *user);
25  ~Use();
26 
28  Use(const Use &) = delete;
30  Use(Use &&) = delete;
31 
34 
36  Use &operator = (const Use &) = delete;
38  Use &operator = (Use &&) = delete;
39 
41  User *getUser() const { return user_; }
43  Use *getNext() const { return next_; }
44 
45  // Return the underlying value.
46  Ref<Value> get() { return val_; }
47  // Return the underlying value.
48  ConstRef<Value> get() const { return val_; }
49 
50  // Return the underlying value.
51  operator Ref<Value>&() { return val_; }
52  // Return the underlying value.
53  operator ConstRef<Value>() const { return val_; }
54 
55  // Return the underlying value.
56  Ref<Value> operator*() { return val_; }
57  // Return the underlying value.
58  ConstRef<Value> operator*() const { return val_; }
59  // Point to the underlying value.
60  Ref<Value> operator->() { return val_; }
61  // Point to the underlying value.
62  ConstRef<Value> operator->() const { return val_; }
63 
64  // Checks if the use points to a value.
65  operator bool() const { return val_; }
66 
67 private:
68  friend class Value;
69  friend class User;
70 
71  void Remove();
72  void Add();
73 
75  Ref<Value> val_;
77  User *user_;
79  Use *prev_ = nullptr;
81  Use *next_ = nullptr;
82 };
83 
Use::Use
Use()
Creates an empty use.
Definition: use.h:21
Use
Definition: use.h:18
Use::getNext
Use * getNext() const
Returns the next use.
Definition: use.h:43
ConstRef
Definition: ref.h:83
Value
Definition: value.h:22
Use::operator=
Use & operator=(Ref< Value > val)
Assign a new value.
Definition: use.cpp:22
Use::getUser
User * getUser() const
Returns the user attached to this use.
Definition: use.h:41
Ref< Value >
User
Definition: user.h:20
Use::~Use
~Use()
Destroys a use.
Definition: use.cpp:53