Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Common / Utils / Boolean / NegationPusher.cs / 2 / 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
- PenThreadPool.cs
- UriTemplate.cs
- OletxTransactionManager.cs
- SchemaTypeEmitter.cs
- PeerApplicationLaunchInfo.cs
- SqlMethodAttribute.cs
- OperatingSystem.cs
- Identifier.cs
- ListItem.cs
- TreeViewEvent.cs
- DataListCommandEventArgs.cs
- DBBindings.cs
- ConfigXmlDocument.cs
- LoadedOrUnloadedOperation.cs
- InvokeMethodActivityDesigner.cs
- Timer.cs
- WebConfigurationManager.cs
- TraceListener.cs
- Attributes.cs
- Point4DValueSerializer.cs
- OdbcInfoMessageEvent.cs
- DoubleLink.cs
- LineBreakRecord.cs
- ObjectDataSource.cs
- FilterFactory.cs
- Recipient.cs
- SelectionListDesigner.cs
- KnownAssemblyEntry.cs
- PasswordTextContainer.cs
- SafeNativeMethods.cs
- XsltOutput.cs
- BindingsCollection.cs
- DataGridViewTextBoxEditingControl.cs
- DataServiceEntityAttribute.cs
- LZCodec.cs
- SecurityKeyIdentifier.cs
- JobDuplex.cs
- DataMember.cs
- Stack.cs
- FormViewDeletedEventArgs.cs
- EFAssociationProvider.cs
- XmlSchemaAttributeGroupRef.cs
- Validator.cs
- TableRowCollection.cs
- SkinBuilder.cs
- CrossSiteScriptingValidation.cs
- ConfigXmlSignificantWhitespace.cs
- HtmlElementEventArgs.cs
- MediaElement.cs
- XmlSerializerAssemblyAttribute.cs
- XmlDigitalSignatureProcessor.cs
- SqlEnums.cs
- XmlWriterTraceListener.cs
- RowBinding.cs
- QueuedDeliveryRequirementsMode.cs
- ObjectStateManagerMetadata.cs
- Nodes.cs
- PrinterResolution.cs
- LineBreak.cs
- _emptywebproxy.cs
- SingleTagSectionHandler.cs
- EventBindingService.cs
- XmlSchemaRedefine.cs
- EmptyCollection.cs
- SessionIDManager.cs
- CrossSiteScriptingValidation.cs
- XmlExtensionFunction.cs
- EncoderReplacementFallback.cs
- TextRunTypographyProperties.cs
- WebPartCloseVerb.cs
- UnsafeNativeMethodsCLR.cs
- SizeFConverter.cs
- CategoryNameCollection.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- PointF.cs
- ConvertEvent.cs
- Compensate.cs
- DataGridCellClipboardEventArgs.cs
- WmpBitmapDecoder.cs
- DataBinding.cs
- BinaryKeyIdentifierClause.cs
- KeyMatchBuilder.cs
- TemplateNodeContextMenu.cs
- DelegateBodyWriter.cs
- RTLAwareMessageBox.cs
- DataKeyPropertyAttribute.cs
- Dispatcher.cs
- DataRecord.cs
- ReflectEventDescriptor.cs
- AnimationClockResource.cs
- SQLByte.cs
- UTF32Encoding.cs
- unsafeIndexingFilterStream.cs
- SQLDecimalStorage.cs
- _BufferOffsetSize.cs
- ToolStripPanelRow.cs
- DrawListViewItemEventArgs.cs
- WebProxyScriptElement.cs
- CompiledIdentityConstraint.cs
- DataGridColumnHeadersPresenterAutomationPeer.cs