Code:
/ 4.0 / 4.0 / 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. //---------------------------------------------------------------------- // // 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
- OracleTransaction.cs
- XsltCompileContext.cs
- DataSourceXmlSubItemAttribute.cs
- XslCompiledTransform.cs
- RangeBase.cs
- ErrorFormatterPage.cs
- BamlResourceContent.cs
- Ref.cs
- WS2007HttpBindingCollectionElement.cs
- StaticExtension.cs
- TickBar.cs
- PropertyEmitter.cs
- JavascriptXmlWriterWrapper.cs
- UniqueSet.cs
- ConsoleCancelEventArgs.cs
- ObfuscationAttribute.cs
- Int32Storage.cs
- AxisAngleRotation3D.cs
- IgnoreFileBuildProvider.cs
- Rules.cs
- MessageRpc.cs
- RegisteredExpandoAttribute.cs
- ImmutableCollection.cs
- XpsResource.cs
- VersionedStreamOwner.cs
- NavigationWindow.cs
- ListSourceHelper.cs
- FastEncoderWindow.cs
- JoinGraph.cs
- Variant.cs
- TouchesCapturedWithinProperty.cs
- RoleManagerEventArgs.cs
- MessageContractAttribute.cs
- DbConnectionStringCommon.cs
- XmlSchemaParticle.cs
- FigureParagraph.cs
- FreezableOperations.cs
- IncomingWebResponseContext.cs
- DoubleAnimation.cs
- SystemIPAddressInformation.cs
- UIElementCollection.cs
- WebInvokeAttribute.cs
- ModifiableIteratorCollection.cs
- PointAnimationUsingKeyFrames.cs
- DbDataSourceEnumerator.cs
- TextTrailingCharacterEllipsis.cs
- Literal.cs
- HtmlTextViewAdapter.cs
- MemberCollection.cs
- DiagnosticTrace.cs
- MsmqHostedTransportConfiguration.cs
- Vector3DConverter.cs
- WindowsNonControl.cs
- EmbeddedMailObjectsCollection.cs
- ExtractedStateEntry.cs
- Blend.cs
- QilIterator.cs
- FlowDocumentPage.cs
- DataObjectCopyingEventArgs.cs
- ReferenceAssemblyAttribute.cs
- MessagePropertyFilter.cs
- JoinElimination.cs
- TemplateBindingExtensionConverter.cs
- InternalConfigSettingsFactory.cs
- ScriptDescriptor.cs
- SqlPersonalizationProvider.cs
- HttpHandlerAction.cs
- HiddenField.cs
- XsdValidatingReader.cs
- HtmlInputFile.cs
- HttpRequest.cs
- ProviderSettings.cs
- XmlSchemaIdentityConstraint.cs
- ZoneLinkButton.cs
- IBuiltInEvidence.cs
- SchemaHelper.cs
- CommentEmitter.cs
- PluralizationServiceUtil.cs
- FixedDocumentSequencePaginator.cs
- XamlPoint3DCollectionSerializer.cs
- ImageBrush.cs
- ActivityTrace.cs
- TemplateNodeContextMenu.cs
- SqlDataSourceParameterParser.cs
- _ProxyRegBlob.cs
- AttributeCollection.cs
- OverflowException.cs
- MultiView.cs
- LicenseManager.cs
- SessionState.cs
- ByteFacetDescriptionElement.cs
- SQLDecimalStorage.cs
- ArcSegment.cs
- ObjectListField.cs
- ModuleConfigurationInfo.cs
- ReverseInheritProperty.cs
- CqlGenerator.cs
- DeflateStream.cs
- TimeSpanValidatorAttribute.cs
- AesCryptoServiceProvider.cs