compiler/ast/idents

  Source   Edit

Identifier handling

An identifier is a shared immutable string that can be compared by its id. This module is essential for the compiler's performance.

Types

IdentCache = ref object
  buckets: array[0 .. 8192 - 1, PIdent]
  wordCounter: int
  idAnon*, idDelegator*, emptyIdent*, identNotFound: PIdent
  Source   Edit
PIdent = ref TIdent
  Source   Edit
TIdent {.acyclic.} = object
  id*: int                   ## unique id; use this for comparisons and not the pointers
  s*: string
  next*: PIdent              ## for hash-table chaining
  h*: Hash                   ## hash value of `s`
  
Identifiers only form a chain, cycles are disallowed.   Source   Edit

Procs

func `==`(a, b: PIdent): bool {.inline, ...raises: [], tags: [].}
identity based (PIdent.id) based equality, unless either are nil, then resort to reference based equality   Source   Edit
proc cmpIgnoreStyle(a, b: cstring; blen: int): int {....raises: [], tags: [].}
  Source   Edit
proc getIdent(ic: IdentCache; identifier: cstring; length: int; h: Hash): PIdent {.
    ...raises: [], tags: [].}
  Source   Edit
proc getIdent(ic: IdentCache; identifier: string): PIdent {....raises: [], tags: [].}
  Source   Edit
proc getIdent(ic: IdentCache; identifier: string; h: Hash): PIdent {....raises: [],
    tags: [].}
  Source   Edit
proc getNotFoundIdent(ic: IdentCache): PIdent {....raises: [], tags: [].}
returns the identifier associated with an error, this will create the identifier if it does not already exist in the cache.   Source   Edit
func hash(x: PIdent): Hash {.inline, ...raises: [], tags: [].}
don't actually compute, we just access it   Source   Edit
func isNotFound(ic: IdentCache; i: PIdent): bool {.inline, ...raises: [], tags: [].}
optimization: check against the cached/canonical not found ident entry   Source   Edit
proc newIdentCache(): IdentCache {....raises: [], tags: [].}
  Source   Edit
proc resetIdentCache() {....raises: [], tags: [].}
  Source   Edit
proc whichKeyword(id: PIdent): TSpecialWord {....raises: [], tags: [].}
  Source   Edit