From d3d3649a68cb1fa589fdd987a6690dbd5d671f0d Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 17 Sep 2017 15:35:20 -0700 Subject: Initial code commit --- src/WixToolset.Core/Preprocess/IfContext.cs | 110 ++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/WixToolset.Core/Preprocess/IfContext.cs (limited to 'src/WixToolset.Core/Preprocess') diff --git a/src/WixToolset.Core/Preprocess/IfContext.cs b/src/WixToolset.Core/Preprocess/IfContext.cs new file mode 100644 index 00000000..64b5bd91 --- /dev/null +++ b/src/WixToolset.Core/Preprocess/IfContext.cs @@ -0,0 +1,110 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Preprocess +{ + using System; + + /// + /// Current state of the if context. + /// + internal enum IfState + { + /// Context currently in unknown state. + Unknown, + + /// Context currently inside if statement. + If, + + /// Context currently inside elseif statement.. + ElseIf, + + /// Conext currently inside else statement. + Else, + } + + /// + /// Context for an if statement in the preprocessor. + /// + internal sealed class IfContext + { + private bool active; + private bool keep; + private bool everKept; + private IfState state; + + /// + /// Creates a default if context object, which are used for if's within an inactive preprocessor block + /// + public IfContext() + { + this.active = false; + this.keep = false; + this.everKept = true; + this.state = IfState.If; + } + + /// + /// Creates an if context object. + /// + /// Flag if context is currently active. + /// Flag if context is currently true. + /// State of context to start in. + public IfContext(bool active, bool keep, IfState state) + { + this.active = active; + this.keep = keep; + this.everKept = keep; + this.state = state; + } + + /// + /// Gets and sets if this if context is currently active. + /// + /// true if context is active. + public bool Active + { + get { return this.active; } + set { this.active = value; } + } + + /// + /// Gets and sets if context is current true. + /// + /// true if context is currently true. + public bool IsTrue + { + get + { + return this.keep; + } + + set + { + this.keep = value; + if (this.keep) + { + this.everKept = true; + } + } + } + + /// + /// Gets if the context was ever true. + /// + /// True if context was ever true. + public bool WasEverTrue + { + get { return this.everKept; } + } + + /// + /// Gets the current state of the if context. + /// + /// Current state of context. + public IfState IfState + { + get { return this.state; } + set { this.state = value; } + } + } +} -- cgit v1.2.3-55-g6feb