BOO-988: Added else block to the for and while statements, and include a suite of...
[boo.git] / src / Boo.Lang.Compiler / TypeSystem / GenericMappedMembers.cs
blob6dd113496bbc85fb6870a97a5046a92293531411
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 IType ReturnType
215 get { return GenericMapping.Map(Source.ReturnType); }
218 public IParameter[] GetParameters()
220 return _parameters ?? (_parameters = GenericMapping.Map(Source.GetParameters()));
224 #endregion
226 #region class GenericMappedConstructor
228 /// <summary>
229 /// A constructor on a generic constructed type.
230 /// </summary>
231 public class GenericMappedConstructor : GenericMappedMethod, IConstructor
233 public GenericMappedConstructor(TypeSystemServices tss, IConstructor source, GenericMapping genericMapping)
234 : base(tss, (IMethod)source, genericMapping)
239 #endregion
241 #region class GenericMappedProperty
243 /// <summary>
244 /// A property on a generic constructed type.
245 /// </summary>
246 public class GenericMappedProperty : GenericMappedAccessibleMember<IProperty>, IProperty
248 IParameter[] _parameters;
250 public GenericMappedProperty(TypeSystemServices tss, IProperty source, GenericMapping genericMapping)
251 : base(tss, source, genericMapping)
255 public IParameter[] GetParameters()
257 return _parameters ?? (_parameters = GenericMapping.Map(Source.GetParameters()));
260 public IMethod GetGetMethod()
262 return GenericMapping.Map(Source.GetGetMethod());
265 public IMethod GetSetMethod()
267 return GenericMapping.Map(Source.GetSetMethod());
270 public override string ToString()
272 return string.Format("{0} as {1}", Name, Type);
275 public bool AcceptVarArgs
277 get { return Source.AcceptVarArgs; }
280 public bool IsExtension
282 get { return Source.IsExtension; }
286 #endregion
288 #region class GenericMappedEvent
290 /// <summary>
291 /// An event in a constructed generic type.
292 /// </summary>
293 public class GenericMappedEvent : GenericMappedMember<IEvent>, IEvent
295 public GenericMappedEvent(TypeSystemServices tss, IEvent source, GenericMapping genericMapping)
296 : base(tss, source, genericMapping)
300 public IMethod GetAddMethod()
302 return GenericMapping.Map(Source.GetAddMethod());
305 public IMethod GetRemoveMethod()
307 return GenericMapping.Map(Source.GetRemoveMethod());
310 public IMethod GetRaiseMethod()
312 return GenericMapping.Map(Source.GetRemoveMethod());
315 public bool IsAbstract
317 get { return Source.IsAbstract; }
320 public bool IsVirtual
322 get { return Source.IsVirtual; }
326 #endregion
328 #region class GenericMappedField
330 /// <summary>
331 /// A field on a generic constructed type.
332 /// </summary>
333 public class GenericMappedField : GenericMappedAccessibleMember<IField>, IField
335 public GenericMappedField(TypeSystemServices tss, IField source, GenericMapping genericMapping)
336 : base(tss, source, genericMapping)
340 public bool IsInitOnly
342 get { return Source.IsInitOnly; }
345 public bool IsLiteral
347 get { return Source.IsLiteral; }
350 public object StaticValue
352 get { return Source.StaticValue; }
356 #endregion
358 #region class GenericMappedParameter
360 /// <summary>
361 /// A parameter in a method constructed from a generic method, or a mapped onto a type constructed
362 /// from a generic type.
363 /// </summary>
364 public class GenericMappedParameter : IParameter
366 private GenericMapping _genericMapping;
367 private IParameter _baseParameter;
369 public GenericMappedParameter(IParameter parameter, GenericMapping genericMapping)
371 _genericMapping = genericMapping;
372 _baseParameter = parameter;
375 public bool IsByRef
377 get { return _baseParameter.IsByRef; }
380 public IType Type
382 get { return _genericMapping.Map(_baseParameter.Type); }
385 public string Name
387 get { return _baseParameter.Name; }
390 public string FullName
392 get { return _baseParameter.FullName; }
395 public EntityType EntityType
397 get { return EntityType.Parameter; }
401 #endregion