Browse Source

* 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 years ago
parent
commit
99c53abf36
1 changed files with 85 additions and 31 deletions
  1. 85 31
      compiler/fppu.pas

+ 85 - 31
compiler/fppu.pas

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