public bool IncrementallyEquivalent(Directive other) { if (this.Kind != other.Kind) { return false; } bool isActive = this.IsActive; bool otherIsActive = other.IsActive; // states of inactive directives don't matter if (!isActive && !otherIsActive) { return true; } if (isActive != otherIsActive) { return false; } switch (this.Kind) { case SyntaxKind.DefineDirectiveTrivia: case SyntaxKind.UndefDirectiveTrivia: return this.GetIdentifier() == other.GetIdentifier(); case SyntaxKind.IfDirectiveTrivia: case SyntaxKind.ElifDirectiveTrivia: case SyntaxKind.ElseDirectiveTrivia: return this.BranchTaken == other.BranchTaken; default: return true; } }
public DirectiveStack Add(Directive directive) { switch (directive.Kind) { case SyntaxKind.EndIfDirectiveTrivia: var prevIf = GetPreviousIf(_directives); if (prevIf == null || !prevIf.Any()) { goto default; // no matching if directive !! leave directive alone } bool tmp; return new DirectiveStack(CompleteIf(_directives, out tmp)); case SyntaxKind.EndRegionDirectiveTrivia: var prevRegion = GetPreviousRegion(_directives); if (prevRegion == null || !prevRegion.Any()) { goto default; // no matching region directive !! leave directive alone } return new DirectiveStack(CompleteRegion(_directives)); // remove region directives from stack but leave everything else default: return new DirectiveStack(new ConsList<Directive>(directive, _directives != null ? _directives : ConsList<Directive>.Empty)); } }