Esempio n. 1
0
        /// <summary>
        /// Determine whether this command is a "Gen" command (that is, generate OpenGL objects).
        /// </summary>
        /// <param name="ctx">
        /// The <see cref="RegistryContext"/> defining the OpenGL registry information.
        /// </param>
        /// <returns>
        /// It returns a boolean value indicating whether this Command is a Gen command.
        /// </returns>
        internal bool IsGenImplementation(RegistryContext ctx)
        {
            if (GetImplementationReturnType(ctx) != "void")
            {
                return(false);
            }
            if (!CommandParameterArrayLength.IsCompatible(ctx, this))
            {
                return(false);
            }

            string implementationName = GetImplementationNameBase(ctx);

            return(implementationName.StartsWith("Gen"));
        }
Esempio n. 2
0
        public virtual void WriteDebugAssertion(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
        {
            if (Length == null)
            {
                return;
            }

            if (CommandParameterArrayLength.IsCompatible(ctx, parentCommand, this))
            {
                sw.WriteLine("Debug.Assert({0}.Length >= {1});", ImplementationName, Length);
            }
#if false
            if (Regex.IsMatch(Length, @"[0-9]+"))
            {
                sw.WriteLine("Debug.Assert({0}.Length >= {1});", ImplementationName, Length);
            }
#endif
        }
Esempio n. 3
0
        /// <summary>
        /// Generate a list of function parameters determining the overloaded methods.
        /// </summary>
        /// <param name="ctx">
        /// The <see cref="RegistryContext"/> defining the OpenGL registry information.
        /// </param>
        /// <returns></returns>
        private List <CommandParameter>[] GetOverridenImplementations(RegistryContext ctx)
        {
            List <List <CommandParameter> > overridenParameters = new List <List <CommandParameter> >();

            // Force plain parameters
            bool plainParams = (Flags & CommandFlags.ForcePlainParams) != 0;
            // At least an array parameter that can out 1 element only
            bool outParamCompatible = CommandParameterOut.IsCompatible(ctx, this);
            // The last parameter is 'out-compatible', and flags allow to generate the override
            bool outLastParamCompatible = ((Flags & CommandFlags.OutParamLast) != 0) && CommandParameterOut.IsCompatible(ctx, this, Parameters[Parameters.Count - 1]);
            // At least a parameter that have a strongly typed representation
            bool isStrongCompatible = CommandParameterStrong.IsCompatible(ctx, this);
            // At least a parameter in meant as pointer/array, that can be represented using structs
            bool isPinnedObjCompatible = CommandParameterPinned.IsCompatible(ctx, this);
            // At least one parameter is an array with length correlated with another parameter
            bool isArrayLengthCompatible = CommandParameterArrayLength.IsCompatible(ctx, this);
            // At least one parameter is a pointer,
            bool isUnsafeCompatible = ((Flags & CommandFlags.UnsafeParams) != 0) && CommandParameterUnsafe.IsCompatible(ctx, this);

            // Standard implementation - default
            if (plainParams || (!isArrayLengthCompatible && !isStrongCompatible))
            {
                overridenParameters.Add(Parameters);
            }

            // Strongly typed implementation
            if (isStrongCompatible)
            {
                overridenParameters.Add(GetStrongParameters(ctx));
            }

            // Pinned object implementation
            if (isPinnedObjCompatible)
            {
                if (plainParams && isStrongCompatible)
                {
                    overridenParameters.Add(GetPinnedParameters(ctx, false));
                }
                overridenParameters.Add(GetPinnedParameters(ctx, true));
            }

            // Out modifier implementation
            if (outParamCompatible && !outLastParamCompatible)
            {
                if (plainParams && isStrongCompatible)
                {
                    overridenParameters.Add(GetOutParameters(ctx, false));
                }
                overridenParameters.Add(GetOutParameters(ctx, true));
            }

            // Out modifier implementation (last parameter only)
            if (outLastParamCompatible)
            {
                overridenParameters.Add(GetOutLastParameters(ctx));
            }

            // Array Length overrides
            if (isArrayLengthCompatible)
            {
                overridenParameters.Add(GetArrayLengthParameters(ctx));
            }

            if (isUnsafeCompatible)
            {
                overridenParameters.Add(GetUnsafeParameters(ctx));
            }

            return(overridenParameters.ToArray());
        }
Esempio n. 4
0
        /// <summary>
        /// Generate the command implementation (generate one object variant).
        /// </summary>
        /// <param name="sw">
        /// The <see cref="SourceStreamWriter"/> used to write the source code.
        /// </param>
        /// <param name="ctx">
        /// The <see cref="RegistryContext"/> defining the OpenGL registry information.
        /// </param>
        /// <param name="commandParams">
        /// A <see cref="T:List{CommandParameter}"/> determining the method overload.
        /// </param>
        private void GenerateImplementation_GenOneObject(SourceStreamWriter sw, RegistryContext ctx)
        {
            List <CommandParameter> commandParams = new List <CommandParameter>();
            string implementationName             = GetImplementationName(ctx);

            if (implementationName.EndsWith("ies"))
            {
                implementationName = implementationName.Substring(0, implementationName.Length - 3) + "y";
            }
            else if (implementationName.EndsWith("s"))
            {
                implementationName = implementationName.Substring(0, implementationName.Length - 1);
            }

            foreach (CommandParameter commandParameter in Parameters)
            {
                commandParams.Add(new CommandParameterArrayLength(commandParameter, ctx, this));
            }

            List <CommandParameterArrayLength> arrayParameters = new List <CommandParameterArrayLength>();
            List <CommandParameter>            signatureParams = commandParams.FindAll(delegate(CommandParameter item) {
                bool compatible       = CommandParameterArrayLength.IsCompatible(ctx, this, item);
                bool arrayLengthParam = CommandParameterArrayLength.IsArrayLengthParameter(item, ctx, this);

                if (compatible)
                {
                    arrayParameters.Add((CommandParameterArrayLength)item);
                }

                return(!compatible && !arrayLengthParam);
            });

            Debug.Assert(arrayParameters.Count == 1);
            CommandParameterArrayLength returnParameter = arrayParameters[0];
            string returnParameterType = returnParameter.GetImplementationType(ctx, this);

            // Remove []
            returnParameterType = returnParameterType.Substring(0, returnParameterType.Length - 2);

            // Signature
            GenerateImplementation_Signature(sw, ctx, signatureParams, implementationName, returnParameterType);

            // Implementation block
            sw.WriteLine("{");
            sw.Indent();

            #region Local Variables

            sw.WriteLine("{0}[] {1} = new {0}[1];", returnParameterType, ReturnVariableName);

            #endregion

            #region Implementation Call

            sw.WriteIdentation();
            sw.Write("{0}(", GetImplementationName(ctx));

            #region Parameters

            for (int i = 0; i < commandParams.Count; i++)
            {
                CommandParameter param = commandParams[i];

                if (CommandParameterArrayLength.IsArrayLengthParameter(param, ctx, this))
                {
                    continue;
                }
                else if (CommandParameterArrayLength.IsCompatible(ctx, this, param))
                {
                    sw.Write(ReturnVariableName);
                }
                else
                {
                    param.WriteDelegateParam(sw, ctx, this);
                }

                if (i != commandParams.Count - 1)
                {
                    sw.Write(", ");
                }
            }

            #endregion

            sw.Write(");");
            sw.WriteLine();

            sw.WriteLine("return ({0}[0]);", ReturnVariableName);

            #endregion

            sw.Unindent();
            sw.WriteLine("}");
        }