Use modern enums in compiler (#15775)

This commit is contained in:
cooldome 2020-11-02 09:35:24 +00:00 • committed by GitHub
commit 00b495de95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 212 additions and 330 deletions

View file

@ -17,21 +17,17 @@ export int128
type type
TCallingConvention* = enum TCallingConvention* = enum
ccNimCall # nimcall, also the default ccNimCall = "nimcall" # nimcall, also the default
ccStdCall # procedure is stdcall ccStdCall = "stdcall" # procedure is stdcall
ccCDecl # cdecl ccCDecl = "cdecl" # cdecl
ccSafeCall # safecall ccSafeCall = "safecall" # safecall
ccSysCall # system call ccSysCall = "syscall" # system call
ccInline # proc should be inlined ccInline = "inline" # proc should be inlined
ccNoInline # proc should not be inlined ccNoInline = "noinline" # proc should not be inlined
ccFastCall # fastcall (pass parameters in registers) ccFastCall = "fastcall" # fastcall (pass parameters in registers)
ccThisCall # thiscall (parameters are pushed right-to-left) ccThisCall = "thiscall" # thiscall (parameters are pushed right-to-left)
ccClosure # proc has a closure ccClosure = "closure" # proc has a closure
ccNoConvention # needed for generating proper C procs sometimes ccNoConvention = "noconv" # needed for generating proper C procs sometimes
const CallingConvToStr*: array[TCallingConvention, string] = ["nimcall", "stdcall",
"cdecl", "safecall", "syscall", "inline", "noinline", "fastcall", "thiscall",
"closure", "noconv"]
type type
TNodeKind* = enum # order is extremely important, because ranges are used TNodeKind* = enum # order is extremely important, because ranges are used

View file

@ -345,7 +345,7 @@ proc typeToYamlAux(conf: ConfigRef; n: PType, marker: var IntSet, indent: int,
result.addf("$N$1\"n\": $2", [istr, treeToYamlAux(conf, n.n, marker, indent + 2, maxRecDepth - 1)]) result.addf("$N$1\"n\": $2", [istr, treeToYamlAux(conf, n.n, marker, indent + 2, maxRecDepth - 1)])
if card(n.flags) > 0: if card(n.flags) > 0:
result.addf("$N$1\"flags\": $2", [istr, flagsToStr(n.flags)]) result.addf("$N$1\"flags\": $2", [istr, flagsToStr(n.flags)])
result.addf("$N$1\"callconv\": $2", [istr, makeYamlString(CallingConvToStr[n.callConv])]) result.addf("$N$1\"callconv\": $2", [istr, makeYamlString($n.callConv)])
result.addf("$N$1\"size\": $2", [istr, rope(n.size)]) result.addf("$N$1\"size\": $2", [istr, rope(n.size)])
result.addf("$N$1\"align\": $2", [istr, rope(n.align)]) result.addf("$N$1\"align\": $2", [istr, rope(n.align)])
result.addf("$N$1\"sons\": $2", [istr, sonsRope]) result.addf("$N$1\"sons\": $2", [istr, sonsRope])

View file

@ -193,12 +193,12 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
elif i < arg.len and (arg[i] in {':', '='}): inc(i) elif i < arg.len and (arg[i] in {':', '='}): inc(i)
else: invalidCmdLineOption(conf, pass, orig, info) else: invalidCmdLineOption(conf, pass, orig, info)
if state == wHint: if state == wHint:
let x = findStr(lineinfos.HintsToStr, id) let x = findStr(hintMin..hintMax, id, errUnknown)
if x >= 0: n = TNoteKind(x + ord(hintMin)) if x != errUnknown: n = TNoteKind(x)
else: localError(conf, info, "unknown hint: " & id) else: localError(conf, info, "unknown hint: " & id)
else: else:
let x = findStr(lineinfos.WarningsToStr, id) let x = findStr(warnMin..warnMax, id, errUnknown)
if x >= 0: n = TNoteKind(x + ord(warnMin)) if x != errUnknown: n = TNoteKind(x)
else: localError(conf, info, "unknown warning: " & id) else: localError(conf, info, "unknown warning: " & id)
var val = substr(arg, i).normalize var val = substr(arg, i).normalize

View file

@ -13,7 +13,7 @@ import
strtabs strtabs
from options import Feature from options import Feature
from lineinfos import HintsToStr, WarningsToStr from lineinfos import hintMin, hintMax, warnMin, warnMax
proc defineSymbol*(symbols: StringTableRef; symbol: string, value: string = "true") = proc defineSymbol*(symbols: StringTableRef; symbol: string, value: string = "true") =
symbols[symbol] = value symbols[symbol] = value
@ -89,10 +89,10 @@ proc initDefines*(symbols: StringTableRef) =
for f in Feature: for f in Feature:
defineSymbol("nimHas" & $f) defineSymbol("nimHas" & $f)
for s in WarningsToStr: for s in warnMin..warnMax:
defineSymbol("nimHasWarning" & s) defineSymbol("nimHasWarning" & $s)
for s in HintsToStr: for s in hintMin..hintMax:
defineSymbol("nimHasHint" & s) defineSymbol("nimHasHint" & $s)
defineSymbol("nimFixedOwned") defineSymbol("nimFixedOwned")
defineSymbol("nimHasStyleChecks") defineSymbol("nimHasStyleChecks")

View file

@ -997,7 +997,7 @@ proc documentEffect(cache: IdentCache; n, x: PNode, effectType: TSpecialWord, id
effects[i].typ = real[i].typ effects[i].typ = real[i].typ
result = newTreeI(nkExprColonExpr, n.info, result = newTreeI(nkExprColonExpr, n.info,
newIdentNode(getIdent(cache, specialWords[effectType]), n.info), effects) newIdentNode(getIdent(cache, $effectType), n.info), effects)
proc documentWriteEffect(cache: IdentCache; n: PNode; flag: TSymFlag; pragmaName: string): PNode = proc documentWriteEffect(cache: IdentCache; n: PNode; flag: TSymFlag; pragmaName: string): PNode =
let s = n[namePos].sym let s = n[namePos].sym

View file

@ -107,8 +107,8 @@ proc newIdentCache*(): IdentCache =
result.idDelegator = result.getIdent":delegator" result.idDelegator = result.getIdent":delegator"
result.emptyIdent = result.getIdent("") result.emptyIdent = result.getIdent("")
# initialize the keywords: # initialize the keywords:
for s in succ(low(specialWords))..high(specialWords): for s in succ(low(TSpecialWord))..high(TSpecialWord):
result.getIdent(specialWords[s], hashIgnoreStyle(specialWords[s])).id = ord(s) result.getIdent($s, hashIgnoreStyle($s)).id = ord(s)
proc whichKeyword*(id: PIdent): TSpecialWord = proc whichKeyword*(id: PIdent): TSpecialWord =
if id.id < 0: result = wInvalid if id.id < 0: result = wInvalid

View file

@ -295,7 +295,7 @@ proc markAsClosure(g: ModuleGraph; owner: PSym; n: PNode) =
[s.name.s, typeToString(s.typ), g.config$s.info]) [s.name.s, typeToString(s.typ), g.config$s.info])
elif not (owner.typ.callConv == ccClosure or owner.typ.callConv == ccNimCall and tfExplicitCallConv notin owner.typ.flags): elif not (owner.typ.callConv == ccClosure or owner.typ.callConv == ccNimCall and tfExplicitCallConv notin owner.typ.flags):
localError(g.config, n.info, "illegal capture '$1' because '$2' has the calling convention: <$3>" % localError(g.config, n.info, "illegal capture '$1' because '$2' has the calling convention: <$3>" %
[s.name.s, owner.name.s, CallingConvToStr[owner.typ.callConv]]) [s.name.s, owner.name.s, $owner.typ.callConv])
incl(owner.typ.flags, tfCapturesEnv) incl(owner.typ.flags, tfCapturesEnv)
owner.typ.callConv = ccClosure owner.typ.callConv = ccClosure

View file

@ -494,7 +494,7 @@ proc emitTok*(em: var Emitter; L: Lexer; tok: Token) =
wrSpace em wrSpace em
if not em.inquote: if not em.inquote:
wr(em, TokTypeToStr[tok.tokType], ltKeyword) wr(em, $tok.tokType, ltKeyword)
if tok.tokType in {tkAnd, tkOr, tkIn, tkNotin}: if tok.tokType in {tkAnd, tkOr, tkIn, tkNotin}:
rememberSplit(splitIn) rememberSplit(splitIn)
wrSpace em wrSpace em
@ -503,28 +503,28 @@ proc emitTok*(em: var Emitter; L: Lexer; tok: Token) =
wr(em, tok.ident.s, ltIdent) wr(em, tok.ident.s, ltIdent)
of tkColon: of tkColon:
wr(em, TokTypeToStr[tok.tokType], ltOther) wr(em, $tok.tokType, ltOther)
wrSpace em wrSpace em
of tkSemiColon, tkComma: of tkSemiColon, tkComma:
wr(em, TokTypeToStr[tok.tokType], ltOther) wr(em, $tok.tokType, ltOther)
rememberSplit(splitComma) rememberSplit(splitComma)
wrSpace em wrSpace em
of openPars: of openPars:
if tok.strongSpaceA > 0 and not em.endsInWhite and if tok.strongSpaceA > 0 and not em.endsInWhite and
(not em.wasExportMarker or tok.tokType == tkCurlyDotLe): (not em.wasExportMarker or tok.tokType == tkCurlyDotLe):
wrSpace em wrSpace em
wr(em, TokTypeToStr[tok.tokType], ltSomeParLe) wr(em, $tok.tokType, ltSomeParLe)
rememberSplit(splitParLe) rememberSplit(splitParLe)
of closedPars: of closedPars:
wr(em, TokTypeToStr[tok.tokType], ltSomeParRi) wr(em, $tok.tokType, ltSomeParRi)
of tkColonColon: of tkColonColon:
wr(em, TokTypeToStr[tok.tokType], ltOther) wr(em, $tok.tokType, ltOther)
of tkDot: of tkDot:
lastTokWasTerse = true lastTokWasTerse = true
wr(em, TokTypeToStr[tok.tokType], ltOther) wr(em, $tok.tokType, ltOther)
of tkEquals: of tkEquals:
if not em.inquote and not em.endsInWhite: wrSpace(em) if not em.inquote and not em.endsInWhite: wrSpace(em)
wr(em, TokTypeToStr[tok.tokType], ltOther) wr(em, $tok.tokType, ltOther)
if not em.inquote: wrSpace(em) if not em.inquote: wrSpace(em)
of tkOpr, tkDotDot: of tkOpr, tkDotDot:
if em.inquote or ((tok.strongSpaceA == 0 and tok.strongSpaceB == 0) and if em.inquote or ((tok.strongSpaceA == 0 and tok.strongSpaceB == 0) and
@ -544,7 +544,7 @@ proc emitTok*(em: var Emitter; L: Lexer; tok: Token) =
wrSpace(em) wrSpace(em)
of tkAccent: of tkAccent:
if not em.inquote and endsInAlpha(em): wrSpace(em) if not em.inquote and endsInAlpha(em): wrSpace(em)
wr(em, TokTypeToStr[tok.tokType], ltOther) wr(em, $tok.tokType, ltOther)
em.inquote = not em.inquote em.inquote = not em.inquote
of tkComment: of tkComment:
if not preventComment: if not preventComment:

View file

@ -31,37 +31,44 @@ const
type type
TokType* = enum TokType* = enum
tkInvalid, tkEof, # order is important here! tkInvalid = "tkInvalid", tkEof = "[EOF]", # order is important here!
tkSymbol, # keywords: tkSymbol = "tkSymbol", # keywords:
tkAddr, tkAnd, tkAs, tkAsm, tkAddr = "addr", tkAnd = "and", tkAs = "as", tkAsm = "asm",
tkBind, tkBlock, tkBreak, tkCase, tkCast, tkBind = "bind", tkBlock = "block", tkBreak = "break", tkCase = "case", tkCast = "cast",
tkConcept, tkConst, tkContinue, tkConverter, tkConcept = "concept", tkConst = "const", tkContinue = "continue", tkConverter = "converter",
tkDefer, tkDiscard, tkDistinct, tkDiv, tkDo, tkDefer = "defer", tkDiscard = "discard", tkDistinct = "distinct", tkDiv = "div", tkDo = "do",
tkElif, tkElse, tkEnd, tkEnum, tkExcept, tkExport, tkElif = "elif", tkElse = "else", tkEnd = "end", tkEnum = "enum", tkExcept = "except", tkExport = "export",
tkFinally, tkFor, tkFrom, tkFunc, tkFinally = "finally", tkFor = "for", tkFrom = "from", tkFunc = "func",
tkIf, tkImport, tkIn, tkInclude, tkInterface, tkIf = "if", tkImport = "import", tkIn = "in", tkInclude = "include", tkInterface = "interface",
tkIs, tkIsnot, tkIterator, tkIs = "is", tkIsnot = "isnot", tkIterator = "iterator",
tkLet, tkLet = "let",
tkMacro, tkMethod, tkMixin, tkMod, tkNil, tkNot, tkNotin, tkMacro = "macro", tkMethod = "method", tkMixin = "mixin", tkMod = "mod", tkNil = "nil", tkNot = "not", tkNotin = "notin",
tkObject, tkOf, tkOr, tkOut, tkObject = "object", tkOf = "of", tkOr = "or", tkOut = "out",
tkProc, tkPtr, tkRaise, tkRef, tkReturn, tkProc = "proc", tkPtr = "ptr", tkRaise = "raise", tkRef = "ref", tkReturn = "return",
tkShl, tkShr, tkStatic, tkShl = "shl", tkShr = "shr", tkStatic = "static",
tkTemplate, tkTemplate = "template",
tkTry, tkTuple, tkType, tkUsing, tkTry = "try", tkTuple = "tuple", tkType = "type", tkUsing = "using",
tkVar, tkWhen, tkWhile, tkXor, tkVar = "var", tkWhen = "when", tkWhile = "while", tkXor = "xor",
tkYield, # end of keywords tkYield = "yield", # end of keywords
tkIntLit, tkInt8Lit, tkInt16Lit, tkInt32Lit, tkInt64Lit,
tkUIntLit, tkUInt8Lit, tkUInt16Lit, tkUInt32Lit, tkUInt64Lit, tkIntLit = "tkIntLit", tkInt8Lit = "tkInt8Lit", tkInt16Lit = "tkInt16Lit",
tkFloatLit, tkFloat32Lit, tkFloat64Lit, tkFloat128Lit, tkInt32Lit = "tkInt32Lit", tkInt64Lit = "tkInt64Lit",
tkStrLit, tkRStrLit, tkTripleStrLit, tkUIntLit = "tkUIntLit", tkUInt8Lit = "tkUInt8Lit", tkUInt16Lit = "tkUInt16Lit",
tkGStrLit, tkGTripleStrLit, tkCharLit, tkParLe, tkParRi, tkBracketLe, tkUInt32Lit = "tkUInt32Lit", tkUInt64Lit = "tkUInt64Lit",
tkBracketRi, tkCurlyLe, tkCurlyRi, tkFloatLit = "tkFloatLit", tkFloat32Lit = "tkFloat32Lit",
tkBracketDotLe, tkBracketDotRi, # [. and .] tkFloat64Lit = "tkFloat64Lit", tkFloat128Lit = "tkFloat128Lit",
tkCurlyDotLe, tkCurlyDotRi, # {. and .} tkStrLit = "tkStrLit", tkRStrLit = "tkRStrLit", tkTripleStrLit = "tkTripleStrLit",
tkParDotLe, tkParDotRi, # (. and .) tkGStrLit = "tkGStrLit", tkGTripleStrLit = "tkGTripleStrLit", tkCharLit = "tkCharLit",
tkComma, tkSemiColon,
tkColon, tkColonColon, tkEquals, tkDot, tkDotDot, tkBracketLeColon, tkParLe = "(", tkParRi = ")", tkBracketLe = "[",
tkOpr, tkComment, tkAccent, tkBracketRi = "]", tkCurlyLe = "{", tkCurlyRi = "}",
tkBracketDotLe = "[.", tkBracketDotRi = ".]",
tkCurlyDotLe = "{.", tkCurlyDotRi = ".}",
tkParDotLe = "(.", tkParDotRi = ".)",
tkComma = ",", tkSemiColon = ";",
tkColon = ":", tkColonColon = "::", tkEquals = "=",
tkDot = ".", tkDotDot = "..", tkBracketLeColon = "[:",
tkOpr, tkComment, tkAccent = "`",
# these are fake tokens used by renderer.nim # these are fake tokens used by renderer.nim
tkSpaces, tkInfixOpr, tkPrefixOpr, tkPostfixOpr tkSpaces, tkInfixOpr, tkPrefixOpr, tkPostfixOpr
@ -74,35 +81,6 @@ const
# tokens that should not be considered for previousToken # tokens that should not be considered for previousToken
tokKeywordLow* = succ(tkSymbol) tokKeywordLow* = succ(tkSymbol)
tokKeywordHigh* = pred(tkIntLit) tokKeywordHigh* = pred(tkIntLit)
TokTypeToStr*: array[TokType, string] = ["tkInvalid", "[EOF]",
"tkSymbol",
"addr", "and", "as", "asm",
"bind", "block", "break", "case", "cast",
"concept", "const", "continue", "converter",
"defer", "discard", "distinct", "div", "do",
"elif", "else", "end", "enum", "except", "export",
"finally", "for", "from", "func", "if",
"import", "in", "include", "interface", "is", "isnot", "iterator",
"let",
"macro", "method", "mixin", "mod",
"nil", "not", "notin", "object", "of", "or",
"out", "proc", "ptr", "raise", "ref", "return",
"shl", "shr", "static",
"template",
"try", "tuple", "type", "using",
"var", "when", "while", "xor",
"yield",
"tkIntLit", "tkInt8Lit", "tkInt16Lit", "tkInt32Lit", "tkInt64Lit",
"tkUIntLit", "tkUInt8Lit", "tkUInt16Lit", "tkUInt32Lit", "tkUInt64Lit",
"tkFloatLit", "tkFloat32Lit", "tkFloat64Lit", "tkFloat128Lit",
"tkStrLit", "tkRStrLit",
"tkTripleStrLit", "tkGStrLit", "tkGTripleStrLit", "tkCharLit", "(",
")", "[", "]", "{", "}", "[.", ".]", "{.", ".}", "(.", ".)",
",", ";",
":", "::", "=", ".", "..", "[:",
"tkOpr", "tkComment", "`",
"tkSpaces", "tkInfixOpr",
"tkPrefixOpr", "tkPostfixOpr"]
type type
NumericalBase* = enum NumericalBase* = enum
@ -171,7 +149,7 @@ proc `$`*(tok: Token): string =
of tkIntLit..tkInt64Lit: $tok.iNumber of tkIntLit..tkInt64Lit: $tok.iNumber
of tkFloatLit..tkFloat64Lit: $tok.fNumber of tkFloatLit..tkFloat64Lit: $tok.fNumber
of tkInvalid, tkStrLit..tkCharLit, tkComment: tok.literal of tkInvalid, tkStrLit..tkCharLit, tkComment: tok.literal
of tkParLe..tkColon, tkEof, tkAccent: TokTypeToStr[tok.tokType] of tkParLe..tkColon, tkEof, tkAccent: $tok.tokType
else: else:
if tok.ident != nil: if tok.ident != nil:
tok.ident.s tok.ident.s
@ -183,8 +161,7 @@ proc prettyTok*(tok: Token): string =
else: $tok else: $tok
proc printTok*(conf: ConfigRef; tok: Token) = proc printTok*(conf: ConfigRef; tok: Token) =
msgWriteln(conf, $tok.line & ":" & $tok.col & "\t" & msgWriteln(conf, $tok.line & ":" & $tok.col & "\t" & $tok.tokType & " " & $tok)
TokTypeToStr[tok.tokType] & " " & $tok)
proc initToken*(L: var Token) = proc initToken*(L: var Token) =
L.tokType = tkInvalid L.tokType = tkInvalid

View file

@ -36,40 +36,40 @@ type
errProveInit, # deadcode errProveInit, # deadcode
errGenerated, errGenerated,
errUser, errUser,
warnCannotOpenFile,
warnOctalEscape, warnXIsNeverRead, warnXmightNotBeenInit, warnCannotOpenFile = "CannotOpenFile", warnOctalEscape = "OctalEscape",
warnDeprecated, warnConfigDeprecated, warnXIsNeverRead = "XIsNeverRead", warnXmightNotBeenInit = "XmightNotBeenInit",
warnSmallLshouldNotBeUsed, warnUnknownMagic, warnRedefinitionOfLabel, warnDeprecated = "Deprecated", warnConfigDeprecated = "ConfigDeprecated",
warnUnknownSubstitutionX, warnLanguageXNotSupported, warnSmallLshouldNotBeUsed = "SmallLshouldNotBeUsed", warnUnknownMagic = "UnknownMagic",
warnFieldXNotSupported, warnCommentXIgnored, warnRedefinitionOfLabel = "RedefinitionOfLabel", warnUnknownSubstitutionX = "UnknownSubstitutionX",
warnTypelessParam, warnLanguageXNotSupported = "LanguageXNotSupported", warnFieldXNotSupported = "FieldXNotSupported",
warnUseBase, warnWriteToForeignHeap, warnUnsafeCode, warnCommentXIgnored = "CommentXIgnored", warnTypelessParam = "TypelessParam",
warnUnusedImportX, warnUseBase = "UseBase", warnWriteToForeignHeap = "WriteToForeignHeap",
warnInheritFromException, warnUnsafeCode = "UnsafeCode", warnUnusedImportX = "UnusedImport",
warnEachIdentIsTuple, warnInheritFromException = "InheritFromException", warnEachIdentIsTuple = "EachIdentIsTuple",
warnUnsafeSetLen, warnUnsafeSetLen = "UnsafeSetLen", warnUnsafeDefault = "UnsafeDefault",
warnUnsafeDefault, warnProveInit = "ProveInit", warnProveField = "ProveField", warnProveIndex = "ProveIndex",
warnProveInit, warnProveField, warnProveIndex, warnUnreachableElse = "UnreachableElse", warnUnreachableCode = "UnreachableCode",
warnUnreachableElse, warnUnreachableCode, warnStaticIndexCheck = "IndexCheck", warnGcUnsafe = "GcUnsafe", warnGcUnsafe2 = "GcUnsafe2",
warnStaticIndexCheck, warnGcUnsafe, warnGcUnsafe2, warnUninit = "Uninit", warnGcMem = "GcMem", warnDestructor = "Destructor",
warnUninit, warnGcMem, warnDestructor, warnLockLevel, warnResultShadowed, warnLockLevel = "LockLevel", warnResultShadowed = "ResultShadowed",
warnInconsistentSpacing, warnCaseTransition, warnCycleCreated, warnInconsistentSpacing = "Spacing", warnCaseTransition = "CaseTransition",
warnObservableStores, warnCycleCreated = "CycleCreated", warnObservableStores = "ObservableStores",
warnUser, warnUser = "User",
hintSuccess, hintSuccessX, hintCC,
hintLineTooLong, hintXDeclaredButNotUsed, hintSuccess = "Success", hintSuccessX = "SuccessX", hintCC = "CC",
hintXCannotRaiseY, hintLineTooLong = "LineTooLong", hintXDeclaredButNotUsed = "XDeclaredButNotUsed",
hintConvToBaseNotNeeded, hintXCannotRaiseY = "XCannotRaiseY", hintConvToBaseNotNeeded = "ConvToBaseNotNeeded",
hintConvFromXtoItselfNotNeeded, hintExprAlwaysX, hintQuitCalled, hintConvFromXtoItselfNotNeeded = "ConvFromXtoItselfNotNeeded", hintExprAlwaysX = "ExprAlwaysX",
hintProcessing, hintCodeBegin, hintCodeEnd, hintConf, hintPath, hintQuitCalled = "QuitCalled", hintProcessing = "Processing", hintCodeBegin = "CodeBegin",
hintConditionAlwaysTrue, hintConditionAlwaysFalse, hintName, hintPattern, hintCodeEnd = "CodeEnd", hintConf = "Conf", hintPath = "Path",
hintExecuting, hintLinking, hintDependency, hintConditionAlwaysTrue = "CondTrue", hintConditionAlwaysFalse = "CondFalse", hintName = "Name",
hintSource, hintPerformance, hintStackTrace, hintGCStats, hintPattern = "Pattern", hintExecuting = "Exec", hintLinking = "Link", hintDependency = "Dependency",
hintGlobalVar, hintExpandMacro, hintSource = "Source", hintPerformance = "Performance", hintStackTrace = "StackTrace",
hintUser, hintUserRaw, hintGCStats = "GCStats", hintGlobalVar = "GlobalVar", hintExpandMacro = "ExpandMacro",
hintExtendedContext, hintUser = "User", hintUserRaw = "UserRaw", hintExtendedContext = "ExtendedContext",
hintMsgOrigin, # since 1.3.5 hintMsgOrigin = "MsgOrigin", # since 1.3.5
hintDeclaredLoc, # since 1.5.1 hintDeclaredLoc = "DeclaredLoc", # since 1.5.1
const const
MsgKindToStr*: array[TMsgKind, string] = [ MsgKindToStr*: array[TMsgKind, string] = [
@ -163,34 +163,6 @@ const
hintDeclaredLoc: "$1", hintDeclaredLoc: "$1",
] ]
const
WarningsToStr* = ["CannotOpenFile", "OctalEscape",
"XIsNeverRead", "XmightNotBeenInit",
"Deprecated", "ConfigDeprecated",
"SmallLshouldNotBeUsed", "UnknownMagic",
"RedefinitionOfLabel", "UnknownSubstitutionX",
"LanguageXNotSupported", "FieldXNotSupported",
"CommentXIgnored",
"TypelessParam", "UseBase", "WriteToForeignHeap",
"UnsafeCode", "UnusedImport", "InheritFromException",
"EachIdentIsTuple",
"UnsafeSetLen", "UnsafeDefault",
"ProveInit", "ProveField", "ProveIndex", "UnreachableElse", "UnreachableCode",
"IndexCheck", "GcUnsafe", "GcUnsafe2", "Uninit",
"GcMem", "Destructor", "LockLevel", "ResultShadowed",
"Spacing", "CaseTransition", "CycleCreated",
"ObservableStores", "User"]
HintsToStr* = [
"Success", "SuccessX", "CC", "LineTooLong",
"XDeclaredButNotUsed", "XCannotRaiseY",
"ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded",
"ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf",
"Path", "CondTrue", "CondFalse", "Name", "Pattern", "Exec", "Link", "Dependency",
"Source", "Performance", "StackTrace", "GCStats", "GlobalVar", "ExpandMacro",
"User", "UserRaw", "ExtendedContext", "MsgOrigin", "DeclaredLoc"
]
const const
fatalMin* = errUnknown fatalMin* = errUnknown
fatalMax* = errInternal fatalMax* = errInternal
@ -201,16 +173,6 @@ const
hintMin* = hintSuccess hintMin* = hintSuccess
hintMax* = high(TMsgKind) hintMax* = high(TMsgKind)
proc msgToStr*(msg: TMsgKind): string =
case msg
of warnMin..warnMax: WarningsToStr[ord(msg) - ord(warnMin)]
of hintMin..hintMax: HintsToStr[ord(msg) - ord(hintMin)]
else: "" # we could at least do $msg - prefix `err`
static:
doAssert HintsToStr.len == ord(hintMax) - ord(hintMin) + 1
doAssert WarningsToStr.len == ord(warnMax) - ord(warnMin) + 1
type type
TNoteKind* = range[warnMin..hintMax] # "notes" are warnings or hints TNoteKind* = range[warnMin..hintMax] # "notes" are warnings or hints
TNoteKinds* = set[TNoteKind] TNoteKinds* = set[TNoteKind]

View file

@ -128,6 +128,6 @@ proc styleCheckUse*(conf: ConfigRef; info: TLineInfo; s: PSym) =
lintReport(conf, info, newName, oldName) lintReport(conf, info, newName, oldName)
proc checkPragmaUse*(conf: ConfigRef; info: TLineInfo; w: TSpecialWord; pragmaName: string) = proc checkPragmaUse*(conf: ConfigRef; info: TLineInfo; w: TSpecialWord; pragmaName: string) =
let wanted = specialWords[w] let wanted = $w
if pragmaName != wanted: if pragmaName != wanted:
lintReport(conf, info, wanted, pragmaName) lintReport(conf, info, wanted, pragmaName)

View file

@ -303,10 +303,10 @@ proc mainCommand*(graph: ModuleGraph) =
var hints = newJObject() # consider factoring with `listHints` var hints = newJObject() # consider factoring with `listHints`
for a in hintMin..hintMax: for a in hintMin..hintMax:
hints[a.msgToStr] = %(a in conf.notes) hints[$a] = %(a in conf.notes)
var warnings = newJObject() var warnings = newJObject()
for a in warnMin..warnMax: for a in warnMin..warnMax:
warnings[a.msgToStr] = %(a in conf.notes) warnings[$a] = %(a in conf.notes)
var dumpdata = %[ var dumpdata = %[
(key: "version", val: %VersionAsString), (key: "version", val: %VersionAsString),

View file

@ -489,7 +489,7 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
color: ForegroundColor color: ForegroundColor
ignoreMsg = false ignoreMsg = false
sev: Severity sev: Severity
let kind = if msg != hintUserRaw: msg.msgToStr else: "" # xxx not sure why hintUserRaw is special let kind = if msg in warnMin..hintMax and msg != hintUserRaw: $msg else: "" # xxx not sure why hintUserRaw is special
case msg case msg
of errMin..errMax: of errMin..errMax:
sev = Severity.Error sev = Severity.Error
@ -536,7 +536,7 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
if hintMsgOrigin in conf.mainPackageNotes: if hintMsgOrigin in conf.mainPackageNotes:
styledMsgWriteln(styleBright, toFileLineCol(info2), resetStyle, styledMsgWriteln(styleBright, toFileLineCol(info2), resetStyle,
" compiler msg initiated here", KindColor, " compiler msg initiated here", KindColor,
KindFormat % hintMsgOrigin.msgToStr, KindFormat % $hintMsgOrigin,
resetStyle) resetStyle)
handleError(conf, msg, eh, s) handleError(conf, msg, eh, s)
@ -612,7 +612,7 @@ proc quotedFilename*(conf: ConfigRef; i: TLineInfo): Rope =
template listMsg(title, r) = template listMsg(title, r) =
msgWriteln(conf, title) msgWriteln(conf, title)
for a in r: msgWriteln(conf, " [$1] $2" % [if a in conf.notes: "x" else: " ", a.msgToStr]) for a in r: msgWriteln(conf, " [$1] $2" % [if a in conf.notes: "x" else: " ", $a])
proc listWarnings*(conf: ConfigRef) = listMsg("Warnings:", warnMin..warnMax) proc listWarnings*(conf: ConfigRef) = listMsg("Warnings:", warnMin..warnMax)
proc listHints*(conf: ConfigRef) = listMsg("Hints:", hintMin..hintMax) proc listHints*(conf: ConfigRef) = listMsg("Hints:", hintMin..hintMax)

View file

@ -219,7 +219,7 @@ proc eat(p: var Parser, tokType: TokType) =
getTok(p) getTok(p)
else: else:
lexMessage(p.lex, errGenerated, lexMessage(p.lex, errGenerated,
"expected: '" & TokTypeToStr[tokType] & "', but got: '" & prettyTok(p.tok) & "'") "expected: '" & $tokType & "', but got: '" & prettyTok(p.tok) & "'")
proc parLineInfo(p: Parser): TLineInfo = proc parLineInfo(p: Parser): TLineInfo =
## Retrieve the line information associated with the parser's current state. ## Retrieve the line information associated with the parser's current state.

View file

@ -330,10 +330,10 @@ proc processDynLib(c: PContext, n: PNode, sym: PSym) =
sym.typ.callConv = ccCDecl sym.typ.callConv = ccCDecl
proc processNote(c: PContext, n: PNode) = proc processNote(c: PContext, n: PNode) =
template handleNote(toStrArray, msgMin, notes) = template handleNote(enumVals, notes) =
let x = findStr(toStrArray, n[0][1].ident.s) let x = findStr(enumVals, n[0][1].ident.s, errUnknown)
if x >= 0: if x != errUnknown:
nk = TNoteKind(x + ord(msgMin)) nk = TNoteKind(x)
let x = c.semConstBoolExpr(c, n[1]) let x = c.semConstBoolExpr(c, n[1])
n[1] = x n[1] = x
if x.kind == nkIntLit and x.intVal != 0: incl(notes, nk) if x.kind == nkIntLit and x.intVal != 0: incl(notes, nk)
@ -347,9 +347,9 @@ proc processNote(c: PContext, n: PNode) =
n[0][1].kind == nkIdent and n[0][0].kind == nkIdent: n[0][1].kind == nkIdent and n[0][0].kind == nkIdent:
var nk: TNoteKind var nk: TNoteKind
case whichKeyword(n[0][0].ident) case whichKeyword(n[0][0].ident)
of wHint: handleNote(HintsToStr, hintMin, c.config.notes) of wHint: handleNote(hintMin .. hintMax, c.config.notes)
of wWarning: handleNote(WarningsToStr, warnMin, c.config.notes) of wWarning: handleNote(warnMin .. warnMax, c.config.notes)
of wWarningAsError: handleNote(WarningsToStr, warnMin, c.config.warningAsErrors) of wWarningAsError: handleNote(warnMin .. warnMax, c.config.warningAsErrors)
else: invalidPragma(c, n) else: invalidPragma(c, n)
else: invalidPragma(c, n) else: invalidPragma(c, n)

View file

@ -597,7 +597,7 @@ proc gcommaAux(g: var TSrcGen, n: PNode, ind: int, start: int = 0,
gsub(g, n[i]) gsub(g, n[i])
if c: if c:
if g.tokens.len > oldLen: if g.tokens.len > oldLen:
putWithSpace(g, separator, TokTypeToStr[separator]) putWithSpace(g, separator, $separator)
if hasCom(n[i]): if hasCom(n[i]):
gcoms(g) gcoms(g)
optNL(g, ind) optNL(g, ind)

View file

@ -700,7 +700,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
if i < t.len - 1: result.add(", ") if i < t.len - 1: result.add(", ")
result.add(')') result.add(')')
if t.len > 0 and t[0] != nil: result.add(": " & typeToString(t[0])) if t.len > 0 and t[0] != nil: result.add(": " & typeToString(t[0]))
var prag = if t.callConv == ccNimCall and tfExplicitCallConv notin t.flags: "" else: CallingConvToStr[t.callConv] var prag = if t.callConv == ccNimCall and tfExplicitCallConv notin t.flags: "" else: $t.callConv
if tfNoSideEffect in t.flags: if tfNoSideEffect in t.flags:
addSep(prag) addSep(prag)
prag.add("noSideEffect") prag.add("noSideEffect")

View file

@ -15,78 +15,99 @@
from strutils import cmpIgnoreStyle from strutils import cmpIgnoreStyle
# Keywords must be kept sorted and within a range
type type
TSpecialWord* = enum TSpecialWord* = enum
wInvalid, wInvalid = "",
wAddr = "addr", wAnd = "and", wAs = "as", wAsm = "asm",
wBind = "bind", wBlock = "block", wBreak = "break", wCase = "case", wCast = "cast",
wConcept = "concept", wConst = "const", wContinue = "continue", wConverter = "converter",
wDefer = "defer", wDiscard = "discard", wDistinct = "distinct", wDiv = "div", wDo = "do",
wElif = "elif", wElse = "else", wEnd = "end", wEnum = "enum", wExcept = "except",
wExport = "export", wFinally = "finally", wFor = "for", wFrom = "from", wFunc = "func",
wIf = "if", wImport = "import", wIn = "in", wInclude = "include", wInterface = "interface",
wIs = "is", wIsnot = "isnot", wIterator = "iterator", wLet = "let", wMacro = "macro",
wMethod = "method", wMixin = "mixin", wMod = "mod", wNil = "nil", wNot = "not", wNotin = "notin",
wObject = "object", wOf = "of", wOr = "or", wOut = "out", wProc = "proc", wPtr = "ptr",
wRaise = "raise", wRef = "ref", wReturn = "return", wShl = "shl", wShr = "shr", wStatic = "static",
wTemplate = "template", wTry = "try", wTuple = "tuple", wType = "type", wUsing = "using",
wVar = "var", wWhen = "when", wWhile = "while", wXor = "xor", wYield = "yield",
wAddr, wAnd, wAs, wAsm, wColon = ":", wColonColon = "::", wEquals = "=", wDot = ".", wDotDot = "..",
wBind, wBlock, wBreak, wCase, wCast, wConcept, wConst, wStar = "*", wMinus = "-",
wContinue, wConverter, wDefer, wDiscard, wDistinct, wDiv, wDo, wMagic = "magic", wThread = "thread", wFinal = "final", wProfiler = "profiler",
wElif, wElse, wEnd, wEnum, wExcept, wExport, wMemTracker = "memtracker", wObjChecks = "objchecks",
wFinally, wFor, wFrom, wFunc, wIf, wImport, wIn, wIntDefine = "intdefine", wStrDefine = "strdefine", wBoolDefine = "booldefine",
wInclude, wInterface, wIs, wIsnot, wIterator, wLet, wCursor = "cursor", wNoalias = "noalias",
wMacro, wMethod, wMixin, wMod, wNil,
wNot, wNotin, wObject, wOf, wOr, wOut, wProc, wPtr, wRaise, wRef, wReturn,
wShl, wShr, wStatic, wTemplate, wTry, wTuple, wType, wUsing, wVar,
wWhen, wWhile, wXor, wYield,
wColon, wColonColon, wEquals, wDot, wDotDot, wImmediate = "immediate", wConstructor = "constructor", wDestructor = "destructor",
wStar, wMinus, wDelegator = "delegator", wOverride = "override", wImportCpp = "importcpp",
wMagic, wThread, wFinal, wProfiler, wMemTracker, wObjChecks, wImportObjC = "importobjc", wImportCompilerProc = "importcompilerproc",
wIntDefine, wStrDefine, wBoolDefine, wCursor, wNoalias, wImportc = "importc", wImportJs = "importjs", wExportc = "exportc", wExportCpp = "exportcpp",
wExportNims = "exportnims",
wIncompleteStruct = "incompleteStruct", # deprecated
wCompleteStruct = "completeStruct", wRequiresInit = "requiresInit", wAlign = "align",
wNodecl = "nodecl", wPure = "pure", wSideEffect = "sideEffect", wHeader = "header",
wNoSideEffect = "noSideEffect", wGcSafe = "gcsafe", wNoreturn = "noreturn",
wNosinks = "nosinks", wMerge = "merge", wLib = "lib", wDynlib = "dynlib",
wCompilerProc = "compilerproc", wCore = "core", wProcVar = "procvar",
wBase = "base", wUsed = "used", wFatal = "fatal", wError = "error", wWarning = "warning",
wHint = "hint", wWarningAsError = "warningAsError", wLine = "line", wPush = "push",
wPop = "pop", wDefine = "define", wUndef = "undef", wLineDir = "lineDir",
wStackTrace = "stackTrace", wLineTrace = "lineTrace", wLink = "link", wCompile = "compile",
wLinksys = "linksys", wDeprecated = "deprecated", wVarargs = "varargs", wCallconv = "callconv",
wDebugger = "debugger", wNimcall = "nimcall", wStdcall = "stdcall", wCdecl = "cdecl",
wSafecall = "safecall", wSyscall = "syscall", wInline = "inline", wNoInline = "noinline",
wFastcall = "fastcall", wThiscall = "thiscall", wClosure = "closure", wNoconv = "noconv",
wOn = "on", wOff = "off", wChecks = "checks", wRangeChecks = "rangeChecks",
wBoundChecks = "boundChecks", wOverflowChecks = "overflowChecks", wNilChecks = "nilChecks",
wFloatChecks = "floatChecks", wNanChecks = "nanChecks", wInfChecks = "infChecks",
wStyleChecks = "styleChecks", wStaticBoundchecks = "staticBoundChecks",
wNonReloadable = "nonReloadable", wExecuteOnReload = "executeOnReload",
wImmediate, wConstructor, wDestructor, wDelegator, wOverride, wAssertions = "assertions", wPatterns = "patterns", wTrMacros = "trmacros",
wImportCpp, wImportObjC, wSinkInference = "sinkInference", wWarnings = "warnings",
wImportCompilerProc, wHints = "hints", wOptimization = "optimization", wRaises = "raises",
wImportc, wImportJs, wExportc, wExportCpp, wExportNims, wWrites = "writes", wReads = "reads", wSize = "size", wEffects = "effects", wTags = "tags",
wIncompleteStruct, # deprecated wRequires = "requires", wEnsures = "ensures", wInvariant = "invariant",
wCompleteStruct, wAssume = "assume", wAssert = "assert",
wRequiresInit, wDeadCodeElimUnused = "deadCodeElim", # deprecated, dead code elim always happens
wAlign, wNodecl, wPure, wSideEffect, wHeader, wSafecode = "safecode", wPackage = "package", wNoForward = "noforward", wReorder = "reorder",
wNoSideEffect, wGcSafe, wNoreturn, wNosinks, wMerge, wLib, wDynlib, wNoRewrite = "norewrite", wNoDestroy = "nodestroy", wPragma = "pragma",
wCompilerProc, wCore, wProcVar, wBase, wUsed, wCompileTime = "compileTime", wNoInit = "noinit", wPassc = "passc", wPassl = "passl",
wFatal, wError, wWarning, wHint, wWarningAsError, wLine, wPush, wPop, wDefine, wUndef, wLocalPassc = "localPassC", wBorrow = "borrow", wDiscardable = "discardable",
wLineDir, wStackTrace, wLineTrace, wLink, wCompile, wFieldChecks = "fieldChecks", wSubsChar = "subschar", wAcyclic = "acyclic",
wLinksys, wDeprecated, wVarargs, wCallconv, wDebugger, wShallow = "shallow", wUnroll = "unroll", wLinearScanEnd = "linearScanEnd",
wNimcall, wStdcall, wCdecl, wSafecall, wSyscall, wInline, wNoInline, wComputedGoto = "computedGoto", wInjectStmt = "injectStmt", wExperimental = "experimental",
wFastcall, wThiscall, wClosure, wNoconv, wOn, wOff, wChecks, wRangeChecks, wWrite = "write", wGensym = "gensym", wInject = "inject", wDirty = "dirty",
wBoundChecks, wOverflowChecks, wNilChecks, wInheritable = "inheritable", wThreadVar = "threadvar", wEmit = "emit",
wFloatChecks, wNanChecks, wInfChecks, wStyleChecks, wStaticBoundchecks, wAsmNoStackFrame = "asmNoStackFrame", wImplicitStatic = "implicitStatic",
wNonReloadable, wExecuteOnReload, wGlobal = "global", wCodegenDecl = "codegenDecl", wUnchecked = "unchecked",
wAssertions, wPatterns, wTrMacros, wSinkInference, wWarnings, wGuard = "guard", wLocks = "locks", wPartial = "partial", wExplain = "explain",
wHints, wOptimization, wRaises, wWrites, wReads, wSize, wEffects, wTags, wLiftLocals = "liftlocals",
wRequires, wEnsures, wInvariant, wAssume, wAssert,
wDeadCodeElimUnused, # deprecated, dead code elim always happens
wSafecode, wPackage, wNoForward, wReorder, wNoRewrite, wNoDestroy,
wPragma,
wCompileTime, wNoInit,
wPassc, wPassl, wLocalPassc, wBorrow, wDiscardable,
wFieldChecks,
wSubsChar, wAcyclic, wShallow, wUnroll, wLinearScanEnd, wComputedGoto,
wInjectStmt, wExperimental,
wWrite, wGensym, wInject, wDirty, wInheritable, wThreadVar, wEmit,
wAsmNoStackFrame,
wImplicitStatic, wGlobal, wCodegenDecl, wUnchecked, wGuard, wLocks,
wPartial, wExplain, wLiftLocals,
wAuto, wBool, wCatch, wChar, wClass, wCompl wAuto = "auto", wBool = "bool", wCatch = "catch", wChar = "char",
wConst_cast, wDefault, wDelete, wDouble, wDynamic_cast, wClass = "class", wCompl = "compl", wConst_cast = "const_cast", wDefault = "default",
wExplicit, wExtern, wFalse, wFloat, wFriend, wDelete = "delete", wDouble = "double", wDynamic_cast = "dynamic_cast",
wGoto, wInt, wLong, wMutable, wNamespace, wNew, wOperator, wExplicit = "explicit", wExtern = "extern", wFalse = "false", wFloat = "float",
wPrivate, wProtected, wPublic, wRegister, wReinterpret_cast, wRestrict, wFriend = "friend", wGoto = "goto", wInt = "int", wLong = "long", wMutable = "mutable",
wShort, wSigned, wSizeof, wStatic_cast, wStruct, wSwitch, wNamespace = "namespace", wNew = "new", wOperator = "operator", wPrivate = "private",
wThis, wThrow, wTrue, wTypedef, wTypeid, wTypeof, wTypename, wProtected = "protected", wPublic = "public", wRegister = "register",
wUnion, wPacked, wUnsigned, wVirtual, wVoid, wVolatile, wWchar_t, wReinterpret_cast = "reinterpret_cast", wRestrict = "restrict", wShort = "short",
wSigned = "signed", wSizeof = "sizeof", wStatic_cast = "static_cast", wStruct = "struct",
wSwitch = "switch", wThis = "this", wThrow = "throw", wTrue = "true", wTypedef = "typedef",
wTypeid = "typeid", wTypeof = "typeof", wTypename = "typename",
wUnion = "union", wPacked = "packed", wUnsigned = "unsigned", wVirtual = "virtual",
wVoid = "void", wVolatile = "volatile", wWchar_t = "wchar_t",
wAlignas, wAlignof, wConstexpr, wDecltype, wNullptr, wNoexcept, wAlignas = "alignas", wAlignof = "alignof", wConstexpr = "constexpr", wDecltype = "decltype",
wThread_local, wStatic_assert, wChar16_t, wChar32_t, wNullptr = "nullptr", wNoexcept = "noexcept",
wThread_local = "thread_local", wStatic_assert = "static_assert",
wChar16_t = "char16_t", wChar32_t = "char32_t",
wStdIn, wStdOut, wStdErr, wStdIn = "stdin", wStdOut = "stdout", wStdErr = "stderr",
wInOut, wByCopy, wByRef, wOneWay, wInOut = "inout", wByCopy = "bycopy", wByRef = "byref", wOneWay = "oneway",
wBitsize wBitsize = "bitsize"
TSpecialWords* = set[TSpecialWord] TSpecialWords* = set[TSpecialWord]
@ -104,82 +125,8 @@ const
wAsm, wBreak, wCase, wConst, wContinue, wDo, wElse, wEnum, wExport, wAsm, wBreak, wCase, wConst, wContinue, wDo, wElse, wEnum, wExport,
wFor, wIf, wReturn, wStatic, wTemplate, wTry, wWhile, wUsing} wFor, wIf, wReturn, wStatic, wTemplate, wTry, wWhile, wUsing}
specialWords*: array[TSpecialWord, string] = ["", proc findStr*[T:enum](a: Slice[T], s: string, default: T): T =
"addr", "and", "as", "asm", for i in a:
"bind", "block", "break", "case", "cast", if cmpIgnoreStyle($i, s) == 0:
"concept", "const", "continue", "converter",
"defer", "discard", "distinct", "div", "do",
"elif", "else", "end", "enum", "except", "export",
"finally", "for", "from", "func", "if",
"import", "in", "include", "interface", "is", "isnot", "iterator",
"let",
"macro", "method", "mixin", "mod", "nil", "not", "notin",
"object", "of", "or",
"out", "proc", "ptr", "raise", "ref", "return",
"shl", "shr", "static",
"template", "try", "tuple", "type", "using", "var",
"when", "while", "xor",
"yield",
":", "::", "=", ".", "..",
"*", "-",
"magic", "thread", "final", "profiler", "memtracker", "objchecks",
"intdefine", "strdefine", "booldefine", "cursor", "noalias",
"immediate", "constructor", "destructor", "delegator", "override",
"importcpp", "importobjc",
"importCompilerProc", "importc", "importjs", "exportc", "exportcpp", "exportnims",
"incompleteStruct",
"completeStruct",
"requiresInit", "align", "nodecl", "pure", "sideEffect",
"header", "noSideEffect", "gcsafe", "noreturn", "nosinks", "merge", "lib", "dynlib",
"compilerproc", "core", "procvar", "base", "used",
"fatal", "error", "warning", "hint", "warningAsError", "line",
"push", "pop", "define", "undef", "lineDir", "stackTrace", "lineTrace",
"link", "compile", "linksys", "deprecated", "varargs",
"callconv", "debugger", "nimcall", "stdcall",
"cdecl", "safecall", "syscall", "inline", "noinline", "fastcall", "thiscall", "closure",
"noconv", "on", "off", "checks", "rangeChecks", "boundChecks",
"overflowChecks", "nilChecks",
"floatChecks", "nanChecks", "infChecks", "styleChecks", "staticBoundChecks",
"nonReloadable", "executeOnReload",
"assertions", "patterns", "trmacros", "sinkinference", "warnings", "hints",
"optimization", "raises", "writes", "reads", "size", "effects", "tags",
"requires", "ensures", "invariant", "assume", "assert",
"deadCodeElim", # deprecated, dead code elim always happens
"safecode", "package", "noforward", "reorder", "norewrite", "nodestroy",
"pragma",
"compileTime", "noinit",
"passc", "passl", "localPassC", "borrow", "discardable", "fieldChecks",
"subschar", "acyclic", "shallow", "unroll", "linearScanEnd",
"computedGoto", "injectStmt", "experimental",
"write", "gensym", "inject", "dirty", "inheritable", "threadvar", "emit",
"asmNoStackFrame", "implicitStatic", "global", "codegenDecl", "unchecked",
"guard", "locks", "partial", "explain", "liftLocals",
"auto", "bool", "catch", "char", "class", "compl",
"const_cast", "default", "delete", "double",
"dynamic_cast", "explicit", "extern", "false",
"float", "friend", "goto", "int", "long", "mutable",
"namespace", "new", "operator",
"private", "protected", "public", "register", "reinterpret_cast", "restrict",
"short", "signed", "sizeof", "static_cast", "struct", "switch",
"this", "throw", "true", "typedef", "typeid", "typeof",
"typename", "union", "packed", "unsigned", "virtual", "void", "volatile",
"wchar_t",
"alignas", "alignof", "constexpr", "decltype", "nullptr", "noexcept",
"thread_local", "static_assert", "char16_t", "char32_t",
"stdin", "stdout", "stderr",
"inout", "bycopy", "byref", "oneway",
"bitsize"
]
proc findStr*(a: openArray[string], s: string): int =
for i in low(a)..high(a):
if cmpIgnoreStyle(a[i], s) == 0:
return i return i
result = - 1 result = default