summary refs log tree commit diff stats
path: root/nim/semtempl.pas
diff options
context:
space:
mode:
authorAndreas Rumpf <andreas@andreas-desktop>2009-11-12 19:34:21 +0100
committerAndreas Rumpf <andreas@andreas-desktop>2009-11-12 19:34:21 +0100
commitac421c37ba9a973155dc5600e38d7a40553d8de6 (patch)
tree5ede0dfe1c02aa547f788a39f070614a64a3b9ab /nim/semtempl.pas
parentd5acb88cccecf54bcc9a7c13f4fbaa095a8b37d4 (diff)
downloadNim-ac421c37ba9a973155dc5600e38d7a40553d8de6.tar.gz
bind table
Diffstat (limited to 'nim/semtempl.pas')
-rwxr-xr-xnim/semtempl.pas14
1 files changed, 9 insertions, 5 deletions
diff --git a/nim/semtempl.pas b/nim/semtempl.pas
index e639960d3..fc7e12a73 100755
--- a/nim/semtempl.pas
+++ b/nim/semtempl.pas
@@ -147,7 +147,8 @@ begin
   end
 end;
 
-function resolveTemplateParams(c: PContext; n: PNode; withinBind: bool): PNode;
+function resolveTemplateParams(c: PContext; n: PNode; withinBind: bool;
+                               var toBind: TIntSet): PNode;
 var
   i: int;
   s: PSym;
@@ -155,7 +156,7 @@ begin
   if n = nil then begin result := nil; exit end;
   case n.kind of
     nkIdent: begin
-      if not withinBind then begin
+      if not withinBind and not IntSetContains(toBind, n.ident.id) then begin
         s := SymTabLocalGet(c.Tab, n.ident);
         if (s <> nil) then begin
           result := newSymNode(s);
@@ -165,17 +166,18 @@ begin
           result := n
       end
       else begin
+        IntSetIncl(toBind, n.ident.id);
         result := symChoice(c, n, lookup(c, n))
       end
     end;
     nkSym..nkNilLit: // atom
       result := n;
     nkBind: 
-      result := resolveTemplateParams(c, n.sons[0], true);
+      result := resolveTemplateParams(c, n.sons[0], true, toBind);
     else begin
       result := n;
       for i := 0 to sonsLen(n)-1 do
-        result.sons[i] := resolveTemplateParams(c, n.sons[i], withinBind);
+        result.sons[i] := resolveTemplateParams(c, n.sons[i], withinBind, toBind);
     end
   end
 end;
@@ -211,6 +213,7 @@ end;
 function semTemplateDef(c: PContext; n: PNode): PNode;
 var
   s: PSym;
+  toBind: TIntSet;
 begin
   if c.p.owner.kind = skModule then begin
     s := semIdentVis(c, skTemplate, n.sons[0], {@set}[sfStar]);
@@ -248,7 +251,8 @@ begin
   addParams(c, s.typ.n);
   
   // resolve parameters:
-  n.sons[codePos] := resolveTemplateParams(c, n.sons[codePos], false);
+  IntSetInit(toBind);
+  n.sons[codePos] := resolveTemplateParams(c, n.sons[codePos], false, toBind);
   if not (s.typ.sons[0].kind in [tyStmt, tyTypeDesc]) then
     n.sons[codePos] := transformToExpr(n.sons[codePos]);