1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
//------------------------------------------------------------------------------
// <copyright file="XmlILAnnotation.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
using System.Xml.Xsl.Qil;
namespace System.Xml.Xsl.IlGen {
/// <summary>
/// Several annotations are created and attached to Qil nodes during the optimization and code generation phase.
/// </summary>
internal class XmlILAnnotation : ListBase<object> {
private object annPrev;
private MethodInfo funcMethod;
private int argPos;
private IteratorDescriptor iterInfo;
private XmlILConstructInfo constrInfo;
private OptimizerPatterns optPatt;
//-----------------------------------------------
// Constructor
//-----------------------------------------------
/// <summary>
/// Create and initialize XmlILAnnotation for the specified node.
/// </summary>
public static XmlILAnnotation Write(QilNode nd) {
XmlILAnnotation ann = nd.Annotation as XmlILAnnotation;
if (ann == null) {
ann = new XmlILAnnotation(nd.Annotation);
nd.Annotation = ann;
}
return ann;
}
private XmlILAnnotation(object annPrev) {
this.annPrev = annPrev;
}
//-----------------------------------------------
// Annotations
//-----------------------------------------------
/// <summary>
/// User-defined functions and global variables and parameters are bound to Clr MethodInfo objects.
/// Attached to Function, global Let, and global Parameter nodes.
/// </summary>
public MethodInfo FunctionBinding {
get { return this.funcMethod; }
set { this.funcMethod = value; }
}
/// <summary>
/// Function arguments are tracked by position.
/// Attached to function Parameter nodes.
/// </summary>
public int ArgumentPosition {
get { return this.argPos; }
set { this.argPos = value; }
}
/// <summary>
/// The IteratorDescriptor that is derived for Qil For and Let nodes is cached so that it can be used when the
/// For/Let node is referenced.
/// Attached to For and Let nodes.
/// </summary>
public IteratorDescriptor CachedIteratorDescriptor {
get { return this.iterInfo; }
set { this.iterInfo = value; }
}
/// <summary>
/// Contains information about how this expression will be constructed by ILGen.
/// Attached to any kind of Qil node.
/// </summary>
public XmlILConstructInfo ConstructInfo {
get { return this.constrInfo; }
set { this.constrInfo = value; }
}
/// <summary>
/// Contains patterns that the subtree rooted at this node matches.
/// Attached to any kind of Qil node.
/// </summary>
public OptimizerPatterns Patterns {
get { return this.optPatt; }
set { this.optPatt = value; }
}
//-----------------------------------------------
// ListBase implementation
//-----------------------------------------------
/// <summary>
/// Return the count of sub-annotations maintained by this annotation.
/// </summary>
public override int Count {
get { return (this.annPrev != null) ? 3 : 2; }
}
/// <summary>
/// Return the annotation at the specified index.
/// </summary>
public override object this[int index] {
get {
if (this.annPrev != null) {
if (index == 0)
return this.annPrev;
index--;
}
switch (index) {
case 0: return this.constrInfo;
case 1: return this.optPatt;
}
throw new IndexOutOfRangeException();
}
set {
throw new NotSupportedException();
}
}
}
}
|