Start a preprocessor conditional, with an initial enable/disable state.
| 935 | |
| 936 | // Start a preprocessor conditional, with an initial enable/disable state. |
| 937 | static void BeginConditional(PreprocessorDirectiveContext* context, bool enable) |
| 938 | { |
| 939 | Preprocessor* preprocessor = context->preprocessor; |
| 940 | PreprocessorInputStream* inputStream = preprocessor->inputStream; |
| 941 | assert(inputStream); |
| 942 | |
| 943 | PreprocessorConditional* conditional = CreateConditional(preprocessor); |
| 944 | |
| 945 | conditional->ifToken = context->directiveToken; |
| 946 | |
| 947 | // Set state of this condition appropriately. |
| 948 | // |
| 949 | // Default to the "haven't yet seen a `true` branch" state. |
| 950 | PreprocessorConditionalState state = PreprocessorConditionalState::Before; |
| 951 | // |
| 952 | // If we are nested inside a `false` branch of another condition, then |
| 953 | // we never want to enable, so we act as if we already *saw* the `true` branch. |
| 954 | // |
| 955 | if (IsSkipping(preprocessor)) state = PreprocessorConditionalState::After; |
| 956 | // |
| 957 | // Similarly, if we ran into any parse errors when dealing with the |
| 958 | // opening directive, then things are probably screwy and we should just |
| 959 | // skip all the branches. |
| 960 | if (IsSkipping(preprocessor)) state = PreprocessorConditionalState::After; |
| 961 | // |
| 962 | // Otherwise, if our condition was true, then set us to be inside the `true` branch |
| 963 | else if (enable) state = PreprocessorConditionalState::During; |
| 964 | |
| 965 | conditional->state = state; |
| 966 | |
| 967 | // Push conditional onto the stack |
| 968 | conditional->parent = inputStream->conditional; |
| 969 | inputStream->conditional = conditional; |
| 970 | } |
| 971 | |
| 972 | // |
| 973 | // Preprocessor Conditional Expressions |
no test coverage detected