Simplify MAKE_REFLECT_TYPE_PROXY

This commit is contained in:
Jacob Dufault 2018-01-29 16:35:01 -08:00
parent a392301be3
commit 7579d71b85
9 changed files with 20 additions and 22 deletions

View File

@ -41,8 +41,7 @@ enum class ClangSymbolKind : uint8_t {
Parameter = 25, Parameter = 25,
Using, Using,
}; };
MAKE_REFLECT_TYPE_PROXY(ClangSymbolKind, MAKE_REFLECT_TYPE_PROXY(ClangSymbolKind);
std::underlying_type<ClangSymbolKind>::type);
// clang/Basic/Specifiers.h clang::StorageClass // clang/Basic/Specifiers.h clang::StorageClass
enum class StorageClass : uint8_t { enum class StorageClass : uint8_t {
@ -63,7 +62,7 @@ enum class StorageClass : uint8_t {
Auto, Auto,
Register Register
}; };
MAKE_REFLECT_TYPE_PROXY(StorageClass, std::underlying_type<StorageClass>::type); MAKE_REFLECT_TYPE_PROXY(StorageClass);
enum class SymbolRole : uint8_t { enum class SymbolRole : uint8_t {
Declaration = 1 << 0, Declaration = 1 << 0,
@ -75,7 +74,7 @@ enum class SymbolRole : uint8_t {
BaseOf = 1 << 5, BaseOf = 1 << 5,
CalledBy = 1 << 6, CalledBy = 1 << 6,
}; };
MAKE_REFLECT_TYPE_PROXY(SymbolRole, std::underlying_type<SymbolRole>::type); MAKE_REFLECT_TYPE_PROXY(SymbolRole);
inline uint8_t operator&(SymbolRole lhs, SymbolRole rhs) { inline uint8_t operator&(SymbolRole lhs, SymbolRole rhs) {
return uint8_t(lhs) & uint8_t(rhs); return uint8_t(lhs) & uint8_t(rhs);

View File

@ -34,7 +34,7 @@ using namespace std::experimental;
// The order matters. In FindSymbolsAtLocation, we want Var/Func ordered in // The order matters. In FindSymbolsAtLocation, we want Var/Func ordered in
// front of others. // front of others.
enum class SymbolKind : uint8_t { Invalid, File, Type, Func, Var }; enum class SymbolKind : uint8_t { Invalid, File, Type, Func, Var };
MAKE_REFLECT_TYPE_PROXY(SymbolKind, uint8_t); MAKE_REFLECT_TYPE_PROXY(SymbolKind);
template <typename T> template <typename T>
struct Id { struct Id {
@ -480,7 +480,7 @@ struct IndexInclude {
// a file previously identified as `C`, will be changed to `Cpp` if it // a file previously identified as `C`, will be changed to `Cpp` if it
// encounters a c++ declaration. // encounters a c++ declaration.
enum class LanguageId { Unknown = 0, C = 1, Cpp = 2, ObjC = 3 }; enum class LanguageId { Unknown = 0, C = 1, Cpp = 2, ObjC = 3 };
MAKE_REFLECT_TYPE_PROXY(LanguageId, std::underlying_type<LanguageId>::type); MAKE_REFLECT_TYPE_PROXY(LanguageId);
struct IndexFile { struct IndexFile {
IdCache id_cache; IdCache id_cache;

View File

@ -67,7 +67,7 @@ enum class IpcId : int {
CqueryWait, CqueryWait,
}; };
MAKE_ENUM_HASHABLE(IpcId) MAKE_ENUM_HASHABLE(IpcId)
MAKE_REFLECT_TYPE_PROXY(IpcId, int) MAKE_REFLECT_TYPE_PROXY(IpcId)
const char* IpcIdToString(IpcId id); const char* IpcIdToString(IpcId id);
struct BaseIpcMessage { struct BaseIpcMessage {

View File

@ -199,7 +199,7 @@ enum class lsSymbolKind : int {
Boolean = 17, Boolean = 17,
Array = 18 Array = 18
}; };
MAKE_REFLECT_TYPE_PROXY(lsSymbolKind, int); MAKE_REFLECT_TYPE_PROXY(lsSymbolKind);
struct lsSymbolInformation { struct lsSymbolInformation {
std::string name; std::string name;
@ -301,7 +301,7 @@ enum class lsInsertTextFormat {
// https://github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md // https://github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md
Snippet = 2 Snippet = 2
}; };
MAKE_REFLECT_TYPE_PROXY(lsInsertTextFormat, int); MAKE_REFLECT_TYPE_PROXY(lsInsertTextFormat);
// The kind of a completion entry. // The kind of a completion entry.
enum class lsCompletionItemKind { enum class lsCompletionItemKind {
@ -331,7 +331,7 @@ enum class lsCompletionItemKind {
Operator = 24, Operator = 24,
TypeParameter = 25, TypeParameter = 25,
}; };
MAKE_REFLECT_TYPE_PROXY(lsCompletionItemKind, int); MAKE_REFLECT_TYPE_PROXY(lsCompletionItemKind);
struct lsCompletionItem { struct lsCompletionItem {
// A set of function parameters. Used internally for signature help. Not sent // A set of function parameters. Used internally for signature help. Not sent
@ -455,7 +455,7 @@ enum class lsDocumentHighlightKind {
// Write-access of a symbol, like writing to a variable. // Write-access of a symbol, like writing to a variable.
Write = 3 Write = 3
}; };
MAKE_REFLECT_TYPE_PROXY(lsDocumentHighlightKind, int); MAKE_REFLECT_TYPE_PROXY(lsDocumentHighlightKind);
struct lsFormattingOptions { struct lsFormattingOptions {
// Size of a tab in spaces. // Size of a tab in spaces.
@ -487,7 +487,7 @@ enum class lsDiagnosticSeverity {
// Reports a hint. // Reports a hint.
Hint = 4 Hint = 4
}; };
MAKE_REFLECT_TYPE_PROXY(lsDiagnosticSeverity, int); MAKE_REFLECT_TYPE_PROXY(lsDiagnosticSeverity);
struct lsDiagnostic { struct lsDiagnostic {
// The range at which the message applies. // The range at which the message applies.
@ -527,7 +527,7 @@ enum class lsErrorCodes {
// Defined by the protocol. // Defined by the protocol.
RequestCancelled = -32800, RequestCancelled = -32800,
}; };
MAKE_REFLECT_TYPE_PROXY(lsErrorCodes, int); MAKE_REFLECT_TYPE_PROXY(lsErrorCodes);
struct Out_Error : public lsOutMessage<Out_Error> { struct Out_Error : public lsOutMessage<Out_Error> {
struct lsResponseError { struct lsResponseError {
// A number indicating the error type that occurred. // A number indicating the error type that occurred.
@ -621,7 +621,7 @@ MAKE_REFLECT_STRUCT(lsTextDocumentDidChangeParams,
// Show a message to the user. // Show a message to the user.
enum class lsMessageType : int { Error = 1, Warning = 2, Info = 3, Log = 4 }; enum class lsMessageType : int { Error = 1, Warning = 2, Info = 3, Log = 4 };
MAKE_REFLECT_TYPE_PROXY(lsMessageType, int) MAKE_REFLECT_TYPE_PROXY(lsMessageType)
struct Out_ShowLogMessageParams { struct Out_ShowLogMessageParams {
lsMessageType type = lsMessageType::Error; lsMessageType type = lsMessageType::Error;
std::string message; std::string message;

View File

@ -39,7 +39,7 @@ struct Out_CqueryCallTree : public lsOutMessage<Out_CqueryCallTree> {
lsRequestId id; lsRequestId id;
std::vector<CallEntry> result; std::vector<CallEntry> result;
}; };
MAKE_REFLECT_TYPE_PROXY(Out_CqueryCallTree::CallType, int); MAKE_REFLECT_TYPE_PROXY(Out_CqueryCallTree::CallType);
MAKE_REFLECT_STRUCT(Out_CqueryCallTree::CallEntry, MAKE_REFLECT_STRUCT(Out_CqueryCallTree::CallEntry,
name, name,
usr, usr,

View File

@ -98,7 +98,7 @@ enum class lsTextDocumentSyncKind {
// send. // send.
Incremental = 2 Incremental = 2
}; };
MAKE_REFLECT_TYPE_PROXY(lsTextDocumentSyncKind, int) MAKE_REFLECT_TYPE_PROXY(lsTextDocumentSyncKind)
struct lsTextDocumentSyncOptions { struct lsTextDocumentSyncOptions {
// Open and close notifications are sent to the server. // Open and close notifications are sent to the server.

View File

@ -22,8 +22,7 @@ enum class lsCompletionTriggerKind {
// the `triggerCharacters` properties of the `CompletionRegistrationOptions`. // the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
TriggerCharacter = 2 TriggerCharacter = 2
}; };
MAKE_REFLECT_TYPE_PROXY(lsCompletionTriggerKind, MAKE_REFLECT_TYPE_PROXY(lsCompletionTriggerKind);
std::underlying_type<lsCompletionTriggerKind>::type);
// Contains additional information about the context in which a completion // Contains additional information about the context in which a completion
// request is triggered. // request is triggered.

View File

@ -12,8 +12,7 @@ enum class lsFileChangeType {
Changed = 2, Changed = 2,
Deleted = 3, Deleted = 3,
}; };
MAKE_REFLECT_TYPE_PROXY(lsFileChangeType, MAKE_REFLECT_TYPE_PROXY(lsFileChangeType);
std::underlying_type<lsFileChangeType>::type);
struct lsFileEvent { struct lsFileEvent {
lsDocumentUri uri; lsDocumentUri uri;

View File

@ -78,8 +78,9 @@ struct IndexFile;
#define REFLECT_MEMBER(name) ReflectMember(visitor, #name, value.name) #define REFLECT_MEMBER(name) ReflectMember(visitor, #name, value.name)
#define REFLECT_MEMBER2(name, value) ReflectMember(visitor, name, value) #define REFLECT_MEMBER2(name, value) ReflectMember(visitor, name, value)
// TODO Make it inline because this macro can be used in header files. #define MAKE_REFLECT_TYPE_PROXY(type_name) \
#define MAKE_REFLECT_TYPE_PROXY(type, as_type) \ MAKE_REFLECT_TYPE_PROXY2(type_name, std::underlying_type<type_name>::type)
#define MAKE_REFLECT_TYPE_PROXY2(type, as_type) \
ATTRIBUTE_UNUSED inline void Reflect(Reader& visitor, type& value) { \ ATTRIBUTE_UNUSED inline void Reflect(Reader& visitor, type& value) { \
as_type value0; \ as_type value0; \
::Reflect(visitor, value0); \ ::Reflect(visitor, value0); \