2 // Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org)
3 // All rights reserved.
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of Rodrigo B. de Oliveira nor the names of its
14 // contributors may be used to endorse or promote products derived from this
15 // software without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 namespace Boo
.Lang
.Compiler
.TypeSystem
31 public class ArrayType
: IArrayType
41 public ArrayType(TypeSystemServices tagManager
, IType elementType
) : this(tagManager
, elementType
, 1)
45 public ArrayType(TypeSystemServices tagManager
, IType elementType
, int rank
)
47 _array
= tagManager
.ArrayType
;
48 _elementType
= elementType
;
50 _enumerable
= tagManager
.IEnumerableGenericType
;
60 return "(" + _elementType
.ToString() + ", " + _rank
+ ")";
62 return "(" + _elementType
.ToString() + ")";
66 public EntityType EntityType
70 return EntityType
.Array
;
74 public string FullName
114 public bool IsInterface
122 public bool IsAbstract
138 public bool IsValueType
154 public int GetTypeDepth()
159 public int GetArrayRank()
164 public IType
GetElementType()
169 public IType BaseType
177 public IEntity
GetDefaultMember()
182 public virtual bool IsSubclassOf(IType other
)
184 if (other
.IsAssignableFrom(_array
)) return true;
186 // Arrays also implement generic IEnumerable of their element type
187 if (other
.ConstructedInfo
!= null &&
188 other
.ConstructedInfo
.GenericDefinition
== _enumerable
&&
189 other
.ConstructedInfo
.GenericArguments
[0].IsAssignableFrom(_elementType
))
196 public virtual bool IsAssignableFrom(IType other
)
198 if (other
== this || other
== Null
.Default
)
205 IArrayType otherArray
= (IArrayType
)other
;
207 if (otherArray
.GetArrayRank() != _rank
)
212 IType otherEntityType
= otherArray
.GetElementType();
213 if (_elementType
.IsValueType
|| otherEntityType
.IsValueType
)
215 return _elementType
== otherEntityType
;
217 return _elementType
.IsAssignableFrom(otherEntityType
);
223 public IConstructor
[] GetConstructors()
225 return new IConstructor
[0];
228 public IType
[] GetInterfaces()
233 public IEntity
[] GetMembers()
235 return _array
.GetMembers();
238 public INamespace ParentNamespace
242 return _array
.ParentNamespace
;
246 public bool Resolve(List targetList
, string name
, EntityType flags
)
248 return _array
.Resolve(targetList
, name
, flags
);
251 override public string ToString()
256 IGenericTypeInfo IType
.GenericInfo
261 IConstructedTypeInfo IType
.ConstructedInfo