Merge branch 'cecil-light'
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Scripting.Core / Actions / CallSiteOps.cs
1 /* ****************************************************************************
2  *
3  * Copyright (c) Microsoft Corporation. 
4  *
5  * This source code is subject to terms and conditions of the Apache License, Version 2.0. 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  Apache License, Version 2.0, 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 Apache License, Version 2.0.
10  *
11  * You must not remove this notice, or any other, from this software.
12  *
13  *
14  * ***************************************************************************/
15
16 using System.ComponentModel;
17 using System.Diagnostics;
18 using System.Dynamic;
19 using System.Collections.Generic;
20
21 namespace System.Runtime.CompilerServices {
22
23     // Conceptually these are instance methods on CallSite<T> but
24     // we don't want users to see them
25
26     /// <summary>
27     /// This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.
28     /// </summary>
29     [EditorBrowsable(EditorBrowsableState.Never), DebuggerStepThrough]
30     public static class CallSiteOps {
31
32         /// <summary>
33         /// Creates an instance of a dynamic call site used for cache lookup.
34         /// </summary>
35         /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
36         /// <returns>The new call site.</returns>
37         [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
38         public static CallSite<T> CreateMatchmaker<T>(CallSite<T> site) where T : class {
39             var mm = site.CreateMatchMaker();
40             CallSiteOps.ClearMatch(mm);
41             return mm;
42         }
43
44         /// <summary>
45         /// Checks if a dynamic site requires an update.
46         /// </summary>
47         /// <param name="site">An instance of the dynamic call site.</param>
48         /// <returns>true if rule does not need updating, false otherwise.</returns>
49         [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
50         public static bool SetNotMatched(CallSite site) {
51             var res = site._match;
52             site._match = false;  //avoid branch here to make sure the method is inlined
53             return res;
54         }
55
56         /// <summary>
57         /// Checks whether the executed rule matched
58         /// </summary>
59         /// <param name="site">An instance of the dynamic call site.</param>
60         /// <returns>true if rule matched, false otherwise.</returns>
61         [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
62         public static bool GetMatch(CallSite site) {
63             return site._match;
64         }
65
66         /// <summary>
67         /// Clears the match flag on the matchmaker call site.
68         /// </summary>
69         /// <param name="site">An instance of the dynamic call site.</param>
70         [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
71         public static void ClearMatch(CallSite site) {
72             site._match = true;
73         }
74
75         /// <summary>
76         /// Adds a rule to the cache maintained on the dynamic call site.
77         /// </summary>
78         /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
79         /// <param name="site">An instance of the dynamic call site.</param>
80         /// <param name="rule">An instance of the call site rule.</param>
81         [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
82         public static void AddRule<T>(CallSite<T> site, T rule) where T : class {
83             site.AddRule(rule);
84         }
85
86         /// <summary>
87         /// Updates rules in the cache.
88         /// </summary>
89         /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
90         /// <param name="this">An instance of the dynamic call site.</param>
91         /// <param name="matched">The matched rule index.</param>
92         [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
93         public static void UpdateRules<T>(CallSite<T> @this, int matched) where T : class {
94             if (matched > 1) {
95                 @this.MoveRule(matched);
96             }
97         }
98
99         /// <summary>
100         /// Gets the dynamic binding rules from the call site.
101         /// </summary>
102         /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
103         /// <param name="site">An instance of the dynamic call site.</param>
104         /// <returns>An array of dynamic binding rules.</returns>
105         [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
106         public static T[] GetRules<T>(CallSite<T> site) where T : class {
107             return site.Rules;
108         }
109
110
111         /// <summary>
112         /// Retrieves binding rule cache.
113         /// </summary>
114         /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
115         /// <param name="site">An instance of the dynamic call site.</param>
116         /// <returns>The cache.</returns>
117         [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
118         public static RuleCache<T> GetRuleCache<T>(CallSite<T> site) where T : class {
119             return site.Binder.GetRuleCache<T>();
120         }
121
122
123         /// <summary>
124         /// Moves the binding rule within the cache.
125         /// </summary>
126         /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
127         /// <param name="cache">The call site rule cache.</param>
128         /// <param name="rule">An instance of the call site rule.</param>
129         /// <param name="i">An index of the call site rule.</param>
130         [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
131         public static void MoveRule<T>(RuleCache<T> cache, T rule, int i) where T : class {
132             if (i > 1) {
133                 cache.MoveRule(rule, i);
134             }
135         }
136
137         /// <summary>
138         /// Searches the dynamic rule cache for rules applicable to the dynamic operation.
139         /// </summary>
140         /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
141         /// <param name="cache">The cache.</param>
142         /// <returns>The collection of applicable rules.</returns>
143         [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
144         public static T[] GetCachedRules<T>(RuleCache<T> cache) where T : class {
145             return cache.GetRules();
146         }
147
148         /// <summary>
149         /// Updates the call site target with a new rule based on the arguments.
150         /// </summary>
151         /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
152         /// <param name="binder">The call site binder.</param>
153         /// <param name="site">An instance of the dynamic call site.</param>
154         /// <param name="args">Arguments to the call site.</param>
155         /// <returns>The new call site target.</returns>
156         [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
157         public static T Bind<T>(CallSiteBinder binder, CallSite<T> site, object[] args) where T : class {
158             return binder.BindCore(site, args);
159         }
160     }
161 }