/// <summary> /// Checks the tree for max overriding depth. /// </summary> /// <param name="root">The root of the tree of the types to check.</param> /// <returns></returns> private Dictionary <string, List <MethodDecl> > CheckTree(TypeDeclWrapper root) { Dictionary <string, List <MethodDecl> > result = new Dictionary <string, List <MethodDecl> >(); foreach (TypeDeclWrapper child in root.Children) { var childResult = CheckTree(child); MergeResults(childResult, result); } foreach (var member in root.TypeDeclaration.Members) { var method = member as MethodDecl; if (method != null) { if (!result.ContainsKey(method.Name.Value)) { result.Add(method.Name.Value, new List <MethodDecl>()); } result[method.Name.Value].Insert(0, method); } } return(result); }
/// <summary> /// Adds a type to the correct place in the inheritance trees. /// </summary> /// <param name="types">The types.</param> /// <param name="inheritanceTrees">The inheritance trees.</param> /// <param name="newType">The new type.</param> private static void AddToInheritanceTrees(IEnumerable <TypeDecl> types, List <TypeDeclWrapper> inheritanceTrees, TypeDecl newType) { var baseClassName = newType.BaseClassName.Value.QualifiedName.Name.Value; TypeDecl baseClass = null; foreach (var type in types) { if (type.Name.Value.Equals(baseClassName, StringComparison.Ordinal)) { baseClass = type; break; } } var message = string.Format(CultureInfo.InvariantCulture, "The base type \"{0}\" for \"{1}\" is not available in the source", baseClassName, newType.Name.Value); Trace.WriteIf(baseClass == null, message); var baseTypeWrapper = FindDTypeWrapper(inheritanceTrees, baseClass); var existingTypeWrapper = FindDTypeWrapper(inheritanceTrees, newType); if (baseTypeWrapper == null && existingTypeWrapper == null) { if (baseClass != null) { baseTypeWrapper = new TypeDeclWrapper(baseClass); baseTypeWrapper.Children.Add(new TypeDeclWrapper(newType)); inheritanceTrees.Add(baseTypeWrapper); } else { inheritanceTrees.Add(new TypeDeclWrapper(newType)); } } else if (baseTypeWrapper != null && existingTypeWrapper == null) { baseTypeWrapper.Children.Add(new TypeDeclWrapper(newType)); } else if (baseTypeWrapper == null && existingTypeWrapper != null) { Debug.Assert(inheritanceTrees.Contains(existingTypeWrapper)); baseTypeWrapper = new TypeDeclWrapper(baseClass); baseTypeWrapper.Children.Add(existingTypeWrapper); inheritanceTrees.Remove(existingTypeWrapper); inheritanceTrees.Add(baseTypeWrapper); } else { Debug.Fail("Unsupported state"); } }
/// <summary> /// Finds the type in a set of inheritance trees. /// </summary> /// <param name="types">The types.</param> /// <param name="type">The type.</param> /// <returns></returns> private static TypeDeclWrapper FindDTypeWrapper(List <TypeDeclWrapper> types, TypeDecl type) { foreach (var inheritanceTree in types) { TypeDeclWrapper result = inheritanceTree.FindType(type); if (result != null) { return(result); } } return(null); }
/// <summary> /// Finds the type in the tree under this instance. /// </summary> /// <param name="typeDeclaration">The type declaration.</param> /// <returns></returns> public TypeDeclWrapper FindType(TypeDecl typeDeclaration) { if (TypeDeclaration == typeDeclaration) { return(this); } foreach (var child in Children) { TypeDeclWrapper result = child.FindType(typeDeclaration); if (result != null) { return(child); } } return(null); }