# semdata

Theme:

- 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; expectedType: PType = nil): PNode {.
          nimcall.}
      semExpr*: proc (c: PContext; n: PNode; flags: TExprFlags = {};
                      expectedType: PType = nil): PNode {.nimcall.}
      semExprWithType*: proc (c: PContext; n: PNode; flags: TExprFlags = {};
                              expectedType: PType = nil): PNode {.nimcall.}
      semTryExpr*: proc (c: PContext; n: PNode; flags: TExprFlags = {}): PNode {.
          nimcall.}
      semTryConstExpr*: proc (c: PContext; n: PNode; expectedType: PType = nil): 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.}
      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
      importModuleLookup*: Table[int, seq[int]]
      skipTypes*: seq[PNode]

  Source Edit

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

  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
      nestedLoopCounter*: int
      nestedBlockCounter*: int
      breakInLoop*: bool
      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: [],
        forbids: [].}

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  creates a type representing an error state Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  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: [], forbids: [].}

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  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