summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-01-12 01:43:25 +0100
committerAraq <rumpf_a@web.de>2015-01-12 02:00:37 +0100
commitb9079b87134864a478ac453fd31363e6d8d86794 (patch)
tree0092602d8d248c4be2b300e9699a1bc710099ba9 /compiler
parentc87f1eb5813cca9ce5c1f251d9b3af3a2d47be71 (diff)
downloadNim-b9079b87134864a478ac453fd31363e6d8d86794.tar.gz
fixes #1915
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ccgexprs.nim4
-rw-r--r--compiler/evaltempl.nim2
-rw-r--r--compiler/semdata.nim1
-rw-r--r--compiler/semexprs.nim13
-rw-r--r--compiler/semstmts.nim3
-rw-r--r--compiler/semtempl.nim15
6 files changed, 29 insertions, 9 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 4a3be0027..2d3cf562b 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -1977,7 +1977,9 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
     of skParam:
       if sym.loc.r == nil or sym.loc.t == nil:
         #echo "FAILED FOR PRCO ", p.prc.name.s
-        internalError(n.info, "expr: param not init " & sym.name.s & "_" & $sym.id)
+        #debug p.prc.typ.n
+        #echo renderTree(p.prc.ast, {renderIds})
+        internalError(n.info, "expr: param not init " & sym.name.s & "_" & $sym.id)          
       putLocIntoDest(p, d, sym.loc)
     else: internalError(n.info, "expr(" & $sym.kind & "); unknown symbol")
   of nkNilLit:
diff --git a/compiler/evaltempl.nim b/compiler/evaltempl.nim
index 78cc691c0..946be68f8 100644
--- a/compiler/evaltempl.nim
+++ b/compiler/evaltempl.nim
@@ -29,7 +29,7 @@ proc evalTemplateAux(templ, actual: PNode, c: var TemplCtx, result: PNode) =
   of nkSym:
     var s = templ.sym
     if s.owner.id == c.owner.id:
-      if s.kind == skParam:
+      if s.kind == skParam and sfGenSym notin s.flags:
         let x = actual.sons[s.position]
         if x.kind == nkArgList:
           for y in items(x): result.add(y)
diff --git a/compiler/semdata.nim b/compiler/semdata.nim
index 623f9b633..bb82db292 100644
--- a/compiler/semdata.nim
+++ b/compiler/semdata.nim
@@ -35,6 +35,7 @@ type
     inTryStmt*: int           # whether we are in a try statement; works also
                               # in standalone ``except`` and ``finally``
     next*: PProcCon           # used for stacking procedure contexts
+    wasForwarded*: bool       # whether the current proc has a separate header
   
   TInstantiationPair* = object
     genericSym*: PSym
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index f9889eee1..a3ae0263d 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -109,9 +109,16 @@ proc semSym(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
     # if a proc accesses a global variable, it is not side effect free:
     if sfGlobal in s.flags:
       incl(c.p.owner.flags, sfSideEffect)
-    elif s.kind == skParam and s.typ.kind == tyStatic and s.typ.n != nil:
-      # XXX see the hack in sigmatch.nim ...
-      return s.typ.n
+    elif s.kind == skParam:
+      if s.typ.kind == tyStatic and s.typ.n != nil:
+        # XXX see the hack in sigmatch.nim ...
+        return s.typ.n
+      elif sfGenSym in s.flags and c.p.wasForwarded:
+        # gensym'ed parameters that nevertheless have been forward declared
+        # need a special fixup:
+        let realParam = c.p.owner.typ.n[s.position+1]
+        internalAssert realParam.kind == nkSym and realParam.sym.kind == skParam
+        return newSymNode(c.p.owner.typ.n[s.position+1].sym, n.info)
     result = newSymNode(s, n.info)
     # We cannot check for access to outer vars for example because it's still
     # not sure the symbol really ends up being used:
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 44f14afd8..3b90337e5 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -982,7 +982,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
   # process parameters:
   if n.sons[paramsPos].kind != nkEmpty:
     semParamList(c, n.sons[paramsPos], gp, s)
-    if sonsLen(gp) > 0: 
+    if sonsLen(gp) > 0:
       if n.sons[genericParamsPos].kind == nkEmpty:
         # we have a list of implicit type parameters:
         n.sons[genericParamsPos] = gp
@@ -1049,6 +1049,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
     if n.sons[genericParamsPos].kind == nkEmpty or usePseudoGenerics:
       if not usePseudoGenerics: paramsTypeCheck(c, s.typ)
       pushProcCon(c, s)
+      c.p.wasForwarded = proto != nil
       maybeAddResult(c, s, n)
       if sfImportc notin s.flags:
         # no semantic checking for importc:
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim
index 81e4f2463..e2c46d3ab 100644
--- a/compiler/semtempl.nim
+++ b/compiler/semtempl.nim
@@ -127,7 +127,7 @@ proc getIdentNode(c: var TemplCtx, n: PNode): PNode =
 
 proc isTemplParam(c: TemplCtx, n: PNode): bool {.inline.} =
   result = n.kind == nkSym and n.sym.kind == skParam and
-           n.sym.owner == c.owner
+           n.sym.owner == c.owner and sfGenSym notin n.sym.flags
 
 proc semTemplBody(c: var TemplCtx, n: PNode): PNode
 
@@ -246,8 +246,8 @@ proc semRoutineInTemplBody(c: var TemplCtx, n: PNode, k: TSymKind): PNode =
     n.sons[i] = semTemplBody(c, n.sons[i])
   closeScope(c)
 
-proc semTemplSomeDecl(c: var TemplCtx, n: PNode, symKind: TSymKind) =
-  for i in countup(0, sonsLen(n) - 1):
+proc semTemplSomeDecl(c: var TemplCtx, n: PNode, symKind: TSymKind; start=0) =
+  for i in countup(start, sonsLen(n) - 1):
     var a = n.sons[i]
     if a.kind == nkCommentStmt: continue
     if (a.kind != nkIdentDefs) and (a.kind != nkVarTuple): illFormedAst(a)
@@ -348,6 +348,10 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
       a.sons[L-1] = semTemplBodyScope(c, a.sons[L-1])
   of nkVarSection: semTemplSomeDecl(c, n, skVar)
   of nkLetSection: semTemplSomeDecl(c, n, skLet)
+  of nkFormalParams:
+    checkMinSonsLen(n, 1)
+    n.sons[0] = semTemplBody(c, n.sons[0])
+    semTemplSomeDecl(c, n, skParam, 1)
   of nkConstSection:
     for i in countup(0, sonsLen(n) - 1): 
       var a = n.sons[i]
@@ -485,6 +489,11 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
   # process parameters:
   if n.sons[paramsPos].kind != nkEmpty:
     semParamList(c, n.sons[paramsPos], gp, s)
+    # a template's parameters are not gensym'ed even if that was originally the
+    # case as we determine whether it's a template parameter in the template
+    # body by the absense of the skGenSym flag:
+    for i in 1 .. s.typ.n.len-1:
+      s.typ.n.sons[i].sym.flags.excl sfGenSym
     if sonsLen(gp) > 0:
       if n.sons[genericParamsPos].kind == nkEmpty:
         # we have a list of implicit type parameters:
previous revision' href='/ahoang/Nim/blame/lib/wrappers/sqlite3.nim?h=devel&id=1a770402784ed99099f1905e1e4c201020e03bca'>^
43bddf62d ^
25e6c53bb ^

43bddf62d ^

b2075302b ^
05a3c1b10 ^
43bddf62d ^
bc79f4028 ^
43bddf62d ^
bc79f4028 ^
cbd8da93f ^

43bddf62d ^
b2075302b ^
43bddf62d ^
b2075302b ^

fa101a722 ^

83ffc6bf5 ^
fa101a722 ^
ea1a26294 ^
43bddf62d ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^

b2075302b ^
ea1a26294 ^

b2075302b ^
ea1a26294 ^
b2075302b ^
43bddf62d ^

ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
43bddf62d ^

ea1a26294 ^

b2075302b ^


ea1a26294 ^
b2075302b ^

ea1a26294 ^
b2075302b ^
43bddf62d ^
ea1a26294 ^
43bddf62d ^
b2075302b ^
ea1a26294 ^
b2075302b ^
43bddf62d ^
ea1a26294 ^
b2075302b ^
43bddf62d ^

ea1a26294 ^
b2075302b ^
43bddf62d ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^


b2075302b ^
25e6c53bb ^
ea1a26294 ^
b2075302b ^
43bddf62d ^
25e6c53bb ^
b2075302b ^
ea1a26294 ^
43bddf62d ^
25e6c53bb ^
ea1a26294 ^
b2075302b ^
25e6c53bb ^
ea1a26294 ^
b2075302b ^
25e6c53bb ^
ea1a26294 ^
25e6c53bb ^
ea1a26294 ^
25e6c53bb ^
ea1a26294 ^

b2075302b ^
25e6c53bb ^
ea1a26294 ^
b2075302b ^
25e6c53bb ^
ea1a26294 ^
b2075302b ^



25e6c53bb ^
ea1a26294 ^
b2075302b ^
25e6c53bb ^
ea1a26294 ^
b2075302b ^
25e6c53bb ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
25e6c53bb ^
ea1a26294 ^
25e6c53bb ^
ea1a26294 ^
25e6c53bb ^
ea1a26294 ^

b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
de989e6fb ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
25e6c53bb ^
ea1a26294 ^


b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
43bddf62d ^




ea1a26294 ^
43bddf62d ^




ea1a26294 ^

b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
43bddf62d ^
ea1a26294 ^

b2075302b ^
ea1a26294 ^
b2075302b ^
43bddf62d ^
ea1a26294 ^
b2075302b ^
43bddf62d ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
43bddf62d ^
ea1a26294 ^
43bddf62d ^
ea1a26294 ^

b2075302b ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
43bddf62d ^
ea1a26294 ^
b2075302b ^
43bddf62d ^
ea1a26294 ^
b2075302b ^
43bddf62d ^
ea1a26294 ^
b2075302b ^
43bddf62d ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^
43bddf62d ^
cbd8da93f ^
ea1a26294 ^
43bddf62d ^
cbd8da93f ^
ea1a26294 ^
cbd8da93f ^
ea1a26294 ^
cbd8da93f ^
ea1a26294 ^

43bddf62d ^
ea1a26294 ^
b2075302b ^
ea1a26294 ^
b2075302b ^






cb3c3c306 ^


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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377