summary refs log tree commit diff stats
path: root/compiler/nimconf.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2016-10-31 15:34:44 +0100
committerAraq <rumpf_a@web.de>2016-10-31 15:34:44 +0100
commit773d17cd14c6f4457245bb3039f644bc3cef64bb (patch)
treedd38ef41036fe77e97a7a15bf3e1eea9f8515d21 /compiler/nimconf.nim
parent5494d78e741037f713df446f9135b976073929c7 (diff)
downloadNim-773d17cd14c6f4457245bb3039f644bc3cef64bb.tar.gz
big refactoring: step 1
Diffstat (limited to 'compiler/nimconf.nim')
-rw-r--r--compiler/nimconf.nim26
1 files changed, 15 insertions, 11 deletions
diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim
index 496bd0123..eb3e4d03f 100644
--- a/compiler/nimconf.nim
+++ b/compiler/nimconf.nim
@@ -156,7 +156,7 @@ proc checkSymbol(L: TLexer, tok: TToken) =
     lexMessage(L, errIdentifierExpected, tokToStr(tok))
 
 proc parseAssignment(L: var TLexer, tok: var TToken) =
-  if tok.ident.id == getIdent("-").id or tok.ident.id == getIdent("--").id:
+  if tok.ident.s == "-" or tok.ident.s == "--":
     confTok(L, tok)           # skip unnecessary prefix
   var info = getLineInfo(L, tok) # save for later in case of an error
   checkSymbol(L, tok)
@@ -179,14 +179,14 @@ proc parseAssignment(L: var TLexer, tok: var TToken) =
     if tok.tokType == tkBracketRi: confTok(L, tok)
     else: lexMessage(L, errTokenExpected, "']'")
     add(val, ']')
-  let percent = tok.ident.id == getIdent("%=").id
+  let percent = tok.ident.s == "%="
   if tok.tokType in {tkColon, tkEquals} or percent:
     if len(val) > 0: add(val, ':')
     confTok(L, tok)           # skip ':' or '=' or '%'
     checkSymbol(L, tok)
     add(val, tokToStr(tok))
     confTok(L, tok)           # skip symbol
-    while tok.ident != nil and tok.ident.id == getIdent("&").id:
+    while tok.ident != nil and tok.ident.s == "&":
       confTok(L, tok)
       checkSymbol(L, tok)
       add(val, tokToStr(tok))
@@ -197,7 +197,7 @@ proc parseAssignment(L: var TLexer, tok: var TToken) =
   else:
     processSwitch(s, val, passPP, info)
 
-proc readConfigFile(filename: string) =
+proc readConfigFile(filename: string; cache: IdentCache) =
   var
     L: TLexer
     tok: TToken
@@ -205,7 +205,7 @@ proc readConfigFile(filename: string) =
   stream = llStreamOpen(filename, fmRead)
   if stream != nil:
     initToken(tok)
-    openLexer(L, filename, stream)
+    openLexer(L, filename, stream, cache)
     tok.tokType = tkEof       # to avoid a pointless warning
     confTok(L, tok)           # read in the first token
     while tok.tokType != tkEof: parseAssignment(L, tok)
@@ -225,22 +225,22 @@ proc getSystemConfigPath(filename: string): string =
     if not existsFile(result): result = joinPath([p, "etc", filename])
     if not existsFile(result): result = "/etc/" & filename
 
-proc loadConfigs*(cfg: string) =
+proc loadConfigs*(cfg: string; cache: IdentCache) =
   setDefaultLibpath()
 
   if optSkipConfigFile notin gGlobalOptions:
-    readConfigFile(getSystemConfigPath(cfg))
+    readConfigFile(getSystemConfigPath(cfg), cache)
 
   if optSkipUserConfigFile notin gGlobalOptions:
-    readConfigFile(getUserConfigPath(cfg))
+    readConfigFile(getUserConfigPath(cfg), cache)
 
   var pd = if gProjectPath.len > 0: gProjectPath else: getCurrentDir()
   if optSkipParentConfigFiles notin gGlobalOptions:
     for dir in parentDirs(pd, fromRoot=true, inclusive=false):
-      readConfigFile(dir / cfg)
+      readConfigFile(dir / cfg, cache)
 
   if optSkipProjConfigFile notin gGlobalOptions:
-    readConfigFile(pd / cfg)
+    readConfigFile(pd / cfg, cache)
 
     if gProjectName.len != 0:
       # new project wide config file:
@@ -251,4 +251,8 @@ proc loadConfigs*(cfg: string) =
         projectConfig = changeFileExt(gProjectFull, "nimrod.cfg")
         if fileExists(projectConfig):
           rawMessage(warnDeprecated, projectConfig)
-      readConfigFile(projectConfig)
+      readConfigFile(projectConfig, cache)
+
+proc loadConfigs*(cfg: string) =
+  # for backwards compatibility only.
+  loadConfigs(cfg, newIdentCache())