Skip to content

Commit 15f1d5f

Browse files
committed
Work on ClreTypeSpec2 resolver
1 parent db11b9e commit 15f1d5f

File tree

3 files changed

+100
-436
lines changed

3 files changed

+100
-436
lines changed

Clojure/Clojure/Lib/ClrTypeSpec.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ internal abstract class ATypeName : IClrTypeName
6767

6868
public bool Equals(IClrTypeName other)
6969
{
70-
return other != null && DisplayName == other.DisplayName;
70+
return other is not null && DisplayName == other.DisplayName;
7171
}
7272

7373
public override int GetHashCode()
@@ -129,8 +129,7 @@ public string InternalName
129129
{
130130
get
131131
{
132-
if (internal_name == null)
133-
internal_name = GetInternalName();
132+
internal_name ??= GetInternalName();
134133
return internal_name;
135134
}
136135
}
@@ -169,7 +168,7 @@ public ClrArraySpec(int dimensions, bool bound)
169168
public override bool Equals(object obj)
170169
{
171170
var o = obj as ClrArraySpec;
172-
if (o == null)
171+
if (o is null)
173172
return false;
174173
return o._dimensions == _dimensions && o._isBound == _isBound;
175174
}
@@ -218,7 +217,7 @@ public ClrPointerSpec(int pointer_level)
218217
public override bool Equals(object obj)
219218
{
220219
var o = obj as ClrPointerSpec;
221-
if (o == null)
220+
if (o is null)
222221
return false;
223222
return o.pointer_level == pointer_level;
224223
}
@@ -264,7 +263,7 @@ public IEnumerable<IClrTypeName> Nested
264263
{
265264
get
266265
{
267-
if (_nested != null)
266+
if (_nested is not null)
268267
return _nested;
269268
else
270269
return Array.Empty<IClrTypeName>();
@@ -275,7 +274,7 @@ public IEnumerable<IClrModifierSpec> Modifiers
275274
{
276275
get
277276
{
278-
if (_modifierSpec != null)
277+
if (_modifierSpec is not null)
279278
return _modifierSpec;
280279
else
281280
return Array.Empty<IClrModifierSpec>();
@@ -286,7 +285,7 @@ public IEnumerable<ClrTypeSpec> GenericParams
286285
{
287286
get
288287
{
289-
if (_genericParams != null)
288+
if (_genericParams is not null)
290289
return _genericParams;
291290
else
292291
return Array.Empty<ClrTypeSpec>();
@@ -332,7 +331,7 @@ string GetDisplayFullName(DisplayNameFormat flags)
332331
{
333332
if (i > 0)
334333
sb.Append(", ");
335-
if (_genericParams[i]._assemblyName != null)
334+
if (_genericParams[i]._assemblyName is not null)
336335
sb.Append('[').Append(_genericParams[i].DisplayFullName).Append(']');
337336
else
338337
sb.Append(_genericParams[i].DisplayFullName);
@@ -343,7 +342,7 @@ string GetDisplayFullName(DisplayNameFormat flags)
343342
if (wantModifiers)
344343
GetModifierString(sb);
345344

346-
if (_assemblyName != null && wantAssembly)
345+
if (_assemblyName is not null && wantAssembly)
347346
sb.Append(", ").Append(_assemblyName);
348347

349348
return sb.ToString();
@@ -448,7 +447,7 @@ void AddName(string type_name)
448447
}
449448
else
450449
{
451-
if (_nested == null)
450+
if (_nested is null)
452451
_nested = new List<IClrTypeIdentifier>();
453452
_nested.Add(ParsedTypeIdentifier(type_name));
454453
}
@@ -487,7 +486,7 @@ static IClrTypeIdentifier ParsedTypeIdentifier(string displayName)
487486
public static ClrTypeSpec Parse(string typeName)
488487
{
489488
int pos = 0;
490-
if (typeName == null)
489+
if (typeName is null)
491490
throw new ArgumentNullException("typeName");
492491

493492
ClrTypeSpec res = Parse(typeName, ref pos, false, true);
@@ -716,14 +715,14 @@ public Type Resolve(
716715
if (assemblyResolver is null && typeResolver is null)
717716
throw new ArgumentException("At least one of assemblyResolver or typeResolver must be non-null");
718717

719-
if (_assemblyName != null)
718+
if (_assemblyName is not null)
720719
{
721-
if (assemblyResolver != null)
720+
if (assemblyResolver is not null)
722721
asm = assemblyResolver(new AssemblyName(_assemblyName));
723722
else
724723
asm = Assembly.Load(_assemblyName);
725724

726-
if (asm == null)
725+
if (asm is null)
727726
{
728727
if (throwOnError)
729728
throw new FileNotFoundException("Could not resolve assembly '" + _assemblyName + "'");
@@ -732,6 +731,7 @@ public Type Resolve(
732731
}
733732

734733
Type type = null;
734+
735735
if (typeResolver is not null)
736736
type = typeResolver(asm, _name.DisplayName, ignoreCase);
737737
else
@@ -744,12 +744,12 @@ public Type Resolve(
744744
return null;
745745
}
746746

747-
if (_nested != null)
747+
if (_nested is not null)
748748
{
749749
foreach (var n in _nested)
750750
{
751751
var tmp = type.GetNestedType(n.DisplayName, BindingFlags.Public | BindingFlags.NonPublic);
752-
if (tmp == null)
752+
if (tmp is null)
753753
{
754754
if (throwOnError)
755755
throw new TypeLoadException("Could not resolve type '" + n + "'");
@@ -759,13 +759,13 @@ public Type Resolve(
759759
}
760760
}
761761

762-
if (_genericParams != null)
762+
if (_genericParams is not null)
763763
{
764764
Type[] args = new Type[_genericParams.Count];
765765
for (int i = 0; i < args.Length; ++i)
766766
{
767767
var tmp = _genericParams[i].Resolve(assemblyResolver, typeResolver, throwOnError, ignoreCase /*, ref stackMark */);
768-
if (tmp == null)
768+
if (tmp is null)
769769
{
770770
if (throwOnError)
771771
throw new TypeLoadException("Could not resolve type '" + _genericParams[i]._name + "'");
@@ -776,7 +776,7 @@ public Type Resolve(
776776
type = type.MakeGenericType(args);
777777
}
778778

779-
if (_modifierSpec != null)
779+
if (_modifierSpec is not null)
780780
{
781781
foreach (var md in _modifierSpec)
782782
type = md.Resolve(type);
@@ -796,12 +796,12 @@ public Type Resolve(
796796
public static Type GetTypeFromName(string name)
797797
{
798798
ClrTypeSpec spec = Parse(name);
799-
if (spec == null)
799+
if (spec is null)
800800
return null;
801801
return spec.Resolve(
802802
assyName => Assembly.Load(assyName),
803803
//(assy, typeName) => assy == null ? RT.classForName(typeName) : assy.GetType(typeName)); <--- this goes into an infinite loop on a non-existent typename
804-
(assy, typeName, ignoreCase) => assy == null ? (name.Equals(typeName) ? null : RT.classForName(typeName)) : assy.GetType(typeName),
804+
(assy, typeName, ignoreCase) => assy is null ? (name.Equals(typeName) ? null : RT.classForName(typeName)) : assy.GetType(typeName),
805805
false,
806806
false);
807807
}

0 commit comments

Comments
 (0)