/libs/Microsoft.Scripting/Stubs.cs

http://ironlua.googlecode.com/ · C# · 382 lines · 290 code · 69 blank · 23 comment · 83 complexity · bc9eb2dcb7d4dd5e60e98826f0a1186d MD5 · raw file

  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Microsoft Public License. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Microsoft Public License, please send an email to
  8. * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Microsoft Public License.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Text;
  18. using System.Reflection;
  19. using System.Globalization;
  20. using System.IO;
  21. using System.Collections;
  22. using Microsoft.Scripting.Utils;
  23. using System.Diagnostics;
  24. #if SILVERLIGHT // Stubs
  25. namespace System {
  26. namespace Runtime.InteropServices {
  27. public sealed class DefaultParameterValueAttribute : Attribute {
  28. public DefaultParameterValueAttribute(object value) { }
  29. }
  30. }
  31. // We reference these namespaces via "using"
  32. // We don't actually use them because the code is #if !SILVERLIGHT
  33. // Rather than fix the usings all over the place, just define these here
  34. namespace Runtime.Remoting { class Dummy {} }
  35. namespace Security.Policy { class Dummy {} }
  36. namespace Xml.XPath { class Dummy {} }
  37. namespace Reflection {
  38. public enum PortableExecutableKinds {
  39. ILOnly = 0
  40. }
  41. public enum ImageFileMachine {
  42. I386 = 1
  43. }
  44. }
  45. namespace ComponentModel {
  46. public class WarningException : SystemException {
  47. public WarningException(string message) : base(message) { }
  48. }
  49. }
  50. public class SerializableAttribute : Attribute {
  51. }
  52. public class NonSerializedAttribute : Attribute {
  53. }
  54. namespace Runtime.Serialization {
  55. public interface ISerializable {
  56. }
  57. }
  58. [Flags]
  59. public enum StringSplitOptions {
  60. None = 0,
  61. RemoveEmptyEntries = 1,
  62. }
  63. public enum ConsoleColor {
  64. Black = 0,
  65. DarkBlue = 1,
  66. DarkGreen = 2,
  67. DarkCyan = 3,
  68. DarkRed = 4,
  69. DarkMagenta = 5,
  70. DarkYellow = 6,
  71. Gray = 7,
  72. DarkGray = 8,
  73. Blue = 9,
  74. Green = 10,
  75. Cyan = 11,
  76. Red = 12,
  77. Magenta = 13,
  78. Yellow = 14,
  79. White = 15,
  80. }
  81. // BitArray, LinkedList<T> and LinkedListNode<T> were removed from CoreCLR
  82. // Recreating simple versions here.
  83. namespace Collections {
  84. #region BitArray
  85. public class BitArray {
  86. readonly int[] _data;
  87. readonly int _count;
  88. public int Length {
  89. get { return _count; }
  90. }
  91. public int Count {
  92. get { return _count; }
  93. }
  94. public BitArray(int count)
  95. : this(count, false) {
  96. }
  97. public BitArray(int count, bool value) {
  98. this._count = count;
  99. this._data = new int[(count + 31) / 32];
  100. if (value) {
  101. Not();
  102. }
  103. }
  104. public BitArray(BitArray bits) {
  105. _count = bits._count;
  106. _data = (int[])bits._data.Clone();
  107. }
  108. public bool Get(int index) {
  109. if (index < 0 || index >= _count) {
  110. throw new ArgumentOutOfRangeException();
  111. }
  112. int elem = index / 32, mask = 1 << (index % 32);
  113. return (_data[elem] & mask) != 0;
  114. }
  115. public void Set(int index, bool value) {
  116. if (index < 0 || index >= _count) {
  117. throw new ArgumentOutOfRangeException();
  118. }
  119. int elem = index / 32, mask = 1 << (index % 32);
  120. if (value) {
  121. _data[elem] |= mask;
  122. } else {
  123. _data[elem] &= ~mask;
  124. }
  125. }
  126. public void SetAll(bool value) {
  127. int set = value ? -1 : 0;
  128. for (int i = 0; i < _data.Length; ++i) {
  129. _data[i] = set;
  130. }
  131. }
  132. public BitArray And(BitArray bits) {
  133. if (bits == null) {
  134. throw new ArgumentNullException();
  135. } else if (bits._count != _count) {
  136. throw new ArgumentException("Array lengths differ");
  137. }
  138. for (int i = 0; i < _data.Length; ++i) {
  139. _data[i] &= bits._data[i];
  140. }
  141. return this;
  142. }
  143. public BitArray Or(BitArray bits) {
  144. if (bits == null) {
  145. throw new ArgumentNullException();
  146. } else if (bits._count != _count) {
  147. throw new ArgumentException("Array lengths differ");
  148. }
  149. for (int i = 0; i < _data.Length; ++i) {
  150. _data[i] |= bits._data[i];
  151. }
  152. return this;
  153. }
  154. public BitArray Not() {
  155. for (int i = 0; i < _data.Length; ++i) {
  156. _data[i] = ~_data[i];
  157. }
  158. return this;
  159. }
  160. }
  161. #endregion
  162. }
  163. namespace Collections.Generic {
  164. #region LinkedList<T>, LinkedListNode<T>
  165. public class LinkedListNode<T> {
  166. internal LinkedList<T> _list;
  167. internal LinkedListNode<T> _previous, _next;
  168. internal T _value;
  169. internal LinkedListNode(LinkedList<T> list, T value) {
  170. _list = list;
  171. _value = value;
  172. }
  173. public LinkedListNode(T value) {
  174. _value = value;
  175. }
  176. public LinkedList<T> List {
  177. get { return _list; }
  178. }
  179. public LinkedListNode<T> Previous {
  180. get { return _previous; }
  181. }
  182. public LinkedListNode<T> Next {
  183. get { return _next; }
  184. }
  185. public T Value {
  186. get { return _value; }
  187. }
  188. }
  189. public class LinkedList<T> {
  190. private LinkedListNode<T> _first;
  191. private LinkedListNode<T> _last;
  192. public LinkedList() { }
  193. public LinkedListNode<T> Last {
  194. get { return _last; }
  195. }
  196. public LinkedListNode<T> First {
  197. get { return _first; }
  198. }
  199. public void AddFirst(T value) {
  200. AddFirst(new LinkedListNode<T>(value));
  201. }
  202. public void AddFirst(LinkedListNode<T> node) {
  203. CheckInvariants();
  204. if (node == null) {
  205. throw new ArgumentNullException("node");
  206. }
  207. if (node._list != null) {
  208. throw new InvalidOperationException("node is already a member of another list");
  209. }
  210. node._list = this;
  211. node._next = _first;
  212. if (_first != null) {
  213. _first._previous = node;
  214. }
  215. _first = node;
  216. if (_last == null) {
  217. _last = node;
  218. }
  219. CheckInvariants();
  220. }
  221. public void AddLast(T value) {
  222. AddLast(new LinkedListNode<T>(value));
  223. }
  224. public void AddLast(LinkedListNode<T> node) {
  225. CheckInvariants();
  226. if (node == null) {
  227. throw new ArgumentNullException("node");
  228. }
  229. if (node._list != null) {
  230. throw new InvalidOperationException("node is already a member of another list");
  231. }
  232. node._list = this;
  233. node._previous = _last;
  234. if (_last != null) {
  235. _last._next = node;
  236. }
  237. _last = node;
  238. if (_first == null) {
  239. _first = node;
  240. }
  241. CheckInvariants();
  242. }
  243. public void Remove(LinkedListNode<T> node) {
  244. CheckInvariants();
  245. if (node == null) {
  246. throw new ArgumentNullException("node");
  247. }
  248. if (node._list != this) {
  249. throw new InvalidOperationException("node is not a member of this list");
  250. }
  251. if (node._previous == null) {
  252. _first = node._next;
  253. } else {
  254. node._previous._next = node._next;
  255. }
  256. if (node._next == null) {
  257. _last = node._previous;
  258. } else {
  259. node._next._previous = node._previous;
  260. }
  261. node._list = null;
  262. node._previous = null;
  263. node._next = null;
  264. CheckInvariants();
  265. }
  266. [Conditional("DEBUG")]
  267. private void CheckInvariants() {
  268. if (_first == null || _last == null) {
  269. // empty list
  270. Debug.Assert(_first == null && _last == null);
  271. } else if (_first == _last) {
  272. // one element
  273. Debug.Assert(_first._next == null && _first._previous == null && _first._list == this);
  274. } else {
  275. Debug.Assert(_first._previous == null && _first._list == this);
  276. Debug.Assert(_last._next == null && _last._list == this);
  277. if (_first._next == _last || _last._previous == _first) {
  278. // two elements
  279. Debug.Assert(_first._next == _last && _last._previous == _first);
  280. } else if (_first._next == _last._previous) {
  281. // three elements
  282. Debug.Assert(_first._next._next == _last && _last._previous._previous == _first);
  283. }
  284. }
  285. }
  286. }
  287. #endregion
  288. }
  289. }
  290. #endif
  291. #if !SPECSHARP
  292. namespace Microsoft.Contracts {
  293. [Conditional("SPECSHARP"), AttributeUsage(AttributeTargets.Delegate | AttributeTargets.Event | AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = false, Inherited = true)]
  294. internal sealed class StateIndependentAttribute : Attribute {
  295. }
  296. [Conditional("SPECSHARP"), AttributeUsage(AttributeTargets.Delegate | AttributeTargets.Event | AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = false, Inherited = true)]
  297. internal sealed class PureAttribute : Attribute {
  298. }
  299. [Conditional("SPECSHARP"), AttributeUsage(AttributeTargets.Delegate | AttributeTargets.Event | AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = false, Inherited = true)]
  300. internal sealed class ConfinedAttribute : Attribute {
  301. }
  302. [Conditional("SPECSHARP"), AttributeUsage(AttributeTargets.Field)]
  303. internal sealed class StrictReadonlyAttribute : Attribute {
  304. }
  305. internal static class NonNullType {
  306. [DebuggerStepThrough]
  307. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters")]
  308. public static void AssertInitialized<T>(T[] array) where T : class {
  309. Assert.NotNullItems<T>(array);
  310. }
  311. }
  312. }
  313. #endif