/// <summary> /// Validates that all the child names are unique. /// </summary> /// <exception cref="InvalidOperationException">Two child objects were found with the same name.</exception> private void ValidateChildNames() { List <BaseTypeInfo> childList = new List <BaseTypeInfo>(); childList.AddRange(DeclaredTypes); childList.AddRange(Functions); childList.AddRange(Procedures); childList.AddRange(SubModule.GetUniqueComponents(SubModules, true)); childList.AddRange(Signals); childList.AddRange(Aliases); childList.AddRange(AttributeDeclarationInfo.GetUniqueAttributeDeclarations(Attributes)); childList.AddRange(Processes); childList.AddRange(Generates); childList.AddRange(SubModules); BaseTypeInfo.ValidateNoDuplicates(childList.ToArray(), Entity.Name, "module"); }
/// <summary> /// Validates that all the child names are unique. /// </summary> /// <exception cref="InvalidOperationException">Two child objects were found with the same name.</exception> private void ValidateChildNames() { List <BaseTypeInfo> childList = new List <BaseTypeInfo>(Generates.Count + Processes.Count + SubModules.Count); foreach (ProcessInfo info in Processes) { childList.Add(info); } foreach (GenerateInfo info in Generates) { childList.Add(info); } foreach (SubModule info in SubModules) { childList.Add(info); } BaseTypeInfo.ValidateNoDuplicates(childList.ToArray(), Name, "generate"); }
/// <summary> /// Writes the process to a stream. /// </summary> /// <param name="wr"><see cref="StreamWriter"/> object to write the process 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">No code lines were specified.</exception> /// <exception cref="IOException">An error occurred while writing to the <see cref="StreamWriter"/> object.</exception> public override void Write(StreamWriter wr, int indentOffset) { if (wr == null) { throw new ArgumentNullException("wr"); } if (indentOffset < 0) { indentOffset = 0; } if (CodeLines.Count == 0) { throw new InvalidOperationException(string.Format("An attempt was made to write a process ({0}), but the processes doesn't have any code associated with it", Name)); } // Write the header. WriteBasicHeader(wr, indentOffset); DocumentationHelper.WriteLine(wr, string.Format("{0}:", Name), indentOffset); DocumentationHelper.WriteLine(wr, GetSensitivityListLine(), indentOffset); // Write the variable declarations out. BaseTypeInfo.WriteBaseTypeInfos(null, wr, Variables.ToArray(), indentOffset + 1, Name, "process"); DocumentationHelper.WriteLine(wr, "begin", indentOffset); // Write the code lines. foreach (string line in CodeLines) { DocumentationHelper.WriteLine(wr, line, indentOffset + 1); } StringBuilder sb = new StringBuilder(); sb.Append("end process"); if (DefaultValues.AddOptionalNames) { sb.AppendFormat(" {0}", Name); } sb.Append(";"); DocumentationHelper.WriteLine(wr, sb.ToString(), indentOffset); }
/// <summary> /// Instantiates a new <see cref="AttributeSpecificationInfo"/> object. /// </summary> /// <param name="declaration"><see cref="AttributeDeclarationInfo"/> object representing the declaration of the attribute.</param> /// <param name="item"><see cref="BaseTypeInfo"/> object representing the item the attribute is applied to.</param> /// <param name="value">Value of the attribute.</param> /// <param name="summary">Summary description of the attribute specification.</param> /// <param name="remarks">Additional remarks to add to the documentation.</param> /// <remarks>Currently only <see cref="DeclarationInfo"/> and <see cref="SignalInfo"/> types are supported for <paramref name="item"/>.</remarks> /// <exception cref="ArgumentNullException"><paramref name="declaration"/>, <paramref name="item"/>, <paramref name="value"/>, or <paramref name="summary"/> is a null reference.</exception> /// <exception cref="ArgumentException"><paramref name="value"/>, or <paramref name="summary"/> is an empty string or <paramref name="item"/> is not a supported type.</exception> public AttributeSpecificationInfo(AttributeDeclarationInfo declaration, BaseTypeInfo item, string value, string summary, string remarks = null) { if (declaration == null) { throw new ArgumentNullException("declaration"); } if (item == null) { throw new ArgumentNullException("item"); } if (value == null) { throw new ArgumentNullException("value"); } if (value.Length == 0) { throw new ArgumentException("value is an empty string"); } if (summary == null) { throw new ArgumentNullException("summary"); } if (summary.Length == 0) { throw new ArgumentException("summary is an empty string"); } if (!(item is DeclarationInfo) && !(item is SignalInfo)) { throw new ArgumentException("item is not a DeclarationInfo or SignalInfo type"); } Declaration = declaration; Item = item; Value = value; Summary = summary; Remarks = remarks; }
/// <summary> /// Writes the declarations to a stream. /// </summary> /// <param name="wr"><see cref="StreamWriter"/> object to write the declarations to.</param> /// <param name="declarations">Array of <see cref="DeclarationInfo"/> objects to write to the stream.</param> /// <param name="indentOffset">Number of indents to add before any documentation begins.</param> /// <param name="parentName">Name of the parent object.</param> /// <param name="parentType">Type of the parent object.</param> /// <remarks>Use this method over the base class method to perform additional checks and better sorting.</remarks> /// <exception cref="ArgumentException"><paramref name="parentName"/>, or <paramref name="parentType"/> is an empty string.</exception> /// <exception cref="ArgumentNullException"><paramref name="wr"/>, <paramref name="parentName"/>, or <paramref name="parentType"/> is a null reference.</exception> /// <exception cref="InvalidOperationException">A circular dependency exists or duplicate name is found in the <paramref name="declarations"/>.</exception> /// <exception cref="IOException">An error occurred while writing to the <see cref="StreamWriter"/> object.</exception> public static void WriteDeclarations(StreamWriter wr, DeclarationInfo[] declarations, int indentOffset, string parentName, string parentType) { if (wr == null) { throw new ArgumentNullException("wr"); } if (declarations == null) { throw new ArgumentNullException("declarations"); } 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 (indentOffset < 0) { indentOffset = 0; } // Write nothing if array is empty. if (declarations.Length == 0) { return; } // Validate that we don't have duplicate names. BaseTypeInfo.ValidateNoDuplicates(declarations, parentName, parentType); // Validate that no circular dependencies exist. foreach (DeclarationInfo dec in declarations) { ValidateDependencies(dec, new DeclarationInfo[0]); } // Validate that all dependencies are in the main list. List <DeclarationInfo> decList = new List <DeclarationInfo>(declarations); foreach (DeclarationInfo dec in declarations) { ValidateDependenciesExist(dec, decList); } // Sort the Values by type. DeclarationInfo[] sorted = SortDeclarations(declarations); DocumentationHelper.WriteRegionStart(wr, "Constants & Types", indentOffset); for (int i = 0; i < sorted.Length; i++) { sorted[i].Write(wr, indentOffset); if (i != sorted.Length - 1) { DocumentationHelper.WriteLine(wr); // Leave a line between declarations. } } DocumentationHelper.WriteRegionEnd(wr, "Constants & Types", indentOffset); }
/// <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); }
/// <summary> /// Writes the attributes to a stream. /// </summary> /// <param name="wr"><see cref="StreamWriter"/> object to write the types to.</param> /// <param name="attributes">Array of <see cref="AttributeSpecificationInfo"/> objects to write to the stream.</param> /// <param name="indentOffset">Number of indents to add before any documentation begins.</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="wr"/>, <paramref name="parentName"/>, or <paramref name="parentType"/> is a null reference.</exception> /// <exception cref="InvalidOperationException">A duplicate object or name is found in the <paramref name="attributes"/>.</exception> /// <exception cref="IOException">An error occurred while writing to the <see cref="StreamWriter"/> object.</exception> public static void WriteAttributes(StreamWriter wr, AttributeSpecificationInfo[] attributes, int indentOffset, string parentName, string parentType) { if (wr == null) { throw new ArgumentNullException("wr"); } if (attributes == null) { throw new ArgumentNullException("attributes"); } 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 (indentOffset < 0) { indentOffset = 0; } // Write nothing if array is empty. if (attributes.Length == 0) { return; } // TODO: should validate that there aren't duplicate declaration/signal combination. - RD Dictionary <AttributeDeclarationInfo, List <AttributeSpecificationInfo> > lookup = new Dictionary <AttributeDeclarationInfo, List <AttributeSpecificationInfo> >(); foreach (AttributeSpecificationInfo info in attributes) { if (!lookup.ContainsKey(info.Declaration)) { lookup.Add(info.Declaration, new List <AttributeSpecificationInfo>()); } lookup[info.Declaration].Add(info); } // Validate that we don't have duplicate names in the declarations. List <AttributeDeclarationInfo> list = new List <AttributeDeclarationInfo>(lookup.Keys); BaseTypeInfo.ValidateNoDuplicates(list.ToArray(), parentName, parentType); list.Sort(); DocumentationHelper.WriteRegionStart(wr, "Attributes", indentOffset); for (int i = 0; i < list.Count; i++) { list[i].Write(wr, indentOffset); DocumentationHelper.WriteLine(wr); for (int j = 0; j < lookup[list[i]].Count; j++) { lookup[list[i]][j].Write(wr, indentOffset); if (j != lookup[list[i]].Count - 1) { DocumentationHelper.WriteLine(wr); // Leave a line between specifications. } } if (i != list.Count - 1) { DocumentationHelper.WriteLine(wr); // Leave a line between declarations. } } DocumentationHelper.WriteRegionEnd(wr, "Attributes", indentOffset); }
/// <summary> /// Writes the procedure to a stream. /// </summary> /// <param name="wr"><see cref="StreamWriter"/> object to write the procedure 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">No code lines were specified or no parameters were specified.</exception> /// <exception cref="IOException">An error occurred while writing to the <see cref="StreamWriter"/> object.</exception> public override void Write(StreamWriter wr, int indentOffset) { if (wr == null) { throw new ArgumentNullException("wr"); } if (indentOffset < 0) { indentOffset = 0; } if (CodeLines.Count == 0) { throw new InvalidOperationException(string.Format("An attempt was made to write a procedure ({0}), but it doesn't have any code associated with it", Name)); } if (Parameters.Count == 0) { throw new InvalidOperationException(string.Format("An attempt was made to write a procedure ({0}), but it doesn't have any parameters", Name)); } // Generate the documentation lookup table. Dictionary <string, string[]> lookup = new Dictionary <string, string[]>(); lookup.Add("Summary", new string[] { Summary }); if (Parameters.Count > 0) { List <string> subItems = new List <string>(Parameters.Count); foreach (ProcedureParameterInfo info in Parameters) { subItems.Add(info.GetDocumentationString()); } lookup.Add("Parameters", subItems.ToArray()); } if (!string.IsNullOrWhiteSpace(Remarks)) { lookup.Add("Remarks", new string[] { Remarks }); } // Write the header. DocumentationHelper.WriteFlowerLine(wr, indentOffset); DocumentationHelper.WriteGeneralDocumentationElements(wr, lookup, indentOffset); DocumentationHelper.WriteFlowerLine(wr, indentOffset); DocumentationHelper.WriteLine(wr, GetSignature(), indentOffset); // Write the variable declarations out. BaseTypeInfo.WriteBaseTypeInfos(null, wr, Variables.ToArray(), indentOffset + 1, Name, "procedure"); DocumentationHelper.WriteLine(wr, "begin", indentOffset); // Write the code lines. foreach (string line in CodeLines) { DocumentationHelper.WriteLine(wr, line, indentOffset + 1); } StringBuilder sb = new StringBuilder(); sb.Append("end"); if (DefaultValues.AddOptionalTypeNames) { sb.Append(" procedure"); } if (DefaultValues.AddOptionalNames) { sb.AppendFormat(" {0}", Name); } sb.Append(";"); DocumentationHelper.WriteLine(wr, sb.ToString(), indentOffset); }
/// <summary> /// Writes the process to a stream. /// </summary> /// <param name="wr"><see cref="StreamWriter"/> object to write the process 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 override void Write(StreamWriter wr, int indentOffset) { if (wr == null) { throw new ArgumentNullException("wr"); } if (indentOffset < 0) { indentOffset = 0; } if (ConcurrentStatements.Count == 0 && Processes.Count == 0 && SubModules.Count == 0 && Generates.Count == 0) { throw new InvalidOperationException(string.Format("An attempt was made to write a generate section ({0}), but the section doesn't have anything to write (processes, sub-modules, etc.).", Name)); } // Validate that there are not duplicate names in the children. ValidateChildNames(); // Validate that there is not an infinite loop. List <GenerateInfo> parentList = new List <GenerateInfo>(); parentList.Add(this); ValidateChildGenerates(parentList); // Write the header. WriteBasicHeader(wr, indentOffset); DocumentationHelper.WriteLine(wr, string.Format("{0}:", Name), indentOffset); DocumentationHelper.WriteLine(wr, string.Format("{0} generate", GenerateStatement), indentOffset); indentOffset++; // Write the code lines. foreach (string line in ConcurrentStatements) { DocumentationHelper.WriteLine(wr, line, indentOffset); } if (ConcurrentStatements.Count > 0) { DocumentationHelper.WriteLine(wr); } // Write the processes. BaseTypeInfo.WriteBaseTypeInfos("Processes", wr, Processes.ToArray(), indentOffset, Name, "generate"); if (Processes.Count > 0) { DocumentationHelper.WriteLine(wr); } // Write the generates. BaseTypeInfo.WriteBaseTypeInfos("Generates", wr, Generates.ToArray(), indentOffset, Name, "generate"); if (Generates.Count > 0) { DocumentationHelper.WriteLine(wr); } // Write the sub-modules. BaseTypeInfo.WriteBaseTypeInfos("Sub-Modules", wr, SubModules.ToArray(), indentOffset, Name, "generate"); indentOffset--; StringBuilder sb = new StringBuilder(); sb.Append("end generate"); if (DefaultValues.AddOptionalNames) { sb.AppendFormat(" {0}", Name); } sb.Append(";"); DocumentationHelper.WriteLine(wr, sb.ToString(), indentOffset); }