2 /* ****************************************************************************
4 * Copyright (c) Microsoft Corporation.
6 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
7 * copy of the license can be found in the License.html file at the root of this distribution. If
8 * you cannot locate the Apache License, Version 2.0, please send an email to
9 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
10 * by the terms of the Apache License, Version 2.0.
12 * You must not remove this notice, or any other, from this software.
15 * ***************************************************************************/
18 using Microsoft
.Scripting
.Ast
;
19 using Microsoft
.Scripting
.Utils
;
21 using System
.Linq
.Expressions
;
24 using System
.Collections
.Generic
;
26 namespace System
.Dynamic
.Utils
{
27 // Miscellaneous helpers that don't belong anywhere else
28 internal static class Helpers
{
30 internal static T CommonNode
<T
>(T first
, T second
, Func
<T
, T
> parent
) where T
: class {
31 var cmp
= EqualityComparer
<T
>.Default
;
32 if (cmp
.Equals(first
, second
)) {
35 var set = new Set
<T
>(cmp
);
36 for (T t
= first
; t
!= null; t
= parent(t
)) {
39 for (T t
= second
; t
!= null; t
= parent(t
)) {
40 if (set.Contains(t
)) {
47 internal static void IncrementCount
<T
>(T key
, Dictionary
<T
, int> dict
) {
49 dict
.TryGetValue(key
, out count
);
50 dict
[key
] = count
+ 1;