BOO-999
[boo.git] / src / Boo.Lang.Compiler / TypeSystem / GenericMappedMembers.cs
blob6368c81a22dbfb6110f048e933882e954647fe03
1 #region license
2 // Copyright (c) 2003, 2004, 2005 Rodrigo B. de Oliveira (rbo@acm.org)
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
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.
16 //
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.
27 #endregion
29 namespace Boo.Lang.Compiler.TypeSystem
31 using System;
32 using System.Collections.Generic;
33 using Boo.Lang.Compiler.TypeSystem;
34 using Boo.Lang.Compiler.Ast;
36 /// <summary>
37 /// A base class for a member mapped from a generic type onto a constructed type.
38 /// </summary>
39 public abstract class GenericMappedMember<T> : IMember where T : IMember
41 protected readonly TypeSystemServices _tss;
42 readonly T _source;
43 readonly GenericMapping _genericMapping;
44 string _fullName = null;
46 protected GenericMappedMember(TypeSystemServices tss, T source, GenericMapping genericMapping)
48 _tss = tss;
49 _source = source;
50 _genericMapping = genericMapping;
53 public T Source
55 get { return _source; }
58 private string BuildFullName()
60 return DeclaringType.FullName + "." + Name;
63 public GenericMapping GenericMapping
65 get { return _genericMapping; }
68 public bool IsDuckTyped
70 get { return Source.IsDuckTyped; }
73 public IType DeclaringType
75 get { return GenericMapping.Map(Source.DeclaringType); }
78 public bool IsStatic
80 get { return Source.IsStatic; }
83 public IType Type
85 get { return GenericMapping.Map(Source.Type); }
88 public EntityType EntityType
90 get { return Source.EntityType; }
93 public string Name
95 get
97 return Source.Name;
101 public string FullName
103 get { return _fullName ?? (_fullName = BuildFullName()); }
106 public bool IsPublic
108 get { return Source.IsPublic; }
111 public override string ToString()
113 return FullName;
117 /// <summary>
118 /// A base class for an accessible member mapped from a generic type onto a constructed type.
119 /// </summary>
120 /// <typeparam name="T"></typeparam>
121 public abstract class GenericMappedAccessibleMember<T> : GenericMappedMember<T> where T : IAccessibleMember
123 protected GenericMappedAccessibleMember(TypeSystemServices tss, T source, GenericMapping genericMapping)
124 : base(tss, source, genericMapping)
128 public bool IsProtected
130 get { return Source.IsProtected; }
133 public bool IsInternal
135 get { return Source.IsInternal; }
138 public bool IsPrivate
140 get { return Source.IsPrivate; }
144 #region class GenericMappedMethod
146 /// <summary>
147 /// A method on a generic constructed type.
148 /// </summary>
149 public class GenericMappedMethod : GenericMappedAccessibleMember<IMethod>, IMethod
151 IParameter[] _parameters = null;
152 ICallableType _callableType = null;
154 public GenericMappedMethod(TypeSystemServices tss, IMethod source, GenericMapping genericMapping)
155 : base(tss, source, genericMapping)
159 public bool IsAbstract
161 get { return Source.IsAbstract; }
164 public bool IsVirtual
166 get { return Source.IsVirtual; }
169 public bool IsSpecialName
171 get { return Source.IsSpecialName; }
174 public bool IsPInvoke
176 get { return Source.IsPInvoke; }
179 public virtual IConstructedMethodInfo ConstructedInfo
181 // Generic mapped methods are not generic methods - those are InternalGenericMethods
182 get { return null; }
185 public IGenericMethodInfo GenericInfo
187 // TODO: Generic mapped methods can be generic definitions!
188 get { return null; }
191 public ICallableType CallableType
195 if (null == _callableType)
197 _callableType = _tss.GetCallableType(this);
199 return _callableType;
203 public bool AcceptVarArgs
205 get { return Source.AcceptVarArgs; }
208 public bool IsExtension
210 get { return Source.IsExtension; }
213 public bool IsBooExtension
215 get { return Source.IsBooExtension; }
218 public bool IsClrExtension
220 get { return Source.IsClrExtension; }
223 public IType ReturnType
225 get { return GenericMapping.Map(Source.ReturnType); }
228 public IParameter[] GetParameters()
230 return _parameters ?? (_parameters = GenericMapping.Map(Source.GetParameters()));
234 #endregion
236 #region class GenericMappedConstructor
238 /// <summary>
239 /// A constructor on a generic constructed type.
240 /// </summary>
241 public class GenericMappedConstructor : GenericMappedMethod, IConstructor
243 public GenericMappedConstructor(TypeSystemServices tss, IConstructor source, GenericMapping genericMapping)
244 : base(tss, (IMethod)source, genericMapping)
249 #endregion
251 #region class GenericMappedProperty
253 /// <summary>
254 /// A property on a generic constructed type.
255 /// </summary>
256 public class GenericMappedProperty : GenericMappedAccessibleMember<IProperty>, IProperty
258 IParameter[] _parameters;
260 public GenericMappedProperty(TypeSystemServices tss, IProperty source, GenericMapping genericMapping)
261 : base(tss, source, genericMapping)
265 public IParameter[] GetParameters()
267 return _parameters ?? (_parameters = GenericMapping.Map(Source.GetParameters()));
270 public IMethod GetGetMethod()
272 return GenericMapping.Map(Source.GetGetMethod());
275 public IMethod GetSetMethod()
277 return GenericMapping.Map(Source.GetSetMethod());
280 public override string ToString()
282 return string.Format("{0} as {1}", Name, Type);
285 public bool AcceptVarArgs
287 get { return Source.AcceptVarArgs; }
290 public bool IsExtension
292 get { return Source.IsExtension; }
295 public bool IsBooExtension
297 get { return Source.IsBooExtension; }
300 public bool IsClrExtension
302 get { return Source.IsClrExtension; }
307 #endregion
309 #region class GenericMappedEvent
311 /// <summary>
312 /// An event in a constructed generic type.
313 /// </summary>
314 public class GenericMappedEvent : GenericMappedMember<IEvent>, IEvent
316 public GenericMappedEvent(TypeSystemServices tss, IEvent source, GenericMapping genericMapping)
317 : base(tss, source, genericMapping)
321 public IMethod GetAddMethod()
323 return GenericMapping.Map(Source.GetAddMethod());
326 public IMethod GetRemoveMethod()
328 return GenericMapping.Map(Source.GetRemoveMethod());
331 public IMethod GetRaiseMethod()
333 return GenericMapping.Map(Source.GetRemoveMethod());
336 public bool IsAbstract
338 get { return Source.IsAbstract; }
341 public bool IsVirtual
343 get { return Source.IsVirtual; }
347 #endregion
349 #region class GenericMappedField
351 /// <summary>
352 /// A field on a generic constructed type.
353 /// </summary>
354 public class GenericMappedField : GenericMappedAccessibleMember<IField>, IField
356 public GenericMappedField(TypeSystemServices tss, IField source, GenericMapping genericMapping)
357 : base(tss, source, genericMapping)
361 public bool IsInitOnly
363 get { return Source.IsInitOnly; }
366 public bool IsLiteral
368 get { return Source.IsLiteral; }
371 public object StaticValue
373 get { return Source.StaticValue; }
377 #endregion
379 #region class GenericMappedParameter
381 /// <summary>
382 /// A parameter in a method constructed from a generic method, or a mapped onto a type constructed
383 /// from a generic type.
384 /// </summary>
385 public class GenericMappedParameter : IParameter
387 private GenericMapping _genericMapping;
388 private IParameter _baseParameter;
390 public GenericMappedParameter(IParameter parameter, GenericMapping genericMapping)
392 _genericMapping = genericMapping;
393 _baseParameter = parameter;
396 public bool IsByRef
398 get { return _baseParameter.IsByRef; }
401 public IType Type
403 get { return _genericMapping.Map(_baseParameter.Type); }
406 public string Name
408 get { return _baseParameter.Name; }
411 public string FullName
413 get { return _baseParameter.FullName; }
416 public EntityType EntityType
418 get { return EntityType.Parameter; }
422 #endregion