summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-09-21 15:49:34 +0200
committerAraq <rumpf_a@web.de>2015-09-21 15:49:48 +0200
commitba4dd92f457b9dd52fd6eddbd3f231b040750b60 (patch)
tree2ae16aedea774c26c9a351faa0bab07f601e6041 /compiler
parentc04e17aea36ddf03955abd8d07ea09ac43f8051e (diff)
downloadNim-ba4dd92f457b9dd52fd6eddbd3f231b040750b60.tar.gz
fixes regression: NimForum compiles again
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semgnrc.nim10
-rw-r--r--compiler/semtempl.nim85
2 files changed, 63 insertions, 32 deletions
diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim
index 89b8847f3..620453277 100644
--- a/compiler/semgnrc.nim
+++ b/compiler/semgnrc.nim
@@ -32,12 +32,6 @@ type
     cursorInBody: bool # only for nimsuggest
     bracketExpr: PNode
 
-template withBracketExpr(x, body: untyped) =
-  let old = ctx.bracketExpr
-  ctx.bracketExpr = x
-  body
-  ctx.bracketExpr = old
-
 type
   TSemGenericFlag = enum
     withinBind, withinTypeDesc, withinMixin
@@ -271,7 +265,7 @@ proc semGenericStmt(c: PContext, n: PNode,
     result = newNodeI(nkCall, n.info)
     result.add newIdentNode(getIdent("[]"), n.info)
     for i in 0 ..< n.len: result.add(n[i])
-    withBracketExpr n.sons[0]:
+    withBracketExpr ctx, n.sons[0]:
       result = semGenericStmt(c, result, flags, ctx)
   of nkAsgn, nkFastAsgn:
     checkSonsLen(n, 2)
@@ -291,7 +285,7 @@ proc semGenericStmt(c: PContext, n: PNode,
       result.add newIdentNode(getIdent("[]="), n.info)
       for i in 0 ..< a.len: result.add(a[i])
       result.add(b)
-      withBracketExpr a.sons[0]:
+      withBracketExpr ctx, a.sons[0]:
         result = semGenericStmt(c, result, flags, ctx)
     else:
       for i in countup(0, sonsLen(n) - 1):
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim
index fc1af7246..2dda8276d 100644
--- a/compiler/semtempl.nim
+++ b/compiler/semtempl.nim
@@ -110,6 +110,13 @@ type
     toBind, toMixin, toInject: IntSet
     owner: PSym
     cursorInBody: bool # only for nimsuggest
+    bracketExpr: PNode
+
+template withBracketExpr(ctx, x, body: untyped) =
+  let old = ctx.bracketExpr
+  ctx.bracketExpr = x
+  body
+  ctx.bracketExpr = old
 
 proc getIdentNode(c: var TemplCtx, n: PNode): PNode =
   case n.kind
@@ -310,6 +317,18 @@ proc wrapInBind(c: var TemplCtx; n: PNode; opr: string): PNode =
   else:
     result = n
 
+proc oprIsRoof(n: PNode): bool =
+  const roof = "^"
+  case n.kind
+  of nkIdent: result = n.ident.s == roof
+  of nkSym: result = n.sym.name.s == roof
+  of nkAccQuoted:
+    if n.len == 1:
+      result = oprIsRoof(n.sons[0])
+  of nkOpenSymChoice, nkClosedSymChoice:
+    result = oprIsRoof(n.sons[0])
+  else: discard
+
 proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
   result = n
   semIdeForTemplateOrGenericCheck(n, c.cursorInBody)
@@ -452,10 +471,16 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
     result.sons[1] = semTemplBody(c, n.sons[1])
   of nkPragma:
     result = onlyReplaceParams(c, n)
-  of nkBracketExpr, nkCurlyExpr:
+  of nkBracketExpr:
     result = newNodeI(nkCall, n.info)
-    result.add newIdentNode(getIdent(if n.kind == nkBracketExpr:"[]" else:"{}"),
-                            n.info)
+    result.add newIdentNode(getIdent("[]"), n.info)
+    for i in 0 ..< n.len: result.add(n[i])
+    let n0 = semTemplBody(c, n.sons[0])
+    withBracketExpr c, n0:
+      result = semTemplBodySons(c, result)
+  of nkCurlyExpr:
+    result = newNodeI(nkCall, n.info)
+    result.add newIdentNode(getIdent("{}"), n.info)
     for i in 0 ..< n.len: result.add(n[i])
     result = semTemplBodySons(c, result)
   of nkAsgn, nkFastAsgn:
@@ -465,33 +490,45 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
 
     let k = a.kind
     case k
-    of nkBracketExpr, nkCurlyExpr:
+    of nkBracketExpr:
+      result = newNodeI(nkCall, n.info)
+      result.add newIdentNode(getIdent("[]="), n.info)
+      for i in 0 ..< a.len: result.add(a[i])
+      result.add(b)
+      let a0 = semTemplBody(c, a.sons[0])
+      withBracketExpr c, a0:
+        result = semTemplBodySons(c, result)
+    of nkCurlyExpr:
       result = newNodeI(nkCall, n.info)
-      result.add newIdentNode(getIdent(if k == nkBracketExpr:"[]=" else:"{}="),
-                              n.info)
+      result.add newIdentNode(getIdent("{}="), n.info)
       for i in 0 ..< a.len: result.add(a[i])
       result.add(b)
+      result = semTemplBodySons(c, result)
     else:
-      result = n
-    result = semTemplBodySons(c, result)
-  else:
+      result = semTemplBodySons(c, n)
+  of nkCallKinds-{nkPostfix}:
+    result = semTemplBodySons(c, n)
+    if c.bracketExpr != nil and n.len == 2 and oprIsRoof(n.sons[0]):
+      result.add c.bracketExpr
+  of nkDotExpr, nkAccQuoted:
     # dotExpr is ambiguous: note that we explicitly allow 'x.TemplateParam',
     # so we use the generic code for nkDotExpr too
-    if n.kind == nkDotExpr or n.kind == nkAccQuoted:
-      let s = qualifiedLookUp(c.c, n, {})
-      if s != nil:
-        # do not symchoice a quoted template parameter (bug #2390):
-        if s.owner == c.owner and s.kind == skParam and
-            n.kind == nkAccQuoted and n.len == 1:
-          incl(s.flags, sfUsed)
-          styleCheckUse(n.info, s)
-          return newSymNode(s, n.info)
-        elif contains(c.toBind, s.id):
-          return symChoice(c.c, n, s, scClosed)
-        elif contains(c.toMixin, s.name.id):
-          return symChoice(c.c, n, s, scForceOpen)
-        else:
-          return symChoice(c.c, n, s, scOpen)
+    let s = qualifiedLookUp(c.c, n, {})
+    if s != nil:
+      # do not symchoice a quoted template parameter (bug #2390):
+      if s.owner == c.owner and s.kind == skParam and
+          n.kind == nkAccQuoted and n.len == 1:
+        incl(s.flags, sfUsed)
+        styleCheckUse(n.info, s)
+        return newSymNode(s, n.info)
+      elif contains(c.toBind, s.id):
+        return symChoice(c.c, n, s, scClosed)
+      elif contains(c.toMixin, s.name.id):
+        return symChoice(c.c, n, s, scForceOpen)
+      else:
+        return symChoice(c.c, n, s, scOpen)
+    result = semTemplBodySons(c, n)
+  else:
     result = semTemplBodySons(c, n)
 
 proc semTemplBodyDirty(c: var TemplCtx, n: PNode): PNode =
de> 2015-03-08 14:45:06 +0100 committer Araq <rumpf_a@web.de> 2015-03-08 14:45:06 +0100 don't use conio.h on windows (#2137)' href='/ahoang/Nim/commit/lib/impure/rdstdin.nim?h=devel&id=419199bf9ae507c104d497e1714ceedf300dc38e'>419199bf9 ^
10a7830ba ^
008b0f19b ^
419199bf9 ^
d6d152e45 ^
dcd23ae1f ^
55c407464 ^
063448668 ^
dcd23ae1f ^
2df9b442c ^
d4bc11b65 ^
aa8b470cf ^
aa01c346f ^

0f37d0e1f ^

aa8b470cf ^

55c407464 ^
2df9b442c ^
d4bc11b65 ^
aa8b470cf ^
aa01c346f ^
ca39e113d ^

a489161b1 ^

aa8b470cf ^

a489161b1 ^

d6d152e45 ^

dcd23ae1f ^




ea03fc688 ^
dcd23ae1f ^

d6d152e45 ^

dcd23ae1f ^




d6d152e45 ^
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