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

RuntimeDeterminedType.cs « RuntimeDetermined « TypeSystem « src « Common « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 48abf82860a3c3f3c1b216909ea94422fb1f32eb (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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;

using Debug = System.Diagnostics.Debug;

namespace Internal.TypeSystem
{
    /// <summary>
    /// Represents a runtime determined type. Runtime determined types are used to represent types
    /// within shared generic method bodies and generic dictionaries. The concrete type will only
    /// be known at runtime (when executing a shared generic method body under a specific generic context).
    /// </summary>
    /// <remarks>
    /// The use of runtime determined types is limited to the dependency analysis and to communicating
    /// with the codegen backend during shared generic code generation. They should not show up within
    /// the system otherwise.
    /// 
    /// Runtime determined types behave mostly like the canonical type they are wrapping. Most of the overrides
    /// this type implements will forward the implementation to the <see cref="_rawCanonType"/>'s
    /// implementation.
    /// 
    /// Runtime determined types also behave like signature variables in the sense that they allow being
    /// substituted during signature instantiation.
    /// </remarks>
    public sealed partial class RuntimeDeterminedType : DefType
    {
        private DefType _rawCanonType;
        private GenericParameterDesc _runtimeDeterminedDetailsType;

        public RuntimeDeterminedType(DefType rawCanonType, GenericParameterDesc runtimeDeterminedDetailsType)
        {
            _rawCanonType = rawCanonType;
            _runtimeDeterminedDetailsType = runtimeDeterminedDetailsType;
        }

        /// <summary>
        /// Gets the generic parameter this runtime determined type represents.
        /// </summary>
        public GenericParameterDesc RuntimeDeterminedDetailsType
        {
            get
            {
                return _runtimeDeterminedDetailsType;
            }
        }

        /// <summary>
        /// Gets the canonical type wrapped by this runtime determined type.
        /// </summary>
        public DefType CanonicalType
        {
            get
            {
                return _rawCanonType;
            }
        }

        public override TypeSystemContext Context
        {
            get
            {
                return _rawCanonType.Context;
            }
        }

        public override bool IsRuntimeDeterminedSubtype
        {
            get
            {
                return true;
            }
        }

        public override DefType BaseType
        {
            get
            {
                return _rawCanonType.BaseType;
            }
        }

        public override Instantiation Instantiation
        {
            get
            {
                return _rawCanonType.Instantiation;
            }
        }

        public override string Name
        {
            get
            {
                return _rawCanonType.Name;
            }
        }

        public override string Namespace
        {
            get
            {
                return String.Concat(_runtimeDeterminedDetailsType.Name, "_", _rawCanonType.Namespace);
            }
        }

        public override IEnumerable<MethodDesc> GetMethods()
        {
            foreach (var method in _rawCanonType.GetMethods())
            {
                yield return Context.GetMethodForRuntimeDeterminedType(method.GetTypicalMethodDefinition(), this);
            }
        }

        public override MethodDesc GetMethod(string name, MethodSignature signature)
        {
            MethodDesc method = _rawCanonType.GetMethod(name, signature);
            if (method == null)
                return null;
            return Context.GetMethodForRuntimeDeterminedType(method.GetTypicalMethodDefinition(), this);
        }

        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = 0;

            if ((mask & TypeFlags.CategoryMask) != 0)
            {
                flags |= _rawCanonType.GetTypeFlags(mask);
            }

            if ((mask & TypeFlags.HasGenericVarianceComputed) != 0)
            {
                flags |= _rawCanonType.GetTypeFlags(mask);
            }

            if ((mask & TypeFlags.AttributeCacheComputed) != 0)
            {
                flags |= _rawCanonType.GetTypeFlags(mask);
            }

            // Might need to define the behavior if we ever hit this.
            Debug.Assert((flags & mask) != 0);
            return flags;
        }

        public override TypeDesc GetTypeDefinition()
        {
            // TODO: this is needed because NameMangler calls it to see if we're dealing with genericness. Revise?
            if (_rawCanonType.HasInstantiation)
            {
                return Context.GetRuntimeDeterminedType((DefType)_rawCanonType.GetTypeDefinition(), _runtimeDeterminedDetailsType);
            }

            return this;
        }

        public override int GetHashCode()
        {
            return _rawCanonType.GetHashCode();
        }

        protected override TypeDesc ConvertToCanonFormImpl(CanonicalFormKind kind)
        {
            return _rawCanonType.ConvertToCanonForm(kind);
        }

        public override bool IsCanonicalSubtype(CanonicalFormKind policy)
        {
            return false;
        }

        public override TypeDesc GetNonRuntimeDeterminedTypeFromRuntimeDeterminedSubtypeViaSubstitution(Instantiation typeInstantiation, Instantiation methodInstantiation)
        {
            if (_runtimeDeterminedDetailsType.Kind == GenericParameterKind.Type)
            {
                return typeInstantiation[_runtimeDeterminedDetailsType.Index];
            }
            else
            {
                Debug.Assert(_runtimeDeterminedDetailsType.Kind == GenericParameterKind.Method);
                return methodInstantiation[_runtimeDeterminedDetailsType.Index];
            }
        }
    }
}