summaryrefslogtreecommitdiff
path: root/src/vm/nsenumhandleallcases.h
blob: 7a7c2dbe1ff20668f4cc159b867882f830e4b6d2 (plain)
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
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
// NSENUMSHANDLEALLCASES.H -
//

//
// Meta-programming to ensure that all NFT cases are properly handled in switch statements that should handle all NFT types
//
// Uses of this header file are done by
//  - #include the header before the case statement, probably at the top of the cpp file
//  - #define NFT_CASE_VERIFICATION_TYPE_NAME(type) before the switch to give a descriptive name based on type. The type name string
//     is the detail that gets used to find the switch statement that has a problem
//  - Instead of using normal case statements, use NFT_CASE(type). See examples in class.cpp.
//  - In a default: case statement, define NFT_VERIFY_ALL_CASES and then include this file again.
//
#ifndef NSENUMHANDLEALLCASES_H
#define NSENUMHANDLEALLCASES_H

// Requiring all nft types to be handled is done by defining a variable in each case statement, and then in the default: statement
// computing a value that depends on the value of all of those variables.

#ifdef _DEBUG
#define NFT_CASE(type) case type: int NFT_CASE_VERIFICATION_TYPE_NAME(type);

#else
#define NFT_CASE(type) case type:
#endif
#endif // NSENUMHANDLEALLCASES_H

#if defined(_DEBUG) && defined(NFT_VERIFY_ALL_CASES)

int *nftAccumulator = nullptr;
do {
#undef DEFINE_NFT
#define DEFINE_NFT(type, size, WinRTSupported) nftAccumulator += (int)&NFT_CASE_VERIFICATION_TYPE_NAME(type),
#include "nsenums.h"
nftAccumulator = nullptr;
} while (false);
#undef DEFINE_NFT
#endif // _DEBUG && NFT_VERIFY_ALL_CASES
#undef NFT_VERIFY_ALL_CASES
#undef NFT_CASE_VERIFICATION_TYPE_NAME