Skip to content

Commit c1fdbd5

Browse files
committed
Random code cleanup
1 parent 87cc110 commit c1fdbd5

File tree

12 files changed

+131
-206
lines changed

12 files changed

+131
-206
lines changed

Clojure/Clojure/CljCompiler/Ast/BodyExpr.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public Expr Parse(ParserContext pcon, object frms)
9090
public object Eval()
9191
{
9292
object ret = null;
93-
for ( int i=0; i<_exprs.count(); i++ )
93+
for (int i = 0; i < _exprs.count(); i++)
9494
ret = ((Expr)_exprs.nth(i)).Eval();
9595

9696
return ret;
@@ -110,10 +110,7 @@ public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
110110
LastExpr.Emit(rhc, objx, ilg);
111111
}
112112

113-
public bool CanEmitPrimitive
114-
{
115-
get { return LastExpr is MaybePrimitiveExpr expr && expr.CanEmitPrimitive; }
116-
}
113+
public bool CanEmitPrimitive => LastExpr is MaybePrimitiveExpr expr && expr.CanEmitPrimitive;
117114

118115
public void EmitUnboxed(RHC rhc, ObjExpr objx, CljILGen ilg)
119116
{
@@ -126,7 +123,7 @@ public void EmitUnboxed(RHC rhc, ObjExpr objx, CljILGen ilg)
126123
mbe.EmitUnboxed(rhc, objx, ilg);
127124
}
128125

129-
public bool HasNormalExit() { return LastExpr.HasNormalExit(); }
126+
public bool HasNormalExit() => LastExpr.HasNormalExit();
130127

131128
#endregion
132129
}

Clojure/Clojure/CljCompiler/Ast/CaseExpr.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ public CaseExpr(IPersistentMap sourceSpan, LocalBindingExpr expr, int shift, int
8888
throw new ArgumentException("Unexpected test type: " + testType);
8989
_testType = testType;
9090
_skipCheck = skipCheck;
91-
ICollection<Expr> returns = new List<Expr>(thens.Values)
92-
{
93-
defaultExpr
94-
};
91+
ICollection<Expr> returns = [.. thens.Values, defaultExpr];
9592
_returnType = Compiler.MaybeClrType(returns);
9693
if (RT.count(skipCheck) > 0 && RT.booleanCast(RT.WarnOnReflectionVar.deref()))
9794
{
@@ -515,10 +512,7 @@ public bool HasNormalExit()
515512
return false;
516513
}
517514

518-
public bool CanEmitPrimitive
519-
{
520-
get { return Util.IsPrimitive(_returnType); }
521-
}
515+
public bool CanEmitPrimitive => Util.IsPrimitive(_returnType);
522516

523517
public void EmitUnboxed(RHC rhc, ObjExpr objx, CljILGen ilg)
524518
{

Clojure/Clojure/CljCompiler/Ast/ConstantExpr.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,22 @@ public ConstantExpr(object v)
3737

3838
#region Type mangling
3939

40-
public override bool HasClrType
41-
{
42-
get
43-
{
44-
return _v.GetType().IsPublic
40+
public override bool HasClrType => _v.GetType().IsPublic
4541
|| _v.GetType().IsNestedPublic
46-
|| typeof(Type).IsInstanceOfType(_v); // This bit of hackery is due to the fact that RuntimeType is not public.
47-
// Without this, System.Int64 would be seen as only type System.Object, not System.RuntimeType.
48-
}
49-
}
42+
|| typeof(Type).IsInstanceOfType(_v); // This bit of hackery is due to the fact that RuntimeType is not public. // Without this, System.Int64 would be seen as only type System.Object, not System.RuntimeType.
5043

5144
public override Type ClrType
5245
{
5346
get
5447
{
55-
if (_v is APersistentMap)
56-
return typeof(APersistentMap);
57-
else if (_v is APersistentSet)
58-
return typeof(APersistentSet);
59-
else if (_v is APersistentVector)
60-
return typeof(APersistentVector);
61-
else if (_v is Type)
62-
return typeof(Type);
63-
else
64-
return _v.GetType();
48+
return _v switch
49+
{
50+
APersistentMap => typeof(APersistentMap),
51+
APersistentSet => typeof(APersistentSet),
52+
APersistentVector => typeof(APersistentVector),
53+
Type => typeof(Type),
54+
_ => _v.GetType()
55+
};
6556
}
6657
}
6758

Clojure/Clojure/CljCompiler/Ast/FnExpr.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public FnExpr(object tag)
4747
}
4848

4949
#endregion
50-
50+
5151
#region Misc
5252

5353
// This naming convention drawn from the Java code.
@@ -61,7 +61,7 @@ internal void ComputeNames(ISeq form, string name)
6161

6262
Symbol nm = RT.second(form) as Symbol;
6363

64-
if (nm != null )
64+
if (nm != null)
6565
{
6666
name = nm.Name + "__" + RT.nextID();
6767
}
@@ -95,7 +95,7 @@ public override Type ClrType
9595
{
9696
get
9797
{
98-
if (_cachedType == null )
98+
if (_cachedType == null)
9999
_cachedType = _tag != null ? HostExpr.TagToType(_tag) : typeof(AFunction);
100100
return _cachedType;
101101
}
@@ -109,29 +109,29 @@ public static Expr Parse(ParserContext pcon, ISeq form, string name)
109109
{
110110
ISeq origForm = form;
111111

112-
FnExpr fn = new FnExpr(Compiler.TagOf(form))
112+
FnExpr fn = new(Compiler.TagOf(form))
113113
{
114114
Src = form
115115
};
116116

117117
Keyword retKey = Keyword.intern(null, "rettag"); // TODO: make static
118118
object retTag = RT.get(RT.meta(form), retKey);
119119
ObjMethod enclosingMethod = (ObjMethod)Compiler.MethodVar.deref();
120-
fn._hasEnclosingMethod = enclosingMethod != null;
120+
fn._hasEnclosingMethod = enclosingMethod is not null;
121121

122122

123-
if (((IMeta)form.first()).meta() != null)
123+
if (((IMeta)form.first()).meta() is not null)
124124
{
125125
fn.OnceOnly = RT.booleanCast(RT.get(RT.meta(form.first()), KW_ONCE));
126126
}
127127

128128
fn.ComputeNames(form, name);
129129

130-
List<string> prims = new List<string>();
130+
List<string> prims = new();
131131

132132
//arglist might be preceded by symbol naming this fn
133-
Symbol nm = RT.second(form) as Symbol;
134-
if (nm != null)
133+
Symbol nm = RT.second(form) as Symbol;
134+
if (nm is not null)
135135
{
136136
fn.ThisName = nm.Name;
137137
form = RT.cons(Compiler.FnSym, RT.next(RT.next(form)));
@@ -162,14 +162,14 @@ public static Expr Parse(ParserContext pcon, ISeq form, string name)
162162
Compiler.ProtocolCallsitesVar, PersistentVector.EMPTY,
163163
Compiler.VarCallsitesVar, Compiler.EmptyVarCallSites(),
164164
Compiler.NoRecurVar, null));
165-
SortedDictionary<int, FnMethod> methods = new SortedDictionary<int, FnMethod>();
165+
SortedDictionary<int, FnMethod> methods = new();
166166
FnMethod variadicMethod = null;
167167
bool usesThis = false;
168168

169169
for (ISeq s = RT.next(form); s != null; s = RT.next(s))
170170
{
171171
FnMethod f = FnMethod.Parse(fn, (ISeq)RT.first(s), retTag);
172-
if ( f.UsesThis)
172+
if (f.UsesThis)
173173
{
174174
//Console.WriteLine("{0} uses this",fn.Name);
175175
usesThis = true;
@@ -200,17 +200,17 @@ public static Expr Parse(ParserContext pcon, ISeq form, string name)
200200
if (variadicMethod != null)
201201
allMethods = RT.conj(allMethods, variadicMethod);
202202

203-
if ( fn.CanBeDirect )
203+
if (fn.CanBeDirect)
204204
{
205205
for (ISeq s = RT.seq(allMethods); s != null; s = s.next())
206206
{
207207
FnMethod fm = s.first() as FnMethod;
208-
if ( fm.Locals != null)
208+
if (fm.Locals != null)
209209
{
210210
for (ISeq sl = RT.seq(RT.keys(fm.Locals)); sl != null; sl = sl.next())
211211
{
212212
LocalBinding lb = sl.first() as LocalBinding;
213-
if ( lb.IsArg)
213+
if (lb.IsArg)
214214
lb.Index -= 1;
215215
}
216216
}
@@ -266,7 +266,7 @@ public static Expr Parse(ParserContext pcon, ISeq form, string name)
266266

267267
internal void AddMethod(FnMethod method)
268268
{
269-
Methods = RT.conj(Methods,method);
269+
Methods = RT.conj(Methods, method);
270270
}
271271

272272

@@ -282,20 +282,20 @@ internal void AddMethod(FnMethod method)
282282
//static readonly MethodInfo Method_FnExpr_GetDynMethod = typeof(FnExpr).GetMethod("GetDynMethod");
283283
//static readonly MethodInfo Method_FnExpr_GetCompiledConstants = typeof(FnExpr).GetMethod("GetCompiledConstants");
284284

285-
static readonly Dictionary<int, Dictionary<int, DynamicMethod > > DynMethodMap = new Dictionary<int,Dictionary<int,DynamicMethod>>();
286-
static readonly Dictionary<int, object[]> ConstantsMap = new Dictionary<int, object[]>();
285+
static readonly Dictionary<int, Dictionary<int, DynamicMethod>> DynMethodMap = new();
286+
static readonly Dictionary<int, object[]> ConstantsMap = new();
287287

288288
public static DynamicMethod GetDynMethod(int key, int arity)
289289
{
290290
DynamicMethod dm = DynMethodMap[key][arity];
291291
if (dm == null)
292292
Console.WriteLine("Bad dynmeth retrieval");
293293
return dm;
294-
// Dictionary<int, WeakReference > dict = DynMethodMap[key];
295-
// WeakReference wr = dict[arity];
296-
// return (DynamicMethod)wr.Target;
294+
// Dictionary<int, WeakReference > dict = DynMethodMap[key];
295+
// WeakReference wr = dict[arity];
296+
// return (DynamicMethod)wr.Target;
297297
}
298-
298+
299299
public static object[] GetCompiledConstants(int key)
300300
{
301301
return ConstantsMap[key];
@@ -354,7 +354,7 @@ protected override void EmitMethods(TypeBuilder tb)
354354
if (IsVariadic)
355355
EmitGetRequiredArityMethod(TypeBuilder, _variadicMethod.RequiredArity);
356356

357-
List<int> supportedArities = new List<int>();
357+
List<int> supportedArities = new();
358358
for (ISeq s = RT.seq(Methods); s != null; s = s.next())
359359
{
360360
FnMethod method = (FnMethod)s.first();
@@ -372,7 +372,7 @@ static void EmitGetRequiredArityMethod(TypeBuilder tb, int requiredArity)
372372
typeof(int),
373373
Type.EmptyTypes);
374374

375-
CljILGen gen = new CljILGen(mb.GetILGenerator());
375+
CljILGen gen = new(mb.GetILGenerator());
376376
gen.EmitInt(requiredArity);
377377
gen.Emit(OpCodes.Ret);
378378
}

Clojure/Clojure/CljCompiler/Ast/InstanceMethodExpr.cs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ public class InstanceMethodExpr : MethodExpr
3434
#region Ctors
3535

3636
public InstanceMethodExpr(
37-
string source,
38-
IPersistentMap spanMap,
39-
Symbol tag,
40-
Expr target,
37+
string source,
38+
IPersistentMap spanMap,
39+
Symbol tag,
40+
Expr target,
4141
Type qualifyingType,
42-
string methodName,
43-
GenericTypeArgList typeArgs,
44-
IList<HostArg> args,
42+
string methodName,
43+
GenericTypeArgList typeArgs,
44+
IList<HostArg> args,
4545
bool tailPosition)
46-
: base(source,spanMap,tag,methodName,typeArgs,args,tailPosition)
46+
: base(source, spanMap, tag, methodName, typeArgs, args, tailPosition)
4747
{
4848
_target = target;
4949
_qualifyingType = qualifyingType ?? (target.HasClrType ? target.ClrType : null);
@@ -61,16 +61,16 @@ public InstanceMethodExpr(
6161
}
6262

6363
public InstanceMethodExpr(
64-
string source,
65-
IPersistentMap
66-
spanMap,
67-
Symbol tag,
68-
Expr target,
64+
string source,
65+
IPersistentMap
66+
spanMap,
67+
Symbol tag,
68+
Expr target,
6969
Type qualifyingType,
70-
string methodName,
71-
MethodInfo resolvedMethod,
72-
GenericTypeArgList typeArgs,
73-
IList<HostArg> args,
70+
string methodName,
71+
MethodInfo resolvedMethod,
72+
GenericTypeArgList typeArgs,
73+
IList<HostArg> args,
7474
bool tailPosition)
7575
: base(source, spanMap, tag, methodName, typeArgs, args, tailPosition)
7676
{
@@ -95,10 +95,10 @@ public override object Eval()
9595
for (int i = 0; i < _args.Count; i++)
9696
argvals[i] = _args[i].ArgExpr.Eval();
9797
if (_method != null)
98-
return Reflector.InvokeMethod(_method,targetVal, argvals);
99-
if (_qualifyingType != null )
98+
return Reflector.InvokeMethod(_method, targetVal, argvals);
99+
if (_qualifyingType != null)
100100
return Reflector.CallInstanceMethod(_qualifyingType, _methodName, _typeArgs, targetVal, argvals);
101-
else
101+
else
102102
return Reflector.CallInstanceMethod(_methodName, _typeArgs, targetVal, argvals);
103103
}
104104
catch (Compiler.CompilerException)
@@ -108,7 +108,7 @@ public override object Eval()
108108
catch (Exception e)
109109
{
110110
throw new Compiler.CompilerException(_source, Compiler.GetLineFromSpanMap(_spanMap), Compiler.GetColumnFromSpanMap(_spanMap), null, Compiler.CompilerException.PhaseExecutionKeyword, e);
111-
}
111+
}
112112
}
113113

114114
#endregion
@@ -134,10 +134,7 @@ public override Type ClrType
134134

135135
#region Code generation
136136

137-
protected override bool IsStaticCall
138-
{
139-
get { return false; }
140-
}
137+
protected override bool IsStaticCall => false;
141138

142139
protected override void EmitTargetExpression(ObjExpr objx, CljILGen ilg)
143140
{

0 commit comments

Comments
 (0)