Exemplo n.º 1
0
 /// <summary>
 /// Adds a new VTable.
 /// </summary>
 /// <param name="table">The table.</param>
 public void AddVTable(VTable table)
 {
     mVTableLookup.Add(table.Type, table);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the parent VTable.
        /// </summary>
        /// <param name="parentType">The parent type.</param>
        private void createParentTable(TypeDefinition parentType)
        {
            VTable parentTable = mLookup.GetVTable(parentType);

            // Match method signatures against own.
            Dictionary <int, MethodDefinition> own = new Dictionary <int, MethodDefinition>();

            foreach (MethodDefinition method in parentType.Methods)
            {
                if (!shouldAddMethod(method))
                {
                    continue;
                }

                string shortName  = NameHelper.CreateShortMethodName(method);
                string parentName = shortName;

                mLookup.SetMethodNotUnique(method);

                // It could have an explicit override...
                // But that's only possible with interfaces.
                if (parentType.IsInterface)
                {
                    string explicitName = string.Format("{0}_{1}", NameHelper.CreateTypeName(parentType), shortName);
                    if (MyNameTable.ContainsKey(explicitName))
                    {
                        shortName = explicitName;
                    }
                }

                // This type overrides the method in the parent type.
                if (MyNameTable.ContainsKey(shortName) && MyTable[MyNameTable[shortName]].IsVirtual)
                {
                    int nameTableIndex = MyNameTable[shortName];
                    own.Add(parentTable.MyNameTable[parentName], MyTable[nameTableIndex]);
                }
                // Use parent method definition.
                else
                {
                    int nameTableIndex = parentTable.MyNameTable[shortName];
                    own.Add(nameTableIndex, method);
                }
            }

            mTable.Add(parentType, own);

            // Generate name table.
            Dictionary <string, int> nameTable = new Dictionary <string, int>();

            foreach (KeyValuePair <int, MethodDefinition> pair in own)
            {
                nameTable.Add(NameHelper.CreateShortMethodName(pair.Value), pair.Key);
            }
            mNameTable.Add(parentType, nameTable);

            // Add other tables that are inside the parent table.
            foreach (KeyValuePair <TypeDefinition, Dictionary <string, int> > pair in parentTable.mNameTable)
            {
                // Skip parent type itself.
                if (pair.Key == parentType)
                {
                    continue;
                }

                // Create own copies of this table.
                Dictionary <int, MethodDefinition> tableCopy = new Dictionary <int, MethodDefinition>();
                mTable.Add(pair.Key, tableCopy);
                mNameTable.Add(pair.Key, pair.Value);

                // Create own copy of table with possible modifications.
                Dictionary <int, MethodDefinition> parentLookupTable = parentTable.mTable[pair.Key];
                foreach (KeyValuePair <string, int> methodPair in pair.Value)
                {
                    string shortName = methodPair.Key;

                    // Did we override this method?
                    if (MyNameTable.ContainsKey(shortName) && (MyTable[MyNameTable[shortName]].IsVirtual))
                    {
                        int nameTableIndex      = MyNameTable[shortName];
                        MethodDefinition method = MyTable[nameTableIndex];
                        mLookup.SetMethodNotUnique(method);
                        tableCopy.Add(methodPair.Value, MyTable[nameTableIndex]);
                    }
                    // Use existing method definition.
                    else
                    {
                        tableCopy.Add(methodPair.Value, parentLookupTable[methodPair.Value]);
                    }
                }
            }
        }