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
- WebPartMenu.cs
- DES.cs
- BitmapEffectState.cs
- XhtmlBasicLiteralTextAdapter.cs
- DiscoveryClientDocuments.cs
- TextEndOfParagraph.cs
- dbenumerator.cs
- PreviewPageInfo.cs
- Form.cs
- TdsRecordBufferSetter.cs
- NominalTypeEliminator.cs
- ToolStripContentPanel.cs
- PointConverter.cs
- SHA512Cng.cs
- CLRBindingWorker.cs
- CompilationUtil.cs
- DbDataRecord.cs
- ToolStripPanelRenderEventArgs.cs
- NumericUpDownAccelerationCollection.cs
- TemplateBamlRecordReader.cs
- ControlBuilder.cs
- Win32PrintDialog.cs
- Lock.cs
- ObjectItemCollection.cs
- DataQuery.cs
- ToolStripHighContrastRenderer.cs
- XmlTypeAttribute.cs
- WebPartZoneBaseDesigner.cs
- ColorContextHelper.cs
- UInt64Storage.cs
- PointValueSerializer.cs
- MaskedTextBox.cs
- Math.cs
- DataRecordObjectView.cs
- BamlReader.cs
- SourceSwitch.cs
- CreateSequenceResponse.cs
- EndPoint.cs
- SymbolDocumentInfo.cs
- SimpleFieldTemplateFactory.cs
- XamlClipboardData.cs
- ClrPerspective.cs
- OwnerDrawPropertyBag.cs
- BaseParagraph.cs
- XmlNodeReader.cs
- SoapReflectionImporter.cs
- DescriptionAttribute.cs
- GenericTextProperties.cs
- Single.cs
- SqlDataSourceCache.cs
- PlatformCulture.cs
- HtmlHistory.cs
- ScrollPatternIdentifiers.cs
- XmlSchemaDocumentation.cs
- XPathNodePointer.cs
- ObjectDataSourceFilteringEventArgs.cs
- OleDbStruct.cs
- Size3D.cs
- LoginCancelEventArgs.cs
- httpserverutility.cs
- AudioSignalProblemOccurredEventArgs.cs
- ArrayWithOffset.cs
- XamlTreeBuilder.cs
- FileStream.cs
- QualificationDataItem.cs
- JsonDeserializer.cs
- SqlDataSourceEnumerator.cs
- MsmqTransportBindingElement.cs
- CompiledQuery.cs
- HostingMessageProperty.cs
- AppDomainFactory.cs
- Point3D.cs
- GlyphsSerializer.cs
- Itemizer.cs
- PerfCounterSection.cs
- QuadraticEase.cs
- ElementNotEnabledException.cs
- WindowsStatic.cs
- StyleModeStack.cs
- FileLevelControlBuilderAttribute.cs
- AnnotationComponentManager.cs
- SmiXetterAccessMap.cs
- DataGridViewControlCollection.cs
- TableCellCollection.cs
- OptimizedTemplateContentHelper.cs
- MachineKeySection.cs
- ColumnProvider.cs
- EmbossBitmapEffect.cs
- _CommandStream.cs
- Pool.cs
- AVElementHelper.cs
- GorillaCodec.cs
- ItemCollectionEditor.cs
- ConnectionPointConverter.cs
- DSASignatureDeformatter.cs
- DecoderExceptionFallback.cs
- StatusBar.cs
- EdmItemError.cs
- MaskDescriptor.cs
- TCEAdapterGenerator.cs