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
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Image.cs
- ParentUndoUnit.cs
- ReliableInputConnection.cs
- Style.cs
- HttpCookie.cs
- CursorConverter.cs
- FileDataSourceCache.cs
- CompilationLock.cs
- SharedPerformanceCounter.cs
- NullableDecimalSumAggregationOperator.cs
- RelatedView.cs
- TemplateColumn.cs
- coordinator.cs
- Debug.cs
- StrokeRenderer.cs
- Zone.cs
- ThicknessConverter.cs
- FloaterBaseParagraph.cs
- TrackingLocationCollection.cs
- StaticDataManager.cs
- InputManager.cs
- ChannelServices.cs
- TextDecorationCollection.cs
- RowToFieldTransformer.cs
- ChtmlTextBoxAdapter.cs
- CodeEntryPointMethod.cs
- mediaclock.cs
- Part.cs
- AddValidationError.cs
- Message.cs
- BitmapEffectGeneralTransform.cs
- Image.cs
- MetadataPropertyCollection.cs
- PrintDialogException.cs
- MachineKey.cs
- Codec.cs
- XmlSerializationReader.cs
- Range.cs
- RegexBoyerMoore.cs
- HttpApplicationFactory.cs
- RectangleHotSpot.cs
- WorkflowQueue.cs
- SynchronousChannelMergeEnumerator.cs
- TemplatePropertyEntry.cs
- LinkLabel.cs
- XPathException.cs
- EtwProvider.cs
- Misc.cs
- SpeechAudioFormatInfo.cs
- ExceptQueryOperator.cs
- CngProvider.cs
- Evaluator.cs
- TextChangedEventArgs.cs
- TrustLevelCollection.cs
- WebSysDisplayNameAttribute.cs
- WebPartConnectionCollection.cs
- DependentTransaction.cs
- UpdateProgress.cs
- OdbcDataAdapter.cs
- UIElementParaClient.cs
- RemotingException.cs
- Pool.cs
- EventLogEntry.cs
- FixedBufferAttribute.cs
- XPathSelectionIterator.cs
- WeakKeyDictionary.cs
- SystemIcons.cs
- FontStyleConverter.cs
- LabelEditEvent.cs
- LinqTreeNodeEvaluator.cs
- ToolStripScrollButton.cs
- ZipIOModeEnforcingStream.cs
- OlePropertyStructs.cs
- LicFileLicenseProvider.cs
- ContextActivityUtils.cs
- StringInfo.cs
- SharedDp.cs
- HtmlButton.cs
- CodeTypeDelegate.cs
- ResourceReferenceExpression.cs
- ServiceHandle.cs
- MonthChangedEventArgs.cs
- SqlTriggerAttribute.cs
- CodeTypeDeclarationCollection.cs
- ClientRoleProvider.cs
- DetailsViewPageEventArgs.cs
- MetadataSource.cs
- XmlSignatureProperties.cs
- BaseValidator.cs
- Vector3DAnimationUsingKeyFrames.cs
- Point.cs
- CommandHelpers.cs
- ParserOptions.cs
- RuleDefinitions.cs
- TextOutput.cs
- DataGridViewColumnConverter.cs
- HttpMethodAttribute.cs
- NullReferenceException.cs
- BinaryMessageEncodingBindingElement.cs
- OleDbDataReader.cs