Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / XmlUtils / System / Xml / Xsl / QIL / QilValidationVisitor.cs / 1 / QilValidationVisitor.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
//-----------------------------------------------------------------------------
using System.Collections;
using System.Diagnostics;
namespace System.Xml.Xsl.Qil {
using Res = System.Xml.Utils.Res;
/// A internal class that validates QilExpression graphs.
///
/// QilValidationVisitor traverses the QilExpression graph once to enforce the following constraints:
///
/// - No circular references
/// - No duplicate nodes (except for references)
/// - No out-of-scope references
/// - Type constraints on operands
/// - Type constraints on operators
/// - No null objects (except where allowed)
/// - No Unknown node types
///
/// When an error occurs, it marks the offending node with an annotation and continues checking,
/// allowing the detection of multiple errors at once and printing the structure after validation.
/// (In the case of circular references, it breaks the loop at the circular reference to allow the graph
/// to print correctly.)
///
///
internal class QilValidationVisitor : QilScopedVisitor {
private SubstitutionList subs = new SubstitutionList();
private QilTypeChecker typeCheck = new QilTypeChecker();
//-----------------------------------------------
// Entry
//-----------------------------------------------
[Conditional("DEBUG")]
public static void Validate(QilNode node) {
Debug.Assert(node != null);
new QilValidationVisitor().VisitAssumeReference(node);
}
protected QilValidationVisitor() {}
#if DEBUG
protected Hashtable allNodes = new ObjectHashtable();
protected Hashtable parents = new ObjectHashtable();
protected Hashtable scope = new ObjectHashtable();
//-----------------------------------------------
// QilVisitor overrides
//-----------------------------------------------
protected override QilNode VisitChildren(QilNode parent) {
if (this.parents.Contains(parent)) {
// We have already visited the node that starts the infinite loop, but don't visit its children
SetError(parent, "Infinite loop");
}
else if (AddNode(parent)) {
if (parent.XmlType == null) {
SetError(parent, "Type information missing");
}
else {
XmlQueryType type = this.typeCheck.Check(parent);
//
if (!type.IsSubtypeOf(parent.XmlType))
SetError(parent, "Type information was not correctly inferred");
}
this.parents.Add(parent, parent);
for (int i = 0; i < parent.Count; i++) {
if (parent[i] == null) {
// Allow parameter name and default value to be null
if (parent.NodeType == QilNodeType.Parameter)
continue;
// Do not allow null anywhere else in the graph
else
SetError(parent, "Child " + i + " must not be null");
}
if (parent.NodeType == QilNodeType.GlobalVariableList ||
parent.NodeType == QilNodeType.GlobalParameterList ||
parent.NodeType == QilNodeType.FunctionList) {
if (((QilReference) parent[i]).DebugName == null)
SetError(parent[i], "DebugName must not be null");
}
// If child is a reference, then call VisitReference instead of Visit in order to avoid circular visits.
if (IsReference(parent, i))
VisitReference(parent[i]);
else
Visit(parent[i]);
}
this.parents.Remove(parent);
}
return parent;
}
///
/// Ensure that the function or iterator reference is already in scope.
///
protected override QilNode VisitReference(QilNode node) {
if (!this.scope.Contains(node))
SetError(node, "Out-of-scope reference");
return node;
}
//-----------------------------------------------
// QilScopedVisitor overrides
//-----------------------------------------------
///
/// Add an iterator or function to scope if it hasn't been added already.
///
protected override void BeginScope(QilNode node) {
if (this.scope.Contains(node))
SetError(node, "Reference already in scope");
else
this.scope.Add(node, node);
}
///
/// Pop scope.
///
protected override void EndScope(QilNode node) {
this.scope.Remove(node);
}
//-----------------------------------------------
// Helper methods
//-----------------------------------------------
private class ObjectHashtable : Hashtable {
protected override bool KeyEquals(object item, object key) {
return item == key;
}
}
private bool AddNode(QilNode n) {
if (!this.allNodes.Contains(n)) {
this.allNodes.Add(n, n);
return true;
}
else {
SetError(n, "Duplicate " + n.NodeType + " node");
return false;
}
}
#endif // DEBUG
[Conditional("DEBUG")]
internal static void SetError(QilNode n, string message) {
message = Res.GetString(Res.Qil_Validation, message);
#if QIL_TRACE_NODE_CREATION
message += " ["+ n.NodeId + " (" + n.NodeType.ToString("G") + ")]";
#endif
string s = n.Annotation as string;
if (s != null) {
message = s + "\n" + message;
}
n.Annotation = message;
Debug.Assert(false, message);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
//-----------------------------------------------------------------------------
using System.Collections;
using System.Diagnostics;
namespace System.Xml.Xsl.Qil {
using Res = System.Xml.Utils.Res;
/// A internal class that validates QilExpression graphs.
///
/// QilValidationVisitor traverses the QilExpression graph once to enforce the following constraints:
///
/// - No circular references
/// - No duplicate nodes (except for references)
/// - No out-of-scope references
/// - Type constraints on operands
/// - Type constraints on operators
/// - No null objects (except where allowed)
/// - No Unknown node types
///
/// When an error occurs, it marks the offending node with an annotation and continues checking,
/// allowing the detection of multiple errors at once and printing the structure after validation.
/// (In the case of circular references, it breaks the loop at the circular reference to allow the graph
/// to print correctly.)
///
///
internal class QilValidationVisitor : QilScopedVisitor {
private SubstitutionList subs = new SubstitutionList();
private QilTypeChecker typeCheck = new QilTypeChecker();
//-----------------------------------------------
// Entry
//-----------------------------------------------
[Conditional("DEBUG")]
public static void Validate(QilNode node) {
Debug.Assert(node != null);
new QilValidationVisitor().VisitAssumeReference(node);
}
protected QilValidationVisitor() {}
#if DEBUG
protected Hashtable allNodes = new ObjectHashtable();
protected Hashtable parents = new ObjectHashtable();
protected Hashtable scope = new ObjectHashtable();
//-----------------------------------------------
// QilVisitor overrides
//-----------------------------------------------
protected override QilNode VisitChildren(QilNode parent) {
if (this.parents.Contains(parent)) {
// We have already visited the node that starts the infinite loop, but don't visit its children
SetError(parent, "Infinite loop");
}
else if (AddNode(parent)) {
if (parent.XmlType == null) {
SetError(parent, "Type information missing");
}
else {
XmlQueryType type = this.typeCheck.Check(parent);
//
if (!type.IsSubtypeOf(parent.XmlType))
SetError(parent, "Type information was not correctly inferred");
}
this.parents.Add(parent, parent);
for (int i = 0; i < parent.Count; i++) {
if (parent[i] == null) {
// Allow parameter name and default value to be null
if (parent.NodeType == QilNodeType.Parameter)
continue;
// Do not allow null anywhere else in the graph
else
SetError(parent, "Child " + i + " must not be null");
}
if (parent.NodeType == QilNodeType.GlobalVariableList ||
parent.NodeType == QilNodeType.GlobalParameterList ||
parent.NodeType == QilNodeType.FunctionList) {
if (((QilReference) parent[i]).DebugName == null)
SetError(parent[i], "DebugName must not be null");
}
// If child is a reference, then call VisitReference instead of Visit in order to avoid circular visits.
if (IsReference(parent, i))
VisitReference(parent[i]);
else
Visit(parent[i]);
}
this.parents.Remove(parent);
}
return parent;
}
///
/// Ensure that the function or iterator reference is already in scope.
///
protected override QilNode VisitReference(QilNode node) {
if (!this.scope.Contains(node))
SetError(node, "Out-of-scope reference");
return node;
}
//-----------------------------------------------
// QilScopedVisitor overrides
//-----------------------------------------------
///
/// Add an iterator or function to scope if it hasn't been added already.
///
protected override void BeginScope(QilNode node) {
if (this.scope.Contains(node))
SetError(node, "Reference already in scope");
else
this.scope.Add(node, node);
}
///
/// Pop scope.
///
protected override void EndScope(QilNode node) {
this.scope.Remove(node);
}
//-----------------------------------------------
// Helper methods
//-----------------------------------------------
private class ObjectHashtable : Hashtable {
protected override bool KeyEquals(object item, object key) {
return item == key;
}
}
private bool AddNode(QilNode n) {
if (!this.allNodes.Contains(n)) {
this.allNodes.Add(n, n);
return true;
}
else {
SetError(n, "Duplicate " + n.NodeType + " node");
return false;
}
}
#endif // DEBUG
[Conditional("DEBUG")]
internal static void SetError(QilNode n, string message) {
message = Res.GetString(Res.Qil_Validation, message);
#if QIL_TRACE_NODE_CREATION
message += " ["+ n.NodeId + " (" + n.NodeType.ToString("G") + ")]";
#endif
string s = n.Annotation as string;
if (s != null) {
message = s + "\n" + message;
}
n.Annotation = message;
Debug.Assert(false, message);
}
}
}
// 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
- SqlConnectionPoolProviderInfo.cs
- XmlSchemaCollection.cs
- AlgoModule.cs
- LayoutDump.cs
- ProcessExitedException.cs
- DataGridItem.cs
- ButtonBaseAutomationPeer.cs
- cryptoapiTransform.cs
- SqlMethodCallConverter.cs
- CreationContext.cs
- RectAnimationClockResource.cs
- UInt64Converter.cs
- PlanCompiler.cs
- DispatcherExceptionEventArgs.cs
- UserMapPath.cs
- TargetInvocationException.cs
- ListViewItem.cs
- WindowsHyperlink.cs
- RotateTransform.cs
- OdbcParameterCollection.cs
- SqlRemoveConstantOrderBy.cs
- Instrumentation.cs
- CredentialCache.cs
- ReadOnlyHierarchicalDataSource.cs
- CngKeyBlobFormat.cs
- JoinElimination.cs
- TemplateXamlTreeBuilder.cs
- ToolStripItemBehavior.cs
- PersonalizationProviderHelper.cs
- Point3DCollection.cs
- HTMLTextWriter.cs
- IdleTimeoutMonitor.cs
- SerializationObjectManager.cs
- BinaryExpression.cs
- TiffBitmapDecoder.cs
- ModelTreeManager.cs
- GZipDecoder.cs
- PrintPreviewGraphics.cs
- SmiContextFactory.cs
- HttpPostedFile.cs
- SafeCoTaskMem.cs
- ListViewSortEventArgs.cs
- CompilerInfo.cs
- ComponentSerializationService.cs
- COM2ExtendedTypeConverter.cs
- PolyBezierSegment.cs
- XmlILModule.cs
- FloaterBaseParagraph.cs
- _HeaderInfoTable.cs
- IncrementalCompileAnalyzer.cs
- __Filters.cs
- XmlReaderSettings.cs
- EntityKey.cs
- BaseParagraph.cs
- __Filters.cs
- MetabaseServerConfig.cs
- SqlNodeTypeOperators.cs
- ViewDesigner.cs
- Stack.cs
- Label.cs
- AddInToken.cs
- ColorBlend.cs
- GenericIdentity.cs
- OleDbConnectionFactory.cs
- DataObjectEventArgs.cs
- GeometryGroup.cs
- ClientProxyGenerator.cs
- WebBrowserHelper.cs
- RuleSettings.cs
- BuildTopDownAttribute.cs
- DispatcherSynchronizationContext.cs
- XmlNavigatorStack.cs
- RowToFieldTransformer.cs
- FormsAuthenticationConfiguration.cs
- ChangesetResponse.cs
- SiteMapDataSourceView.cs
- ContainerUIElement3D.cs
- ConnectivityStatus.cs
- SByteConverter.cs
- Int32Collection.cs
- SspiSecurityToken.cs
- XamlStream.cs
- SrgsElement.cs
- WebBrowserSiteBase.cs
- SrgsElementFactoryCompiler.cs
- MessagePartDescriptionCollection.cs
- ShaderEffect.cs
- CompositeFontParser.cs
- ListBoxChrome.cs
- MemoryMappedViewStream.cs
- DefaultPropertyAttribute.cs
- BitmapFrame.cs
- SQLChars.cs
- DesignerSerializerAttribute.cs
- StatusBar.cs
- ConfigurationSection.cs
- NavigationProgressEventArgs.cs
- Point3DCollection.cs
- XmlExpressionDumper.cs
- ScriptRegistrationManager.cs