5
// Jb Evain (jbevain@gmail.com)
7
// Copyright (c) 2008 - 2010 Jb Evain
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
using Mono.Collections.Generic;
32
using MD = Mono.Cecil.Metadata;
34
namespace Mono.Cecil {
36
public struct ArrayDimension {
41
public int? LowerBound {
42
get { return lower_bound; }
43
set { lower_bound = value; }
46
public int? UpperBound {
47
get { return upper_bound; }
48
set { upper_bound = value; }
52
get { return lower_bound.HasValue || upper_bound.HasValue; }
55
public ArrayDimension (int? lowerBound, int? upperBound)
57
this.lower_bound = lowerBound;
58
this.upper_bound = upperBound;
61
public override string ToString ()
65
: lower_bound + "..." + upper_bound;
69
public sealed class ArrayType : TypeSpecification {
71
Collection<ArrayDimension> dimensions;
73
public Collection<ArrayDimension> Dimensions {
75
if (dimensions != null)
78
dimensions = new Collection<ArrayDimension> ();
79
dimensions.Add (new ArrayDimension ());
85
get { return dimensions == null ? 1 : dimensions.Count; }
88
public bool IsVector {
90
if (dimensions == null)
93
if (dimensions.Count > 1)
96
var dimension = dimensions [0];
98
return !dimension.IsSized;
102
public override bool IsValueType {
103
get { return false; }
104
set { throw new InvalidOperationException (); }
107
public override string Name {
108
get { return base.Name + Suffix; }
111
public override string FullName {
112
get { return base.FullName + Suffix; }
120
var suffix = new StringBuilder ();
122
for (int i = 0; i < dimensions.Count; i++) {
126
suffix.Append (dimensions [i].ToString ());
130
return suffix.ToString ();
134
public override bool IsArray {
138
public ArrayType (TypeReference type)
141
Mixin.CheckType (type);
142
this.etype = MD.ElementType.Array;
145
public ArrayType (TypeReference type, int rank)
148
Mixin.CheckType (type);
153
dimensions = new Collection<ArrayDimension> (rank);
154
for (int i = 0; i < rank; i++)
155
dimensions.Add (new ArrayDimension ());
156
this.etype = MD.ElementType.Array;