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 #638

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 @@ -388,7 +388,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 @@ -203,7 +203,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 @@ -677,7 +677,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 @@ -214,23 +214,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 @@ -249,7 +249,7 @@ out target
if (hasOnlyGenerics) {
genericTypeDefinition = Value.DeclaringType.GetGenericTypeDefinition();
}
} else if (Value.DeclaringType.IsGenericTypeDefinition()) {
} else if (Value.DeclaringType.IsGenericTypeDefinition) {
genericTypeDefinition = Value.DeclaringType;
}

Expand All @@ -259,19 +259,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/MetaPythonType.Calls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ internal partial class MetaPythonType : MetaPythonObject, IPythonInvokable {
);
} else {
string msg;
if (Value.UnderlyingSystemType.IsAbstract()) {
if (Value.UnderlyingSystemType.IsAbstract) {
msg = String.Format("Cannot create instances of {0} because it is abstract", Value.Name);
}else{
msg = String.Format("Cannot create instances of {0} because it has no public constructors", Value.Name);
Expand Down Expand Up @@ -146,7 +146,7 @@ internal 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 @@ -969,7 +969,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 @@ -171,7 +171,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
10 changes: 5 additions & 5 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 @@ -99,8 +99,8 @@ public PythonBinder(PythonBinder binder) {
}

internal static MethodInfo GetGenericConvertMethod(Type toType) {
if (toType.IsValueType()) {
if (toType.IsGenericType() && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) {
if (toType.IsValueType) {
if (toType.IsGenericType && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) {
return typeof(Converter).GetMethod(nameof(Converter.ConvertToNullableType));
} else {
return typeof(Converter).GetMethod(nameof(Converter.ConvertToValueType));
Expand Down Expand Up @@ -416,7 +416,7 @@ private void AddExtensionTypes(Type t, List<Type> list) {
}
}

if (t.IsGenericType()) {
if (t.IsGenericType) {
// search for generic extensions, e.g. ListOfTOps<T> for List<T>,
// we then make a new generic type out of the extension type.
Type typeDef = t.GetGenericTypeDefinition();
Expand Down Expand Up @@ -822,7 +822,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 @@ -47,7 +47,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 @@ -331,7 +331,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 @@ -623,7 +623,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(PythonList) || fromType.IsSubclassOf(typeof(PythonList)))) {
if (toParameter.Type.IsGenericType() &&
if (toParameter.Type.IsGenericType &&
toParameter.Type.GetGenericTypeDefinition() == typeof(IList<>) &&
toParameter.ParameterInfo.IsDefined(typeof(BytesConversionAttribute), false)) {
return false;
Expand Down Expand Up @@ -127,7 +127,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 @@ -1134,7 +1134,7 @@ private static void MakeSlotCallWorker(PythonContext/*!*/ state, PythonTypeSlot/
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
4 changes: 2 additions & 2 deletions Src/IronPython/Runtime/ClrModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -977,11 +977,11 @@ public static PythonTuple GetSubclassedTypes() {
Type clrBaseType = info.BaseType;
Type tempType = clrBaseType;
while (tempType != null) {
if (tempType.IsGenericType() && tempType.GetGenericTypeDefinition() == typeof(Extensible<>)) {
if (tempType.IsGenericType && tempType.GetGenericTypeDefinition() == typeof(Extensible<>)) {
clrBaseType = tempType.GetGenericArguments()[0];
break;
}
tempType = tempType.GetBaseType();
tempType = tempType.BaseType;
}

PythonType baseType = DynamicHelpers.GetPythonTypeFromType(clrBaseType);
Expand Down
Loading