Some days ago I stated that the build-in macros %LINE% and %FILE%, used
inside a macro, expand to the wrong (in my opinion) info from the
defining context and not to those from the expanding context.

That makes them nearly useless, because using them inside a macro for
debugging purposes is their main benefit.

I wrote two small changes for scanner.pas and fmodule.pas which solve
the problem. Maybe the devils are interested in applying it, or
something similar.

The 'unknown' from my changes are in real Internal-Errors, which should
never occur. But changing this let's trying him to find an Environment-
Variable with the same name, which gives a Warning. So ...

Best regards
        Jörg
Index: compiler/fmodule.pas
===================================================================
--- compiler/fmodule.pas	(Revision 17417)
+++ compiler/fmodule.pas	(Arbeitskopie)
@@ -235,6 +235,7 @@
     function get_source_file(moduleindex,fileindex : longint) : tinputfile;
     procedure addloadedunit(hp:tmodule);
     function find_module_from_symtable(st:tsymtable):tmodule;
+    function ascend_from_macros(f:tinputfile) : tinputfile;
 
 
 implementation
@@ -336,6 +337,13 @@
       end;
 
 
+    function ascend_from_macros(f:tinputfile) : tinputfile;
+      begin
+        while assigned(f) and f.is_macro do f:=f.next;
+        ascend_from_macros:=f;
+      end;
+
+
     procedure addloadedunit(hp:tmodule);
       begin
         hp.moduleid:=loaded_units.count;
Index: compiler/scanner.pas
===================================================================
--- compiler/scanner.pas	(Revision 17417)
+++ compiler/scanner.pas	(Arbeitskopie)
@@ -1712,11 +1712,24 @@
              hs:=getdatestr
            else
             if hs='FILE' then
-             hs:=current_module.sourcefiles.get_file_name(current_filepos.fileindex)
+             begin
+               hp:=ascend_from_macros(current_module.sourcefiles.get_file(current_filepos.fileindex));
+               if assigned(hp) then hs:=hp.name^ else hs:='unknown'
+             end
            else
             if hs='LINE' then
-             hs:=tostr(current_filepos.line)
+             begin
+               hp:=ascend_from_macros(current_module.sourcefiles.get_file(current_filepos.fileindex));
+               if assigned(hp) then hs:=tostr(hp.saveline_no) else hs:='unknown'
+             end
            else
+            if hs='PATH' then
+             begin
+               hp:=ascend_from_macros(current_module.sourcefiles.get_file(current_filepos.fileindex));
+               if assigned(hp) then hs:=hp.path^ else hs:='unknown';
+               if hs='' then hs:=CurDirRelPath(target_info)
+             end
+           else
             if hs='FPCVERSION' then
              hs:=version_string
            else
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to