Exemplo n.º 1
0
        /// <summary>
        /// Processes the specified type.
        /// </summary>
        /// <param name="theType">The type to process.</param>
        /// <returns>The debug database type info created during processing.</returns>
        private DB_Type ProcessType(Type theType, bool partialprocess = false)
        {
            if (theType.IsValueType || theType.IsPointer)
            {
                partialprocess = false;
            }

            //TODO - How are we handling interfaces?

            if (!AllTypes.Contains(theType))
            {
                AllTypes.Add(theType);
            }

            if (!ProcessedTypes.Contains(theType))
            {
                if (ProcessingTypes.Count == 0)
                {
                    //We must start processing of types from the bottom of a type inheritance chain 
                    //  otherwise we end up in a dependency loop!
                    List<Type> childTypes = (from types in AllTypes
                                             where (types.IsSubclassOf(theType))
                                             select types).ToList();
                    if (childTypes.Count > 0)
                    {
                        for (int i = 0; i < childTypes.Count; i++)
                        {
                            ProcessType(childTypes[i]);
                        }
                    }
                }

                if (!ProcessedTypes.Contains(theType))
                {
                    try
                    {
                        ProcessingTypes.Add(theType);
                        if (!partialprocess)
                        {
                            ProcessedTypes.Add(theType);
                        }
                        
                        string TypeId = TheScannerState.GetTypeID(theType);

                        DB_Type TheDBType = DebugDatabase.GetType(TypeId);
                        if (TheDBType == null)
                        {
                            TheDBType = new DB_Type();
                            TheDBType.Id = TypeId;
                            TheDBType.Signature = theType.FullName;
                            TheDBType.StackBytesSize = Utils.GetNumBytesForType(theType);
                            TheDBType.IsValueType = theType.IsValueType;
                            TheDBType.IsPointerType = theType.IsPointer;
                            
                            DebugDatabase.AddType(TheDBType);
                            DebugDatabase.SubmitChanges();
                        }

                        if (!partialprocess)
                        {
                            int totalMemSize = 0;
                            int index = 0;
                            List<DB_ComplexTypeLink> complexTypeLinks = new List<DB_ComplexTypeLink>();

                            //Process inherited fields like this so that (start of) the memory structures
                            //  of all types that inherit from this base type are the same i.e. inherited 
                            //  fields appear in at same offset memory for all inheriting types
                            if (theType.BaseType != null)
                            {
                                Type baseType = theType.BaseType;
                                if (!baseType.AssemblyQualifiedName.Contains("mscorlib"))
                                {
                                    DB_Type baseDBType = ProcessType(baseType);
                                    TheDBType.BaseTypeId = baseDBType.Id;
                                    totalMemSize += baseDBType.BytesSize;
                                    foreach (DB_ComplexTypeLink childLink in baseDBType.ChildTypes)
                                    {
                                        DB_ComplexTypeLink DBTypeLink = new DB_ComplexTypeLink();
                                        DBTypeLink.Id = Guid.NewGuid();
                                        DBTypeLink.ParentTypeID = TheDBType.Id;
                                        DBTypeLink.ChildTypeID = childLink.ChildTypeID;
                                        DBTypeLink.ParentIndex = childLink.ParentIndex;
                                        DBTypeLink.FieldId = childLink.FieldId;
                                        complexTypeLinks.Add(DBTypeLink);

                                        index++;
                                    }
                                }
                            }

                            if (!theType.AssemblyQualifiedName.Contains("mscorlib"))
                            {
                                List<FieldInfo> AllFields = theType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).ToList();

                                foreach (FieldInfo anInfo in AllFields)
                                {
                                    //Ignore inherited fields - process inherited fields above
                                    if (anInfo.DeclaringType == theType)
                                    {
                                        DB_Type childDBType = ProcessType(anInfo.FieldType, true);
                                        totalMemSize += childDBType.IsValueType ? childDBType.BytesSize : childDBType.StackBytesSize;

                                        DB_ComplexTypeLink DBTypeLink = new DB_ComplexTypeLink();
                                        DBTypeLink.Id = Guid.NewGuid();
                                        DBTypeLink.ParentTypeID = TheDBType.Id;
                                        DBTypeLink.ChildTypeID = childDBType.Id;
                                        DBTypeLink.ParentIndex = index;
                                        DBTypeLink.FieldId = anInfo.Name;
                                        complexTypeLinks.Add(DBTypeLink);

                                        index++;
                                    }
                                }
                            }

                            if ((theType.IsValueType && totalMemSize == 0) || theType.IsPointer)
                            {
                                totalMemSize = Utils.GetSizeForType(theType);
                            }

                            TheDBType.BytesSize = totalMemSize;

                            foreach (DB_ComplexTypeLink typeLink in complexTypeLinks)
                            {
                                DebugDatabase.AddComplexTypeLink(typeLink);
                            }

                            DebugDatabase.SubmitChanges();

                            TheScannerState.AddType(TheDBType);
                            TheScannerState.AddTypeMethods(theType);
                            TheScannerState.AddTypeFields(theType);

                            if (!theType.AssemblyQualifiedName.Contains("mscorlib"))
                            {
                                ProcessStaticFields(theType);
                            }
                        }

                        TypeClassAttribute typeClassAttr = (TypeClassAttribute)theType.GetCustomAttribute(typeof(TypeClassAttribute));
                        if (typeClassAttr != null)
                        {
                            TheScannerState.TypeClass = theType;
                        }

                        MethodInfoStructAttribute methodInfoStructAttr = (MethodInfoStructAttribute)theType.GetCustomAttribute(typeof(MethodInfoStructAttribute));
                        if (methodInfoStructAttr != null)
                        {
                            TheScannerState.MethodInfoStruct = theType;
                        }

                        FieldInfoStructAttribute fieldInfoStructAttr = (FieldInfoStructAttribute)theType.GetCustomAttribute(typeof(FieldInfoStructAttribute));
                        if (fieldInfoStructAttr != null)
                        {
                            TheScannerState.FieldInfoStruct = theType;
                        }

                        ArrayClassAttribute arrayClassAttr = (ArrayClassAttribute)theType.GetCustomAttribute(typeof(ArrayClassAttribute));
                        if (arrayClassAttr != null)
                        {
                            TheScannerState.ArrayClass = theType;
                        }

                        StringClassAttribute stringClassAttr = (StringClassAttribute)theType.GetCustomAttribute(typeof(StringClassAttribute));
                        if (stringClassAttr != null)
                        {
                            TheScannerState.StringClass = theType;
                        }

                        return TheDBType;
                    }
                    finally
                    {
                        ProcessingTypes.Remove(theType);
                    }

                    return null;
                }
                else
                {
                    return DebugDatabase.GetType(TheScannerState.GetTypeID(theType));
                }
            }
            else
            {
                return DebugDatabase.GetType(TheScannerState.GetTypeID(theType));
            }
        }
Exemplo n.º 2
0
 partial void UpdateDB_ComplexTypeLink(DB_ComplexTypeLink instance);
Exemplo n.º 3
0
 partial void DeleteDB_ComplexTypeLink(DB_ComplexTypeLink instance);
Exemplo n.º 4
0
 partial void InsertDB_ComplexTypeLink(DB_ComplexTypeLink instance);
Exemplo n.º 5
0
		private void detach_DB_ComplexTypeLinks1(DB_ComplexTypeLink entity)
		{
			this.SendPropertyChanging();
			entity.ParentType = null;
		}
Exemplo n.º 6
0
		private void attach_DB_ComplexTypeLinks(DB_ComplexTypeLink entity)
		{
			this.SendPropertyChanging();
			entity.ChildType = this;
		}
Exemplo n.º 7
0
 /// <summary>
 /// Removes the specified complex type link from the database.
 /// <para>To Do's: See <see cref="RemoveMethod"/>'s to do's.</para>
 /// </summary>
 /// <param name="aComplexTypeLink">The entry to remove.</param>
 /// <remarks>
 /// <para>
 /// For the moment this method does no more than just directly remove
 /// the entry from the database.
 /// </para>
 /// <para>
 /// <see cref="SubmitChanges"/> must be called at some point after this
 /// method for changes to actually be submitted to the database.
 /// </para>
 /// </remarks>
 public static void RemoveComplexTypeLink(DB_ComplexTypeLink aComplexTypeLink)
 {
     DB.DB_ComplexTypeLinks.DeleteOnSubmit(aComplexTypeLink);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Adds the pre-created complex type link to the database. All the entries's
 /// required parameters (i.e. ones which cannot be null) should 
 /// be set.
 /// <para>To Do's: See <see cref="AddMethod"/>'s to do's.</para>
 /// </summary>
 /// <param name="aComplexTypeLink">The entry to add.</param>
 /// <remarks>
 /// <para>
 /// For the moment this method does no more than just directly add
 /// the entry to the database.
 /// </para>
 /// <para>
 /// <see cref="SubmitChanges"/> must be called at some point after this
 /// method for changes to actually be submitted to the database.
 /// </para>
 /// </remarks>
 public static void AddComplexTypeLink(DB_ComplexTypeLink aComplexTypeLink)
 {
     DB.DB_ComplexTypeLinks.InsertOnSubmit(aComplexTypeLink);
 }