Welcome to mirror list, hosted at ThFree Co, Russian Federation.

QilFunction.cs « QIL « Xsl « Xml « System « System.Data.SqlXml « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c08b149dc3f10c13c11cab26172be63ee8a5033e (plain)
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
//------------------------------------------------------------------------------
// <copyright file="QilFunction.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace System.Xml.Xsl.Qil {

    /// <summary>
    /// An anonymous QilExpression function node.
    /// </summary>
    /// <remarks>
    /// <para>Function is a block, so it may introduce assignments (scoped to the function body).
    /// Additionally, it has an argument list, which will be assigned values
    /// when the function is invoked.</para>
    /// <para>The XmlType property defines the expected return type of this function.
    /// Normally, this should be the same as its definition's types, so setting the function
    /// definition changes the function's types.  In some rare cases, a compiler may wish to
    /// override the types after setting the function's definition (for example, an XQuery
    /// might define a function's return type to be wider than its definition would imply.)</para>
    /// </remarks>
    internal class QilFunction : QilReference {
        private QilNode arguments, definition, sideEffects;

        //-----------------------------------------------
        // Constructor
        //-----------------------------------------------

        /// <summary>
        /// Construct a node
        /// </summary>
        public QilFunction(QilNodeType nodeType, QilNode arguments, QilNode definition, QilNode sideEffects, XmlQueryType resultType)
            : base(nodeType) {
            this.arguments = arguments;
            this.definition = definition;
            this.sideEffects = sideEffects;
            this.xmlType = resultType;
        }


        //-----------------------------------------------
        // IList<QilNode> methods -- override
        //-----------------------------------------------

        public override int Count {
            get { return 3; }
        }

        public override QilNode this[int index] {
            get {
                switch (index) {
                    case 0: return this.arguments;
                    case 1: return this.definition;
                    case 2: return this.sideEffects;
                    default: throw new IndexOutOfRangeException();
                }
            }
            set {
                switch (index) {
                    case 0: this.arguments = value; break;
                    case 1: this.definition = value; break;
                    case 2: this.sideEffects = value; break;
                    default: throw new IndexOutOfRangeException();
                }
            }
        }


        //-----------------------------------------------
        // QilFunction methods
        //-----------------------------------------------

        /// <summary>
        /// Formal arguments of this function.
        /// </summary>
        public QilList Arguments {
            get { return (QilList) this.arguments; }
            set { this.arguments = value; }
        }

        /// <summary>
        /// Body of this function.
        /// </summary>
        public QilNode Definition {
            get { return this.definition; }
            set { this.definition = value; }
        }

        /// <summary>
        /// QilNodeType.True if this function might have side-effects.
        /// </summary>
        public bool MaybeSideEffects {
            get { return this.sideEffects.NodeType == QilNodeType.True; }
            set { this.sideEffects.NodeType = value ? QilNodeType.True : QilNodeType.False; }
        }
    }
}