compiler/front/optionsprocessor

  Source   Edit

this modules processes various options given as flags and applies them to a given ConfigRef. This allows for command line, configuration, comptime, etc configuration building and updates through a unified interface

Types

CmdSwitchKind = enum
  cmdSwitchFromcmd, cmdSwitchPath, cmdSwitchNimblepath, cmdSwitchNonimblepath,
  cmdSwitchClearnimblepath, cmdSwitchExcludepath, cmdSwitchNimcache,
  cmdSwitchOut, cmdSwitchOutdir, cmdSwitchDepfile, cmdSwitchUsenimcache,
  cmdSwitchDocseesrcurl, cmdSwitchDocroot, cmdSwitchBackend, cmdSwitchDoccmd,
  cmdSwitchDefine, cmdSwitchUndef, cmdSwitchCompile, cmdSwitchLink,
  cmdSwitchDebuginfo, cmdSwitchEmbedsrc, cmdSwitchCompileonly,
  cmdSwitchNolinking, cmdSwitchNomain, cmdSwitchForcebuild, cmdSwitchProject,
  cmdSwitchGc, cmdSwitchWarnings, cmdSwitchWarning, cmdSwitchHint,
  cmdSwitchWarningaserror, cmdSwitchHintaserror, cmdSwitchHints,
  cmdSwitchThreadanalysis, cmdSwitchStacktrace, cmdSwitchStacktracemsgs,
  cmdSwitchExcessivestacktrace, cmdSwitchLinetrace, cmdSwitchDebugger,
  cmdSwitchProfiler, cmdSwitchMemtracker, cmdSwitchChecks, cmdSwitchFloatchecks,
  cmdSwitchInfchecks, cmdSwitchNanchecks, cmdSwitchObjchecks,
  cmdSwitchFieldchecks, cmdSwitchRangechecks, cmdSwitchBoundchecks,
  cmdSwitchOverflowchecks, cmdSwitchStaticboundchecks, cmdSwitchStylechecks,
  cmdSwitchLinedir, cmdSwitchAssertions, cmdSwitchThreads,
  cmdSwitchTlsemulation, cmdSwitchImplicitstatic, cmdSwitchTrmacros,
  cmdSwitchOpt, cmdSwitchApp, cmdSwitchPassc, cmdSwitchPassl,
  cmdSwitchCincludes, cmdSwitchClibdir, cmdSwitchClib, cmdSwitchHeader,
  cmdSwitchIndex, cmdSwitchImport, cmdSwitchInclude, cmdSwitchListcmd,
  cmdSwitchAsm, cmdSwitchGenmapping, cmdSwitchOs, cmdSwitchCpu, cmdSwitchRun,
  cmdSwitchMaxloopiterationsvm, cmdSwitchErrormax, cmdSwitchVerbosity,
  cmdSwitchParallelbuild, cmdSwitchIncremental, cmdSwitchSkipcfg,
  cmdSwitchSkipprojcfg, cmdSwitchSkipusercfg, cmdSwitchSkipparentcfg,
  cmdSwitchGenscript, cmdSwitchColors, cmdSwitchLib, cmdSwitchPutenv,
  cmdSwitchCc, cmdSwitchStdout, cmdSwitchFilenames, cmdSwitchProcessing,
  cmdSwitchUnitsep, cmdSwitchListfullpaths, cmdSwitchSpellsuggest,
  cmdSwitchDeclaredlocs, cmdSwitchDynliboverride, cmdSwitchDynliboverrideall,
  cmdSwitchExperimental, cmdSwitchExceptions, cmdSwitchCppdefine,
  cmdSwitchSeqsv2, cmdSwitchStylecheck, cmdSwitchShowallmismatches,
  cmdSwitchDocinternal, cmdSwitchMultimethods, cmdSwitchExpandmacro,
  cmdSwitchExpandarc, cmdSwitchBenchmarkvm, cmdSwitchProfilevm,
  cmdSwitchSinkinference, cmdSwitchCursorinference, cmdSwitchPanics,
  cmdSwitchSourcemap, cmdSwitchDeepcopy, cmdSwitchProjStdin,
  cmdSwitchCmdexitgcstats, cmdSwitchShowIr, cmdSwitchConfigVar
  Source   Edit
CmdSwitchTextKind = enum
  fullSwitchTxtFromcmd = "fromcmd", fullSwitchTxtPath = "path",
  smolSwitchTxtPath = "p", fullSwitchTxtNimblepath = "nimblepath",
  fullSwitchTxtNonimblepath = "nonimblepath",
  fullSwitchTxtClearnimblepath = "clearnimblepath",
  fullSwitchTxtExcludepath = "excludepath", fullSwitchTxtNimcache = "nimcache",
  fullSwitchTxtOut = "out", smolSwitchTxtOut = "o",
  fullSwitchTxtOutdir = "outdir", fullSwitchTxtDepfile = "depfile",
  fullSwitchTxtUsenimcache = "usenimcache",
  fullSwitchTxtDocseesrcurl = "docseesrcurl", fullSwitchTxtDocroot = "docroot",
  fullSwitchTxtBackend = "backend", smolSwitchTxtBackend = "b",
  fullSwitchTxtDoccmd = "doccmd", fullSwitchTxtDefine = "define",
  smolSwitchTxtDefine = "d", fullSwitchTxtUndef = "undef",
  smolSwitchTxtUndef = "u", fullSwitchTxtCompile = "compile",
  fullSwitchTxtLink = "link", fullSwitchTxtDebuginfo = "debuginfo",
  fullSwitchTxtEmbedsrc = "embedsrc", fullSwitchTxtCompileonly = "compileonly",
  smolSwitchTxtCompileonly = "c", fullSwitchTxtNolinking = "nolinking",
  fullSwitchTxtNomain = "nomain", fullSwitchTxtForcebuild = "forcebuild",
  smolSwitchTxtForcebuild = "f", fullSwitchTxtGc = "gc",
  fullSwitchTxtProject = "project", fullSwitchTxtWarnings = "warnings",
  smolSwitchTxtWarnings = "w", fullSwitchTxtWarning = "warning",
  fullSwitchTxtHint = "hint", fullSwitchTxtWarningaserror = "warningaserror",
  fullSwitchTxtHintaserror = "hintaserror", fullSwitchTxtHints = "hints",
  fullSwitchTxtThreadanalysis = "threadanalysis",
  fullSwitchTxtStacktrace = "stacktrace",
  fullSwitchTxtStacktracemsgs = "stacktracemsgs",
  fullSwitchTxtExcessivestacktrace = "excessivestacktrace",
  fullSwitchTxtLinetrace = "linetrace", fullSwitchTxtDebugger = "debugger",
  fullSwitchTxtProfiler = "profiler", fullSwitchTxtMemtracker = "memtracker",
  fullSwitchTxtChecks = "checks", fullSwitchTxtFloatchecks = "floatchecks",
  fullSwitchTxtInfchecks = "infchecks", fullSwitchTxtNanchecks = "nanchecks",
  fullSwitchTxtObjchecks = "objchecks",
  fullSwitchTxtFieldchecks = "fieldchecks",
  fullSwitchTxtRangechecks = "rangechecks",
  fullSwitchTxtBoundchecks = "boundchecks",
  fullSwitchTxtOverflowchecks = "overflowchecks",
  fullSwitchTxtStaticboundchecks = "staticboundchecks",
  fullSwitchTxtStylechecks = "stylechecks", fullSwitchTxtLinedir = "linedir",
  fullSwitchTxtAssertions = "assertions", fullSwitchTxtThreads = "threads",
  fullSwitchTxtTlsemulation = "tlsemulation",
  fullSwitchTxtImplicitstatic = "implicitstatic",
  fullSwitchTxtTrmacros = "trmacros", fullSwitchTxtOpt = "opt",
  fullSwitchTxtApp = "app", fullSwitchTxtPassc = "passc",
  fullSwitchTxtPassl = "passl", fullSwitchTxtCincludes = "cincludes",
  fullSwitchTxtClibdir = "clibdir", fullSwitchTxtClib = "clib",
  fullSwitchTxtHeader = "header", fullSwitchTxtIndex = "index",
  fullSwitchTxtImport = "import", fullSwitchTxtInclude = "include",
  fullSwitchTxtListcmd = "listcmd", fullSwitchTxtAsm = "asm",
  fullSwitchTxtGenmapping = "genmapping", fullSwitchTxtOs = "os",
  fullSwitchTxtCpu = "cpu", fullSwitchTxtRun = "run",
  fullSwitchTxtMaxloopiterationsvm = "maxloopiterationsvm",
  fullSwitchTxtErrormax = "errormax", fullSwitchTxtVerbosity = "verbosity",
  fullSwitchTxtParallelbuild = "parallelbuild",
  fullSwitchTxtIncremental = "incremental", aliasSwitchTxtIncremental = "ic\'",
  fullSwitchTxtSkipcfg = "skipcfg", fullSwitchTxtSkipprojcfg = "skipprojcfg",
  fullSwitchTxtSkipusercfg = "skipusercfg",
  fullSwitchTxtSkipparentcfg = "skipparentcfg",
  fullSwitchTxtGenscript = "genscript", fullSwitchTxtColors = "colors",
  fullSwitchTxtLib = "lib", fullSwitchTxtPutenv = "putenv",
  fullSwitchTxtCc = "cc", fullSwitchTxtStdout = "stdout",
  fullSwitchTxtFilenames = "filenames", fullSwitchTxtProcessing = "processing",
  fullSwitchTxtUnitsep = "unitsep",
  fullSwitchTxtListfullpaths = "listfullpaths",
  fullSwitchTxtSpellsuggest = "spellsuggest",
  fullSwitchTxtDeclaredlocs = "declaredlocs",
  fullSwitchTxtDynliboverride = "dynliboverride",
  fullSwitchTxtDynliboverrideall = "dynliboverrideall",
  fullSwitchTxtExperimental = "experimental",
  fullSwitchTxtExceptions = "exceptions", fullSwitchTxtCppdefine = "cppdefine",
  fullSwitchTxtSeqsv2 = "seqsv2", fullSwitchTxtStylecheck = "stylecheck",
  fullSwitchTxtShowallmismatches = "showallmismatches",
  fullSwitchTxtDocinternal = "docinternal",
  fullSwitchTxtMultimethods = "multimethods",
  fullSwitchTxtExpandmacro = "expandmacro",
  fullSwitchTxtExpandarc = "expandarc",
  fullSwitchTxtBenchmarkvm = "benchmarkvm",
  fullSwitchTxtProfilevm = "profilevm",
  fullSwitchTxtSinkinference = "sinkinference",
  fullSwitchTxtCursorinference = "cursorinference",
  fullSwitchTxtPanics = "panics", fullSwitchTxtSourcemap = "sourcemap",
  fullSwitchTxtDeepcopy = "deepcopy",
  fullSwitchTxtCmdexitgcstats = "cmdexitgcstats", fullSwitchShowIr = "showir",
  smolSwitchTxtProjStdin = "", fullSwitchTxtConfigVar = "*.*",
  fullSwitchTxtInvalid = "!ERROR!"
  Source   Edit
CompileOptArgCheckResult = enum
  compileOptArgCheckSuccessTrue, compileOptArgCheckSuccessFalse,
  compileOptArgCheckWarnFalseDeprecated,
  compileOptArgCheckFailedWithInvalidOption,
  compileOptArgCheckFailedWithUnexpectedValue
  Source   Edit
CompileOptCheckResult = enum
  compileOptCheckSuccessTrue, compileOptCheckSuccessFalse,
  compileOptCheckWarnFalseDeprecated, compileOptCheckFailedWithInvalidOption
  Source   Edit
ProcessNoteResult = object
  case kind*: ProcessNoteResultKind
  of procNoteSuccess:
      nil

  of procNoteInvalidOption, procNoteExpectedOnOrOff, procNoteOnlyAllOffSupported:
      switch*: string
      argVal*: string

  of procNoteInvalidHint, procNoteInvalidWarning:
      invalidHintOrWarning*: string

  
  Source   Edit
ProcessNoteResultKind = enum
  procNoteSuccess, procNoteInvalidOption, procNoteInvalidHint,
  procNoteInvalidWarning, procNoteExpectedOnOrOff, procNoteOnlyAllOffSupported
  Source   Edit
ProcSwitchNimblePathResult = object
  case didProcess*: bool
  of true:
      nimblePathAttempted*: AbsoluteDir
      nimblePathResult*: NimblePathResult

  of false:
      nil

  
  Source   Edit
ProcSwitchResult = object
  srcCodeOrigin*: InstantiationInfo
  givenSwitch*, givenArg*: string
  case switch*: CmdSwitchKind ## the switch being processed, ignored if
                              ## `kind` is `procSwitchErrInvalid`
  of cmdSwitchNimblepath:
      processedNimblePath*: ProcSwitchNimblePathResult

  else:
      nil

  case kind*: ProcSwitchResultKind
  of procSwitchSuccess:
      nil

  of procSwitchErrInvalid:
      nil

  of procSwitchErrArgExpected, procSwitchErrArgForbidden,
     procSwitchErrArgMalformedKeyValPair, procSwitchErrArgExpectedOnOrOff,
     procSwitchErrArgExpectedOnOffOrList, procSwitchErrArgExpectedAllOrOff,
     procSwitchErrArgExpectedFromList, procSwitchErrArgNotInValidList,
     procSwitchErrArgUnknownCCompiler,
     procSwitchErrArgUnknownExperimentalFeature, procSwitchErrArgNimblePath:
      nil

  of procSwitchErrArgPathInvalid:
      pathAttempted*: string

  of procSwitchErrArgInvalidHintOrWarning:
      processNoteResult*: ProcessNoteResult

  
  Source   Edit
ProcSwitchResultErrorKind = range[procSwitchErrInvalid ..
    procSwitchErrArgInvalidHintOrWarning]
  Source   Edit
ProcSwitchResultKind = enum
  procSwitchSuccess, procSwitchErrInvalid, procSwitchErrArgExpected, ## flag expected argument
  procSwitchErrArgForbidden, ## flag expected no arguments
  procSwitchErrArgExpectedFromList, ## no arg given, expect form list
  procSwitchErrArgNotInValidList, ## `--flag:v` where `v` is not an
                                   ## allowed value
  procSwitchErrArgPathInvalid, procSwitchErrArgMalformedKeyValPair, ## `--define:abc=def` where `abc=def`
                                                                     ## is malformed syntax
  procSwitchErrArgExpectedOnOrOff, procSwitchErrArgExpectedOnOffOrList, procSwitchErrArgExpectedAllOrOff, ## flag expected 'on'/'off', or 'list'
                                                                                                           ## of values
  procSwitchErrArgUnknownCCompiler, procSwitchErrArgUnknownExperimentalFeature,
  procSwitchErrArgNimblePath, procSwitchErrArgInvalidHintOrWarning ## rest is under `ProcessNoteResult`
  Source   Edit

Consts

procSwitchResultErrorKinds = {procSwitchErrInvalid..procSwitchErrArgInvalidHintOrWarning}
  Source   Edit

Procs

func allowedCompileOptionArgs(switch: string): seq[string] {....raises: [],
    tags: [].}
  Source   Edit
func allowedCompileOptionsArgs(switch: CmdSwitchKind): seq[string] {....raises: [],
    tags: [].}
  Source   Edit
proc handleCmdInput(conf: ConfigRef) {....raises: [OSError],
                                       tags: [ReadEnvEffect, ReadIOEffect].}
  Source   Edit
proc handleStdinInput(conf: ConfigRef) {....raises: [OSError],
    tags: [ReadEnvEffect, ReadIOEffect].}
  Source   Edit
proc processSpecificNote(arg: string; state: TSpecialWord; pass: TCmdLinePass;
                         orig: string; conf: ConfigRef): ProcessNoteResult {.
    ...raises: [], tags: [].}
  Source   Edit
proc processSwitch(pass: TCmdLinePass; p: OptParser; config: ConfigRef): ProcSwitchResult {....raises: [
    ValueError, OSError, IOError, KeyError, Exception, ERecoverableError,
    EOFError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect,
                      WriteDirEffect, RootEffect, WriteIOEffect, WriteEnvEffect].}
  Source   Edit
proc processSwitch(switch, arg: string; pass: TCmdLinePass; conf: ConfigRef): ProcSwitchResult {....raises: [
    ValueError, OSError, OSError, OSError, IOError, OSError, OSError, OSError,
    OSError, OSError, KeyError, Exception, ERecoverableError, EOFError, OSError,
    OSError, OSError, OSError], tags: [ReadEnvEffect, ReadIOEffect,
                                       ReadDirEffect, WriteDirEffect,
                                       RootEffect, WriteIOEffect, WriteEnvEffect].}
  Source   Edit
func procResultToHumanStr(procResult: ProcSwitchResult): string {.
    ...raises: [ValueError], tags: [].}
creates a human readable string message for a switch result, does not include any extra information such as line info, severity, and so on.   Source   Edit
proc setCmd(conf: ConfigRef; cmd: Command) {....raises: [], tags: [].}
sets cmd, backend so subsequent flags can query it (e.g. so --gc:arc can be ignored for backendJs)   Source   Edit
proc setCommandEarly(conf: ConfigRef; command: string) {....raises: [], tags: [].}
  Source   Edit
func testCompileOption(conf: ConfigRef; switch: string): CompileOptCheckResult {.
    ...raises: [], tags: [].}
  Source   Edit
func testCompileOptionArg(conf: ConfigRef; switch, arg: string): CompileOptArgCheckResult {.
    ...raises: [], tags: [].}
  Source   Edit