Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- GroupBoxAutomationPeer.cs
- Wizard.cs
- InvalidPrinterException.cs
- RuntimeHandles.cs
- ThreadStartException.cs
- ProfileSettings.cs
- ErrorActivity.cs
- ExtensionDataObject.cs
- SQLGuidStorage.cs
- Binding.cs
- SoapReflector.cs
- FunctionParameter.cs
- EntitySetRetriever.cs
- SqlFactory.cs
- DateTimeParse.cs
- BreakRecordTable.cs
- DataColumn.cs
- DateTimeOffsetConverter.cs
- UTF7Encoding.cs
- EventDescriptorCollection.cs
- Error.cs
- WebHeaderCollection.cs
- CanonicalXml.cs
- TypedTableGenerator.cs
- MeshGeometry3D.cs
- ProfileManager.cs
- WS2007FederationHttpBindingCollectionElement.cs
- SiteMapNodeItem.cs
- newinstructionaction.cs
- CodeGenerator.cs
- CallbackValidatorAttribute.cs
- SetterBase.cs
- XDeferredAxisSource.cs
- MethodToken.cs
- Matrix.cs
- TransportConfigurationTypeElementCollection.cs
- ConstructorNeedsTagAttribute.cs
- WebMethodAttribute.cs
- JavaScriptString.cs
- ArithmeticException.cs
- OdbcTransaction.cs
- BamlResourceSerializer.cs
- AssertFilter.cs
- SqlDataRecord.cs
- WebHostedComPlusServiceHost.cs
- OutOfMemoryException.cs
- WS2007HttpBindingCollectionElement.cs
- InitializerFacet.cs
- DesignerVerb.cs
- ActivationArguments.cs
- PagesSection.cs
- DayRenderEvent.cs
- PseudoWebRequest.cs
- SimpleFieldTemplateFactory.cs
- SynchronizedKeyedCollection.cs
- DataGridViewCell.cs
- DbConnectionHelper.cs
- CommandDevice.cs
- Canvas.cs
- InlinedAggregationOperatorEnumerator.cs
- WebHeaderCollection.cs
- Utils.cs
- DrawItemEvent.cs
- SelfIssuedAuthRSAPKCS1SignatureFormatter.cs
- ItemCheckedEvent.cs
- RequestQueryProcessor.cs
- TypeContext.cs
- NameNode.cs
- TraceContextRecord.cs
- XmlNodeComparer.cs
- TCEAdapterGenerator.cs
- GridViewCommandEventArgs.cs
- QilIterator.cs
- TraceLevelStore.cs
- AssociatedControlConverter.cs
- XmlHelper.cs
- SingleAnimation.cs
- DataSourceView.cs
- SystemException.cs
- Line.cs
- CreateParams.cs
- SQLMembershipProvider.cs
- columnmapfactory.cs
- RenderContext.cs
- HttpRequestCacheValidator.cs
- DbConnectionHelper.cs
- Rfc2898DeriveBytes.cs
- ByteConverter.cs
- CancelRequestedQuery.cs
- HandoffBehavior.cs
- Transactions.cs
- hwndwrapper.cs
- EditorZone.cs
- COM2IDispatchConverter.cs
- CollectionExtensions.cs
- DelegatingStream.cs
- RuntimeCompatibilityAttribute.cs
- SplineKeyFrames.cs
- ExceptionHandler.cs
- ContentHostHelper.cs