PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/Microsoft.Scripting/Interpretation/CommaAddress.cs

https://bitbucket.org/stefanrusek/xronos
C# | 61 lines | 39 code | 8 blank | 14 comment | 7 complexity | ce38ca9a751b67ee3290c6bd79d0d1f5 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; using Microsoft;
  16. using System.Collections.Generic;
  17. #if CODEPLEX_40
  18. using System.Linq.Expressions;
  19. #else
  20. using Microsoft.Linq.Expressions;
  21. #endif
  22. namespace Microsoft.Scripting.Interpretation {
  23. internal class CommaAddress : EvaluationAddress {
  24. private List<EvaluationAddress> _addrs;
  25. internal CommaAddress(BlockExpression address, List<EvaluationAddress> addresses)
  26. : base(address) {
  27. _addrs = addresses;
  28. }
  29. internal override object GetValue(InterpreterState state, bool outParam) {
  30. object result = null;
  31. for (int i = 0; i < _addrs.Count; i++) {
  32. EvaluationAddress current = _addrs[i];
  33. if (current != null) {
  34. object val = current.GetValue(state, outParam);
  35. if (i == Index) {
  36. result = val;
  37. }
  38. }
  39. }
  40. return result;
  41. }
  42. internal override object AssignValue(InterpreterState state, object value) {
  43. EvaluationAddress addr = _addrs[Index];
  44. if (addr != null) return addr.AssignValue(state, value);
  45. return null;
  46. }
  47. internal int Index {
  48. get {
  49. return ((BlockExpression)Expression).Expressions.Count - 1;
  50. }
  51. }
  52. }
  53. }