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
- TreeSet.cs
- DataGridViewUtilities.cs
- InheritablePropertyChangeInfo.cs
- CheckBox.cs
- SourceInterpreter.cs
- EntityUtil.cs
- ValidationPropertyAttribute.cs
- Compress.cs
- DataGridTextBoxColumn.cs
- SqlParameter.cs
- HashCodeCombiner.cs
- WebExceptionStatus.cs
- ProfilePropertyMetadata.cs
- BitmapDownload.cs
- ExtendedPropertyDescriptor.cs
- DataControlImageButton.cs
- OleDbDataReader.cs
- RootBrowserWindowAutomationPeer.cs
- Span.cs
- DataViewListener.cs
- IERequestCache.cs
- TrustManagerMoreInformation.cs
- RegexCharClass.cs
- MetadataHelper.cs
- MissingManifestResourceException.cs
- CalendarData.cs
- RestrictedTransactionalPackage.cs
- ProjectionCamera.cs
- ISAPIApplicationHost.cs
- SafeEventLogReadHandle.cs
- HttpResponse.cs
- TextContainer.cs
- DictionaryBase.cs
- ObjectListDesigner.cs
- ForeignKeyConstraint.cs
- BitmapPalette.cs
- CompilerCollection.cs
- QuaternionConverter.cs
- ValidationError.cs
- RegexRunnerFactory.cs
- CheckBox.cs
- GridViewHeaderRowPresenter.cs
- TextRangeProviderWrapper.cs
- DataSourceControlBuilder.cs
- PrimitiveType.cs
- StylusPointPropertyId.cs
- WindowsTab.cs
- PageContent.cs
- TripleDESCryptoServiceProvider.cs
- BitmapCodecInfoInternal.cs
- DisableDpiAwarenessAttribute.cs
- SystemResourceHost.cs
- DataBoundControlAdapter.cs
- EditCommandColumn.cs
- ServiceDeploymentInfo.cs
- TablePatternIdentifiers.cs
- CompositeCollectionView.cs
- Accessors.cs
- ImpersonateTokenRef.cs
- WorkflowViewStateService.cs
- CodeStatementCollection.cs
- SQLMoneyStorage.cs
- QilScopedVisitor.cs
- CommentEmitter.cs
- DataGridViewRowStateChangedEventArgs.cs
- GeneralTransform2DTo3DTo2D.cs
- CriticalHandle.cs
- StorageEntityTypeMapping.cs
- RijndaelManagedTransform.cs
- httpserverutility.cs
- IndentedWriter.cs
- MiniLockedBorderGlyph.cs
- DataTemplateSelector.cs
- CacheOutputQuery.cs
- ThousandthOfEmRealDoubles.cs
- PageTheme.cs
- CapabilitiesSection.cs
- ReachDocumentReferenceSerializerAsync.cs
- ObjectDataSourceView.cs
- InputLanguageProfileNotifySink.cs
- BinHexEncoder.cs
- TableLayoutCellPaintEventArgs.cs
- PackUriHelper.cs
- CompiledRegexRunnerFactory.cs
- HandoffBehavior.cs
- SerializationEventsCache.cs
- MappingItemCollection.cs
- VScrollBar.cs
- ObjectStateManagerMetadata.cs
- XmlSchemaExternal.cs
- _IPv4Address.cs
- Token.cs
- DataGridViewSelectedRowCollection.cs
- Calendar.cs
- MsmqMessage.cs
- DrawingVisual.cs
- TdsParserStaticMethods.cs
- HttpClientChannel.cs
- ZipIOLocalFileDataDescriptor.cs
- MergeFilterQuery.cs