Exemplo n.º 1
0
        /// <summary>
        ///   Writes the signal to a stream.
        /// </summary>
        /// <param name="wr"><see cref="StreamWriter"/> object to write the signal 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="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;
            }

            string defaultValueString = string.Empty;

            if (!string.IsNullOrWhiteSpace(DefaultValue))
            {
                defaultValueString = string.Format(" := {0}", DefaultValue);
            }

            string nextValueString = string.Empty;

            if (AddPreClockSignal)
            {
                nextValueString = string.Format(", next_{0}", Name);
            }

            // Write the header.
            WriteBasicHeader(wr, indentOffset);
            DocumentationHelper.WriteLine(wr, string.Format("signal {0}{1} : {2}{3};", Name, nextValueString, Type, defaultValueString), indentOffset);
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Writes the generic declaration to a stream.
        /// </summary>
        /// <param name="wr"><see cref="StreamWriter"/> object to write the declaration to.</param>
        /// <param name="generics">Array of <see cref="SimplifiedGenericInfo"/> objects to write in the declaration.</param>
        /// <param name="indentOffset">Number of indents to add before any documentation begins.</param>
        /// <exception cref="ArgumentNullException"><paramref name="wr"/>, or <paramref name="generics"/> is a null reference.</exception>
        /// <exception cref="ArgumentException"><paramref name="generics"/> is an empty array.</exception>
        /// <exception cref="IOException">An error occurred while writing to the <see cref="StreamWriter"/> object.</exception>
        public static void WriteGenericDeclaration(StreamWriter wr, SimplifiedGenericInfo[] generics, int indentOffset)
        {
            if (generics == null)
            {
                throw new ArgumentNullException("generics");
            }
            if (generics.Length == 0)
            {
                throw new ArgumentException("generics is an empty array");
            }

            if (DefaultValues.AddSpaceAfterKeyWords)
            {
                DocumentationHelper.WriteLine(wr, "generic (", indentOffset);
            }
            else
            {
                DocumentationHelper.WriteLine(wr, "generic(", indentOffset);
            }
            string ending = ";";

            for (int i = 0; i < generics.Length; i++)
            {
                if (i == generics.Length - 1)
                {
                    ending = string.Empty;
                }
                DocumentationHelper.WriteLine(wr, string.Format("{0}{1}", generics[i].GetDeclaration(), ending), indentOffset + 1);
            }
            DocumentationHelper.WriteLine(wr, ");", indentOffset);
        }
        /// <summary>
        ///   Writes the attribute specification to a stream.
        /// </summary>
        /// <param name="wr"><see cref="StreamWriter"/> object to write the attribute specification 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="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;
            }

            Dictionary <string, string[]> lookup = new Dictionary <string, string[]>(2);

            lookup.Add("Summary", new string[] { Summary });
            if (!string.IsNullOrWhiteSpace(Remarks))
            {
                lookup.Add("Remarks", new string[] { Remarks });
            }

            DocumentationHelper.WriteFlowerLine(wr, indentOffset);
            DocumentationHelper.WriteGeneralDocumentationElements(wr, lookup, indentOffset);
            DocumentationHelper.WriteFlowerLine(wr, indentOffset);
            DocumentationHelper.WriteLine(wr, string.Format("attribute {0} of {1} : {2} is {3};", Declaration.Name, Item.Name, GetItemString(), Value), indentOffset);
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Writes the file to the <see cref="StreamWriter"/> object.
        /// </summary>
        /// <param name="wr"><see cref="StreamWriter"/> object to write the code to.</param>
        /// <exception cref="ArgumentNullException"><paramref name="wr"/> is a null reference.</exception>
        /// <exception cref="IOException">An error occurred while writing to the <see cref="StreamWriter"/> object.</exception>
        private void WriteFileSubHeader(StreamWriter wr)
        {
            List <Dictionary <string, List <string> > > subInfo = null;
            List <string> info = null;

            GenerateModuleInfo(Module, out info, out subInfo);

            // Determine the first part maximum string length.
            int maxSizeRegions = 0;

            foreach (Dictionary <string, List <string> > lookup in subInfo)
            {
                foreach (string key in lookup.Keys)
                {
                    MaxStringLength(key, ref maxSizeRegions);
                }
            }

            int col1  = maxSizeRegions + 6;            // 6 is for "--   " and space after.
            int index = 0;

            foreach (string key in info)
            {
                // Write the module of the file.
                StringBuilder sb = new StringBuilder();
                sb.Append("-- ");
                sb.Append(key);
                DocumentationHelper.WriteLine(wr, sb.ToString(), 0);
                Dictionary <string, List <string> > lookup = subInfo[index++];
                int subIndex = 0;
                foreach (string subKey in lookup.Keys)
                {
                    DocumentationHelper.WriteLine(wr, string.Format("--   {0}", subKey), 0);
                    for (int i = 0; i < lookup[subKey].Count; i++)
                    {
                        sb.Clear();
                        sb.Append("--");
                        for (int j = 2; j < col1; j++)
                        {
                            sb.Append(" ");
                        }
                        sb.Append(lookup[subKey][i]);
                        DocumentationHelper.WriteLine(wr, sb.ToString(), 0);
                    }
                    subIndex++;

                    if (subIndex != lookup.Keys.Count)
                    {
                        DocumentationHelper.WriteLine(wr, "--", 0);
                    }
                }
                DocumentationHelper.WriteFlowerLine(wr, 0);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///   Writes the attribute declaration to a stream.
        /// </summary>
        /// <param name="wr"><see cref="StreamWriter"/> object to write the attribute declaration 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="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;
            }

            // Write the header.
            WriteBasicHeader(wr, indentOffset);
            DocumentationHelper.WriteLine(wr, string.Format("attribute {0} : {1};", Name, Type), indentOffset);
        }
Exemplo n.º 6
0
        /// <summary>
        ///   Writes the component to a stream.
        /// </summary>
        /// <param name="wr"><see cref="StreamWriter"/> object to write the component 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 generics or ports 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 (SkipDeclaration)
            {
                return;
            }

            if (indentOffset < 0)
            {
                indentOffset = 0;
            }

            if (Generics.Count == 0 && Ports.Count == 0)
            {
                throw new InvalidOperationException(string.Format("An attempt was made to write a component ({0}), but it doesn't have any ports or generics defined.", Name));
            }

            // Write the header.
            WriteBasicHeader(wr, indentOffset);
            DocumentationHelper.WriteLine(wr, string.Format("component {0} is", Name), indentOffset);

            if (Generics.Count > 0)
            {
                SimplifiedGenericInfo.WriteGenericDeclaration(wr, Generics.ToArray(), indentOffset);
            }

            if (Ports.Count > 0)
            {
                SimplifiedPortInfo.WritePortDeclaration(wr, Ports.ToArray(), indentOffset);
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("end component");
            if (DefaultValues.AddOptionalNames)
            {
                sb.AppendFormat(" {0}", Name);
            }
            sb.Append(";");
            DocumentationHelper.WriteLine(wr, sb.ToString(), indentOffset);
        }
Exemplo n.º 7
0
        /// <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);
        }
Exemplo n.º 8
0
        /// <summary>
        ///   Writes the declaration to a stream.
        /// </summary>
        /// <param name="wr"><see cref="StreamWriter"/> object to write the declaration 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">An attempt was made to write a default value to a non-constant.</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 (DefaultValue != null && DefaultValue.Length > 0 && Declaration != DeclarationType.Constant)
            {
                throw new InvalidOperationException(string.Format
                                                    (
                                                        "An attempt was made to write the DeclarationInfo object with a default value ({0}), for a non-constant ({1}). Only constants can have default values.",
                                                        DefaultValue,
                                                        Enum.GetName(typeof(DeclarationType), Declaration)
                                                    ));
            }

            string typeAssigner = "is";

            if (Declaration == DeclarationType.Constant)
            {
                typeAssigner = ":";
            }

            string defaultValueString = string.Empty;

            if (!string.IsNullOrWhiteSpace(DefaultValue))
            {
                defaultValueString = string.Format(" := {0}", DefaultValue);
            }

            // Write the header.
            WriteBasicHeader(wr, indentOffset);
            DocumentationHelper.WriteLine(wr, string.Format("{0} {1} {2} {3}{4};", Enum.GetName(typeof(DeclarationType), Declaration).ToLower(), Name, typeAssigner, Type, defaultValueString), indentOffset);
        }
Exemplo n.º 9
0
        /// <summary>
        ///   Writes the basic file header composed of the summary and remarks section.
        /// </summary>
        /// <param name="wr"><see cref="StreamWriter"/> object to write the header 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="IOException">An error occurred while writing to the <see cref="StreamWriter"/> object.</exception>
        public void WriteBasicHeader(StreamWriter wr, int indentOffset)
        {
            if (wr == null)
            {
                throw new ArgumentNullException("wr");
            }

            if (indentOffset < 0)
            {
                indentOffset = 0;
            }

            Dictionary <string, string[]> lookup = new Dictionary <string, string[]>(2);

            lookup.Add("Summary", new string[] { Summary });
            if (!string.IsNullOrWhiteSpace(Remarks))
            {
                lookup.Add("Remarks", new string[] { Remarks });
            }

            DocumentationHelper.WriteFlowerLine(wr, indentOffset);
            DocumentationHelper.WriteGeneralDocumentationElements(wr, lookup, indentOffset);
            DocumentationHelper.WriteFlowerLine(wr, indentOffset);
        }
Exemplo n.º 10
0
        /// <summary>
        ///   Writes the entity 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">The number of ports and generics is zero.</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 (Generics.Count == 0 && Ports.Count == 0)
            {
                throw new InvalidOperationException(string.Format("An attempt was made to write an entity ({0}), but the entity does not have any ports or generics.", Name));
            }

            // Generate the documentation lookup table.
            Dictionary <string, string[]> lookup = new Dictionary <string, string[]>();

            lookup.Add("Summary", new string[] { Summary });

            if (Generics.Count > 0)
            {
                List <string> subItems = new List <string>(Generics.Count);
                foreach (GenericInfo info in Generics)
                {
                    subItems.Add(info.GetDocumentationString());
                }
                lookup.Add("Generics", subItems.ToArray());
            }

            if (Ports.Count > 0)
            {
                List <string> subItems = new List <string>(Ports.Count);
                foreach (PortInfo info in Ports)
                {
                    subItems.Add(info.GetDocumentationString());
                }
                lookup.Add("Ports", 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, string.Format("entity {0} is", Name), indentOffset);

            if (Generics.Count > 0)
            {
                SimplifiedGenericInfo.WriteGenericDeclaration(wr, Generics.ToArray(), indentOffset);
            }

            if (Ports.Count > 0)
            {
                SimplifiedPortInfo.WritePortDeclaration(wr, Ports.ToArray(), indentOffset);
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("end");
            if (DefaultValues.AddOptionalTypeNames)
            {
                sb.Append(" entity");
            }
            if (DefaultValues.AddOptionalNames)
            {
                sb.AppendFormat(" {0}", Name);
            }
            sb.Append(";");
            DocumentationHelper.WriteLine(wr, sb.ToString(), indentOffset);
        }
Exemplo n.º 11
0
        /// <summary>
        ///   Writes the sub-module to a stream.
        /// </summary>
        /// <param name="wr"><see cref="StreamWriter"/> object to write the sub-module 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">There was a problem with the mappings.</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;
            }

            // Validate the mappings.
            ValidateMappings();

            // Write the header.
            WriteBasicHeader(wr, indentOffset);
            if (ConfigurationName == null)
            {
                // Component instantiation.
                DocumentationHelper.WriteLine(wr, string.Format("{0}: {1}", Name, Component.Name), indentOffset);
            }
            else
            {
                // Direct instantiation.
                // TODO: We are assuming the current working library here. Do we want the library specified somewhere in the component. - RD
                DocumentationHelper.WriteLine(wr, string.Format("{0}: entity work.{1}({2})", Name, Component.Name, ConfigurationName), indentOffset);
            }

            if (GenericMap.Count > 0)
            {
                if (DefaultValues.AddSpaceAfterKeyWords)
                {
                    DocumentationHelper.WriteLine(wr, "generic map (", indentOffset);
                }
                else
                {
                    DocumentationHelper.WriteLine(wr, "generic map(", indentOffset);
                }

                // Write the generics out.
                int    index  = 0;
                string ending = ",";
                foreach (SimplifiedGenericInfo info in GenericMap.Keys)
                {
                    if (index == GenericMap.Count - 1)
                    {
                        ending = string.Empty;
                    }
                    DocumentationHelper.WriteLine(wr, string.Format("{0} => {1}{2}", info.Name, GenericMap[info], ending), indentOffset + 1);
                    index++;
                }

                if (PortMap.Count == 0)
                {
                    DocumentationHelper.WriteLine(wr, ");", indentOffset);
                }
                else
                {
                    DocumentationHelper.WriteLine(wr, ")", indentOffset);
                }
            }

            if (PortMap.Count > 0)
            {
                if (DefaultValues.AddSpaceAfterKeyWords)
                {
                    DocumentationHelper.WriteLine(wr, "port map (", indentOffset);
                }
                else
                {
                    DocumentationHelper.WriteLine(wr, "port map(", indentOffset);
                }

                // Write the ports out.
                int    index  = 0;
                string ending = ",";
                foreach (SimplifiedPortInfo info in PortMap.Keys)
                {
                    if (index == PortMap.Count - 1)
                    {
                        ending = string.Empty;
                    }
                    if (ConversionMap[info] == null)
                    {
                        DocumentationHelper.WriteLine(wr, string.Format("{0} => {1}{2}", info.Name, PortMap[info], ending), indentOffset + 1);
                    }
                    else
                    {
                        DocumentationHelper.WriteLine(wr, string.Format("{0}({1}) => {2}{3}", ConversionMap[info], info.Name, PortMap[info], ending), indentOffset + 1);
                    }
                    index++;
                }

                DocumentationHelper.WriteLine(wr, ");", indentOffset);
            }
        }
Exemplo n.º 12
0
        /// <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);
        }
Exemplo n.º 13
0
        /// <summary>
        ///   Writes the types to a stream.
        /// </summary>
        /// <param name="regionName">Name of the region for the types.</param>
        /// <param name="wr"><see cref="StreamWriter"/> object to write the types to.</param>
        /// <param name="types">Array of <see cref="BaseTypeInfo"/> 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="types"/>.</exception>
        /// <exception cref="IOException">An error occurred while writing to the <see cref="StreamWriter"/> object.</exception>
        public static void WriteBaseTypeInfos(string regionName, StreamWriter wr, BaseTypeInfo[] types, int indentOffset, string parentName, string parentType)
        {
            if (wr == null)
            {
                throw new ArgumentNullException("wr");
            }
            if (types == null)
            {
                throw new ArgumentNullException("types");
            }
            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 (types.Length == 0)
            {
                return;
            }

            // Validate that we don't have duplicate names.
            BaseTypeInfo.ValidateNoDuplicates(types, parentName, parentType);

            List <BaseTypeInfo> list = new List <BaseTypeInfo>();

            list.AddRange(types);
            list.Sort();

            if (!string.IsNullOrWhiteSpace(regionName))
            {
                DocumentationHelper.WriteRegionStart(wr, regionName, indentOffset);
            }
            for (int i = 0; i < list.Count; i++)
            {
                list[i].Write(wr, indentOffset);
                if (i != list.Count - 1)
                {
                    DocumentationHelper.WriteLine(wr);                     // Leave a line between declarations.
                }
            }
            if (!string.IsNullOrWhiteSpace(regionName))
            {
                DocumentationHelper.WriteRegionEnd(wr, regionName, indentOffset);
            }
        }
Exemplo n.º 14
0
        /// <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);
        }
Exemplo n.º 15
0
        /// <summary>
        ///   Writes the source code information in this object out to a file in the form of source code.
        /// </summary>
        /// <param name="rootFolder">Root location of the file. (The relative path will be added to this folder to generate the file.)</param>
        /// <exception cref="ArgumentNullException"><paramref name="rootFolder"/> is a null reference.</exception>
        /// <exception cref="ArgumentException"><paramref name="rootFolder"/> is not a valid folder path.</exception>
        /// <exception cref="IOException">An error occurred while writing to the file.</exception>
        public void WriteToFile(string rootFolder, bool uppercaseFileName = true)
        {
            if (rootFolder == null)
            {
                throw new ArgumentNullException("rootFolder");
            }
            if (rootFolder.Length == 0)
            {
                throw new ArgumentException("rootFolder is an empty string");
            }
            try
            {
                rootFolder = Path.GetFullPath(rootFolder);
            }
            catch (Exception e)
            {
                throw new ArgumentException("rootFolder is not a valid path (see inner exception).", e);
            }

            string fullFolderPath;

            if (RelativePath.Length > 0)
            {
                fullFolderPath = Path.Combine(rootFolder, RelativePath);
            }
            else
            {
                fullFolderPath = rootFolder;
            }
            string fileName = FileName;

            if (!uppercaseFileName)
            {
                fileName = FileName.ToLower();
            }
            string fullPath = Path.Combine(fullFolderPath, fileName);

            // Generate any needed directories.
            DefaultValues.CreateFolderPath(fullFolderPath);
            using (StreamWriter wr = new StreamWriter(fullPath))
            {
                DocumentationHelper.WriteFileHeader(wr, fileName, Description);

                if (DefaultValues.IncludeSubHeader)
                {
                    WriteFileSubHeader(wr);
                }

                // Add usings.
                string[] usings = Module.Usings;
                if (usings.Length > 0)
                {
                    Dictionary <string, List <string> > lookup = GetLibraryLookup();
                    foreach (string key in lookup.Keys)
                    {
                        DocumentationHelper.WriteLine(wr, string.Format("library {0};", key), 0);
                        foreach (string use in lookup[key])
                        {
                            DocumentationHelper.WriteLine(wr, string.Format("use {0};", use), 0);
                        }
                        DocumentationHelper.WriteLine(wr);
                    }
                }

                Module.Write(wr, 0);
            }
        }
        /// <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);
        }
Exemplo n.º 17
0
        /// <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);
        }
Exemplo n.º 18
0
        /// <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);
        }