# compiler/semdata

Dark Mode

- Index

Search:
Group by:
Source Edit

This module contains the data structures for the semantic checking phase.

# Imports

options, ast, astalgo, msgs, idents, renderer, magicsys, vmdef, modulegraphs, lineinfos, pathutils, ic/ic

# Types

    ImportedModule = object
      m*: PSym
      case mode*: ImportMode
      of importAll:
        nil
      of importSet:
          imported*: IntSet

      of importExcept:
          exceptSet*: IntSet

  Source Edit

    ImportMode = enum
      importAll, importSet, importExcept

  Source Edit

    PContext = ref TContext

  Source Edit

    POptionEntry = ref TOptionEntry

  Source Edit

    PProcCon = ref TProcCon

  Source Edit

    TContext = object of TPassContext
      enforceVoidContext*: PType
      voidType*: PType
      module*: PSym
      currentScope*: PScope
      moduleScope*: PScope
      imports*: seq[ImportedModule]
      topLevelScope*: PScope
      p*: PProcCon
      intTypeCache*: array[-5 .. 32, PType]
      nilTypeCache*: PType
      matchedConcept*: ptr TMatchedConcept
      friendModules*: seq[PSym]
      instCounter*: int
      templInstCounter*: ref int
      inGenericContext*: int
      inStaticContext*: int
      inUnrolledContext*: int
      compilesContextId*: int
      compilesContextIdGenerator*: int
      inGenericInst*: int
      converters*: seq[PSym]
      patterns*: seq[PSym]
      optionStack*: seq[POptionEntry]
      symMapping*: TIdTable
      libs*: seq[PLib]
      semConstExpr*: proc (c: PContext; n: PNode): PNode {.nimcall.}
      semExpr*: proc (c: PContext; n: PNode; flags: TExprFlags = {}): PNode {.
          nimcall.}
      semTryExpr*: proc (c: PContext; n: PNode; flags: TExprFlags = {}): PNode {.
          nimcall.}
      semTryConstExpr*: proc (c: PContext; n: PNode): PNode {.nimcall.}
      computeRequiresInit*: proc (c: PContext; t: PType): bool {.nimcall.}
      hasUnresolvedArgs*: proc (c: PContext; n: PNode): bool
      semOperand*: proc (c: PContext; n: PNode; flags: TExprFlags = {}): PNode {.
          nimcall.}
      semConstBoolExpr*: proc (c: PContext; n: PNode): PNode {.nimcall.}
      semOverloadedCall*: proc (c: PContext; n, nOrig: PNode; filter: TSymKinds;
                                flags: TExprFlags): PNode {.nimcall.}
      semTypeNode*: proc (c: PContext; n: PNode; prev: PType): PType {.nimcall.}
      semInferredLambda*: proc (c: PContext; pt: TIdTable; n: PNode): PNode
      semGenerateInstance*: proc (c: PContext; fn: PSym; pt: TIdTable;
                                  info: TLineInfo): PSym
      includedFiles*: IntSet
      pureEnumFields*: TStrTable
      userPragmas*: TStrTable
      evalContext*: PEvalContext
      unknownIdents*: IntSet
      generics*: seq[TInstantiationPair]
      topStmts*: int
      lastGenericIdx*: int
      hloLoopDetector*: int
      inParallelStmt*: int
      instTypeBoundOp*: proc (c: PContext; dc: PSym; t: PType; info: TLineInfo;
                              op: TTypeAttachedOp; col: int): PSym {.nimcall.}
      selfName*: PIdent
      cache*: IdentCache
      graph*: ModuleGraph
      signatures*: TStrTable
      recursiveDep*: string
      suggestionsMade*: bool
      isAmbiguous*: bool
      features*: set[Feature]
      inTypeContext*, inConceptDecl*: int
      unusedImports*: seq[(PSym, TLineInfo)]
      exportIndirections*: HashSet[(int, int)]
      importModuleMap*: Table[int, int]
      lastTLineInfo*: TLineInfo
      sideEffects*: Table[int, seq[(TLineInfo, PSym)]]
      inUncheckedAssignSection*: int

  Source Edit

    TExprFlag = enum
      efLValue, efWantIterator, efWantIterable, efInTypeof, efNeedStatic,
      efPreferStatic, efPreferNilResult, efWantStmt, efAllowStmt, efDetermineType,
      efExplain, efWantValue, efOperand, efNoSemCheck, efNoEvaluateGeneric,
      efInCall, efFromHlo, efNoSem2Check, efNoUndeclared

  Source Edit

    TExprFlags = set[TExprFlag]

  Source Edit

    TInstantiationPair = object
      genericSym*: PSym
      inst*: PInstantiation

  Source Edit

    TMatchedConcept = object
      candidateType*: PType
      prev*: ptr TMatchedConcept
      depth*: int

  Source Edit

    TOptionEntry = object
      options*: TOptions
      defaultCC*: TCallingConvention
      dynlib*: PLib
      notes*: TNoteKinds
      features*: set[Feature]
      otherPragmas*: PNode
      warningAsErrors*: TNoteKinds

  Source Edit

    TProcCon {.acyclic.} = object
      owner*: PSym
      resultSym*: PSym
      selfSym*: PSym
      nestedLoopCounter*: int
      nestedBlockCounter*: int
      next*: PProcCon
      mappingExists*: bool
      mapping*: TIdTable
      caseContext*: seq[tuple[n: PNode, idx: int]]
      localBindStmts*: seq[PNode]

  Source Edit

# Procs

    proc addConverter(c: PContext; conv: LazySym) {....raises: [], tags: [].}

  Source Edit

    proc addConverterDef(c: PContext; conv: LazySym) {....raises: [], tags: [].}

  Source Edit

    proc addImportFileDep(c: PContext; f: FileIndex) {....raises: [], tags: [].}

  Source Edit

    proc addIncludeFileDep(c: PContext; f: FileIndex) {....raises: [IOError],
        tags: [ReadIOEffect].}

  Source Edit

    proc addPattern(c: PContext; p: LazySym) {....raises: [], tags: [].}

  Source Edit

    proc addPragmaComputation(c: PContext; n: PNode) {....raises: [], tags: [].}

  Source Edit

    proc addPureEnum(c: PContext; e: LazySym) {....raises: [], tags: [].}

  Source Edit

    proc addToGenericCache(c: PContext; s: PSym; inst: PType) {....raises: [], tags: [].}

  Source Edit

    proc addToGenericProcCache(c: PContext; s: PSym; inst: PInstantiation) {.
        ...raises: [], tags: [].}

  Source Edit

    proc addToLib(lib: PLib; sym: PSym) {....raises: [], tags: [].}

  Source Edit

    proc checkMinSonsLen(n: PNode; length: int; conf: ConfigRef) {....raises: [
        Exception, ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc checkSonsLen(n: PNode; length: int; conf: ConfigRef) {....raises: [Exception,
        ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc considerGenSyms(c: PContext; n: PNode) {....raises: [], tags: [].}

  Source Edit

    proc errorNode(c: PContext; n: PNode): PNode {....raises: [], tags: [].}

  Source Edit

    proc errorType(c: PContext): PType {....raises: [], tags: [].}

  creates a type representing an error state Source Edit

    proc exportSym(c: PContext; s: PSym) {....raises: [], tags: [].}

  Source Edit

    proc filename(c: PContext): string {....raises: [], tags: [].}

  Source Edit

    proc fillTypeS(dest: PType; kind: TTypeKind; c: PContext) {....raises: [], tags: [].}

  Source Edit

    proc get(p: PProcCon; key: PSym): PSym {....raises: [], tags: [].}

  Source Edit

    proc getCurrOwner(c: PContext): PSym {....raises: [], tags: [].}

  Source Edit

    proc getGenSym(c: PContext; s: PSym): PSym {....raises: [], tags: [].}

  Source Edit

    proc getIntLitType(c: PContext; literal: PNode): PType {....raises: [KeyError,
        Exception, ValueError, OSError, IOError, ERecoverableError], tags: [
        ReadDirEffect, RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc illFormedAst(n: PNode; conf: ConfigRef) {....raises: [Exception, ValueError,
        KeyError, OSError, IOError, ERecoverableError], tags: [RootEffect,
        ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc illFormedAstLocal(n: PNode; conf: ConfigRef) {....raises: [Exception,
        ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc isTopLevel(c: PContext): bool {.inline, ...raises: [], tags: [].}

  Source Edit

    proc isTopLevelInsideDeclaration(c: PContext; sym: PSym): bool {.inline,
        ...raises: [], tags: [].}

  Source Edit

    proc lastOptionEntry(c: PContext): POptionEntry {....raises: [], tags: [].}

  Source Edit

    proc makeAndType(c: PContext; t1, t2: PType): PType {....raises: [], tags: [].}

  Source Edit

    proc makeInstPair(s: PSym; inst: PInstantiation): TInstantiationPair {.
        ...raises: [], tags: [].}

  Source Edit

    proc makeNotType(c: PContext; t1: PType): PType {....raises: [], tags: [].}

  Source Edit

    proc makeOrType(c: PContext; t1, t2: PType): PType {....raises: [], tags: [].}

  Source Edit

    proc makePtrType(c: PContext; baseType: PType): PType {....raises: [], tags: [].}

  Source Edit

    proc makePtrType(owner: PSym; baseType: PType; idgen: IdGenerator): PType {.
        ...raises: [], tags: [].}

  Source Edit

    proc makeRangeType(c: PContext; first, last: BiggestInt; info: TLineInfo;
                       intType: PType = nil): PType {....raises: [KeyError, Exception,
        ValueError, OSError, IOError, ERecoverableError], tags: [ReadDirEffect,
        RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc makeRangeWithStaticExpr(c: PContext; n: PNode): PType {....raises: [KeyError,
        Exception, ValueError, OSError, IOError, ERecoverableError], tags: [
        ReadDirEffect, RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc makeStaticExpr(c: PContext; n: PNode): PNode {....raises: [], tags: [].}

  Source Edit

    proc makeTypeFromExpr(c: PContext; n: PNode): PType {....raises: [], tags: [].}

  Source Edit

    proc makeTypeSymNode(c: PContext; typ: PType; info: TLineInfo): PNode {....raises: [
        Exception, ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc makeTypeWithModifier(c: PContext; modifier: TTypeKind; baseType: PType): PType {.
        ...raises: [], tags: [].}

  Source Edit

    proc makeVarType(c: PContext; baseType: PType; kind = tyVar): PType {.
        ...raises: [], tags: [].}

  Source Edit

    proc makeVarType(owner: PSym; baseType: PType; idgen: IdGenerator; kind = tyVar): PType {.
        ...raises: [], tags: [].}

  Source Edit

    proc markIndirect(c: PContext; s: PSym) {.inline, ...raises: [], tags: [].}

  Source Edit

    proc newContext(graph: ModuleGraph; module: PSym): PContext {....raises: [IOError],
        tags: [ReadIOEffect].}

  Source Edit

    proc newLib(kind: TLibKind): PLib {....raises: [], tags: [].}

  Source Edit

    proc newOptionEntry(conf: ConfigRef): POptionEntry {....raises: [], tags: [].}

  Source Edit

    proc newTypeS(kind: TTypeKind; c: PContext): PType {....raises: [], tags: [].}

  Source Edit

    proc newTypeWithSons(c: PContext; kind: TTypeKind; sons: seq[PType]): PType {.
        ...raises: [], tags: [].}

  Source Edit

    proc newTypeWithSons(owner: PSym; kind: TTypeKind; sons: seq[PType];
                         idgen: IdGenerator): PType {....raises: [], tags: [].}

  Source Edit

    proc popCaseContext(c: PContext) {....raises: [], tags: [].}

  Source Edit

    proc popOptionEntry(c: PContext) {....raises: [], tags: [].}

  Source Edit

    proc popOwner(c: PContext) {....raises: [Exception, ValueError, KeyError, OSError,
                                          IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc popProcCon(c: PContext) {.inline, ...raises: [], tags: [].}

  Source Edit

    proc pushCaseContext(c: PContext; caseNode: PNode) {....raises: [], tags: [].}

  Source Edit

    proc pushOptionEntry(c: PContext): POptionEntry {....raises: [], tags: [].}

  Source Edit

    proc pushOwner(c: PContext; owner: PSym) {....raises: [], tags: [].}

  Source Edit

    proc put(p: PProcCon; key, val: PSym) {....raises: [], tags: [].}

  Source Edit

    proc reexportSym(c: PContext; s: PSym) {....raises: [], tags: [].}

  Source Edit

    proc rememberExpansion(c: PContext; info: TLineInfo; expandedSym: PSym) {.
        ...raises: [], tags: [].}

  Templates and macros are very special in Nim; these have inlining semantics so after semantic checking they leave no trace in the sem'checked AST. This is very bad for IDE-like tooling ("find all usages of this template" would not work). We need special logic to remember macro/template expansions. This is done here and delegated to the "rod" file mechanism. Source Edit

    proc scopeDepth(c: PContext): int {.inline, ...raises: [], tags: [].}

  Source Edit

    proc sealRodFile(c: PContext) {....raises: [], tags: [].}

  Source Edit

    proc setCaseContextIdx(c: PContext; idx: int) {....raises: [], tags: [].}

  Source Edit

    proc setIntLitType(c: PContext; result: PNode) {....raises: [KeyError, Exception,
        ValueError, OSError, IOError, ERecoverableError], tags: [ReadDirEffect,
        RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc storeRodNode(c: PContext; n: PNode) {....raises: [Exception],
        tags: [RootEffect].}

  Source Edit

# Templates

    template addExport(c: PContext; s: PSym)

  convenience to export a symbol from the current module Source Edit

    template config(c: PContext): ConfigRef

  Source Edit

    template encoder(c): untyped

  Source Edit

    template localErrorNode(c: PContext; n: PNode; arg: string): PNode

  Source Edit

    template localErrorNode(c: PContext; n: PNode; info: TLineInfo; arg: string): PNode

  Source Edit

    template localErrorNode(c: PContext; n: PNode; info: TLineInfo; msg: TMsgKind;
                            arg: string): PNode

  Source Edit

    template localErrorNode(c: PContext; n: PNode; msg: TMsgKind; arg: string): PNode

  Source Edit

    template packedRepr(c): untyped

  Source Edit

    template rangeHasUnresolvedStatic(t: PType): bool

  Source Edit