This repository was archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.cpp
More file actions
56 lines (39 loc) · 1.48 KB
/
type.cpp
File metadata and controls
56 lines (39 loc) · 1.48 KB
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
#ifndef JDECOMPILER_TYPE_H
#define JDECOMPILER_TYPE_H
#include "type.h"
namespace jdecompiler {
template<bool isNoexcept, bool widest>
const Type* Type::cast0(const Type* type) const {
// I love such constructions in C++ :)
// It's a pointer to a member function
static constexpr const Type* (Type::* castImplFunc)(const Type*) const = getCastImplFunction<widest>();
static constexpr const Type* (Type::* reversedCastImplFunc)(const Type*) const = getReversedCastImplFunction<widest>();
const Type* castedType;
if((castedType = (this->*castImplFunc)(type)) != nullptr) {
return castedType;
}
(type->*reversedCastImplFunc)(this);
if(this->canReverseCast(type) && (castedType = (type->*reversedCastImplFunc)(this)) != nullptr) {
return castedType;
}
if constexpr(isNoexcept)
return nullptr;
else
throw IncopatibleTypesException(this, type);
}
template<class T>
const T* Type::twoWayCastTo(const T* t) const {
checkType<T>();
const Type* castedType;
if((castedType = this->castToWidestImpl(t)) != nullptr)
return safe_cast<const T*>(castedType);
if((castedType = ((const Type*)t)->castToWidestImpl(this)) != nullptr)
return safe_cast<const T*>(castedType);
if((castedType = this->reversedCastToWidestImpl(t)) != nullptr)
return safe_cast<const T*>(castedType);
if((castedType = ((const Type*)t)->reversedCastToWidestImpl(this)) != nullptr)
return safe_cast<const T*>(castedType);
throw IncopatibleTypesException(this, t);
}
}
#endif