Thorin 1.9.0
The Higher ORder INtermediate representation
Loading...
Searching...
No Matches
util.h File Reference
#include <optional>
#include <queue>
#include <stack>
#include <type_traits>
#include <absl/container/flat_hash_map.h>
#include <absl/container/flat_hash_set.h>
#include <absl/container/node_hash_map.h>
#include <absl/container/node_hash_set.h>
#include <fe/assert.h>
#include "thorin/util/hash.h"
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  thorin::unique_stack< Set >
 
class  thorin::unique_queue< Set >
 
struct  thorin::GIDHash< T >
 
struct  thorin::GIDEq< T >
 
struct  thorin::GIDLt< T >
 

Namespaces

namespace  thorin
 

Macros

#define THORIN_ENUM_OPERATORS(E)
 Use this to declare all kind of bit and comparison operators for an enum E.
 

Typedefs

GID
template<class K , class V >
using thorin::GIDMap = absl::flat_hash_map< K, V, GIDHash< K >, GIDEq< K > >
 
template<class K >
using thorin::GIDSet = absl::flat_hash_set< K, GIDHash< K >, GIDEq< K > >
 
template<class K , class V >
using thorin::GIDNodeMap = absl::node_hash_map< K, V, GIDHash< K >, GIDEq< K > >
 
template<class K >
using thorin::GIDNodeSet = absl::node_hash_set< K, GIDHash< K >, GIDEq< K > >
 

Functions

Utility Functions
template<class This , class T >
T & thorin::lazy_init (const This *self, std::unique_ptr< T > &ptr)
 
template<class D , class S >
thorin::bitcast (const S &src)
 A bitcast from src of type S to D.
 
template<class T >
bool thorin::get_sign (T val)
 
u64 thorin::pad (u64 offset, u64 align)
 
Algorithms
template<class I , class T , class Cmp >
thorin::binary_find (I begin, I end, T val, Cmp cmp)
 
std::string_view thorin::subview (std::string_view s, size_t i, size_t n=std::string_view::npos)
 Like std::string::substr, but works on std::string_view instead.
 
void thorin::find_and_replace (std::string &str, std::string_view what, std::string_view repl)
 Replaces all occurrences of what with repl.
 
Helpers for Containers
template<class S >
auto thorin::pop (S &s) -> decltype(s.top(), typename S::value_type())
 
template<class Q >
auto thorin::pop (Q &q) -> decltype(q.front(), typename Q::value_type())
 
template<class C , class K >
auto thorin::lookup (const C &container, const K &key)
 Yields pointer to element (or the element itself if it is already a pointer), if found and nullptr otherwise.
 
template<class C , class... Args>
auto thorin::assert_emplace (C &container, Args &&... args)
 Invokes emplace on container, asserts that insertion actually happened, and returns the iterator.
 

Macro Definition Documentation

◆ THORIN_ENUM_OPERATORS

#define THORIN_ENUM_OPERATORS (   E)
Value:
constexpr auto operator&( E x, E y) { return std::underlying_type_t<E>(x) & std::underlying_type_t<E>(y); } \
constexpr auto operator&(std::underlying_type_t<E> x, E y) { return x & std::underlying_type_t<E>(y); } \
constexpr auto operator&( E x, std::underlying_type_t<E> y) { return std::underlying_type_t<E>(x) & y ; } \
constexpr auto operator|( E x, E y) { return std::underlying_type_t<E>(x) | std::underlying_type_t<E>(y); } \
constexpr auto operator|(std::underlying_type_t<E> x, E y) { return x | std::underlying_type_t<E>(y); } \
constexpr auto operator|( E x, std::underlying_type_t<E> y) { return std::underlying_type_t<E>(x) | y ; } \
constexpr auto operator^( E x, E y) { return std::underlying_type_t<E>(x) ^ std::underlying_type_t<E>(y); } \
constexpr auto operator^(std::underlying_type_t<E> x, E y) { return x ^ std::underlying_type_t<E>(y); } \
constexpr auto operator^( E x, std::underlying_type_t<E> y) { return std::underlying_type_t<E>(x) ^ y ; } \
constexpr std::strong_ordering operator<=>(std::underlying_type_t<E> x, E y) { return x <=> std::underlying_type_t<E>(y); } \
constexpr std::strong_ordering operator<=>(E x, std::underlying_type_t<E> y) { return std::underlying_type_t<E>(x) <=> y; } \
constexpr bool operator==(std::underlying_type_t<E> x, E y) { return x == std::underlying_type_t<E>(y); } \
constexpr bool operator==(E x, std::underlying_type_t<E> y) { return std::underlying_type_t<E>(x) == y; }

Use this to declare all kind of bit and comparison operators for an enum E.

Note that the bit operators return E's underlying type and not the original enum E. This is because the result may not be a valid enum value. For the same reason, it doesn't make sense to declare operators such as &=.

Definition at line 189 of file util.h.