88 * You must not remove this notice, or any other, from this software.
99 **/
1010
11- /**
12- * Author: David Miller
13- **/
14-
1511using System ;
1612using System . Reflection ;
1713using System . Reflection . Emit ;
1814
19-
2015namespace clojure . lang . CljCompiler . Ast
2116{
2217 public class DefExpr : Expr
2318 {
2419 #region Data
2520
2621 readonly Var _var ;
27- public Var Var { get { return _var ; } }
22+ public Var Var => _var ;
2823
2924 readonly Expr _init ;
30- public Expr Init { get { return _init ; } }
25+ public Expr Init => _init ;
3126
3227 readonly Expr _meta ;
33- public Expr Meta { get { return _meta ; } }
28+ public Expr Meta => _meta ;
3429
3530 readonly bool _initProvided ;
36- public bool InitProvided { get { return _initProvided ; } }
37-
31+ public bool InitProvided => _initProvided ;
32+
3833 readonly bool _isDynamic ;
39- public bool IsDynamic { get { return _isDynamic ; } }
40-
34+ public bool IsDynamic => _isDynamic ;
35+
4136 readonly string _source ;
42- public string Source { get { return _source ; } }
43-
37+ public string Source => _source ;
38+
4439 readonly int _line ;
45- public int Line { get { return _line ; } }
46-
40+ public int Line => _line ;
41+
4742 readonly int _column ;
48- public int Column { get { return _column ; } }
43+ public int Column => _column ;
4944
5045 #endregion
5146
@@ -67,15 +62,9 @@ public DefExpr(string source, int line, int column, Var var, Expr init, Expr met
6762
6863 #region Type mangling
6964
70- public bool HasClrType
71- {
72- get { return true ; }
73- }
65+ public bool HasClrType => true ;
7466
75- public Type ClrType
76- {
77- get { return typeof ( Var ) ; }
78- }
67+ public Type ClrType => typeof ( Var ) ;
7968
8069 #endregion
8170
@@ -101,19 +90,19 @@ public Expr Parse(ParserContext pcon, object form)
10190
10291 Symbol sym = RT . second ( form ) as Symbol ;
10392
104- if ( sym == null )
93+ if ( sym is null )
10594 throw new ParseException ( "First argument to def must be a Symbol." ) ;
10695
10796 //Console.WriteLine("Def {0}", sym.Name);
108-
97+
10998 Var v = Compiler . LookupVar ( sym , true ) ;
11099
111- if ( v == null )
100+ if ( v is null )
112101 throw new ParseException ( "Can't refer to qualified var that doesn't exist" ) ;
113102
114103 if ( ! v . Namespace . Equals ( Compiler . CurrentNamespace ) )
115104 {
116- if ( sym . Namespace == null )
105+ if ( sym . Namespace is null )
117106 {
118107 v = Compiler . CurrentNamespace . intern ( sym ) ;
119108 Compiler . RegisterVar ( v ) ;
@@ -133,7 +122,7 @@ public Expr Parse(ParserContext pcon, object form)
133122 {
134123 RT . errPrintWriter ( ) . WriteLine ( "Warning: {0} not declared dynamic and thus is not dynamically rebindable, "
135124 + "but its name suggests otherwise. Please either indicate ^:dynamic {0} or change the name. ({1}:{2}\n " ,
136- sym , Compiler . SourcePathVar . get ( ) , Compiler . LineVar . get ( ) ) ;
125+ sym , Compiler . SourcePathVar . get ( ) , Compiler . LineVar . get ( ) ) ;
137126 RT . errPrintWriter ( ) . Flush ( ) ;
138127 }
139128
@@ -148,10 +137,10 @@ public Expr Parse(ParserContext pcon, object form)
148137
149138 Object source_path = Compiler . SourcePathVar . get ( ) ;
150139 source_path = source_path ?? "NO_SOURCE_FILE" ;
151- mm = ( IPersistentMap ) RT . assoc ( mm , RT . LineKey , Compiler . LineVar . get ( ) )
152- . assoc ( RT . ColumnKey , Compiler . ColumnVar . get ( ) )
140+ mm = ( IPersistentMap ) RT . assoc ( mm , RT . LineKey , Compiler . LineVar . get ( ) )
141+ . assoc ( RT . ColumnKey , Compiler . ColumnVar . get ( ) )
153142 . assoc ( RT . FileKey , source_path ) ;
154- //.assoc(RT.SOURCE_SPAN_KEY,Compiler.SOURCE_SPAN.deref());
143+ //.assoc(RT.SOURCE_SPAN_KEY,Compiler.SOURCE_SPAN.deref());
155144 if ( docstring != null )
156145 mm = ( IPersistentMap ) RT . assoc ( mm , RT . DocKey , docstring ) ;
157146
@@ -168,15 +157,15 @@ public Expr Parse(ParserContext pcon, object form)
168157
169158 mm = ( IPersistentMap ) Compiler . ElideMeta ( mm ) ;
170159
171- Expr meta = mm == null || mm . count ( ) == 0 ? null : Compiler . Analyze ( pcon . EvalOrExpr ( ) , mm ) ;
172- Expr init = Compiler . Analyze ( pcon . EvalOrExpr ( ) , RT . third ( form ) , v . Symbol . Name ) ;
160+ Expr meta = mm is null || mm . count ( ) == 0 ? null : Compiler . Analyze ( pcon . EvalOrExpr ( ) , mm ) ;
161+ Expr init = Compiler . Analyze ( pcon . EvalOrExpr ( ) , RT . third ( form ) , v . Symbol . Name ) ;
173162 bool initProvided = RT . count ( form ) == 3 ;
174163
175164 return new DefExpr (
176165 ( string ) Compiler . SourceVar . deref ( ) ,
177166 Compiler . LineVarDeref ( ) ,
178167 Compiler . ColumnVarDeref ( ) ,
179- v , init , meta , initProvided , isDynamic ) ;
168+ v , init , meta , initProvided , isDynamic ) ;
180169 }
181170 }
182171
@@ -190,10 +179,10 @@ public object Eval()
190179 {
191180 if ( _initProvided )
192181 _var . bindRoot ( _init . Eval ( ) ) ;
193- if ( _meta != null )
182+ if ( _meta is not null )
194183 {
195- if ( _initProvided || true ) // includesExplicitMetadata((MapExpr)_meta))
196- _var . setMeta ( ( IPersistentMap ) _meta . Eval ( ) ) ;
184+ // if (InitProvided || true) // includesExplicitMetadata((MapExpr)_meta)) -- the last time I checked X || true is always true
185+ _var . setMeta ( ( IPersistentMap ) _meta . Eval ( ) ) ;
197186 }
198187 return _var . setDynamic ( _isDynamic ) ;
199188 }
@@ -231,12 +220,12 @@ public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
231220 expr . EmitForDefn ( objx , ilg ) ;
232221 else
233222 _init . Emit ( RHC . Expression , objx , ilg ) ;
234- ilg . Emit ( OpCodes . Call , Compiler . Method_Var_bindRoot ) ;
223+ ilg . Emit ( OpCodes . Call , Compiler . Method_Var_bindRoot ) ;
235224 }
236225
237- if ( _meta != null )
226+ if ( _meta is not null )
238227 {
239- if ( _initProvided || true ) //IncludesExplicitMetadata((MapExpr)_meta))
228+ // if (InitProvided || true) //IncludesExplicitMetadata((MapExpr)_meta)) -- the last time I checked X || true is always true
240229 {
241230 ilg . Emit ( OpCodes . Dup ) ;
242231 _meta . Emit ( RHC . Expression , objx , ilg ) ;
@@ -255,6 +244,7 @@ public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
255244
256245 #region Misc
257246
247+ // This is in the JVM code, but all uses are commented out.
258248 //private static bool IncludesExplicitMetadata(MapExpr expr)
259249 //{
260250 // for (int i = 0; i < expr.KeyVals.count(); i += 2)
0 commit comments