소스 검색

* when inlining a function we need to import symbols that were loaded from another unit (or the same unit if the inlined function is from another unit and uses another function in the same unit)

git-svn-id: trunk@34380 -
svenbarth 9 년 전
부모
커밋
d46c015eb1
1개의 변경된 파일31개의 추가작업 그리고 0개의 파일을 삭제
  1. 31 0
      compiler/ncal.pas

+ 31 - 0
compiler/ncal.pas

@@ -4850,6 +4850,36 @@ implementation
       end;
 
 
+    { reference symbols that are imported from another unit }
+    function importglobalsyms(var n:tnode; arg:pointer):foreachnoderesult;
+      var
+        sym : tsym;
+      begin
+        result:=fen_false;
+        if n.nodetype=loadn then
+          begin
+            sym:=tloadnode(n).symtableentry;
+            if sym.typ=staticvarsym then
+              begin
+                if FindUnitSymtable(tloadnode(n).symtable).moduleid<>current_module.moduleid then
+                  current_module.addimportedsym(sym);
+              end
+            else if (sym.typ=constsym) and (tconstsym(sym).consttyp=constresourcestring) then
+              begin
+                if tloadnode(n).symtableentry.owner.moduleid<>current_module.moduleid then
+                  current_module.addimportedsym(sym);
+              end;
+          end
+        else if (n.nodetype=calln) then
+          begin
+            if (assigned(tcallnode(n).procdefinition)) and
+               (tcallnode(n).procdefinition.typ=procdef) and
+               (findunitsymtable(tcallnode(n).procdefinition.owner).moduleid<>current_module.moduleid) then
+              current_module.addimportedsym(tprocdef(tcallnode(n).procdefinition).procsym);
+          end;
+      end;
+
+
     function tcallnode.pass1_inline:tnode;
       var
         n,
@@ -4887,6 +4917,7 @@ implementation
         { create a copy of the body and replace parameter loads with the parameter values }
         body:=tprocdef(procdefinition).inlininginfo^.code.getcopy;
         foreachnodestatic(pm_postprocess,body,@removeusercodeflag,nil);
+        foreachnodestatic(pm_postprocess,body,@importglobalsyms,nil);
         foreachnode(pm_preprocess,body,@replaceparaload,@fileinfo);
 
         { Concat the body and finalization parts }