浏览代码

+ TSymtablestack.getcopyuntil() method that creates a copy of a
symtablestack up to and including a particular symtable

git-svn-id: branches/jvmbackend@18582 -

Jonas Maebe 14 年之前
父节点
当前提交
1bc846dd3c
共有 1 个文件被更改,包括 25 次插入0 次删除
  1. 25 0
      compiler/symbase.pas

+ 25 - 0
compiler/symbase.pas

@@ -133,6 +133,7 @@ interface
          procedure push(st:TSymtable); virtual;
          procedure push(st:TSymtable); virtual;
          procedure pop(st:TSymtable); virtual;
          procedure pop(st:TSymtable); virtual;
          function  top:TSymtable;
          function  top:TSymtable;
+         function getcopyuntil(finalst: TSymtable): TSymtablestack;
        end;
        end;
 
 
 
 
@@ -430,6 +431,30 @@ implementation
       end;
       end;
 
 
 
 
+  function addstitemreverse(st: TSymtablestack; finalst: tsymtable; curitem: psymtablestackitem): boolean;
+    begin
+      if not assigned(curitem) then
+        begin
+          result:=true;
+          exit;
+        end;
+      if addstitemreverse(st,finalst,curitem^.next) then
+        begin
+          st.push(curitem^.symtable);
+          result:=curitem^.symtable<>finalst
+        end
+      else
+        result:=false
+    end;
+
+
+  function TSymtablestack.getcopyuntil(finalst: TSymtable): TSymtablestack;
+    begin
+      result:=TSymtablestack.create;
+      addstitemreverse(result,finalst,stack);
+    end;
+
+
 {$ifdef MEMDEBUG}
 {$ifdef MEMDEBUG}
 initialization
 initialization
   memrealnames:=TMemDebug.create('Realnames');
   memrealnames:=TMemDebug.create('Realnames');