Пример #1
0
        static GacMethod TryPickFunction(GacUDT udt, GacMethod[] methods, string methodLocalName, string methodParameters)
        {
            var candidates1 = methods.Where(m => m.Name == udt.Name + "::" + methodLocalName).ToArray();
            var candidates2 = methods.Where(m => m.Name == methodLocalName).ToArray();
            var m1          = TryPickFunction(candidates1, methodParameters);
            var m2          = TryPickFunction(candidates2, methodParameters);

            return(m1 ?? m2);
        }
Пример #2
0
        static GacField PickField(GacUDT udt, string fieldLocalName)
        {
            var fields =
                udt.Constants.Concat(udt.Fields).Concat(udt.StaticFields)
                .Where(f => f.Name == fieldLocalName)
                .ToArray();

            if (fields.Length != 1)
            {
                throw new ArgumentException();
            }
            return(fields[0]);
        }
Пример #3
0
        static GacMethod PickFunction(GacUDT udt, string methodLocalName, string methodParameters)
        {
            if (methodLocalName == "#ctor")
            {
                CppName cppName = CppName.Parse(udt.Name);
                methodLocalName = cppName.Cascade().Last().Name;
            }
            var m1 = TryPickFunction(udt, udt.Methods, methodLocalName, methodParameters);
            var m2 = TryPickFunction(udt, udt.StaticMethods, methodLocalName, methodParameters);

            if ((m1 == null) ^ (m2 == null) != true)
            {
                throw new ArgumentException();
            }
            return(m1 ?? m2);
        }
Пример #4
0
        public static Dictionary <string, GacUDT> LoadTypes(XDocument document)
        {
            Dictionary <string, GacUDT> udts = new Dictionary <string, GacUDT>();

            foreach (var udtElement in document.Root.Elements().Where(e => e.Name != "functions"))
            {
                GacUDT udt = new GacUDT();
                udt.Name = udtElement.Attribute("name").Value;
                switch (udtElement.Name.LocalName)
                {
                case "class":
                    udt.Kind = GacUDTKind.Class;
                    break;

                case "enum":
                    udt.Kind = GacUDTKind.Enum;
                    break;
                }
                udts.Add(udt.Name, udt);
            }
            foreach (var udtElement in document.Root.Elements().Where(e => e.Name != "functions"))
            {
                FillUdt(udts, udts[udtElement.Attribute("name").Value], udtElement);
            }
            foreach (var udt in udts.Values)
            {
                List <GacBaseClass> newBaseClasses  = new List <GacBaseClass>();
                HashSet <GacUDT>    baseBaseClasses = new HashSet <GacUDT>(udt.BaseClasses.SelectMany(b => GetBaseClasses(b.UDT)));
                foreach (var baseUdt in udt.BaseClasses)
                {
                    if (!baseBaseClasses.Contains(baseUdt.UDT))
                    {
                        newBaseClasses.Add(baseUdt);
                    }
                }
                udt.BaseClasses = newBaseClasses.ToArray();
            }
            return(udts);
        }
Пример #5
0
        public DocType GetType(GacUDT udt, Dictionary <string, GacUDT> udts)
        {
            DocType resultType = null;

            if (!this.typeCache.TryGetValue(udt, out resultType))
            {
                CppName cppName      = CppName.Parse(udt.Name);
                var     cascadeNames = cppName
                                       .Cascade()
                                       .Select(c => new CppName()
                {
                    Name       = c.Name,
                    Parameters = c.Parameters,
                }.ToPdbString())
                                       .ToArray();

                string currentName    = "";
                int    namespaceCount = 0;
                for (int i = 0; i < cascadeNames.Length; i++)
                {
                    currentName += (i == 0 ? "" : "::") + cascadeNames[i];
                    if (udts.ContainsKey(currentName))
                    {
                        break;
                    }
                    namespaceCount = i + 1;
                }

                DocItemContainer ic = GetNamespace(cascadeNames.Take(namespaceCount));
                for (int i = namespaceCount; i < cascadeNames.Length; i++)
                {
                    ic = ic.GetType(cascadeNames[i]);
                }
                resultType     = (DocType)ic;
                resultType.Udt = udt;
                this.typeCache.Add(udt, resultType);
            }
            return(resultType);
        }
Пример #6
0
 static void FillUdt(Dictionary <string, GacUDT> udts, GacUDT udt, XElement udtElement)
 {
     udt.BaseClasses = udtElement.Element("baseClasses") == null ? new GacBaseClass[0] : udtElement
                       .Element("baseClasses")
                       .Elements("baseClass")
                       .Select(e => new GacBaseClass
     {
         Access = TranslateAccess(e.Attribute("access").Value),
         UDT    = udts[e.Attribute("name").Value],
     })
                       .ToArray();
     udt.Fields = udtElement.Element("fields") == null ? new GacField[0] : udtElement
                  .Element("fields")
                  .Elements("field")
                  .Select(e => TranslateField(udts, e, udt))
                  .ToArray();
     udt.StaticFields = udtElement.Element("fields") == null ? new GacField[0] : udtElement
                        .Element("fields")
                        .Elements("staticField")
                        .Select(e => TranslateField(udts, e, udt))
                        .ToArray();
     udt.Constants = udtElement.Element("fields") == null ? new GacConst[0] : udtElement
                     .Element("fields")
                     .Elements("const")
                     .Select(e => TranslateEnumField(udts, e, udt))
                     .ToArray();
     udt.Methods = udtElement.Element("methods") == null ? new GacMethod[0] : udtElement
                   .Element("methods")
                   .Elements("method")
                   .Select(e => TranslateMethod(udts, e, udt))
                   .ToArray();
     udt.StaticMethods = udtElement.Element("methods") == null ? new GacMethod[0] : udtElement
                         .Element("methods")
                         .Elements("staticMethod")
                         .Select(e => TranslateMethod(udts, e, udt))
                         .ToArray();
     udt.IsAbstract = udt.Methods.Any(m => m.Kind == GacMethodKind.Abstract);
 }
Пример #7
0
 static GacUDT[] GetBaseClasses(GacUDT udt)
 {
     return(udt.BaseClasses.Select(b => b.UDT).Concat(udt.BaseClasses.SelectMany(b => GetBaseClasses(b.UDT))).ToArray());
 }
Пример #8
0
 static GacMethod TranslateMethod(Dictionary <string, GacUDT> udts, XElement methodElement, GacUDT ownerUDT)
 {
     return(new GacMethod
     {
         Name = methodElement.Attribute("name").Value,
         Kind = TranslateVirtual(methodElement.Attribute("virtual").Value),
         Access = TranslateAccess(methodElement.Attribute("access").Value),
         Type = TranslateType(udts, methodElement.Element("type").Elements().First()),
         ParameterNames = methodElement.Element("arguments").Elements("argument").Select(e => e.Attribute("name").Value).ToArray(),
         OwnerUDT = ownerUDT,
     });
 }
Пример #9
0
        static GacConst TranslateEnumField(Dictionary <string, GacUDT> udts, XElement fieldElement, GacUDT ownerUDT)
        {
            GacField field = TranslateField(udts, fieldElement, ownerUDT);

            return(new GacConst
            {
                Name = field.Name,
                Access = field.Access,
                Type = field.Type,
                OwnerUDT = field.OwnerUDT,
                EnumItemValue = int.Parse(fieldElement.Element("intValue").Attribute("value").Value),
            });
        }
Пример #10
0
 static GacField TranslateField(Dictionary <string, GacUDT> udts, XElement fieldElement, GacUDT ownerUDT)
 {
     return(new GacField
     {
         Name = fieldElement.Attribute("name").Value,
         Access = TranslateAccess(fieldElement.Attribute("access").Value),
         Type = TranslateType(udts, fieldElement.Element("type").Elements().First()),
         OwnerUDT = ownerUDT,
     });
 }
Пример #11
0
        public static GacSymbol FindSymbol(XElement docItem, Dictionary <string, GacUDT> udts, Dictionary <string, GacMethod[]> funcs)
        {
            string name = docItem.Attribute("name").Value;
            string head = name.Substring(0, 2);

            name = name.Substring(2);
            switch (head)
            {
            case "T:":
            {
                string className = ConvertDocNameToCppName(name);
                return(udts[className]);
            }

            case "F:":
            {
                string typeName       = "";
                string fieldLocalName = "";
                {
                    int pointIndex = name.LastIndexOf('.');
                    typeName       = ConvertDocNameToCppName(name.Substring(0, pointIndex));
                    fieldLocalName = name.Substring(pointIndex + 1);
                }

                GacUDT udt = udts[typeName];
                return(PickField(udt, fieldLocalName));
            }

            case "M:":
            {
                string methodName       = name;
                string methodParameters = "";
                {
                    int bracketIndex = methodName.IndexOf('(');
                    if (bracketIndex != -1)
                    {
                        methodName       = name.Substring(0, bracketIndex);
                        methodParameters = name.Substring(bracketIndex);
                    }
                }

                string containerName   = "";
                string methodLocalName = methodName;
                {
                    int pointIndex = methodName.LastIndexOf('.');
                    if (pointIndex != -1)
                    {
                        containerName   = methodName.Substring(0, pointIndex);
                        methodLocalName = methodName.Substring(pointIndex + 1);
                    }
                }

                if (containerName != "")
                {
                    string className = ConvertDocNameToCppName(containerName);
                    GacUDT udt       = null;
                    if (udts.TryGetValue(className, out udt))
                    {
                        return(PickFunction(udt, methodLocalName, methodParameters));
                    }
                }
                string methodFullName = ConvertDocNameToCppName(methodName);
                return(PickFunction(funcs[methodFullName], methodParameters));
            }

            default:
                throw new ArgumentException();
            }
        }