Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Mono.Cecil.Cil/MethodBody.cs')
-rw-r--r--Mono.Cecil.Cil/MethodBody.cs44
1 files changed, 19 insertions, 25 deletions
diff --git a/Mono.Cecil.Cil/MethodBody.cs b/Mono.Cecil.Cil/MethodBody.cs
index e74866b..31767dd 100644
--- a/Mono.Cecil.Cil/MethodBody.cs
+++ b/Mono.Cecil.Cil/MethodBody.cs
@@ -1,32 +1,15 @@
//
-// MethodBody.cs
-//
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2011 Jb Evain
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
+// Copyright (c) 2008 - 2015 Jb Evain
+// Copyright (c) 2008 - 2011 Novell, Inc.
//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+// Licensed under the MIT/X11 license.
//
using System;
+using System.Threading;
using Mono.Collections.Generic;
@@ -100,15 +83,26 @@ namespace Mono.Cecil.Cil {
if (method == null || method.DeclaringType == null)
throw new NotSupportedException ();
- if (this_parameter == null) {
- this_parameter = new ParameterDefinition (method.DeclaringType);
- this_parameter.method = method;
- }
+ if (!method.HasThis)
+ return null;
+
+ if (this_parameter == null)
+ Interlocked.CompareExchange (ref this_parameter, CreateThisParameter (method), null);
return this_parameter;
}
}
+ static ParameterDefinition CreateThisParameter (MethodDefinition method)
+ {
+ var declaring_type = method.DeclaringType;
+ var type = declaring_type.IsValueType || declaring_type.IsPrimitive
+ ? new PointerType (declaring_type)
+ : declaring_type as TypeReference;
+
+ return new ParameterDefinition (type, method);
+ }
+
public MethodBody (MethodDefinition method)
{
this.method = method;