Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / Common / Utils / Boolean / NegationPusher.cs / 1 / NegationPusher.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Linq;
namespace System.Data.Common.Utils.Boolean
{
// Top-down push-down of negation in Boolean expressions.
// - !(A or B) iff. !A and !B
// - !(A and B) iff. !A or !B
// - !!A iff. A
// Uses two visitor classes: one to handle negated subtrees (essentially creates
// an inverted tree) and one to handle non-negated subtrees (replicates until it
// encounters NotExpr)
internal static class NegationPusher
{
internal static BoolExpr> EliminateNot(BoolExpr> expression)
{
return expression.Accept(NonNegatedDomainConstraintTreeVisitor.Instance);
}
private class NonNegatedTreeVisitor : BasicVisitor
{
internal static readonly NonNegatedTreeVisitor Instance = new NonNegatedTreeVisitor();
protected NonNegatedTreeVisitor()
{
}
internal override BoolExpr VisitNot(NotExpr expression)
{
return expression.Child.Accept(NegatedTreeVisitor.Instance);
}
}
private class NegatedTreeVisitor : Visitor>
{
internal static readonly NegatedTreeVisitor Instance = new NegatedTreeVisitor();
protected NegatedTreeVisitor()
{
}
internal override BoolExpr VisitTrue(TrueExpr expression)
{
return FalseExpr.Value;
}
internal override BoolExpr VisitFalse(FalseExpr expression)
{
return TrueExpr.Value;
}
internal override BoolExpr VisitTerm(TermExpr expression)
{
return new NotExpr(expression);
}
internal override BoolExpr VisitNot(NotExpr expression)
{
return expression.Child.Accept(NonNegatedTreeVisitor.Instance);
}
internal override BoolExpr VisitAnd(AndExpr expression)
{
return new OrExpr(expression.Children.Select(child => child.Accept(this)));
}
internal override BoolExpr VisitOr(OrExpr expression)
{
return new AndExpr(expression.Children.Select(child => child.Accept(this)));
}
}
private class NonNegatedDomainConstraintTreeVisitor : NonNegatedTreeVisitor>
{
internal new static readonly NonNegatedDomainConstraintTreeVisitor Instance = new NonNegatedDomainConstraintTreeVisitor();
private NonNegatedDomainConstraintTreeVisitor()
{
}
internal override BoolExpr> VisitNot(NotExpr> expression)
{
return expression.Child.Accept(NegatedDomainConstraintTreeVisitor.Instance);
}
}
private class NegatedDomainConstraintTreeVisitor : NegatedTreeVisitor>
{
internal new static readonly NegatedDomainConstraintTreeVisitor Instance = new NegatedDomainConstraintTreeVisitor();
private NegatedDomainConstraintTreeVisitor()
{
}
internal override BoolExpr> VisitNot(NotExpr> expression)
{
return expression.Child.Accept(NonNegatedDomainConstraintTreeVisitor.Instance);
}
internal override BoolExpr> VisitTerm(TermExpr> expression)
{
return new TermExpr>(expression.Identifier.InvertDomainConstraint());
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Linq;
namespace System.Data.Common.Utils.Boolean
{
// Top-down push-down of negation in Boolean expressions.
// - !(A or B) iff. !A and !B
// - !(A and B) iff. !A or !B
// - !!A iff. A
// Uses two visitor classes: one to handle negated subtrees (essentially creates
// an inverted tree) and one to handle non-negated subtrees (replicates until it
// encounters NotExpr)
internal static class NegationPusher
{
internal static BoolExpr> EliminateNot(BoolExpr> expression)
{
return expression.Accept(NonNegatedDomainConstraintTreeVisitor.Instance);
}
private class NonNegatedTreeVisitor : BasicVisitor
{
internal static readonly NonNegatedTreeVisitor Instance = new NonNegatedTreeVisitor();
protected NonNegatedTreeVisitor()
{
}
internal override BoolExpr VisitNot(NotExpr expression)
{
return expression.Child.Accept(NegatedTreeVisitor.Instance);
}
}
private class NegatedTreeVisitor : Visitor>
{
internal static readonly NegatedTreeVisitor Instance = new NegatedTreeVisitor();
protected NegatedTreeVisitor()
{
}
internal override BoolExpr VisitTrue(TrueExpr expression)
{
return FalseExpr.Value;
}
internal override BoolExpr VisitFalse(FalseExpr expression)
{
return TrueExpr.Value;
}
internal override BoolExpr VisitTerm(TermExpr expression)
{
return new NotExpr(expression);
}
internal override BoolExpr VisitNot(NotExpr expression)
{
return expression.Child.Accept(NonNegatedTreeVisitor.Instance);
}
internal override BoolExpr VisitAnd(AndExpr expression)
{
return new OrExpr(expression.Children.Select(child => child.Accept(this)));
}
internal override BoolExpr VisitOr(OrExpr expression)
{
return new AndExpr(expression.Children.Select(child => child.Accept(this)));
}
}
private class NonNegatedDomainConstraintTreeVisitor : NonNegatedTreeVisitor>
{
internal new static readonly NonNegatedDomainConstraintTreeVisitor Instance = new NonNegatedDomainConstraintTreeVisitor();
private NonNegatedDomainConstraintTreeVisitor()
{
}
internal override BoolExpr> VisitNot(NotExpr> expression)
{
return expression.Child.Accept(NegatedDomainConstraintTreeVisitor.Instance);
}
}
private class NegatedDomainConstraintTreeVisitor : NegatedTreeVisitor>
{
internal new static readonly NegatedDomainConstraintTreeVisitor Instance = new NegatedDomainConstraintTreeVisitor();
private NegatedDomainConstraintTreeVisitor()
{
}
internal override BoolExpr> VisitNot(NotExpr> expression)
{
return expression.Child.Accept(NonNegatedDomainConstraintTreeVisitor.Instance);
}
internal override BoolExpr> VisitTerm(TermExpr> expression)
{
return new TermExpr>(expression.Identifier.InvertDomainConstraint());
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BufferedStream.cs
- CompositeScriptReferenceEventArgs.cs
- RectKeyFrameCollection.cs
- TextCompositionManager.cs
- ContentWrapperAttribute.cs
- FunctionQuery.cs
- VerificationException.cs
- DockProviderWrapper.cs
- BatchServiceHost.cs
- Wizard.cs
- EdmPropertyAttribute.cs
- LabelLiteral.cs
- ConstrainedDataObject.cs
- ActiveDocumentEvent.cs
- SettingsSection.cs
- ScrollItemPatternIdentifiers.cs
- Pair.cs
- TextBoxBase.cs
- DropShadowBitmapEffect.cs
- RepeaterCommandEventArgs.cs
- AutomationPropertyInfo.cs
- SystemInfo.cs
- TypeSystemHelpers.cs
- TypeDefinition.cs
- Visitor.cs
- Assembly.cs
- RawStylusInputCustomData.cs
- WebException.cs
- WebReferencesBuildProvider.cs
- UrlMappingsSection.cs
- Walker.cs
- DrawingGroupDrawingContext.cs
- DragSelectionMessageFilter.cs
- StyleSelector.cs
- WithParamAction.cs
- AppDomainShutdownMonitor.cs
- StrokeNodeData.cs
- NativeMethodsCLR.cs
- InputLanguageManager.cs
- AsynchronousChannelMergeEnumerator.cs
- AdapterDictionary.cs
- WriterOutput.cs
- PriorityRange.cs
- HtmlHead.cs
- MethodBody.cs
- odbcmetadatafactory.cs
- Assembly.cs
- ToolStripItemCollection.cs
- TextChangedEventArgs.cs
- TextLine.cs
- DataServices.cs
- FileRecordSequenceHelper.cs
- Rules.cs
- path.cs
- SchemaElementLookUpTableEnumerator.cs
- DataError.cs
- MetadataArtifactLoaderFile.cs
- MD5Cng.cs
- EntityDataReader.cs
- RestHandlerFactory.cs
- RegexCapture.cs
- ArgumentValidation.cs
- RadioButtonAutomationPeer.cs
- CuspData.cs
- EncodedStreamFactory.cs
- AdapterUtil.cs
- EncryptedReference.cs
- WhiteSpaceTrimStringConverter.cs
- SourceSwitch.cs
- Parallel.cs
- ExecutionEngineException.cs
- TextEditorLists.cs
- IResourceProvider.cs
- StorageEntityContainerMapping.cs
- LabelAutomationPeer.cs
- AppSecurityManager.cs
- GB18030Encoding.cs
- ZipPackagePart.cs
- DiscoveryClientDuplexChannel.cs
- XmlCodeExporter.cs
- PaperSize.cs
- xmlfixedPageInfo.cs
- SafePEFileHandle.cs
- DoubleConverter.cs
- ParallelTimeline.cs
- TextBox.cs
- WorkflowQueueInfo.cs
- DataGridAddNewRow.cs
- DatatypeImplementation.cs
- GroupItemAutomationPeer.cs
- Serializer.cs
- TemplatedMailWebEventProvider.cs
- Tokenizer.cs
- StringUtil.cs
- PatternMatcher.cs
- Debug.cs
- UITypeEditor.cs
- Crypto.cs
- SamlAuthenticationStatement.cs
- MultiTouchSystemGestureLogic.cs