private static CppName ParseCppName(string name, ref int index) { CppName result = new CppName(); result.Name = ParseName(name, ref index); result.Parameters = new CppName[0]; if (ParseChar(name, '<', ref index)) { List <CppName> parameters = new List <CppName>(); while (true) { parameters.Add(ParseCppName(name, ref index)); if (ParseChar(name, '>', ref index)) { break; } else if (!ParseChar(name, ',', ref index)) { throw new ArgumentException(); } } result.Parameters = parameters.ToArray(); } if (ParseChar(name, ':', ref index)) { if (!ParseChar(name, ':', ref index)) { throw new ArgumentException(); } result.Member = ParseCppName(name, ref index); } return(result); }
public static CppName Parse(string name) { int index = 0; CppName result = ParseCppName(name.Trim(), ref index); if (index != name.Length) { throw new ArgumentException(); } return(result); }
public IEnumerable <CppName> Cascade() { CppName current = this; while (current != null) { yield return(current); current = current.Member; } }
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); }
static DocRootNamespace Categorize(Dictionary <GacUDT, DocTypeInfo> typeGroupedItems, Tuple <XElement, GacMethod>[] gfuncItems, Dictionary <string, GacUDT> udts) { HashSet <GacUDT> hashUdts = new HashSet <GacUDT>(typeGroupedItems.Keys); DocRootNamespace root = new DocRootNamespace(); foreach (var p in typeGroupedItems) { DocType type = root.GetType(p.Key, udts); FillType(type, p, root, udts, hashUdts); } foreach (var m in gfuncItems) { CppName[] names = CppName.Parse(m.Item2.Name).Cascade().ToArray(); string[] nsNames = names.Take(names.Length - 1).Select(n => n.Name).ToArray(); var ns = root.GetNamespace(nsNames); BuildFunction(ns, m); } return(root); }
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); }
static void FillField(DocField docField, Tuple <XElement, GacField> field) { docField.Name = CppName.Parse(field.Item2.Name).Cascade().Last().Name; docField.Field = field.Item2; docField.FieldDocItem = field.Item1; }
static void FillFunction(DocFunction docFunction, Tuple <XElement, GacMethod> method) { docFunction.Name = CppName.Parse(method.Item2.Name).Cascade().Last().Name; docFunction.Method = method.Item2; docFunction.MethodDocItem = method.Item1; }