Ejemplo n.º 1
0
        static QualifiedIdentifier ParseTypeName(string line, int start, int i, out string label)
        {
            string fullName = line.Substring(start, i - start).Trim();
            int    dot      = fullName.LastIndexOf('.');

            if (dot > 0)
            {
                label = fullName.Substring(dot + 1);
            }
            else
            {
                label = fullName;
            }
            return(QualifiedIdentifier.GetPartial(typeName, fullName));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse SOS GCRoot output in the format and return valid QualifiedIdentifier
        /// "// 179763ec(MS.Utility.SingleItemList`1[[System.Windows.RoutedEventHandlerInfo, PresentationCore]])->"
        /// </summary>
        static QualifiedIdentifier ParseLine(string line, out string label)
        {
            QualifiedIdentifier address = null;
            QualifiedIdentifier name    = null;

            label = null;
            int start = 0;

            for (int i = 0, n = line.Length; i < n; i++)
            {
                char c = line[i];
                if (c == '(')
                {
                    address = QualifiedIdentifier.GetPartial(addressName, line.Substring(0, i));
                    start   = i + 1;
                }
                else if (c == '[')
                {
                    if (i > start)
                    {
                        name = ParseTypeName(line, start, i, out label);
                    }
                    // array or generics parameters
                    QualifiedIdentifier parameters = ParseParameters(line, ref i, false);
                    name  = QualifiedIdentifier.GetNested(name, parameters);
                    start = i;
                }
                else if (c == ')')
                {
                    if (i > start)
                    {
                        if (name != null)
                        {
                            Console.WriteLine("ERROR");
                        }
                        name = ParseTypeName(line, start, i, out label);
                    }
                    // end
                    break;
                }
            }
            if (address == null)
            {
                return(null);
            }
            return(QualifiedIdentifier.GetNested(address, name));
        }
Ejemplo n.º 3
0
        static QualifiedIdentifier ParseParameters(string line, ref int i, bool nested)
        {
            List <QualifiedIdentifier> result = new List <QualifiedIdentifier>();
            int dimensions = 0;

            for (int n = line.Length; i < n; i++)
            {
                char c = line[i];
                if (c == '[' && i + 1 < n && line[i + 1] != ']')
                {
                    int start = i + 1;
                    if (line[start] == '[')// expected
                    {
                        start++;
                    }
                    QualifiedIdentifier type     = null;
                    QualifiedIdentifier assembly = null;
                    // then we have a type name
                    for (int j = start; j < n; j++)
                    {
                        c = line[j];
                        if (c == ',')
                        {
                            type  = QualifiedIdentifier.GetPartial(typeName, line.Substring(start, j - start).Trim());
                            start = j + 1;
                        }
                        else if (c == ']')
                        {
                            assembly = QualifiedIdentifier.GetPartial(assemblyName, line.Substring(start, j - start).Trim());
                            i        = j + 1;
                            break;
                        }
                        else if (c == '[')
                        {
                            type = QualifiedIdentifier.GetPartial(typeName, line.Substring(start, j - start).Trim());
                            QualifiedIdentifier inner = ParseParameters(line, ref j, true);
                            type  = QualifiedIdentifier.GetNested(type, inner);
                            start = j;
                        }
                    }

                    result.Add(QualifiedIdentifier.GetNested(type, assembly));
                }
                else if (c == ',')
                {
                    if (nested)
                    {
                        i++;
                        break;
                    }
                    // skip, we have another type coming.
                    dimensions++;
                }
                else if (c == ']')
                {
                    // then it was an empty array []
                    i++;
                    break; // done!
                }
            }
            if (result.Count == 0)
            {
                result.Add(QualifiedIdentifier.GetArray(arrayName, dimensions));
            }

            if (result.Count == 1)
            {
                return(result[0]);
            }
            return(QualifiedIdentifier.GetNested(result.ToArray()));
        }