-
Notifications
You must be signed in to change notification settings - Fork 37
change all enum to enum class
#759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,19 @@ using TCppFuncAddr_t = void*; | |
| using TInterp_t = void*; | ||
| using TCppObject_t = void*; | ||
|
|
||
| enum Operator : unsigned char { | ||
| template <typename T> struct TruthValue { | ||
| T t; | ||
| constexpr TruthValue(T t) : t(t) {} | ||
| constexpr operator T() const { return t; } | ||
| constexpr explicit operator bool() const { return underlying(t); } | ||
| }; | ||
|
|
||
| template <typename T> using Underlying = std::underlying_type_t<T>; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "std::underlying_type_t" is directly included [misc-include-cleaner] include/CppInterOp/CppInterOp.h:22: - #include <vector>
+ #include <type_traits>
+ #include <vector> |
||
| template <typename T> constexpr Underlying<T> underlying(T t) { | ||
| return Underlying<T>(t); | ||
| } | ||
|
|
||
| enum class Operator : unsigned char { | ||
| OP_None, | ||
| OP_New, | ||
| OP_Delete, | ||
|
|
@@ -93,18 +105,31 @@ enum Operator : unsigned char { | |
| OP_Coawait, | ||
| }; | ||
|
|
||
| enum OperatorArity : unsigned char { kUnary = 1, kBinary, kBoth }; | ||
| enum class OperatorArity : unsigned char { kUnary = 1, kBinary, kBoth }; | ||
|
|
||
| constexpr TruthValue<OperatorArity> operator&(OperatorArity l, | ||
| OperatorArity r) { | ||
| return OperatorArity(underlying(l) & underlying(r)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think arity could be xor-ed -- we have already |
||
| } | ||
|
|
||
| constexpr TruthValue<OperatorArity> operator|(OperatorArity l, | ||
| OperatorArity r) { | ||
| return OperatorArity(underlying(l) | underlying(r)); | ||
| } | ||
|
|
||
| /// Enum modelling CVR qualifiers. | ||
| enum QualKind : unsigned char { | ||
| enum class QualKind : unsigned char { | ||
| Const = 1 << 0, | ||
| Volatile = 1 << 1, | ||
| Restrict = 1 << 2 | ||
| }; | ||
|
|
||
| inline QualKind operator|(QualKind a, QualKind b) { | ||
| return static_cast<QualKind>(static_cast<unsigned char>(a) | | ||
| static_cast<unsigned char>(b)); | ||
| constexpr TruthValue<QualKind> operator&(QualKind l, QualKind r) { | ||
| return QualKind(underlying(l) & underlying(r)); | ||
| } | ||
|
|
||
| constexpr TruthValue<QualKind> operator|(QualKind l, QualKind r) { | ||
| return QualKind(underlying(l) | underlying(r)); | ||
| } | ||
|
|
||
| /// A class modeling function calls for functions produced by the interpreter | ||
|
|
@@ -686,7 +711,7 @@ CPPINTEROP_API OperatorArity GetOperatorArity(TCppFunction_t op); | |
| ///\returns list of operator overloads | ||
| CPPINTEROP_API void GetOperator(TCppScope_t scope, Operator op, | ||
| std::vector<TCppFunction_t>& operators, | ||
| OperatorArity kind = kBoth); | ||
| OperatorArity kind = OperatorArity::kBoth); | ||
|
|
||
| /// Creates an owned instance of the interpreter we need for the various interop | ||
| /// services and pushes it onto a stack. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect we can forward declare the operators and implement them in the cpp file and then we could hide this class completely from the interface.