Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Common / Utils / Boolean / NegationPusher.cs / 1305376 / 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.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GenericRootAutomationPeer.cs
- HybridDictionary.cs
- KeyFrames.cs
- DataGrid.cs
- _BaseOverlappedAsyncResult.cs
- EntityContainerRelationshipSetEnd.cs
- BuildProvider.cs
- BmpBitmapEncoder.cs
- PagedDataSource.cs
- _ContextAwareResult.cs
- CodeDOMProvider.cs
- WrapPanel.cs
- WebServiceParameterData.cs
- RegisteredExpandoAttribute.cs
- DocumentViewerConstants.cs
- RootBrowserWindow.cs
- StylusCollection.cs
- RsaSecurityToken.cs
- TextWriterTraceListener.cs
- IApplicationTrustManager.cs
- APCustomTypeDescriptor.cs
- TreeNodeStyle.cs
- XmlSchemaAnnotated.cs
- InstanceData.cs
- smtppermission.cs
- ConfigXmlWhitespace.cs
- NullableDecimalAverageAggregationOperator.cs
- CodeDirectiveCollection.cs
- AnnotationResource.cs
- WebHttpDispatchOperationSelector.cs
- PropertyEmitter.cs
- ToolZone.cs
- CornerRadius.cs
- UserControlAutomationPeer.cs
- RadialGradientBrush.cs
- GeneralTransform3DGroup.cs
- ExpressionEditorAttribute.cs
- WindowsFormsSectionHandler.cs
- Int64AnimationBase.cs
- CapabilitiesSection.cs
- GlyphCache.cs
- ProxyElement.cs
- CdpEqualityComparer.cs
- FixedPage.cs
- TextSelectionHelper.cs
- ConfigurationSchemaErrors.cs
- FunctionDetailsReader.cs
- ResourceProperty.cs
- ContentTextAutomationPeer.cs
- AsyncResult.cs
- TableSectionStyle.cs
- SMSvcHost.cs
- ExceptionHelpers.cs
- CustomErrorsSection.cs
- CodeIterationStatement.cs
- bidPrivateBase.cs
- SqlUdtInfo.cs
- DbConnectionPoolGroup.cs
- UIElementHelper.cs
- HttpHandlerActionCollection.cs
- SecurityIdentifierElementCollection.cs
- InkCanvasInnerCanvas.cs
- DataBoundLiteralControl.cs
- CollectionViewGroupInternal.cs
- HtmlInputImage.cs
- XmlAnyElementAttributes.cs
- HttpPostedFile.cs
- ListViewGroupItemCollection.cs
- InOutArgument.cs
- ToolStripItemImageRenderEventArgs.cs
- AppLevelCompilationSectionCache.cs
- ListBindingHelper.cs
- XmlIterators.cs
- AutomationAttributeInfo.cs
- odbcmetadatafactory.cs
- BaseProcessor.cs
- ConfigurationLocation.cs
- FixedBufferAttribute.cs
- CodeMethodMap.cs
- TypeNameHelper.cs
- MapPathBasedVirtualPathProvider.cs
- Baml2006Reader.cs
- UrlPropertyAttribute.cs
- ListView.cs
- StringResourceManager.cs
- UTF7Encoding.cs
- CaseInsensitiveOrdinalStringComparer.cs
- InvalidProgramException.cs
- HtmlWindow.cs
- TextProviderWrapper.cs
- TargetException.cs
- PerfCounterSection.cs
- ProxyFragment.cs
- JapaneseLunisolarCalendar.cs
- GroupQuery.cs
- DataGridCommandEventArgs.cs
- ComponentEditorPage.cs
- Switch.cs
- BasicCommandTreeVisitor.cs
- HTMLTagNameToTypeMapper.cs