diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/commands.nim | 4 | ||||
-rw-r--r-- | compiler/pragmas.nim | 2 | ||||
-rw-r--r-- | compiler/wordrecg.nim | 25 |
3 files changed, 21 insertions, 10 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim index a35d1dae7..cb7517f06 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -193,11 +193,11 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass, elif i < arg.len and (arg[i] in {':', '='}): inc(i) else: invalidCmdLineOption(conf, pass, orig, info) if state == wHint: - let x = findStr(hintMin..hintMax, id, errUnknown) + let x = findStr(hintMin, hintMax, id, errUnknown) if x != errUnknown: n = TNoteKind(x) else: localError(conf, info, "unknown hint: " & id) else: - let x = findStr(warnMin..warnMax, id, errUnknown) + let x = findStr(warnMin, warnMax, id, errUnknown) if x != errUnknown: n = TNoteKind(x) else: localError(conf, info, "unknown warning: " & id) diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index c1d54c4a2..8affccbf3 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -331,7 +331,7 @@ proc processDynLib(c: PContext, n: PNode, sym: PSym) = proc processNote(c: PContext, n: PNode) = template handleNote(enumVals, notes) = - let x = findStr(enumVals, n[0][1].ident.s, errUnknown) + let x = findStr(enumVals.a, enumVals.b, n[0][1].ident.s, errUnknown) if x != errUnknown: nk = TNoteKind(x) let x = c.semConstBoolExpr(c, n[1]) diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim index e2e3a1d2f..170d04df1 100644 --- a/compiler/wordrecg.nim +++ b/compiler/wordrecg.nim @@ -13,8 +13,6 @@ # does not support strings. Without this the code would # be slow and unreadable. -from strutils import cmpIgnoreStyle - type TSpecialWord* = enum wInvalid = "", @@ -125,8 +123,21 @@ const wAsm, wBreak, wCase, wConst, wContinue, wDo, wElse, wEnum, wExport, wFor, wIf, wReturn, wStatic, wTemplate, wTry, wWhile, wUsing} -proc findStr*[T:enum](a: Slice[T], s: string, default: T): T = - for i in a: - if cmpIgnoreStyle($i, s) == 0: - return i - result = default \ No newline at end of file + +const enumUtilsExist = compiles: + import std/enumutils + +when enumUtilsExist: + from std/enumutils import genEnumCaseStmt + from strutils import normalize + proc findStr*[T: enum](a, b: static[T], s: string, default: T): T = + genEnumCaseStmt(T, s, default, ord(a), ord(b), normalize) + +else: + from strutils import cmpIgnoreStyle + proc findStr*[T: enum](a, b: static[T], s: string, default: T): T {.deprecated.} = + # used for compiler bootstrapping only + for i in a..b: + if cmpIgnoreStyle($i, s) == 0: + return i + result = default \ No newline at end of file |