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);
		}
		/// <summary>
		/// Construct a CommandParameterArray from the original parameter.
		/// </summary>
		/// <param name="otherParam"></param>
		/// <param name="ctx"></param>
		/// <param name="parentCommand"></param>
		public CommandParameterArrayLength(CommandParameter otherParam, RegistryContext ctx, Command parentCommand)
			: base(otherParam, ctx, parentCommand)
		{
			if (otherParam == null)
				throw new ArgumentNullException("otherParam");

			
		}
		/// <summary>
		/// Construct a CommandParameterUnsafe from the original parameter.
		/// </summary>
		/// <param name="otherParam"></param>
		/// <param name="ctx"></param>
		/// <param name="parentCommand"></param>
		public CommandParameterUnsafe(CommandParameter otherParam, RegistryContext ctx, Command parentCommand)
			: base(otherParam)
		{
			if (otherParam == null)
				throw new ArgumentNullException("otherParam");

			if (IsCompatible(ctx, parentCommand, otherParam)) {
				_IsPointer = true;
			}
		}
		/// <summary>
		/// Construct a CommandParameterStrong from the original parameter.
		/// </summary>
		/// <param name="otherParam"></param>
		/// <param name="ctx"></param>
		/// <param name="parentCommand"></param>
		public CommandParameterStrong(CommandParameter otherParam, RegistryContext ctx, Command parentCommand)
			: base(otherParam)
		{
			if (otherParam == null)
				throw new ArgumentNullException("otherParam");

			if (IsCompatible(otherParam, ctx, parentCommand)) {
				Type = otherParam.Group;
				mIsStrong = true;
			}
		}
		internal static CommandParameter GetArrayLengthParameter(CommandParameter param, RegistryContext ctx, Command parentCommand)
		{
			List<CommandParameter> arrayLengthParams = parentCommand.Parameters.FindAll(delegate(CommandParameter item) {
				return (parentCommand.Parameters.FindIndex(delegate(CommandParameter subitem) { return (item.Length == param.Name); }) >= 0);
			});

			if (arrayLengthParams.Count > 0)
				return (arrayLengthParams[0]);
			else
				return (null);
		}
		internal static new bool IsCompatible(RegistryContext ctx, Command parentCommand, CommandParameter param)
		{
			if (!param.IsManagedArray || param.Length == null)
				return (false);

			int sizeParamIndex = parentCommand.Parameters.FindIndex(delegate (CommandParameter item) { return (item.Name == param.Length); });

			if (sizeParamIndex < 0)
				return (false);

			return (true);
		}
		internal static bool IsCompatible(CommandParameter param, RegistryContext ctx, Command parentCommand)
		{
			// 'bool' parameters are in Boolean group: conditions below will pass
			if (param.GetImplementationType(ctx, parentCommand) == "bool")
				return (false);

			// Unsafe parameters are not allowed, Group is a requirement
			if (!param.IsSafe || param.Group == null)
				return (false);

			// Check actual existence of strongly typed enum
			return (ctx.Registry.Groups.FindIndex(delegate(EnumerantGroup item) { return (item.Name == param.Group); }) >= 0);
		}
		/// <summary>
		/// Construct a CommandParameterOut from the original parameter.
		/// </summary>
		/// <param name="otherParam"></param>
		/// <param name="ctx"></param>
		/// <param name="parentCommand"></param>
		public CommandParameterOut(CommandParameter otherParam, RegistryContext ctx, Command parentCommand, bool strong)
			: base(otherParam)
		{
			if (otherParam == null)
				throw new ArgumentNullException("otherParam");

			if (IsCompatible(ctx, parentCommand, otherParam))
				Length = "1";
			else if (strong && CommandParameterStrong.IsCompatible(ctx, parentCommand, otherParam)) {
				Type = otherParam.Group;
				mIsStrong = true;
			}
		}
		/// <summary>
		/// Construct a CommandParameterPinned from the original parameter.
		/// </summary>
		/// <param name="otherParam"></param>
		/// <param name="ctx"></param>
		/// <param name="parentCommand"></param>
		public CommandParameterPinned(CommandParameter otherParam, RegistryContext ctx, Command parentCommand, bool strong)
			: base(otherParam)
		{
			if (otherParam == null)
				throw new ArgumentNullException("otherParam");

			if (IsCompatible(ctx, parentCommand, otherParam)) {
				Type = "Object";
				TypeDecorators.Clear();
				mIsPinned = true;
			} else if (strong && CommandParameterStrong.IsCompatible(ctx, parentCommand, otherParam)) {
				Type = otherParam.Group;
			}
		}
		internal static bool IsCompatible(RegistryContext ctx, Command command, CommandParameter param)
		{
			// Already "out" param?
			if (param.GetImplementationTypeModifier(ctx, command) == "out")
				return (false);

			string implementationType = param.ManagedImplementationType;

			// Type[] + IsGetImplementation -> out Type
			// Type[] + OutParam -> out Type
			// Type[] + OutParamLast -> out Type
			if ((param.IsConstant == false) && implementationType.EndsWith("[]") && (param.Length != "1") && ((command.Flags & (CommandFlags.OutParam | CommandFlags.OutParamLast)) != 0))
				return (true);

			return (false);
		}
		internal static bool IsCompatible(RegistryContext ctx, Command command, CommandParameter param)
		{
			switch (ctx.Class.ToLower()) {
				case "gl":
					break;
				default:
					return (false);
			}

			if (param.GetImplementationType(ctx, command) != "IntPtr")
				return (false);
			if (Regex.IsMatch(param.Name, "offset"))
				return (false);
			if (param.IsConstant || command.IsGetImplementation(ctx))
				return (true);

			return (false);
		}
		public override void WritePinnedVariable(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			if (GetImplementationType(ctx, parentCommand) == "Object")
				sw.WriteLine("GCHandle {0} = GCHandle.Alloc({1}, GCHandleType.Pinned);", PinnedLocalVarName, ImplementationName);
		}
Example #13
0
		public virtual void WriteUnpinCommand(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			// No code for common parameter
		}
Example #14
0
		public virtual void WritePinnedVariable(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			// No code for common parameter
		}
Example #15
0
		public virtual void WriteCallLogArgParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			WriteCallLogArgParam(sw, ImplementationName, GetImplementationType(ctx, parentCommand));
		}
Example #16
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);
		}
Example #17
0
		public virtual void WriteDelegateParam(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			if (IsFixed(ctx, parentCommand) == false) {
				sw.Write(DelegateCallVarName);
			} else
				sw.Write(FixedLocalVarName);
		}
Example #18
0
		public string GetImplementationTypeModifier(RegistryContext ctx, Command parentCommand)
		{
			string implementationType = ManagedImplementationType;

			// Type[] + Length=1 -> out Type
			if ((IsConstant == false) && implementationType.EndsWith("[]") && (Length == "1") && (parentCommand.IsGetImplementation(ctx)))
				return ("out");
			// Type[] + Length=1 -> out Type
			if ((IsConstant == false) && implementationType.EndsWith("[]") && (Length == "1") && ((parentCommand.Flags & CommandFlags.OutParam) != 0))
				return ("out");

			return (null);
		}
Example #19
0
		public virtual void WriteDebugAssertion(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			if (Length == null)
				return;

			if (CommandParameterArray.IsCompatible(this, ctx, parentCommand))
				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
		}
		internal static bool IsCompatible(RegistryContext ctx, Command command)
		{
			return (IsCompatible(ctx, command, command.Parameters));
		}
Example #21
0
		public string GetDelegateType(RegistryContext ctx, Command parentCommand)
		{
			string implementationType = ImportType;

			// String + Length!=null -> [Out] StringBuilder
			if ((IsConstant == false) && (implementationType == "String") && (Length != null) && ((parentCommand.IsGetImplementation(ctx) || ((parentCommand.Flags & CommandFlags.OutParam) != 0))))
				implementationType = "StringBuilder";

			return (implementationType.Trim());
		}
Example #22
0
		public string GetImplementationTypeAttributes(RegistryContext ctx, Command parentCommand)
		{
			string implementationType = ManagedImplementationType;
			string implementationMod = GetImplementationTypeModifier(ctx, parentCommand);
			string attribute = null;

			// String + Length!=null && !IsConst -> [Out] StringBuilder (in Get commands)
			if ((IsConstant == false) && (implementationType == "String") && (Length != null) && ((parentCommand.IsGetImplementation(ctx) || ((parentCommand.Flags & CommandFlags.OutParam) != 0))))
				attribute = "[Out]";
			// Array && !IsConst -> [Out] T[] (in Get commands)
			if ((IsConstant == false) && (implementationType.EndsWith("[]")) && ((implementationMod != "out") && (implementationMod != "ref")) && ((parentCommand.IsGetImplementation(ctx) || ((parentCommand.Flags & CommandFlags.OutParam) != 0))))
				attribute = "[Out]";

			return (attribute);
		}
		public override void WriteUnpinCommand(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			if (GetImplementationType(ctx, parentCommand) == "Object")
				sw.WriteLine("{0}.Free();", PinnedLocalVarName);
		}
Example #24
0
		public virtual void WriteFixedStatement(SourceStreamWriter sw, RegistryContext ctx, Command parentCommand)
		{
			if (IsFixed(ctx, parentCommand) == false)
				return;

			string dereference = String.Empty;

			switch (GetImplementationTypeModifier(ctx, parentCommand)) {
				case "out":
				case "ref":
					dereference = "&";
					break;
			}

			sw.WriteLine("fixed ({0} {1} = {2}{3})", ImportType, FixedLocalVarName, dereference, ImplementationName);
		}
Example #25
0
		public string GetDelegateTypeModifier(RegistryContext ctx, Command parentCommand)
		{
			return (null);
		}
Example #26
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="parentCommand"></param>
		/// <returns></returns>
		/// <remarks>
		/// <para>
		/// In the generale case, the implementation type corresponds to <see cref="ManagedImplementationType"/>.
		/// </para>
		/// <para>
		/// In the case the implementation type is a managed array, but the specification assert a length equals to
		/// 1, and <paramref name="parentCommand"/> is a "Get" implementation, the implementation type is converted
		/// to a basic type, with an "out" modifier.
		/// </para>
		/// <para>
		/// 
		/// </para>
		/// </remarks>
		public string GetImplementationType(RegistryContext ctx, Command parentCommand)
		{
			string implementationType = ManagedImplementationType;

			// Type[] + Length=1 -> out Type
			if ((IsConstant == false) && implementationType.EndsWith("[]") && (Length == "1") && ((parentCommand.IsGetImplementation(ctx) || ((parentCommand.Flags & CommandFlags.OutParam) != 0))))
				implementationType = implementationType.Substring(0, implementationType.Length - 2);
			// String + Length!=null && !IsConst -> [Out] StringBuilder (in Get commands)
			if ((IsConstant == false) && (implementationType == "String") && (Length != null) && ((parentCommand.IsGetImplementation(ctx) || ((parentCommand.Flags & CommandFlags.OutParam) != 0))))
				implementationType = "StringBuilder";

			return (implementationType);
		}
		internal static bool IsCompatible(RegistryContext ctx, Command command, List<CommandParameter> parameters)
		{
			return (parameters.FindIndex(delegate (CommandParameter item) { return (IsCompatible(ctx, command, item)); }) >= 0);
		}
Example #28
0
		public string GetDelegateTypeAttributes(RegistryContext ctx, Command parentCommand)
		{
			string implementationType = ManagedImplementationType;
			string attribute = null;

			// String + Length!=null -> [Out] StringBuilder
			if ((IsConstant == false) && (implementationType == "String") && (Length != null) && ((parentCommand.IsGetImplementation(ctx) || ((parentCommand.Flags & CommandFlags.OutParam) != 0))))
				attribute = "[Out]";

			return (attribute);
		}
		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);
		}
Example #30
0
		public virtual bool IsImplicit(RegistryContext ctx, Command parentCommand) { return (false); }