Exemplo n.º 1
0
        bool IsSubclassOf(TargetMemoryAccess target, TargetClassType type,
                          TargetType parent)
        {
            while (type != null)
            {
                if (type == parent)
                {
                    return(true);
                }

                if (!type.HasParent)
                {
                    return(false);
                }

                type = type.GetParentType(target);
            }

            return(false);
        }
Exemplo n.º 2
0
        protected string FormatType(Thread target, string prefix,
                                    TargetType type, Hashtable hash)
        {
            string retval;

            if (hash == null)
            {
                hash = new Hashtable();
            }

            if (hash.Contains(type))
            {
                return(type.Name);
            }
            else
            {
                hash.Add(type, true);
            }

            switch (type.Kind)
            {
            case TargetObjectKind.Array: {
                TargetArrayType atype = (TargetArrayType)type;
                retval = atype.Name;
                break;
            }

            case TargetObjectKind.Enum: {
                StringBuilder  sb    = new StringBuilder();
                TargetEnumType etype = type as TargetEnumType;
                sb.Append("enum ");

                if (etype.Name != null)
                {
                    sb.Append(etype.Name);
                }

                sb.Append("\n" + prefix + "{\n");

                foreach (TargetEnumInfo field in etype.Members)
                {
                    sb.Append(FormatEnumMember(target, prefix, field, false, hash));
                    if (field != etype.Members[etype.Members.Length - 1])
                    {
                        sb.Append(",");
                    }
                    sb.Append("\n");
                }


                sb.Append(prefix + "}");

                retval = sb.ToString();
                break;
            }

            case TargetObjectKind.Class:
            case TargetObjectKind.Struct: {
                StringBuilder   sb    = new StringBuilder();
                TargetClassType ctype = (TargetClassType)type;
                if (type.Kind == TargetObjectKind.Struct)
                {
                    sb.Append("struct ");
                }
                else
                {
                    sb.Append("class ");
                }
                if (ctype.Name != null)
                {
                    sb.Append(ctype.Name);
                    sb.Append(" ");
                }
                if (ctype.HasParent)
                {
                    TargetClassType parent = ctype.GetParentType(target);
                    sb.Append(": ");
                    sb.Append(parent.Name);
                }

                sb.Append("\n" + prefix + "{\n");
                sb.Append(FormatStruct(prefix, ctype, hash));
                sb.Append(prefix + "}");

                retval = sb.ToString();
                break;
            }

            case TargetObjectKind.Alias: {
                TargetTypeAlias alias = (TargetTypeAlias)type;
                string          name;
                if (alias.TargetType != null)
                {
                    name = FormatType(target, prefix, alias.TargetType, hash);
                }
                else
                {
                    name = "<unknown type>";
                }
                retval = String.Format("typedef {0} = {1}", alias.Name, name);
                break;
            }

            case TargetObjectKind.GenericInstance: {
                TargetGenericInstanceType gtype = (TargetGenericInstanceType)type;

                StringBuilder sb = new StringBuilder();
                if (gtype.ContainerType.Kind == TargetObjectKind.Struct)
                {
                    sb.Append("struct ");
                }
                else
                {
                    sb.Append("class ");
                }

                sb.Append(String.Format("{0} = ", gtype.Name));

                TargetClassType parent = gtype.ContainerType.GetParentType(target);
                sb.Append(String.Format("{0}", gtype.ContainerType.Name));
                if (parent != null)
                {
                    sb.Append(String.Format(" : {0}", parent.Name));
                }

                sb.Append("\n" + prefix + "{\n");
                sb.Append(FormatStruct(prefix, gtype.ContainerType, hash));
                sb.Append(prefix + "}");

                retval = sb.ToString();
                break;
            }

            default:
                retval = type.Name;
                break;
            }

            hash.Remove(type);
            return(retval);
        }