summary refs log tree commit diff stats
path: root/nim/ccgutils.pas
diff options
context:
space:
mode:
Diffstat (limited to 'nim/ccgutils.pas')
-rw-r--r--nim/ccgutils.pas32
1 files changed, 30 insertions, 2 deletions
diff --git a/nim/ccgutils.pas b/nim/ccgutils.pas
index 6817f4518..09cd504bc 100644
--- a/nim/ccgutils.pas
+++ b/nim/ccgutils.pas
@@ -17,15 +17,41 @@ interface
 
 uses
   charsets, nsystem,
-  ast, astalgo, ropes, lists, hashes, strutils, types;
+  ast, astalgo, ropes, lists, hashes, strutils, types, msgs;
 
 function toCChar(c: Char): string;
 function makeCString(const s: string): PRope;
 
 function TableGetType(const tab: TIdTable; key: PType): PObject;
+function GetUniqueType(key: PType): PType;
 
 implementation
 
+var
+  gTypeTable: TIdTable;
+
+function GetUniqueType(key: PType): PType;
+var
+  t: PType;
+  h: THash;
+begin
+  result := key;
+  if key = nil then exit;
+  assert(key.kind <> tyForward);
+  if key.kind = tyGenericInst then begin
+    result := GetUniqueType(lastSon(key));
+    exit
+  end;
+  if IdTableHasObjectAsKey(gTypeTable, key) then exit;
+  // we have to do a slow linear search because types may need
+  // to be compared by their structure:
+  for h := 0 to high(gTypeTable.data) do begin
+    t := PType(gTypeTable.data[h].key);
+    if (t <> nil) and sameType(t, key) then begin result := t; exit end
+  end;
+  IdTablePut(gTypeTable, key, key);
+end;
+
 function TableGetType(const tab: TIdTable; key: PType): PObject;
 var
   t: PType;
@@ -69,7 +95,7 @@ begin
   result := nil;
   res := '"'+'';
   for i := strStart to length(s)+strStart-1 do begin
-    if i mod MaxLineLength = 0 then begin
+    if (i-strStart+1) mod MaxLineLength = 0 then begin
       res := res +{&} '"' +{&} nl;
       app(result, toRope(res));
       res := '"'+''; // reset
@@ -80,4 +106,6 @@ begin
   app(result, toRope(res));
 end;
 
+initialization
+  InitIdTable(gTypeTable);
 end.
ir is now flat' href='/ahoang/Nim/commit/compiler/rodutils.nim?h=devel&id=7ebaf44897c0e2b0229654cc110b751f54275edb'>7ebaf4489 ^
4de84024e ^


7ebaf4489 ^
4de84024e ^
















7ebaf4489 ^
4de84024e ^



















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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136