Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CallSite.cs
Go to the documentation of this file.
9
11
12public class CallSite
13{
15
16 internal readonly CallSiteBinder _binder;
17
18 internal bool _match;
19
21
23 {
25 }
26
28 {
31 if (!delegateType.IsSubclassOf(typeof(MulticastDelegate)))
32 {
34 }
36 if (cacheDict == null)
37 {
39 }
41 {
42 MethodInfo method = typeof(CallSite<>).MakeGenericType(delegateType).GetMethod("Create");
43 if (delegateType.IsCollectible)
44 {
45 return (CallSite)method.Invoke(null, new object[1] { binder });
46 }
49 }
50 return value(binder);
51 }
52}
53public class CallSite<T> : CallSite where T : class
54{
55 public T Target;
56
57 internal T[] Rules;
58
60
61 private static T s_cachedUpdate;
62
63 private static volatile T s_cachedNoMatch;
64
65 public T Update
66 {
67 get
68 {
69 if (_match)
70 {
71 return s_cachedNoMatch;
72 }
73 return s_cachedUpdate;
74 }
75 }
76
82
83 private CallSite()
84 : base(null)
85 {
86 }
87
89 {
90 return new CallSite<T>();
91 }
92
94 {
96 if (callSite != null)
97 {
99 }
100 return callSite ?? new CallSite<T>
101 {
102 _match = true
103 };
104 }
105
107 {
108 if (Rules != null)
109 {
111 }
112 }
113
115 {
116 if (!typeof(T).IsSubclassOf(typeof(MulticastDelegate)))
117 {
119 }
121 return new CallSite<T>(binder);
122 }
123
125 {
127 }
128
130 {
131 if (addr == null)
132 {
134 }
135 return addr;
136 }
137
138 internal void AddRule(T newRule)
139 {
140 T[] rules = Rules;
141 if (rules == null)
142 {
143 Rules = new T[1] { newRule };
144 return;
145 }
146 T[] array;
147 if (rules.Length < 9)
148 {
149 array = new T[rules.Length + 1];
150 Array.Copy(rules, 0, array, 1, rules.Length);
151 }
152 else
153 {
154 array = new T[10];
155 Array.Copy(rules, 0, array, 1, 9);
156 }
157 array[0] = newRule;
158 Rules = array;
159 }
160
161 internal void MoveRule(int i)
162 {
163 if (i > 1)
164 {
165 T[] rules = Rules;
166 if (i < rules.Length)
167 {
168 T val = rules[i];
169 rules[i] = rules[i - 1];
170 rules[i - 1] = rules[i - 2];
171 rules[i - 2] = val;
172 }
173 }
174 }
175
176 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod", Justification = "UpdateDelegates methods don't have ILLink annotations.")]
178 {
180 MethodInfo invokeMethod = typeFromHandle.GetInvokeMethod();
182 {
183 MethodInfo methodInfo = null;
184 MethodInfo methodInfo2 = null;
185 if (invokeMethod.ReturnType == typeof(void))
186 {
188 {
189 methodInfo = typeof(UpdateDelegates).GetMethod("UpdateAndExecuteVoid" + sig.Length, BindingFlags.Static | BindingFlags.NonPublic);
190 methodInfo2 = typeof(UpdateDelegates).GetMethod("NoMatchVoid" + sig.Length, BindingFlags.Static | BindingFlags.NonPublic);
191 }
192 }
194 {
195 methodInfo = typeof(UpdateDelegates).GetMethod("UpdateAndExecute" + (sig.Length - 1), BindingFlags.Static | BindingFlags.NonPublic);
196 methodInfo2 = typeof(UpdateDelegates).GetMethod("NoMatch" + (sig.Length - 1), BindingFlags.Static | BindingFlags.NonPublic);
197 }
198 if (methodInfo != null)
199 {
200 s_cachedNoMatch = (T)(object)methodInfo2.MakeGenericMethod(sig).CreateDelegate(typeFromHandle);
201 return (T)(object)methodInfo.MakeGenericMethod(sig).CreateDelegate(typeFromHandle);
202 }
203 }
206 }
207
209 {
210 ParameterInfo[] parametersCached = invoke.GetParametersCached();
211 ContractUtils.Requires(parametersCached.Length != 0 && parametersCached[0].ParameterType == typeof(CallSite), "T");
212 Type[] array = new Type[(invoke.ReturnType != typeof(void)) ? parametersCached.Length : (parametersCached.Length - 1)];
213 bool result = true;
214 for (int i = 1; i < parametersCached.Length; i++)
215 {
217 if (parameterInfo.IsByRefParameter())
218 {
219 result = false;
220 }
221 array[i - 1] = parameterInfo.ParameterType;
222 }
223 if (invoke.ReturnType != typeof(void))
224 {
225 array[^1] = invoke.ReturnType;
226 }
227 sig = array;
228 return result;
229 }
230
231 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod", Justification = "CallSiteOps methods don't have trimming annotations.")]
233 {
234 Type returnType = invoke.GetReturnType();
235 bool flag = returnType == typeof(void);
238 ParameterExpression[] array = Array.ConvertAll(invoke.GetParametersCached(), (ParameterInfo p) => Expression.Parameter(p.ParameterType, p.Name));
240 Type[] typeArguments = new Type[1] { typeof(T) };
242 ParameterExpression[] array2 = array.RemoveFirst();
244 builder2.UncheckedAdd(parameterExpression2);
247 builder2.UncheckedAdd(parameterExpression3);
249 builder2.UncheckedAdd(parameterExpression4);
251 builder2.UncheckedAdd(parameterExpression5);
255 if (!flag)
256 {
257 builder2.UncheckedAdd(parameterExpression6 = Expression.Variable(labelTarget.Type, "result"));
258 }
260 builder2.UncheckedAdd(parameterExpression7);
262 builder2.UncheckedAdd(parameterExpression8);
277 builder2.UncheckedAdd(parameterExpression9);
288 Expression[] list2 = Array.ConvertAll(array2, (ParameterExpression p) => Convert(p, typeof(object)));
289 builder2.UncheckedAdd(parameterExpression10);
294 builder.UncheckedAdd(Expression.Loop(Expression.Block(arg6, arg3, arg5, expression2), null, null));
295 builder.UncheckedAdd(Expression.Default(labelTarget.Type));
297 return expression6.Compile();
298 }
299
301 {
302 ParameterExpression[] array = Array.ConvertAll(invoke.GetParametersCached(), (ParameterInfo p) => Expression.Parameter(p.ParameterType, p.Name));
303 return Expression.Lambda<T>(Expression.Block(Expression.Call(typeof(CallSiteOps).GetMethod("SetNotMatched"), array[0]), Expression.Default(invoke.GetReturnType())), new TrueReadOnlyCollection<ParameterExpression>(array)).Compile();
304 }
305
307 {
309 {
310 return arg;
311 }
312 return Expression.Convert(arg, type);
313 }
314}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static void Requires([DoesNotReturnIf(false)] bool precondition, string paramName)
static void RequiresNotNull(object value, string paramName)
static bool AreReferenceAssignable(Type dest, Type src)
Definition TypeUtils.cs:673
static Exception TypeMustBeDerivedFromSystemDelegate()
Definition Error.cs:123
static ConstantExpression Constant(object? value)
static BlockExpression Block(Expression arg0, Expression arg1)
static DefaultExpression Default(Type type)
static BinaryExpression NotEqual(Expression left, Expression right)
static LambdaExpression Lambda(Expression body, params ParameterExpression[]? parameters)
static UnaryExpression ArrayLength(Expression array)
static GotoExpression Return(LabelTarget target)
static MethodCallExpression Call(MethodInfo method)
static BinaryExpression Assign(Expression left, Expression right)
static ParameterExpression Parameter(Type type)
static UnaryExpression PreIncrementAssign(Expression expression)
static GotoExpression Break(LabelTarget target)
static IndexExpression Property(Expression instance, string propertyName, params Expression[]? arguments)
static LabelExpression Label(LabelTarget target)
static ConditionalExpression IfThen(Expression test, Expression ifTrue)
static LoopExpression Loop(Expression body)
static UnaryExpression Convert(Expression expression, Type type)
static MemberExpression Field(Expression? expression, FieldInfo field)
static NewArrayExpression NewArrayInit(Type type, params Expression[] initializers)
static BinaryExpression Equal(Expression left, Expression right)
static TryExpression TryFinally(Expression body, Expression? @finally)
static IndexExpression ArrayAccess(Expression array, params Expression[]? indexes)
static ParameterExpression Variable(Type type)
static InvocationExpression Invoke(Expression expression)
static ConstantExpression Constant(bool value)
Definition Utils.cs:64
static bool IsSimpleSignature(MethodInfo invoke, out Type[] sig)
Definition CallSite.cs:208
static CallSite< T > Create(CallSiteBinder binder)
Definition CallSite.cs:114
readonly CallSiteBinder _binder
Definition CallSite.cs:16
static CallSite Create(Type delegateType, CallSiteBinder binder)
Definition CallSite.cs:27
CallSite(CallSiteBinder binder)
Definition CallSite.cs:22
static volatile CacheDict< Type, Func< CallSiteBinder, CallSite > > s_siteCtors
Definition CallSite.cs:14
T CreateCustomNoMatchDelegate(MethodInfo invoke)
Definition CallSite.cs:300
T CreateCustomUpdateDelegate(MethodInfo invoke)
Definition CallSite.cs:232
void ReleaseMatchmaker(CallSite matchMaker)
Definition CallSite.cs:106
static Expression Convert(Expression arg, Type type)
Definition CallSite.cs:306
static int Exchange(ref int location1, int value)