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
- CachedPathData.cs
- XmlLoader.cs
- BlockingCollection.cs
- XmlEncApr2001.cs
- FrameworkElementFactory.cs
- InfoCardSchemas.cs
- BuildProviderCollection.cs
- BaseProcessor.cs
- WindowsToolbarAsMenu.cs
- TransactionManager.cs
- InheritanceAttribute.cs
- ParserContext.cs
- ServerValidateEventArgs.cs
- ToolStripTextBox.cs
- XNameConverter.cs
- DataBoundLiteralControl.cs
- UnsafeNativeMethods.cs
- LayoutInformation.cs
- TouchesCapturedWithinProperty.cs
- DateTimeFormatInfoScanner.cs
- GroupPartitionExpr.cs
- CompilationSection.cs
- EntityContainerEmitter.cs
- DesignerCapabilities.cs
- CornerRadius.cs
- PropertyGridDesigner.cs
- RepeatButtonAutomationPeer.cs
- PageVisual.cs
- XPathMultyIterator.cs
- PreviewKeyDownEventArgs.cs
- HMACSHA512.cs
- ClickablePoint.cs
- DataServiceRequestOfT.cs
- ToolBarTray.cs
- WebPartConnectionsEventArgs.cs
- Cursor.cs
- EntityConnectionStringBuilder.cs
- DependencyObjectCodeDomSerializer.cs
- UriTemplateDispatchFormatter.cs
- Viewport3DVisual.cs
- ScriptResourceHandler.cs
- StringComparer.cs
- TextEditorSpelling.cs
- _BasicClient.cs
- GridViewSortEventArgs.cs
- XmlSchemas.cs
- MenuCommand.cs
- CorrelationRequestContext.cs
- DataDocumentXPathNavigator.cs
- Error.cs
- _ScatterGatherBuffers.cs
- FileChangeNotifier.cs
- RequestDescription.cs
- CompiledXpathExpr.cs
- ZipIOBlockManager.cs
- Part.cs
- ModelPropertyImpl.cs
- FrameworkTextComposition.cs
- AdornerPresentationContext.cs
- MultipartIdentifier.cs
- AdRotator.cs
- OracleTransaction.cs
- ZipArchive.cs
- PropertyChangedEventManager.cs
- LinqDataView.cs
- BufferedStream.cs
- SamlAuthenticationClaimResource.cs
- FontFamily.cs
- XmlCharacterData.cs
- Metafile.cs
- OdbcConnectionPoolProviderInfo.cs
- XmlSchemaSimpleContentRestriction.cs
- WizardPanelChangingEventArgs.cs
- Relationship.cs
- indexingfiltermarshaler.cs
- NetTcpBinding.cs
- TextBox.cs
- InvokeMethodActivityDesigner.cs
- ConditionCollection.cs
- ContainerVisual.cs
- RegexInterpreter.cs
- SqlUtils.cs
- ComponentCodeDomSerializer.cs
- ScrollBarRenderer.cs
- IssuanceLicense.cs
- ServiceObjectContainer.cs
- PersonalizableTypeEntry.cs
- SafeRegistryKey.cs
- ReferenceList.cs
- WizardPanelChangingEventArgs.cs
- FactoryGenerator.cs
- ScrollItemPatternIdentifiers.cs
- ConstraintManager.cs
- BindingNavigator.cs
- PropertyToken.cs
- PointLight.cs
- XmlLanguage.cs
- PointAnimationBase.cs
- datacache.cs
- OleDbDataAdapter.cs