/// <summary> /// Validates that all the dependencies exist in the given list. /// </summary> /// <param name="info"><see cref="DeclarationInfo"/> object to validate the dependencies of.</param> /// <param name="declarations">List of <see cref="DeclarationInfo"/> to validate against.</param> /// <exception cref="InvalidOperationException">Occurs if one of the dependencies of <paramref name="info"/> doesn't exist in <paramref name="declarations"/>.</exception> private static void ValidateDependenciesExist(DeclarationInfo info, List <DeclarationInfo> declarations) { foreach (DeclarationInfo child in info.Dependency) { // Check that the child exists. if (!declarations.Contains(child)) { throw new InvalidOperationException(string.Format("The DeclarationInfo object ({0}) has a dependency ({0}) that does not exist.", info.Name, child.Name)); } // Check that any dependencies of the child exist. ValidateDependenciesExist(child, declarations); } }
/// <summary> /// Returns the string corresponding to the <see cref="Item"/> type. /// </summary> /// <returns>String representing the item type.</returns> private string GetItemString() { if (Item is DeclarationInfo) { DeclarationInfo info = Item as DeclarationInfo; return(Enum.GetName(typeof(DeclarationType), info.Declaration)); } if (Item is SignalInfo) { return("signal"); } throw new NotImplementedException("The Item type was not a recognized type."); }
/// <summary> /// Validiates that there is not a circular dependency. /// </summary> /// <param name="info"><see cref="DeclarationInfo"/> to check for a circular dependency.</param> /// <param name="descendents">Chain of descendents that are dependent on <paramref name="info"/>.</param> /// <exception cref="InvalidOperationException"><paramref name="info"/> is a dependency of itself.</exception> private static void ValidateDependencies(DeclarationInfo info, DeclarationInfo[] descendents) { // Validate that this object is not in the chain. List <DeclarationInfo> checkList = new List <DeclarationInfo>(descendents); if (checkList.Contains(info)) { throw new InvalidOperationException(string.Format("The DeclarationInfo object ({0}) contains a dependency of itself.", info.Name)); } // Add this object to the chain. checkList.Add(info); // Validate it's parents. DeclarationInfo[] newArray = checkList.ToArray(); foreach (DeclarationInfo child in info.Dependency) { ValidateDependencies(child, newArray); } }
/// <summary> /// Checks that all the dependencies of <paramref name="info"/> are included in the <paramref name="list"/>. /// </summary> /// <param name="info"><see cref="DeclarationInfo"/> object to check dependencies of.</param> /// <param name="list">List of <see cref="DeclarationInfo"/> objects to validate against.</param> /// <returns>True if all were contained in the list, or no dependencies were found, false if a dependency was found that wasn't in the list.</returns> private static bool CheckDependenciesAreIncluded(DeclarationInfo info, List <DeclarationInfo> list) { if (info.Dependency.Count == 0) { return(true); } foreach (DeclarationInfo dep in info.Dependency) { if (!list.Contains(dep)) { return(false); } if (!CheckDependenciesAreIncluded(dep, list)) { return(false); } } return(true); }
/// <summary> /// Validates that the two objects are not equal and have unique names. /// </summary> /// <param name="info1">First <see cref="BaseTypeInfo"/> object to compare.</param> /// <param name="info2">Second <see cref="BaseTypeInfo"/> object to compare.</param> /// <param name="parentName">Name of the parent object.</param> /// <param name="parentType">Type of the parent object.</param> /// <exception cref="ArgumentException"><paramref name="parentName"/>, or <paramref name="parentType"/> is an empty string.</exception> /// <exception cref="ArgumentNullException"><paramref name="info1"/>, <paramref name="info2"/>, <paramref name="parentName"/>, or <paramref name="parentType"/> is a null reference.</exception> /// <exception cref="InvalidOperationException">The objects are the same or have the same name.</exception> private static void ValidateUniqueNames(BaseTypeInfo info1, BaseTypeInfo info2, string parentName, string parentType) { if (info1 == null) { throw new ArgumentNullException("info1"); } if (info2 == null) { throw new ArgumentNullException("info2"); } if (parentName == null) { throw new ArgumentNullException("parentName"); } if (parentName.Length == 0) { throw new ArgumentException("parentName is an empty string"); } if (parentType == null) { throw new ArgumentNullException("parentType"); } if (parentType.Length == 0) { throw new ArgumentException("parentType is an empty string"); } if (string.Compare(info1.Name, info2.Name, true) != 0) { return; } string name1 = info1.GetTypeName(); if (info1 is DeclarationInfo) { DeclarationInfo info = info1 as DeclarationInfo; name1 = Enum.GetName(typeof(DeclarationType), info.Declaration); } string name2 = info2.GetTypeName(); if (info2 is DeclarationInfo) { DeclarationInfo info = info2 as DeclarationInfo; name2 = Enum.GetName(typeof(DeclarationType), info.Declaration); } if (info1 == info2) { throw new InvalidOperationException(string.Format ( "A {0} ({1}) contains duplicate {2} object children ({2}).", parentType, parentName, name1, info1.Name )); } if (string.Compare(name1, name2, true) == 0) { throw new InvalidOperationException(string.Format ( "A {0} ({1}) contains two {2} object children with the same name ({2}).", parentType, parentName, name1, info1.Name )); } else { throw new InvalidOperationException(string.Format ( "A {0} ({1}) contains a child {2} and {3} object with the same name ({4}).", parentType, parentName, name1, name2, info1.Name )); } }
/// <summary> /// Writes the module to a stream. /// </summary> /// <param name="wr"><see cref="StreamWriter"/> object to write the entity to.</param> /// <param name="indentOffset">Number of indents to add before any documentation begins.</param> /// <exception cref="ArgumentNullException"><paramref name="wr"/> is a null reference.</exception> /// <exception cref="InvalidOperationException">Unable to write the object out in its current state.</exception> /// <exception cref="IOException">An error occurred while writing to the <see cref="StreamWriter"/> object.</exception> public void Write(StreamWriter wr, int indentOffset) { if (wr == null) { throw new ArgumentNullException("wr"); } if (indentOffset < 0) { indentOffset = 0; } ValidateChildNames(); // Write the entity. Entity.Write(wr, indentOffset); DocumentationHelper.WriteLine(wr); DocumentationHelper.WriteLine(wr, string.Format("architecture {0} of {1} is", Enum.GetName(typeof(ArchitecturalType), Type), Entity.Name), indentOffset); DocumentationHelper.WriteLine(wr); // Functions BaseTypeInfo.WriteBaseTypeInfos("Functions", wr, Functions.ToArray(), indentOffset, Entity.Name, "module"); if (Functions.Count > 0) { DocumentationHelper.WriteLine(wr); } // Types and Constants DeclarationInfo.WriteDeclarations(wr, DeclaredTypes.ToArray(), indentOffset, Entity.Name, "module"); if (DeclaredTypes.Count > 0) { DocumentationHelper.WriteLine(wr); } // Procedures BaseTypeInfo.WriteBaseTypeInfos("Procedures", wr, Procedures.ToArray(), indentOffset, Entity.Name, "module"); if (Procedures.Count > 0) { DocumentationHelper.WriteLine(wr); } // Components ComponentInfo[] components = SubModule.GetUniqueComponents(SubModule.GetAllSubModules(this), true); BaseTypeInfo.WriteBaseTypeInfos("Components", wr, components, indentOffset, Entity.Name, "module"); if (components.Length > 0) { DocumentationHelper.WriteLine(wr); } // Signals BaseTypeInfo.WriteBaseTypeInfos("Signals", wr, Signals.ToArray(), indentOffset, Entity.Name, "module"); if (Signals.Count > 0) { DocumentationHelper.WriteLine(wr); } // Aliases BaseTypeInfo.WriteBaseTypeInfos("Aliases", wr, Aliases.ToArray(), indentOffset, Entity.Name, "module"); if (Aliases.Count > 0) { DocumentationHelper.WriteLine(wr); } // Attributes AttributeSpecificationInfo.WriteAttributes(wr, Attributes.ToArray(), indentOffset, Entity.Name, "module"); if (Attributes.Count > 0) { DocumentationHelper.WriteLine(wr); } DocumentationHelper.WriteLine(wr, "begin", indentOffset); DocumentationHelper.WriteLine(wr); // Concurrent Statements foreach (string line in ConcurrentStatements) { DocumentationHelper.WriteLine(wr, line, indentOffset); } if (ConcurrentStatements.Count > 0) { DocumentationHelper.WriteLine(wr); } // Processes BaseTypeInfo.WriteBaseTypeInfos("Processes", wr, Processes.ToArray(), indentOffset, Entity.Name, "module"); if (Processes.Count > 0) { DocumentationHelper.WriteLine(wr); } // Generates BaseTypeInfo.WriteBaseTypeInfos("Generates", wr, Generates.ToArray(), indentOffset, Entity.Name, "module"); if (Generates.Count > 0) { DocumentationHelper.WriteLine(wr); } BaseTypeInfo.WriteBaseTypeInfos("Sub-Modules", wr, SubModules.ToArray(), indentOffset, Entity.Name, "module"); if (SubModules.Count > 0) { DocumentationHelper.WriteLine(wr); } StringBuilder sb = new StringBuilder(); sb.Append("end"); if (DefaultValues.AddOptionalTypeNames) { sb.Append(" architecture"); } if (DefaultValues.AddOptionalNames) { sb.AppendFormat(" {0}", Enum.GetName(typeof(ArchitecturalType), Type)); } sb.Append(";"); DocumentationHelper.Write(wr, sb.ToString(), indentOffset); }