Skip to content

Commit 24faf30

Browse files
committed
more compiler code cleanp
1 parent 0eae960 commit 24faf30

File tree

6 files changed

+132
-223
lines changed

6 files changed

+132
-223
lines changed

Clojure/Clojure/CljCompiler/Ast/BindingInit.cs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,31 @@
88
* You must not remove this notice, or any other, from this software.
99
**/
1010

11-
/**
12-
* Author: David Miller
13-
**/
14-
15-
1611
namespace clojure.lang.CljCompiler.Ast
1712
{
18-
public struct BindingInit
13+
public struct BindingInit(LocalBinding binding, Expr init)
1914
{
2015
#region Data
16+
public readonly LocalBinding Binding => binding;
2117

22-
private readonly LocalBinding _binding;
23-
public LocalBinding Binding { get { return _binding; } }
24-
25-
private readonly Expr _init;
26-
public Expr Init { get { return _init; } }
18+
public readonly Expr Init => init;
2719

2820
#endregion
2921

3022
#region Ctors
3123

32-
public BindingInit(LocalBinding binding, Expr init)
33-
{
34-
_binding = binding;
35-
_init = init;
36-
}
37-
3824
#endregion
3925

4026
#region Object overrides
4127

42-
public override bool Equals(object obj)
28+
public override readonly bool Equals(object obj)
4329
{
44-
if ( ! (obj is BindingInit) )
30+
if (obj is not BindingInit)
4531
return false;
4632

47-
BindingInit bi = (BindingInit) obj;
33+
BindingInit bi = (BindingInit)obj;
4834

49-
return _binding.Equals(bi._binding) && bi._init.Equals(bi._init);
35+
return binding.Equals(bi.Binding) && init.Equals(bi.Init);
5036
}
5137

5238
public static bool operator ==(BindingInit b1, BindingInit b2)
@@ -59,11 +45,11 @@ public override bool Equals(object obj)
5945
return !b1.Equals(b2);
6046
}
6147

62-
public override int GetHashCode()
48+
public override readonly int GetHashCode()
6349
{
64-
return Util.hashCombine(_binding.GetHashCode(), _init.GetHashCode());
50+
return Util.hashCombine(binding.GetHashCode(), init.GetHashCode());
6551
}
66-
52+
6753
#endregion
6854
}
6955
}

Clojure/Clojure/CljCompiler/Ast/BodyExpr.cs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
* You must not remove this notice, or any other, from this software.
99
**/
1010

11-
/**
12-
* Author: David Miller
13-
**/
14-
1511
using System;
1612

1713
namespace clojure.lang.CljCompiler.Ast
@@ -21,15 +17,9 @@ public class BodyExpr : Expr, MaybePrimitiveExpr
2117
#region Data
2218

2319
readonly IPersistentVector _exprs;
24-
public IPersistentVector Exprs { get { return _exprs; } }
20+
public IPersistentVector Exprs => _exprs;
2521

26-
public Expr LastExpr
27-
{
28-
get
29-
{
30-
return (Expr)_exprs.nth(_exprs.count() - 1);
31-
}
32-
}
22+
public Expr LastExpr => (Expr)_exprs.nth(_exprs.count() - 1);
3323

3424
#endregion
3525

@@ -44,15 +34,9 @@ public BodyExpr(IPersistentVector exprs)
4434

4535
#region Type mangling
4636

47-
public bool HasClrType
48-
{
49-
get { return LastExpr.HasClrType; }
50-
}
37+
public bool HasClrType => LastExpr.HasClrType;
5138

52-
public Type ClrType
53-
{
54-
get { return LastExpr.ClrType; }
55-
}
39+
public Type ClrType => LastExpr.ClrType;
5640

5741
#endregion
5842

Clojure/Clojure/CljCompiler/Ast/LocalBinding.cs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
* You must not remove this notice, or any other, from this software.
99
**/
1010

11-
/**
12-
* Author: David Miller
13-
**/
14-
1511
using System;
1612
using System.Reflection.Emit;
1713

@@ -22,32 +18,32 @@ public sealed class LocalBinding
2218
#region Data
2319

2420
private readonly Symbol _sym;
25-
public Symbol Symbol { get { return _sym; } }
21+
public Symbol Symbol => _sym;
2622

2723
public Symbol Tag { get; set; }
2824

2925
public Expr Init { get; set; }
3026

3127
private readonly String _name;
32-
public String Name { get { return _name; } }
28+
public String Name => _name;
29+
30+
public int Index { get; set; }
3331

34-
public int Index { get; set;}
35-
3632
public LocalBuilder LocalVar { get; set; }
3733

3834
readonly bool _isArg;
39-
public bool IsArg { get { return _isArg; } }
35+
public bool IsArg => _isArg;
4036

4137
readonly bool _isByRef;
42-
public bool IsByRef { get { return _isByRef; } }
38+
public bool IsByRef => _isByRef;
4339

4440
readonly bool _isThis;
45-
public bool IsThis { get { return _isThis; } }
41+
public bool IsThis => _isThis;
4642

4743
public bool RecurMismatch { get; set; }
4844

4945
readonly Type _declaredType;
50-
public Type DeclaredType { get { return _declaredType; } }
46+
public Type DeclaredType => _declaredType;
5147

5248
bool _hasTypeCached = false;
5349
bool _cachedHasType = false;
@@ -87,7 +83,7 @@ public bool HasClrType
8783
if (Init != null
8884
&& Init.HasClrType
8985
&& Util.IsPrimitive(Init.ClrType)
90-
&& !(Init is MaybePrimitiveExpr))
86+
&& Init is not MaybePrimitiveExpr)
9187
_cachedHasType = false;
9288
else
9389
_cachedHasType = Tag != null || (Init != null && Init.HasClrType);
@@ -101,16 +97,12 @@ public Type ClrType
10197
{
10298
get
10399
{
104-
if (_cachedType == null)
105-
_cachedType = Tag != null ? HostExpr.TagToType(Tag) : Init.ClrType;
100+
_cachedType ??= Tag != null ? HostExpr.TagToType(Tag) : Init.ClrType;
106101
return _cachedType;
107102
}
108103
}
109104

110-
public Type PrimitiveType
111-
{
112-
get { return Compiler.MaybePrimitiveType(Init); }
113-
}
105+
public Type PrimitiveType => Compiler.MaybePrimitiveType(Init);
114106

115107
#endregion
116108
}

Clojure/Clojure/CljCompiler/Ast/LocalBindingExpr.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,19 @@
88
* You must not remove this notice, or any other, from this software.
99
**/
1010

11-
/**
12-
* Author: David Miller
13-
**/
14-
1511
using System;
1612

17-
1813
namespace clojure.lang.CljCompiler.Ast
1914
{
2015
public class LocalBindingExpr : Expr, MaybePrimitiveExpr, AssignableExpr
2116
{
2217
#region Data
2318

2419
readonly LocalBinding _b;
25-
public LocalBinding Binding { get { return _b; } }
20+
public LocalBinding Binding => _b;
2621

2722
readonly Symbol _tag;
28-
public Symbol Tag { get { return _tag; } }
23+
public Symbol Tag => _tag;
2924

3025
Type _cachedType;
3126

@@ -35,7 +30,7 @@ public class LocalBindingExpr : Expr, MaybePrimitiveExpr, AssignableExpr
3530

3631
public LocalBindingExpr(LocalBinding b, Symbol tag)
3732
{
38-
if (b.PrimitiveType != null && tag != null)
33+
if (b.PrimitiveType is not null && tag is not null)
3934
if (!b.PrimitiveType.Equals(Compiler.TagType(tag)))
4035
throw new InvalidOperationException("Can't type hint a primitive local with a diffent type");
4136
else _tag = null;
@@ -47,17 +42,13 @@ public LocalBindingExpr(LocalBinding b, Symbol tag)
4742

4843
#region Type mangling
4944

50-
public bool HasClrType
51-
{
52-
get { return _tag != null || _b.HasClrType; }
53-
}
45+
public bool HasClrType => _tag is not null || _b.HasClrType;
5446

5547
public Type ClrType
5648
{
5749
get
5850
{
59-
if (_cachedType == null)
60-
_cachedType = _tag != null ? HostExpr.TagToType(_tag) : _b.ClrType;
51+
_cachedType ??= _tag != null ? HostExpr.TagToType(_tag) : _b.ClrType;
6152
return _cachedType;
6253
}
6354
}
@@ -81,9 +72,9 @@ public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
8172
objx.EmitLocal(ilg, _b);
8273
}
8374

84-
public bool HasNormalExit() { return true; }
75+
public bool HasNormalExit() => true;
8576

86-
public bool CanEmitPrimitive => _b.PrimitiveType != null;
77+
public bool CanEmitPrimitive => _b.PrimitiveType is not null;
8778

8879
public void EmitUnboxed(RHC rhc, ObjExpr objx, CljILGen ilg) => objx.EmitUnboxedLocal(ilg, _b);
8980

Clojure/Clojure/CljCompiler/Ast/MethodParamExpr.cs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,39 @@
1717

1818
namespace clojure.lang.CljCompiler.Ast
1919
{
20-
public sealed class MethodParamExpr : Expr, MaybePrimitiveExpr
20+
public sealed class MethodParamExpr(Type t) : Expr, MaybePrimitiveExpr
2121
{
22-
#region Data
2322

24-
readonly Type _t;
25-
public Type Type { get { return _t; } }
23+
#region Data
24+
public Type Type => t;
2625

2726
#endregion
2827

2928
#region C-tors
3029

31-
public MethodParamExpr(Type t)
32-
{
33-
_t = t;
34-
}
35-
3630
#endregion
3731

3832
#region Type mangling
3933

40-
public bool HasClrType => _t != null;
34+
public bool HasClrType => t != null;
4135

42-
public Type ClrType => _t;
36+
public Type ClrType => t;
4337

4438
#endregion
4539

4640
#region eval
4741

48-
public object Eval()
49-
{
50-
throw new InvalidOperationException("Can't eval");
51-
}
42+
public object Eval() => throw new InvalidOperationException("Can't eval");
5243

5344
#endregion
5445

5546
#region Code generation
5647

5748
public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg) => throw new InvalidOperationException("Can't emit");
5849

59-
public bool HasNormalExit() { return true; }
50+
public bool HasNormalExit() => true;
6051

61-
public bool CanEmitPrimitive => Util.IsPrimitive(_t);
52+
public bool CanEmitPrimitive => Util.IsPrimitive(t);
6253

6354
public void EmitUnboxed(RHC rhc, ObjExpr objx, CljILGen ilg) => throw new InvalidOperationException("Can't emit");
6455

0 commit comments

Comments
 (0)