Skip to content

Commit

Permalink
removing ValidationOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-montrose committed Dec 24, 2013
1 parent 03c8647 commit fa1d38b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 85 deletions.
13 changes: 6 additions & 7 deletions Sigil/DisassembledOperations.cs
Expand Up @@ -132,7 +132,7 @@ private void Apply(int i, Emit<DelegateType> emit)
this[i].Apply(emit);
}

private Emit<DelegateType> EmitFrom(int from, int length, string name = null, ModuleBuilder module = null, ValidationOptions validationOptions = ValidationOptions.All)
private Emit<DelegateType> EmitFrom(int from, int length, string name = null, ModuleBuilder module = null)
{
if (from < 0 || from > Operations.Count)
{
Expand All @@ -153,8 +153,7 @@ private Emit<DelegateType> EmitFrom(int from, int length, string name = null, Mo
Emit<DelegateType>.DisassemblerDynamicMethod(
LinqAlternative.Select(Parameters, p => p.ParameterType).ToArray(),
name,
module,
validationOptions
module
);

for (var i = 0; i < length; i++)
Expand All @@ -165,7 +164,7 @@ private Emit<DelegateType> EmitFrom(int from, int length, string name = null, Mo
return e1;
}

private Emit<DelegateType> Emit(int length, string name = null, ModuleBuilder module = null, ValidationOptions validationOptions = ValidationOptions.All)
private Emit<DelegateType> Emit(int length, string name = null, ModuleBuilder module = null)
{
if (!CanEmit)
{
Expand All @@ -177,15 +176,15 @@ private Emit<DelegateType> Emit(int length, string name = null, ModuleBuilder mo
throw new InvalidOperationException("length must be between 0 and "+Operations.Count+", inclusive; found "+length);
}

return EmitFrom(0, length, name, module, validationOptions);
return EmitFrom(0, length, name, module);
}

/// <summary>
/// Emits the disassembled instructions into a new Emit.
/// </summary>
public Emit<DelegateType> EmitAll(string name = null, ModuleBuilder module = null, ValidationOptions validationOptions = ValidationOptions.All)
public Emit<DelegateType> EmitAll(string name = null, ModuleBuilder module = null)
{
return Emit(this.Count, name, module, validationOptions);
return Emit(this.Count, name, module);
}

/// <summary>
Expand Down
65 changes: 23 additions & 42 deletions Sigil/Emit.cs
Expand Up @@ -79,13 +79,6 @@ static Emit()
/// </summary>
public int MaxStackSize { get; private set; }

/// <summary>
/// Returns the validation options that were used when creating this emit.
///
/// These control when certain validation steps are run.
/// </summary>
public ValidationOptions ValidationOptions { get; private set; }

private LinqList<Local> FreedLocals { get; set; }

private LinqDictionary<string, Local> CurrentLocals;
Expand Down Expand Up @@ -113,10 +106,8 @@ static Emit()

private LinqDictionary<int, LinqList<TypeOnStack>> TypesProducedAtIndex;

private Emit(CallingConventions callConvention, Type returnType, Type[] parameterTypes, bool allowUnverifiable, ValidationOptions opts)
private Emit(CallingConventions callConvention, Type returnType, Type[] parameterTypes, bool allowUnverifiable)
{
ValidationOptions = opts;

CallingConventions = callConvention;

AllowsUnverifiableCIL = allowUnverifiable;
Expand Down Expand Up @@ -168,9 +159,9 @@ private Emit(CallingConventions callConvention, Type returnType, Type[] paramete
MarkLabel(start);
}

internal static Emit<NonGenericPlaceholderDelegate> MakeNonGenericEmit(CallingConventions callConvention, Type returnType, Type[] parameterTypes, bool allowUnverifiable, ValidationOptions opts)
internal static Emit<NonGenericPlaceholderDelegate> MakeNonGenericEmit(CallingConventions callConvention, Type returnType, Type[] parameterTypes, bool allowUnverifiable)
{
return new Emit<NonGenericPlaceholderDelegate>(callConvention, returnType, parameterTypes, allowUnverifiable, opts);
return new Emit<NonGenericPlaceholderDelegate>(callConvention, returnType, parameterTypes, allowUnverifiable);
}

/// <summary>
Expand Down Expand Up @@ -451,7 +442,7 @@ public ConstructorBuilder CreateConstructor(OptimizationOptions optimizationOpti
return CreateConstructor(out ignored, optimizationOptions);
}

private static void ValidateNewParameters<CheckDelegateType>(ValidationOptions validationOptions)
private static void ValidateNewParameters<CheckDelegateType>()
{
var delType = typeof(CheckDelegateType);

Expand All @@ -468,11 +459,6 @@ private static void ValidateNewParameters<CheckDelegateType>(ValidationOptions v
{
throw new ArgumentException("DelegateType must be a delegate, found " + delType.FullName);
}

if ((validationOptions & ~ValidationOptions.All) != 0)
{
throw new ArgumentException("validationOptions contained unknown flags, found " + validationOptions);
}
}

internal static bool AllowsUnverifiableCode(Module m)
Expand Down Expand Up @@ -510,18 +496,18 @@ internal static bool AllowsUnverifiableCode(ModuleBuilder m)
///
/// If module is not defined, a module with the same trust as the executing assembly is used instead.
/// </summary>
public static Emit<DelegateType> NewDynamicMethod(string name = null, ModuleBuilder module = null, ValidationOptions validationOptions = ValidationOptions.All)
public static Emit<DelegateType> NewDynamicMethod(string name = null, ModuleBuilder module = null)
{
return DisassemblerDynamicMethod(name: name, module: module, validationOptions: validationOptions);
return DisassemblerDynamicMethod(name: name, module: module);
}

internal static Emit<DelegateType> DisassemblerDynamicMethod(Type[] parameters = null, string name = null, ModuleBuilder module = null, ValidationOptions validationOptions = ValidationOptions.All)
internal static Emit<DelegateType> DisassemblerDynamicMethod(Type[] parameters = null, string name = null, ModuleBuilder module = null)
{
module = module ?? Module;

name = name ?? AutoNamer.Next("_DynamicMethod");

ValidateNewParameters<DelegateType>(validationOptions);
ValidateNewParameters<DelegateType>();

var delType = typeof(DelegateType);

Expand All @@ -531,7 +517,7 @@ internal static Emit<DelegateType> DisassemblerDynamicMethod(Type[] parameters =

var dynMethod = new DynamicMethod(name, returnType, parameterTypes, module, skipVisibility: true);

var ret = new Emit<DelegateType>(dynMethod.CallingConvention, returnType, parameterTypes, AllowsUnverifiableCode(module), validationOptions);
var ret = new Emit<DelegateType>(dynMethod.CallingConvention, returnType, parameterTypes, AllowsUnverifiableCode(module));
ret.DynMethod = dynMethod;

return ret;
Expand All @@ -544,16 +530,16 @@ internal static Emit<DelegateType> DisassemblerDynamicMethod(Type[] parameters =
///
/// If owner is not defined, a module with the same trust as the executing assembly is used instead.
/// </summary>
public static Emit<DelegateType> NewDynamicMethod(Type owner, string name = null, ValidationOptions validationOptions = ValidationOptions.All)
public static Emit<DelegateType> NewDynamicMethod(Type owner, string name = null)
{
if (owner == null)
{
return NewDynamicMethod(name: name, module: null, validationOptions: validationOptions);
return NewDynamicMethod(name: name, module: null);
}

name = name ?? AutoNamer.Next("_DynamicMethod");

ValidateNewParameters<DelegateType>(validationOptions);
ValidateNewParameters<DelegateType>();

var delType = typeof(DelegateType);

Expand All @@ -563,7 +549,7 @@ public static Emit<DelegateType> NewDynamicMethod(Type owner, string name = null

var dynMethod = new DynamicMethod(name, returnType, parameterTypes, owner, skipVisibility: true);

var ret = new Emit<DelegateType>(dynMethod.CallingConvention, returnType, parameterTypes, AllowsUnverifiableCode(owner.Module), validationOptions);
var ret = new Emit<DelegateType>(dynMethod.CallingConvention, returnType, parameterTypes, AllowsUnverifiableCode(owner.Module));
ret.DynMethod = dynMethod;

return ret;
Expand Down Expand Up @@ -597,19 +583,14 @@ private static bool HasFlag(CallingConventions value, CallingConventions flag)
return (value & flag) != 0;
}

private static bool HasFlag(ValidationOptions value, ValidationOptions flag)
{
return (value & flag) != 0;
}

/// <summary>
/// Creates a new Emit, suitable for building a method on the given TypeBuilder.
///
/// The DelegateType and MethodBuilder must agree on return types, parameter types, and parameter counts.
///
/// If you intend to use unveriable code, you must set allowUnverifiableCode to true.
/// </summary>
public static Emit<DelegateType> BuildMethod(TypeBuilder type, string name, MethodAttributes attributes, CallingConventions callingConvention, bool allowUnverifiableCode = false, ValidationOptions validationOptions = ValidationOptions.All)
public static Emit<DelegateType> BuildMethod(TypeBuilder type, string name, MethodAttributes attributes, CallingConventions callingConvention, bool allowUnverifiableCode = false)
{
if (type == null)
{
Expand All @@ -623,7 +604,7 @@ public static Emit<DelegateType> BuildMethod(TypeBuilder type, string name, Meth

CheckAttributesAndConventions(attributes, callingConvention);

ValidateNewParameters<DelegateType>(validationOptions);
ValidateNewParameters<DelegateType>();

var delType = typeof(DelegateType);

Expand All @@ -642,7 +623,7 @@ public static Emit<DelegateType> BuildMethod(TypeBuilder type, string name, Meth
parameterTypes = pList.ToArray();
}

var ret = new Emit<DelegateType>(callingConvention, returnType, parameterTypes, allowUnverifiableCode, validationOptions);
var ret = new Emit<DelegateType>(callingConvention, returnType, parameterTypes, allowUnverifiableCode);
ret.MtdBuilder = methodBuilder;

return ret;
Expand All @@ -653,19 +634,19 @@ public static Emit<DelegateType> BuildMethod(TypeBuilder type, string name, Meth
///
/// Equivalent to calling to BuildMethod, but with MethodAttributes.Static set and CallingConventions.Standard.
/// </summary>
public static Emit<DelegateType> BuildStaticMethod(TypeBuilder type, string name, MethodAttributes attributes, bool allowUnverifiableCode = false, ValidationOptions validationOptions = ValidationOptions.All)
public static Emit<DelegateType> BuildStaticMethod(TypeBuilder type, string name, MethodAttributes attributes, bool allowUnverifiableCode = false)
{
return BuildMethod(type, name, attributes | MethodAttributes.Static, CallingConventions.Standard, allowUnverifiableCode, validationOptions);
return BuildMethod(type, name, attributes | MethodAttributes.Static, CallingConventions.Standard, allowUnverifiableCode);
}

/// <summary>
/// Convenience method for creating instance methods.
///
/// Equivalent to calling to BuildMethod, but with CallingConventions.HasThis.
/// </summary>
public static Emit<DelegateType> BuildInstanceMethod(TypeBuilder type, string name, MethodAttributes attributes, bool allowUnverifiableCode = false, ValidationOptions validationOptions = ValidationOptions.All)
public static Emit<DelegateType> BuildInstanceMethod(TypeBuilder type, string name, MethodAttributes attributes, bool allowUnverifiableCode = false)
{
return BuildMethod(type, name, attributes, CallingConventions.HasThis, allowUnverifiableCode, validationOptions);
return BuildMethod(type, name, attributes, CallingConventions.HasThis, allowUnverifiableCode);
}

/// <summary>
Expand All @@ -675,7 +656,7 @@ public static Emit<DelegateType> BuildInstanceMethod(TypeBuilder type, string na
///
/// If you intend to use unveriable code, you must set allowUnverifiableCode to true.
/// </summary>
public static Emit<DelegateType> BuildConstructor(TypeBuilder type, MethodAttributes attributes, CallingConventions callingConvention = CallingConventions.HasThis, bool allowUnverifiableCode = false, ValidationOptions validationOptions = ValidationOptions.All)
public static Emit<DelegateType> BuildConstructor(TypeBuilder type, MethodAttributes attributes, CallingConventions callingConvention = CallingConventions.HasThis, bool allowUnverifiableCode = false)
{
if (type == null)
{
Expand All @@ -689,7 +670,7 @@ public static Emit<DelegateType> BuildConstructor(TypeBuilder type, MethodAttrib
throw new ArgumentException("Constructors always have a this reference");
}

ValidateNewParameters<DelegateType>(validationOptions);
ValidateNewParameters<DelegateType>();

var delType = typeof(DelegateType);

Expand All @@ -710,7 +691,7 @@ public static Emit<DelegateType> BuildConstructor(TypeBuilder type, MethodAttrib

parameterTypes = pList.ToArray();

var ret = new Emit<DelegateType>(callingConvention, typeof(void), parameterTypes, allowUnverifiableCode, validationOptions);
var ret = new Emit<DelegateType>(callingConvention, typeof(void), parameterTypes, allowUnverifiableCode);
ret.ConstrBuilder = constructorBuilder;

return ret;
Expand Down

0 comments on commit fa1d38b

Please sign in to comment.