summary refs log tree commit diff stats
path: root/doc/docgen.md
Commit message (Expand)AuthorAgeFilesLines
* doc: fix typos (#22869)shuoer862023-10-251-2/+2
* docgen: add Pandoc footnotes (fixes #21080) (#22591)Andrey Makarov2023-09-031-2/+2
* Update nim 2.0 documentation for docgen & nimgrep (#21665)Andrey Makarov2023-04-171-6/+28
* fixes #19396; Nimdoc hide nonexported fields (#21305)ringabout2023-02-011-0/+1
* docgen: implement cross-document links (#20990)Andrey Makarov2023-01-041-35/+280
* Markdown indented code blocks (#20473)Andrey Makarov2022-10-051-82/+89
* remove deprecated and broken nimweb tools (#20442)ringabout2022-09-281-5/+1
* Extract markdown/rst doc into separate file (#20404)Andrey Makarov2022-09-221-26/+5
* Markdown links migration part 1 (#20319)Andrey Makarov2022-09-091-27/+27
* Implement Pandoc Markdown concise link extension (#20304)Andrey Makarov2022-09-041-2/+2
* Markdown code blocks part 5 (#20236)Andrey Makarov2022-08-171-14/+17
* Improve Markdown code blocks & start moving docs to Markdown style (#19954)Andrey Makarov2022-07-151-0/+638
ss='oid'>d68181246 ^
e25474154 ^
226595515 ^

e25474154 ^

9764ba933 ^
367abca38 ^
773d17cd1 ^




b4e5c9d07 ^
e25474154 ^
ed5b7cbac ^
773d17cd1 ^
4de84024e ^

e25474154 ^
4de84024e ^
e25474154 ^
902bf0587 ^

4de84024e ^



e25474154 ^
d68181246 ^
e25474154 ^

4de84024e ^
e25474154 ^
d68181246 ^
4de84024e ^


e25474154 ^
4de84024e ^


e25474154 ^
d68181246 ^
e25474154 ^

d68181246 ^
e25474154 ^
e25474154 ^
b4e5c9d07 ^


4de84024e ^

d68181246 ^


e25474154 ^

b4e5c9d07 ^

d68181246 ^
4de84024e ^
e25474154 ^






7e747d11c ^
b4e5c9d07 ^

d68181246 ^
b4e5c9d07 ^

d68181246 ^
4de84024e ^

b4e5c9d07 ^
7e747d11c ^
4de84024e ^

b4e5c9d07 ^
7e747d11c ^
4de84024e ^
773d17cd1 ^
40ec7be45 ^





00b495de9 ^

773d17cd1 ^



796498525 ^




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

 
                            
                                         





                                                   
                                                                        

                                                              
      
                  
 
    
                      

                                                                       

                                                       
                                              
 




                                              
                                 
 
                                                     
                           

           
            
                 
                             

                             



                                                                         
                              
                                           

          
                 
                               
 


                                              
            


                 
                              
                                           

          
                 
                               
 


                                                                                   

                        


                                                            

                                                          

                                     
            
                                                                    






                                            
                                                  

                               
             

                               
       

                  
                                                            
                                                            

                                                
                                                                     
                                                               
 
                                   





                                                  

                                                        



                                              




                                                   
#
#
#           The Nim Compiler
#        (c) Copyright 2012 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

# 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.

import
  hashes, wordrecg

type
  PIdent* = ref TIdent
  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

  IdentCache* = ref object
    buckets: array[0..4096 * 2 - 1, PIdent]
    wordCounter: int
    idAnon*, idDelegator*, emptyIdent*: PIdent

proc resetIdentCache*() = discard

proc cmpIgnoreStyle*(a, b: cstring, blen: int): int =
  if a[0] != b[0]: return 1
  var i = 0
  var j = 0
  result = 1
  while j < blen:
    while a[i] == '_': inc(i)
    while b[j] == '_': inc(j)
    # tolower inlined:
    var aa = a[i]
    var bb = b[j]
    if aa >= 'A' and aa <= 'Z': aa = chr(ord(aa) + (ord('a') - ord('A')))
    if bb >= 'A' and bb <= 'Z': bb = chr(ord(bb) + (ord('a') - ord('A')))
    result = ord(aa) - ord(bb)
    if (result != 0) or (aa == '\0'): break
    inc(i)
    inc(j)
  if result == 0:
    if a[i] != '\0': result = 1

proc cmpExact(a, b: cstring, blen: int): int =
  var i = 0
  var j = 0
  result = 1
  while j < blen:
    var aa = a[i]
    var bb = b[j]
    result = ord(aa) - ord(bb)
    if (result != 0) or (aa == '\0'): break
    inc(i)
    inc(j)
  if result == 0:
    if a[i] != '\0': result = 1

proc getIdent*(ic: IdentCache; identifier: cstring, length: int, h: Hash): PIdent =
  var idx = h and high(ic.buckets)
  result = ic.buckets[idx]
  var last: PIdent = nil
  var id = 0
  while result != nil:
    if cmpExact(cstring(result.s), identifier, length) == 0:
      if last != nil:
        # make access to last looked up identifier faster:
        last.next = result.next
        result.next = ic.buckets[idx]
        ic.buckets[idx] = result
      return
    elif cmpIgnoreStyle(cstring(result.s), identifier, length) == 0:
      assert((id == 0) or (id == result.id))
      id = result.id
    last = result
    result = result.next
  new(result)
  result.h = h
  result.s = newString(length)
  for i in 0..<length: result.s[i] = identifier[i]
  result.next = ic.buckets[idx]
  ic.buckets[idx] = result
  if id == 0:
    inc(ic.wordCounter)
    result.id = -ic.wordCounter
  else:
    result.id = id

proc getIdent*(ic: IdentCache; identifier: string): PIdent =
  result = getIdent(ic, cstring(identifier), identifier.len,
                    hashIgnoreStyle(identifier))

proc getIdent*(ic: IdentCache; identifier: string, h: Hash): PIdent =
  result = getIdent(ic, cstring(identifier), identifier.len, h)

proc newIdentCache*(): IdentCache =
  result = IdentCache()
  result.idAnon = result.getIdent":anonymous"
  result.wordCounter = 1
  result.idDelegator = result.getIdent":delegator"
  result.emptyIdent = result.getIdent("")
  # initialize the keywords:
  for s in succ(low(TSpecialWord))..high(TSpecialWord):
    result.getIdent($s, hashIgnoreStyle($s)).id = ord(s)

proc whichKeyword*(id: PIdent): TSpecialWord =
  if id.id < 0: result = wInvalid
  else: result = TSpecialWord(id.id)

proc hash*(x: PIdent): Hash {.inline.} = x.h
proc `==`*(a, b: PIdent): bool {.inline.} =
  if a.isNil or b.isNil: result = system.`==`(a, b)
  else: result = a.id == b.id