PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/Dependencies/boo/src/Boo.Lang.Compiler/TypeSystem/GenericMappedMembers.cs

https://github.com/w4x/boolangstudio
C# | 423 lines | 295 code | 75 blank | 53 comment | 2 complexity | f2f581846d7f71dece2cb6ce6ce4b039 MD5 | raw file
Possible License(s): GPL-2.0
  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
  28. namespace Boo.Lang.Compiler.TypeSystem
  29. {
  30. using System;
  31. using System.Collections.Generic;
  32. using Boo.Lang.Compiler.TypeSystem;
  33. using Boo.Lang.Compiler.Ast;
  34. /// <summary>
  35. /// A base class for a member mapped from a generic type onto a constructed type.
  36. /// </summary>
  37. public abstract class GenericMappedMember<T> : IMember where T : IMember
  38. {
  39. protected readonly TypeSystemServices _tss;
  40. readonly T _source;
  41. readonly GenericMapping _genericMapping;
  42. string _fullName = null;
  43. protected GenericMappedMember(TypeSystemServices tss, T source, GenericMapping genericMapping)
  44. {
  45. _tss = tss;
  46. _source = source;
  47. _genericMapping = genericMapping;
  48. }
  49. public T Source
  50. {
  51. get { return _source; }
  52. }
  53. private string BuildFullName()
  54. {
  55. return DeclaringType.FullName + "." + Name;
  56. }
  57. public GenericMapping GenericMapping
  58. {
  59. get { return _genericMapping; }
  60. }
  61. public bool IsDuckTyped
  62. {
  63. get { return Source.IsDuckTyped; }
  64. }
  65. public IType DeclaringType
  66. {
  67. get { return GenericMapping.Map(Source.DeclaringType); }
  68. }
  69. public bool IsStatic
  70. {
  71. get { return Source.IsStatic; }
  72. }
  73. public IType Type
  74. {
  75. get { return GenericMapping.Map(Source.Type); }
  76. }
  77. public EntityType EntityType
  78. {
  79. get { return Source.EntityType; }
  80. }
  81. public string Name
  82. {
  83. get
  84. {
  85. return Source.Name;
  86. }
  87. }
  88. public string FullName
  89. {
  90. get { return _fullName ?? (_fullName = BuildFullName()); }
  91. }
  92. public bool IsPublic
  93. {
  94. get { return Source.IsPublic; }
  95. }
  96. public override string ToString()
  97. {
  98. return FullName;
  99. }
  100. }
  101. /// <summary>
  102. /// A base class for an accessible member mapped from a generic type onto a constructed type.
  103. /// </summary>
  104. /// <typeparam name="T"></typeparam>
  105. public abstract class GenericMappedAccessibleMember<T> : GenericMappedMember<T> where T : IAccessibleMember
  106. {
  107. protected GenericMappedAccessibleMember(TypeSystemServices tss, T source, GenericMapping genericMapping)
  108. : base(tss, source, genericMapping)
  109. {
  110. }
  111. public bool IsProtected
  112. {
  113. get { return Source.IsProtected; }
  114. }
  115. public bool IsInternal
  116. {
  117. get { return Source.IsInternal; }
  118. }
  119. public bool IsPrivate
  120. {
  121. get { return Source.IsPrivate; }
  122. }
  123. }
  124. #region class GenericMappedMethod
  125. /// <summary>
  126. /// A method on a generic constructed type.
  127. /// </summary>
  128. public class GenericMappedMethod : GenericMappedAccessibleMember<IMethod>, IMethod
  129. {
  130. IParameter[] _parameters = null;
  131. ICallableType _callableType = null;
  132. public GenericMappedMethod(TypeSystemServices tss, IMethod source, GenericMapping genericMapping)
  133. : base(tss, source, genericMapping)
  134. {
  135. }
  136. public bool IsAbstract
  137. {
  138. get { return Source.IsAbstract; }
  139. }
  140. public bool IsVirtual
  141. {
  142. get { return Source.IsVirtual; }
  143. }
  144. public bool IsSpecialName
  145. {
  146. get { return Source.IsSpecialName; }
  147. }
  148. public bool IsPInvoke
  149. {
  150. get { return Source.IsPInvoke; }
  151. }
  152. public virtual IConstructedMethodInfo ConstructedInfo
  153. {
  154. // Generic mapped methods are not generic methods - those are InternalGenericMethods
  155. get { return null; }
  156. }
  157. public IGenericMethodInfo GenericInfo
  158. {
  159. // TODO: Generic mapped methods can be generic definitions!
  160. get { return null; }
  161. }
  162. public ICallableType CallableType
  163. {
  164. get
  165. {
  166. if (null == _callableType)
  167. {
  168. _callableType = _tss.GetCallableType(this);
  169. }
  170. return _callableType;
  171. }
  172. }
  173. public bool AcceptVarArgs
  174. {
  175. get { return Source.AcceptVarArgs; }
  176. }
  177. public bool IsExtension
  178. {
  179. get { return Source.IsExtension; }
  180. }
  181. public bool IsBooExtension
  182. {
  183. get { return Source.IsBooExtension; }
  184. }
  185. public bool IsClrExtension
  186. {
  187. get { return Source.IsClrExtension; }
  188. }
  189. public IType ReturnType
  190. {
  191. get { return GenericMapping.Map(Source.ReturnType); }
  192. }
  193. public IParameter[] GetParameters()
  194. {
  195. return _parameters ?? (_parameters = GenericMapping.Map(Source.GetParameters()));
  196. }
  197. }
  198. #endregion
  199. #region class GenericMappedConstructor
  200. /// <summary>
  201. /// A constructor on a generic constructed type.
  202. /// </summary>
  203. public class GenericMappedConstructor : GenericMappedMethod, IConstructor
  204. {
  205. public GenericMappedConstructor(TypeSystemServices tss, IConstructor source, GenericMapping genericMapping)
  206. : base(tss, (IMethod)source, genericMapping)
  207. {
  208. }
  209. }
  210. #endregion
  211. #region class GenericMappedProperty
  212. /// <summary>
  213. /// A property on a generic constructed type.
  214. /// </summary>
  215. public class GenericMappedProperty : GenericMappedAccessibleMember<IProperty>, IProperty
  216. {
  217. IParameter[] _parameters;
  218. public GenericMappedProperty(TypeSystemServices tss, IProperty source, GenericMapping genericMapping)
  219. : base(tss, source, genericMapping)
  220. {
  221. }
  222. public IParameter[] GetParameters()
  223. {
  224. return _parameters ?? (_parameters = GenericMapping.Map(Source.GetParameters()));
  225. }
  226. public IMethod GetGetMethod()
  227. {
  228. return GenericMapping.Map(Source.GetGetMethod());
  229. }
  230. public IMethod GetSetMethod()
  231. {
  232. return GenericMapping.Map(Source.GetSetMethod());
  233. }
  234. public override string ToString()
  235. {
  236. return string.Format("{0} as {1}", Name, Type);
  237. }
  238. public bool AcceptVarArgs
  239. {
  240. get { return Source.AcceptVarArgs; }
  241. }
  242. public bool IsExtension
  243. {
  244. get { return Source.IsExtension; }
  245. }
  246. public bool IsBooExtension
  247. {
  248. get { return Source.IsBooExtension; }
  249. }
  250. public bool IsClrExtension
  251. {
  252. get { return Source.IsClrExtension; }
  253. }
  254. }
  255. #endregion
  256. #region class GenericMappedEvent
  257. /// <summary>
  258. /// An event in a constructed generic type.
  259. /// </summary>
  260. public class GenericMappedEvent : GenericMappedMember<IEvent>, IEvent
  261. {
  262. public GenericMappedEvent(TypeSystemServices tss, IEvent source, GenericMapping genericMapping)
  263. : base(tss, source, genericMapping)
  264. {
  265. }
  266. public IMethod GetAddMethod()
  267. {
  268. return GenericMapping.Map(Source.GetAddMethod());
  269. }
  270. public IMethod GetRemoveMethod()
  271. {
  272. return GenericMapping.Map(Source.GetRemoveMethod());
  273. }
  274. public IMethod GetRaiseMethod()
  275. {
  276. return GenericMapping.Map(Source.GetRemoveMethod());
  277. }
  278. public bool IsAbstract
  279. {
  280. get { return Source.IsAbstract; }
  281. }
  282. public bool IsVirtual
  283. {
  284. get { return Source.IsVirtual; }
  285. }
  286. }
  287. #endregion
  288. #region class GenericMappedField
  289. /// <summary>
  290. /// A field on a generic constructed type.
  291. /// </summary>
  292. public class GenericMappedField : GenericMappedAccessibleMember<IField>, IField
  293. {
  294. public GenericMappedField(TypeSystemServices tss, IField source, GenericMapping genericMapping)
  295. : base(tss, source, genericMapping)
  296. {
  297. }
  298. public bool IsInitOnly
  299. {
  300. get { return Source.IsInitOnly; }
  301. }
  302. public bool IsLiteral
  303. {
  304. get { return Source.IsLiteral; }
  305. }
  306. public object StaticValue
  307. {
  308. get { return Source.StaticValue; }
  309. }
  310. }
  311. #endregion
  312. #region class GenericMappedParameter
  313. /// <summary>
  314. /// A parameter in a method constructed from a generic method, or a mapped onto a type constructed
  315. /// from a generic type.
  316. /// </summary>
  317. public class GenericMappedParameter : IParameter
  318. {
  319. private GenericMapping _genericMapping;
  320. private IParameter _baseParameter;
  321. public GenericMappedParameter(IParameter parameter, GenericMapping genericMapping)
  322. {
  323. _genericMapping = genericMapping;
  324. _baseParameter = parameter;
  325. }
  326. public bool IsByRef
  327. {
  328. get { return _baseParameter.IsByRef; }
  329. }
  330. public IType Type
  331. {
  332. get { return _genericMapping.Map(_baseParameter.Type); }
  333. }
  334. public string Name
  335. {
  336. get { return _baseParameter.Name; }
  337. }
  338. public string FullName
  339. {
  340. get { return _baseParameter.FullName; }
  341. }
  342. public EntityType EntityType
  343. {
  344. get { return EntityType.Parameter; }
  345. }
  346. }
  347. #endregion
  348. }