Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the usage of some ReflectionUtils methods #663

Merged
merged 1 commit into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Src/IronPython/Compiler/UncollectableCompilationMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override LightLambdaExpression ReduceAst(PythonAst instance, string name)
// going to a call site which can be strongly typed. We need to coordinate
// more with whoever consumes the values.
if (CompilerHelpers.CanEmitConstant(value, CompilerHelpers.GetType(value)) &&
!CompilerHelpers.GetType(value).IsValueType()) {
!CompilerHelpers.GetType(value).IsValueType) {
return Utils.Constant(value);
}

Expand All @@ -71,7 +71,7 @@ public override LightLambdaExpression ReduceAst(PythonAst instance, string name)
}

public override Type GetConstantType(object value) {
if (value == null || value.GetType().IsValueType()) {
if (value == null || value.GetType().IsValueType) {
return typeof(object);
}

Expand Down Expand Up @@ -429,7 +429,7 @@ public override int FieldCount {
public override Type/*!*/ Type {
get {
Type returnType = _value.GetType();
if (!returnType.IsValueType()) {
if (!returnType.IsValueType) {
return returnType;
} else {
return typeof(object);
Expand All @@ -444,7 +444,7 @@ public object Value {
}

public override MSAst.Expression Reduce() {
if (_value.GetType().IsValueType()) {
if (_value.GetType().IsValueType) {
return base.Reduce();
} else {
return MSAst.Expression.Convert(base.Reduce(), _value.GetType());
Expand Down
2 changes: 1 addition & 1 deletion Src/IronPython/Runtime/Binding/BindingHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ internal static bool IsDataMember(object p) {
}

internal static DynamicMetaObject AddPythonBoxing(DynamicMetaObject res) {
if (res.Expression.Type.IsValueType()) {
if (res.Expression.Type.IsValueType) {
// Use Python boxing rules if we're return a value type
res = new DynamicMetaObject(
AddPythonBoxing(res.Expression),
Expand Down
6 changes: 3 additions & 3 deletions Src/IronPython/Runtime/Binding/ConversionBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override Type ReturnType {

return (_kind == ConversionResultKind.ExplicitCast || _kind == ConversionResultKind.ImplicitCast) ?
Type :
_type.IsValueType() ?
_type.IsValueType ?
typeof(object) :
_type;
}
Expand Down Expand Up @@ -215,7 +215,7 @@ internal DynamicMetaObject FallbackConvert(Type returnType, DynamicMetaObject se
break;
}

if (type.IsEnum() && Enum.GetUnderlyingType(type) == self.GetLimitType()) {
if (type.IsEnum && Enum.GetUnderlyingType(type) == self.GetLimitType()) {
// numeric type to enum, this is ok if the value is zero
object value = Activator.CreateInstance(type);

Expand Down Expand Up @@ -701,7 +701,7 @@ private DynamicMetaObject TryToCharConversion(DynamicMetaObject/*!*/ self) {
} else if (typeof(IStrongBox).IsAssignableFrom(self.GetLimitType())) {
// Explictly block conversion of References to bool
res = MakeStrongBoxToBoolConversionError(self);
} else if (self.GetLimitType().IsPrimitive() || self.GetLimitType().IsEnum()) {
} else if (self.GetLimitType().IsPrimitive || self.GetLimitType().IsEnum) {
// optimization - rather than doing a method call for primitives and enums generate
// the comparison to zero directly.
res = MakePrimitiveToBoolComparison(self);
Expand Down
18 changes: 9 additions & 9 deletions Src/IronPython/Runtime/Binding/MetaBuiltinFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,23 @@ out target
if (CompilerHelpers.IsStrongBox(instanceValue)) {
instance = ReadStrongBoxValue(instance);
instanceValue = ((IStrongBox)instanceValue).Value;
} else if (!testType.IsEnum()) {
} else if (!testType.IsEnum) {
// We need to deal w/ wierd types like MarshalByRefObject.
// We could have an MBRO whos DeclaringType is completely different.
// Therefore we special case it here and cast to the declaring type

Type selfType = CompilerHelpers.GetType(Value.BindingSelf);
selfType = CompilerHelpers.GetVisibleType(selfType);

if (selfType == typeof(object) && Value.DeclaringType.IsInterface()) {
if (selfType == typeof(object) && Value.DeclaringType.IsInterface) {
selfType = Value.DeclaringType;

Type genericTypeDefinition = null;
// the behavior is different on Mono, it sets FullName for the DeclaringType
if (Value.DeclaringType.IsGenericType() &&
if (Value.DeclaringType.IsGenericType &&
(ClrModule.IsMono || Value.DeclaringType.FullName == null) &&
Value.DeclaringType.ContainsGenericParameters() &&
!Value.DeclaringType.IsGenericTypeDefinition()) {
Value.DeclaringType.ContainsGenericParameters &&
!Value.DeclaringType.IsGenericTypeDefinition) {
// from MSDN: If the current type contains generic type parameters that have not been replaced by
// specific types (that is, the ContainsGenericParameters property returns true), but the type
// is not a generic type definition (that is, the IsGenericTypeDefinition property returns false),
Expand All @@ -251,7 +251,7 @@ out target
if (hasOnlyGenerics) {
genericTypeDefinition = Value.DeclaringType.GetGenericTypeDefinition();
}
} else if (Value.DeclaringType.IsGenericTypeDefinition()) {
} else if (Value.DeclaringType.IsGenericTypeDefinition) {
genericTypeDefinition = Value.DeclaringType;
}

Expand All @@ -261,19 +261,19 @@ out target
// the concrete selfType.
var interfaces = CompilerHelpers.GetType(Value.BindingSelf).GetInterfaces();
foreach (var iface in interfaces) {
if (iface.IsGenericType() && iface.GetGenericTypeDefinition() == genericTypeDefinition) {
if (iface.IsGenericType && iface.GetGenericTypeDefinition() == genericTypeDefinition) {
selfType = iface;
break;
}
}
}
}

if (Value.DeclaringType.IsInterface() && selfType.IsValueType()) {
if (Value.DeclaringType.IsInterface && selfType.IsValueType) {
// explicit interface implementation dispatch on a value type, don't
// unbox the value type before the dispatch.
instance = AstUtils.Convert(instance, Value.DeclaringType);
} else if (selfType.IsValueType()) {
} else if (selfType.IsValueType) {
// We might be calling a a mutating method (like
// Rectangle.Intersect). If so, we want it to mutate
// the boxed value directly
Expand Down
4 changes: 2 additions & 2 deletions Src/IronPython/Runtime/Binding/MetaOldInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public DynamicMetaObject BindConvert(PythonConversionBinder binder) {
}

public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type type, Type retType, ConversionResultKind kind) {
if (!type.IsEnum()) {
if (!type.IsEnum) {
switch (type.GetTypeCode()) {
case TypeCode.Boolean:
return MakeConvertToBool(binder);
Expand All @@ -127,7 +127,7 @@ public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type type
return MakeConvertToIEnumerable(binder);
} else if (type == typeof(IEnumerator)) {
return MakeConvertToIEnumerator(binder);
} else if (type.IsGenericType() && type.GetGenericTypeDefinition() == typeof(IEnumerable<>)) {
} else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>)) {
return MakeConvertToIEnumerable(binder, type, type.GetGenericArguments()[0]);
} else if (type.IsSubclassOf(typeof(Delegate))) {
return MakeDelegateTarget(binder, type, Restrict(typeof(OldInstance)));
Expand Down
2 changes: 1 addition & 1 deletion Src/IronPython/Runtime/Binding/MetaPythonType.Calls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ partial class MetaPythonType : MetaPythonObject, IPythonInvokable {

if (TooManyArgsForDefaultNew(call, args)) {
return MakeIncorrectArgumentsForCallError(call, ai, valInfo);
} else if (Value.UnderlyingSystemType.IsGenericTypeDefinition()) {
} else if (Value.UnderlyingSystemType.IsGenericTypeDefinition) {
return MakeGenericTypeDefinitionError(call, ai, valInfo);
} else if (Value.HasAbstractMethods(PythonContext.GetPythonContext(call).SharedContext)) {
return MakeAbstractInstantiationError(call, ai, valInfo);
Expand Down
2 changes: 1 addition & 1 deletion Src/IronPython/Runtime/Binding/MetaUserObject.Members.cs
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ protected override DynamicMetaObject Finish() {
_target.Restrict(Instance.GetType()).Restrictions.Merge(_result.Restrictions)
);

Debug.Assert(!_result.Expression.Type.IsValueType());
Debug.Assert(!_result.Expression.Type.IsValueType);

return BindingHelpers.AddDynamicTestAndDefer(
_info.Action,
Expand Down
2 changes: 1 addition & 1 deletion Src/IronPython/Runtime/Binding/MetaUserObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private DynamicMetaObject InvokeFallback(DynamicMetaObjectBinder action, Express
#region Conversions

private DynamicMetaObject TryPythonConversion(DynamicMetaObjectBinder conversion, Type type) {
if (!type.IsEnum()) {
if (!type.IsEnum) {
switch (type.GetTypeCode()) {
case TypeCode.Object:
if (type == typeof(Complex)) {
Expand Down
8 changes: 4 additions & 4 deletions Src/IronPython/Runtime/Binding/PythonBinaryOperationBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private T BindAdd<T>(CallSite<T> site, object[] args) where T : class {
return (T)(object)new Func<CallSite, object, object, object>(TupleAdd);
}

} else if (!t.IsEnum()) {
} else if (!t.IsEnum) {
switch (t.GetTypeCode()) {
case TypeCode.Double:
if(typeof(T) == typeof(Func<CallSite, object, object, object>)) {
Expand All @@ -295,7 +295,7 @@ private T BindAdd<T>(CallSite<T> site, object[] args) where T : class {

private T BindSubtract<T>(CallSite<T> site, object[] args) where T : class {
Type t = args[0].GetType();
if (!t.IsEnum()) {
if (!t.IsEnum) {
switch (t.GetTypeCode()) {
case TypeCode.Double:
if (typeof(T) == typeof(Func<CallSite, object, object, object>)) {
Expand Down Expand Up @@ -326,7 +326,7 @@ private T BindEqual<T>(CallSite<T> site, object[] args) where T : class {
} else if (typeof(T) == typeof(Func<CallSite, object, string, object>)) {
return (T)(object)new Func<CallSite, object, string, object>(StringEqual);
}
} else if (!t.IsEnum() && typeof(T) == typeof(Func<CallSite, object, object, object>)) {
} else if (!t.IsEnum && typeof(T) == typeof(Func<CallSite, object, object, object>)) {
switch (t.GetTypeCode()) {
case TypeCode.Double:
return (T)(object)new Func<CallSite, object, object, object>(DoubleEqual);
Expand All @@ -347,7 +347,7 @@ private T BindNotEqual<T>(CallSite<T> site, object[] args) where T : class {
} else if (typeof(T) == typeof(Func<CallSite, string, object, object>)) {
return (T)(object)new Func<CallSite, string, object, object>(StringNotEqual);
}
} else if (!t.IsEnum() && typeof(T) == typeof(Func<CallSite, object, object, object>)) {
} else if (!t.IsEnum && typeof(T) == typeof(Func<CallSite, object, object, object>)) {
switch (t.GetTypeCode()) {
case TypeCode.Double:
return (T)(object)new Func<CallSite, object, object, object>(DoubleNotEqual);
Expand Down
6 changes: 3 additions & 3 deletions Src/IronPython/Runtime/Binding/PythonBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public PythonBinder(PythonBinder binder) {
Type exprType = expr.Type;

if (toType == typeof(object)) {
if (exprType.IsValueType()) {
if (exprType.IsValueType) {
return AstUtils.Convert(expr, toType);
} else {
return expr;
Expand Down Expand Up @@ -98,7 +98,7 @@ public PythonBinder(PythonBinder binder) {
}

internal static MethodInfo GetGenericConvertMethod(Type toType) {
if (toType.IsValueType()) {
if (toType.IsValueType) {
if (toType.IsGenericType() && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) {
return typeof(Converter).GetMethod("ConvertToNullableType");
} else {
Expand Down Expand Up @@ -821,7 +821,7 @@ private void DomainManager_AssemblyLoaded(object sender, AssemblyLoadedEventArgs
if (attrs.Any()) {
lock (_dlrExtensionTypes) {
foreach (ExtensionTypeAttribute attr in attrs) {
if (attr.Extends.IsInterface()) {
if (attr.Extends.IsInterface) {
_registeredInterfaceExtensions = true;
}

Expand Down
2 changes: 1 addition & 1 deletion Src/IronPython/Runtime/Binding/PythonExtensionBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override MemberGroup GetMember(MemberRequestKind actionKind, Type type, s

internal static bool IsApplicableExtensionMethod(Type instanceType, Type extensionMethodThisType) {

if (extensionMethodThisType.ContainsGenericParameters()) {
if (extensionMethodThisType.ContainsGenericParameters) {
Dictionary<Type, Type> binding = new Dictionary<Type, Type>();

if (extensionMethodThisType.IsArray) {
Expand Down
4 changes: 2 additions & 2 deletions Src/IronPython/Runtime/Binding/PythonGetMemberBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private Func<CallSite, TSelfType, CodeContext, object> MakeGetMemberTarget<TSelf

MemberGroup members = Context.Binder.GetMember(MemberRequestKind.Get, type, name);

if (members.Count == 0 && type.IsInterface()) {
if (members.Count == 0 && type.IsInterface) {
// all interfaces have object members
type = typeof(object);
members = Context.Binder.GetMember(MemberRequestKind.Get, type, name);
Expand Down Expand Up @@ -620,7 +620,7 @@ internal static DynamicMetaObject FallbackWorker(PythonContext context, DynamicM

// Default binder can return something typed to boolean or int.
// If that happens, we need to apply Python's boxing rules.
if (res.Expression.Type.IsValueType()) {
if (res.Expression.Type.IsValueType) {
res = new DynamicMetaObject(
AstUtils.Convert(res.Expression, typeof(object)),
res.Restrictions
Expand Down
4 changes: 2 additions & 2 deletions Src/IronPython/Runtime/Binding/PythonOverloadResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public PythonOverloadResolver(PythonBinder binder, IList<DynamicMetaObject> args

public override bool CanConvertFrom(Type fromType, DynamicMetaObject fromArg, ParameterWrapper toParameter, NarrowingLevel level) {
if ((fromType == typeof(List) || fromType.IsSubclassOf(typeof(List)))) {
if (toParameter.Type.IsGenericType() &&
if (toParameter.Type.IsGenericType &&
toParameter.Type.GetGenericTypeDefinition() == typeof(IList<>) &&
(toParameter.ParameterInfo.IsDefined(typeof(BytesConversionAttribute), false) ||
toParameter.ParameterInfo.IsDefined(typeof(BytesConversionNoStringAttribute), false))) {
Expand Down Expand Up @@ -141,7 +141,7 @@ public override Type GetGenericInferenceType(DynamicMetaObject dynamicObject) {
Type res = PythonTypeOps.GetFinalSystemType(dynamicObject.LimitType);
if (res == typeof(ExtensibleString) ||
res == typeof(ExtensibleComplex) ||
(res.IsGenericType() && res.GetGenericTypeDefinition() == typeof(Extensible<>))) {
(res.IsGenericType && res.GetGenericTypeDefinition() == typeof(Extensible<>))) {
return typeof(object);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ private static void DoCoerce(PythonContext/*!*/ pyContext, ConditionalBuilder/*!
AstUtils.Constant(0),
BindingRestrictions.Combine(types)
);
} else if (yType.UnderlyingSystemType.IsPrimitive() || yType.UnderlyingSystemType == typeof(BigInteger)) {
} else if (yType.UnderlyingSystemType.IsPrimitive || yType.UnderlyingSystemType == typeof(BigInteger)) {
return new DynamicMetaObject(
AstUtils.Constant(-1),
BindingRestrictions.Combine(types)
Expand Down
16 changes: 8 additions & 8 deletions Src/IronPython/Runtime/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ internal static object Convert(object value, Type to) {
}

object res = site.Target(site, value);
if (to.IsValueType() && res == null &&
(!to.IsGenericType() || to.GetGenericTypeDefinition() != typeof(Nullable<>))) {
if (to.IsValueType && res == null &&
(!to.IsGenericType || to.GetGenericTypeDefinition() != typeof(Nullable<>))) {
throw MakeTypeError(to, value);
}
return res;
Expand Down Expand Up @@ -565,7 +565,7 @@ private static TypeConverter GetTypeConverter(TypeConverterAttribute tca) {
#endif

private static bool HasImplicitNumericConversion(Type fromType, Type toType) {
if (fromType.IsEnum()) return false;
if (fromType.IsEnum) return false;

if (fromType == typeof(BigInteger)) {
if (toType == typeof(double)) return true;
Expand Down Expand Up @@ -804,7 +804,7 @@ private static bool HasNarrowingConversion(Type fromType, Type toType, Narrowing

if (toType == typeof(IEnumerator)) {
if (IsPythonType(fromType)) return true;
} else if (toType.IsGenericType()) {
} else if (toType.IsGenericType) {
Type genTo = toType.GetGenericTypeDefinition();
if (genTo == IEnumerableOfTType) {
return IEnumerableOfObjectType.IsAssignableFrom(fromType) ||
Expand All @@ -824,7 +824,7 @@ private static bool HasNarrowingConversion(Type fromType, Type toType, Narrowing
if (toType == BigIntegerType && HasPythonProtocol(fromType, "__long__")) return true;
}

if (toType.IsGenericType()) {
if (toType.IsGenericType) {
Type genTo = toType.GetGenericTypeDefinition();
if (genTo == IListOfTType) {
return IListOfObjectType.IsAssignableFrom(fromType);
Expand All @@ -838,7 +838,7 @@ private static bool HasNarrowingConversion(Type fromType, Type toType, Narrowing
}

if (fromType == BigIntegerType && toType == Int64Type) return true;
if (toType.IsEnum() && fromType == Enum.GetUnderlyingType(toType)) return true;
if (toType.IsEnum && fromType == Enum.GetUnderlyingType(toType)) return true;

return false;
}
Expand All @@ -858,7 +858,7 @@ private static bool HasImplicitConversionWorker(Type lookupType, Type fromType,
return true;
}
}
lookupType = lookupType.GetBaseType();
lookupType = lookupType.BaseType;
}
return false;
}
Expand Down Expand Up @@ -896,7 +896,7 @@ private static bool HasImplicitConversionWorker(Type lookupType, Type fromType,
}

internal static bool IsNumeric(Type t) {
if (t.IsEnum()) return false;
if (t.IsEnum) return false;

const TypeCode TypeCodeDbNull = (TypeCode)2; // TypeCode.DBNull
switch (t.GetTypeCode()) {
Expand Down
Loading