/// <summary>
        /// FormatParam - returns a string representation of the comment for a given parameter for unmanged code.
        /// </summary>
        /// <returns>
        /// The string representation of the comment for a given parameter
        /// </returns>
        /// <param name="fieldName"> The name of the parameter. </param>
        /// <param name="comment"> The comment associated with the parameter. </param>
        /// <param name="fieldTypeName"> The name of the field's type. </param>
        /// <param name="lineBreakLength"> The max length of each line of the comment. </param>
        internal static string FormatParamUnmanaged(string fieldName,
                                                    string comment,
                                                    string fieldTypeName,
                                                    int lineBreakLength)
        {
            string prefix = "//              " + fieldName + ":";

            // Does this fit onto one line? (add one for the space)
            if (prefix.Length + comment.Length + 1 <= lineBreakLength)
            {
                return(prefix + " " + comment);
            }

            StringCodeSink cs = new StringCodeSink();

            string formattedComment = FormatComment(comment, lineBreakLength, "\n", null, false /* unmanaged */);

            cs.Write("//              " + fieldName + ":");

            if ((null == formattedComment) || (formattedComment.Length < 1))
            {
                cs.Write(fieldTypeName);
            }
            else
            {
                cs.Write(formattedComment);
            }

            return(cs.ToString());
        }
        /// <summary>
        /// FormatParam - returns a string representation of the comment for a given parameter
        /// </summary>
        /// <returns>
        /// The string representation of the comment for a given parameter
        /// </returns>
        /// <param name="fieldName"> The name of the parameter. </param>
        /// <param name="comment"> The comment associated with the parameter. </param>
        /// <param name="fieldTypeName"> The name of the field's type. </param>
        /// <param name="lineBreakLength"> The max length of each line of the comment. </param>
        internal static string FormatParam(string fieldName,
                                           string comment,
                                           string fieldTypeName,
                                           int lineBreakLength)
        {
            string prefix  = "/// <param name=\"" + fieldName + "\">";
            string postfix = "</param>";

            // Does this fit onto one line? (add two for spaces)
            if (prefix.Length + postfix.Length + comment.Length + 2 <= lineBreakLength)
            {
                return(prefix + " " + comment + " " + postfix);
            }

            StringCodeSink cs = new StringCodeSink();

            string formattedComment = FormatComment(comment, lineBreakLength, "\n", null, true /* managed */);

            cs.Write(prefix);

            if (null == formattedComment)
            {
                cs.Write(fieldTypeName);
            }
            else
            {
                cs.Write(formattedComment + "\n/// ");
            }

            cs.Write(postfix);

            return(cs.ToString());
        }
        /// <summary>
        ///     FormatComment - formats a comment at a given line break length.
        /// </summary>
        /// <returns>
        ///     string - The string which contains the comment, or String.Empty if there's nothing to do.
        /// </returns>
        /// <param name="comment"> string - The comment itself. </param>
        /// <param name="lineBreakLength"> int - the line break length </param>
        /// <param name="leadingString"> string - the leading string to prepend to the output if the
        /// comment contains any text. </param>
        /// <param name="alternateText"> string - The string to return if the comment is empty. </param>
        /// <param name="managed"> If true, emit a managed-style comment, else unmanaged. </param>
        internal static string FormatComment(string comment,
                                             int lineBreakLength,
                                             string leadingString,
                                             string alternateText,
                                             bool managed)
        {
            if (comment == null)
            {
                return(alternateText);
            }

            comment = comment.Replace("\r\n", "\n");
            comment = comment.Trim();

            if (comment.Length <= 0)
            {
                return(alternateText);
            }

            StringCodeSink cs = new StringCodeSink();

            cs.Write(leadingString);

            cs.Write(FormatComment(comment, lineBreakLength, managed ? "///     " : "//                  "));

            return(cs.ToString());
        }
        internal static string WriteFieldStatementsFirstLastWithSeparator(McgField[] fields,
                                                                          string firstStatement,
                                                                          string statement,
                                                                          string lastStatement,
                                                                          string separator)
        {
            StringCodeSink cs = new StringCodeSink();

            for (int i = 0; i < fields.Length; i++)
            {
                if (i == 0)
                {
                    cs.Write(WriteFieldStatement(fields[i], firstStatement));
                    cs.Write(separator);
                }
                else if (i < fields.Length - 1)
                {
                    cs.Write(WriteFieldStatement(fields[i], statement));
                    cs.Write(separator);
                }
                else
                {
                    cs.Write(WriteFieldStatement(fields[i], lastStatement));
                }
            }

            return(cs.ToString());
        }
        internal static string WriteFieldStatements(McgField[] fields, string statement)
        {
            StringCodeSink cs = new StringCodeSink();

            foreach (McgField field in fields)
            {
                cs.WriteBlock(WriteFieldStatement(field, statement));
            }

            return(cs.ToString());
        }
예제 #6
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        public override void Go()
        {
            string generatedPath =
                Path.Combine(
                    _resourceModel.OutputDirectory,
                    "src\\Graphics\\Include\\Generated"
                    );

            FileCodeSink cppFile = new FileCodeSink(generatedPath, "wgx_misc.h");;
            FileCodeSink csFile  = new FileCodeSink(generatedPath, "wgx_misc.cs");

            m_cpp = new StringCodeSink();
            m_cs  = new StringCodeSink();

            //
            // Write the definitions
            //

            WriteEnums();

            WriteStructs();

            //
            // Serialize the C++ header and the C# files for the Avalon commands:
            //

            Helpers.Style.WriteFileHeader(cppFile);
            cppFile.WriteBlock(m_cpp.ToString());

            csFile.WriteBlock(Helpers.ManagedStyle.WriteFileHeader("wgx_misc.cs"));
            csFile.WriteBlock(m_cs.ToString());


            cppFile.Dispose();
            csFile.Dispose();
        }
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        public override void Go()
        {
            string generatedPath =
                Path.Combine(
                    _resourceModel.OutputDirectory,
                    "src\\Graphics\\Include\\Generated"
                    );

            FileCodeSink cppFile = new FileCodeSink(generatedPath, "wgx_commands.h");;
            FileCodeSink csFile  = new FileCodeSink(generatedPath, "wgx_commands.cs");

            m_redirection = new StringCodeSink();
            m_dwm         = new StringCodeSink();
            m_cpp         = new StringCodeSink();
            m_cs          = new StringCodeSink();


            //
            // Collect the commands from the resource model and start generation.
            //

            PaddedCommandCollection commands =
                new PaddedCommandCollection(_resourceModel);

            // Contains list of Commands which contain security critical resources
            List <String> commandList = new List <String>();

            foreach (PaddedCommand command in commands.PaddedCommands)
            {
                if (command.Domain == "Redirection")
                {
                    WriteRedirectionCommand(command);
                }
                else if (command.Domain == "DWM")
                {
                    WriteDwmCommand(command);
                }
                else if (command.Origin != PaddedCommandOrigin.RenderDataInstruction)
                {
                    //
                    // Skip the render data instruction, they are emitted by
                    // the RenderData.cs generator...
                    //

                    WriteCommand(command);

                    // IsSecurityCritical does not make sense if the command is only for
                    // unmanaged code since its an attribute in managed code
                    if (command.CommandIsSecurityCritical && !command.CommandIsUnmanagedOnly)
                    {
                        commandList.Add(command.TypeName);
                    }
                }
            }

            // Parses the commands (which are securityCritical) to make switch-case statement.
            StringBuilder switchCaseBlock = MakeSwitchCaseStatement(commandList);

            //
            // Serialize the C++ header and the C# files for the Avalon commands:
            //

            Helpers.Style.WriteFileHeader(cppFile);
            cppFile.WriteBlock(m_cpp.ToString());

            csFile.WriteBlock(
                Helpers.ManagedStyle.WriteFileHeader("wgx_commands.cs"));

            csFile.WriteBlock(
        /// <summary>
        ///     FormatComment - formats a comment at a given line break length.
        /// </summary>
        /// <returns>
        ///     string - The string which contains the comment, or String.Empty if there's nothing to do.
        /// </returns>
        /// <param name="comment"> string - The comment itself. </param>
        /// <param name="lineBreakLength"> int - the line break length </param>
        /// <param name="lineLeader"> string - the leading string to prepend to each line</param>
        internal static string FormatComment(string comment,
                                             int lineBreakLength,
                                             string lineLeader)
        {
            if (comment == null)
            {
                return(String.Empty);
            }

            comment = comment.Replace("\r\n", "\n");
            comment = comment.Trim();

            StringCodeSink cs = new StringCodeSink();

            int  curChar   = 0;
            bool firstLine = true;

            while (curChar < comment.Length)
            {
                //
                // Find the appropriate line-break point
                //

                int firstNonSpace = curChar;

                while ((firstNonSpace < comment.Length) && Char.IsWhiteSpace(comment[firstNonSpace]))
                {
                    firstNonSpace++;
                }

                if (firstNonSpace == comment.Length)
                {
                    break;
                }

                int lastSpace = firstNonSpace + lineBreakLength - 1;

                //
                // The line-break point is the first occurrence of
                // a newline character, if one occurs within lineBreakLength
                // of the firstNonSpace.
                // We have to take a minimum because IndexOf requires that the
                // count doesn't go beyond the end of the string.
                //
                int firstNewline = comment.IndexOf(
                    '\n',
                    firstNonSpace,
                    Math.Min(lastSpace, comment.Length - 1) - firstNonSpace + 1);

                if (firstNewline != -1)
                {
                    lastSpace = firstNewline - 1;
                }
                else
                {
                    //
                    // If no newline characters appear within lineBreakLength of the
                    // firstNonSpace, the line-break point is the end of the comment,
                    // if the comment ends within lineBreakLength of the firstNonSpace
                    //
                    if (lastSpace >= comment.Length)
                    {
                        lastSpace = comment.Length - 1;
                    }
                    else
                    {
                        //
                        // Otherwise the line-break point is the last space
                        // character within lineBreakLength of the firstNonSpace.
                        //
                        while ((lastSpace > firstNonSpace) && !Char.IsWhiteSpace(comment[lastSpace]))
                        {
                            lastSpace--;
                        }

                        //
                        // If no space characters exist, then the line is unbreakable
                        // so we just break at lineBreakLength from firstNonSpace
                        //
                        if (lastSpace == firstNonSpace)
                        {
                            lastSpace = firstNonSpace + lineBreakLength - 1;
                        }
                    }
                }

                //
                // For all lines but the first we write a newline character to
                // terminate the previous line.
                //
                if (firstLine)
                {
                    firstLine = false;
                }
                else
                {
                    cs.Write("\n");
                }

                cs.Write(lineLeader);

                cs.Write(comment.Substring(firstNonSpace, lastSpace - firstNonSpace + 1));

                //
                // Set curChar to the beginning of the next line
                //
                curChar = lastSpace + 1;
            }

            return(cs.ToString());
        }