소스 검색

* also take into account default namespace when looking for a unit:
if looking for a unit's PPU or source failed (and no explicit name was specified)
then all namespaces are walked in the order they were given in and then first the
PPU is looked for and then the source

git-svn-id: trunk@38915 -

svenbarth 7 년 전
부모
커밋
99c53abf36
1개의 변경된 파일85개의 추가작업 그리고 31개의 파일을 삭제
  1. 85 31
      compiler/fppu.pas

+ 85 - 31
compiler/fppu.pas

@@ -123,7 +123,7 @@ implementation
 uses
   SysUtils,
   cfileutl,
-  systems,version,
+  systems,version,options,
   symtable, symsym,
   wpoinfo,
   scanner,
@@ -374,34 +374,49 @@ var
          singlepathstring,
          filename : TCmdStr;
 
-         Function UnitExists(const ext:string;var foundfile:TCmdStr):boolean;
+         Function UnitExists(const ext:string;var foundfile:TCmdStr;const prefix:TCmdStr):boolean;
+         var
+           s : tcmdstr;
          begin
            if CheckVerbosity(V_Tried) then
              Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
-           UnitExists:=FindFile(FileName+ext,Singlepathstring,true,foundfile);
+           s:=FileName+ext;
+           if prefix<>'' then
+             s:=prefix+'.'+s;
+           UnitExists:=FindFile(s,Singlepathstring,true,foundfile);
          end;
 
-         Function PPUSearchPath(const s:TCmdStr):boolean;
+         Function PPUSearchPath(const s,prefix:TCmdStr):boolean;
          var
            found : boolean;
-           hs    : TCmdStr;
+           hs,
+           newname : TCmdStr;
          begin
            Found:=false;
            singlepathstring:=FixPath(s,false);
          { Check for PPU file }
-           Found:=UnitExists(target_info.unitext,hs);
+           Found:=UnitExists(target_info.unitext,hs,prefix);
            if Found then
             Begin
               SetFileName(hs,false);
+              if prefix<>'' then
+                begin
+                  newname:=prefix+'.'+realmodulename^;
+                  stringdispose(realmodulename);
+                  realmodulename:=stringdup(newname);
+                  stringdispose(modulename);
+                  modulename:=stringdup(upper(newname));
+                end;
               Found:=openppufile;
             End;
            PPUSearchPath:=Found;
          end;
 
-         Function SourceSearchPath(const s:TCmdStr):boolean;
+         Function SourceSearchPath(const s,prefix:TCmdStr):boolean;
          var
            found   : boolean;
-           hs      : TCmdStr;
+           hs,
+           newname : TCmdStr;
          begin
            Found:=false;
            singlepathstring:=FixPath(s,false);
@@ -410,18 +425,18 @@ var
            do_compile:=true;
            recompile_reason:=rr_noppu;
          {Check for .pp file}
-           Found:=UnitExists(sourceext,hs);
+           Found:=UnitExists(sourceext,hs,prefix);
            if not Found then
             begin
               { Check for .pas }
-              Found:=UnitExists(pasext,hs);
+              Found:=UnitExists(pasext,hs,prefix);
             end;
            if not Found and
               ((m_mac in current_settings.modeswitches) or
                (tf_p_ext_support in target_info.flags)) then
             begin
               { Check for .p, if mode is macpas}
-              Found:=UnitExists(pext,hs);
+              Found:=UnitExists(pext,hs,prefix);
             end;
            mainsource:='';
            if Found then
@@ -430,26 +445,34 @@ var
               { Load Filenames when found }
               mainsource:=hs;
               SetFileName(hs,false);
+              if prefix<>'' then
+                begin
+                  newname:=prefix+'.'+realmodulename^;
+                  stringdispose(realmodulename);
+                  realmodulename:=stringdup(newname);
+                  stringdispose(modulename);
+                  modulename:=stringdup(upper(newname));
+                end;
             end
            else
             sources_avail:=false;
            SourceSearchPath:=Found;
          end;
 
-         Function SearchPath(const s:TCmdStr):boolean;
+         Function SearchPath(const s,prefix:TCmdStr):boolean;
          var
            found : boolean;
          begin
            { First check for a ppu, then for the source }
            found:=false;
            if not onlysource then
-            found:=PPUSearchPath(s);
+            found:=PPUSearchPath(s,prefix);
            if not found then
-            found:=SourceSearchPath(s);
+            found:=SourceSearchPath(s,prefix);
            SearchPath:=found;
          end;
 
-         Function SearchPathList(list:TSearchPathList):boolean;
+         Function SearchPathList(list:TSearchPathList;const prefix:TCmdStr):boolean;
          var
            hp : TCmdStrListItem;
            found : boolean;
@@ -458,7 +481,7 @@ var
            hp:=TCmdStrListItem(list.First);
            while assigned(hp) do
             begin
-              found:=SearchPath(hp.Str);
+              found:=SearchPath(hp.Str,prefix);
               if found then
                break;
               hp:=TCmdStrListItem(hp.next);
@@ -466,9 +489,30 @@ var
            SearchPathList:=found;
          end;
 
+         function SearchPPUPaths(const prefix:TCmdStr):boolean;
+         begin
+           result:=PPUSearchPath('.',prefix);
+           if (not result) and (outputpath<>'') then
+            result:=PPUSearchPath(outputpath,prefix);
+           if (not result) and Assigned(main_module) and (main_module.Path<>'')  then
+            result:=PPUSearchPath(main_module.Path,prefix);
+         end;
+
+         function SearchSourcePaths(const prefix:TCmdStr):boolean;
+         begin
+           result:=SourceSearchPath('.',prefix);
+           if (not result) and Assigned(main_module) and (main_module.Path<>'') then
+             result:=SourceSearchPath(main_module.Path,prefix);
+           if (not result) and Assigned(loaded_from) then
+             result:=SearchPathList(loaded_from.LocalUnitSearchPath,prefix);
+           if not result then
+             result:=SearchPathList(UnitSearchPath,prefix);
+         end;
+
        var
          fnd : boolean;
          hs  : TPathStr;
+         nsitem : TCmdStrListItem;
        begin
          if shortname then
           filename:=FixFileName(Copy(realmodulename^,1,8))
@@ -482,16 +526,12 @@ var
             5. look for source in cwd
             6. look for source in maindir
             7. local unit pathlist
-            8. global unit pathlist }
+            8. global unit pathlist
+            9. for each default namespace:
+                  repeat 1 - 3 and 5 - 8 with namespace as prefix }
          fnd:=false;
          if not onlysource then
-          begin
-            fnd:=PPUSearchPath('.');
-            if (not fnd) and (outputpath<>'') then
-             fnd:=PPUSearchPath(outputpath);
-            if (not fnd) and Assigned(main_module) and (main_module.Path<>'')  then
-             fnd:=PPUSearchPath(main_module.Path);
-          end;
+            fnd:=SearchPPUPaths('');
          if (not fnd) and (sourcefn<>'') then
           begin
             { the full filename is specified so we can't use here the
@@ -523,13 +563,27 @@ var
              end;
           end;
          if not fnd then
-           fnd:=SourceSearchPath('.');
-         if (not fnd) and Assigned(main_module) and (main_module.Path<>'') then
-           fnd:=SourceSearchPath(main_module.Path);
-         if (not fnd) and Assigned(loaded_from) then
-           fnd:=SearchPathList(loaded_from.LocalUnitSearchPath);
-         if not fnd then
-           fnd:=SearchPathList(UnitSearchPath);
+           begin
+             fnd:=SearchSourcePaths('');
+             if not fnd and (namespacelist.count>0) then
+               begin
+                 nsitem:=TCmdStrListItem(namespacelist.first);
+                 while assigned(nsitem) do
+                   begin
+                     if not onlysource then
+                       begin
+                         fnd:=SearchPPUPaths(nsitem.str);
+                         if fnd then
+                           break;
+                       end;
+                     fnd:=SearchSourcePaths(nsitem.str);
+                     if fnd then
+                       break;
+
+                     nsitem:=TCmdStrListItem(nsitem.next);
+                   end;
+               end;
+           end;
          search_unit:=fnd;
       end;