compiler/ast/astalgo

    Dark Mode
Search:
  Source   Edit

Algorithms for the abstract syntax tree: hash tables, lists and sets of nodes are supported. Efficiency is important as the data structures here are used in various places of the compiler.

Types

TIdentIter = object
  h*: Hash
  name*: PIdent
  Source   Edit
TIIPair {.final.} = object
  key*, val*: int
  Source   Edit
TIIPairSeq = seq[TIIPair]
  Source   Edit
TIITable {.final.} = object
  counter*: int
  data*: TIIPairSeq
  Source   Edit
TTabIter = object
  h: Hash
  Source   Edit

Consts

InvalidKey = -9223372036854775808
  Source   Edit

Procs

proc firstIdentExcluding(ti: var TIdentIter; tab: TStrTable; s: PIdent;
                         excluding: IntSet): PSym {....raises: [], tags: [].}
  Source   Edit
proc fromSystem(op: PSym): bool {.inline, ...raises: [], tags: [].}
  Source   Edit
proc getModule(s: PSym): PSym {....raises: [], tags: [].}
if it's a module returns itself, otherwise looks through s' owners, may return nil if none are found.   Source   Edit
proc getNamedParamFromList(list: PNode; ident: PIdent): PSym {....raises: [],
    tags: [].}
Named parameters are special because a named parameter can be gensym'ed and then they have '`<number>' suffix that we need to ignore, see compiler / evaltempl.nim, snippet:
result.add newIdentNode(getIdent(c.ic, x.name.s & "\`gensym" & $x.id),
         if c.instLines: actual.info else: templ.info)
  Source   Edit
proc getSymFromList(list: PNode; ident: PIdent; start: int = 0): PSym {.
    ...raises: [], tags: [].}
  Source   Edit
proc hashNode(p: RootRef): Hash {....raises: [], tags: [].}
  Source   Edit
proc idNodeTableGet(t: TIdNodeTable; key: PIdObj): PNode {....raises: [], tags: [].}
  Source   Edit
proc idNodeTablePut(t: var TIdNodeTable; key: PIdObj; val: PNode) {....raises: [],
    tags: [].}
  Source   Edit
proc idTableGet(t: TIdTable; key: int): RootRef {....raises: [], tags: [].}
  Source   Edit
proc idTableGet(t: TIdTable; key: PIdObj): RootRef {....raises: [], tags: [].}
  Source   Edit
proc idTableHasObjectAsKey(t: TIdTable; key: PIdObj): bool {....raises: [],
    tags: [].}
  Source   Edit
proc idTablePut(t: var TIdTable; key: PIdObj; val: RootRef) {....raises: [],
    tags: [].}
  Source   Edit
proc iiTableGet(t: TIITable; key: int): int {....raises: [], tags: [].}
  Source   Edit
proc iiTablePut(t: var TIITable; key, val: int) {....raises: [], tags: [].}
  Source   Edit
proc initIdentIter(ti: var TIdentIter; tab: TStrTable; s: PIdent): PSym {.
    ...raises: [], tags: [].}
  Source   Edit
proc initIiTable(x: var TIITable) {....raises: [], tags: [].}
  Source   Edit
proc initTabIter(ti: var TTabIter; tab: TStrTable): PSym {....raises: [], tags: [].}
  Source   Edit
func isAddrNode(n: PNode): bool {....raises: [], tags: [].}
  Source   Edit
proc isDiscriminantField(n: PNode): bool {....raises: [], tags: [].}
  Source   Edit
proc leValue(a, b: PNode): bool {....raises: [ERecoverableError], tags: [].}
  Source   Edit
proc listSymbolNames(symbols: openArray[PSym]): string {....raises: [], tags: [].}
  Source   Edit
proc lookupInRecord(n: PNode; field: PIdent): PSym {....raises: [], tags: [].}
  Source   Edit
func lookupInRecord(n: PNode; pos: int): PSym {....raises: [], tags: [].}
Searches record AST n for a symbol with position pos, returning the symbol if one is found.   Source   Edit
proc mustRehash(length, counter: int): bool {....raises: [], tags: [].}
  Source   Edit
proc nextIdentExcluding(ti: var TIdentIter; tab: TStrTable; excluding: IntSet): PSym {.
    ...raises: [], tags: [].}
  Source   Edit
proc nextIdentIter(ti: var TIdentIter; tab: TStrTable): PSym {....raises: [],
    tags: [].}
  Source   Edit
proc nextIter(ti: var TTabIter; tab: TStrTable): PSym {....raises: [], tags: [].}
  Source   Edit
proc nextTry(h, maxHash: Hash): Hash {.inline, ...raises: [], tags: [].}
  Source   Edit
proc objectSetContains(t: TObjectSet; obj: RootRef): bool {....raises: [], tags: [].}
  Source   Edit
proc objectSetContainsOrIncl(t: var TObjectSet; obj: RootRef): bool {.
    ...raises: [], tags: [].}
  Source   Edit
proc objectSetIncl(t: var TObjectSet; obj: RootRef) {....raises: [], tags: [].}
  Source   Edit
proc sameValue(a, b: PNode): bool {....raises: [ERecoverableError], tags: [].}
  Source   Edit
proc skipConvCastAndClosure(n: PNode): PNode {....raises: [], tags: [].}
  Source   Edit
proc strTableAdd(t: var TStrTable; n: PSym) {....raises: [], tags: [].}
  Source   Edit
proc strTableContains(t: TStrTable; n: PSym): bool {....raises: [], tags: [].}
  Source   Edit
proc strTableGet(t: TStrTable; name: PIdent): PSym {....raises: [], tags: [].}
  Source   Edit
proc strTableIncl(t: var TStrTable; n: PSym; onConflictKeepOld = false): bool {.
    discardable, ...raises: [], tags: [].}
  Source   Edit
proc strTableInclReportConflict(t: var TStrTable; n: PSym;
                                onConflictKeepOld = false): PSym {....raises: [],
    tags: [].}
  Source   Edit
proc symTabReplace(t: var TStrTable; prevSym: PSym; newSym: PSym) {....raises: [],
    tags: [].}
  Source   Edit
proc weakLeValue(a, b: PNode): TImplication {....raises: [ERecoverableError],
    tags: [].}
  Source   Edit

Iterators

iterator idTablePairs(t: TIdTable): tuple[key: PIdObj, val: RootRef] {.
    ...raises: [], tags: [].}
  Source   Edit
iterator items(tab: TStrTable): PSym {....raises: [], tags: [].}
  Source   Edit
iterator pairs(t: TIdNodeTable): tuple[key: PIdObj, val: PNode] {....raises: [],
    tags: [].}
  Source   Edit
iterator pairs(t: TIdTable): tuple[key: int, value: RootRef] {....raises: [],
    tags: [].}
  Source   Edit