summary refs log tree commit diff stats
path: root/compiler/semstmts.nim
Commit message (Expand)AuthorAgeFilesLines
* fixes #2400Araq2015-03-251-1/+4
* do not warn about gensym'd resultsSimon Hafner2015-03-111-1/+1
* fixes #2220; #2219; breaks #2022; for #2022 callsite needs to be usedAraq2015-03-101-93/+93
* Merge pull request #2274 from reactormonk/warning-for-resultAndreas Rumpf2015-03-081-0/+3
|\
| * Merge branch 'devel' into warning-for-resultSimon Hafner2015-03-051-14/+30
| |\
| * | added a warning for when result is shadowed #868Simon Hafner2015-02-011-0/+3
* | | .n.isNil checks for tyTuple PTypes.Max Zerzouri2015-03-071-1/+1
| |/ |/|
* | some love for the testsuite; fixed regressionsAraq2015-03-011-1/+2
* | reprocess pragmas after macro annotation for SqueakNimAraq2015-02-271-4/+10
* | Fix typosFederico Ceratto2015-02-151-1/+1
* | Fix typosFederico Ceratto2015-02-151-3/+3
* | fixes #1131Araq2015-02-101-0/+4
* | fixes #2073Araq2015-02-081-2/+2
* | fixes #2057Araq2015-02-041-4/+9
|/
* nimsuggest improvementsAraq2015-01-301-2/+3
* non-destructible context only produces a warning for nowAraq2015-01-241-3/+3
* better error message for 'invalid type'Araq2015-01-231-3/+4
* fixes #1915Araq2015-01-121-1/+2
* fixes #1903Araq2015-01-111-1/+2
* fixes tconfusing_arrow bugAraq2015-01-101-1/+3
* support for static params in the user defined type classesZahary Karadjov2015-01-021-4/+8
* fixes #1774Araq2014-12-311-1/+2
* fixes #1120Araq2014-12-251-1/+4
* fixes #1742Araq2014-12-241-5/+9
* fixed typos so docgen works againAraq2014-12-201-0/+1
* extracted the fields iterator magic to its own fileAraq2014-12-121-147/+1
* destuctors are experimental; 'func' is now a keywordAraq2014-12-101-1/+4
* implements 'defer'Araq2014-12-041-4/+17
* user defined pragmas work for generics instantiated in different modulesAraq2014-11-061-1/+1
* updated some testsAraq2014-10-041-1/+1
* deprecated string case statements without 'else'Araq2014-10-021-1/+5
* deepCopy is instantiated when its corresponding type is instantiatedAraq2014-09-261-1/+6
* made some tests greenAraq2014-09-211-1/+1
* implemented 'guard' annotationAraq2014-09-211-2/+7
* minor changes to manual.txtAraq2014-09-131-1/+1
* 'pretty' command does not exist anymore; improvements for nimfixAraq2014-09-101-0/+3
* nimfix can fix obsolete statement commentsAraq2014-09-081-0/+5
* fix #959Zahary Karadjov2014-09-041-3/+8
* fixes #1511Araq2014-09-031-14/+17
* Nimrod renamed to NimAraq2014-08-281-1/+1
* check there is only one deepCopy per typeAraq2014-08-051-1/+4
* progress on deepCopyAraq2014-08-011-1/+23
* fixes #1362Araq2014-07-151-1/+2
* fixes #1285Araq2014-06-301-2/+2
* Fixing issue #1090Clay Sweetser2014-06-151-0/+3
* Fixed #1172 (for real)Clay Sweetser2014-06-011-2/+8
* Renamed considerAccents to considerQuotedIdentClay Sweetser2014-05-261-2/+2
* Renamed 'considerAcc' to 'considerAccents' for clarityClay Sweetser2014-05-241-2/+2
* bugfix: bool for case statementsAraq2014-05-061-1/+1
* small bugfix for iteratorsAraq2014-04-301-1/+1
ss='alt'>
e25474154 ^






4de84024e ^
e25474154 ^



4de84024e ^
e25474154 ^
4de84024e ^








2df9b442c ^
4de84024e ^
d9d82fb0a ^
083d4f470 ^
28d9398de ^
d9d82fb0a ^
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

 
                            
                                         





                                                   
                                                                        


                                                              
                  

     
                             
                                                                       






                                                       
 
                               
                                            
 
                                                    

                             

           
            
                 
                             

                             



                                                                         



                                            
                 

                               


                                              
            


                 





                                            
 
                   
 

                                                                    
                       

                        







                                                             
                                                                    






                                            
                                                              



                            
                            
        








                                                            
                                                
                                     
 
                                  
                                       
 
#
#
#           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, strutils

type 
  TIdObj* = object of RootObj
    id*: int # unique id; use this for comparisons and not the pointers
  
  PIdObj* = ref TIdObj
  PIdent* = ref TIdent
  TIdent*{.acyclic.} = object of TIdObj
    s*: string
    next*: PIdent             # for hash-table chaining
    h*: THash                 # hash value of s

var firstCharIsCS*: bool = true
var buckets*: array[0..4096 * 2 - 1, PIdent]

proc cmpIgnoreStyle(a, b: cstring, blen: int): int =
  if firstCharIsCS:
    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

var wordCounter = 1

proc getIdent*(identifier: cstring, length: int, h: THash): PIdent =
  var idx = h and high(buckets)
  result = 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 = buckets[idx]
        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 countup(0, length - 1): result.s[i] = identifier[i]
  result.next = buckets[idx]
  buckets[idx] = result
  if id == 0: 
    inc(wordCounter)
    result.id = -wordCounter
  else: 
    result.id = id

proc getIdent*(identifier: string): PIdent = 
  result = getIdent(cstring(identifier), len(identifier), 
                    hashIgnoreStyle(identifier))

proc getIdent*(identifier: string, h: THash): PIdent = 
  result = getIdent(cstring(identifier), len(identifier), h)

proc identEq*(id: PIdent, name: string): bool = 
  result = id.id == getIdent(name).id

var idAnon* = getIdent":anonymous"
let idDelegator* = getIdent":delegator"