~ubuntu-branches/ubuntu/trusty/smuxi/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/db4o-net/Db4objects.Db4o.Instrumentation/native/Db4objects.Db4o.Instrumentation/Cecil/CecilMethodBuilder.cs

  • Committer: Package Import Robot
  • Author(s): Mirco Bauer
  • Date: 2013-05-25 22:11:31 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20130525221131-nd2mc0kzubuwyx20
Tags: 0.8.11-1
* [22d13d5] Imported Upstream version 0.8.11
* [6d2b95a] Refreshed patches
* [89eb66e] Added ServiceStack libraries to smuxi-engine package
* [848ab10] Enable Campfire engine
* [c6dbdc7] Always build db4o for predictable build result
* [13ec489] Exclude OS X specific libraries from dh_clideps

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
using System;
2
 
using System.IO;
3
 
using System.Reflection;
4
 
using Cecil.FlowAnalysis.Utilities;
5
 
using Db4objects.Db4o.Instrumentation.Api;
6
 
using Mono.Cecil;
7
 
using Mono.Cecil.Cil;
8
 
 
9
 
namespace Db4objects.Db4o.Instrumentation.Cecil
10
 
{
11
 
        internal class CecilMethodBuilder : IMethodBuilder
12
 
        {
13
 
                private readonly MethodDefinition _method;
14
 
                private readonly ILProcessor _il;
15
 
 
16
 
                public CecilMethodBuilder(MethodDefinition method)
17
 
                {
18
 
                        _method = method;
19
 
                        _il = method.Body.GetILProcessor();
20
 
                }
21
 
 
22
 
                public IReferenceProvider References
23
 
                {
24
 
                        get { return CecilReferenceProvider.ForModule(_method.DeclaringType.Module.Assembly.MainModule); }
25
 
                }
26
 
 
27
 
                public void Ldc(object value)
28
 
                {
29
 
                        Type type = value.GetType();
30
 
                        TypeCode code = Type.GetTypeCode(type);
31
 
                        switch (code)
32
 
                        {
33
 
                                case TypeCode.SByte:
34
 
                                        _il.Emit(OpCodes.Ldc_I4_S, (SByte)value);
35
 
                                        break;
36
 
                                case TypeCode.Int32:
37
 
                                        _il.Emit(OpCodes.Ldc_I4, (Int32)value);
38
 
                                        break;
39
 
                                case TypeCode.Int64:
40
 
                                        _il.Emit(OpCodes.Ldc_I8, (Int64)value);
41
 
                                        break;
42
 
                                case TypeCode.String:
43
 
                                        _il.Emit(OpCodes.Ldstr, (String)value);
44
 
                                        break;
45
 
                                default:
46
 
                                        throw new NotImplementedException(code.ToString());
47
 
                        }
48
 
                }
49
 
 
50
 
                public void LoadArgument(int index)
51
 
                {
52
 
                        switch (index)
53
 
                        {
54
 
                                case 0:
55
 
                                        _il.Emit(OpCodes.Ldarg_0);
56
 
                                        break;
57
 
                                case 1:
58
 
                                        _il.Emit(OpCodes.Ldarg_1);
59
 
                                        break;
60
 
                                default:
61
 
                                        // TODO: This is wrong. Emit expects an VariableDefinition for a Ldarg .
62
 
                    //       But actually no code passes idexes other than 0 and 1 
63
 
                    _il.Emit(OpCodes.Ldarg, index);
64
 
                                        break;
65
 
                        }
66
 
                }
67
 
 
68
 
                public void Pop()
69
 
                {
70
 
                        _il.Emit(OpCodes.Pop);
71
 
                }
72
 
 
73
 
                public void LoadArrayElement(ITypeRef elementType)
74
 
                {
75
 
                        throw new NotImplementedException();
76
 
                }
77
 
 
78
 
                public void Add(ITypeRef operandType)
79
 
                {
80
 
                        throw new NotImplementedException();
81
 
                }
82
 
 
83
 
                public void Subtract(ITypeRef operandType)
84
 
                {
85
 
                        throw new NotImplementedException();
86
 
                }
87
 
 
88
 
                public void Multiply(ITypeRef operandType)
89
 
                {
90
 
                        throw new NotImplementedException();
91
 
                }
92
 
 
93
 
                public void Divide(ITypeRef operandType)
94
 
                {
95
 
                        throw new NotImplementedException();
96
 
                }
97
 
 
98
 
                public void Invoke(IMethodRef method, CallingConvention convention)
99
 
                {
100
 
                        _il.Emit(OpCodeForConvention(convention), CecilMethodRef.GetReference(method));
101
 
                }
102
 
 
103
 
                private static OpCode OpCodeForConvention(CallingConvention convention)
104
 
                {
105
 
                        return convention == CallingConvention.Static
106
 
                                ? OpCodes.Call
107
 
                                : OpCodes.Callvirt;
108
 
                }
109
 
 
110
 
                public void Invoke(MethodInfo method)
111
 
                {
112
 
                        throw new NotImplementedException();
113
 
                }
114
 
 
115
 
                public void LoadField(IFieldRef fieldRef)
116
 
                {
117
 
                        _il.Emit(OpCodes.Ldfld, GetReference(fieldRef));
118
 
                }
119
 
 
120
 
                private static FieldReference GetReference(IFieldRef fieldRef)
121
 
                {
122
 
                        return CecilFieldRef.GetReference(fieldRef);
123
 
                }
124
 
 
125
 
                public void LoadStaticField(IFieldRef fieldRef)
126
 
                {
127
 
                        _il.Emit(OpCodes.Ldsfld, GetReference(fieldRef));
128
 
                }
129
 
 
130
 
                public void Box(ITypeRef boxedType)
131
 
                {
132
 
                        TypeReference type = CecilTypeRef.GetReference(boxedType);
133
 
                        if (!type.IsValueType) return;
134
 
                        _il.Emit(OpCodes.Box, type);
135
 
                }
136
 
 
137
 
                public void EndMethod()
138
 
                {
139
 
                        _il.Emit(OpCodes.Ret);
140
 
                }
141
 
 
142
 
                public void Print(TextWriter @out)
143
 
                {
144
 
                        Formatter.WriteMethodBody(@out, _method);
145
 
                }
146
 
        }
147
 
}
 
 
b'\\ No newline at end of file'