Skip to content

Commit 5b2d5d6

Browse files
committed
clean up code
1 parent 3c0ee12 commit 5b2d5d6

File tree

1 file changed

+28
-50
lines changed

1 file changed

+28
-50
lines changed

compiler/nimconfcache.nim

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ proc fromNif[T: enum](result: var T; n: var Cursor) =
4343
result = parseEnum[T](pool.strings[n.litId])
4444
inc n
4545

46-
proc fromNif[T: enum](result: var set[T]; n: var Cursor) =
46+
proc fromNif[T: enum](result: var set[T]; tag: string; n: var Cursor) =
47+
expectTag n, tag
48+
inc n
4749
# clear it so that it has the same value as it was stored to the cache.
4850
# some switches turn off options that were turned on when conf was initialized.
4951
result = {}
@@ -53,17 +55,21 @@ proc fromNif[T: enum](result: var set[T]; n: var Cursor) =
5355
inc n
5456
inc n
5557

56-
proc fromNif2[T: enum](result: var set[T]; n: var Cursor) =
58+
proc fromNif2[T: enum](result: var set[T]; tag: string; n: var Cursor) =
5759
# same to fromNif but works with enums `parseEnum` doesn't support.
5860
# e.g. TNoteKind
61+
expectTag n, tag
62+
inc n
5963
result = {}
6064
assert n.kind in {IntLit, ParRi}
6165
while n.kind != ParRi:
6266
result.incl pool.integers[n.intId].T
6367
inc n
6468
inc n
6569

66-
proc fromNif(result: StringTableRef; n: var Cursor) =
70+
proc fromNif(result: StringTableRef; tag: string; n: var Cursor) =
71+
expectTag n, tag
72+
inc n
6773
result.clear
6874
assert n.kind in {ParLe, ParRi}
6975
while n.kind != ParRi:
@@ -274,15 +280,8 @@ proc loadConfigsFromNif(conf: ConfigRef; n: var Cursor) =
274280
fromNif targetCPU, n
275281
conf.target.setTarget(targetOS, targetCPU)
276282

277-
expectTag n, "options"
278-
inc n
279-
fromNif(conf.options, n)
280-
#echo conf.options
281-
282-
expectTag n, "globalOptions"
283-
inc n
284-
fromNif(conf.globalOptions, n)
285-
#echo conf.globalOptions
283+
fromNif conf.options, "options", n
284+
fromNif conf.globalOptions, "globalOptions", n
286285

287286
conf.macrosToExpand.clear
288287
expectTag n, "macrosToExpand"
@@ -304,14 +303,12 @@ proc loadConfigsFromNif(conf: ConfigRef; n: var Cursor) =
304303
conf.arcToExpand[m] = "T"
305304
inc n
306305

307-
fromNif(conf.filenameOption, n)
306+
fromNif conf.filenameOption, n
308307
conf.unitSep = pool.strings[n.litId]
309308
inc n
310309

311-
fromNif(conf.selectedGC, n)
312-
#echo conf.selectedGC
313-
fromNif(conf.exc, n)
314-
#echo conf.exc
310+
fromNif conf.selectedGC, n
311+
fromNif conf.exc, n
315312
conf.hintProcessingDots = pool.integers[n.intId].bool
316313
inc n
317314
conf.verbosity = pool.integers[n.intId]
@@ -327,29 +324,15 @@ proc loadConfigsFromNif(conf: ConfigRef; n: var Cursor) =
327324
inc n
328325
#echo conf.nimbasePattern
329326

330-
expectTag n, "features"
331-
inc n
332-
fromNif(conf.features, n)
333-
expectTag n, "legacyFeatures"
334-
inc n
335-
fromNif(conf.legacyFeatures, n)
336-
fromNif(conf.cCompiler, n)
327+
fromNif conf.features, "features", n
328+
fromNif conf.legacyFeatures, "legacyFeatures", n
329+
fromNif conf.cCompiler, n
337330

338-
expectTag n, "modifiedyNotes"
339-
inc n
340-
fromNif2(conf.modifiedyNotes, n)
341-
expectTag n, "foreignPackageNotes"
342-
inc n
343-
fromNif2(conf.foreignPackageNotes, n)
344-
expectTag n, "notes"
345-
inc n
346-
fromNif2(conf.notes, n)
347-
expectTag n, "warningAsErrors"
348-
inc n
349-
fromNif2(conf.warningAsErrors, n)
350-
expectTag n, "mainPackageNotes"
351-
inc n
352-
fromNif2(conf.mainPackageNotes, n)
331+
fromNif2 conf.modifiedyNotes, "modifiedyNotes", n
332+
fromNif2 conf.foreignPackageNotes, "foreignPackageNotes", n
333+
fromNif2 conf.notes, "notes", n
334+
fromNif2 conf.warningAsErrors, "warningAsErrors", n
335+
fromNif2 conf.mainPackageNotes, "mainPackageNotes", n
353336

354337
conf.errorMax = pool.integers[n.intId]
355338
inc n
@@ -358,9 +341,7 @@ proc loadConfigsFromNif(conf: ConfigRef; n: var Cursor) =
358341
conf.maxCallDepthVM = pool.integers[n.intId]
359342
inc n
360343

361-
expectTag n, "configVars"
362-
inc n
363-
fromNif(conf.configVars, n)
344+
fromNif conf.configVars, "configVars", n
364345

365346
conf.symbols.clear
366347
expectTag n, "defines"
@@ -377,21 +358,18 @@ proc loadConfigsFromNif(conf: ConfigRef; n: var Cursor) =
377358

378359
conf.outFile = pool.strings[n.litId].RelativeFile
379360
inc n
380-
fromNif(conf.outDir, n)
381-
fromNif(conf.prefixDir, n)
382-
fromNif(conf.libpath, n)
383-
fromNif(conf.nimcacheDir, n)
361+
fromNif conf.outDir, n
362+
fromNif conf.prefixDir, n
363+
fromNif conf.libpath, n
364+
fromNif conf.nimcacheDir, n
384365

385366
expectTag n, "dllOverrides"
386367
inc n
387368
while n.kind != ParRi:
388369
conf.inclDynlibOverride(pool.strings[n.litId])
389370
inc n
390371
inc n
391-
392-
expectTag n, "moduleOverrides"
393-
inc n
394-
fromNif(conf.moduleOverrides, n)
372+
fromNif conf.moduleOverrides, "moduleOverrides", n
395373

396374
fromNif conf.implicitImports, "implicitImports", n
397375
fromNif conf.implicitIncludes, "implicitIncludes", n

0 commit comments

Comments
 (0)