/// <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());
        }
Beispiel #2
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods


        /// <summary>
        ///     Controller method that generates each enumeration in the XML description.
        /// </summary>
        public override void Go()
        {
            foreach (McgEnum enumType in _resourceModel.AllEnums)
            {
                if (!_resourceModel.ShouldGenerate(CodeSections.ManagedClass, enumType))
                {
                    continue;
                }

                //
                // Generate enum values & validation code sinks
                //                    
                    
                StringCodeSink enumValuesCS = new StringCodeSink();
                StringCodeSink checkEnumValues = new StringCodeSink();

                bool first = true;
                foreach(McgEnumValue enumValue in enumType.AllValues)
                {
                    if (enumValue.UnmanagedOnly)
                    {
                        continue;
                    }

                    enumValuesCS.WriteBlock(
        /// <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>
        ///     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());
        }
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        public override void Go()
        {
            //
            // Opened the generated files
            //

            string generatedPath =
                Path.Combine(
                    _resourceModel.OutputDirectory,
                    "src\\Graphics\\Include\\Generated"
                    );

            string extensionPath =
                Path.Combine(
                    _resourceModel.OutputDirectory,
                    "src\\Graphics\\exts"
                    );

            FileCodeSink enumFile =
                new FileCodeSink(generatedPath, "wgx_command_types.h");

            FileCodeSink enumCsFile =
                new FileCodeSink(generatedPath, "wgx_command_types.cs");

            FileCodeSink extsFile =
                new FileCodeSink(extensionPath, "cmdstruct.h");

            m_redirectionEnum  = new StringCodeSink();
            m_redirectionTypes = new StringCodeSink();
            m_dwmEnum          = new StringCodeSink();
            m_enum             = new StringCodeSink();
            m_milTypes         = new StringCodeSink();
            m_exts             = new StringCodeSink();


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

            PaddedCommandCollection paddedCommands =
                new PaddedCommandCollection(_resourceModel);


            /* ------------------------------------------------------------- */
            /* -- EMIT THE REDIRECTION COMMANDS ---------------------------- */
            /* ------------------------------------------------------------- */

            uint redirectionCommandIndex = 1;

            m_redirectionEnum.Write(
Beispiel #8
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        public override void Go()
        {
            //
            // Opened the generated files
            //

            string generatedPath =
                Path.Combine(
                    _resourceModel.OutputDirectory,
                    "src\\Graphics\\core\\uce"
                    );

            FileCodeSink chFile =
                new FileCodeSink(generatedPath, "generated_resource_factory.h");

            FileCodeSink ccFile =
                new FileCodeSink(generatedPath, "generated_resource_factory.cpp");

            m_factory = new StringCodeSink();


            //
            // Collect the resource types...
            //

            foreach (McgResource resource in _resourceModel.Resources)
            {
                if (resource.IsValueType ||
                    resource.IsAbstract ||
                    !resource.HasUnmanagedResource)
                {
                    //
                    // Do not allow creation of value types (Int32 etc.) or abstract resources.
                    //

                    continue;
                }

                EmitResourceCreator(resource);
            }


            //
            // Serialize the C++ file containing the resource factory implementation
            //

            Helpers.Style.WriteFileHeader(ccFile);

            ccFile.WriteBlock(
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        public override void Go()
        {
            //
            // Opened the generated files
            //

            string generatedPath =
                Path.Combine(
                    _resourceModel.OutputDirectory,
                    "src\\Graphics\\Include\\Generated"
                    );

            FileCodeSink ccFile =
                new FileCodeSink(generatedPath, "wgx_resource_types.h");

            FileCodeSink csFile =
                new FileCodeSink(generatedPath, "wgx_resource_types.cs");

            m_enum = new StringCodeSink();


            //
            // Collect the resource types...
            //

            m_resourceIndex = 1;

            foreach (McgResource resource in _resourceModel.Resources)
            {
                if (resource.IsValueType || !resource.HasUnmanagedResource)
                {
                    continue;
                }

                EmitTypeOfResource(resource);
            }


            //
            // Serialize the C++ header and the C# files:
            //

            Helpers.Style.WriteFileHeader(ccFile);

            ccFile.WriteBlock(
Beispiel #10
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

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

            FileCodeSink processMessageFile = new FileCodeSink(generatedPath, "generated_process_message.inl");

            m_processMessage = new StringCodeSink();


            //
            // Walk the padded commands and build the message processing routine:
            //

            PaddedCommandCollection commands =
                new PaddedCommandCollection(_resourceModel);

            foreach (PaddedCommand command in commands.PaddedCommands)
            {
                if (command.Origin == PaddedCommandOrigin.RenderDataInstruction
                    || command.Domain == "DWM" 
                    || command.Domain == "Redirection" 
                    || command.Domain == "RenderData" 
                    || (command.Domain == "Transport" && command.Target == "Ts")
                    || (command.Target == String.Empty && command.Name == "GlyphBitmap")
                    || command.Name == "GradientStop")
                {
                    continue;
                }

                WriteCommandHandler(command);
            }


            //
            // Serialize the resulting routine
            //
            
            Helpers.Style.WriteFileHeader(processMessageFile);

            processMessageFile.WriteBlock(
Beispiel #11
0
        private void WriteGetHashCode(McgResource resource,
                                      StringCodeSink cs)
        {
            // At this time, we only know how to emit GetHashCode() for value types
            if (!resource.IsValueType) return;

            string getHashCodeBody = String.Empty;

            if (resource.LocalFields.Length < 1)
            {
                throw new System.NotSupportedException("Do not attempt to generate local fields for resources without local fields.");
            }
            else
            {
                StringCodeSink returnStmt = new StringCodeSink();

                // The inline block intentionally lacks a newline so that the first field
                // will be on the same line as the return.
                returnStmt.Write(
Beispiel #12
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(
Beispiel #14
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        public override void Go()
        {
            //
            // The MIL and DWM SDK versions are automagically calculated from the
            // UCE and DWM/redirection protocol fingerprints and manually incremented
            // SDK revisions.
            //

            uint uiDwmSdkVersion = 0, uiMilSdkVersion = 0;

            string generatedPath =
                Path.Combine(
                    _resourceModel.OutputDirectory,
                    "src\\Graphics\\Include\\Generated"
                    );

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

            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>();


            //
            // Calculate the fingerprints of UCE and DWM protocols. Do it in two
            // passes and re-initialize the not-so-random number generator so that
            // DWM protocol changes do not affect MIL (and vice versae).
            //

            unchecked
            {
                InitializeSeeds();

                uint uiDwmFingerprint = Seed;

                foreach (PaddedCommand command in commands.PaddedCommands)
                {
                    if (command.Domain == "Redirection" || command.Domain == "DWM")
                    {
                        uiDwmFingerprint = Ror(uiDwmFingerprint ^ GetCommandHash(command));
                    }
                }

                uiDwmSdkVersion = uiDwmFingerprint;
            }


            unchecked
            {
                InitializeSeeds();

                uint uiMilFingerprint = Seed;

                foreach (PaddedCommand command in commands.PaddedCommands)
                {
                    if (command.Domain != "Redirection" && command.Domain != "DWM")
                    {
                        uiMilFingerprint = Ror(uiMilFingerprint ^ GetCommandHash(command));
                    }
                }

                uiMilSdkVersion = uiMilFingerprint;
            }


            //
            // Take into account the manually incremented SDK revisions
            //

            unchecked
            {
                XmlDocument document = LoadDocument("xml\\Version.xml", "xml\\Version.xsd");

                string milSdkVersion = document.SelectSingleNode("/MilVersion/MilSdkVersion").InnerText;
                string dwmSdkVersion = document.SelectSingleNode("/MilVersion/DwmSdkVersion").InnerText;

                uiMilSdkVersion = Ror(uiMilSdkVersion ^ (Convert.ToUInt32(milSdkVersion) * 0x13579BDF));
                uiDwmSdkVersion = Ror(uiDwmSdkVersion ^ (Convert.ToUInt32(dwmSdkVersion) * 0xFDB97531));
            }


            //
            // Serialize the C++ header and the C# files:
            //

            Helpers.Style.WriteFileHeader(cppFile);

            cppFile.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());
        }