Exemplo n.º 1
0
        public override void WriteCallLogArgParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
        {
            if (IsArrayLengthParameter(this, ctx, parentCommand))
            {
                CommandParameter arrayParam = GetArrayParameter(this, ctx, parentCommand);

                switch (arrayParam.LengthMode)
                {
                case CommandParameterLengthMode.ArgumentReference:
                    sw.Write("{0}.Length", arrayParam.GetDelegateCallVarName(parentCommand));
                    break;

                case CommandParameterLengthMode.ArgumentMultiple:
                    uint multiple = arrayParam.LengthMultiple;

                    if (multiple > 1)
                    {
                        sw.Write("{0}.Length / {1}", arrayParam.GetDelegateCallVarName(parentCommand), multiple);
                    }
                    else
                    {
                        sw.Write("{0}.Length", arrayParam.GetDelegateCallVarName(parentCommand));
                    }
                    break;
                }
            }
            else
            {
                base.WriteCallLogArgParam(sw, ctx, parentCommand);
            }
        }
Exemplo n.º 2
0
        public override void WriteDelegateParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
        {
            string paramModifier = GetImplementationTypeModifier(ctx, parentCommand);

            if (mIsPinned)
            {
                if (paramModifier != null)
                {
                    sw.Write("{0} ", paramModifier);
                }
                // Object parameters are pinned
                sw.Write("{0}.AddrOfPinnedObject()", PinnedLocalVarName);
            }
            else if (IsFixed(ctx, parentCommand))
            {
                if (paramModifier != null)
                {
                    sw.Write("{0} ", paramModifier);
                }
                // Fixed parameters are fixed in overloaded method call
                sw.Write(DelegateCallVarName);
            }
            else
            {
                base.WriteDelegateParam(sw, ctx, parentCommand);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generate the command delegate source code.
        /// </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>
        internal void GenerateDelegate(SourceStreamWriter sw, RegistryContext ctx)
        {
            // No sure if it is really necessary
            sw.WriteLine("[SuppressUnmanagedCodeSecurity()]");

            // Delegate type definition
            sw.WriteIdentation(); sw.Write("internal ");
            if (IsSafeImplementation == false)
            {
                sw.Write("unsafe ");
            }
            sw.Write("delegate ");

            sw.Write("{0} {1}(", DelegateReturnType, ImportName);

            int paramCount = Parameters.Count;

            foreach (CommandParameter param in Parameters)
            {
                string paramAttributes = param.GetDelegateTypeAttributes(ctx, this);
                string paramModifier   = param.GetDelegateTypeModifier(ctx, this);

                if (paramAttributes != null)
                {
                    sw.Write("{0} ", paramAttributes);
                }
                if (paramModifier != null)
                {
                    sw.Write("{0} ", paramModifier);
                }


                sw.Write("{0} {1}", param.GetDelegateType(ctx, this), param.ImportName);
                paramCount--;
                if (paramCount > 0)
                {
                    sw.Write(", ");
                }
            }
            sw.Write(");");
            sw.WriteLine();

            sw.WriteLine();
            if (Aliases.Count > 0)
            {
                sw.WriteLine("[AliasOf(\"{0}\")]", ImportName);
                foreach (Command aliasOf in Aliases)
                {
                    sw.WriteLine("[AliasOf(\"{0}\")]", aliasOf.ImportName);
                }
            }

            // Required on Windows platform: different threads can bind different OpenGL context, which can have different
            // entry points
            sw.WriteLine("[ThreadStatic]");

            // Delegate field
            sw.WriteLine("internal static {0} {1};", ImportName, DelegateName);
        }
Exemplo n.º 4
0
 public virtual void WriteDelegateParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
 {
     if (IsFixed(ctx, parentCommand) == false)
     {
         sw.Write(DelegateCallVarName);
     }
     else
     {
         sw.Write(FixedLocalVarName);
     }
 }
Exemplo n.º 5
0
 public static void WriteCallLogArgParam(SourceStreamWriter sw, string implementationName, string implementationType)
 {
     if (implementationType.EndsWith("*"))
     {
         sw.Write("new IntPtr({0})", implementationName);
     }
     //else if (implementationType == "IntPtr")
     //	sw.Write("{0}.ToString(\"X8\")", implementationName);
     else
     {
         sw.Write("{0}", implementationName);
     }
 }
Exemplo n.º 6
0
        public virtual void WriteCallLogFormatParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand, int paramIndex)
        {
            string implementationType     = GetImplementationType(ctx, parentCommand);
            bool   safeImplementationType = !implementationType.EndsWith("*") && implementationType != "IntPtr";

            if (safeImplementationType == false)
            {
                sw.Write("0x{{{0}}}", paramIndex);
            }
            else
            {
                sw.Write("{{{0}}}", paramIndex);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Generate the C# source code for this enumerant.
        /// </summary>
        /// <param name="sw">
        /// A <see cref="SourceStreamWriter"/> used for writing the source code.
        /// </param>
        internal void GenerateSource(SourceStreamWriter sw, RegistryContext ctx)
        {
            if (sw == null)
            {
                throw new ArgumentNullException("sw");
            }

            RegistryDocumentation.GenerateDocumentation(sw, ctx, this);

            foreach (Enumerant aliasOf in AliasOf)
            {
                sw.WriteLine("[AliasOf(\"{0}\")]", aliasOf.Name);
            }

            foreach (IFeature feature in RequiredBy)
            {
                sw.WriteLine("[RequiredByFeature(\"{0}\")]", feature.Name);
            }
            foreach (Enumerant aliasOf in AliasOf)
            {
                foreach (IFeature feature in aliasOf.RequiredBy)
                {
                    sw.WriteLine("[RequiredByFeature(\"{0}\")]", feature.Name);
                }
            }
            foreach (IFeature feature in RemovedBy)
            {
                sw.WriteLine("[RemovedByFeature(\"{0}\")]", feature.Name);
            }

            // This metadata is used for procedure logging function
            bool requiresLogAttribute = ParentEnumerantBlock.Type == "bitmask";

            if (requiresLogAttribute == true)
            {
                if (ParentEnumerantBlock.Type == "bitmask")
                {
                    sw.WriteLine("[Log(BitmaskName = \"{0}\")]", ParentEnumerantBlock.Namespace);
                }
            }

            if (IsDeprecated)
            {
                sw.Write("#if DEBUG && !OPENGL_NET_COMPATIBILITY_PROFILE" + Environment.NewLine);
                sw.WriteLine("[Obsolete(\"Deprecated/removed by {0}.\")]", SpecificationStyle.GetKhronosVersionHumanReadable(RemovedBy[0].Name));
                sw.Write("#endif" + Environment.NewLine);
            }

            sw.WriteLine(Declaration);
        }
Exemplo n.º 8
0
 public static void WriteCallLogArgParam(SourceStreamWriter sw, string implementationName, string implementationType)
 {
     if (implementationType.EndsWith("*"))
     {
         sw.Write("{0} != null ? {0}->ToString() : \"(null)\"", implementationName);
     }
     else if (implementationType == "IntPtr")
     {
         sw.Write("{0}.ToString(\"X8\")", implementationName);
     }
     else
     {
         sw.Write("{0}", implementationName);
     }
 }
Exemplo n.º 9
0
		public override void WriteDelegateParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			if (mIsStrong) {
				// Strongly typed enum must be casted to delegate call type (int or uint)
				sw.Write("({0}){1}", OverridenParameter.ImportType, DelegateCallVarName);
			} else
				base.WriteDelegateParam(sw, ctx, parentCommand);
		}
Exemplo n.º 10
0
        public virtual void WriteCallLogArgParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
        {
            CommandFlagsDatabase.CommandItem.ParameterItemFlags parameterFlags = CommandFlagsDatabase.GetCommandParameterFlags(parentCommand, this);

            if (((Type != null) && (Type == "GLenum")) || ((parameterFlags & CommandFlagsDatabase.CommandItem.ParameterItemFlags.LogAsEnum) != 0))
            {
                sw.Write("LogEnumName({0})", ImplementationName);
            }
            else if (IsManagedArray && GetImplementationTypeModifier(ctx, parentCommand) != "out")
            {
                sw.Write("LogValue({0})", ImplementationName);
            }
            else
            {
                WriteCallLogArgParam(sw, ImplementationName, GetImplementationType(ctx, parentCommand));
            }
        }
Exemplo n.º 11
0
        public virtual void WriteDelegateParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
        {
            if (IsFixed(ctx, parentCommand) == false)
            {
                string modifier = CommandFlagsDatabase.GetCommandArgumentModifier(parentCommand, this);

                if (modifier != null)
                {
                    sw.Write(modifier + " ");
                }

                sw.Write(GetDelegateCallVarName(parentCommand));
            }
            else
            {
                sw.Write(FixedLocalVarName);
            }
        }
Exemplo n.º 12
0
 public override void WriteCallLogArgParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
 {
     if (_IsPointer == true)
     {
         sw.Write("new IntPtr({0}).ToString(\"X8\")", ImplementationName);
     }
     else
     {
         base.WriteCallLogArgParam(sw, ctx, parentCommand);
     }
 }
Exemplo n.º 13
0
        public override void WriteDelegateParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
        {
            if (IsArrayLengthParameter(this, ctx, parentCommand))
            {
                int arrayLengthParamIndex = parentCommand.Parameters.FindIndex(delegate(CommandParameter item) {
                    return(parentCommand.Parameters.FindIndex(delegate(CommandParameter subitem) { return (item.Length == Name); }) >= 0);
                });

                if (OverridenParameter.ImportType != "int")
                {
                    sw.Write("({0})", OverridenParameter.ImportType);
                }

                sw.Write("{0}.Length", parentCommand.Parameters[arrayLengthParamIndex].DelegateCallVarName);
            }
            else
            {
                base.WriteDelegateParam(sw, ctx, parentCommand);
            }
        }
Exemplo n.º 14
0
 public override void WriteDelegateParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
 {
     if (mIsStrong)
     {
         // Strongly typed enum must be casted to delegate call type (int or uint)
         sw.Write("({0}){1}", OverridenParameter.GetImportType(parentCommand), GetDelegateCallVarName(parentCommand));
     }
     else
     {
         base.WriteDelegateParam(sw, ctx, parentCommand);
     }
 }
Exemplo n.º 15
0
 public override void WriteDelegateParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
 {
     if (_IsPointer == true)
     {
         // Writer plain variable name
         sw.Write(DelegateCallVarName);
     }
     else
     {
         base.WriteDelegateParam(sw, ctx, parentCommand);
     }
 }
Exemplo n.º 16
0
        /// <summary>
        /// Generate the command import source code.
        /// </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>
        internal void GenerateImport(SourceStreamWriter sw, RegistryContext ctx)
        {
            // The SuppressUnmanagedCodeSecurity attribute is used to increase P/Invoke performance
            sw.WriteLine("[SuppressUnmanagedCodeSecurity()]");
            // Import definition
            CommandFlags commandFlags = CommandFlagsDatabase.GetCommandFlags(this);

            if ((commandFlags & CommandFlags.SetLastError) != 0)
            {
                sw.WriteLine("[DllImport(Library, EntryPoint = \"{0}\", ExactSpelling = true, SetLastError = true)]", ImportName);
            }
            else
            {
                sw.WriteLine("[DllImport(Library, EntryPoint = \"{0}\", ExactSpelling = true)]", ImportName);
            }

            // GLboolean is mapped to 'unsigned char': instruct to marshal return value as 1 byte boolean
            if (Prototype.Type == "GLboolean")
            {
                sw.WriteLine("[return: MarshalAs(UnmanagedType.I1)]");
            }
            // BOOL is mapped to 'unsigned int': instruct to marshal return value as 4 byte boolean
            if (Prototype.Type == "BOOL")
            {
                sw.WriteLine("[return: MarshalAs(UnmanagedType.Bool)]");
            }

            // Import declaration
            sw.WriteIdentation(); sw.Write("internal extern static ");
            if (IsSafeImplementation == false)
            {
                sw.Write("unsafe ");
            }

            sw.Write("{0} {1}(", DelegateReturnType, ImportName);

            int paramCount = Parameters.Count;

            foreach (CommandParameter param in Parameters)
            {
                sw.Write("{0} {1}", param.ImportType, param.ImportName);
                paramCount--;
                if (paramCount > 0)
                {
                    sw.Write(", ");
                }
            }
            sw.Write(");");
            sw.WriteLine();
        }
Exemplo n.º 17
0
		public virtual void WriteCallLogFormatParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand, int paramIndex)
		{
			string implementationType = GetImplementationType(ctx, parentCommand);
			bool safeImplementationType = !implementationType.EndsWith("*") && implementationType != "IntPtr";

			if (safeImplementationType == false)
				sw.Write("0x{{{0}}}", paramIndex);
			else
				sw.Write("{{{0}}}", paramIndex);
		}
		public override void WriteCallLogArgParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			if (_IsPointer == true) {
				sw.Write("new IntPtr({0}).ToString(\"X8\")", ImplementationName);
			} else
				base.WriteCallLogArgParam(sw, ctx, parentCommand);
		}
Exemplo n.º 19
0
		public virtual void WriteDelegateParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			if (IsFixed(ctx, parentCommand) == false) {
				sw.Write(DelegateCallVarName);
			} else
				sw.Write(FixedLocalVarName);
		}
Exemplo n.º 20
0
		/// <summary>
		/// Generate the command implementation signature and the method documentation.
		/// </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_Signature(SourceStreamWriter sw, RegistryContext ctx, List<CommandParameter> commandParams, string implementationName, string returnType)
		{
#if !DEBUG
			// Documentation
			RegistryDocumentation.GenerateDocumentation(sw, ctx, this, commandParams);
#endif

			foreach (IFeature feature in RequiredBy)
				sw.WriteLine("[RequiredByFeature(\"{0}\")]", feature.Name);
			foreach (IFeature feature in RemovedBy)
				sw.WriteLine("[RemovedByFeature(\"{0}\")]", feature.Name);

			#region Signature

			sw.WriteIdentation();

			// Signature
			sw.Write("{0} static ", CommandFlagsDatabase.GetCommandVisibility(this));
			if (IsUnsafeImplementationSignature(ctx, commandParams))
				sw.Write("unsafe ");
			sw.Write("{0} {1}(", returnType, implementationName);
			// Signature - Parameters
			int paramCount = commandParams.FindAll(delegate(CommandParameter item) { return (!item.IsImplicit(ctx, this)); }).Count;

			foreach (CommandParameter param in commandParams) {
				// Skip in signature implicit parameters
				if (param.IsImplicit(ctx, this))
					continue;

				string paramAttributes = param.GetImplementationTypeAttributes(ctx, this);
				string paramModifier = param.GetImplementationTypeModifier(ctx, this);

				if (paramAttributes != null)
					sw.Write("{0} ", paramAttributes);
				if (paramModifier != null)
					sw.Write("{0} ", paramModifier);

				if ((paramCount == 1) && (param.IsManagedArray) && ((Flags & CommandFlags.VariadicParams) != 0))
					sw.Write("params ");

				sw.Write("{0} {1}", param.GetImplementationType(ctx, this), param.ImplementationName);
				paramCount--;
				if (paramCount > 0)
					sw.Write(", ");
			}
			sw.Write(")");
			sw.WriteLine();

			#endregion
		}
		public override void WriteDelegateParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			if (_IsPointer == true) {
				// Writer plain variable name
				sw.Write(DelegateCallVarName);
			} else
				base.WriteDelegateParam(sw, ctx, parentCommand);
		}
Exemplo n.º 22
0
		/// <summary>
		/// Generate the command implementation (fixed 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_Default(SourceStreamWriter sw, RegistryContext ctx, List<CommandParameter> commandParams)
		{
			List<Command> aliases = new List<Command>();
			Command aliasCommand = this;

			// The implementation returned type
			string returnType = aliasCommand.GetImplementationReturnType(ctx);
			// Is fixed implementation
			bool fixedImplementation = IsFixedImplementation(ctx, commandParams);

			aliases.Add(this);
			aliases.AddRange(Aliases);

			// Signature
			GenerateImplementation_Signature(sw, ctx, commandParams);

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

			#region Debug Assertions

			// Debug assertions
			foreach (CommandParameter param in commandParams)
				param.WriteDebugAssertion(sw, ctx, this);

			#endregion

			#region Local Variables

			// Local variable: returned value
			if (HasReturnValue) {
				sw.WriteLine("{0} {1};", DelegateReturnType, ReturnVariableName);
				sw.WriteLine();
			}

			#endregion

			#region Unsafe Block (Open)

			if (fixedImplementation) {
				sw.WriteLine("unsafe {");								// (1)
				sw.Indent();

				foreach (CommandParameter param in commandParams)
					param.WriteFixedStatement(sw, ctx, this);

				sw.WriteLine("{");										// (2)
				sw.Indent();
			}

			#endregion

			sw.WriteLine("Debug.Assert(Delegates.{0} != null, \"{0} not implemented\");", aliasCommand.DelegateName);

			#region Delegate Call

			sw.WriteIdentation();

			// Local return value
			if (HasReturnValue) 
				sw.Write("{0} = ", ReturnVariableName);

			sw.Write("Delegates.{0}(", aliasCommand.DelegateName);

			#region Parameters

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

				param.WriteDelegateParam(sw, ctx, this);

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

			#endregion

			sw.Write(")");

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

			#endregion

			#region Call Log

			sw.WriteIdentation(); sw.Write("LogFunction(");

			#region Call Log - Format String

			sw.Write("\"{0}(", aliasCommand.ImportName);
			for (int i = 0; i < commandParams.Count; i++)
			{
				commandParams[i].WriteCallLogFormatParam(sw, ctx, this, i);
				if (i < commandParams.Count - 1)
					sw.Write(", ");
			}
			sw.Write(")");

			if (HasReturnValue)
				sw.Write(" = {{{0}}}", commandParams.Count);

			sw.Write("\"");

			#endregion

			#region Call Log - Format Arguments

			if ((commandParams.Count > 0) || HasReturnValue) {
				sw.Write(", ");

				for (int i = 0; i < commandParams.Count; i++) {
					commandParams[i].WriteCallLogArgParam(sw, ctx, this);
					if (i < commandParams.Count - 1)
						sw.Write(", ");
				}
			}

			// Return value
			if (HasReturnValue)
			{
				if (commandParams.Count > 0)
					sw.Write(", ");
				CommandParameter.WriteCallLogArgParam(sw, GetReturnValueExpression(ctx), returnType);
			}

			#endregion

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

			#endregion

			#region Unsafe Block (Close)

			if (fixedImplementation)
			{
				sw.Unindent();
				sw.WriteLine("}");										// (2) CLOSED
				sw.Unindent();
				sw.WriteLine("}");										// (1) CLOSED
			}

			#endregion

			// Check call errors
			if ((Flags & CommandFlags.NoGetError) == 0) {
				string returnValue = "null";

				// Optionally pass the returned value to error checking method
				if (HasReturnValue)
					returnValue = ReturnVariableName;

				sw.WriteLine("DebugCheckErrors({0});", returnValue);
			}

			// Returns value
			if (HasReturnValue) {
				sw.WriteLine();
				sw.WriteLine("return ({0});", GetReturnValueExpression(ctx));
			}

			sw.Unindent();
			sw.WriteLine("}");
		}
Exemplo n.º 23
0
        /// <summary>
        /// Generate the command delegate source code.
        /// </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>
        internal void GenerateDelegate(SourceStreamWriter sw, RegistryContext ctx)
        {
            // Attributes required for checking API commands support
            string classDefaultApi = ctx.Class.ToLower();

            foreach (IFeature feature in RequiredBy)
            {
                sw.WriteLine(feature.GenerateRequiredByAttribute(this, classDefaultApi));
            }

            foreach (IFeature feature in RemovedBy)
            {
                sw.WriteLine(feature.GenerateRemovedByAttribute(classDefaultApi));
            }

            // Not yet sure if it is really necessary
            sw.WriteLine("[SuppressUnmanagedCodeSecurity()]");

            // Delegate type definition
            sw.WriteIdentation(); sw.Write("internal ");
            if (IsSafeImplementation == false)
            {
                sw.Write("unsafe ");
            }
            sw.Write("delegate ");

            sw.Write("{0} {1}(", DelegateReturnType, ImportName);

            int paramCount = Parameters.Count;

            foreach (CommandParameter param in Parameters)
            {
                string paramAttributes = param.GetDelegateTypeAttributes(ctx, this);
                string paramModifier   = param.GetDelegateTypeModifier(ctx, this);

                if (paramAttributes != null)
                {
                    sw.Write("{0} ", paramAttributes);
                }
                if (paramModifier != null)
                {
                    sw.Write("{0} ", paramModifier);
                }


                sw.Write("{0} {1}", param.GetDelegateType(ctx, this), param.ImportName);
                paramCount--;
                if (paramCount > 0)
                {
                    sw.Write(", ");
                }
            }
            sw.Write(");");
            sw.WriteLine();

            sw.WriteLine();

            foreach (IFeature feature in RequiredBy)
            {
                sw.WriteLine(feature.GenerateRequiredByAttribute(this, classDefaultApi));
            }

            foreach (IFeature feature in RemovedBy)
            {
                sw.WriteLine(feature.GenerateRemovedByAttribute(classDefaultApi));
            }

            // Required on Windows platform: different threads can bind different OpenGL context, which can have different
            // entry points
            if (ctx.Class == "Gl")
            {
                sw.WriteLine("[ThreadStatic]");
            }

            // Delegate field
            sw.WriteLine("internal static {0} {1};", ImportName, DelegateName);
        }
Exemplo n.º 24
0
		public static void WriteCallLogArgParam(SourceStreamWriter sw, string implementationName, string implementationType)
		{
			if (implementationType.EndsWith("*"))
				sw.Write("{0} != null ? {0}->ToString() : \"(null)\"", implementationName);
			else if (implementationType == "IntPtr")
				sw.Write("{0}.ToString(\"X8\")", implementationName);
			else
				sw.Write("{0}", implementationName);
		}
		public override void WriteDelegateParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			string paramModifier = GetImplementationTypeModifier(ctx, parentCommand);

			if        (mIsPinned) {
				if (paramModifier != null)
					sw.Write("{0} ", paramModifier);
				// Object parameters are pinned
				sw.Write("{0}.AddrOfPinnedObject()", PinnedLocalVarName);
			} else if (IsFixed(ctx, parentCommand)) {
				if (paramModifier != null)
					sw.Write("{0} ", paramModifier);
				// Fixed parameters are fixed in overloaded method call
				sw.Write(DelegateCallVarName);
			} else
				base.WriteDelegateParam(sw, ctx, parentCommand);
		}
Exemplo n.º 26
0
 public virtual void WriteImplementationParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
 {
     sw.Write(DelegateCallVarName);
 }
Exemplo n.º 27
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("}");
        }
Exemplo n.º 28
0
		/// <summary>
		/// Generate the C# source code for this enumerant.
		/// </summary>
		/// <param name="sw">
		/// A <see cref="SourceStreamWriter"/> used for writing the source code.
		/// </param>
		internal void GenerateSource(SourceStreamWriter sw, RegistryContext ctx)
		{
			if (sw == null)
				throw new ArgumentNullException("sw");

			RegistryDocumentation.GenerateDocumentation(sw, ctx, this);

			foreach (Enumerant aliasOf in AliasOf)
				sw.WriteLine("[AliasOf(\"{0}\")]", aliasOf.Name);

			foreach (IFeature feature in RequiredBy)
				sw.WriteLine("[RequiredByFeature(\"{0}\")]", feature.Name);
			foreach (Enumerant aliasOf in AliasOf) {
				foreach (IFeature feature in aliasOf.RequiredBy)
					sw.WriteLine("[RequiredByFeature(\"{0}\")]", feature.Name);
			}
			foreach (IFeature feature in RemovedBy)
				sw.WriteLine("[RemovedByFeature(\"{0}\")]", feature.Name);

			if (IsDeprecated) {
				sw.Write("#if DEBUG && !OPENGL_NET_COMPATIBILITY_PROFILE" + Environment.NewLine);
				sw.WriteLine("[Obsolete(\"Deprecated/removed by {0}.\")]", SpecificationStyle.GetHumanToken(RemovedBy[0].Name));
				sw.Write("#endif" + Environment.NewLine);
			}

			sw.WriteLine(Declaration);
		}
Exemplo n.º 29
0
		/// <summary>
		/// Generate the command import source code.
		/// </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>
		internal void GenerateImport(SourceStreamWriter sw, RegistryContext ctx)
		{
			// The SuppressUnmanagedCodeSecurity attribute is used to increase P/Invoke performance
			sw.WriteLine("[SuppressUnmanagedCodeSecurity()]");
			// Import definition
			sw.WriteLine("[DllImport(Library, EntryPoint = \"{0}\", ExactSpelling = true)]", ImportName);

			// GLboolean is mapped to 'unsigned char': instruct to marshal return value as 1 byte boolean
			if (Prototype.Type == "GLboolean")
				sw.WriteLine("[return: MarshalAs(UnmanagedType.I1)]");
			// BOOL is mapped to 'unsigned int': instruct to marshal return value as 4 byte boolean
			if (Prototype.Type == "BOOL")
				sw.WriteLine("[return: MarshalAs(UnmanagedType.Bool)]");

			// Import declaration
			sw.WriteIdentation(); sw.Write("internal extern static ");
			if (IsSafeImplementation == false) sw.Write("unsafe ");

			sw.Write("{0} {1}(", DelegateReturnType, ImportName);

			int paramCount = Parameters.Count;

			foreach (CommandParameter param in Parameters) {
				sw.Write("{0} {1}", param.ImportType, param.ImportName);
				paramCount--;
				if (paramCount > 0)
					sw.Write(", ");
			}
			sw.Write(");");
			sw.WriteLine();
		}
Exemplo n.º 30
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 CommandParameterArray(commandParameter, ctx, this));

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

				if (compatible)
					arrayParameters.Add((CommandParameterArray)item);

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

			Debug.Assert(arrayParameters.Count == 1);
			CommandParameterArray 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        (CommandParameterArray.IsArrayLengthParameter(param, ctx, this)) {
					continue;
				} else if (CommandParameterArray.IsCompatible(param, ctx, this))
					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("}");
		}
Exemplo n.º 31
0
		/// <summary>
		/// Generate the command implementation (pinned 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_Pinned(SourceStreamWriter sw, RegistryContext ctx, List<CommandParameter> commandParams)
		{
			// Signature
			GenerateImplementation_Signature(sw, ctx, commandParams);

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

			#region Pinned Object Block (Open)

			foreach (CommandParameter param in commandParams)
				param.WritePinnedVariable(sw, ctx, this);

			sw.WriteLine("try {");
			sw.Indent();

			#endregion

			#region Implementation Call

			sw.WriteIdentation();
			if (HasReturnValue)
				sw.Write("return (");

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

			#region Parameters

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

				param.WriteDelegateParam(sw, ctx, this);

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

			#endregion

			sw.Write(")");

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

			#endregion

			#region Pinned Object Block (Close)

			sw.Unindent();
			sw.WriteLine("} finally {");
			sw.Indent();

			foreach (CommandParameter param in commandParams)
				param.WriteUnpinCommand(sw, ctx, this);

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

			#endregion

			sw.Unindent();
			sw.WriteLine("}");
		}
Exemplo n.º 32
0
		/// <summary>
		/// Generate the command implementation (fixed 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_Default(SourceStreamWriter sw, RegistryContext ctx, List<CommandParameter> commandParams)
		{
			List<Command> aliases = new List<Command>();
			Command aliasCommand = this;

			// The implementation returned type
			string returnType = aliasCommand.GetImplementationReturnType(ctx);
			// The delegate returned type
			string delegateReturnType = aliasCommand.DelegateReturnType;

			bool fixedImplementation = IsFixedImplementation(ctx, commandParams);
			// At least one parameter is an array with length correlated with another parameter
			bool isArrayImplementation = commandParams.FindIndex(delegate(CommandParameter item) { return (item is CommandParameterArray); }) >= 0;
			// Returned value must be marshalled as string
			bool marshalReturnedString = aliasCommand.HasReturnValue && (returnType.ToLower() == "string") && (delegateReturnType.ToLower() != "string");
			// Returned value must be marshalled as structure
			bool marshalReturnedStruct = aliasCommand.HasReturnValue && (DelegateReturnType == "IntPtr") && (GetImplementationReturnType(ctx) != "IntPtr");

			aliases.Add(this);
			aliases.AddRange(Aliases);

			// Signature
			GenerateImplementation_Signature(sw, ctx, commandParams);

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

			#region Debug Assertions

			// Debug assertions
			foreach (CommandParameter param in commandParams)
				param.WriteDebugAssertion(sw, ctx, this);

			#endregion

			#region Local Variables

			// Local variable: returned value
			if (HasReturnValue) {
				sw.WriteLine("{0} {1};", DelegateReturnType, ReturnVariableName);
				sw.WriteLine();
			}

			#endregion

			#region Unsafe Block (Open)

			if (fixedImplementation) {
				sw.WriteLine("unsafe {");								// (1)
				sw.Indent();

				foreach (CommandParameter param in commandParams)
					param.WriteFixedStatement(sw, ctx, this);

				sw.WriteLine("{");										// (2)
				sw.Indent();
			}

			#endregion

			sw.WriteLine("Debug.Assert(Delegates.{0} != null, \"{0} not implemented\");", aliasCommand.DelegateName);

			#region Delegate Call

			sw.WriteIdentation();

			// Local return value
			if (HasReturnValue) 
				sw.Write("{0} = ", ReturnVariableName);

			sw.Write("Delegates.{0}(", aliasCommand.DelegateName);

			#region Parameters

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

				param.WriteDelegateParam(sw, ctx, this);

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

			#endregion

			sw.Write(")");

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

			#endregion

			#region Call Log

			sw.WriteIdentation(); sw.Write("CallLog(");

			#region Call Log - Format String

			sw.Write("\"{0}(", aliasCommand.ImportName);
			for (int i = 0; i < commandParams.Count; i++)
			{
				commandParams[i].WriteCallLogFormatParam(sw, ctx, this, i);
				if (i < commandParams.Count - 1)
					sw.Write(", ");
			}
			sw.Write(")");

			if (HasReturnValue)
				sw.Write(" = {{{0}}}", commandParams.Count);

			sw.Write("\"");

			#endregion

			#region Call Log - Format Arguments

			if ((commandParams.Count > 0) || HasReturnValue) {
				sw.Write(", ");

				for (int i = 0; i < commandParams.Count; i++) {
					commandParams[i].WriteCallLogArgParam(sw, ctx, this);
					if (i < commandParams.Count - 1)
						sw.Write(", ");
				}
			}

			// Return value
			if (HasReturnValue)
			{
				if (commandParams.Count > 0)
					sw.Write(", ");
				CommandParameter.WriteCallLogArgParam(sw, ReturnVariableName, returnType);
			}

			#endregion

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

			#endregion

			#region Unsafe Block (Close)

			if (fixedImplementation)
			{
				sw.Unindent();
				sw.WriteLine("}");										// (2) CLOSED
				sw.Unindent();
				sw.WriteLine("}");										// (1) CLOSED
			}

			#endregion

			// Check call errors
			if ((Flags & CommandFlags.NoGetError) == 0)
				sw.WriteLine("DebugCheckErrors();");

			// Returns value
			if (HasReturnValue) {
				sw.WriteLine();

				if      (marshalReturnedString)
					sw.WriteLine("return (Marshal.PtrToStringAnsi({0}));", ReturnVariableName);
				else if (marshalReturnedStruct)
					sw.WriteLine("return (({1})Marshal.PtrToStructure({0}, typeof({1})));", ReturnVariableName, GetImplementationReturnType(ctx));
				else if (returnType != delegateReturnType)
					sw.WriteLine("return (({1}){0});", ReturnVariableName, GetImplementationReturnType(ctx));
				else
					sw.WriteLine("return ({0});", ReturnVariableName);
			}

			sw.Unindent();
			sw.WriteLine("}");
		}
Exemplo n.º 33
0
		public virtual void WriteCallLogArgParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			CommandFlagsDatabase.CommandItem.ParameterItemFlags parameterFlags = CommandFlagsDatabase.GetCommandParameterFlags(parentCommand, this);

			if (((Type != null) && (Type == "GLenum")) || ((parameterFlags & CommandFlagsDatabase.CommandItem.ParameterItemFlags.LogAsEnum) != 0))
				sw.Write("LogEnumName({0})", ImplementationName);
			else if (IsManagedArray && GetImplementationTypeModifier(ctx, parentCommand) != "out")
				sw.Write("LogValue({0})", ImplementationName);
			else
				WriteCallLogArgParam(sw, ImplementationName, GetImplementationType(ctx, parentCommand));
		}
		public override void WriteCallLogArgParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			if (IsArrayLengthParameter(this, ctx, parentCommand)) {
				int arrayLengthParamIndex = parentCommand.Parameters.FindIndex(delegate(CommandParameter item) {
					return (parentCommand.Parameters.FindIndex(delegate(CommandParameter subitem) { return (item.Length == Name); }) >= 0);
				});

				sw.Write("{0}.Length", parentCommand.Parameters[arrayLengthParamIndex].DelegateCallVarName);
			} else
				base.WriteCallLogArgParam(sw, ctx, parentCommand);
		}
Exemplo n.º 35
0
		public override void WriteDelegateParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			if (IsArrayLengthParameter(this, ctx, parentCommand)) {
				int arrayLengthParamIndex = parentCommand.Parameters.FindIndex(delegate(CommandParameter item) {
					return (parentCommand.Parameters.FindIndex(delegate(CommandParameter subitem) { return (item.Length == Name); }) >= 0);
				});

				if (OverridenParameter.ImportType != "int")
					sw.Write("({0})", OverridenParameter.ImportType);

				sw.Write("{0}.Length", parentCommand.Parameters[arrayLengthParamIndex].DelegateCallVarName);
			} else if (mIsStrong) {
				// Strongly typed enum must be casted to delegate call type (int or uint)
				sw.Write("({0}){1}", OverridenParameter.ImportType, DelegateCallVarName);
			} else
				base.WriteDelegateParam(sw, ctx, parentCommand);
		}
Exemplo n.º 36
0
        /// <summary>
        /// Generate the command implementation signature and the method documentation.
        /// </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_Signature(SourceStreamWriter sw, RegistryContext ctx, List <CommandParameter> commandParams, string implementationName, string returnType)
        {
#if !DEBUG
            // Documentation
            RegistryDocumentation.GenerateDocumentation(sw, ctx, this, commandParams);
#endif

            foreach (IFeature feature in RequiredBy)
            {
                sw.WriteLine("[RequiredByFeature(\"{0}\")]", feature.Name);
            }
            foreach (IFeature feature in RemovedBy)
            {
                sw.WriteLine("[RemovedByFeature(\"{0}\")]", feature.Name);
            }

            #region Signature

            sw.WriteIdentation();

            // Signature
            sw.Write("{0} static ", CommandFlagsDatabase.GetCommandVisibility(this));
            if (IsUnsafeImplementationSignature(ctx, commandParams))
            {
                sw.Write("unsafe ");
            }
            sw.Write("{0} {1}(", returnType, implementationName);
            // Signature - Parameters
            int paramCount = commandParams.FindAll(delegate(CommandParameter item) { return(!item.IsImplicit(ctx, this)); }).Count;

            foreach (CommandParameter param in commandParams)
            {
                // Skip in signature implicit parameters
                if (param.IsImplicit(ctx, this))
                {
                    continue;
                }

                string paramAttributes = param.GetImplementationTypeAttributes(ctx, this);
                string paramModifier   = param.GetImplementationTypeModifier(ctx, this);

                if (paramAttributes != null)
                {
                    sw.Write("{0} ", paramAttributes);
                }
                if (paramModifier != null)
                {
                    sw.Write("{0} ", paramModifier);
                }

                if ((paramCount == 1) && (param.IsManagedArray) && ((Flags & CommandFlags.VariadicParams) != 0))
                {
                    sw.Write("params ");
                }

                sw.Write("{0} {1}", param.GetImplementationType(ctx, this), param.ImplementationName);
                paramCount--;
                if (paramCount > 0)
                {
                    sw.Write(", ");
                }
            }
            sw.Write(")");
            sw.WriteLine();

            #endregion
        }
Exemplo n.º 37
0
		/// <summary>
		/// Generate the C# source code for this enumerant.
		/// </summary>
		/// <param name="sw">
		/// A <see cref="SourceStreamWriter"/> used for writing the source code.
		/// </param>
		internal void GenerateSource(SourceStreamWriter sw, RegistryContext ctx)
		{
			if (sw == null)
				throw new ArgumentNullException("sw");

			RegistryDocumentation.GenerateDocumentation(sw, ctx, this);

			foreach (Enumerant aliasOf in AliasOf)
				sw.WriteLine("[AliasOf(\"{0}\")]", aliasOf.Name);

			foreach (IFeature feature in RequiredBy)
				sw.WriteLine("[RequiredByFeature(\"{0}\")]", feature.Name);
			foreach (Enumerant aliasOf in AliasOf) {
				foreach (IFeature feature in aliasOf.RequiredBy)
					sw.WriteLine("[RequiredByFeature(\"{0}\")]", feature.Name);
			}
			foreach (IFeature feature in RemovedBy)
				sw.WriteLine("[RemovedByFeature(\"{0}\")]", feature.Name);

			// This metadata is used for procedure logging function
			bool requiresLogAttribute = ParentEnumerantBlock.Type == "bitmask";

			if (requiresLogAttribute == true) {
				if (ParentEnumerantBlock.Type == "bitmask")
					sw.WriteLine("[Log(BitmaskName = \"{0}\")]", ParentEnumerantBlock.Namespace);
			}

			if (IsDeprecated) {
				sw.Write("#if DEBUG && !OPENGL_NET_COMPATIBILITY_PROFILE" + Environment.NewLine);
				sw.WriteLine("[Obsolete(\"Deprecated/removed by {0}.\")]", SpecificationStyle.GetKhronosVersionHumanReadable(RemovedBy[0].Name));
				sw.Write("#endif" + Environment.NewLine);
			}

			sw.WriteLine(Declaration);
		}
Exemplo n.º 38
0
        /// <summary>
        /// Generate the command implementation (fixed 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_Default(SourceStreamWriter sw, RegistryContext ctx, List <CommandParameter> commandParams)
        {
            List <Command> aliases      = new List <Command>();
            Command        aliasCommand = this;

            // The implementation returned type
            string returnType = aliasCommand.GetImplementationReturnType(ctx);
            // Is fixed implementation
            bool fixedImplementation = IsFixedImplementation(ctx, commandParams);

            aliases.Add(this);
            aliases.AddRange(Aliases);

            // Signature
            GenerateImplementation_Signature(sw, ctx, commandParams);

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

            #region Debug Assertions

            // Debug assertions
            foreach (CommandParameter param in commandParams)
            {
                param.WriteDebugAssertion(sw, ctx, this);
            }

            #endregion

            #region Local Variables

            // Local variable: returned value
            if (HasReturnValue)
            {
                sw.WriteLine("{0} {1};", DelegateReturnType, ReturnVariableName);
                sw.WriteLine();
            }

            #endregion

            #region Unsafe Block (Open)

            if (fixedImplementation)
            {
                sw.WriteLine("unsafe {");                                                                               // (1)
                sw.Indent();

                foreach (CommandParameter param in commandParams)
                {
                    param.WriteFixedStatement(sw, ctx, this);
                }

                sw.WriteLine("{");                                                                                              // (2)
                sw.Indent();
            }

            #endregion

            sw.WriteLine("Debug.Assert(Delegates.{0} != null, \"{0} not implemented\");", aliasCommand.DelegateName);

            #region Delegate Call

            sw.WriteIdentation();

            // Local return value
            if (HasReturnValue)
            {
                sw.Write("{0} = ", ReturnVariableName);
            }

            sw.Write("Delegates.{0}(", aliasCommand.DelegateName);

            #region Parameters

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

                param.WriteDelegateParam(sw, ctx, this);

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

            #endregion

            sw.Write(")");

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

            #endregion

            #region Call Log

            sw.WriteIdentation(); sw.Write("LogFunction(");

            #region Call Log - Format String

            sw.Write("\"{0}(", aliasCommand.ImportName);
            for (int i = 0; i < commandParams.Count; i++)
            {
                commandParams[i].WriteCallLogFormatParam(sw, ctx, this, i);
                if (i < commandParams.Count - 1)
                {
                    sw.Write(", ");
                }
            }
            sw.Write(")");

            if (HasReturnValue)
            {
                sw.Write(" = {{{0}}}", commandParams.Count);
            }

            sw.Write("\"");

            #endregion

            #region Call Log - Format Arguments

            if ((commandParams.Count > 0) || HasReturnValue)
            {
                sw.Write(", ");

                for (int i = 0; i < commandParams.Count; i++)
                {
                    commandParams[i].WriteCallLogArgParam(sw, ctx, this);
                    if (i < commandParams.Count - 1)
                    {
                        sw.Write(", ");
                    }
                }
            }

            // Return value
            if (HasReturnValue)
            {
                if (commandParams.Count > 0)
                {
                    sw.Write(", ");
                }
                CommandParameter.WriteCallLogArgParam(sw, GetReturnValueExpression(ctx), returnType);
            }

            #endregion

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

            #endregion

            #region Unsafe Block (Close)

            if (fixedImplementation)
            {
                sw.Unindent();
                sw.WriteLine("}");                                                                                              // (2) CLOSED
                sw.Unindent();
                sw.WriteLine("}");                                                                                              // (1) CLOSED
            }

            #endregion

            // Check call errors
            if ((Flags & CommandFlags.NoGetError) == 0)
            {
                string returnValue = "null";

                // Optionally pass the returned value to error checking method
                if (HasReturnValue)
                {
                    returnValue = ReturnVariableName;
                }

                sw.WriteLine("DebugCheckErrors({0});", returnValue);
            }

            // Returns value
            if (HasReturnValue)
            {
                sw.WriteLine();
                sw.WriteLine("return ({0});", GetReturnValueExpression(ctx));
            }

            sw.Unindent();
            sw.WriteLine("}");
        }
Exemplo n.º 39
0
        /// <summary>
        /// Generate the command implementation (pinned 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_Pinned(SourceStreamWriter sw, RegistryContext ctx, List <CommandParameter> commandParams)
        {
            // Signature
            GenerateImplementation_Signature(sw, ctx, commandParams);

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

            #region Pinned Object Block (Open)

            foreach (CommandParameter param in commandParams)
            {
                param.WritePinnedVariable(sw, ctx, this);
            }

            sw.WriteLine("try {");
            sw.Indent();

            #endregion

            #region Implementation Call

            sw.WriteIdentation();
            if (HasReturnValue)
            {
                sw.Write("return (");
            }

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

            #region Parameters

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

                param.WriteDelegateParam(sw, ctx, this);

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

            #endregion

            sw.Write(")");

            if (HasReturnValue)
            {
                sw.Write(")");
            }
            sw.Write(";");
            sw.WriteLine();

            #endregion

            #region Pinned Object Block (Close)

            sw.Unindent();
            sw.WriteLine("} finally {");
            sw.Indent();

            foreach (CommandParameter param in commandParams)
            {
                param.WriteUnpinCommand(sw, ctx, this);
            }

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

            #endregion

            sw.Unindent();
            sw.WriteLine("}");
        }
Exemplo n.º 40
0
		/// <summary>
		/// Generate the command delegate source code.
		/// </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>
		internal void GenerateDelegate(SourceStreamWriter sw, RegistryContext ctx)
		{
			if (Aliases.Count > 0) {
				sw.WriteLine("[AliasOf(\"{0}\")]", ImportName);
				foreach (Command aliasOf in Aliases)
					sw.WriteLine("[AliasOf(\"{0}\")]", aliasOf.ImportName);
			}

			// No sure if it is really necessary
			sw.WriteLine("[SuppressUnmanagedCodeSecurity()]");

			// Delegate type definition
			sw.WriteIdentation(); sw.Write("internal ");
			if (IsSafeImplementation == false) sw.Write("unsafe ");
			sw.Write("delegate ");

			sw.Write("{0} {1}(", DelegateReturnType, ImportName);

			int paramCount = Parameters.Count;

			foreach (CommandParameter param in Parameters) {
				string paramAttributes = param.GetDelegateTypeAttributes(ctx, this);
				string paramModifier = param.GetDelegateTypeModifier(ctx, this);

				if (paramAttributes != null)
					sw.Write("{0} ", paramAttributes);
				if (paramModifier != null)
					sw.Write("{0} ", paramModifier);


				sw.Write("{0} {1}", param.GetDelegateType(ctx, this), param.ImportName);
				paramCount--;
				if (paramCount > 0)
					sw.Write(", ");
			}
			sw.Write(");");
			sw.WriteLine();

			// Required on Windows platform: different threads can bind different OpenGL context, which can have different
			// entry points
			sw.WriteLine("[ThreadStatic]");

			// Delegate field
			sw.WriteLine("internal static {0} {1};", ImportName, DelegateName);
		}