IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
LocalSymInfo.cs
Go to the documentation of this file.
1using System;
2using System.Diagnostics.SymbolStore;
3
5{
6
7 internal sealed class LocalSymInfo
8 {
9
10 // This class tracks the local variable's debugging information
11 // and namespace information with a given active lexical scope.
12
13 #region Internal Data Members
14 internal string[] m_strName = null!; // All these arrys initialized in helper method
15 internal byte[][] m_ubSignature = null!;
16 internal int[] m_iLocalSlot = null!;
17 internal int[] m_iStartOffset = null!;
18 internal int[] m_iEndOffset = null!;
19 internal int m_iLocalSymCount; // how many entries in the arrays are occupied
20 internal string[] m_namespace = null!;
21 internal int m_iNameSpaceCount;
22 internal const int InitialSize = 16;
23 #endregion
24
25 #region Constructor
26 internal LocalSymInfo()
27 {
28 // initialize data variables
29 m_iLocalSymCount = 0;
30 m_iNameSpaceCount = 0;
31 }
32 #endregion
33
34 #region Private Members
35 private void EnsureCapacityNamespace()
36 {
37 if (m_iNameSpaceCount == 0)
38 {
39 m_namespace = new string[InitialSize];
40 }
41 else if (m_iNameSpaceCount == m_namespace.Length)
42 {
43 string[] strTemp = new string[checked(m_iNameSpaceCount * 2)];
44 Array.Copy(m_namespace, strTemp, m_iNameSpaceCount);
45 m_namespace = strTemp;
46 }
47 }
48
49 private void EnsureCapacity()
50 {
51 if (m_iLocalSymCount == 0)
52 {
53 // First time. Allocate the arrays.
54 m_strName = new string[InitialSize];
55 m_ubSignature = new byte[InitialSize][];
56 m_iLocalSlot = new int[InitialSize];
57 m_iStartOffset = new int[InitialSize];
58 m_iEndOffset = new int[InitialSize];
59 }
60 else if (m_iLocalSymCount == m_strName.Length)
61 {
62 // the arrays are full. Enlarge the arrays
63 // why aren't we just using lists here?
64 int newSize = checked(m_iLocalSymCount * 2);
65 int[] temp = new int[newSize];
66 Array.Copy(m_iLocalSlot, temp, m_iLocalSymCount);
67 m_iLocalSlot = temp;
68
69 temp = new int[newSize];
70 Array.Copy(m_iStartOffset, temp, m_iLocalSymCount);
71 m_iStartOffset = temp;
72
73 temp = new int[newSize];
74 Array.Copy(m_iEndOffset, temp, m_iLocalSymCount);
75 m_iEndOffset = temp;
76
77 string[] strTemp = new string[newSize];
78 Array.Copy(m_strName, strTemp, m_iLocalSymCount);
79 m_strName = strTemp;
80
81 byte[][] ubTemp = new byte[newSize][];
82 Array.Copy(m_ubSignature, ubTemp, m_iLocalSymCount);
83 m_ubSignature = ubTemp;
84 }
85 }
86
87 #endregion
88
89 #region Internal Members
90 internal void AddLocalSymInfo(string strName, byte[] signature, int slot, int startOffset, int endOffset)
91 {
92 // make sure that arrays are large enough to hold addition info
93 EnsureCapacity();
94 m_iStartOffset[m_iLocalSymCount] = startOffset;
95 m_iEndOffset[m_iLocalSymCount] = endOffset;
96 m_iLocalSlot[m_iLocalSymCount] = slot;
97 m_strName[m_iLocalSymCount] = strName;
98 m_ubSignature[m_iLocalSymCount] = signature;
99 checked { m_iLocalSymCount++; }
100 }
101
102 internal void AddUsingNamespace(string strNamespace)
103 {
104 EnsureCapacityNamespace();
105 m_namespace[m_iNameSpaceCount] = strNamespace;
106 checked { m_iNameSpaceCount++; }
107 }
108 internal void EmitLocalSymInfo(ISymbolWriter symWriter)
109 {
110 int i;
111
112 for (i = 0; i < m_iLocalSymCount; i++)
113 {
114 symWriter.DefineLocalVariable(
115 m_strName[i],
116 System.Reflection.FieldAttributes.PrivateScope,
117 m_ubSignature[i],
118 SymAddressKind.ILOffset,
119 m_iLocalSlot[i],
120 0, // addr2 is not used yet
121 0, // addr3 is not used
122 m_iStartOffset[i],
123 m_iEndOffset[i]);
124 }
125 for (i = 0; i < m_iNameSpaceCount; i++)
126 {
127 symWriter.UsingNamespace(m_namespace[i]);
128 }
129 }
130
131 #endregion
132
133 }
134
135}