PageRenderTime 122ms CodeModel.GetById 101ms app.highlight 3ms RepoModel.GetById 17ms 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 * ***************************************************************************/
15using System; using Microsoft;
16
17
18using System.Collections.Generic;
19#if CODEPLEX_40
20using System.Linq.Expressions;
21#else
22using Microsoft.Linq.Expressions;
23#endif
24
25namespace Microsoft.Scripting.Interpretation {
26    internal class CommaAddress : EvaluationAddress {
27        private List<EvaluationAddress> _addrs;
28
29        internal CommaAddress(BlockExpression address, List<EvaluationAddress> addresses)
30            : base(address) {
31            _addrs = addresses;
32        }
33
34        internal override object GetValue(InterpreterState state, bool outParam) {
35            object result = null;
36            for (int i = 0; i < _addrs.Count; i++) {
37                EvaluationAddress current = _addrs[i];
38
39                if (current != null) {
40                    object val = current.GetValue(state, outParam);
41                    if (i == Index) {
42                        result = val;
43                    }
44                }
45            }
46            return result;
47        }
48
49        internal override object AssignValue(InterpreterState state, object value) {
50            EvaluationAddress addr = _addrs[Index];
51            if (addr != null) return addr.AssignValue(state, value);
52            return null;
53        }
54
55        internal int Index {
56            get {
57                return ((BlockExpression)Expression).Expressions.Count - 1;
58            }
59        }
60    }
61}