IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
MultiArrayType.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2009-2015 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24namespace IKVM.Reflection
25{
26
28 {
29
30 readonly int rank;
31 readonly int[] sizes;
32 readonly int[] lobounds;
33
34 internal static Type Make(Type type, int rank, int[] sizes, int[] lobounds, CustomModifiers mods)
35 {
36 return type.Universe.CanonicalizeType(new MultiArrayType(type, rank, sizes, lobounds, mods));
37 }
38
47 MultiArrayType(Type type, int rank, int[] sizes, int[] lobounds, CustomModifiers mods) :
48 base(type, mods, Signature.ELEMENT_TYPE_ARRAY)
49 {
50 this.rank = rank;
51 this.sizes = sizes;
52 this.lobounds = lobounds;
53 }
54
55 public override Type BaseType
56 {
57 get { return elementType.Module.Universe.System_Array; }
58 }
59
60 public override MethodBase[] __GetDeclaredMethods()
61 {
62 var int32 = Module.Universe.System_Int32;
63 var setArgs = new Type[rank + 1];
64 var getArgs = new Type[rank];
65 var ctorArgs = new Type[rank * 2];
66 for (int i = 0; i < rank; i++)
67 {
68 setArgs[i] = int32;
69 getArgs[i] = int32;
70 ctorArgs[i * 2 + 0] = int32;
71 ctorArgs[i * 2 + 1] = int32;
72 }
73
74 setArgs[rank] = elementType;
75
76 return new MethodBase[]
77 {
78 new ConstructorInfoImpl(new BuiltinArrayMethod(Module, this, ".ctor", CallingConventions.Standard | CallingConventions.HasThis, Module.Universe.System_Void, getArgs)),
79 new ConstructorInfoImpl(new BuiltinArrayMethod(Module, this, ".ctor", CallingConventions.Standard | CallingConventions.HasThis, Module.Universe.System_Void, ctorArgs)),
80 new BuiltinArrayMethod(Module, this, "Set", CallingConventions.Standard | CallingConventions.HasThis, Module.Universe.System_Void, setArgs),
81 new BuiltinArrayMethod(Module, this, "Address", CallingConventions.Standard | CallingConventions.HasThis, elementType.MakeByRefType(), getArgs),
82 new BuiltinArrayMethod(Module, this, "Get", CallingConventions.Standard | CallingConventions.HasThis, elementType, getArgs),
83 };
84 }
85
86 public override TypeAttributes Attributes
87 {
88 get { return TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Serializable; }
89 }
90
91 public override int GetArrayRank()
92 {
93 return rank;
94 }
95
96 public override int[] __GetArraySizes()
97 {
98 return Util.Copy(sizes);
99 }
100
101 public override int[] __GetArrayLowerBounds()
102 {
103 return Util.Copy(lobounds);
104 }
105
106 public override bool Equals(object o)
107 {
108 var at = o as MultiArrayType;
109 return EqualsHelper(at)
110 && at.rank == rank
111 && ArrayEquals(at.sizes, sizes)
112 && ArrayEquals(at.lobounds, lobounds);
113 }
114
115 static bool ArrayEquals(int[] i1, int[] i2)
116 {
117 if (i1.Length == i2.Length)
118 {
119 for (int i = 0; i < i1.Length; i++)
120 if (i1[i] != i2[i])
121 return false;
122
123 return true;
124 }
125
126 return false;
127 }
128
129 public override int GetHashCode()
130 {
131 return elementType.GetHashCode() * 9 + rank;
132 }
133
134 internal override string GetSuffix()
135 {
136 if (rank == 1)
137 return "[*]";
138 else
139 return "[" + new string(',', rank - 1) + "]";
140 }
141
142 protected override Type Wrap(Type type, CustomModifiers mods)
143 {
144 return Make(type, rank, sizes, lobounds, mods);
145 }
146
147 }
148
149}
bool EqualsHelper(ElementHolderType other)
override MethodBase[] __GetDeclaredMethods()
override TypeAttributes Attributes
override bool Equals(object o)
override Type Wrap(Type type, CustomModifiers mods)
override int[] __GetArrayLowerBounds()